list.php 92 KB

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