card.php 26 KB

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