list.php 90 KB

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