card.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770
  1. <?php
  2. /* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2020 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005 Eric Seigne <eric.seigne@ryxeo.com>
  5. * Copyright (C) 2005-2018 Regis Houssin <regis.houssin@inodbox.com>
  6. * Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
  7. * Copyright (C) 2011-2014 Juanjo Menent <jmenent@2byte.es>
  8. * Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
  9. * Copyright (C) 2023 Benjamin Falière <benjamin.faliere@altairis.fr>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 3 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  23. */
  24. /**
  25. * \file htdocs/product/composition/card.php
  26. * \ingroup product
  27. * \brief Page of product file
  28. */
  29. // Load Dolibarr environment
  30. require '../../main.inc.php';
  31. require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
  33. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  34. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  35. // Load translation files required by the page
  36. $langs->loadLangs(array('bills', 'products', 'stocks'));
  37. $id = GETPOST('id', 'int');
  38. $ref = GETPOST('ref', 'alpha');
  39. $action = GETPOST('action', 'aZ09');
  40. $confirm = GETPOST('confirm', 'alpha');
  41. $cancel = GETPOST('cancel', 'alpha');
  42. $key = GETPOST('key');
  43. $parent = GETPOST('parent');
  44. // Security check
  45. if (!empty($user->socid)) {
  46. $socid = $user->socid;
  47. }
  48. $fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref : ''));
  49. $fieldtype = (!empty($ref) ? 'ref' : 'rowid');
  50. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  51. $hookmanager->initHooks(array('productcompositioncard', 'globalcard'));
  52. $object = new Product($db);
  53. $objectid = 0;
  54. if ($id > 0 || !empty($ref)) {
  55. $result = $object->fetch($id, $ref);
  56. $objectid = $object->id;
  57. $id = $object->id;
  58. }
  59. $result = restrictedArea($user, 'produit|service', $fieldvalue, 'product&product', '', '', $fieldtype);
  60. if ($object->id > 0) {
  61. if ($object->type == $object::TYPE_PRODUCT) {
  62. restrictedArea($user, 'produit', $object->id, 'product&product', '', '');
  63. }
  64. if ($object->type == $object::TYPE_SERVICE) {
  65. restrictedArea($user, 'service', $object->id, 'product&product', '', '');
  66. }
  67. } else {
  68. restrictedArea($user, 'produit|service', $fieldvalue, 'product&product', '', '', $fieldtype);
  69. }
  70. $usercanread = (($object->type == Product::TYPE_PRODUCT && $user->rights->produit->lire) || ($object->type == Product::TYPE_SERVICE && $user->hasRight('service', 'lire')));
  71. $usercancreate = (($object->type == Product::TYPE_PRODUCT && $user->rights->produit->creer) || ($object->type == Product::TYPE_SERVICE && $user->hasRight('service', 'creer')));
  72. $usercandelete = (($object->type == Product::TYPE_PRODUCT && $user->rights->produit->supprimer) || ($object->type == Product::TYPE_SERVICE && $user->rights->service->supprimer));
  73. /*
  74. * Actions
  75. */
  76. if ($cancel) {
  77. $action = '';
  78. }
  79. $reshook = $hookmanager->executeHooks('doActions', [], $object, $action); // Note that $action and $object may have been modified by some hooks
  80. if ($reshook < 0) {
  81. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  82. }
  83. if (empty($reshook)) {
  84. // Add subproduct to product
  85. if ($action == 'add_prod' && ($user->hasRight('produit', 'creer') || $user->hasRight('service', 'creer'))) {
  86. $error = 0;
  87. $maxprod = GETPOST("max_prod", 'int');
  88. for ($i = 0; $i < $maxprod; $i++) {
  89. $qty = price2num(GETPOST("prod_qty_" . $i, 'alpha'), 'MS');
  90. if ($qty > 0) {
  91. if ($object->add_sousproduit($id, GETPOST("prod_id_" . $i, 'int'), $qty, GETPOST("prod_incdec_" . $i, 'int')) > 0) {
  92. //var_dump($i.' '.GETPOST("prod_id_".$i, 'int'), $qty, GETPOST("prod_incdec_".$i, 'int'));
  93. $action = 'edit';
  94. } else {
  95. $error++;
  96. $action = 're-edit';
  97. if ($object->error == "isFatherOfThis") {
  98. setEventMessages($langs->trans("ErrorAssociationIsFatherOfThis"), null, 'errors');
  99. } else {
  100. setEventMessages($object->error, $object->errors, 'errors');
  101. }
  102. }
  103. } else {
  104. if ($object->del_sousproduit($id, GETPOST("prod_id_" . $i, 'int')) > 0) {
  105. $action = 'edit';
  106. } else {
  107. $error++;
  108. $action = 're-edit';
  109. setEventMessages($object->error, $object->errors, 'errors');
  110. }
  111. }
  112. }
  113. if (!$error) {
  114. header("Location: " . $_SERVER["PHP_SELF"] . '?id=' . $object->id);
  115. exit;
  116. }
  117. } elseif ($action === 'save_composed_product') {
  118. $TProduct = GETPOST('TProduct', 'array');
  119. if (!empty($TProduct)) {
  120. foreach ($TProduct as $id_product => $row) {
  121. if ($row['qty'] > 0) {
  122. $object->update_sousproduit($id, $id_product, $row['qty'], isset($row['incdec']) ? 1 : 0);
  123. } else {
  124. $object->del_sousproduit($id, $id_product);
  125. }
  126. }
  127. setEventMessages('RecordSaved', null);
  128. }
  129. $action = '';
  130. header("Location: " . $_SERVER["PHP_SELF"] . '?id=' . $object->id);
  131. exit;
  132. }
  133. }
  134. /*
  135. * View
  136. */
  137. $form = new Form($db);
  138. $formproduct = new FormProduct($db);
  139. $product_fourn = new ProductFournisseur($db);
  140. $productstatic = new Product($db);
  141. // action recherche des produits par mot-cle et/ou par categorie
  142. if ($action == 'search') {
  143. $current_lang = $langs->getDefaultLang();
  144. $sql = 'SELECT DISTINCT p.rowid, p.ref, p.label, p.fk_product_type as type, p.barcode, p.price, p.price_ttc, p.price_base_type, p.entity,';
  145. $sql .= ' p.fk_product_type, p.tms as datem, p.tobatch';
  146. $sql .= ', p.tosell as status, p.tobuy as status_buy';
  147. if (getDolGlobalInt('MAIN_MULTILANGS')) {
  148. $sql .= ', pl.label as labelm, pl.description as descriptionm';
  149. }
  150. $parameters = array();
  151. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
  152. $sql .= $hookmanager->resPrint;
  153. $sql .= ' FROM '.MAIN_DB_PREFIX.'product as p';
  154. $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON p.rowid = cp.fk_product';
  155. if (getDolGlobalInt('MAIN_MULTILANGS')) {
  156. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_lang as pl ON pl.fk_product = p.rowid AND lang='".($current_lang)."'";
  157. }
  158. $sql .= ' WHERE p.entity IN ('.getEntity('product').')';
  159. $parameters = array();
  160. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
  161. $sql .= $hookmanager->resPrint;
  162. if ($key != "") {
  163. // For natural search
  164. $params = array('p.ref', 'p.label', 'p.description', 'p.note');
  165. // multilang
  166. if (getDolGlobalInt('MAIN_MULTILANGS')) {
  167. $params[] = 'pl.label';
  168. $params[] = 'pl.description';
  169. $params[] = 'pl.note';
  170. }
  171. if (isModEnabled('barcode')) {
  172. $params[] = 'p.barcode';
  173. }
  174. $sql .= natural_search($params, $key);
  175. }
  176. if (isModEnabled('categorie') && !empty($parent) && $parent != -1) {
  177. $sql .= " AND cp.fk_categorie ='".$db->escape($parent)."'";
  178. }
  179. $sql .= " ORDER BY p.ref ASC";
  180. $resql = $db->query($sql);
  181. }
  182. $title = $langs->trans('ProductServiceCard');
  183. $help_url = '';
  184. $shortlabel = dol_trunc($object->label, 16);
  185. if (GETPOST("type") == '0' || ($object->type == Product::TYPE_PRODUCT)) {
  186. $title = $langs->trans('Product')." ".$shortlabel." - ".$langs->trans('AssociatedProducts');
  187. $help_url = 'EN:Module_Products|FR:Module_Produits|ES:M&oacute;dulo_Productos|DE:Modul_Produkte';
  188. }
  189. if (GETPOST("type") == '1' || ($object->type == Product::TYPE_SERVICE)) {
  190. $title = $langs->trans('Service')." ".$shortlabel." - ".$langs->trans('AssociatedProducts');
  191. $help_url = 'EN:Module_Services_En|FR:Module_Services|ES:M&oacute;dulo_Servicios|DE:Modul_Leistungen';
  192. }
  193. llxHeader('', $title, $help_url);
  194. $head = product_prepare_head($object);
  195. $titre = $langs->trans("CardProduct".$object->type);
  196. $picto = ($object->type == Product::TYPE_SERVICE ? 'service' : 'product');
  197. print dol_get_fiche_head($head, 'subproduct', $titre, -1, $picto);
  198. if ($id > 0 || !empty($ref)) {
  199. /*
  200. * Product card
  201. */
  202. if ($user->hasRight('produit', 'lire') || $user->hasRight('service', 'lire')) {
  203. $linkback = '<a href="'.DOL_URL_ROOT.'/product/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  204. $shownav = 1;
  205. if ($user->socid && !in_array('product', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) {
  206. $shownav = 0;
  207. }
  208. dol_banner_tab($object, 'ref', $linkback, $shownav, 'ref', '');
  209. if ($object->type != Product::TYPE_SERVICE || !empty($conf->global->STOCK_SUPPORTS_SERVICES) || empty($conf->global->PRODUIT_MULTIPRICES)) {
  210. print '<div class="fichecenter">';
  211. print '<div class="fichehalfleft">';
  212. print '<div class="underbanner clearboth"></div>';
  213. print '<table class="border centpercent tableforfield">';
  214. // Type
  215. if (isModEnabled("product") && isModEnabled("service")) {
  216. $typeformat = 'select;0:'.$langs->trans("Product").',1:'.$langs->trans("Service");
  217. print '<tr><td class="titlefield">';
  218. print (empty($conf->global->PRODUCT_DENY_CHANGE_PRODUCT_TYPE)) ? $form->editfieldkey("Type", 'fk_product_type', $object->type, $object, $usercancreate, $typeformat) : $langs->trans('Type');
  219. print '</td><td>';
  220. print $form->editfieldval("Type", 'fk_product_type', $object->type, $object, $usercancreate, $typeformat);
  221. print '</td></tr>';
  222. }
  223. print '</table>';
  224. print '</div><div class="fichehalfright">';
  225. print '<div class="underbanner clearboth"></div>';
  226. print '<table class="border centpercent tableforfield">';
  227. // Nature
  228. if ($object->type != Product::TYPE_SERVICE) {
  229. if (empty($conf->global->PRODUCT_DISABLE_NATURE)) {
  230. print '<tr><td>'.$form->textwithpicto($langs->trans("NatureOfProductShort"), $langs->trans("NatureOfProductDesc")).'</td><td>';
  231. print $object->getLibFinished();
  232. //print $formproduct->selectProductNature('finished', $object->finished);
  233. print '</td></tr>';
  234. }
  235. }
  236. if (empty($conf->global->PRODUIT_MULTIPRICES)) {
  237. // Price
  238. print '<tr><td class="titlefield">'.$langs->trans("SellingPrice").'</td><td>';
  239. if ($object->price_base_type == 'TTC') {
  240. print price($object->price_ttc).' '.$langs->trans($object->price_base_type);
  241. } else {
  242. print price($object->price).' '.$langs->trans($object->price_base_type ? $object->price_base_type : 'HT');
  243. }
  244. print '</td></tr>';
  245. // Price minimum
  246. print '<tr><td>'.$langs->trans("MinPrice").'</td><td>';
  247. if ($object->price_base_type == 'TTC') {
  248. print price($object->price_min_ttc).' '.$langs->trans($object->price_base_type);
  249. } else {
  250. print price($object->price_min).' '.$langs->trans($object->price_base_type ? $object->price_base_type : 'HT');
  251. }
  252. print '</td></tr>';
  253. }
  254. print '</table>';
  255. print '</div>';
  256. print '</div>';
  257. }
  258. print dol_get_fiche_end();
  259. print '<br><br>';
  260. $prodsfather = $object->getFather(); // Parent Products
  261. $object->get_sousproduits_arbo(); // Load $object->sousprods
  262. $parent_label = $object->label;
  263. $prods_arbo = $object->get_arbo_each_prod();
  264. $tmpid = $id;
  265. if (!empty($conf->use_javascript_ajax)) {
  266. $nboflines = $prods_arbo;
  267. $table_element_line='product_association';
  268. include DOL_DOCUMENT_ROOT . '/core/tpl/ajaxrow.tpl.php';
  269. }
  270. $id = $tmpid;
  271. $nbofsubsubproducts = count($prods_arbo); // This include sub sub product into nb
  272. $prodschild = $object->getChildsArbo($id, 1);
  273. $nbofsubproducts = count($prodschild); // This include only first level of childs
  274. print '<div class="fichecenter">';
  275. print load_fiche_titre($langs->trans("ProductParentList"), '', '');
  276. print '<table class="liste">';
  277. print '<tr class="liste_titre">';
  278. print '<td>'.$langs->trans('ParentProducts').'</td>';
  279. print '<td>'.$langs->trans('Label').'</td>';
  280. print '<td class="right">'.$langs->trans('Qty').'</td>';
  281. print '</td>';
  282. if (count($prodsfather) > 0) {
  283. foreach ($prodsfather as $value) {
  284. $idprod = $value["id"];
  285. $productstatic->id = $idprod; // $value["id"];
  286. $productstatic->type = $value["fk_product_type"];
  287. $productstatic->ref = $value['ref'];
  288. $productstatic->label = $value['label'];
  289. $productstatic->entity = $value['entity'];
  290. $productstatic->status = $value['status'];
  291. $productstatic->status_buy = $value['status_buy'];
  292. print '<tr class="oddeven">';
  293. print '<td>'.$productstatic->getNomUrl(1, 'composition').'</td>';
  294. print '<td>'.dol_escape_htmltag($productstatic->label).'</td>';
  295. print '<td class="right">'.dol_escape_htmltag($value['qty']).'</td>';
  296. print '</tr>';
  297. }
  298. } else {
  299. print '<tr class="oddeven">';
  300. print '<td colspan="3"><span class="opacitymedium">'.$langs->trans("None").'</span></td>';
  301. print '</tr>';
  302. }
  303. print '</table>';
  304. print '</div>';
  305. print '<br>'."\n";
  306. print '<div class="fichecenter">';
  307. $atleastonenotdefined = 0;
  308. print load_fiche_titre($langs->trans("ProductAssociationList"), '', '');
  309. print '<form name="formComposedProduct" action="'.$_SERVER['PHP_SELF'].'" method="post">';
  310. print '<input type="hidden" name="token" value="'.newToken().'" />';
  311. print '<input type="hidden" name="action" value="save_composed_product" />';
  312. print '<input type="hidden" name="id" value="'.$id.'" />';
  313. print '<table id="tablelines" class="ui-sortable liste nobottom">';
  314. print '<tr class="liste_titre nodrag nodrop">';
  315. // Rank
  316. print '<td>'.$langs->trans('Position').'</td>';
  317. // Product ref
  318. print '<td>'.$langs->trans('ComposedProduct').'</td>';
  319. // Product label
  320. print '<td>'.$langs->trans('Label').'</td>';
  321. // Min supplier price
  322. print '<td class="right" colspan="2">'.$langs->trans('MinSupplierPrice').'</td>';
  323. // Min customer price
  324. print '<td class="right" colspan="2">'.$langs->trans('MinCustomerPrice').'</td>';
  325. // Stock
  326. if (isModEnabled('stock')) {
  327. print '<td class="right">'.$langs->trans('Stock').'</td>';
  328. }
  329. // Qty in kit
  330. print '<td class="right">'.$langs->trans('Qty').'</td>';
  331. // Stoc inc/dev
  332. print '<td class="center">'.$langs->trans('ComposedProductIncDecStock').'</td>';
  333. // Move
  334. print '<td class="linecolmove" style="width: 10px"></td>';
  335. print '</tr>'."\n";
  336. $totalsell = 0;
  337. $total = 0;
  338. if (count($prods_arbo)) {
  339. foreach ($prods_arbo as $value) {
  340. $productstatic->fetch($value['id']);
  341. if ($value['level'] <= 1) {
  342. print '<tr id="'.$object->sousprods[$parent_label][$value['id']][6].'" class="drag drop oddeven level1">';
  343. // Rank
  344. print '<td>'.$object->sousprods[$parent_label][$value['id']][7].'</td>';
  345. $notdefined = 0;
  346. $nb_of_subproduct = $value['nb'];
  347. // Product ref
  348. print '<td>'.$productstatic->getNomUrl(1, 'composition').'</td>';
  349. // Product label
  350. print '<td title="'.dol_escape_htmltag($productstatic->label).'" class="tdoverflowmax150">'.dol_escape_htmltag($productstatic->label).'</td>';
  351. // Best buying price
  352. print '<td class="right">';
  353. if ($product_fourn->find_min_price_product_fournisseur($productstatic->id) > 0) {
  354. print $langs->trans("BuyingPriceMinShort").': ';
  355. if ($product_fourn->product_fourn_price_id > 0) {
  356. print $product_fourn->display_price_product_fournisseur(0, 0);
  357. } else {
  358. print $langs->trans("NotDefined"); $notdefined++; $atleastonenotdefined++;
  359. }
  360. }
  361. print '</td>';
  362. // For avoid a non-numeric value
  363. $fourn_unitprice = (!empty($product_fourn->fourn_unitprice) ? $product_fourn->fourn_unitprice : 0);
  364. $fourn_remise_percent = (!empty($product_fourn->fourn_remise_percent) ? $product_fourn->fourn_remise_percent : 0);
  365. $fourn_remise = (!empty($product_fourn->fourn_remise) ? $product_fourn->fourn_remise : 0);
  366. $unitline = price2num(($fourn_unitprice * (1 - ($fourn_remise_percent / 100)) - $fourn_remise), 'MU');
  367. $totalline = price2num($value['nb'] * ($fourn_unitprice * (1 - ($fourn_remise_percent / 100)) - $fourn_remise), 'MT');
  368. $total += $totalline;
  369. print '<td class="right nowraponall">';
  370. print ($notdefined ? '' : ($value['nb'] > 1 ? $value['nb'].'x ' : '').'<span class="amount">'.price($unitline, '', '', 0, 0, -1, $conf->currency)).'</span>';
  371. print '</td>';
  372. // Best selling price
  373. $pricesell = $productstatic->price;
  374. if (!empty($conf->global->PRODUIT_MULTIPRICES)) {
  375. $pricesell = 'Variable';
  376. } else {
  377. $totallinesell = price2num($value['nb'] * ($pricesell), 'MT');
  378. $totalsell += $totallinesell;
  379. }
  380. print '<td class="right" colspan="2">';
  381. print ($notdefined ? '' : ($value['nb'] > 1 ? $value['nb'].'x ' : ''));
  382. if (is_numeric($pricesell)) {
  383. print '<span class="amount">'.price($pricesell, '', '', 0, 0, -1, $conf->currency).'</span>';
  384. } else {
  385. print '<span class="opacitymedium">'.$langs->trans($pricesell).'</span>';
  386. }
  387. print '</td>';
  388. // Stock
  389. if (isModEnabled('stock')) {
  390. print '<td class="right">'.$value['stock'].'</td>'; // Real stock
  391. }
  392. // Qty + IncDec
  393. if ($user->hasRight('produit', 'creer') || $user->hasRight('service', 'creer')) {
  394. print '<td class="center"><input type="text" value="'.$nb_of_subproduct.'" name="TProduct['.$productstatic->id.'][qty]" class="right width40" /></td>';
  395. print '<td class="center"><input type="checkbox" name="TProduct['.$productstatic->id.'][incdec]" value="1" '.($value['incdec'] == 1 ? 'checked' : '').' /></td>';
  396. } else {
  397. print '<td>'.$nb_of_subproduct.'</td>';
  398. print '<td>'.($value['incdec'] == 1 ? 'x' : '').'</td>';
  399. }
  400. // Move action
  401. print '<td class="linecolmove tdlineupdown center"></td>';
  402. print '</tr>'."\n";
  403. } else {
  404. $hide = '';
  405. if (empty($conf->global->PRODUCT_SHOW_SUB_SUB_PRODUCTS)) {
  406. $hide = ' hideobject'; // By default, we do not show this. It makes screen very difficult to understand
  407. }
  408. print '<tr class="oddeven'.$hide.'" id="sub-'.$value['id_parent'].'" data-ignoreidfordnd=1>';
  409. //$productstatic->ref=$value['label'];
  410. $productstatic->ref = $value['ref'];
  411. // Rankd
  412. print '<td></td>';
  413. // Product ref
  414. print '<td>';
  415. for ($i = 0; $i < $value['level']; $i++) {
  416. print ' &nbsp; &nbsp; '; // Add indentation
  417. }
  418. print $productstatic->getNomUrl(1, 'composition');
  419. print '</td>';
  420. // Product label
  421. print '<td>'.dol_escape_htmltag($productstatic->label).'</td>';
  422. // Best buying price
  423. print '<td>&nbsp;</td>';
  424. print '<td>&nbsp;</td>';
  425. // Best selling price
  426. print '<td>&nbsp;</td>';
  427. print '<td>&nbsp;</td>';
  428. // Stock
  429. if (isModEnabled('stock')) {
  430. print '<td></td>'; // Real stock
  431. }
  432. // Qty in kit
  433. print '<td class="right">'.dol_escape_htmltag($value['nb']).'</td>';
  434. // Inc/dec
  435. print '<td>&nbsp;</td>';
  436. // Action move
  437. print '<td>&nbsp;</td>';
  438. print '</tr>'."\n";
  439. }
  440. }
  441. // Total
  442. print '<tr class="liste_total">';
  443. // Rank
  444. print '<td></td>';
  445. // Product ref
  446. print '<td class="liste_total"></td>';
  447. // Product label
  448. print '<td class="liste_total"></td>';
  449. // Minimum buying price
  450. print '<td class="liste_total right">';
  451. print $langs->trans("TotalBuyingPriceMinShort");
  452. print '</td>';
  453. print '<td class="liste_total right">';
  454. if ($atleastonenotdefined) {
  455. print $langs->trans("Unknown").' ('.$langs->trans("SomeSubProductHaveNoPrices").')';
  456. }
  457. print ($atleastonenotdefined ? '' : price($total, '', '', 0, 0, -1, $conf->currency));
  458. print '</td>';
  459. // Minimum selling price
  460. print '<td class="liste_total right">';
  461. print $langs->trans("TotalSellingPriceMinShort");
  462. print '</td>';
  463. print '<td class="liste_total right">';
  464. if ($atleastonenotdefined) {
  465. print $langs->trans("Unknown").' ('.$langs->trans("SomeSubProductHaveNoPrices").')';
  466. }
  467. print ($atleastonenotdefined ? '' : price($totalsell, '', '', 0, 0, -1, $conf->currency));
  468. print '</td>';
  469. // Stock
  470. if (isModEnabled('stock')) {
  471. print '<td class="liste_total right">&nbsp;</td>';
  472. }
  473. print '<td></td>';
  474. print '<td class="center">';
  475. if ($user->hasRight('produit', 'creer') || $user->hasRight('service', 'creer')) {
  476. print '<input type="submit" class="button button-save" value="'.$langs->trans("Save").'">';
  477. }
  478. print '</td>';
  479. print '<td></td>';
  480. print '</tr>'."\n";
  481. } else {
  482. $colspan = 10;
  483. if (isModEnabled('stock')) {
  484. $colspan++;
  485. }
  486. print '<tr class="oddeven">';
  487. print '<td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("None").'</span></td>';
  488. print '</tr>';
  489. }
  490. print '</table>';
  491. /*if($user->rights->produit->creer || $user->hasRight('service', 'creer')) {
  492. print '<input type="submit" class="button button-save" value="'.$langs->trans("Save").'">';
  493. }*/
  494. print '</form>';
  495. print '</div>';
  496. // Form with product to add
  497. if ((empty($action) || $action == 'view' || $action == 'edit' || $action == 'search' || $action == 're-edit') && ($user->hasRight('produit', 'creer') || $user->hasRight('service', 'creer'))) {
  498. print '<br>';
  499. $rowspan = 1;
  500. if (isModEnabled('categorie')) {
  501. $rowspan++;
  502. }
  503. print load_fiche_titre($langs->trans("ProductToAddSearch"), '', '');
  504. print '<form action="'.DOL_URL_ROOT.'/product/composition/card.php?id='.$id.'" method="POST">';
  505. print '<input type="hidden" name="action" value="search">';
  506. print '<input type="hidden" name="id" value="'.$id.'">';
  507. print '<div class="inline-block">';
  508. print '<input type="hidden" name="token" value="'.newToken().'">';
  509. print $langs->trans("KeywordFilter").': ';
  510. print '<input type="text" name="key" value="'.$key.'"> &nbsp; ';
  511. print '</div>';
  512. if (isModEnabled('categorie')) {
  513. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  514. print '<div class="inline-block">'.$langs->trans("CategoryFilter").': ';
  515. print $form->select_all_categories(Categorie::TYPE_PRODUCT, $parent, 'parent').' &nbsp; </div>';
  516. print ajax_combobox('parent');
  517. }
  518. print '<div class="inline-block">';
  519. print '<input type="submit" class="button small" value="'.$langs->trans("Search").'">';
  520. print '</div>';
  521. print '</form>';
  522. }
  523. // List of products
  524. if ($action == 'search') {
  525. print '<br>';
  526. print '<form action="'.DOL_URL_ROOT.'/product/composition/card.php?id='.$id.'" method="post">';
  527. print '<input type="hidden" name="token" value="'.newToken().'">';
  528. print '<input type="hidden" name="action" value="add_prod">';
  529. print '<input type="hidden" name="id" value="'.$id.'">';
  530. print '<table class="noborder centpercent">';
  531. print '<tr class="liste_titre">';
  532. print '<th class="liste_titre">'.$langs->trans("ComposedProduct").'</td>';
  533. print '<th class="liste_titre">'.$langs->trans("Label").'</td>';
  534. //print '<th class="liste_titre center">'.$langs->trans("IsInPackage").'</td>';
  535. print '<th class="liste_titre right">'.$langs->trans("Qty").'</td>';
  536. print '<th class="center">'.$langs->trans('ComposedProductIncDecStock').'</th>';
  537. print '</tr>';
  538. if ($resql) {
  539. $num = $db->num_rows($resql);
  540. $i = 0;
  541. if ($num == 0) {
  542. print '<tr><td colspan="4">'.$langs->trans("NoMatchFound").'</td></tr>';
  543. }
  544. $MAX = 100;
  545. while ($i < min($num, $MAX)) {
  546. $objp = $db->fetch_object($resql);
  547. if ($objp->rowid != $id) {
  548. // check if a product is not already a parent product of this one
  549. $prod_arbo = new Product($db);
  550. $prod_arbo->id = $objp->rowid;
  551. // This type is not supported (not required to have virtual products working).
  552. if (getDolGlobalString('PRODUCT_USE_DEPRECATED_ASSEMBLY_AND_STOCK_KIT_TYPE')) {
  553. if ($prod_arbo->type == 2 || $prod_arbo->type == 3) {
  554. $is_pere = 0;
  555. $prod_arbo->get_sousproduits_arbo();
  556. // associations sousproduits
  557. $prods_arbo = $prod_arbo->get_arbo_each_prod();
  558. if (count($prods_arbo) > 0) {
  559. foreach ($prods_arbo as $key => $value) {
  560. if ($value[1] == $id) {
  561. $is_pere = 1;
  562. }
  563. }
  564. }
  565. if ($is_pere == 1) {
  566. $i++;
  567. continue;
  568. }
  569. }
  570. }
  571. print "\n";
  572. print '<tr class="oddeven">';
  573. $productstatic->id = $objp->rowid;
  574. $productstatic->ref = $objp->ref;
  575. $productstatic->label = $objp->label;
  576. $productstatic->type = $objp->type;
  577. $productstatic->entity = $objp->entity;
  578. $productstatic->status = $objp->status;
  579. $productstatic->status_buy = $objp->status_buy;
  580. $productstatic->status_batch = $objp->tobatch;
  581. print '<td>'.$productstatic->getNomUrl(1, '', 24).'</td>';
  582. $labeltoshow = $objp->label;
  583. if (getDolGlobalInt('MAIN_MULTILANGS') && !empty($objp->labelm)) {
  584. $labeltoshow = $objp->labelm;
  585. }
  586. print '<td>'.$labeltoshow.'</td>';
  587. if ($object->is_sousproduit($id, $objp->rowid)) {
  588. //$addchecked = ' checked';
  589. $qty = $object->is_sousproduit_qty;
  590. $incdec = $object->is_sousproduit_incdec;
  591. } else {
  592. //$addchecked = '';
  593. $qty = 0;
  594. $incdec = 0;
  595. }
  596. // Contained into package
  597. /*print '<td class="center"><input type="hidden" name="prod_id_'.$i.'" value="'.$objp->rowid.'">';
  598. print '<input type="checkbox" '.$addchecked.'name="prod_id_chk'.$i.'" value="'.$objp->rowid.'"></td>';*/
  599. // Qty
  600. print '<td class="right"><input type="hidden" name="prod_id_'.$i.'" value="'.$objp->rowid.'"><input type="text" size="2" name="prod_qty_'.$i.'" value="'.($qty ? $qty : '').'"></td>';
  601. // Inc Dec
  602. print '<td class="center">';
  603. if ($qty) {
  604. print '<input type="checkbox" name="prod_incdec_'.$i.'" value="1" '.($incdec ? 'checked' : '').'>';
  605. } else {
  606. // TODO Hide field and show it when setting a qty
  607. print '<input type="checkbox" name="prod_incdec_'.$i.'" value="1" checked>';
  608. //print '<input type="checkbox" disabled name="prod_incdec_'.$i.'" value="1" checked>';
  609. }
  610. print '</td>';
  611. print '</tr>';
  612. }
  613. $i++;
  614. }
  615. if ($num > $MAX) {
  616. print '<tr class="oddeven">';
  617. print '<td><span class="opacitymedium">'.$langs->trans("More").'...</span></td>';
  618. print '<td></td>';
  619. print '<td></td>';
  620. print '<td></td>';
  621. print '</tr>';
  622. }
  623. } else {
  624. dol_print_error($db);
  625. }
  626. print '</table>';
  627. print '<input type="hidden" name="max_prod" value="'.$i.'">';
  628. if ($num > 0) {
  629. print '<div class="center">';
  630. print '<input type="submit" class="button button-save" name="save" value="'.$langs->trans("Add").'/'.$langs->trans("Update").'">';
  631. print '<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
  632. print '</div>';
  633. }
  634. print '</form>';
  635. }
  636. }
  637. }
  638. // End of page
  639. llxFooter();
  640. $db->close();