list.php 80 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927
  1. <?php
  2. /* Copyright (C) 2001-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2019 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2012-2016 Marcos García <marcosgdf@gmail.com>
  6. * Copyright (C) 2013-2019 Juanjo Menent <jmenent@2byte.es>
  7. * Copyright (C) 2013-2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
  8. * Copyright (C) 2013 Jean Heimburger <jean@tiaris.info>
  9. * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
  10. * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
  11. * Copyright (C) 2013 Adolfo segura <adolfo.segura@gmail.com>
  12. * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
  13. * Copyright (C) 2016 Ferran Marcet <fmarcet@2byte.es>
  14. * Copyright (C) 2020-2021 Open-DSI <support@open-dsi.fr>
  15. *
  16. * This program is free software; you can redistribute it and/or modify
  17. * it under the terms of the GNU General Public License as published by
  18. * the Free Software Foundation; either version 3 of the License, or
  19. * (at your option) any later version.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU General Public License
  27. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  28. */
  29. /**
  30. * \file htdocs/product/list.php
  31. * \ingroup produit
  32. * \brief Page to list products and services
  33. */
  34. require '../main.inc.php';
  35. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  36. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
  37. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  38. require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
  39. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  40. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  41. require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
  42. if (!empty($conf->categorie->enabled)) {
  43. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  44. }
  45. // Load translation files required by the page
  46. $langs->loadLangs(array('products', 'stocks', 'suppliers', 'companies', 'margins'));
  47. if (!empty($conf->productbatch->enabled)) {
  48. $langs->load("productbatch");
  49. }
  50. $action = GETPOST('action', 'aZ09');
  51. $massaction = GETPOST('massaction', 'alpha');
  52. $show_files = GETPOST('show_files', 'int');
  53. $confirm = GETPOST('confirm', 'alpha');
  54. $toselect = GETPOST('toselect', 'array');
  55. $sall = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
  56. $search_id = GETPOST("search_id", 'alpha');
  57. $search_ref = GETPOST("search_ref", 'alpha');
  58. $search_ref_supplier = GETPOST("search_ref_supplier", 'alpha');
  59. $search_barcode = GETPOST("search_barcode", 'alpha');
  60. $search_label = GETPOST("search_label", 'alpha');
  61. $search_type = GETPOST("search_type", 'int');
  62. $search_vatrate = GETPOST("search_vatrate", 'alpha');
  63. $searchCategoryProductOperator = 0;
  64. if (GETPOSTISSET('formfilteraction')) {
  65. $searchCategoryProductOperator = GETPOST('search_category_product_operator', 'int');
  66. } elseif (!empty($conf->global->MAIN_SEARCH_CAT_OR_BY_DEFAULT)) {
  67. $searchCategoryProductOperator = $conf->global->MAIN_SEARCH_CAT_OR_BY_DEFAULT;
  68. }
  69. $searchCategoryProductList = GETPOST('search_category_product_list', 'array');
  70. $search_tosell = GETPOST("search_tosell", 'int');
  71. $search_tobuy = GETPOST("search_tobuy", 'int');
  72. $search_country = GETPOST("search_country", 'int');
  73. $search_state = GETPOST("state_id", 'int');
  74. $fourn_id = GETPOST("fourn_id", 'int');
  75. $catid = GETPOST('catid', 'int');
  76. $search_tobatch = GETPOST("search_tobatch", 'int');
  77. $search_accountancy_code_sell = GETPOST("search_accountancy_code_sell", 'alpha');
  78. $search_accountancy_code_sell_intra = GETPOST("search_accountancy_code_sell_intra", 'alpha');
  79. $search_accountancy_code_sell_export = GETPOST("search_accountancy_code_sell_export", 'alpha');
  80. $search_accountancy_code_buy = GETPOST("search_accountancy_code_buy", 'alpha');
  81. $search_accountancy_code_buy_intra = GETPOST("search_accountancy_code_buy_intra", 'alpha');
  82. $search_accountancy_code_buy_export = GETPOST("search_accountancy_code_buy_export", 'alpha');
  83. $search_finished = GETPOST("search_finished", 'int');
  84. $optioncss = GETPOST('optioncss', 'alpha');
  85. $type = GETPOST("type", "int");
  86. //Show/hide child products
  87. if (!empty($conf->variants->enabled) && !empty($conf->global->PRODUIT_ATTRIBUTES_HIDECHILD)) {
  88. $show_childproducts = GETPOST('search_show_childproducts');
  89. } else {
  90. $show_childproducts = '';
  91. }
  92. $diroutputmassaction = $conf->product->dir_output.'/temp/massgeneration/'.$user->id;
  93. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  94. $sortfield = GETPOST('sortfield', 'aZ09comma');
  95. $sortorder = GETPOST('sortorder', 'aZ09comma');
  96. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  97. if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
  98. $page = 0;
  99. } // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action
  100. $offset = $limit * $page;
  101. $pageprev = $page - 1;
  102. $pagenext = $page + 1;
  103. if (!$sortfield) {
  104. $sortfield = "p.ref";
  105. }
  106. if (!$sortorder) {
  107. $sortorder = "ASC";
  108. }
  109. // Initialize context for list
  110. $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'productservicelist';
  111. if ((string) $type == '1') {
  112. $contextpage = 'servicelist'; if ($search_type == '') {
  113. $search_type = '1';
  114. }
  115. }
  116. if ((string) $type == '0') {
  117. $contextpage = 'productlist'; if ($search_type == '') {
  118. $search_type = '0';
  119. }
  120. }
  121. // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array of hooks
  122. $object = new Product($db);
  123. $hookmanager->initHooks(array('productservicelist'));
  124. $extrafields = new ExtraFields($db);
  125. $form = new Form($db);
  126. $formcompany = new FormCompany($db);
  127. $formproduct = new FormProduct($db);
  128. // fetch optionals attributes and labels
  129. $extrafields->fetch_name_optionals_label($object->table_element);
  130. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  131. if (empty($action)) {
  132. $action = 'list';
  133. }
  134. // Get object canvas (By default, this is not defined, so standard usage of dolibarr)
  135. $canvas = GETPOST("canvas");
  136. $objcanvas = null;
  137. if (!empty($canvas)) {
  138. require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php';
  139. $objcanvas = new Canvas($db, $action);
  140. $objcanvas->getCanvas('product', 'list', $canvas);
  141. }
  142. // Define virtualdiffersfromphysical
  143. $virtualdiffersfromphysical = 0;
  144. if (!empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT)
  145. || !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER)
  146. || !empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE)
  147. || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION)
  148. || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE)
  149. || !empty($conf->mrp->enabled)) {
  150. $virtualdiffersfromphysical = 1; // According to increase/decrease stock options, virtual and physical stock may differs.
  151. }
  152. // List of fields to search into when doing a "search in all"
  153. $fieldstosearchall = array(
  154. 'p.ref'=>"Ref",
  155. 'pfp.ref_fourn'=>"RefSupplier",
  156. 'p.label'=>"ProductLabel",
  157. 'p.description'=>"Description",
  158. "p.note"=>"Note",
  159. );
  160. // multilang
  161. if (!empty($conf->global->MAIN_MULTILANGS)) {
  162. $fieldstosearchall['pl.label'] = 'ProductLabelTranslated';
  163. $fieldstosearchall['pl.description'] = 'ProductDescriptionTranslated';
  164. $fieldstosearchall['pl.note'] = 'ProductNoteTranslated';
  165. }
  166. if (!empty($conf->barcode->enabled)) {
  167. $fieldstosearchall['p.barcode'] = 'Gencod';
  168. $fieldstosearchall['pfp.barcode'] = 'GencodBuyPrice';
  169. }
  170. // Personalized search criterias. Example: $conf->global->PRODUCT_QUICKSEARCH_ON_FIELDS = 'p.ref=ProductRef;p.label=ProductLabel;p.description=Description;p.note=Note;'
  171. if (!empty($conf->global->PRODUCT_QUICKSEARCH_ON_FIELDS)) {
  172. $fieldstosearchall = dolExplodeIntoArray($conf->global->PRODUCT_QUICKSEARCH_ON_FIELDS);
  173. }
  174. if (empty($conf->global->PRODUIT_MULTIPRICES)) {
  175. $titlesellprice = $langs->trans("SellingPrice");
  176. if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
  177. $titlesellprice = $form->textwithpicto($langs->trans("SellingPrice"), $langs->trans("DefaultPriceRealPriceMayDependOnCustomer"));
  178. }
  179. }
  180. $isInEEC = isInEEC($mysoc);
  181. $alias_product_perentity = empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED) ? "p" : "ppe";
  182. // Definition of array of fields for columns
  183. $arrayfields = array(
  184. 'p.rowid'=>array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-2, 'noteditable'=>1, 'notnull'=> 1, 'index'=>1, 'position'=>1, 'comment'=>'Id', 'css'=>'left'),
  185. 'p.ref'=>array('label'=>"Ref", 'checked'=>1, 'position'=>10),
  186. //'pfp.ref_fourn'=>array('label'=>$langs->trans("RefSupplier"), 'checked'=>1, 'enabled'=>(! empty($conf->barcode->enabled))),
  187. 'thumbnail'=>array('label'=>'Photo', 'checked'=>0, 'position'=>10),
  188. 'p.label'=>array('label'=>"Label", 'checked'=>1, 'position'=>10),
  189. 'p.fk_product_type'=>array('label'=>"Type", 'checked'=>0, 'enabled'=>(!empty($conf->product->enabled) && !empty($conf->service->enabled)), 'position'=>11),
  190. 'p.barcode'=>array('label'=>"Gencod", 'checked'=>1, 'enabled'=>(!empty($conf->barcode->enabled)), 'position'=>12),
  191. 'p.duration'=>array('label'=>"Duration", 'checked'=>($contextpage != 'productlist'), 'enabled'=>(!empty($conf->service->enabled) && (string) $type == '1'), 'position'=>13),
  192. 'p.finished'=>array('label'=>"Nature", 'checked'=>0, 'enabled'=>(!empty($conf->product->enabled) && $type != '1'), 'position'=>19),
  193. 'p.weight'=>array('label'=>'Weight', 'checked'=>0, 'enabled'=>(!empty($conf->product->enabled) && $type != '1'), 'position'=>20),
  194. 'p.weight_units'=>array('label'=>'WeightUnits', 'checked'=>0, 'enabled'=>(!empty($conf->product->enabled) && $type != '1'), 'position'=>21),
  195. 'p.length'=>array('label'=>'Length', 'checked'=>0, 'enabled'=>(!empty($conf->product->enabled) && empty($conf->global->PRODUCT_DISABLE_SIZE) && $type != '1'), 'position'=>22),
  196. 'p.length_units'=>array('label'=>'LengthUnits', 'checked'=>0, 'enabled'=>(!empty($conf->product->enabled) && empty($conf->global->PRODUCT_DISABLE_SIZE) && $type != '1'), 'position'=>23),
  197. 'p.width'=>array('label'=>'Width', 'checked'=>0, 'enabled'=>(!empty($conf->product->enabled) && empty($conf->global->PRODUCT_DISABLE_SIZE) && $type != '1'), 'position'=>24),
  198. 'p.width_units'=>array('label'=>'WidthUnits', 'checked'=>0, 'enabled'=>(!empty($conf->product->enabled) && empty($conf->global->PRODUCT_DISABLE_SIZE) && $type != '1'), 'position'=>25),
  199. 'p.height'=>array('label'=>'Height', 'checked'=>0, 'enabled'=>(!empty($conf->product->enabled) && empty($conf->global->PRODUCT_DISABLE_SIZE) && $type != '1'), 'position'=>26),
  200. 'p.height_units'=>array('label'=>'HeightUnits', 'checked'=>0, 'enabled'=>(!empty($conf->product->enabled) && empty($conf->global->PRODUCT_DISABLE_SIZE) && $type != '1'), 'position'=>27),
  201. 'p.surface'=>array('label'=>'Surface', 'checked'=>0, 'enabled'=>(!empty($conf->product->enabled) && empty($conf->global->PRODUCT_DISABLE_SURFACE) && $type != '1'), 'position'=>28),
  202. 'p.surface_units'=>array('label'=>'SurfaceUnits', 'checked'=>0, 'enabled'=>(!empty($conf->product->enabled) && empty($conf->global->PRODUCT_DISABLE_SURFACE) && $type != '1'), 'position'=>29),
  203. 'p.volume'=>array('label'=>'Volume', 'checked'=>0, 'enabled'=>(!empty($conf->product->enabled) && empty($conf->global->PRODUCT_DISABLE_VOLUME) && $type != '1'), 'position'=>30),
  204. 'p.volume_units'=>array('label'=>'VolumeUnits', 'checked'=>0, 'enabled'=>(!empty($conf->product->enabled) && empty($conf->global->PRODUCT_DISABLE_VOLUME) && $type != '1'), 'position'=>31),
  205. 'cu.label'=>array('label'=>"DefaultUnitToShow", 'checked'=>0, 'enabled'=>(!empty($conf->product->enabled) && !empty($conf->global->PRODUCT_USE_UNITS)), 'position'=>32),
  206. 'p.sellprice'=>array('label'=>"SellingPrice", 'checked'=>1, 'enabled'=>empty($conf->global->PRODUIT_MULTIPRICES), 'position'=>40),
  207. 'p.tva_tx'=>array('label'=>"VATRate", 'checked'=>0, 'enabled'=>empty($conf->global->PRODUIT_MULTIPRICES), 'position'=>41),
  208. 'p.minbuyprice'=>array('label'=>"BuyingPriceMinShort", 'checked'=>1, 'enabled'=>(!empty($user->rights->fournisseur->lire)), 'position'=>42),
  209. 'p.numbuyprice'=>array('label'=>"BuyingPriceNumShort", 'checked'=>0, 'enabled'=>(!empty($user->rights->fournisseur->lire)), 'position'=>43),
  210. 'p.pmp'=>array('label'=>"PMPValueShort", 'checked'=>0, 'enabled'=>(!empty($user->rights->fournisseur->lire)), 'position'=>44),
  211. 'p.cost_price'=>array('label'=>"CostPrice", 'checked'=>0, 'enabled'=>(!empty($user->rights->fournisseur->lire)), 'position'=>45),
  212. 'p.seuil_stock_alerte'=>array('label'=>"StockLimit", 'checked'=>0, 'enabled'=>(!empty($conf->stock->enabled) && $user->rights->stock->lire && $contextpage != 'service'), 'position'=>50),
  213. 'p.desiredstock'=>array('label'=>"DesiredStock", 'checked'=>1, 'enabled'=>(!empty($conf->stock->enabled) && $user->rights->stock->lire && $contextpage != 'service'), 'position'=>51),
  214. 'p.stock'=>array('label'=>"PhysicalStock", 'checked'=>1, 'enabled'=>(!empty($conf->stock->enabled) && $user->rights->stock->lire && $contextpage != 'service'), 'position'=>52),
  215. 'stock_virtual'=>array('label'=>"VirtualStock", 'checked'=>1, 'enabled'=>(!empty($conf->stock->enabled) && $user->rights->stock->lire && $contextpage != 'service' && $virtualdiffersfromphysical), 'position'=>53),
  216. 'p.tobatch'=>array('label'=>"ManageLotSerial", 'checked'=>0, 'enabled'=>(!empty($conf->productbatch->enabled)), 'position'=>60),
  217. 'p.fk_country'=>array('label'=>"Country", 'checked'=>0, 'position'=>100),
  218. 'p.fk_state'=>array('label'=>"State", 'checked'=>0, 'position'=>101),
  219. $alias_product_perentity . '.accountancy_code_sell'=>array('label'=>"ProductAccountancySellCode", 'checked'=>0, 'position'=>400),
  220. $alias_product_perentity . '.accountancy_code_sell_intra'=>array('label'=>"ProductAccountancySellIntraCode", 'checked'=>0, 'enabled'=>$isInEEC, 'position'=>401),
  221. $alias_product_perentity . '.accountancy_code_sell_export'=>array('label'=>"ProductAccountancySellExportCode", 'checked'=>0, 'position'=>402),
  222. $alias_product_perentity . '.accountancy_code_buy'=>array('label'=>"ProductAccountancyBuyCode", 'checked'=>0, 'position'=>403),
  223. $alias_product_perentity . '.accountancy_code_buy_intra'=>array('label'=>"ProductAccountancyBuyIntraCode", 'checked'=>0, 'enabled'=>$isInEEC, 'position'=>404),
  224. $alias_product_perentity . '.accountancy_code_buy_export'=>array('label'=>"ProductAccountancyBuyExportCode", 'checked'=>0, 'position'=>405),
  225. 'p.datec'=>array('label'=>"DateCreation", 'checked'=>0, 'position'=>500),
  226. 'p.tms'=>array('label'=>"DateModificationShort", 'checked'=>0, 'position'=>500),
  227. 'p.tosell'=>array('label'=>$langs->transnoentitiesnoconv("Status").' ('.$langs->transnoentitiesnoconv("Sell").')', 'checked'=>1, 'position'=>1000),
  228. 'p.tobuy'=>array('label'=>$langs->transnoentitiesnoconv("Status").' ('.$langs->transnoentitiesnoconv("Buy").')', 'checked'=>1, 'position'=>1000)
  229. );
  230. /*foreach ($object->fields as $key => $val) {
  231. // If $val['visible']==0, then we never show the field
  232. if (!empty($val['visible'])) {
  233. $visible = dol_eval($val['visible'], 1, 1, '1');
  234. $arrayfields['p.'.$key] = array(
  235. 'label'=>$val['label'],
  236. 'checked'=>(($visible < 0) ? 0 : 1),
  237. 'enabled'=>($visible != 3 && dol_eval($val['enabled'], 1, 1, '1')),
  238. 'position'=>$val['position']
  239. );
  240. }
  241. }*/
  242. // MultiPrices
  243. if (!empty($conf->global->PRODUIT_MULTIPRICES)) {
  244. for ($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++) {
  245. $keyforlabel = 'PRODUIT_MULTIPRICES_LABEL'.$i;
  246. if (!empty($conf->global->$keyforlabel)) {
  247. $labelp = $i.' - '.$langs->transnoentitiesnoconv($conf->global->$keyforlabel);
  248. } else {
  249. $labelp = $langs->transnoentitiesnoconv("SellingPrice")." ".$i;
  250. }
  251. $arrayfields['p.sellprice'.$i] = array('label'=>$labelp, 'checked'=>($i == 1 ? 1 : 0), 'enabled'=>$conf->global->PRODUIT_MULTIPRICES, 'position'=>floatval('40.'.sprintf('%03s', $i)));
  252. $arraypricelevel[$i] = array($i);
  253. }
  254. }
  255. //var_dump($arraypricelevel);
  256. // Extra fields
  257. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
  258. $object->fields = dol_sort_array($object->fields, 'position');
  259. $arrayfields = dol_sort_array($arrayfields, 'position');
  260. // Security check
  261. if ($search_type == '0') {
  262. $result = restrictedArea($user, 'produit', '', '', '', '', '', 0);
  263. } elseif ($search_type == '1') {
  264. $result = restrictedArea($user, 'service', '', '', '', '', '', 0);
  265. } else {
  266. $result = restrictedArea($user, 'produit|service', '', '', '', '', '', 0);
  267. }
  268. /*
  269. * Actions
  270. */
  271. if (GETPOST('cancel', 'alpha')) {
  272. $action = 'list'; $massaction = '';
  273. }
  274. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
  275. $massaction = '';
  276. }
  277. $parameters = array();
  278. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  279. if ($reshook < 0) {
  280. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  281. }
  282. $rightskey = 'produit';
  283. if ($type == Product::TYPE_SERVICE) {
  284. $rightskey = 'service';
  285. }
  286. if (empty($reshook)) {
  287. // Selection of new fields
  288. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  289. // Purge search criteria
  290. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
  291. $sall = "";
  292. $search_id = '';
  293. $search_ref = "";
  294. $search_ref_supplier = "";
  295. $search_label = "";
  296. $search_barcode = "";
  297. $searchCategoryProductOperator = 0;
  298. $searchCategoryProductList = array();
  299. $search_tosell = "";
  300. $search_tobuy = "";
  301. $search_tobatch = '';
  302. $search_country = "";
  303. $search_state = "";
  304. $search_vatrate = "";
  305. $search_finished = '';
  306. //$search_type=''; // There is 2 types of list: a list of product and a list of services. No list with both. So when we clear search criteria, we must keep the filter on type.
  307. $show_childproducts = '';
  308. $search_accountancy_code_sell = '';
  309. $search_accountancy_code_sell_intra = '';
  310. $search_accountancy_code_sell_export = '';
  311. $search_accountancy_code_buy = '';
  312. $search_accountancy_code_buy_intra = '';
  313. $search_accountancy_code_buy_export = '';
  314. $search_array_options = array();
  315. }
  316. // Mass actions
  317. $objectclass = 'Product';
  318. if ((string) $search_type == '1') {
  319. $objectlabel = 'Services';
  320. }
  321. if ((string) $search_type == '0') {
  322. $objectlabel = 'Products';
  323. }
  324. $permissiontoread = $user->rights->{$rightskey}->lire;
  325. $permissiontodelete = $user->rights->{$rightskey}->supprimer;
  326. $permissiontoadd = $user->rights->{$rightskey}->creer;
  327. $uploaddir = $conf->product->dir_output;
  328. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  329. if (!$error && $massaction == 'switchonsalestatus' && $permissiontoadd) {
  330. $product = new Product($db);
  331. foreach ($toselect as $toselectid) {
  332. $result = $product->fetch($toselectid);
  333. if ($result > 0 && $product->id > 0) {
  334. $product->setStatut($product->status ? 0 : 1, null, 'product', 'PRODUCT_MODIFY', 'tosell');
  335. }
  336. }
  337. }
  338. if (!$error && $massaction == 'switchonpurchasestatus' && $permissiontoadd) {
  339. $product = new Product($db);
  340. foreach ($toselect as $toselectid) {
  341. $result = $product->fetch($toselectid);
  342. if ($result > 0 && $product->id > 0) {
  343. $product->setStatut($product->status_buy ? 0 : 1, null, 'product', 'PRODUCT_MODIFY', 'tobuy');
  344. }
  345. }
  346. }
  347. }
  348. /*
  349. * View
  350. */
  351. $title = $langs->trans("ProductsAndServices");
  352. if ($search_type != '' && $search_type != '-1') {
  353. if ($search_type == 1) {
  354. $texte = $langs->trans("Services");
  355. } else {
  356. $texte = $langs->trans("Products");
  357. }
  358. } else {
  359. $texte = $langs->trans("ProductsAndServices");
  360. }
  361. $sql = 'SELECT DISTINCT p.rowid, p.ref, p.label, p.fk_product_type, p.barcode, p.price, p.tva_tx, p.price_ttc, p.price_base_type, p.entity,';
  362. $sql .= ' p.fk_product_type, p.duration, p.finished, p.tosell, p.tobuy, p.seuil_stock_alerte, p.desiredstock,';
  363. $sql .= ' p.tobatch,';
  364. if (empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
  365. $sql .= " p.accountancy_code_sell, p.accountancy_code_sell_intra, p.accountancy_code_sell_export, p.accountancy_code_buy, p.accountancy_code_buy_intra, p.accountancy_code_buy_export,";
  366. } else {
  367. $sql .= " ppe.accountancy_code_sell, ppe.accountancy_code_sell_intra, ppe.accountancy_code_sell_export, ppe.accountancy_code_buy, ppe.accountancy_code_buy_intra, ppe.accountancy_code_buy_export,";
  368. }
  369. $sql .= ' p.datec as date_creation, p.tms as date_update, p.pmp, p.stock, p.cost_price,';
  370. $sql .= ' p.weight, p.weight_units, p.length, p.length_units, p.width, p.width_units, p.height, p.height_units, p.surface, p.surface_units, p.volume, p.volume_units, fk_country, fk_state,';
  371. if (!empty($conf->global->PRODUCT_USE_UNITS)) {
  372. $sql .= ' p.fk_unit, cu.label as cu_label,';
  373. }
  374. $sql .= ' MIN(pfp.unitprice) as minsellprice';
  375. if (!empty($conf->variants->enabled) && (!empty($conf->global->PRODUIT_ATTRIBUTES_HIDECHILD) && !$show_childproducts)) {
  376. $sql .= ', pac.rowid prod_comb_id';
  377. }
  378. // Add fields from extrafields
  379. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  380. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  381. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
  382. }
  383. }
  384. // Add fields from hooks
  385. $parameters = array();
  386. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  387. $sql .= $hookmanager->resPrint;
  388. $sql .= ' FROM '.MAIN_DB_PREFIX.'product as p';
  389. if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
  390. $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_perentity as ppe ON ppe.fk_product = p.rowid AND ppe.entity = " . ((int) $conf->entity);
  391. }
  392. if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
  393. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_extrafields as ef on (p.rowid = ef.fk_object)";
  394. }
  395. if (!empty($searchCategoryProductList) || !empty($catid)) {
  396. $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_product as cp ON p.rowid = cp.fk_product"; // We'll need this table joined to the select in order to filter by categ
  397. }
  398. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON p.rowid = pfp.fk_product";
  399. // multilang
  400. if (!empty($conf->global->MAIN_MULTILANGS)) {
  401. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_lang as pl ON pl.fk_product = p.rowid AND pl.lang = '".$db->escape($langs->getDefaultLang())."'";
  402. }
  403. if (!empty($conf->variants->enabled) && (!empty($conf->global->PRODUIT_ATTRIBUTES_HIDECHILD) && !$show_childproducts)) {
  404. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_attribute_combination pac ON pac.fk_product_child = p.rowid";
  405. }
  406. if (!empty($conf->global->PRODUCT_USE_UNITS)) {
  407. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_units cu ON cu.rowid = p.fk_unit";
  408. }
  409. $sql .= ' WHERE p.entity IN ('.getEntity('product').')';
  410. if ($sall) {
  411. $sql .= natural_search(array_keys($fieldstosearchall), $sall);
  412. }
  413. // if the type is not 1, we show all products (type = 0,2,3)
  414. if (dol_strlen($search_type) && $search_type != '-1') {
  415. if ($search_type == 1) {
  416. $sql .= " AND p.fk_product_type = 1";
  417. } else {
  418. $sql .= " AND p.fk_product_type <> 1";
  419. }
  420. }
  421. if (!empty($conf->variants->enabled) && (!empty($conf->global->PRODUIT_ATTRIBUTES_HIDECHILD) && !$show_childproducts)) {
  422. $sql .= " AND pac.rowid IS NULL";
  423. }
  424. if ($search_id) {
  425. $sql .= natural_search('p.rowid', $search_id, 1);
  426. }
  427. if ($search_ref) {
  428. $sql .= natural_search('p.ref', $search_ref);
  429. }
  430. if ($search_label) {
  431. $sql .= natural_search('p.label', $search_label);
  432. }
  433. if ($search_barcode) {
  434. $sql .= natural_search('p.barcode', $search_barcode);
  435. }
  436. if (isset($search_tosell) && dol_strlen($search_tosell) > 0 && $search_tosell != -1) {
  437. $sql .= " AND p.tosell = ".((int) $search_tosell);
  438. }
  439. if (isset($search_tobuy) && dol_strlen($search_tobuy) > 0 && $search_tobuy != -1) {
  440. $sql .= " AND p.tobuy = ".((int) $search_tobuy);
  441. }
  442. if (isset($search_tobatch) && dol_strlen($search_tobatch) > 0 && $search_tobatch != -1) {
  443. $sql .= " AND p.tobatch = ".((int) $search_tobatch);
  444. }
  445. if ($search_vatrate) {
  446. $sql .= natural_search('p.tva_tx', $search_vatrate, 1);
  447. }
  448. if (dol_strlen($canvas) > 0) {
  449. $sql .= " AND p.canvas = '".$db->escape($canvas)."'";
  450. }
  451. if ($catid > 0) {
  452. $sql .= " AND cp.fk_categorie = ".((int) $catid);
  453. }
  454. if ($catid == -2) {
  455. $sql .= " AND cp.fk_categorie IS NULL";
  456. }
  457. $searchCategoryProductSqlList = array();
  458. if ($searchCategoryProductOperator == 1) {
  459. foreach ($searchCategoryProductList as $searchCategoryProduct) {
  460. if (intval($searchCategoryProduct) == -2) {
  461. $searchCategoryProductSqlList[] = "cp.fk_categorie IS NULL";
  462. } elseif (intval($searchCategoryProduct) > 0) {
  463. $searchCategoryProductSqlList[] = "cp.fk_categorie = ".$db->escape($searchCategoryProduct);
  464. }
  465. }
  466. if (!empty($searchCategoryProductSqlList)) {
  467. $sql .= " AND (".implode(' OR ', $searchCategoryProductSqlList).")";
  468. }
  469. } else {
  470. foreach ($searchCategoryProductList as $searchCategoryProduct) {
  471. if (intval($searchCategoryProduct) == -2) {
  472. $searchCategoryProductSqlList[] = "cp.fk_categorie IS NULL";
  473. } elseif (intval($searchCategoryProduct) > 0) {
  474. $searchCategoryProductSqlList[] = "p.rowid IN (SELECT fk_product FROM ".MAIN_DB_PREFIX."categorie_product WHERE fk_categorie = ".((int) $searchCategoryProduct).")";
  475. }
  476. }
  477. if (!empty($searchCategoryProductSqlList)) {
  478. $sql .= " AND (".implode(' AND ', $searchCategoryProductSqlList).")";
  479. }
  480. }
  481. if ($fourn_id > 0) {
  482. $sql .= " AND pfp.fk_soc = ".((int) $fourn_id);
  483. }
  484. if ($search_country) {
  485. $sql .= " AND p.fk_country = ".((int) $search_country);
  486. }
  487. if ($search_state) {
  488. $sql .= " AND p.fk_state = ".((int) $search_state);
  489. }
  490. if ($search_finished >= 0 && $search_finished !== '') {
  491. $sql .= " AND p.finished = ".((int) $search_finished);
  492. }
  493. if ($search_accountancy_code_sell) {
  494. $sql .= natural_search($alias_product_perentity . '.accountancy_code_sell', $search_accountancy_code_sell);
  495. }
  496. if ($search_accountancy_code_sell_intra) {
  497. $sql .= natural_search($alias_product_perentity . '.accountancy_code_sell_intra', $search_accountancy_code_sell_intra);
  498. }
  499. if ($search_accountancy_code_sell_export) {
  500. $sql .= natural_search($alias_product_perentity . '.accountancy_code_sell_export', $search_accountancy_code_sell_export);
  501. }
  502. if ($search_accountancy_code_buy) {
  503. $sql .= natural_search($alias_product_perentity . '.accountancy_code_buy', $search_accountancy_code_buy);
  504. }
  505. if ($search_accountancy_code_buy_intra) {
  506. $sql .= natural_search($alias_product_perentity . '.accountancy_code_buy_intra', $search_accountancy_code_buy_intra);
  507. }
  508. if ($search_accountancy_code_buy_export) {
  509. $sql .= natural_search($alias_product_perentity . '.accountancy_code_buy_export', $search_accountancy_code_buy_export);
  510. }
  511. // Add where from extra fields
  512. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  513. // Add where from hooks
  514. $parameters = array();
  515. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  516. $sql .= $hookmanager->resPrint;
  517. $sql .= " GROUP BY p.rowid, p.ref, p.label, p.barcode, p.price, p.tva_tx, p.price_ttc, p.price_base_type,";
  518. $sql .= " p.fk_product_type, p.duration, p.finished, p.tosell, p.tobuy, p.seuil_stock_alerte, p.desiredstock,";
  519. $sql .= ' p.datec, p.tms, p.entity, p.tobatch, p.pmp, p.cost_price, p.stock,';
  520. if (empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
  521. $sql .= " p.accountancy_code_sell, p.accountancy_code_sell_intra, p.accountancy_code_sell_export, p.accountancy_code_buy, p.accountancy_code_buy_intra, p.accountancy_code_buy_export,";
  522. } else {
  523. $sql .= " ppe.accountancy_code_sell, ppe.accountancy_code_sell_intra, ppe.accountancy_code_sell_export, ppe.accountancy_code_buy, ppe.accountancy_code_buy_intra, ppe.accountancy_code_buy_export,";
  524. }
  525. $sql .= ' p.weight, p.weight_units, p.length, p.length_units, p.width, p.width_units, p.height, p.height_units, p.surface, p.surface_units, p.volume, p.volume_units, p.fk_country, p.fk_state';
  526. if (!empty($conf->global->PRODUCT_USE_UNITS)) {
  527. $sql .= ', p.fk_unit, cu.label';
  528. }
  529. if (!empty($conf->variants->enabled) && (!empty($conf->global->PRODUIT_ATTRIBUTES_HIDECHILD) && !$show_childproducts)) {
  530. $sql .= ', pac.rowid';
  531. }
  532. // Add fields from extrafields
  533. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  534. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  535. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key : '');
  536. }
  537. }
  538. // Add fields from hooks
  539. $parameters = array();
  540. $reshook = $hookmanager->executeHooks('printFieldSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  541. $sql .= $hookmanager->resPrint;
  542. //if (GETPOST("toolowstock")) $sql.= " HAVING SUM(s.reel) < p.seuil_stock_alerte"; // Not used yet
  543. $sql .= $db->order($sortfield, $sortorder);
  544. $nbtotalofrecords = '';
  545. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
  546. $result = $db->query($sql);
  547. $nbtotalofrecords = $db->num_rows($result);
  548. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
  549. $page = 0;
  550. $offset = 0;
  551. }
  552. }
  553. $sql .= $db->plimit($limit + 1, $offset);
  554. $resql = $db->query($sql);
  555. if ($resql) {
  556. $num = $db->num_rows($resql);
  557. $arrayofselected = is_array($toselect) ? $toselect : array();
  558. if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $sall) {
  559. $obj = $db->fetch_object($resql);
  560. $id = $obj->rowid;
  561. header("Location: ".DOL_URL_ROOT.'/product/card.php?id='.$id);
  562. exit;
  563. }
  564. $helpurl = '';
  565. if ($search_type != '') {
  566. if ($search_type == 0) {
  567. $helpurl = 'EN:Module_Products|FR:Module_Produits|ES:M&oacute;dulo_Productos';
  568. } elseif ($search_type == 1) {
  569. $helpurl = 'EN:Module_Services_En|FR:Module_Services|ES:M&oacute;dulo_Servicios';
  570. }
  571. }
  572. $paramsCat = '';
  573. foreach ($searchCategoryProductList as $searchCategoryProduct) {
  574. $paramsCat .= "&search_category_product_list[]=".urlencode($searchCategoryProduct);
  575. }
  576. //llxHeader('', $title, $helpurl, '', 0, 0, array(), array(), $paramsCat, 'classforhorizontalscrolloftabs');
  577. llxHeader('', $title, $helpurl, '', 0, 0, array(), array(), $paramsCat, '');
  578. // Displays product removal confirmation
  579. if (GETPOST('delprod')) {
  580. setEventMessages($langs->trans("ProductDeleted", GETPOST('delprod')), null, 'mesgs');
  581. }
  582. $param = '';
  583. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  584. $param .= '&contextpage='.urlencode($contextpage);
  585. }
  586. if ($limit > 0 && $limit != $conf->liste_limit) {
  587. $param .= '&limit='.urlencode($limit);
  588. }
  589. if ($sall) {
  590. $param .= "&sall=".urlencode($sall);
  591. }
  592. if ($searchCategoryProductOperator == 1) {
  593. $param .= "&search_category_product_operator=".urlencode($searchCategoryProductOperator);
  594. }
  595. foreach ($searchCategoryProductList as $searchCategoryProduct) {
  596. $param .= "&search_category_product_list[]=".urlencode($searchCategoryProduct);
  597. }
  598. if ($search_ref) {
  599. $param = "&search_ref=".urlencode($search_ref);
  600. }
  601. if ($search_ref_supplier) {
  602. $param = "&search_ref_supplier=".urlencode($search_ref_supplier);
  603. }
  604. if ($search_barcode) {
  605. $param .= ($search_barcode ? "&search_barcode=".urlencode($search_barcode) : "");
  606. }
  607. if ($search_label) {
  608. $param .= "&search_label=".urlencode($search_label);
  609. }
  610. if ($search_tosell != '') {
  611. $param .= "&search_tosell=".urlencode($search_tosell);
  612. }
  613. if ($search_tobuy != '') {
  614. $param .= "&search_tobuy=".urlencode($search_tobuy);
  615. }
  616. if ($search_tobatch) {
  617. $param = "&search_tobatch=".urlencode($search_tobatch);
  618. }
  619. if ($search_country != '') {
  620. $param .= "&search_country=".urlencode($search_country);
  621. }
  622. if ($search_state != '') {
  623. $param .= "&search_state=".urlencode($search_state);
  624. }
  625. if ($search_vatrate) {
  626. $param = "&search_vatrate=".urlencode($search_vatrate);
  627. }
  628. if ($fourn_id > 0) {
  629. $param .= "&fourn_id=".urlencode($fourn_id);
  630. }
  631. //if ($seach_categ) $param.=($search_categ?"&search_categ=".urlencode($search_categ):"");
  632. if ($show_childproducts) {
  633. $param .= ($show_childproducts ? "&search_show_childproducts=".urlencode($show_childproducts) : "");
  634. }
  635. if ($type != '') {
  636. $param .= '&type='.urlencode($type);
  637. }
  638. if ($search_type != '') {
  639. $param .= '&search_type='.urlencode($search_type);
  640. }
  641. if ($optioncss != '') {
  642. $param .= '&optioncss='.urlencode($optioncss);
  643. }
  644. if ($search_accountancy_code_sell) {
  645. $param = "&search_accountancy_code_sell=".urlencode($search_accountancy_code_sell);
  646. }
  647. if ($search_accountancy_code_sell_intra) {
  648. $param = "&search_accountancy_code_sell_intra=".urlencode($search_accountancy_code_sell_intra);
  649. }
  650. if ($search_accountancy_code_sell_export) {
  651. $param = "&search_accountancy_code_sell_export=".urlencode($search_accountancy_code_sell_export);
  652. }
  653. if ($search_accountancy_code_buy) {
  654. $param = "&search_accountancy_code_buy=".urlencode($search_accountancy_code_buy);
  655. }
  656. if ($search_accountancy_code_buy_intra) {
  657. $param = "&search_accountancy_code_buy_intra=".urlencode($search_accountancy_code_buy_intra);
  658. }
  659. if ($search_accountancy_code_buy_export) {
  660. $param = "&search_accountancy_code_buy_export=".urlencode($search_accountancy_code_buy_export);
  661. }
  662. if ($search_finished) {
  663. $param = "&search_finished=".urlencode($search_finished);
  664. }
  665. // Add $param from extra fields
  666. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  667. // List of mass actions available
  668. $arrayofmassactions = array(
  669. 'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
  670. 'edit_extrafields'=>img_picto('', 'edit', 'class="pictofixedwidth"').$langs->trans("ModifyValueExtrafields"),
  671. //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
  672. //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
  673. );
  674. if ($user->rights->{$rightskey}->supprimer) {
  675. $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
  676. }
  677. if ($user->rights->{$rightskey}->creer) {
  678. $arrayofmassactions['switchonsalestatus'] = img_picto('', 'stop-circle', 'class="pictofixedwidth"').$langs->trans("SwitchOnSaleStatus");
  679. $arrayofmassactions['switchonpurchasestatus'] = img_picto('', 'stop-circle', 'class="pictofixedwidth"').$langs->trans("SwitchOnPurchaseStatus");
  680. $arrayofmassactions['preaffecttag'] = img_picto('', 'category', 'class="pictofixedwidth"').$langs->trans("AffectTag");
  681. }
  682. if (in_array($massaction, array('presend', 'predelete','preaffecttag', 'edit_extrafields'))) {
  683. $arrayofmassactions = array();
  684. }
  685. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  686. $newcardbutton = '';
  687. if ($type === "") {
  688. $perm = ($user->rights->produit->creer || $user->rights->service->creer);
  689. } elseif ($type == Product::TYPE_SERVICE) {
  690. $perm = $user->rights->service->creer;
  691. } elseif ($type == Product::TYPE_PRODUCT) {
  692. $perm = $user->rights->produit->creer;
  693. }
  694. $oldtype = $type;
  695. $params = array();
  696. if ($type === "") {
  697. $params['forcenohideoftext'] = 1;
  698. }
  699. if ($type === "") {
  700. $newcardbutton .= dolGetButtonTitle($langs->trans('NewProduct'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/product/card.php?action=create&type=0', '', $perm, $params);
  701. $type = Product::TYPE_SERVICE;
  702. }
  703. $label = 'NewProduct';
  704. if ($type == Product::TYPE_SERVICE) {
  705. $label = 'NewService';
  706. }
  707. $newcardbutton .= dolGetButtonTitle($langs->trans($label), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/product/card.php?action=create&type='.$type, '', $perm, $params);
  708. $type = $oldtype;
  709. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post" name="formulaire">';
  710. if ($optioncss != '') {
  711. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  712. }
  713. print '<input type="hidden" name="token" value="'.newToken().'">';
  714. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  715. print '<input type="hidden" name="action" value="list">';
  716. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  717. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  718. //print '<input type="hidden" name="page" value="'.$page.'">';
  719. print '<input type="hidden" name="type" value="'.$type.'">';
  720. if (empty($arrayfields['p.fk_product_type']['checked'])) {
  721. print '<input type="hidden" name="search_type" value="'.dol_escape_htmltag($search_type).'">';
  722. }
  723. $picto = 'product';
  724. if ($type == 1) {
  725. $picto = 'service';
  726. }
  727. print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, $picto, 0, $newcardbutton, '', $limit, 0, 0, 1);
  728. $topicmail = "Information";
  729. $modelmail = "product";
  730. $objecttmp = new Product($db);
  731. $trackid = 'prod'.$object->id;
  732. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  733. if (!empty($catid)) {
  734. print "<div id='ways'>";
  735. $c = new Categorie($db);
  736. $ways = $c->print_all_ways(' &gt; ', 'product/list.php');
  737. print " &gt; ".$ways[0]."<br>\n";
  738. print "</div><br>";
  739. }
  740. if ($sall) {
  741. $setupstring = '';
  742. foreach ($fieldstosearchall as $key => $val) {
  743. $fieldstosearchall[$key] = $langs->trans($val);
  744. $setupstring .= $key."=".$val.";";
  745. }
  746. print '<!-- Search done like if PRODUCT_QUICKSEARCH_ON_FIELDS = '.$setupstring.' -->'."\n";
  747. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'</div>'."\n";
  748. }
  749. // Filter on categories
  750. $moreforfilter = '';
  751. if (!empty($conf->categorie->enabled) && $user->rights->categorie->lire) {
  752. $moreforfilter .= '<div class="divsearchfield">';
  753. $moreforfilter .= img_picto($langs->trans('Categories'), 'category', 'class="pictofixedwidth"');
  754. $categoriesProductArr = $form->select_all_categories(Categorie::TYPE_PRODUCT, '', '', 64, 0, 1);
  755. $categoriesProductArr[-2] = '- '.$langs->trans('NotCategorized').' -';
  756. $moreforfilter .= Form::multiselectarray('search_category_product_list', $categoriesProductArr, $searchCategoryProductList, 0, 0, 'minwidth300');
  757. $moreforfilter .= ' <input type="checkbox" class="valignmiddle" id="search_category_product_operator" name="search_category_product_operator" value="1"'.($searchCategoryProductOperator == 1 ? ' checked="checked"' : '').'/><label class="none valignmiddle" for="search_category_product_operator">'.$langs->trans('UseOrOperatorForCategories').'</label>';
  758. $moreforfilter .= '</div>';
  759. }
  760. //Show/hide child products. Hidden by default
  761. if (!empty($conf->variants->enabled) && !empty($conf->global->PRODUIT_ATTRIBUTES_HIDECHILD)) {
  762. $moreforfilter .= '<div class="divsearchfield">';
  763. $moreforfilter .= '<input type="checkbox" id="search_show_childproducts" name="search_show_childproducts"'.($show_childproducts ? 'checked="checked"' : '').'>';
  764. $moreforfilter .= ' <label for="search_show_childproducts">'.$langs->trans('ShowChildProducts').'</label>';
  765. $moreforfilter .= '</div>';
  766. }
  767. $parameters = array();
  768. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  769. if (empty($reshook)) {
  770. $moreforfilter .= $hookmanager->resPrint;
  771. } else {
  772. $moreforfilter = $hookmanager->resPrint;
  773. }
  774. if ($moreforfilter) {
  775. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  776. print $moreforfilter;
  777. print '</div>';
  778. }
  779. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  780. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  781. if ($massactionbutton) {
  782. $selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
  783. }
  784. print '<div class="div-table-responsive">';
  785. print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  786. // Lines with input filters
  787. print '<tr class="liste_titre_filter">';
  788. if (!empty($arrayfields['p.rowid']['checked'])) {
  789. print '<td class="liste_titre left">';
  790. print '<input class="flat" type="text" name="search_id" size="4" value="'.dol_escape_htmltag($search_id).'">';
  791. print '</td>';
  792. }
  793. if (!empty($arrayfields['p.ref']['checked'])) {
  794. print '<td class="liste_titre left">';
  795. print '<input class="flat" type="text" name="search_ref" size="8" value="'.dol_escape_htmltag($search_ref).'">';
  796. print '</td>';
  797. }
  798. if (!empty($arrayfields['pfp.ref_fourn']['checked'])) {
  799. print '<td class="liste_titre left">';
  800. print '<input class="flat" type="text" name="search_ref_supplier" size="8" value="'.dol_escape_htmltag($search_ref_supplier).'">';
  801. print '</td>';
  802. }
  803. // Thumbnail
  804. if (!empty($arrayfields['thumbnail']['checked'])) {
  805. print '<td class="liste_titre center">';
  806. print '</td>';
  807. }
  808. if (!empty($arrayfields['p.label']['checked'])) {
  809. print '<td class="liste_titre left">';
  810. print '<input class="flat" type="text" name="search_label" size="12" value="'.dol_escape_htmltag($search_label).'">';
  811. print '</td>';
  812. }
  813. // Type
  814. if (!empty($arrayfields['p.fk_product_type']['checked'])) {
  815. print '<td class="liste_titre center">';
  816. $array = array('-1'=>'&nbsp;', '0'=>$langs->trans('Product'), '1'=>$langs->trans('Service'));
  817. print $form->selectarray('search_type', $array, $search_type);
  818. print '</td>';
  819. }
  820. // Barcode
  821. if (!empty($arrayfields['p.barcode']['checked'])) {
  822. print '<td class="liste_titre">';
  823. print '<input class="flat" type="text" name="search_barcode" size="6" value="'.dol_escape_htmltag($search_barcode).'">';
  824. print '</td>';
  825. }
  826. // Duration
  827. if (!empty($arrayfields['p.duration']['checked'])) {
  828. print '<td class="liste_titre">';
  829. print '</td>';
  830. }
  831. // Finished
  832. if (!empty($arrayfields['p.finished']['checked'])) {
  833. print '<td class="liste_titre">';
  834. print $formproduct->selectProductNature('search_finished', $search_finished);
  835. print '</td>';
  836. }
  837. // Weight
  838. if (!empty($arrayfields['p.weight']['checked'])) {
  839. print '<td class="liste_titre">';
  840. print '</td>';
  841. }
  842. // Weight units
  843. if (!empty($arrayfields['p.weight_units']['checked'])) {
  844. print '<td class="liste_titre">';
  845. print '</td>';
  846. }
  847. // Length
  848. if (!empty($arrayfields['p.length']['checked'])) {
  849. print '<td class="liste_titre">';
  850. print '</td>';
  851. }
  852. // Length units
  853. if (!empty($arrayfields['p.length_units']['checked'])) {
  854. print '<td class="liste_titre">';
  855. print '</td>';
  856. }
  857. // Width
  858. if (!empty($arrayfields['p.width']['checked'])) {
  859. print '<td class="liste_titre">';
  860. print '</td>';
  861. }
  862. // Width units
  863. if (!empty($arrayfields['p.width_units']['checked'])) {
  864. print '<td class="liste_titre">';
  865. print '</td>';
  866. }
  867. // Height
  868. if (!empty($arrayfields['p.height']['checked'])) {
  869. print '<td class="liste_titre">';
  870. print '</td>';
  871. }
  872. // Height units
  873. if (!empty($arrayfields['p.height_units']['checked'])) {
  874. print '<td class="liste_titre">';
  875. print '</td>';
  876. }
  877. // Surface
  878. if (!empty($arrayfields['p.surface']['checked'])) {
  879. print '<td class="liste_titre">';
  880. print '</td>';
  881. }
  882. // Surface units
  883. if (!empty($arrayfields['p.surface_units']['checked'])) {
  884. print '<td class="liste_titre">';
  885. print '</td>';
  886. }
  887. // Volume
  888. if (!empty($arrayfields['p.volume']['checked'])) {
  889. print '<td class="liste_titre">';
  890. print '</td>';
  891. }
  892. // Volume units
  893. if (!empty($arrayfields['p.volume_units']['checked'])) {
  894. print '<td class="liste_titre">';
  895. print '</td>';
  896. }
  897. // Unit
  898. if (!empty($arrayfields['cu.label']['checked'])) {
  899. print '<td class="liste_titre">';
  900. print '</td>';
  901. }
  902. // Sell price
  903. if (!empty($arrayfields['p.sellprice']['checked'])) {
  904. print '<td class="liste_titre right">';
  905. print '</td>';
  906. }
  907. // Multiprice
  908. if (!empty($conf->global->PRODUIT_MULTIPRICES)) {
  909. foreach ($arraypricelevel as $key => $value) {
  910. if (!empty($arrayfields['p.sellprice'.$key]['checked'])) {
  911. print '<td class="liste_titre right">';
  912. print '</td>';
  913. }
  914. }
  915. }
  916. // Minimum buying Price
  917. if (!empty($arrayfields['p.minbuyprice']['checked'])) {
  918. print '<td class="liste_titre">';
  919. print '&nbsp;';
  920. print '</td>';
  921. }
  922. // Number buying Price
  923. if (!empty($arrayfields['p.numbuyprice']['checked'])) {
  924. print '<td class="liste_titre">';
  925. print '&nbsp;';
  926. print '</td>';
  927. }
  928. // Sell price
  929. if (!empty($arrayfields['p.tva_tx']['checked'])) {
  930. print '<td class="liste_titre right">';
  931. print '<input class="right flat maxwidth50" placeholder="%" type="text" name="search_vatrate" size="1" value="'.dol_escape_htmltag($search_vatrate).'">';
  932. print '</td>';
  933. }
  934. // WAP
  935. if (!empty($arrayfields['p.pmp']['checked'])) {
  936. print '<td class="liste_titre">';
  937. print '&nbsp;';
  938. print '</td>';
  939. }
  940. // cost_price
  941. if (!empty($arrayfields['p.cost_price']['checked'])) {
  942. print '<td class="liste_titre">';
  943. print '&nbsp;';
  944. print '</td>';
  945. }
  946. // Limit for alert
  947. if (!empty($arrayfields['p.seuil_stock_alerte']['checked'])) {
  948. print '<td class="liste_titre">';
  949. print '&nbsp;';
  950. print '</td>';
  951. }
  952. // Desired stock
  953. if (!empty($arrayfields['p.desiredstock']['checked'])) {
  954. print '<td class="liste_titre">';
  955. print '&nbsp;';
  956. print '</td>';
  957. }
  958. // Stock
  959. if (!empty($arrayfields['p.stock']['checked'])) {
  960. print '<td class="liste_titre">&nbsp;</td>';
  961. }
  962. // Stock
  963. if (!empty($arrayfields['stock_virtual']['checked'])) {
  964. print '<td class="liste_titre">&nbsp;</td>';
  965. }
  966. // To batch
  967. if (!empty($arrayfields['p.tobatch']['checked'])) {
  968. print '<td class="liste_titre center">';
  969. $statutarray = array(
  970. '-1' => '',
  971. '0' => $langs->trans("ProductStatusNotOnBatchShort"),
  972. '1' => $langs->trans("ProductStatusOnBatchShort"),
  973. '2' => $langs->trans("ProductStatusOnSerialShort")
  974. );
  975. print $form->selectarray('search_tobatch', $statutarray, $search_tobatch);
  976. print '</td>';
  977. }
  978. // Country
  979. if (!empty($arrayfields['p.fk_country']['checked'])) {
  980. print '<td class="liste_titre center">';
  981. print $form->select_country($search_country, 'search_country', '', 0);
  982. print '</td>';
  983. }
  984. // State
  985. if (!empty($arrayfields['p.fk_state']['checked'])) {
  986. print '<td class="liste_titre center">';
  987. print $formcompany->select_state($search_state, $search_country);
  988. print '</td>';
  989. }
  990. // Accountancy code sell
  991. if (!empty($arrayfields[$alias_product_perentity . '.accountancy_code_sell']['checked'])) {
  992. print '<td class="liste_titre"><input class="flat maxwidth75" type="text" name="search_accountancy_code_sell" value="'.dol_escape_htmltag($search_accountancy_code_sell).'"></td>';
  993. }
  994. if (!empty($arrayfields[$alias_product_perentity . '.accountancy_code_sell_intra']['checked'])) {
  995. print '<td class="liste_titre"><input class="flat maxwidth75" type="text" name="search_accountancy_code_sell_intra" value="'.dol_escape_htmltag($search_accountancy_code_sell_intra).'"></td>';
  996. }
  997. if (!empty($arrayfields[$alias_product_perentity . '.accountancy_code_sell_export']['checked'])) {
  998. print '<td class="liste_titre"><input class="flat maxwidth75" type="text" name="search_accountancy_code_sell_export" value="'.dol_escape_htmltag($search_accountancy_code_sell_export).'"></td>';
  999. }
  1000. // Accountancy code buy
  1001. if (!empty($arrayfields[$alias_product_perentity . '.accountancy_code_buy']['checked'])) {
  1002. print '<td class="liste_titre"><input class="flat maxwidth75" type="text" name="search_accountancy_code_buy" value="'.dol_escape_htmltag($search_accountancy_code_buy).'"></td>';
  1003. }
  1004. if (!empty($arrayfields[$alias_product_perentity . '.accountancy_code_buy_intra']['checked'])) {
  1005. print '<td class="liste_titre"><input class="flat maxwidth75" type="text" name="search_accountancy_code_buy_intra" value="'.dol_escape_htmltag($search_accountancy_code_buy_intra).'"></td>';
  1006. }
  1007. if (!empty($arrayfields[$alias_product_perentity . '.accountancy_code_buy_export']['checked'])) {
  1008. print '<td class="liste_titre"><input class="flat maxwidth75" type="text" name="search_accountancy_code_buy_export" value="'.dol_escape_htmltag($search_accountancy_code_buy_export).'"></td>';
  1009. }
  1010. // Extra fields
  1011. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  1012. // Fields from hook
  1013. $parameters = array('arrayfields'=>$arrayfields);
  1014. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  1015. print $hookmanager->resPrint;
  1016. // Date creation
  1017. if (!empty($arrayfields['p.datec']['checked'])) {
  1018. print '<td class="liste_titre">';
  1019. print '</td>';
  1020. }
  1021. // Date modification
  1022. if (!empty($arrayfields['p.tms']['checked'])) {
  1023. print '<td class="liste_titre">';
  1024. print '</td>';
  1025. }
  1026. if (!empty($arrayfields['p.tosell']['checked'])) {
  1027. print '<td class="liste_titre center">';
  1028. print $form->selectarray('search_tosell', array('0'=>$langs->trans('ProductStatusNotOnSellShort'), '1'=>$langs->trans('ProductStatusOnSellShort')), $search_tosell, 1);
  1029. print '</td >';
  1030. }
  1031. if (!empty($arrayfields['p.tobuy']['checked'])) {
  1032. print '<td class="liste_titre center">';
  1033. print $form->selectarray('search_tobuy', array('0'=>$langs->trans('ProductStatusNotOnBuyShort'), '1'=>$langs->trans('ProductStatusOnBuyShort')), $search_tobuy, 1);
  1034. print '</td>';
  1035. }
  1036. print '<td class="liste_titre center maxwidthsearch">';
  1037. $searchpicto = $form->showFilterButtons();
  1038. print $searchpicto;
  1039. print '</td>';
  1040. print '</tr>';
  1041. print '<tr class="liste_titre">';
  1042. if (!empty($arrayfields['p.rowid']['checked'])) {
  1043. print_liste_field_titre($arrayfields['p.rowid']['label'], $_SERVER["PHP_SELF"], "p.rowid", "", $param, "", $sortfield, $sortorder);
  1044. }
  1045. if (!empty($arrayfields['p.ref']['checked'])) {
  1046. print_liste_field_titre($arrayfields['p.ref']['label'], $_SERVER["PHP_SELF"], "p.ref", "", $param, "", $sortfield, $sortorder);
  1047. }
  1048. if (!empty($arrayfields['pfp.ref_fourn']['checked'])) {
  1049. print_liste_field_titre($arrayfields['pfp.ref_fourn']['label'], $_SERVER["PHP_SELF"], "pfp.ref_fourn", "", $param, "", $sortfield, $sortorder);
  1050. }
  1051. if (!empty($arrayfields['thumbnail']['checked'])) {
  1052. print_liste_field_titre($arrayfields['thumbnail']['label'], $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'center ');
  1053. }
  1054. if (!empty($arrayfields['p.label']['checked'])) {
  1055. print_liste_field_titre($arrayfields['p.label']['label'], $_SERVER["PHP_SELF"], "p.label", "", $param, "", $sortfield, $sortorder);
  1056. }
  1057. if (!empty($arrayfields['p.fk_product_type']['checked'])) {
  1058. print_liste_field_titre($arrayfields['p.fk_product_type']['label'], $_SERVER["PHP_SELF"], "p.fk_product_type", "", $param, "", $sortfield, $sortorder, 'center ');
  1059. }
  1060. if (!empty($arrayfields['p.barcode']['checked'])) {
  1061. print_liste_field_titre($arrayfields['p.barcode']['label'], $_SERVER["PHP_SELF"], "p.barcode", "", $param, "", $sortfield, $sortorder);
  1062. }
  1063. if (!empty($arrayfields['p.duration']['checked'])) {
  1064. print_liste_field_titre($arrayfields['p.duration']['label'], $_SERVER["PHP_SELF"], "p.duration", "", $param, '', $sortfield, $sortorder, 'center ');
  1065. }
  1066. if (!empty($arrayfields['p.finished']['checked'])) {
  1067. print_liste_field_titre($arrayfields['p.finished']['label'], $_SERVER["PHP_SELF"], "p.finished", "", $param, '', $sortfield, $sortorder, 'center ');
  1068. }
  1069. if (!empty($arrayfields['p.weight']['checked'])) {
  1070. print_liste_field_titre($arrayfields['p.weight']['label'], $_SERVER['PHP_SELF'], 'p.weight', '', $param, '', $sortfield, $sortorder, 'center ');
  1071. }
  1072. if (!empty($arrayfields['p.weight_units']['checked'])) {
  1073. print_liste_field_titre($arrayfields['p.weight_units']['label'], $_SERVER['PHP_SELF'], 'p.weight_units', '', $param, '', $sortfield, $sortorder, 'center ');
  1074. }
  1075. if (!empty($arrayfields['p.length']['checked'])) {
  1076. print_liste_field_titre($arrayfields['p.length']['label'], $_SERVER['PHP_SELF'], 'p.length', '', $param, '', $sortfield, $sortorder, 'center ');
  1077. }
  1078. if (!empty($arrayfields['p.length_units']['checked'])) {
  1079. print_liste_field_titre($arrayfields['p.length_units']['label'], $_SERVER['PHP_SELF'], 'p.length_units', '', $param, '', $sortfield, $sortorder, 'center ');
  1080. }
  1081. if (!empty($arrayfields['p.width']['checked'])) {
  1082. print_liste_field_titre($arrayfields['p.width']['label'], $_SERVER['PHP_SELF'], 'p.width', '', $param, '', $sortfield, $sortorder, 'center ');
  1083. }
  1084. if (!empty($arrayfields['p.width_units']['checked'])) {
  1085. print_liste_field_titre($arrayfields['p.width_units']['label'], $_SERVER['PHP_SELF'], 'p.width_units', '', $param, '', $sortfield, $sortorder, 'center ');
  1086. }
  1087. if (!empty($arrayfields['p.height']['checked'])) {
  1088. print_liste_field_titre($arrayfields['p.height']['label'], $_SERVER['PHP_SELF'], 'p.height', '', $param, '', $sortfield, $sortorder, 'center ');
  1089. }
  1090. if (!empty($arrayfields['p.height_units']['checked'])) {
  1091. print_liste_field_titre($arrayfields['p.height_units']['label'], $_SERVER['PHP_SELF'], 'p.height_units', '', $param, '', $sortfield, $sortorder, 'center ');
  1092. }
  1093. if (!empty($arrayfields['p.surface']['checked'])) {
  1094. print_liste_field_titre($arrayfields['p.surface']['label'], $_SERVER['PHP_SELF'], "p.surface", '', $param, '', $sortfield, $sortorder, 'center ');
  1095. }
  1096. if (!empty($arrayfields['p.surface_units']['checked'])) {
  1097. print_liste_field_titre($arrayfields['p.surface_units']['label'], $_SERVER['PHP_SELF'], 'p.surface_units', '', $param, '', $sortfield, $sortorder, 'center ');
  1098. }
  1099. if (!empty($arrayfields['p.volume']['checked'])) {
  1100. print_liste_field_titre($arrayfields['p.volume']['label'], $_SERVER['PHP_SELF'], 'p.volume', '', $param, '', $sortfield, $sortorder, 'center ');
  1101. }
  1102. if (!empty($arrayfields['p.volume_units']['checked'])) {
  1103. print_liste_field_titre($arrayfields['p.volume_units']['label'], $_SERVER['PHP_SELF'], 'p.volume_units', '', $param, '', $sortfield, $sortorder, 'center ');
  1104. }
  1105. if (!empty($arrayfields['cu.label']['checked'])) {
  1106. print_liste_field_titre($arrayfields['cu.label']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'center ');
  1107. }
  1108. if (!empty($arrayfields['p.sellprice']['checked'])) {
  1109. print_liste_field_titre($arrayfields['p.sellprice']['label'], $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'right ');
  1110. }
  1111. // Multiprices
  1112. if (!empty($conf->global->PRODUIT_MULTIPRICES)) {
  1113. foreach ($arraypricelevel as $key => $value) {
  1114. if (!empty($arrayfields['p.sellprice'.$key]['checked'])) {
  1115. print_liste_field_titre($arrayfields['p.sellprice'.$key]['label'], $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'right ');
  1116. }
  1117. }
  1118. }
  1119. if (!empty($arrayfields['p.minbuyprice']['checked'])) {
  1120. print_liste_field_titre($arrayfields['p.minbuyprice']['label'], $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'right ');
  1121. }
  1122. if (!empty($arrayfields['p.numbuyprice']['checked'])) {
  1123. print_liste_field_titre($arrayfields['p.numbuyprice']['label'], $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'right ');
  1124. }
  1125. if (!empty($arrayfields['p.tva_tx']['checked'])) {
  1126. print_liste_field_titre($arrayfields['p.tva_tx']['label'], $_SERVER["PHP_SELF"], 'p.tva_tx', "", $param, '', $sortfield, $sortorder, 'right ');
  1127. }
  1128. if (!empty($arrayfields['p.pmp']['checked'])) {
  1129. print_liste_field_titre($arrayfields['p.pmp']['label'], $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'right ');
  1130. }
  1131. if (!empty($arrayfields['p.cost_price']['checked'])) {
  1132. print_liste_field_titre($arrayfields['p.cost_price']['label'], $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'right ');
  1133. }
  1134. if (!empty($arrayfields['p.seuil_stock_alerte']['checked'])) {
  1135. print_liste_field_titre($arrayfields['p.seuil_stock_alerte']['label'], $_SERVER["PHP_SELF"], "p.seuil_stock_alerte", "", $param, '', $sortfield, $sortorder, 'right ');
  1136. }
  1137. if (!empty($arrayfields['p.desiredstock']['checked'])) {
  1138. print_liste_field_titre($arrayfields['p.desiredstock']['label'], $_SERVER["PHP_SELF"], "p.desiredstock", "", $param, '', $sortfield, $sortorder, 'right ');
  1139. }
  1140. if (!empty($arrayfields['p.stock']['checked'])) {
  1141. print_liste_field_titre($arrayfields['p.stock']['label'], $_SERVER["PHP_SELF"], "p.stock", "", $param, '', $sortfield, $sortorder, 'right ');
  1142. }
  1143. if (!empty($arrayfields['stock_virtual']['checked'])) {
  1144. print_liste_field_titre($arrayfields['stock_virtual']['label'], $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'right ');
  1145. }
  1146. if (!empty($arrayfields['p.tobatch']['checked'])) {
  1147. print_liste_field_titre($arrayfields['p.tobatch']['label'], $_SERVER["PHP_SELF"], "p.tobatch", "", $param, '', $sortfield, $sortorder, 'center ');
  1148. }
  1149. if (!empty($arrayfields['p.fk_country']['checked'])) {
  1150. print_liste_field_titre($arrayfields['p.fk_country']['label'], $_SERVER["PHP_SELF"], "p.fk_country", "", $param, '', $sortfield, $sortorder);
  1151. }
  1152. if (!empty($arrayfields['p.fk_state']['checked'])) {
  1153. print_liste_field_titre($arrayfields['p.fk_state']['label'], $_SERVER["PHP_SELF"], "p.fk_state", "", $param, '', $sortfield, $sortorder);
  1154. }
  1155. if (!empty($arrayfields[$alias_product_perentity . '.accountancy_code_sell']['checked'])) {
  1156. print_liste_field_titre($arrayfields[$alias_product_perentity . '.accountancy_code_sell']['label'], $_SERVER["PHP_SELF"], $alias_product_perentity . ".accountancy_code_sell", "", $param, '', $sortfield, $sortorder);
  1157. }
  1158. if (!empty($arrayfields[$alias_product_perentity . '.accountancy_code_sell_intra']['checked'])) {
  1159. print_liste_field_titre($arrayfields[$alias_product_perentity . '.accountancy_code_sell_intra']['label'], $_SERVER["PHP_SELF"], $alias_product_perentity . ".accountancy_code_sell_intra", "", $param, '', $sortfield, $sortorder);
  1160. }
  1161. if (!empty($arrayfields[$alias_product_perentity . '.accountancy_code_sell_export']['checked'])) {
  1162. print_liste_field_titre($arrayfields[$alias_product_perentity . '.accountancy_code_sell_export']['label'], $_SERVER["PHP_SELF"], $alias_product_perentity . ".accountancy_code_sell_export", "", $param, '', $sortfield, $sortorder);
  1163. }
  1164. if (!empty($arrayfields[$alias_product_perentity . '.accountancy_code_buy']['checked'])) {
  1165. print_liste_field_titre($arrayfields[$alias_product_perentity . '.accountancy_code_buy']['label'], $_SERVER["PHP_SELF"], $alias_product_perentity . ".accountancy_code_buy", "", $param, '', $sortfield, $sortorder);
  1166. }
  1167. if (!empty($arrayfields[$alias_product_perentity . '.accountancy_code_buy_intra']['checked'])) {
  1168. print_liste_field_titre($arrayfields[$alias_product_perentity . '.accountancy_code_buy_intra']['label'], $_SERVER["PHP_SELF"], $alias_product_perentity . ".accountancy_code_buy_intra", "", $param, '', $sortfield, $sortorder);
  1169. }
  1170. if (!empty($arrayfields[$alias_product_perentity . '.accountancy_code_buy_export']['checked'])) {
  1171. print_liste_field_titre($arrayfields[$alias_product_perentity . '.accountancy_code_buy_export']['label'], $_SERVER["PHP_SELF"], $alias_product_perentity . ".accountancy_code_buy_export", "", $param, '', $sortfield, $sortorder);
  1172. }
  1173. // Extra fields
  1174. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  1175. // Hook fields
  1176. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
  1177. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  1178. print $hookmanager->resPrint;
  1179. if (!empty($arrayfields['p.datec']['checked'])) {
  1180. print_liste_field_titre($arrayfields['p.datec']['label'], $_SERVER["PHP_SELF"], "p.datec", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  1181. }
  1182. if (!empty($arrayfields['p.tms']['checked'])) {
  1183. print_liste_field_titre($arrayfields['p.tms']['label'], $_SERVER["PHP_SELF"], "p.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  1184. }
  1185. if (!empty($arrayfields['p.tosell']['checked'])) {
  1186. print_liste_field_titre($arrayfields['p.tosell']['label'], $_SERVER["PHP_SELF"], "p.tosell", "", $param, '', $sortfield, $sortorder, 'center ');
  1187. }
  1188. if (!empty($arrayfields['p.tobuy']['checked'])) {
  1189. print_liste_field_titre($arrayfields['p.tobuy']['label'], $_SERVER["PHP_SELF"], "p.tobuy", "", $param, '', $sortfield, $sortorder, 'center ');
  1190. }
  1191. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
  1192. print "</tr>\n";
  1193. $product_static = new Product($db);
  1194. $product_fourn = new ProductFournisseur($db);
  1195. $i = 0;
  1196. $totalarray = array();
  1197. $totalarray['nbfield'] = 0;
  1198. while ($i < min($num, $limit)) {
  1199. $obj = $db->fetch_object($resql);
  1200. // Multilangs
  1201. if (!empty($conf->global->MAIN_MULTILANGS)) { // If multilang is enabled
  1202. $sql = "SELECT label";
  1203. $sql .= " FROM ".MAIN_DB_PREFIX."product_lang";
  1204. $sql .= " WHERE fk_product = ".((int) $obj->rowid);
  1205. $sql .= " AND lang = '".$db->escape($langs->getDefaultLang())."'";
  1206. $sql .= " LIMIT 1";
  1207. $result = $db->query($sql);
  1208. if ($result) {
  1209. $objtp = $db->fetch_object($result);
  1210. if (!empty($objtp->label)) {
  1211. $obj->label = $objtp->label;
  1212. }
  1213. }
  1214. }
  1215. $product_static->id = $obj->rowid;
  1216. $product_static->ref = $obj->ref;
  1217. $product_static->ref_fourn = empty($obj->ref_supplier) ? '' : $obj->ref_supplier; // deprecated
  1218. $product_static->ref_supplier = empty($obj->ref_supplier) ? '' : $obj->ref_supplier;
  1219. $product_static->label = $obj->label;
  1220. $product_static->finished = $obj->finished;
  1221. $product_static->type = $obj->fk_product_type;
  1222. $product_static->status_buy = $obj->tobuy;
  1223. $product_static->status = $obj->tosell;
  1224. $product_static->status_batch = $obj->tobatch;
  1225. $product_static->entity = $obj->entity;
  1226. $product_static->pmp = $obj->pmp;
  1227. $product_static->accountancy_code_sell = $obj->accountancy_code_sell;
  1228. $product_static->accountancy_code_sell_export = $obj->accountancy_code_sell_export;
  1229. $product_static->accountancy_code_sell_intra = $obj->accountancy_code_sell_intra;
  1230. $product_static->accountancy_code_buy = $obj->accountancy_code_buy;
  1231. $product_static->accountancy_code_buy_intra = $obj->accountancy_code_buy_intra;
  1232. $product_static->accountancy_code_buy_export = $obj->accountancy_code_buy_export;
  1233. $product_static->length = $obj->length;
  1234. $product_static->length_units = $obj->length_units;
  1235. $product_static->width = $obj->width;
  1236. $product_static->width_units = $obj->width_units;
  1237. $product_static->height = $obj->height;
  1238. $product_static->height_units = $obj->height_units;
  1239. $product_static->weight = $obj->weight;
  1240. $product_static->weight_units = $obj->weight_units;
  1241. $product_static->volume = $obj->volume;
  1242. $product_static->volume_units = $obj->volume_units;
  1243. $product_static->surface = $obj->surface;
  1244. $product_static->surface_units = $obj->surface_units;
  1245. if (!empty($conf->global->PRODUCT_USE_UNITS)) {
  1246. $product_static->fk_unit = $obj->fk_unit;
  1247. }
  1248. // STOCK_DISABLE_OPTIM_LOAD can be set to force load_stock whatever is permissions on stock.
  1249. if ((!empty($conf->stock->enabled) && $user->rights->stock->lire && $search_type != 1) || !empty($conf->global->STOCK_DISABLE_OPTIM_LOAD)) { // To optimize call of load_stock
  1250. if ($obj->fk_product_type != 1 || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) { // Not a service
  1251. $option = 'nobatch';
  1252. if (empty($arrayfields['stock_virtual']['checked'])) {
  1253. $option .= ',novirtual';
  1254. }
  1255. $product_static->load_stock($option); // Load stock_reel + stock_warehouse. This can also call load_virtual_stock()
  1256. }
  1257. }
  1258. print '<tr class="oddeven">';
  1259. // Ref
  1260. if (!empty($arrayfields['p.rowid']['checked'])) {
  1261. print '<td class="nowraponall">';
  1262. print $product_static->id;
  1263. print "</td>\n";
  1264. if (!$i) {
  1265. $totalarray['nbfield']++;
  1266. }
  1267. }
  1268. // Ref
  1269. if (!empty($arrayfields['p.ref']['checked'])) {
  1270. print '<td class="tdoverflowmax200">';
  1271. print $product_static->getNomUrl(1);
  1272. print "</td>\n";
  1273. if (!$i) {
  1274. $totalarray['nbfield']++;
  1275. }
  1276. }
  1277. // Ref supplier
  1278. if (!empty($arrayfields['pfp.ref_fourn']['checked'])) {
  1279. print '<td class="tdoverflowmax200">';
  1280. print $product_static->getNomUrl(1);
  1281. print "</td>\n";
  1282. if (!$i) {
  1283. $totalarray['nbfield']++;
  1284. }
  1285. }
  1286. // Thumbnail
  1287. if (!empty($arrayfields['thumbnail']['checked'])) {
  1288. $product_thumbnail_html = '';
  1289. if (!empty($product_static->entity)) {
  1290. $product_thumbnail = $product_static->show_photos('product', $conf->product->multidir_output[$product_static->entity], 1, 1, 0, 0, 0, 80);
  1291. if ($product_static->nbphoto > 0) {
  1292. $product_thumbnail_html = $product_thumbnail;
  1293. }
  1294. }
  1295. print '<td class="center">' . $product_thumbnail_html . '</td>';
  1296. if (!$i) {
  1297. $totalarray['nbfield']++;
  1298. }
  1299. }
  1300. // Label
  1301. if (!empty($arrayfields['p.label']['checked'])) {
  1302. print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($obj->label).'">'.$obj->label.'</td>';
  1303. if (!$i) {
  1304. $totalarray['nbfield']++;
  1305. }
  1306. }
  1307. // Type
  1308. if (!empty($arrayfields['p.fk_product_type']['checked'])) {
  1309. print '<td class="center">';
  1310. $s = '';
  1311. if ($obj->fk_product_type == 0) {
  1312. $s .= img_picto($langs->trans("Product"), 'product', 'class="paddingleftonly paddingrightonly colorgrey"');
  1313. } else {
  1314. $s .= img_picto($langs->trans("Service"), 'service', 'class="paddingleftonly paddingrightonly colorgrey"');
  1315. }
  1316. print $s;
  1317. print '</td>';
  1318. if (!$i) {
  1319. $totalarray['nbfield']++;
  1320. }
  1321. }
  1322. // Barcode
  1323. if (!empty($arrayfields['p.barcode']['checked'])) {
  1324. print '<td>'.$obj->barcode.'</td>';
  1325. if (!$i) {
  1326. $totalarray['nbfield']++;
  1327. }
  1328. }
  1329. // Duration
  1330. if (!empty($arrayfields['p.duration']['checked'])) {
  1331. print '<td class="center nowraponall">';
  1332. if (preg_match('/([^a-z]+)[a-z]$/i', $obj->duration)) {
  1333. $duration_value = substr($obj->duration, 0, dol_strlen($obj->duration) - 1);
  1334. $duration_unit = substr($obj->duration, -1);
  1335. if ((float) $duration_value > 1) {
  1336. $dur = array("i"=>$langs->trans("Minutes"), "h"=>$langs->trans("Hours"), "d"=>$langs->trans("Days"), "w"=>$langs->trans("Weeks"), "m"=>$langs->trans("Months"), "y"=>$langs->trans("Years"));
  1337. } elseif ((float) $duration_value > 0) {
  1338. $dur = array("i"=>$langs->trans("Minute"), "h"=>$langs->trans("Hour"), "d"=>$langs->trans("Day"), "w"=>$langs->trans("Week"), "m"=>$langs->trans("Month"), "y"=>$langs->trans("Year"));
  1339. }
  1340. print $duration_value;
  1341. print ((!empty($duration_unit) && isset($dur[$duration_unit]) && $duration_value != '') ? ' '.$langs->trans($dur[$duration_unit]) : '');
  1342. } elseif (!preg_match('/^[a-z]$/i', $obj->duration)) { // If duration is a simple char (like 's' of 'm'), we do not show value
  1343. print $obj->duration;
  1344. }
  1345. print '</td>';
  1346. if (!$i) {
  1347. $totalarray['nbfield']++;
  1348. }
  1349. }
  1350. // Finished
  1351. if (!empty($arrayfields['p.finished']['checked'])) {
  1352. print '<td class="center">';
  1353. print $product_static->getLibFinished();
  1354. print '</td>';
  1355. if (!$i) {
  1356. $totalarray['nbfield']++;
  1357. }
  1358. }
  1359. // Weight
  1360. if (!empty($arrayfields['p.weight']['checked'])) {
  1361. print '<td class="center">';
  1362. print $obj->weight;
  1363. print '</td>';
  1364. if (!$i) {
  1365. $totalarray['nbfield']++;
  1366. }
  1367. }
  1368. // Weight units
  1369. if (!empty($arrayfields['p.weight_units']['checked'])) {
  1370. print '<td class="center">';
  1371. if ($product_static->weight != '') {
  1372. print measuringUnitString(0, 'weight', $product_static->weight_units);
  1373. }
  1374. print '</td>';
  1375. if (!$i) {
  1376. $totalarray['nbfield']++;
  1377. }
  1378. }
  1379. // Length
  1380. if (!empty($arrayfields['p.length']['checked'])) {
  1381. print '<td class="center">';
  1382. print $obj->length;
  1383. print '</td>';
  1384. if (!$i) {
  1385. $totalarray['nbfield']++;
  1386. }
  1387. }
  1388. // Length units
  1389. if (!empty($arrayfields['p.length_units']['checked'])) {
  1390. print '<td class="center">';
  1391. if ($product_static->length != '') {
  1392. print measuringUnitString(0, 'size', $product_static->length_units);
  1393. }
  1394. print '</td>';
  1395. if (!$i) {
  1396. $totalarray['nbfield']++;
  1397. }
  1398. }
  1399. // Width
  1400. if (!empty($arrayfields['p.width']['checked'])) {
  1401. print '<td align="center">';
  1402. print $obj->width;
  1403. print '</td>';
  1404. if (!$i) {
  1405. $totalarray['nbfield']++;
  1406. }
  1407. }
  1408. // Width units
  1409. if (!empty($arrayfields['p.width_units']['checked'])) {
  1410. print '<td class="center">';
  1411. if ($product_static->width != '') {
  1412. print measuringUnitString(0, 'size', $product_static->width_units);
  1413. }
  1414. print '</td>';
  1415. if (!$i) {
  1416. $totalarray['nbfield']++;
  1417. }
  1418. }
  1419. // Height
  1420. if (!empty($arrayfields['p.height']['checked'])) {
  1421. print '<td align="center">';
  1422. print $obj->height;
  1423. print '</td>';
  1424. if (!$i) {
  1425. $totalarray['nbfield']++;
  1426. }
  1427. }
  1428. // Height units
  1429. if (!empty($arrayfields['p.height_units']['checked'])) {
  1430. print '<td class="center">';
  1431. if ($product_static->height != '') {
  1432. print measuringUnitString(0, 'size', $product_static->height_units);
  1433. }
  1434. print '</td>';
  1435. if (!$i) {
  1436. $totalarray['nbfield']++;
  1437. }
  1438. }
  1439. // Surface
  1440. if (!empty($arrayfields['p.surface']['checked'])) {
  1441. print '<td class="center">';
  1442. print $obj->surface;
  1443. print '</td>';
  1444. if (!$i) {
  1445. $totalarray['nbfield']++;
  1446. }
  1447. }
  1448. // Surface units
  1449. if (!empty($arrayfields['p.surface_units']['checked'])) {
  1450. print '<td class="center">';
  1451. if ($product_static->surface != '') {
  1452. print measuringUnitString(0, 'surface', $product_static->surface_units);
  1453. }
  1454. print '</td>';
  1455. if (!$i) {
  1456. $totalarray['nbfield']++;
  1457. }
  1458. }
  1459. // Volume
  1460. if (!empty($arrayfields['p.volume']['checked'])) {
  1461. print '<td class="center">';
  1462. print $obj->volume;
  1463. print '</td>';
  1464. if (!$i) {
  1465. $totalarray['nbfield']++;
  1466. }
  1467. }
  1468. // Volume units
  1469. if (!empty($arrayfields['p.volume_units']['checked'])) {
  1470. print '<td class="center">';
  1471. if ($product_static->volume != '') {
  1472. print measuringUnitString(0, 'volume', $product_static->volume_units);
  1473. }
  1474. print '</td>';
  1475. if (!$i) {
  1476. $totalarray['nbfield']++;
  1477. }
  1478. }
  1479. // Unit
  1480. if (!empty($arrayfields['cu.label']['checked'])) {
  1481. print '<td align="center">';
  1482. if (!empty($obj->cu_label)) {
  1483. print $langs->trans($obj->cu_label);
  1484. }
  1485. print '</td>';
  1486. if (!$i) {
  1487. $totalarray['nbfield']++;
  1488. }
  1489. }
  1490. // Sell price
  1491. if (!empty($arrayfields['p.sellprice']['checked'])) {
  1492. print '<td class="right nowraponall">';
  1493. if ($obj->tosell) {
  1494. if ($obj->price_base_type == 'TTC') {
  1495. print '<span class="amount">'.price($obj->price_ttc).' '.$langs->trans("TTC").'</span>';
  1496. } else {
  1497. print '<span class="amount">'.price($obj->price).' '.$langs->trans("HT").'</span>';
  1498. }
  1499. }
  1500. print '</td>';
  1501. if (!$i) {
  1502. $totalarray['nbfield']++;
  1503. }
  1504. }
  1505. // Multiprices
  1506. if (! empty($conf->global->PRODUIT_MULTIPRICES)) {
  1507. if (! isset($productpricescache)) {
  1508. $productpricescache=array();
  1509. }
  1510. if (! isset($productpricescache[$obj->rowid])) {
  1511. $productpricescache[$obj->rowid] = array();
  1512. }
  1513. if ($obj->tosell) {
  1514. // Make 1 request for all price levels (without filter on price_level) and saved result into an cache array
  1515. // then reuse the cache array if we need prices for other price levels
  1516. $sqlp = "SELECT p.rowid, p.fk_product, p.price, p.price_ttc, p.price_level, p.date_price, p.price_base_type";
  1517. $sqlp .= " FROM ".MAIN_DB_PREFIX."product_price as p";
  1518. $sqlp .= " WHERE fk_product = ".((int) $obj->rowid);
  1519. $sqlp .= " ORDER BY p.date_price DESC, p.rowid DESC, p.price_level ASC";
  1520. $resultp = $db->query($sqlp);
  1521. if ($resultp) {
  1522. $nump = $db->num_rows($resultp);
  1523. $j = 0;
  1524. while ($j < $nump) {
  1525. $objp = $db->fetch_object($resultp);
  1526. if (empty($productpricescache[$obj->rowid][$objp->price_level])) {
  1527. $productpricescache[$obj->rowid][$objp->price_level]['price'] = $objp->price;
  1528. $productpricescache[$obj->rowid][$objp->price_level]['price_ttc'] = $objp->price_ttc;
  1529. $productpricescache[$obj->rowid][$objp->price_level]['price_base_type'] = $objp->price_base_type;
  1530. }
  1531. $j++;
  1532. }
  1533. $db->free($resultp);
  1534. } else {
  1535. dol_print_error($db);
  1536. }
  1537. }
  1538. foreach ($arraypricelevel as $key => $value) {
  1539. if (!empty($arrayfields['p.sellprice'.$key]['checked'])) {
  1540. print '<td class="right nowraponall">';
  1541. if (!empty($productpricescache[$obj->rowid])) {
  1542. if ($productpricescache[$obj->rowid][$key]['price_base_type'] == 'TTC') {
  1543. print '<span class="amount">'.price($productpricescache[$obj->rowid][$key]['price_ttc']).' '.$langs->trans("TTC").'</span>';
  1544. } else {
  1545. print '<span class="amount">'.price($productpricescache[$obj->rowid][$key]['price']).' '.$langs->trans("HT").'</span>';
  1546. }
  1547. }
  1548. print '</td>';
  1549. if (!$i) {
  1550. $totalarray['nbfield']++;
  1551. }
  1552. }
  1553. }
  1554. }
  1555. // Better buy price
  1556. if (!empty($arrayfields['p.minbuyprice']['checked'])) {
  1557. print '<td class="right nowraponall">';
  1558. if ($obj->tobuy && $obj->minsellprice != '') {
  1559. //print price($obj->minsellprice).' '.$langs->trans("HT");
  1560. if ($product_fourn->find_min_price_product_fournisseur($obj->rowid) > 0) {
  1561. if ($product_fourn->product_fourn_price_id > 0) {
  1562. if ((!empty($conf->fournisseur->enabled) && !empty($user->rights->fournisseur->lire) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || (!empty($conf->supplier_order->enabled) && !empty($user->rights->supplier_order->lire)) || (!empty($conf->supplier_invoice->enabled) && !empty($user->rights->supplier_invoice->lire))) {
  1563. $htmltext = $product_fourn->display_price_product_fournisseur(1, 1, 0, 1);
  1564. print '<span class="amount">'.$form->textwithpicto(price($product_fourn->fourn_unitprice * (1 - $product_fourn->fourn_remise_percent / 100) - $product_fourn->fourn_remise).' '.$langs->trans("HT"), $htmltext).'</span>';
  1565. } else {
  1566. print '<span class="amount">'.price($product_fourn->fourn_unitprice).' '.$langs->trans("HT").'</span>';
  1567. }
  1568. }
  1569. }
  1570. }
  1571. print '</td>';
  1572. if (!$i) {
  1573. $totalarray['nbfield']++;
  1574. }
  1575. }
  1576. // Number of buy prices
  1577. if (!empty($arrayfields['p.numbuyprice']['checked'])) {
  1578. print '<td class="right">';
  1579. if ($obj->tobuy) {
  1580. if (count($productFournList = $product_fourn->list_product_fournisseur_price($obj->rowid)) > 0) {
  1581. $htmltext = $product_fourn->display_price_product_fournisseur(1, 1, 0, 1, $productFournList);
  1582. print $form->textwithpicto(count($productFournList), $htmltext);
  1583. }
  1584. }
  1585. print '</td>';
  1586. }
  1587. // VAT or Sell Tax Rate
  1588. if (!empty($arrayfields['p.tva_tx']['checked'])) {
  1589. print '<td class="right">';
  1590. print vatrate($obj->tva_tx, true);
  1591. print '</td>';
  1592. if (!$i) {
  1593. $totalarray['nbfield']++;
  1594. }
  1595. }
  1596. // WAP
  1597. if (!empty($arrayfields['p.pmp']['checked'])) {
  1598. print '<td class="nowrap right">';
  1599. print '<span class="amount">'.price($product_static->pmp, 1, $langs)."</span>";
  1600. print '</td>';
  1601. }
  1602. // Cost price
  1603. if (!empty($arrayfields['p.cost_price']['checked'])) {
  1604. print '<td class="nowrap right">';
  1605. //print $obj->cost_price;
  1606. print '<span class="amount">'.price($obj->cost_price).' '.$langs->trans("HT").'</span>';
  1607. print '</td>';
  1608. }
  1609. // Limit alert
  1610. if (!empty($arrayfields['p.seuil_stock_alerte']['checked'])) {
  1611. print '<td class="right">';
  1612. if ($obj->fk_product_type != 1) {
  1613. print $obj->seuil_stock_alerte;
  1614. }
  1615. print '</td>';
  1616. if (!$i) {
  1617. $totalarray['nbfield']++;
  1618. }
  1619. }
  1620. // Desired stock
  1621. if (!empty($arrayfields['p.desiredstock']['checked'])) {
  1622. print '<td class="right">';
  1623. if ($obj->fk_product_type != 1) {
  1624. print $obj->desiredstock;
  1625. }
  1626. print '</td>';
  1627. if (!$i) {
  1628. $totalarray['nbfield']++;
  1629. }
  1630. }
  1631. // Stock real
  1632. if (!empty($arrayfields['p.stock']['checked'])) {
  1633. print '<td class="right">';
  1634. if ($obj->fk_product_type != 1) {
  1635. if ($obj->seuil_stock_alerte != '' && $product_static->stock_reel < (float) $obj->seuil_stock_alerte) {
  1636. print img_warning($langs->trans("StockLowerThanLimit", $obj->seuil_stock_alerte)).' ';
  1637. }
  1638. print price(price2num($product_static->stock_reel, 'MS'));
  1639. }
  1640. print '</td>';
  1641. if (!$i) {
  1642. $totalarray['nbfield']++;
  1643. }
  1644. }
  1645. // Stock virtual
  1646. if (!empty($arrayfields['stock_virtual']['checked'])) {
  1647. print '<td class="right">';
  1648. if ($obj->fk_product_type != 1) {
  1649. if ($obj->seuil_stock_alerte != '' && $product_static->stock_theorique < (float) $obj->seuil_stock_alerte) {
  1650. print img_warning($langs->trans("StockLowerThanLimit", $obj->seuil_stock_alerte)).' ';
  1651. }
  1652. print price(price2num($product_static->stock_theorique, 'MS'));
  1653. }
  1654. print '</td>';
  1655. if (!$i) {
  1656. $totalarray['nbfield']++;
  1657. }
  1658. }
  1659. // Lot/Serial
  1660. if (!empty($arrayfields['p.tobatch']['checked'])) {
  1661. print '<td class="center">';
  1662. print $product_static->getLibStatut(1, 2);
  1663. print '</td>';
  1664. if (!$i) {
  1665. $totalarray['nbfield']++;
  1666. }
  1667. }
  1668. // Country
  1669. if (!empty($arrayfields['p.fk_country']['checked'])) {
  1670. print '<td>'.getCountry($obj->fk_country, 0, $db).'</td>';
  1671. if (!$i) {
  1672. $totalarray['nbfield']++;
  1673. }
  1674. }
  1675. // State
  1676. if (!empty($arrayfields['p.fk_state']['checked'])) {
  1677. print '<td>';
  1678. if (!empty($obj->fk_state)) {
  1679. print getState($obj->fk_state, 0, $db);
  1680. }
  1681. print '</td>';
  1682. if (!$i) {
  1683. $totalarray['nbfield']++;
  1684. }
  1685. }
  1686. // Accountancy code sell
  1687. if (!empty($arrayfields[$alias_product_perentity . '.accountancy_code_sell']['checked'])) {
  1688. print '<td>'.$obj->accountancy_code_sell.'</td>';
  1689. if (!$i) {
  1690. $totalarray['nbfield']++;
  1691. }
  1692. }
  1693. if (!empty($arrayfields[$alias_product_perentity . '.accountancy_code_sell_intra']['checked'])) {
  1694. print '<td>'.$obj->accountancy_code_sell_intra.'</td>';
  1695. if (!$i) {
  1696. $totalarray['nbfield']++;
  1697. }
  1698. }
  1699. if (!empty($arrayfields[$alias_product_perentity . '.accountancy_code_sell_export']['checked'])) {
  1700. print '<td>'.$obj->accountancy_code_sell_export.'</td>';
  1701. if (!$i) {
  1702. $totalarray['nbfield']++;
  1703. }
  1704. }
  1705. // Accountancy code buy
  1706. if (!empty($arrayfields[$alias_product_perentity . '.accountancy_code_buy']['checked'])) {
  1707. print '<td>'.$obj->accountancy_code_buy.'</td>';
  1708. if (!$i) {
  1709. $totalarray['nbfield']++;
  1710. }
  1711. }
  1712. if (!empty($arrayfields[$alias_product_perentity . '.accountancy_code_buy_intra']['checked'])) {
  1713. print '<td>'.$obj->accountancy_code_buy_intra.'</td>';
  1714. if (!$i) {
  1715. $totalarray['nbfield']++;
  1716. }
  1717. }
  1718. if (!empty($arrayfields[$alias_product_perentity . '.accountancy_code_buy_export']['checked'])) {
  1719. print '<td>'.$obj->accountancy_code_buy_export.'</td>';
  1720. if (!$i) {
  1721. $totalarray['nbfield']++;
  1722. }
  1723. }
  1724. // Extra fields
  1725. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  1726. // Fields from hook
  1727. $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  1728. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  1729. print $hookmanager->resPrint;
  1730. // Date creation
  1731. if (!empty($arrayfields['p.datec']['checked'])) {
  1732. print '<td class="center nowraponall">';
  1733. print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
  1734. print '</td>';
  1735. if (!$i) {
  1736. $totalarray['nbfield']++;
  1737. }
  1738. }
  1739. // Date modification
  1740. if (!empty($arrayfields['p.tms']['checked'])) {
  1741. print '<td class="center nowraponall">';
  1742. print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser');
  1743. print '</td>';
  1744. if (!$i) {
  1745. $totalarray['nbfield']++;
  1746. }
  1747. }
  1748. // Status (to sell)
  1749. if (!empty($arrayfields['p.tosell']['checked'])) {
  1750. print '<td class="center nowrap">';
  1751. if (!empty($conf->use_javascript_ajax) && $user->rights->produit->creer && !empty($conf->global->MAIN_DIRECT_STATUS_UPDATE)) {
  1752. print ajax_object_onoff($product_static, 'status', 'tosell', 'ProductStatusOnSell', 'ProductStatusNotOnSell');
  1753. } else {
  1754. print $product_static->LibStatut($obj->tosell, 5, 0);
  1755. }
  1756. print '</td>';
  1757. if (!$i) {
  1758. $totalarray['nbfield']++;
  1759. }
  1760. }
  1761. // Status (to buy)
  1762. if (!empty($arrayfields['p.tobuy']['checked'])) {
  1763. print '<td class="center nowrap">';
  1764. if (!empty($conf->use_javascript_ajax) && $user->rights->produit->creer && !empty($conf->global->MAIN_DIRECT_STATUS_UPDATE)) {
  1765. print ajax_object_onoff($product_static, 'status_buy', 'tobuy', 'ProductStatusOnBuy', 'ProductStatusNotOnBuy');
  1766. } else {
  1767. print $product_static->LibStatut($obj->tobuy, 5, 1);
  1768. }
  1769. print '</td>';
  1770. if (!$i) {
  1771. $totalarray['nbfield']++;
  1772. }
  1773. }
  1774. // Action
  1775. print '<td class="nowrap center">';
  1776. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  1777. $selected = 0;
  1778. if (in_array($obj->rowid, $arrayofselected)) {
  1779. $selected = 1;
  1780. }
  1781. print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
  1782. }
  1783. print '</td>';
  1784. if (!$i) {
  1785. $totalarray['nbfield']++;
  1786. }
  1787. print "</tr>\n";
  1788. $i++;
  1789. }
  1790. $db->free($resql);
  1791. print "</table>";
  1792. print "</div>";
  1793. print '</form>';
  1794. } else {
  1795. dol_print_error($db);
  1796. }
  1797. // End of page
  1798. llxFooter();
  1799. $db->close();