PageRenderTime 41ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/product/composition/fiche.php

https://bitbucket.org/speedealing/speedealing
PHP | 504 lines | 362 code | 74 blank | 68 comment | 79 complexity | 21ca98244e97c6f397f74a8d8a96428e MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005 Eric Seigne <eric.seigne@ryxeo.com>
  5. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
  6. * Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
  7. * Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. */
  22. /**
  23. * \file htdocs/product/composition/fiche.php
  24. * \ingroup product
  25. * \brief Page de la fiche produit
  26. */
  27. require '../../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  31. $langs->load("bills");
  32. $langs->load("products");
  33. $id=GETPOST('id','int');
  34. $ref=GETPOST('ref','alpha');
  35. $action=GETPOST('action','alpha');
  36. $confirm=GETPOST('confirm','alpha');
  37. $cancel=GETPOST('cancel','alpha');
  38. $key=GETPOST('key');
  39. $parent=GETPOST('parent');
  40. // Security check
  41. if (! empty($user->societe_id)) $socid=$user->societe_id;
  42. $fieldvalue = (! empty($id) ? $id : (! empty($ref) ? $ref : ''));
  43. $fieldtype = (! empty($ref) ? 'ref' : 'rowid');
  44. $result=restrictedArea($user,'produit|service',$fieldvalue,'product&product','','',$fieldtype);
  45. $mesg = '';
  46. $product = new Product($db);
  47. $productid=0;
  48. if ($id || $ref)
  49. {
  50. $result = $product->fetch($id,$ref);
  51. $productid=$product->id;
  52. }
  53. /*
  54. * Actions
  55. */
  56. // Action association d'un sousproduit
  57. if ($action == 'add_prod' &&
  58. $cancel <> $langs->trans("Cancel") &&
  59. ($user->rights->produit->creer || $user->rights->service->creer))
  60. {
  61. $error=0;
  62. for($i=0;$i<$_POST["max_prod"];$i++)
  63. {
  64. // print "<br> : ".$_POST["prod_id_chk".$i];
  65. if($_POST["prod_id_chk".$i] != "")
  66. {
  67. if($product->add_sousproduit($id, $_POST["prod_id_".$i],$_POST["prod_qty_".$i]) > 0)
  68. {
  69. $action = 'edit';
  70. }
  71. else
  72. {
  73. $error++;
  74. $action = 're-edit';
  75. if ($product->error == "isFatherOfThis") $mesg = $langs->trans("ErrorAssociationIsFatherOfThis");
  76. else $mesg=$product->error;
  77. }
  78. }
  79. else
  80. {
  81. if ($product->del_sousproduit($id, $_POST["prod_id_".$i]) > 0)
  82. {
  83. $action = 'edit';
  84. }
  85. else
  86. {
  87. $error++;
  88. $action = 're-edit';
  89. $mesg=$product->error;
  90. }
  91. }
  92. }
  93. if (! $error)
  94. {
  95. header("Location: ".$_SERVER["PHP_SELF"].'?id='.$product->id);
  96. exit;
  97. }
  98. }
  99. if ($cancel == $langs->trans("Cancel"))
  100. {
  101. $action = '';
  102. header("Location: fiche.php?id=".$_POST["id"]);
  103. exit;
  104. }
  105. /*
  106. * View
  107. */
  108. // action recherche des produits par mot-cle et/ou par categorie
  109. if ($action == 'search')
  110. {
  111. $current_lang = $langs->getDefaultLang();
  112. $sql = 'SELECT DISTINCT p.rowid, p.ref, p.label, p.price, p.fk_product_type as type';
  113. if (! empty($conf->global->MAIN_MULTILANGS)) $sql.= ', pl.label as labelm, pl.description as descriptionm';
  114. $sql.= ' FROM '.MAIN_DB_PREFIX.'product as p';
  115. $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON p.rowid = cp.fk_product';
  116. if (! empty($conf->global->MAIN_MULTILANGS)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_lang as pl ON pl.fk_product = p.rowid AND lang='".($current_lang)."'";
  117. $sql.= ' WHERE p.entity IN ('.getEntity("product", 1).')';
  118. if ($key != "")
  119. {
  120. if (! empty($conf->global->MAIN_MULTILANGS))
  121. {
  122. $sql.= " AND (p.ref LIKE '%".$key."%'";
  123. $sql.= " OR pl.label LIKE '%".$key."%')";
  124. }
  125. else
  126. {
  127. $sql.= " AND (p.ref LIKE '%".$key."%'";
  128. $sql.= " OR p.label LIKE '%".$key."%')";
  129. }
  130. }
  131. if (! empty($conf->categorie->enabled) && ! empty($parent) && $parent != -1)
  132. {
  133. $sql.= " AND cp.fk_categorie ='".$db->escape($parent)."'";
  134. }
  135. $sql.= " ORDER BY p.ref ASC";
  136. $resql = $db->query($sql);
  137. }
  138. //print $sql;
  139. $productstatic = new Product($db);
  140. $form = new Form($db);
  141. llxHeader("","",$langs->trans("CardProduct".$product->type));
  142. $form = new Form($db);
  143. dol_htmloutput_errors($mesg);
  144. $head=product_prepare_head($product, $user);
  145. $titre=$langs->trans("CardProduct".$product->type);
  146. $picto=($product->type==1?'service':'product');
  147. dol_fiche_head($head, 'subproduct', $titre, 0, $picto);
  148. if ($id || $ref)
  149. {
  150. if ($result)
  151. {
  152. if ($action <> 'edit' && $action <> 'search' && $action <> 're-edit')
  153. {
  154. /*
  155. * En mode visu
  156. */
  157. print '<table class="border" width="100%">';
  158. print "<tr>";
  159. $nblignes=6;
  160. if ($product->isproduct() && ! empty($conf->stock->enabled)) $nblignes++;
  161. if ($product->isservice()) $nblignes++;
  162. // Reference
  163. print '<td width="25%">'.$langs->trans("Ref").'</td><td>';
  164. print $form->showrefnav($product,'ref','',1,'ref');
  165. print '</td></tr>';
  166. // Libelle
  167. print '<tr><td>'.$langs->trans("Label").'</td><td>'.$product->libelle.'</td>';
  168. print '</tr>';
  169. // Number of subproducts
  170. $prodsfather = $product->getFather(); //Parent Products
  171. $product->get_sousproduits_arbo();
  172. print '<tr><td>'.$langs->trans("AssociatedProductsNumber").'</td><td>'.count($product->get_arbo_each_prod()).'</td>';
  173. dol_fiche_end();
  174. // List of subproducts
  175. $prods_arbo = $product->get_arbo_each_prod();
  176. if (count($prods_arbo) > 0)
  177. {
  178. print '<tr><td colspan="2">';
  179. print '<b>'.$langs->trans("ProductAssociationList").'</b><br>';
  180. print '<table class="nobordernopadding">';
  181. foreach($prods_arbo as $value)
  182. {
  183. $productstatic->id=$value['id'];
  184. $productstatic->type=$value['type'];
  185. $productstatic->ref=$value['fullpath'];
  186. if (! empty($conf->stock->enabled)) $productstatic->load_stock();
  187. //var_dump($value);
  188. //print '<pre>'.$productstatic->ref.'</pre>';
  189. //print $productstatic->getNomUrl(1).'<br>';
  190. //print $value[0]; // This contains a tr line.
  191. print '<tr>';
  192. print '<td>'.$productstatic->getNomUrl(1,'composition').' ('.$value['nb'].') &nbsp &nbsp</td>';
  193. if (! empty($conf->stock->enabled)) print '<td>'.$langs->trans("Stock").' : <b>'.$productstatic->stock_reel.'</b></td>';
  194. print '</tr>';
  195. }
  196. print '</table>';
  197. print '</td></tr>';
  198. }
  199. // Number of parent products
  200. print '<tr><td>'.$langs->trans("ParentProductsNumber").'</td><td>'.count($prodsfather).'</td>';
  201. if (count($prodsfather) > 0)
  202. {
  203. print '<tr><td colspan="2">';
  204. print '<b>'.$langs->trans("ProductParentList").'</b><br>';
  205. print '<table class="nobordernopadding">';
  206. foreach($prodsfather as $value)
  207. {
  208. $idprod= $value["id"];
  209. $productstatic->id=$idprod;// $value["id"];
  210. $productstatic->type=$value["fk_product_type"];
  211. $productstatic->ref=$value['label'];
  212. print '<tr>';
  213. print '<td>'.$productstatic->getNomUrl(1,'composition').'</td>';;
  214. print '</tr>';
  215. }
  216. print '</table>';
  217. print '</td></tr>';
  218. }
  219. print "</table>\n";
  220. dol_fiche_end();
  221. }
  222. }
  223. /*
  224. * Fiche en mode edition
  225. */
  226. if (($action == 'edit' || $action == 'search' || $action == 're-edit') && ($user->rights->produit->creer || $user->rights->service->creer))
  227. {
  228. print '<table class="border" width="100%">';
  229. print "<tr>";
  230. $nblignes=6;
  231. if ($product->isproduct() && ! empty($conf->stock->enabled)) $nblignes++;
  232. if ($product->isservice()) $nblignes++;
  233. // Reference
  234. print '<td width="25%">'.$langs->trans("Ref").'</td><td>';
  235. print $form->showrefnav($product,'ref','',1,'ref');
  236. print '</td>';
  237. print '</tr>';
  238. // Label
  239. print '<tr><td>'.$langs->trans("Label").'</td><td>'.$product->libelle.'</td>';
  240. print '</tr>';
  241. // Number of subproducts
  242. $prodsfather = $product->getFather(); //Parent Products
  243. $product->get_sousproduits_arbo();
  244. print '<tr><td>'.$langs->trans("AssociatedProductsNumber").'</td><td>'.count($product->get_arbo_each_prod()).'</td>';
  245. print '</tr>';
  246. // List of subproducts
  247. $prods_arbo = $product->get_arbo_each_prod();
  248. //var_dump($prods_arbo);
  249. if(count($prods_arbo) > 0)
  250. {
  251. print '<tr><td colspan="2">';
  252. print '<b>'.$langs->trans("ProductAssociationList").'</b><br>';
  253. print '<table class="nobordernopadding">';
  254. foreach($prods_arbo as $value)
  255. {
  256. $productstatic->id=$value['id'];
  257. $productstatic->type=$value['type'];
  258. $productstatic->ref=$value['fullpath'];
  259. if (! empty($conf->stock->enabled)) $productstatic->load_stock();
  260. //var_dump($value);
  261. //print '<pre>'.$productstatic->ref.'</pre>';
  262. //print $productstatic->getNomUrl(1).'<br>';
  263. //print $value[0]; // This contains a tr line.
  264. print '<tr>';
  265. print '<td>'.$productstatic->getNomUrl(1,'composition').' ('.$value['nb'].') &nbsp &nbsp</td>';
  266. if (! empty($conf->stock->enabled)) print '<td>'.$langs->trans("Stock").' : <b>'.$productstatic->stock_reel.'</b></td>';
  267. print '</tr>';
  268. }
  269. print '</table>';
  270. print '</td></tr>';
  271. }
  272. // Number of parent products
  273. print '<tr><td>'.$langs->trans("ParentProductsNumber").'</td><td>'.count($prodsfather).'</td>';
  274. if (count($prodsfather) > 0)
  275. {
  276. print '<tr><td colspan="2">';
  277. print '<b>'.$langs->trans("ProductParentList").'</b><br>';
  278. print '<table class="nobordernopadding">';
  279. foreach($prodsfather as $value)
  280. {
  281. $idprod= $value["id"];
  282. $productstatic->id=$idprod;// $value["id"];
  283. $productstatic->type=$value["fk_product_type"];
  284. $productstatic->ref=$value['label'];
  285. print '<tr>';
  286. print '<td>'.$productstatic->getNomUrl(1,'composition').'</td>';;
  287. print '</tr>';
  288. }
  289. print '</table>';
  290. print '</td></tr>';
  291. }
  292. print '</table>';
  293. dol_fiche_end();
  294. print '<br>';
  295. $rowspan=1;
  296. if (! empty($conf->categorie->enabled)) $rowspan++;
  297. print_fiche_titre($langs->trans("ProductToAddSearch"),'','');
  298. print '<form action="'.DOL_URL_ROOT.'/product/composition/fiche.php?id='.$id.'" method="post">';
  299. print '<table class="border" width="100%"><tr><td>';
  300. print '<table class="nobordernopadding">';
  301. print '<tr><td>';
  302. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  303. print $langs->trans("KeywordFilter").' &nbsp; ';
  304. print '</td>';
  305. print '<td><input type="text" name="key" value="'.$key.'">';
  306. print '<input type="hidden" name="action" value="search">';
  307. print '<input type="hidden" name="id" value="'.$id.'">';
  308. print '</td>';
  309. print '<td rowspan="'.$rowspan.'" valign="middle">';
  310. print '<input type="submit" class="button" value="'.$langs->trans("Search").'">';
  311. print '</td></tr>';
  312. if (! empty($conf->categorie->enabled))
  313. {
  314. print '<tr><td>'.$langs->trans("CategoryFilter").' &nbsp; </td>';
  315. print '<td>'.$form->select_all_categories(0, $parent).'</td></tr>';
  316. }
  317. print '</table>';
  318. print '</td></td></table>';
  319. print '</form>';
  320. if ($action == 'search')
  321. {
  322. print '<br>';
  323. print '<form action="'.DOL_URL_ROOT.'/product/composition/fiche.php?id='.$id.'" method="post">';
  324. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  325. print '<input type="hidden" name="action" value="add_prod">';
  326. print '<input type="hidden" name="id" value="'.$id.'">';
  327. print '<table class="nobordernopadding" width="100%">';
  328. print '<tr class="liste_titre">';
  329. print '<th class="liste_titre">'.$langs->trans("Ref").'</td>';
  330. print '<th class="liste_titre">'.$langs->trans("Label").'</td>';
  331. print '<th class="liste_titre" align="center">'.$langs->trans("AddDel").'</td>';
  332. print '<th class="liste_titre" align="right">'.$langs->trans("Quantity").'</td>';
  333. print '</tr>';
  334. if ($resql)
  335. {
  336. $num = $db->num_rows($resql);
  337. $i=0;
  338. $var=true;
  339. if($num == 0) print '<tr><td colspan="4">'.$langs->trans("NoMatchFound").'</td></tr>';
  340. while ($i < $num)
  341. {
  342. $objp = $db->fetch_object($resql);
  343. if($objp->rowid != $id)
  344. {
  345. // check if a product is not already a parent product of this one
  346. $prod_arbo=new Product($db);
  347. $prod_arbo->id=$objp->rowid;
  348. if ($prod_arbo->type==2 || $prod_arbo->type==3)
  349. {
  350. $is_pere=0;
  351. $prod_arbo->get_sousproduits_arbo();
  352. // associations sousproduits
  353. $prods_arbo = $prod_arbo->get_arbo_each_prod();
  354. if (count($prods_arbo) > 0)
  355. {
  356. foreach($prods_arbo as $key => $value)
  357. {
  358. if ($value[1]==$id)
  359. {
  360. $is_pere=1;
  361. }
  362. }
  363. }
  364. if ($is_pere==1)
  365. {
  366. $i++;
  367. continue;
  368. }
  369. }
  370. $var=!$var;
  371. print "\n<tr ".$bc[$var].">";
  372. $productstatic->id=$objp->rowid;
  373. $productstatic->ref=$objp->ref;
  374. $productstatic->libelle=$objp->label;
  375. $productstatic->type=$objp->type;
  376. print '<td>'.$productstatic->getNomUrl(1,'',24).'</td>';
  377. $labeltoshow=$objp->label;
  378. if ($conf->global->MAIN_MULTILANGS && $objp->labelm) $labeltoshow=$objp->labelm;
  379. print '<td>'.$labeltoshow.'</td>';
  380. if($product->is_sousproduit($id, $objp->rowid))
  381. {
  382. $addchecked = ' checked="checked"';
  383. $qty=$product->is_sousproduit_qty;
  384. }
  385. else
  386. {
  387. $addchecked = '';
  388. $qty="1";
  389. }
  390. print '<td align="center"><input type="hidden" name="prod_id_'.$i.'" value="'.$objp->rowid.'">';
  391. print '<input type="checkbox" '.$addchecked.'name="prod_id_chk'.$i.'" value="'.$objp->rowid.'"></td>';
  392. print '<td align="right"><input type="text" size="3" name="prod_qty_'.$i.'" value="'.$qty.'"></td>';
  393. print '</tr>';
  394. }
  395. $i++;
  396. }
  397. }
  398. else
  399. {
  400. dol_print_error($db);
  401. }
  402. print '</table>';
  403. print '<input type="hidden" name="max_prod" value="'.$i.'">';
  404. if($num > 0)
  405. {
  406. print '<br><center><input type="submit" class="button" value="'.$langs->trans("Add").'/'.$langs->trans("Update").'">';
  407. print ' &nbsp; &nbsp; <input type="submit" class="button" value="'.$langs->trans("Cancel").'">';
  408. print '</center>';
  409. }
  410. print '</form>';
  411. }
  412. }
  413. }
  414. /* ************************************************************************** */
  415. /* */
  416. /* Barre d'action */
  417. /* */
  418. /* ************************************************************************** */
  419. print "\n<div class=\"tabsAction\">\n";
  420. if ($action == '')
  421. {
  422. if ($user->rights->produit->creer || $user->rights->service->creer)
  423. {
  424. print '<a class="butAction" href="'.DOL_URL_ROOT.'/product/composition/fiche.php?action=edit&amp;id='.$productid.'">'.$langs->trans("EditAssociate").'</a>';
  425. }
  426. }
  427. print "\n</div>\n";
  428. llxFooter();
  429. $db->close();
  430. ?>