list_det.php 96 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278
  1. <?php
  2. /* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2019 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
  5. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  6. * Copyright (C) 2012 Juanjo Menent <jmenent@2byte.es>
  7. * Copyright (C) 2013 Christophe Battarel <christophe.battarel@altairis.fr>
  8. * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
  9. * Copyright (C) 2015-2018 Frédéric France <frederic.france@netlogic.fr>
  10. * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
  11. * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
  12. * Copyright (C) 2016-2021 Ferran Marcet <fmarcet@2byte.es>
  13. * Copyright (C) 2018-2023 Charlene Benke <charlene@patas-monkey.com>
  14. * Copyright (C) 2021-2023 Anthony Berton <anthony.berton@bb2a.fr>
  15. *
  16. * This program is free software; you can redistribute it and/or modify
  17. * it under the terms of the GNU General Public License as published by
  18. * the Free Software Foundation; either version 3 of the License, or
  19. * (at your option) any later version.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU General Public License
  27. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  28. */
  29. /**
  30. * \file htdocs/commande/list.php
  31. * \ingroup commande
  32. * \brief Page to list orders
  33. */
  34. require '../main.inc.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  36. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  37. require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
  38. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  39. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  40. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  41. if (isModEnabled('margin')) {
  42. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmargin.class.php';
  43. }
  44. require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
  45. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  46. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  47. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  48. if (isModEnabled('categorie')) {
  49. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcategory.class.php';
  50. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  51. }
  52. // Load translation files required by the page
  53. $langs->loadLangs(array("orders", 'sendings', 'deliveries', 'companies', 'compta', 'bills', 'stocks', 'products'));
  54. $action = GETPOST('action', 'aZ09');
  55. $massaction = GETPOST('massaction', 'alpha');
  56. $show_files = GETPOST('show_files', 'int');
  57. $confirm = GETPOST('confirm', 'alpha');
  58. $toselect = GETPOST('toselect', 'array');
  59. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'orderlistdet';
  60. $productobuy = GETPOST('productobuy', 'alpha');
  61. $productonly = GETPOST('productonly', 'alpha');
  62. $disablelinefree = GETPOST('disablelinefree', 'alpha');
  63. $search_datecloture_start = GETPOST('search_datecloture_start', 'int');
  64. if (empty($search_datecloture_start)) {
  65. $search_datecloture_start = dol_mktime(0, 0, 0, GETPOST('search_datecloture_startmonth', 'int'), GETPOST('search_datecloture_startday', 'int'), GETPOST('search_datecloture_startyear', 'int'));
  66. }
  67. $search_datecloture_end = GETPOST('search_datecloture_end', 'int');
  68. if (empty($search_datecloture_end)) {
  69. $search_datecloture_end = dol_mktime(23, 59, 59, GETPOST('search_datecloture_endmonth', 'int'), GETPOST('search_datecloture_endday', 'int'), GETPOST('search_datecloture_endyear', 'int'));
  70. }
  71. $search_dateorder_start = dol_mktime(0, 0, 0, GETPOST('search_dateorder_start_month', 'int'), GETPOST('search_dateorder_start_day', 'int'), GETPOST('search_dateorder_start_year', 'int'));
  72. $search_dateorder_end = dol_mktime(23, 59, 59, GETPOST('search_dateorder_end_month', 'int'), GETPOST('search_dateorder_end_day', 'int'), GETPOST('search_dateorder_end_year', 'int'));
  73. $search_datedelivery_start = dol_mktime(0, 0, 0, GETPOST('search_datedelivery_start_month', 'int'), GETPOST('search_datedelivery_start_day', 'int'), GETPOST('search_datedelivery_start_year', 'int'));
  74. $search_datedelivery_end = dol_mktime(23, 59, 59, GETPOST('search_datedelivery_end_month', 'int'), GETPOST('search_datedelivery_end_day', 'int'), GETPOST('search_datedelivery_end_year', 'int'));
  75. if (isModEnabled('categorie')) {
  76. $search_product_category_array = GETPOST("search_category_".Categorie::TYPE_PRODUCT."_list", "array");
  77. $searchCategoryProductOperator = 0;
  78. if (GETPOSTISSET('formfilteraction')) {
  79. $searchCategoryProductOperator = GETPOSTINT('search_category_product_operator');
  80. } elseif (getDolGlobalString('MAIN_SEARCH_CAT_OR_BY_DEFAULT')) {
  81. $searchCategoryProductOperator = $conf->global->MAIN_SEARCH_CAT_OR_BY_DEFAULT;
  82. }
  83. }
  84. // Détail commande
  85. $search_id = GETPOST('search_id', 'alpha');
  86. $search_refProduct = GETPOST('search_refProduct', 'alpha');
  87. $search_descProduct = GETPOST('search_descProduct', 'alpha');
  88. $search_ref = GETPOST('search_ref', 'alpha') != '' ? GETPOST('search_ref', 'alpha') : GETPOST('sref', 'alpha');
  89. $search_ref_customer = GETPOST('search_ref_customer', 'alpha');
  90. $search_company = GETPOST('search_company', 'alpha');
  91. $search_company_alias = GETPOST('search_company_alias', 'alpha');
  92. $search_town = GETPOST('search_town', 'alpha');
  93. $search_zip = GETPOST('search_zip', 'alpha');
  94. $search_state = GETPOST("search_state", 'alpha');
  95. $search_country = GETPOST("search_country", 'int');
  96. $search_type_thirdparty = GETPOST("search_type_thirdparty", 'int');
  97. $sall = trim((GETPOST('search_all', 'alphanohtml') != '') ? GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
  98. $socid = GETPOST('socid', 'int');
  99. $search_user = GETPOST('search_user', 'int');
  100. $search_sale = GETPOST('search_sale', 'int');
  101. $search_total_ht = GETPOST('search_total_ht', 'alpha');
  102. $search_total_vat = GETPOST('search_total_vat', 'alpha');
  103. $search_total_ttc = GETPOST('search_total_ttc', 'alpha');
  104. $search_warehouse = GETPOST('search_warehouse', 'int');
  105. $search_multicurrency_code = GETPOST('search_multicurrency_code', 'alpha');
  106. $search_multicurrency_tx = GETPOST('search_multicurrency_tx', 'alpha');
  107. $search_multicurrency_montant_ht = GETPOST('search_multicurrency_montant_ht', 'alpha');
  108. $search_multicurrency_montant_vat = GETPOST('search_multicurrency_montant_vat', 'alpha');
  109. $search_multicurrency_montant_ttc = GETPOST('search_multicurrency_montant_ttc', 'alpha');
  110. $search_login = GETPOST('search_login', 'alpha');
  111. $search_categ_cus = GETPOST("search_categ_cus", 'int');
  112. $optioncss = GETPOST('optioncss', 'alpha');
  113. $search_billed = GETPOSTISSET('search_billed') ? GETPOST('search_billed', 'int') : GETPOST('billed', 'int');
  114. $search_status = GETPOST('search_status', 'int');
  115. $search_btn = GETPOST('button_search', 'alpha');
  116. $search_remove_btn = GETPOST('button_removefilter', 'alpha');
  117. $search_project_ref = GETPOST('search_project_ref', 'alpha');
  118. $search_project = GETPOST('search_project', 'alpha');
  119. $search_shippable = GETPOST('search_shippable', 'aZ09');
  120. $search_fk_cond_reglement = GETPOST("search_fk_cond_reglement", 'int');
  121. $search_fk_shipping_method = GETPOST("search_fk_shipping_method", 'int');
  122. $search_fk_mode_reglement = GETPOST("search_fk_mode_reglement", 'int');
  123. $search_fk_input_reason = GETPOST("search_fk_input_reason", 'int');
  124. $diroutputmassaction = $conf->commande->multidir_output[$conf->entity].'/temp/massgeneration/'.$user->id;
  125. // Load variable for pagination
  126. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  127. $sortfield = GETPOST('sortfield', 'aZ09comma');
  128. $sortorder = GETPOST('sortorder', 'aZ09comma');
  129. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  130. if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
  131. $page = 0;
  132. } // If $page is not defined, or '' or -1 or if we click on clear filters
  133. $offset = $limit * $page;
  134. $pageprev = $page - 1;
  135. $pagenext = $page + 1;
  136. if (!$sortfield) {
  137. $sortfield = 'pr.ref';
  138. }
  139. if (!$sortorder) {
  140. $sortorder = 'ASC';
  141. }
  142. $show_shippable_command = GETPOST('show_shippable_command', 'aZ09');
  143. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  144. $object = new Commande($db);
  145. $hookmanager->initHooks(array('orderlistdetail'));
  146. $extrafields = new ExtraFields($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. // List of fields to search into when doing a "search in all"
  151. $fieldstosearchall = array(
  152. 'c.ref'=>'Ref',
  153. 'c.ref_client'=>'RefCustomerOrder',
  154. 'cdet.description'=>'Description',
  155. 's.nom'=>"ThirdParty",
  156. 's.name_alias'=>"AliasNameShort",
  157. 's.zip'=>"Zip",
  158. 's.town'=>"Town",
  159. 'c.note_public'=>'NotePublic',
  160. );
  161. if (empty($user->socid)) {
  162. $fieldstosearchall["c.note_private"] = "NotePrivate";
  163. }
  164. $checkedtypetiers = 0;
  165. $arrayfields = array(
  166. // Détail commande
  167. 'rowid'=> array('label'=>'TechnicalID', 'checked'=>1, 'position'=>1, 'enabled'=>(getDolGlobalInt('MAIN_SHOW_TECHNICAL_ID') ? 1 : 0)),
  168. 'pr.ref'=> array('label'=>'ProductRef', 'checked'=>1, 'position'=>1),
  169. 'pr.desc'=> array('label'=>'ProductDescription', 'checked'=>-1, 'position'=>1),
  170. 'cdet.qty'=> array('label'=>'QtyOrdered', 'checked'=>1, 'position'=>1),
  171. 'c.ref'=>array('label'=>"Ref", 'checked'=>1, 'position'=>5),
  172. 'c.ref_client'=>array('label'=>"RefCustomerOrder", 'checked'=>-1, 'position'=>10),
  173. 'p.ref'=>array('label'=>"ProjectRef", 'checked'=>-1, 'enabled'=>(empty($conf->project->enabled) ? 0 : 1), 'position'=>20),
  174. 'p.title'=>array('label'=>"ProjectLabel", 'checked'=>0, 'enabled'=>(empty($conf->project->enabled) ? 0 : 1), 'position'=>25),
  175. 's.nom'=>array('label'=>"ThirdParty", 'checked'=>1, 'position'=>30),
  176. 's.name_alias'=>array('label'=>"AliasNameShort", 'checked'=>-1, 'position'=>31),
  177. 's.town'=>array('label'=>"Town", 'checked'=>-1, 'position'=>35),
  178. 's.zip'=>array('label'=>"Zip", 'checked'=>-1, 'position'=>40),
  179. 'state.nom'=>array('label'=>"StateShort", 'checked'=>0, 'position'=>45),
  180. 'country.code_iso'=>array('label'=>"Country", 'checked'=>0, 'position'=>50),
  181. 'typent.code'=>array('label'=>"ThirdPartyType", 'checked'=>$checkedtypetiers, 'position'=>55),
  182. 'c.date_commande'=>array('label'=>"OrderDateShort", 'checked'=>1, 'position'=>60),
  183. 'c.date_delivery'=>array('label'=>"DateDeliveryPlanned", 'checked'=>1, 'enabled'=>!getDolGlobalString('ORDER_DISABLE_DELIVERY_DATE'), 'position'=>65),
  184. 'c.fk_shipping_method'=>array('label'=>"SendingMethod", 'checked'=>-1, 'position'=>66 , 'enabled'=>isModEnabled('expedition')),
  185. 'c.fk_cond_reglement'=>array('label'=>"PaymentConditionsShort", 'checked'=>-1, 'position'=>67),
  186. 'c.fk_mode_reglement'=>array('label'=>"PaymentMode", 'checked'=>-1, 'position'=>68),
  187. 'c.fk_input_reason'=>array('label'=>"Channel", 'checked'=>-1, 'position'=>69),
  188. 'cdet.total_ht'=>array('label'=>"AmountHT", 'checked'=>1, 'position'=>75),
  189. 'c.total_vat'=>array('label'=>"AmountVAT", 'checked'=>0, 'position'=>80),
  190. 'cdet.total_ttc'=>array('label'=>"AmountTTC", 'checked'=>0, 'position'=>85),
  191. 'c.multicurrency_code'=>array('label'=>'Currency', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1), 'position'=>90),
  192. 'c.multicurrency_tx'=>array('label'=>'CurrencyRate', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1), 'position'=>95),
  193. 'c.multicurrency_total_ht'=>array('label'=>'MulticurrencyAmountHT', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1), 'position'=>100),
  194. 'c.multicurrency_total_vat'=>array('label'=>'MulticurrencyAmountVAT', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1), 'position'=>105),
  195. 'c.multicurrency_total_ttc'=>array('label'=>'MulticurrencyAmountTTC', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1), 'position'=>110),
  196. 'c.fk_warehouse'=>array('label'=>'Warehouse', 'checked'=>0, 'enabled'=>(!isModEnabled('stock') && !getDolGlobalString('WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER') ? 0 : 1), 'position'=>110),
  197. 'u.login'=>array('label'=>"Author", 'checked'=>1, 'position'=>115),
  198. 'sale_representative'=>array('label'=>"SaleRepresentativesOfThirdParty", 'checked'=>0, 'position'=>116),
  199. 'total_pa' => array('label' => (getDolGlobalString('MARGIN_TYPE') == '1' ? 'BuyingPrice' : 'CostPrice'), 'checked' => 0, 'position' => 300, 'enabled' => (!isModEnabled('margin') || !$user->rights->margins->liretous ? 0 : 1)),
  200. 'total_margin' => array('label' => 'Margin', 'checked' => 0, 'position' => 301, 'enabled' => (!isModEnabled('margin') || !$user->rights->margins->liretous ? 0 : 1)),
  201. 'total_margin_rate' => array('label' => 'MarginRate', 'checked' => 0, 'position' => 302, 'enabled' => (!isModEnabled('margin') || !$user->rights->margins->liretous || !getDolGlobalString('DISPLAY_MARGIN_RATES') ? 0 : 1)),
  202. 'total_mark_rate' => array('label' => 'MarkRate', 'checked' => 0, 'position' => 303, 'enabled' => (!isModEnabled('margin') || !$user->rights->margins->liretous || !getDolGlobalString('DISPLAY_MARK_RATES') ? 0 : 1)),
  203. 'c.datec'=>array('label'=>"DateCreation", 'checked'=>0, 'position'=>120),
  204. 'c.tms'=>array('label'=>"DateModificationShort", 'checked'=>0, 'position'=>125),
  205. 'c.date_cloture'=>array('label'=>"DateClosing", 'checked'=>0, 'position'=>130),
  206. 'c.note_public'=>array('label'=>'NotePublic', 'checked'=>0, 'enabled'=>(!getDolGlobalString('MAIN_LIST_ALLOW_PUBLIC_NOTES')), 'position'=>135),
  207. 'c.note_private'=>array('label'=>'NotePrivate', 'checked'=>0, 'enabled'=>(!getDolGlobalString('MAIN_LIST_ALLOW_PRIVATE_NOTES')), 'position'=>140),
  208. 'shippable'=>array('label'=>"Shippable", 'checked'=>1,'enabled'=>(isModEnabled('expedition')), 'position'=>990),
  209. 'c.facture'=>array('label'=>"Billed", 'checked'=>1, 'enabled'=>(!getDolGlobalString('WORKFLOW_BILL_ON_SHIPMENT')), 'position'=>995),
  210. 'c.import_key' =>array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-2, 'position'=>999),
  211. 'c.fk_statut'=>array('label'=>"Status", 'checked'=>1, 'position'=>1000)
  212. );
  213. // Extra fields
  214. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
  215. $object->fields = dol_sort_array($object->fields, 'position');
  216. $arrayfields = dol_sort_array($arrayfields, 'position');
  217. if (!$user->hasRight('societe', 'client', 'voir')) {
  218. $search_sale = $user->id;
  219. }
  220. // Security check
  221. $id = (GETPOST('orderid') ? GETPOST('orderid', 'int') : GETPOST('id', 'int'));
  222. if ($user->socid) {
  223. $socid = $user->socid;
  224. }
  225. $result = restrictedArea($user, 'commande', $id, '');
  226. /*
  227. * Actions
  228. */
  229. if (GETPOST('cancel', 'alpha')) {
  230. $action = 'list';
  231. $massaction = '';
  232. }
  233. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend' && $massaction != 'confirm_createbills') {
  234. $massaction = '';
  235. }
  236. $parameters = array('socid'=>$socid);
  237. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  238. if ($reshook < 0) {
  239. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  240. }
  241. if (empty($reshook)) {
  242. // Selection of new fields
  243. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  244. // Purge search criteria
  245. 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
  246. $productobuy = '';
  247. $productonly = '';
  248. $disablelinefree = '';
  249. $search_categ = '';
  250. $search_user = '';
  251. $search_sale = '';
  252. $search_product_category_array = array();
  253. $searchCategoryProductOperator = 0;
  254. $search_id = '';
  255. $search_refProduct = '';
  256. $search_descProduct = '';
  257. $search_ref = '';
  258. $search_ref_customer = '';
  259. $search_company = '';
  260. $search_company_alias = '';
  261. $search_town = '';
  262. $search_zip = "";
  263. $search_state = "";
  264. $search_type = '';
  265. $search_country = '';
  266. $search_type_thirdparty = '';
  267. $search_total_ht = '';
  268. $search_total_vat = '';
  269. $search_total_ttc = '';
  270. $search_warehouse = '';
  271. $search_multicurrency_code = '';
  272. $search_multicurrency_tx = '';
  273. $search_multicurrency_montant_ht = '';
  274. $search_multicurrency_montant_vat = '';
  275. $search_multicurrency_montant_ttc = '';
  276. $search_login = '';
  277. $search_dateorder_start = '';
  278. $search_dateorder_end = '';
  279. $search_datedelivery_start = '';
  280. $search_datedelivery_end = '';
  281. $search_project_ref = '';
  282. $search_project = '';
  283. $search_status = '';
  284. $search_billed = '';
  285. $toselect = array();
  286. $search_array_options = array();
  287. $search_categ_cus = 0;
  288. $search_datecloture_start = '';
  289. $search_datecloture_end = '';
  290. $search_fk_cond_reglement = '';
  291. $search_fk_shipping_method = '';
  292. $search_fk_mode_reglement = '';
  293. $search_fk_input_reason = '';
  294. }
  295. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
  296. || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
  297. $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
  298. }
  299. // Mass actions
  300. $objectclass = 'Commande';
  301. $objectlabel = 'Orders';
  302. $permissiontoread = $user->hasRight("commande", "lire");
  303. $permissiontoadd = $user->hasRight("commande", "creer");
  304. $permissiontodelete = $user->hasRight("commande", "supprimer");
  305. $permissiontoexport = $user->hasRight("commande", "commande", "export");
  306. if (getDolGlobalString('MAIN_USE_ADVANCED_PERMS')) {
  307. $permissiontovalidate = $user->hasRight("commande", "order_advance", "validate");
  308. $permissiontoclose = $user->hasRight("commande", "order_advance", "close");
  309. $permissiontocancel = $user->hasRight("commande", "order_advance", "annuler");
  310. $permissiontosendbymail = $user->hasRight("commande", "order_advance", "send");
  311. } else {
  312. $permissiontovalidate = $user->hasRight("commande", "creer");
  313. $permissiontoclose = $user->hasRight("commande", "creer");
  314. $permissiontocancel = $user->hasRight("commande", "creer");
  315. $permissiontosendbymail = $user->hasRight("commande", "creer");
  316. }
  317. $uploaddir = $conf->commande->multidir_output[$conf->entity];
  318. $triggersendname = 'ORDER_SENTBYMAIL';
  319. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  320. }
  321. // Closed records
  322. // if (!$error && $massaction === 'setbilled' && $permissiontoclose) {
  323. // }
  324. /*
  325. * View
  326. */
  327. $now = dol_now();
  328. $form = new Form($db);
  329. $formother = new FormOther($db);
  330. $formfile = new FormFile($db);
  331. $formmargin = null;
  332. if (isModEnabled('margin')) {
  333. $formmargin = new FormMargin($db);
  334. }
  335. $companystatic = new Societe($db);
  336. $formcompany = new FormCompany($db);
  337. $projectstatic = new Project($db);
  338. $title = $langs->trans("Orders");
  339. $help_url = "EN:Module_Customers_Orders|FR:Module_Commandes_Clients|ES:Módulo_Pedidos_de_clientes";
  340. // llxHeader('',$title,$help_url);
  341. $sql = 'SELECT';
  342. if ($sall || $search_product_category_array > 0 || $search_user > 0) {
  343. $sql = 'SELECT DISTINCT';
  344. }
  345. $sql .= ' s.rowid as socid, s.nom as name, s.name_alias as alias, s.email, s.phone, s.fax, s.address, s.town, s.zip, s.fk_pays, s.client, s.code_client,';
  346. $sql .= " typent.code as typent_code,";
  347. $sql .= " state.code_departement as state_code, state.nom as state_name,";
  348. $sql .= " country.code as country_code,";
  349. $sql .= ' c.rowid as c_rowid, c.ref, c.ref_client, c.fk_user_author,';
  350. $sql .= ' c.fk_multicurrency, c.multicurrency_code, c.multicurrency_tx, c.multicurrency_total_ht, c.multicurrency_total_tva as multicurrency_total_vat, c.multicurrency_total_ttc,';
  351. $sql .= ' c.total_ht as c_total_ht, c.total_tva as c_total_tva, c.total_ttc as c_total_ttc, c.fk_warehouse as warehouse,';
  352. $sql .= ' c.date_valid, c.date_commande, c.note_public, c.note_private, c.date_livraison as date_delivery, c.fk_statut, c.facture as billed,';
  353. $sql .= ' c.date_creation as date_creation, c.tms as date_update, c.date_cloture as date_cloture,';
  354. $sql .= ' p.rowid as project_id, p.ref as project_ref, p.title as project_label,';
  355. $sql .= ' u.login, u.lastname, u.firstname, u.email as user_email, u.statut as user_statut, u.entity, u.photo, u.office_phone, u.office_fax, u.user_mobile, u.job, u.gender,';
  356. $sql .= ' c.fk_cond_reglement,c.deposit_percent,c.fk_mode_reglement,c.fk_shipping_method,';
  357. $sql .= ' c.fk_input_reason, c.import_key,';
  358. // Lines or order
  359. $sql .= ' cdet.rowid, cdet.description, cdet.qty, cdet.product_type, cdet.fk_product, cdet.total_ht, cdet.total_tva, cdet.total_ttc,';
  360. $sql .= ' pr.rowid as product_rowid, pr.ref as product_ref, pr.label as product_label, pr.barcode as product_barcode, pr.tobatch as product_batch, pr.tosell as product_status, pr.tobuy as product_status_buy';
  361. if (($search_categ_cus > 0) || ($search_categ_cus == -2)) {
  362. $sql .= ", cc.fk_categorie, cc.fk_soc";
  363. }
  364. // Add fields from extrafields
  365. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  366. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  367. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
  368. }
  369. }
  370. // Add fields from hooks
  371. $parameters = array();
  372. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
  373. $sql .= $hookmanager->resPrint;
  374. $sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s';
  375. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
  376. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
  377. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)";
  378. if (($search_categ_cus > 0) || ($search_categ_cus == -2)) {
  379. $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_societe as cc ON s.rowid = cc.fk_soc"; // We'll need this table joined to the select in order to filter by categ
  380. }
  381. // Détail commande
  382. $sql .= ', '.MAIN_DB_PREFIX.'commandedet as cdet';
  383. $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'commande as c ON cdet.fk_commande=c.rowid';
  384. $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as pr ON pr.rowid=cdet.fk_product';
  385. if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
  386. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."commande_extrafields as ef on (c.rowid = ef.fk_object)";
  387. }
  388. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as p ON p.rowid = c.fk_projet";
  389. $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as u ON c.fk_user_author = u.rowid';
  390. if ($search_user > 0) {
  391. $sql .= ", ".MAIN_DB_PREFIX."element_contact as ec";
  392. $sql .= ", ".MAIN_DB_PREFIX."c_type_contact as tc";
  393. }
  394. // Add table from hooks
  395. $parameters = array();
  396. $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
  397. $sql .= $hookmanager->resPrint;
  398. $sql .= ' WHERE c.fk_soc = s.rowid';
  399. $sql .= ' AND c.entity IN ('.getEntity('commande').')';
  400. $sql .= ' AND cdet.product_type <> 9';
  401. if (!empty($productobuy)) {
  402. $sql .= " AND pr.tobuy = 1";
  403. }
  404. if (!empty($productonly)) {
  405. $sql .= " AND (cdet.product_type = 0 OR cdet.product_type = 1)";
  406. }
  407. if (!empty($disablelinefree)) {
  408. $sql .= " AND cdet.fk_product IS NOT NULL";
  409. }
  410. if ($socid > 0) {
  411. $sql .= ' AND s.rowid = '.((int) $socid);
  412. }
  413. if ($search_id) {
  414. $sql .= natural_search('cdet.rowid', $search_id);
  415. }
  416. if ($search_refProduct) {
  417. $sql .= natural_search('pr.ref', $search_refProduct);
  418. }
  419. if ($search_descProduct) {
  420. $sql .= natural_search(array('pr.label','cdet.description'), $search_descProduct);
  421. }
  422. if ($search_ref) {
  423. $sql .= natural_search('c.ref', $search_ref);
  424. }
  425. if ($search_ref_customer) {
  426. $sql .= natural_search('c.ref_client', $search_ref_customer);
  427. }
  428. if ($sall) {
  429. $sql .= natural_search(array_keys($fieldstosearchall), $sall);
  430. }
  431. if ($search_billed != '' && $search_billed >= 0) {
  432. $sql .= ' AND c.facture = '.((int) $search_billed);
  433. }
  434. if ($search_status != '') {
  435. if ($search_status <= 3 && $search_status >= -1) { // status from -1 to 3 are real status (other are virtual combination)
  436. if ($search_status == 1 && !isModEnabled('expedition')) {
  437. $sql .= ' AND c.fk_statut IN (1,2)'; // If module expedition disabled, we include order with status 'sending in process' into 'validated'
  438. } else {
  439. $sql .= ' AND c.fk_statut = '.((int) $search_status); // brouillon, validee, en cours, annulee
  440. }
  441. }
  442. if ($search_status == -2) { // To process
  443. //$sql.= ' AND c.fk_statut IN (1,2,3) AND c.facture = 0';
  444. $sql .= " AND ((c.fk_statut IN (1,2)) OR (c.fk_statut = 3 AND c.facture = 0))"; // If status is 2 and facture=1, it must be selected
  445. }
  446. if ($search_status == -3) { // To bill
  447. //$sql.= ' AND c.fk_statut in (1,2,3)';
  448. //$sql.= ' AND c.facture = 0'; // invoice not created
  449. $sql .= ' AND ((c.fk_statut IN (1,2)) OR (c.fk_statut = 3 AND c.facture = 0))'; // validated, in process or closed but not billed
  450. }
  451. if ($search_status == -4) { // "validate and in progress"
  452. $sql .= ' AND (c.fk_statut IN (1,2))'; // validated, in process
  453. }
  454. }
  455. if ($search_datecloture_start) {
  456. $sql .= " AND c.date_cloture >= '".$db->idate($search_datecloture_start)."'";
  457. }
  458. if ($search_datecloture_end) {
  459. $sql .= " AND c.date_cloture <= '".$db->idate($search_datecloture_end)."'";
  460. }
  461. if ($search_dateorder_start) {
  462. $sql .= " AND c.date_commande >= '".$db->idate($search_dateorder_start)."'";
  463. }
  464. if ($search_dateorder_end) {
  465. $sql .= " AND c.date_commande <= '".$db->idate($search_dateorder_end)."'";
  466. }
  467. if ($search_datedelivery_start) {
  468. $sql .= " AND c.date_livraison >= '".$db->idate($search_datedelivery_start)."'";
  469. }
  470. if ($search_datedelivery_end) {
  471. $sql .= " AND c.date_livraison <= '".$db->idate($search_datedelivery_end)."'";
  472. }
  473. if ($search_town) {
  474. $sql .= natural_search('s.town', $search_town);
  475. }
  476. if ($search_zip) {
  477. $sql .= natural_search("s.zip", $search_zip);
  478. }
  479. if ($search_state) {
  480. $sql .= natural_search("state.nom", $search_state);
  481. }
  482. if ($search_country) {
  483. $sql .= " AND s.fk_pays IN (".$db->sanitize($search_country).')';
  484. }
  485. if ($search_type_thirdparty && $search_type_thirdparty != '-1') {
  486. $sql .= " AND s.fk_typent IN (".$db->sanitize($search_type_thirdparty).')';
  487. }
  488. if ($search_company) {
  489. $sql .= natural_search('s.nom', $search_company);
  490. }
  491. if ($search_company_alias) {
  492. $sql .= natural_search('s.name_alias', $search_company_alias);
  493. }
  494. if ($search_user > 0) {
  495. $sql .= " AND ec.fk_c_type_contact = tc.rowid AND tc.element='commande' AND tc.source='internal' AND ec.element_id = c.rowid AND ec.fk_socpeople = ".((int) $search_user);
  496. }
  497. if ($search_total_ht != '') {
  498. $sql .= natural_search('cdet.total_ht', $search_total_ht, 1);
  499. }
  500. if ($search_total_vat != '') {
  501. $sql .= natural_search('cdet.total_tva', $search_total_vat, 1);
  502. }
  503. if ($search_total_ttc != '') {
  504. $sql .= natural_search('cdet.total_ttc', $search_total_ttc, 1);
  505. }
  506. if ($search_warehouse != '' && $search_warehouse > 0) {
  507. $sql .= natural_search('c.fk_warehouse', $search_warehouse, 1);
  508. }
  509. if ($search_multicurrency_code != '') {
  510. $sql .= " AND c.multicurrency_code = '".$db->escape($search_multicurrency_code)."'";
  511. }
  512. if ($search_multicurrency_tx != '') {
  513. $sql .= natural_search('c.multicurrency_tx', $search_multicurrency_tx, 1);
  514. }
  515. if ($search_multicurrency_montant_ht != '') {
  516. $sql .= natural_search('c.multicurrency_total_ht', $search_multicurrency_montant_ht, 1);
  517. }
  518. if ($search_multicurrency_montant_vat != '') {
  519. $sql .= natural_search('c.multicurrency_total_tva', $search_multicurrency_montant_vat, 1);
  520. }
  521. if ($search_multicurrency_montant_ttc != '') {
  522. $sql .= natural_search('c.multicurrency_total_ttc', $search_multicurrency_montant_ttc, 1);
  523. }
  524. if ($search_login) {
  525. $sql .= natural_search(array("u.login", "u.firstname", "u.lastname"), $search_login);
  526. }
  527. if ($search_project_ref != '') {
  528. $sql .= natural_search("p.ref", $search_project_ref);
  529. }
  530. if ($search_project != '') {
  531. $sql .= natural_search("p.title", $search_project);
  532. }
  533. if ($search_categ_cus > 0) {
  534. $sql .= " AND cc.fk_categorie = ".((int) $search_categ_cus);
  535. }
  536. if ($search_categ_cus == -2) {
  537. $sql .= " AND cc.fk_categorie IS NULL";
  538. }
  539. if ($search_fk_cond_reglement > 0) {
  540. $sql .= " AND c.fk_cond_reglement = ".((int) $search_fk_cond_reglement);
  541. }
  542. if ($search_fk_shipping_method > 0) {
  543. $sql .= " AND c.fk_shipping_method = ".((int) $search_fk_shipping_method);
  544. }
  545. if ($search_fk_mode_reglement > 0) {
  546. $sql .= " AND c.fk_mode_reglement = ".((int) $search_fk_mode_reglement);
  547. }
  548. if ($search_fk_input_reason > 0) {
  549. $sql .= " AND c.fk_input_reason = ".((int) $search_fk_input_reason);
  550. }
  551. // Search on sale representative
  552. if ($search_sale && $search_sale != '-1') {
  553. if ($search_sale == -2) {
  554. $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = c.fk_soc)";
  555. } elseif ($search_sale > 0) {
  556. $sql .= " AND EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = c.fk_soc AND sc.fk_user = ".((int) $search_sale).")";
  557. }
  558. }
  559. // Search for tag/category ($searchCategoryProductList is an array of ID)
  560. $searchCategoryProductList = $search_product_category_array;
  561. if (!empty($searchCategoryProductList)) {
  562. $searchCategoryProjectSqlList = array();
  563. $listofcategoryid = '';
  564. foreach ($searchCategoryProductList as $searchCategoryProject) {
  565. if (intval($searchCategoryProject) == -2) {
  566. $searchCategoryProjectSqlList[] = "NOT EXISTS (SELECT cp.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as cp WHERE cdet.fk_product = cp.fk_product)";
  567. } elseif (intval($searchCategoryProject) > 0) {
  568. if ($searchCategoryProductOperator == 0) {
  569. $searchCategoryProjectSqlList[] = " EXISTS (SELECT cp.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as cp WHERE cdet.fk_product = cp.fk_product AND cp.fk_categorie = ".((int) $searchCategoryProject).")";
  570. } else {
  571. $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryProject);
  572. }
  573. }
  574. }
  575. if ($listofcategoryid) {
  576. $searchCategoryProjectSqlList[] = " EXISTS (SELECT cp.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as cp WHERE cdet.fk_product = cp.fk_product AND cp.fk_categorie IN (".$db->sanitize($listofcategoryid)."))";
  577. }
  578. if ($searchCategoryProductOperator == 1) {
  579. if (!empty($searchCategoryProjectSqlList)) {
  580. $sql .= " AND (".implode(' OR ', $searchCategoryProjectSqlList).")";
  581. }
  582. } else {
  583. if (!empty($searchCategoryProjectSqlList)) {
  584. $sql .= " AND (".implode(' AND ', $searchCategoryProjectSqlList).")";
  585. }
  586. }
  587. }
  588. // Add where from extra fields
  589. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  590. // Add where from hooks
  591. $parameters = array();
  592. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
  593. $sql .= $hookmanager->resPrint;
  594. // Add HAVING from hooks
  595. $parameters = array();
  596. $reshook = $hookmanager->executeHooks('printFieldListHaving', $parameters, $object); // Note that $action and $object may have been modified by hook
  597. $sql .= empty($hookmanager->resPrint) ? "" : " HAVING 1=1 ".$hookmanager->resPrint;
  598. $sql .= $db->order($sortfield, $sortorder);
  599. // Count total nb of records
  600. $nbtotalofrecords = '';
  601. if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
  602. $result = $db->query($sql);
  603. $nbtotalofrecords = $db->num_rows($result);
  604. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
  605. $page = 0;
  606. $offset = 0;
  607. }
  608. }
  609. $sql .= $db->plimit($limit + 1, $offset);
  610. //print $sql;
  611. $resql = $db->query($sql);
  612. if ($resql) {
  613. if ($socid > 0) {
  614. $soc = new Societe($db);
  615. $soc->fetch($socid);
  616. $title = $langs->trans('ListOrderLigne').' - '.$soc->name;
  617. if (empty($search_company)) {
  618. $search_company = $soc->name;
  619. }
  620. } else {
  621. $title = $langs->trans('ListOrderLigne');
  622. }
  623. if (strval($search_status) == '0') {
  624. $title .= ' - '.$langs->trans('StatusOrderDraftShort');
  625. }
  626. if ($search_status == 1) {
  627. $title .= ' - '.$langs->trans('StatusOrderValidatedShort');
  628. }
  629. if ($search_status == 2) {
  630. $title .= ' - '.$langs->trans('StatusOrderSentShort');
  631. }
  632. if ($search_status == 3) {
  633. $title .= ' - '.$langs->trans('StatusOrderToBillShort');
  634. }
  635. if ($search_status == -1) {
  636. $title .= ' - '.$langs->trans('StatusOrderCanceledShort');
  637. }
  638. if ($search_status == -2) {
  639. $title .= ' - '.$langs->trans('StatusOrderToProcessShort');
  640. }
  641. if ($search_status == -3) {
  642. $title .= ' - '.$langs->trans('StatusOrderValidated').', '.(!isModEnabled('expedition') ? '' : $langs->trans("StatusOrderSent").', ').$langs->trans('StatusOrderToBill');
  643. }
  644. if ($search_status == -4) {
  645. $title .= ' - '.$langs->trans("StatusOrderValidatedShort").'+'.$langs->trans("StatusOrderSentShort");
  646. }
  647. $num = $db->num_rows($resql);
  648. $arrayofselected = is_array($toselect) ? $toselect : array();
  649. if ($num == 1 && getDolGlobalString('MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE') && $sall) {
  650. $obj = $db->fetch_object($resql);
  651. $id = $obj->rowid;
  652. header("Location: ".DOL_URL_ROOT.'/commande/card.php?id='.$id);
  653. exit;
  654. }
  655. llxHeader('', $title, $help_url);
  656. $param = '';
  657. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  658. $param .= '&contextpage='.urlencode($contextpage);
  659. }
  660. if ($limit > 0 && $limit != $conf->liste_limit) {
  661. $param .= '&limit='.((int) $limit);
  662. }
  663. if ($sall) {
  664. $param .= '&sall='.urlencode($sall);
  665. }
  666. if ($socid > 0) {
  667. $param .= '&socid='.urlencode($socid);
  668. }
  669. if ($search_id) {
  670. $param .= '&search_id='.urlencode($search_id);
  671. }
  672. // Détail commande
  673. if ($search_refProduct) {
  674. $param .= '&search_refProduct='.urlencode($search_refProduct);
  675. }
  676. if ($search_descProduct) {
  677. $param .= '&search_descProduct='.urlencode($search_descProduct);
  678. }
  679. if ($search_status != '') {
  680. $param .= '&search_status='.urlencode($search_status);
  681. }
  682. if ($search_datecloture_start) {
  683. $param .= '&search_datecloture_startday='.dol_print_date($search_datecloture_start, '%d').'&search_datecloture_startmonth='.dol_print_date($search_datecloture_start, '%m').'&search_datecloture_startyear='.dol_print_date($search_datecloture_start, '%Y');
  684. }
  685. if ($search_datecloture_end) {
  686. $param .= '&search_datecloture_endday='.dol_print_date($search_datecloture_end, '%d').'&search_datecloture_endmonth='.dol_print_date($search_datecloture_end, '%m').'&search_datecloture_endyear='.dol_print_date($search_datecloture_end, '%Y');
  687. }
  688. if ($search_dateorder_start) {
  689. $param .= '&search_dateorder_start_day='.dol_print_date($search_dateorder_start, '%d').'&search_dateorder_start_month='.dol_print_date($search_dateorder_start, '%m').'&search_dateorder_start_year='.dol_print_date($search_dateorder_start, '%Y');
  690. }
  691. if ($search_dateorder_end) {
  692. $param .= '&search_dateorder_end_day='.dol_print_date($search_dateorder_end, '%d').'&search_dateorder_end_month='.dol_print_date($search_dateorder_end, '%m').'&search_dateorder_end_year='.dol_print_date($search_dateorder_end, '%Y');
  693. }
  694. if ($search_datedelivery_start) {
  695. $param .= '&search_datedelivery_start_day='.dol_print_date($search_datedelivery_start, '%d').'&search_datedelivery_start_month='.dol_print_date($search_datedelivery_start, '%m').'&search_datedelivery_start_year='.dol_print_date($search_datedelivery_start, '%Y');
  696. }
  697. if ($search_datedelivery_end) {
  698. $param .= '&search_datedelivery_end_day='.dol_print_date($search_datedelivery_end, '%d').'&search_datedelivery_end_month='.dol_print_date($search_datedelivery_end, '%m').'&search_datedelivery_end_year='.dol_print_date($search_datedelivery_end, '%Y');
  699. }
  700. if ($search_ref) {
  701. $param .= '&search_ref='.urlencode($search_ref);
  702. }
  703. if ($search_company) {
  704. $param .= '&search_company='.urlencode($search_company);
  705. }
  706. if ($search_company_alias) {
  707. $param .= '&search_company_alias='.urlencode($search_company_alias);
  708. }
  709. if ($search_ref_customer) {
  710. $param .= '&search_ref_customer='.urlencode($search_ref_customer);
  711. }
  712. if ($search_user > 0) {
  713. $param .= '&search_user='.urlencode($search_user);
  714. }
  715. if ($search_sale > 0) {
  716. $param .= '&search_sale='.urlencode($search_sale);
  717. }
  718. if ($search_total_ht != '') {
  719. $param .= '&search_total_ht='.urlencode($search_total_ht);
  720. }
  721. if ($search_total_vat != '') {
  722. $param .= '&search_total_vat='.urlencode($search_total_vat);
  723. }
  724. if ($search_total_ttc != '') {
  725. $param .= '&search_total_ttc='.urlencode($search_total_ttc);
  726. }
  727. if ($search_warehouse != '') {
  728. $param .= '&search_warehouse='.urlencode($search_warehouse);
  729. }
  730. if ($search_login) {
  731. $param .= '&search_login='.urlencode($search_login);
  732. }
  733. if ($search_multicurrency_code != '') {
  734. $param .= '&search_multicurrency_code='.urlencode($search_multicurrency_code);
  735. }
  736. if ($search_multicurrency_tx != '') {
  737. $param .= '&search_multicurrency_tx='.urlencode($search_multicurrency_tx);
  738. }
  739. if ($search_multicurrency_montant_ht != '') {
  740. $param .= '&search_multicurrency_montant_ht='.urlencode($search_multicurrency_montant_ht);
  741. }
  742. if ($search_multicurrency_montant_vat != '') {
  743. $param .= '&search_multicurrency_montant_vat='.urlencode($search_multicurrency_montant_vat);
  744. }
  745. if ($search_multicurrency_montant_ttc != '') {
  746. $param .= '&search_multicurrency_montant_ttc='.urlencode($search_multicurrency_montant_ttc);
  747. }
  748. if ($search_project_ref >= 0) {
  749. $param .= "&search_project_ref=".urlencode($search_project_ref);
  750. }
  751. if ($search_town != '') {
  752. $param .= '&search_town='.urlencode($search_town);
  753. }
  754. if ($search_zip != '') {
  755. $param .= '&search_zip='.urlencode($search_zip);
  756. }
  757. if ($search_state != '') {
  758. $param .= '&search_state='.urlencode($search_state);
  759. }
  760. if ($search_country != '') {
  761. $param .= '&search_country='.urlencode($search_country);
  762. }
  763. if ($search_type_thirdparty && $search_type_thirdparty != '-1') {
  764. $param .= '&search_type_thirdparty='.urlencode($search_type_thirdparty);
  765. }
  766. if (!empty($search_product_category_array)) {
  767. foreach ($search_product_category_array as $tmpval) {
  768. $param .= '&search_categegory_product_list[]='.urlencode($tmpval);
  769. }
  770. }
  771. if (($search_categ_cus > 0) || ($search_categ_cus == -2)) {
  772. $param .= '&search_categ_cus='.urlencode($search_categ_cus);
  773. }
  774. if ($show_files) {
  775. $param .= '&show_files='.urlencode($show_files);
  776. }
  777. if ($optioncss != '') {
  778. $param .= '&optioncss='.urlencode($optioncss);
  779. }
  780. if ($search_billed != '') {
  781. $param .= '&search_billed='.urlencode($search_billed);
  782. }
  783. if ($search_fk_cond_reglement > 0) {
  784. $param .= '&search_fk_cond_reglement='.urlencode($search_fk_cond_reglement);
  785. }
  786. if ($search_fk_shipping_method > 0) {
  787. $param .= '&search_fk_shipping_method='.urlencode($search_fk_shipping_method);
  788. }
  789. if ($search_fk_mode_reglement > 0) {
  790. $param .= '&search_fk_mode_reglement='.urlencode($search_fk_mode_reglement);
  791. }
  792. if ($search_fk_input_reason > 0) {
  793. $param .= '&search_fk_input_reason='.urlencode($search_fk_input_reason);
  794. }
  795. if (!empty($productobuy)) {
  796. $param .= '&productobuy='.urlencode($productobuy);
  797. }
  798. if (!empty($productonly)) {
  799. $param .= '&productonly='.urlencode($productonly);
  800. }
  801. if (!empty($disablelinefree)) {
  802. $param .= '&disablelinefree='.urlencode($disablelinefree);
  803. }
  804. // Add $param from extra fields
  805. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  806. // Add $param from hooks
  807. $parameters = array();
  808. $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
  809. $param .= $hookmanager->resPrint;
  810. // List of mass actions available
  811. $arrayofmassactions = array(
  812. // TODO add mass action here
  813. // 'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
  814. );
  815. // if ($permissiontovalidate) {
  816. // $arrayofmassactions['prevalidate'] = img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate");
  817. // }
  818. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  819. $url = DOL_URL_ROOT.'/commande/card.php?action=create';
  820. if (!empty($socid)) {
  821. $url .= '&socid='.$socid;
  822. }
  823. $newcardbutton = '';//dolGetButtonTitle($langs->trans('NewOrder'), '', 'fa fa-plus-circle', $url, '', $contextpage == 'orderlistdet' && $permissiontoadd);
  824. // Lines of title fields
  825. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
  826. if ($optioncss != '') {
  827. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  828. }
  829. print '<input type="hidden" name="token" value="'.newToken().'">';
  830. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  831. print '<input type="hidden" name="action" value="list">';
  832. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  833. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  834. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  835. print '<input type="hidden" name="search_status" value="'.$search_status.'">';
  836. print '<input type="hidden" name="socid" value="'.$socid.'">';
  837. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'order', 0, $newcardbutton, '', $limit, 0, 0, 1);
  838. $topicmail = "SendOrderRef";
  839. $modelmail = "order_send";
  840. $objecttmp = new Commande($db);
  841. $trackid = 'ord'.$object->id;
  842. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  843. if ($sall) {
  844. foreach ($fieldstosearchall as $key => $val) {
  845. $fieldstosearchall[$key] = $langs->trans($val);
  846. }
  847. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'</div>';
  848. }
  849. $moreforfilter = '';
  850. $moreforfilter .= '<div class="divsearchfield">';
  851. $moreforfilter .= '<input type="checkbox" id="productobuy" name="productobuy"'.(!empty($productobuy) ? 'value="productobuychecked" checked' : '').'><label for="productobuy">'.$langs->trans("productobuy").'</label>';
  852. $moreforfilter .= '</div>';
  853. $moreforfilter .= '<div class="divsearchfield">';
  854. $moreforfilter .= '<input type="checkbox" id="productonly" name="productonly"'.(!empty($productonly) ? 'value="productonlychecked" checked' : '').'><label for="productonly">'.$langs->trans("productonly").'</label>';
  855. $moreforfilter .= '</div>';
  856. $moreforfilter .= '<div class="divsearchfield">';
  857. $moreforfilter .= '<input type="checkbox" id="disablelinefree" name="disablelinefree"'.(!empty($disablelinefree) ? 'value="disablelinefreechecked" checked' : '').'><label for="disablelinefree">'.$langs->trans("disablelinefree").'</label>';
  858. $moreforfilter .= '</div><br>';
  859. // If the user can view prospects other than his'
  860. if ($user->hasRight('user', 'user', 'lire')) {
  861. $langs->load("commercial");
  862. $moreforfilter .= '<div class="divsearchfield">';
  863. $tmptitle = $langs->trans('ThirdPartiesOfSaleRepresentative');
  864. $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, $tmptitle, 'maxwidth250 widthcentpercentminusx');
  865. $moreforfilter .= '</div>';
  866. }
  867. // If the user can view other users
  868. if ($user->hasRight('user', 'user', 'lire')) {
  869. $moreforfilter .= '<div class="divsearchfield">';
  870. $tmptitle = $langs->trans('LinkedToSpecificUsers');
  871. $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$form->select_dolusers($search_user, 'search_user', $tmptitle, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth250 widthcentpercentminusx');
  872. $moreforfilter .= '</div>';
  873. }
  874. // Filter on categories
  875. if (isModEnabled("categorie") && $user->hasRight('categorie', 'lire') && ($user->hasRight('produit', 'lire') || $user->hasRight('service', 'lire'))) {
  876. $formcategory = new FormCategory($db);
  877. $moreforfilter .= $formcategory->getFilterBox(Categorie::TYPE_PRODUCT, $search_product_category_array, 'minwidth300imp minwidth300', $searchCategoryProductOperator ? $searchCategoryProductOperator : 0);
  878. }
  879. if (isModEnabled("categorie") && $user->hasRight('categorie', 'lire')) {
  880. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  881. $moreforfilter .= '<div class="divsearchfield">';
  882. $tmptitle = $langs->trans('CustomersProspectsCategoriesShort');
  883. $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"').$formother->select_categories('customer', $search_categ_cus, 'search_categ_cus', 1, $tmptitle, 'maxwidth300 widthcentpercentminusx');
  884. $moreforfilter .= '</div>';
  885. }
  886. if (isModEnabled('stock') && getDolGlobalString('WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER')) {
  887. require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
  888. $formproduct = new FormProduct($db);
  889. $moreforfilter .= '<div class="divsearchfield">';
  890. $tmptitle = $langs->trans('Warehouse');
  891. $moreforfilter .= img_picto($tmptitle, 'stock', 'class="pictofixedwidth"').$formproduct->selectWarehouses($search_warehouse, 'search_warehouse', '', 1, 0, 0, $tmptitle, 0, 0, array(), 'maxwidth250 widthcentpercentminusx');
  892. $moreforfilter .= '</div>';
  893. }
  894. $parameters = array();
  895. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
  896. if (empty($reshook)) {
  897. $moreforfilter .= $hookmanager->resPrint;
  898. } else {
  899. $moreforfilter = $hookmanager->resPrint;
  900. }
  901. if (!empty($moreforfilter)) {
  902. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  903. print $moreforfilter;
  904. print '</div>';
  905. }
  906. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  907. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN', '')); // This also change content of $arrayfields
  908. $selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
  909. if (GETPOST('autoselectall', 'int')) {
  910. $selectedfields .= '<script>';
  911. $selectedfields .= ' $(document).ready(function() {';
  912. $selectedfields .= ' console.log("Autoclick on checkforselects");';
  913. $selectedfields .= ' $("#checkforselects").click();';
  914. $selectedfields .= ' $("#massaction").val("createbills").change();';
  915. $selectedfields .= ' });';
  916. $selectedfields .= '</script>';
  917. }
  918. print '<div class="div-table-responsive">';
  919. print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  920. print '<tr class="liste_titre_filter">';
  921. // Action column
  922. if (getDolGlobalInt('MAIN_CHECKBOX_LEFT_COLUMN')) {
  923. print '<td class="liste_titre" align="middle">';
  924. $searchpicto = $form->showFilterButtons('left');
  925. print $searchpicto;
  926. print '</td>';
  927. }
  928. // ID
  929. if (!empty($arrayfields['rowid']['checked'])) {
  930. print '<td class="liste_titre" data-key="id">';
  931. print '<input class="flat searchstring" type="text" name="search_id" size="1" value="'.dol_escape_htmltag($search_id).'">';
  932. print '</td>';
  933. }
  934. // Détail commande
  935. if (!empty($arrayfields['pr.ref']['checked'])) {
  936. print '<td class="liste_titre">';
  937. print '<input class="flat" size="6" type="text" name="search_refProduct" value="'.dol_escape_htmltag($search_refProduct).'">';
  938. print '</td>';
  939. }
  940. // Product Description
  941. if (!empty($arrayfields['pr.desc']['checked'])) {
  942. print '<td class="liste_titre">';
  943. print '<input class="flat" size="6" type="text" name="search_descProduct" value="'.dol_escape_htmltag($search_descProduct).'">';
  944. print '</td>';
  945. }
  946. // Product QtyOrdered
  947. if (!empty($arrayfields['cdet.qty']['checked'])) {
  948. print '<td class="liste_titre"></td>';
  949. }
  950. // Ref
  951. if (!empty($arrayfields['c.ref']['checked'])) {
  952. print '<td class="liste_titre">';
  953. print '<input class="flat" size="6" type="text" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">';
  954. print '</td>';
  955. }
  956. // Ref customer
  957. if (!empty($arrayfields['c.ref_client']['checked'])) {
  958. print '<td class="liste_titre" align="left">';
  959. print '<input class="flat" type="text" size="6" name="search_ref_customer" value="'.dol_escape_htmltag($search_ref_customer).'">';
  960. print '</td>';
  961. }
  962. // Project ref
  963. if (!empty($arrayfields['p.ref']['checked'])) {
  964. print '<td class="liste_titre"><input type="text" class="flat" size="6" name="search_project_ref" value="'.dol_escape_htmltag($search_project_ref).'"></td>';
  965. }
  966. // Project title
  967. if (!empty($arrayfields['p.title']['checked'])) {
  968. print '<td class="liste_titre"><input type="text" class="flat" size="6" name="search_project" value="'.dol_escape_htmltag($search_project).'"></td>';
  969. }
  970. // Thirpdarty
  971. if (!empty($arrayfields['s.nom']['checked'])) {
  972. print '<td class="liste_titre" align="left">';
  973. print '<input class="flat maxwidth100" type="text" name="search_company" value="'.dol_escape_htmltag($search_company).'">';
  974. print '</td>';
  975. }
  976. // Alias
  977. if (!empty($arrayfields['s.name_alias']['checked'])) {
  978. print '<td class="liste_titre" align="left">';
  979. print '<input class="flat maxwidth100" type="text" name="search_company_alias" value="'.dol_escape_htmltag($search_company_alias).'">';
  980. print '</td>';
  981. }
  982. // Town
  983. if (!empty($arrayfields['s.town']['checked'])) {
  984. print '<td class="liste_titre"><input class="flat" type="text" size="4" name="search_town" value="'.dol_escape_htmltag($search_town).'"></td>';
  985. }
  986. // Zip
  987. if (!empty($arrayfields['s.zip']['checked'])) {
  988. print '<td class="liste_titre"><input class="flat" type="text" size="4" name="search_zip" value="'.dol_escape_htmltag($search_zip).'"></td>';
  989. }
  990. // State
  991. if (!empty($arrayfields['state.nom']['checked'])) {
  992. print '<td class="liste_titre">';
  993. print '<input class="flat" size="4" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
  994. print '</td>';
  995. }
  996. // Country
  997. if (!empty($arrayfields['country.code_iso']['checked'])) {
  998. print '<td class="liste_titre" align="center">';
  999. print $form->select_country($search_country, 'search_country', '', 0, 'minwidth100imp maxwidth100');
  1000. print '</td>';
  1001. }
  1002. // Company type
  1003. if (!empty($arrayfields['typent.code']['checked'])) {
  1004. print '<td class="liste_titre maxwidthonsmartphone" align="center">';
  1005. print $form->selectarray("search_type_thirdparty", $formcompany->typent_array(0), $search_type_thirdparty, 1, 0, 0, '', 0, 0, 0, (!getDolGlobalString('SOCIETE_SORT_ON_TYPEENT') ? 'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT), '', 1);
  1006. print '</td>';
  1007. }
  1008. // Date order
  1009. if (!empty($arrayfields['c.date_commande']['checked'])) {
  1010. print '<td class="liste_titre center">';
  1011. print '<div class="nowrapfordate">';
  1012. print $form->selectDate($search_dateorder_start ? $search_dateorder_start : -1, 'search_dateorder_start_', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  1013. print '</div>';
  1014. print '<div class="nowrapfordate">';
  1015. print $form->selectDate($search_dateorder_end ? $search_dateorder_end : -1, 'search_dateorder_end_', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  1016. print '</div>';
  1017. print '</td>';
  1018. }
  1019. if (!empty($arrayfields['c.date_delivery']['checked'])) {
  1020. print '<td class="liste_titre center">';
  1021. print '<div class="nowrapfordate">';
  1022. print $form->selectDate($search_datedelivery_start ? $search_datedelivery_start : -1, 'search_datedelivery_start_', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  1023. print '</div>';
  1024. print '<div class="nowrapfordate">';
  1025. print $form->selectDate($search_datedelivery_end ? $search_datedelivery_end : -1, 'search_datedelivery_end_', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  1026. print '</div>';
  1027. print '</td>';
  1028. }
  1029. // Shipping Method
  1030. if (!empty($arrayfields['c.fk_shipping_method']['checked'])) {
  1031. print '<td class="liste_titre">';
  1032. $form->selectShippingMethod($search_fk_shipping_method, 'search_fk_shipping_method', '', 1, '', 1);
  1033. print '</td>';
  1034. }
  1035. // Payment term
  1036. if (!empty($arrayfields['c.fk_cond_reglement']['checked'])) {
  1037. print '<td class="liste_titre">';
  1038. $form->select_conditions_paiements($search_fk_cond_reglement, 'search_fk_cond_reglement', 1, 1, 1);
  1039. print '</td>';
  1040. }
  1041. // Payment mode
  1042. if (!empty($arrayfields['c.fk_mode_reglement']['checked'])) {
  1043. print '<td class="liste_titre">';
  1044. $form->select_types_paiements($search_fk_mode_reglement, 'search_fk_mode_reglement', '', 0, 1, 1, 0, -1);
  1045. print '</td>';
  1046. }
  1047. // Channel
  1048. if (!empty($arrayfields['c.fk_input_reason']['checked'])) {
  1049. print '<td class="liste_titre">';
  1050. $form->selectInputReason($search_fk_input_reason, 'search_fk_input_reason', '', 1, '', 1);
  1051. print '</td>';
  1052. }
  1053. if (!empty($arrayfields['cdet.total_ht']['checked'])) {
  1054. // Amount
  1055. print '<td class="liste_titre right">';
  1056. print '<input class="flat" type="text" size="4" name="search_total_ht" value="'.dol_escape_htmltag($search_total_ht).'">';
  1057. print '</td>';
  1058. }
  1059. if (!empty($arrayfields['c.total_vat']['checked'])) {
  1060. // Amount
  1061. print '<td class="liste_titre right">';
  1062. print '<input class="flat" type="text" size="4" name="search_total_vat" value="'.dol_escape_htmltag($search_total_vat).'">';
  1063. print '</td>';
  1064. }
  1065. if (!empty($arrayfields['cdet.total_ttc']['checked'])) {
  1066. // Amount
  1067. print '<td class="liste_titre right">';
  1068. print '<input class="flat" type="text" size="5" name="search_total_ttc" value="'.$search_total_ttc.'">';
  1069. print '</td>';
  1070. }
  1071. if (!empty($arrayfields['c.fk_warehouse']['checked'])) {
  1072. // Warehouse
  1073. print '<td class="liste_titre right"></td>';
  1074. }
  1075. if (!empty($arrayfields['c.multicurrency_code']['checked'])) {
  1076. // Currency
  1077. print '<td class="liste_titre">';
  1078. print $form->selectMultiCurrency($search_multicurrency_code, 'search_multicurrency_code', 1);
  1079. print '</td>';
  1080. }
  1081. if (!empty($arrayfields['c.multicurrency_tx']['checked'])) {
  1082. // Currency rate
  1083. print '<td class="liste_titre">';
  1084. print '<input class="flat" type="text" size="4" name="search_multicurrency_tx" value="'.dol_escape_htmltag($search_multicurrency_tx).'">';
  1085. print '</td>';
  1086. }
  1087. if (!empty($arrayfields['c.multicurrency_total_ht']['checked'])) {
  1088. // Amount
  1089. print '<td class="liste_titre right">';
  1090. print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_ht" value="'.dol_escape_htmltag($search_multicurrency_montant_ht).'">';
  1091. print '</td>';
  1092. }
  1093. if (!empty($arrayfields['c.multicurrency_total_vat']['checked'])) {
  1094. // Amount VAT
  1095. print '<td class="liste_titre right">';
  1096. print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_vat" value="'.dol_escape_htmltag($search_multicurrency_montant_vat).'">';
  1097. print '</td>';
  1098. }
  1099. if (!empty($arrayfields['c.multicurrency_total_ttc']['checked'])) {
  1100. // Amount
  1101. print '<td class="liste_titre right">';
  1102. print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_ttc" value="'.dol_escape_htmltag($search_multicurrency_montant_ttc).'">';
  1103. print '</td>';
  1104. }
  1105. if (!empty($arrayfields['u.login']['checked'])) {
  1106. // Author
  1107. print '<td class="liste_titre" align="center">';
  1108. print '<input class="flat" size="4" type="text" name="search_login" value="'.dol_escape_htmltag($search_login).'">';
  1109. print '</td>';
  1110. }
  1111. if (!empty($arrayfields['sale_representative']['checked'])) {
  1112. print '<td class="liste_titre"></td>';
  1113. }
  1114. if (!empty($arrayfields['total_pa']['checked'])) {
  1115. print '<td class="liste_titre right">';
  1116. print '</td>';
  1117. }
  1118. if (!empty($arrayfields['total_margin']['checked'])) {
  1119. print '<td class="liste_titre right">';
  1120. print '</td>';
  1121. }
  1122. if (!empty($arrayfields['total_margin_rate']['checked'])) {
  1123. print '<td class="liste_titre right">';
  1124. print '</td>';
  1125. }
  1126. if (!empty($arrayfields['total_mark_rate']['checked'])) {
  1127. print '<td class="liste_titre right">';
  1128. print '</td>';
  1129. }
  1130. // Extra fields
  1131. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  1132. // Fields from hook
  1133. $parameters = array('arrayfields'=>$arrayfields);
  1134. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
  1135. print $hookmanager->resPrint;
  1136. // Date creation
  1137. if (!empty($arrayfields['c.datec']['checked'])) {
  1138. print '<td class="liste_titre">';
  1139. print '</td>';
  1140. }
  1141. // Date modification
  1142. if (!empty($arrayfields['c.tms']['checked'])) {
  1143. print '<td class="liste_titre">';
  1144. print '</td>';
  1145. }
  1146. // Date cloture
  1147. if (!empty($arrayfields['c.date_cloture']['checked'])) {
  1148. print '<td class="liste_titre center">';
  1149. print '<div class="nowrapfordate">';
  1150. print $form->selectDate($search_datecloture_start ? $search_datecloture_start : -1, 'search_datecloture_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  1151. print '</div>';
  1152. print '<div class="nowrapfordate">';
  1153. print $form->selectDate($search_datecloture_end ? $search_datecloture_end : -1, 'search_datecloture_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  1154. print '</div>';
  1155. print '</td>';
  1156. }
  1157. // Note public
  1158. if (!empty($arrayfields['c.note_public']['checked'])) {
  1159. print '<td class="liste_titre">';
  1160. print '</td>';
  1161. }
  1162. // Note private
  1163. if (!empty($arrayfields['c.note_private']['checked'])) {
  1164. print '<td class="liste_titre">';
  1165. print '</td>';
  1166. }
  1167. // Shippable
  1168. if (!empty($arrayfields['shippable']['checked'])) {
  1169. print '<td class="liste_titre maxwidthonsmartphone" align="center">';
  1170. //print $form->selectyesno('search_shippable', $search_shippable, 1, 0, 1, 1);
  1171. if (getDolGlobalString('ORDER_SHIPABLE_STATUS_DISABLED_BY_DEFAULT')) {
  1172. print '<input type="checkbox" name="show_shippable_command" value="1"'.($show_shippable_command ? ' checked' : '').'>';
  1173. print $langs->trans('ShowShippableStatus');
  1174. } else {
  1175. $show_shippable_command = 1;
  1176. }
  1177. print '</td>';
  1178. }
  1179. // Status billed
  1180. if (!empty($arrayfields['c.facture']['checked'])) {
  1181. print '<td class="liste_titre maxwidthonsmartphone" align="center">';
  1182. print $form->selectyesno('search_billed', $search_billed, 1, 0, 1, 1);
  1183. print '</td>';
  1184. }
  1185. // Import key
  1186. if (!empty($arrayfields['c.import_key']['checked'])) {
  1187. print '<td class="liste_titre maxwidthonsmartphone" align="center">';
  1188. print '</td>';
  1189. }
  1190. // Status
  1191. if (!empty($arrayfields['c.fk_statut']['checked'])) {
  1192. print '<td class="liste_titre maxwidthonsmartphone center">';
  1193. $liststatus = array(
  1194. Commande::STATUS_DRAFT => $langs->trans("StatusOrderDraftShort"),
  1195. Commande::STATUS_VALIDATED => $langs->trans("StatusOrderValidated"),
  1196. Commande::STATUS_SHIPMENTONPROCESS => $langs->trans("StatusOrderSentShort"),
  1197. -2 => $langs->trans("StatusOrderValidatedShort").'+'.$langs->trans("StatusOrderSentShort"),
  1198. -3 => $langs->trans("StatusOrderValidatedShort").'+'.$langs->trans("StatusOrderSentShort").'+'.$langs->trans("StatusOrderDelivered"),
  1199. Commande::STATUS_CLOSED => $langs->trans("StatusOrderDelivered"),
  1200. Commande::STATUS_CANCELED => $langs->trans("StatusOrderCanceledShort")
  1201. );
  1202. print $form->selectarray('search_status', $liststatus, $search_status, -5, 0, 0, '', 0, 0, 0, '', 'maxwidth125', 1);
  1203. print '</td>';
  1204. }
  1205. // Action column
  1206. if (!getDolGlobalInt('MAIN_CHECKBOX_LEFT_COLUMN')) {
  1207. print '<td class="liste_titre" align="middle">';
  1208. $searchpicto = $form->showFilterButtons();
  1209. print $searchpicto;
  1210. print '</td>';
  1211. }
  1212. print "</tr>\n";
  1213. // Fields title
  1214. print '<tr class="liste_titre">';
  1215. if (getDolGlobalInt('MAIN_CHECKBOX_LEFT_COLUMN')) {
  1216. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, 'maxwidthsearch center ');
  1217. }
  1218. // Détail commande
  1219. if (!empty($arrayfields['rowid']['checked'])) {
  1220. print_liste_field_titre($arrayfields['rowid']['label'], $_SERVER["PHP_SELF"], 'rowid', '', $param, '', $sortfield, $sortorder);
  1221. }
  1222. if (!empty($arrayfields['pr.ref']['checked'])) {
  1223. print_liste_field_titre($arrayfields['pr.ref']['label'], $_SERVER["PHP_SELF"], 'pr.ref', '', $param, '', $sortfield, $sortorder);
  1224. }
  1225. if (!empty($arrayfields['pr.desc']['checked'])) {
  1226. print_liste_field_titre($arrayfields['pr.desc']['label'], $_SERVER["PHP_SELF"], 'pr.desc', '', $param, '', $sortfield, $sortorder);
  1227. }
  1228. if (!empty($arrayfields['cdet.qty']['checked'])) {
  1229. print_liste_field_titre($arrayfields['cdet.qty']['label'], $_SERVER["PHP_SELF"], 'cdet.qty', '', $param, '', $sortfield, $sortorder);
  1230. }
  1231. if (!empty($arrayfields['c.ref']['checked'])) {
  1232. print_liste_field_titre($arrayfields['c.ref']['label'], $_SERVER["PHP_SELF"], 'c.ref', '', $param, '', $sortfield, $sortorder);
  1233. }
  1234. if (!empty($arrayfields['c.ref_client']['checked'])) {
  1235. print_liste_field_titre($arrayfields['c.ref_client']['label'], $_SERVER["PHP_SELF"], 'c.ref_client', '', $param, '', $sortfield, $sortorder);
  1236. }
  1237. if (!empty($arrayfields['p.ref']['checked'])) {
  1238. print_liste_field_titre($arrayfields['p.ref']['label'], $_SERVER["PHP_SELF"], "p.ref", "", $param, '', $sortfield, $sortorder);
  1239. }
  1240. if (!empty($arrayfields['p.title']['checked'])) {
  1241. print_liste_field_titre($arrayfields['p.title']['label'], $_SERVER["PHP_SELF"], "p.title", "", $param, '', $sortfield, $sortorder);
  1242. }
  1243. if (!empty($arrayfields['s.nom']['checked'])) {
  1244. print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], 's.nom', '', $param, '', $sortfield, $sortorder);
  1245. }
  1246. if (!empty($arrayfields['s.name_alias']['checked'])) {
  1247. print_liste_field_titre($arrayfields['s.name_alias']['label'], $_SERVER["PHP_SELF"], 's.name_alias', '', $param, '', $sortfield, $sortorder);
  1248. }
  1249. if (!empty($arrayfields['s.town']['checked'])) {
  1250. print_liste_field_titre($arrayfields['s.town']['label'], $_SERVER["PHP_SELF"], 's.town', '', $param, '', $sortfield, $sortorder);
  1251. }
  1252. if (!empty($arrayfields['s.zip']['checked'])) {
  1253. print_liste_field_titre($arrayfields['s.zip']['label'], $_SERVER["PHP_SELF"], 's.zip', '', $param, '', $sortfield, $sortorder);
  1254. }
  1255. if (!empty($arrayfields['state.nom']['checked'])) {
  1256. print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder);
  1257. }
  1258. if (!empty($arrayfields['country.code_iso']['checked'])) {
  1259. print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, '', $sortfield, $sortorder, 'center ');
  1260. }
  1261. if (!empty($arrayfields['typent.code']['checked'])) {
  1262. print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, '', $sortfield, $sortorder, 'center ');
  1263. }
  1264. if (!empty($arrayfields['c.date_commande']['checked'])) {
  1265. print_liste_field_titre($arrayfields['c.date_commande']['label'], $_SERVER["PHP_SELF"], 'c.date_commande', '', $param, '', $sortfield, $sortorder, 'center ');
  1266. }
  1267. if (!empty($arrayfields['c.date_delivery']['checked'])) {
  1268. print_liste_field_titre($arrayfields['c.date_delivery']['label'], $_SERVER["PHP_SELF"], 'c.date_livraison', '', $param, '', $sortfield, $sortorder, 'center ');
  1269. }
  1270. if (!empty($arrayfields['c.fk_shipping_method']['checked'])) {
  1271. print_liste_field_titre($arrayfields['c.fk_shipping_method']['label'], $_SERVER["PHP_SELF"], "c.fk_shipping_method", "", $param, '', $sortfield, $sortorder);
  1272. }
  1273. if (!empty($arrayfields['c.fk_cond_reglement']['checked'])) {
  1274. print_liste_field_titre($arrayfields['c.fk_cond_reglement']['label'], $_SERVER["PHP_SELF"], "c.fk_cond_reglement", "", $param, '', $sortfield, $sortorder);
  1275. }
  1276. if (!empty($arrayfields['c.fk_mode_reglement']['checked'])) {
  1277. print_liste_field_titre($arrayfields['c.fk_mode_reglement']['label'], $_SERVER["PHP_SELF"], "c.fk_mode_reglement", "", $param, '', $sortfield, $sortorder);
  1278. }
  1279. if (!empty($arrayfields['c.fk_input_reason']['checked'])) {
  1280. print_liste_field_titre($arrayfields['c.fk_input_reason']['label'], $_SERVER["PHP_SELF"], "c.fk_input_reason", "", $param, '', $sortfield, $sortorder);
  1281. }
  1282. if (!empty($arrayfields['cdet.total_ht']['checked'])) {
  1283. print_liste_field_titre($arrayfields['cdet.total_ht']['label'], $_SERVER["PHP_SELF"], 'cdet.total_ht', '', $param, '', $sortfield, $sortorder, 'right ');
  1284. }
  1285. if (!empty($arrayfields['c.total_vat']['checked'])) {
  1286. print_liste_field_titre($arrayfields['c.total_vat']['label'], $_SERVER["PHP_SELF"], 'cdet.total_tva', '', $param, '', $sortfield, $sortorder, 'right ');
  1287. }
  1288. if (!empty($arrayfields['cdet.total_ttc']['checked'])) {
  1289. print_liste_field_titre($arrayfields['cdet.total_ttc']['label'], $_SERVER["PHP_SELF"], 'cdet.total_ttc', '', $param, '', $sortfield, $sortorder, 'right ');
  1290. }
  1291. if (!empty($arrayfields['c.fk_warehouse']['checked'])) {
  1292. print_liste_field_titre($arrayfields['c.fk_warehouse']['label'], "", '', '', $param, '', $sortfield, $sortorder);
  1293. }
  1294. if (!empty($arrayfields['c.multicurrency_code']['checked'])) {
  1295. print_liste_field_titre($arrayfields['c.multicurrency_code']['label'], $_SERVER['PHP_SELF'], 'c.multicurrency_code', '', $param, '', $sortfield, $sortorder);
  1296. }
  1297. if (!empty($arrayfields['c.multicurrency_tx']['checked'])) {
  1298. print_liste_field_titre($arrayfields['c.multicurrency_tx']['label'], $_SERVER['PHP_SELF'], 'c.multicurrency_tx', '', $param, '', $sortfield, $sortorder);
  1299. }
  1300. if (!empty($arrayfields['c.multicurrency_total_ht']['checked'])) {
  1301. print_liste_field_titre($arrayfields['c.multicurrency_total_ht']['label'], $_SERVER['PHP_SELF'], 'c.multicurrency_total_ht', '', $param, 'class="right"', $sortfield, $sortorder);
  1302. }
  1303. if (!empty($arrayfields['c.multicurrency_total_vat']['checked'])) {
  1304. print_liste_field_titre($arrayfields['c.multicurrency_total_vat']['label'], $_SERVER['PHP_SELF'], 'c.multicurrency_total_tva', '', $param, 'class="right"', $sortfield, $sortorder);
  1305. }
  1306. if (!empty($arrayfields['c.multicurrency_total_ttc']['checked'])) {
  1307. print_liste_field_titre($arrayfields['c.multicurrency_total_ttc']['label'], $_SERVER['PHP_SELF'], 'c.multicurrency_total_ttc', '', $param, 'class="right"', $sortfield, $sortorder);
  1308. }
  1309. if (!empty($arrayfields['u.login']['checked'])) {
  1310. print_liste_field_titre($arrayfields['u.login']['label'], $_SERVER["PHP_SELF"], 'u.login', '', $param, 'align="center"', $sortfield, $sortorder);
  1311. }
  1312. if (!empty($arrayfields['sale_representative']['checked'])) {
  1313. print_liste_field_titre($arrayfields['sale_representative']['label'], $_SERVER["PHP_SELF"], "", "", "$param", '', $sortfield, $sortorder);
  1314. }
  1315. if (!empty($arrayfields['total_pa']['checked'])) {
  1316. print_liste_field_titre($arrayfields['total_pa']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
  1317. }
  1318. if (!empty($arrayfields['total_margin']['checked'])) {
  1319. print_liste_field_titre($arrayfields['total_margin']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
  1320. }
  1321. if (!empty($arrayfields['total_margin_rate']['checked'])) {
  1322. print_liste_field_titre($arrayfields['total_margin_rate']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
  1323. }
  1324. if (!empty($arrayfields['total_mark_rate']['checked'])) {
  1325. print_liste_field_titre($arrayfields['total_mark_rate']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
  1326. }
  1327. $totalarray = array(
  1328. 'nbfield' => 0,
  1329. 'val' => array(
  1330. 'cdet.total_ht' => 0,
  1331. 'cdet.total_tva' => 0,
  1332. 'cdet.total_ttc' => 0,
  1333. ),
  1334. 'pos' => array(),
  1335. );
  1336. // Extra fields
  1337. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  1338. // Hook fields
  1339. $parameters = array(
  1340. 'arrayfields' => $arrayfields,
  1341. 'param' => $param,
  1342. 'sortfield' => $sortfield,
  1343. 'sortorder' => $sortorder,
  1344. 'totalarray' => &$totalarray,
  1345. );
  1346. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
  1347. print $hookmanager->resPrint;
  1348. if (!empty($arrayfields['c.datec']['checked'])) {
  1349. print_liste_field_titre($arrayfields['c.datec']['label'], $_SERVER["PHP_SELF"], "c.date_creation", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  1350. }
  1351. if (!empty($arrayfields['c.tms']['checked'])) {
  1352. print_liste_field_titre($arrayfields['c.tms']['label'], $_SERVER["PHP_SELF"], "c.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  1353. }
  1354. if (!empty($arrayfields['c.date_cloture']['checked'])) {
  1355. print_liste_field_titre($arrayfields['c.date_cloture']['label'], $_SERVER["PHP_SELF"], "c.date_cloture", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  1356. }
  1357. if (!empty($arrayfields['c.note_public']['checked'])) {
  1358. print_liste_field_titre($arrayfields['c.note_public']['label'], $_SERVER["PHP_SELF"], "c.note_public", "", $param, '', $sortfield, $sortorder, 'right ');
  1359. }
  1360. if (!empty($arrayfields['c.note_private']['checked'])) {
  1361. print_liste_field_titre($arrayfields['c.note_private']['label'], $_SERVER["PHP_SELF"], "c.note_private", "", $param, '', $sortfield, $sortorder, 'right ');
  1362. }
  1363. if (!empty($arrayfields['shippable']['checked'])) {
  1364. print_liste_field_titre($arrayfields['shippable']['label'], $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'center ');
  1365. }
  1366. if (!empty($arrayfields['c.facture']['checked'])) {
  1367. print_liste_field_titre($arrayfields['c.facture']['label'], $_SERVER["PHP_SELF"], 'c.facture', '', $param, '', $sortfield, $sortorder, 'center ');
  1368. }
  1369. if (!empty($arrayfields['c.import_key']['checked'])) {
  1370. print_liste_field_titre($arrayfields['c.import_key']['label'], $_SERVER["PHP_SELF"], "c.import_key", "", $param, '', $sortfield, $sortorder, 'center ');
  1371. }
  1372. if (!empty($arrayfields['c.fk_statut']['checked'])) {
  1373. print_liste_field_titre($arrayfields['c.fk_statut']['label'], $_SERVER["PHP_SELF"], "c.fk_statut", "", $param, '', $sortfield, $sortorder, 'center ');
  1374. }
  1375. if (!getDolGlobalInt('MAIN_CHECKBOX_LEFT_COLUMN')) {
  1376. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, 'maxwidthsearch center ');
  1377. }
  1378. print '</tr>'."\n";
  1379. $total = 0;
  1380. $subtotal = 0;
  1381. $productstat_cache = array();
  1382. $productstat_cachevirtual = array();
  1383. $getNomUrl_cache = array();
  1384. $generic_commande = new Commande($db);
  1385. $generic_product = new Product($db);
  1386. $userstatic = new User($db);
  1387. $i = 0;
  1388. $with_margin_info = false;
  1389. if (isModEnabled('margin') && (
  1390. !empty($arrayfields['total_pa']['checked'])
  1391. || !empty($arrayfields['total_margin']['checked'])
  1392. || !empty($arrayfields['total_margin_rate']['checked'])
  1393. || !empty($arrayfields['total_mark_rate']['checked'])
  1394. )
  1395. ) {
  1396. $with_margin_info = true;
  1397. }
  1398. $total_ht = 0;
  1399. $total_margin = 0;
  1400. // Détail commande
  1401. $totalqty = 0;
  1402. $totalarray = array();
  1403. $totalarray['nbfield'] = 0;
  1404. $subtotalarray['nbfield'] = 0;
  1405. $totalarray['val']['cdet.total_tva'] = 0;
  1406. $totalarray['val']['cdet.total_ttc'] = 0;
  1407. $imaxinloop = ($limit ? min($num, $limit) : $num);
  1408. while ($i < $imaxinloop) {
  1409. $obj = $db->fetch_object($resql);
  1410. $notshippable = 0;
  1411. $warning = 0;
  1412. $text_info = '';
  1413. $text_warning = '';
  1414. $nbprod = 0;
  1415. // Print SubTotal
  1416. if (empty($i)) {
  1417. $oldref = $obj->product_ref;
  1418. }
  1419. if ($oldref != $obj->product_ref && $sortfield == 'pr.ref') {
  1420. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_subtotal.tpl.php';
  1421. $oldref = $obj->product_ref;
  1422. }
  1423. $companystatic->id = $obj->socid;
  1424. $companystatic->name = $obj->name;
  1425. $companystatic->name_alias = $obj->alias;
  1426. $companystatic->client = $obj->client;
  1427. $companystatic->code_client = $obj->code_client;
  1428. $companystatic->email = $obj->email;
  1429. $companystatic->phone = $obj->phone;
  1430. $companystatic->address = $obj->address;
  1431. $companystatic->zip = $obj->zip;
  1432. $companystatic->town = $obj->town;
  1433. $companystatic->country_code = $obj->country_code;
  1434. if (!isset($getNomUrl_cache[$obj->socid])) {
  1435. $getNomUrl_cache[$obj->socid] = $companystatic->getNomUrl(1, 'customer');
  1436. }
  1437. $generic_commande->id = $obj->c_rowid;
  1438. $generic_commande->ref = $obj->ref;
  1439. $generic_commande->statut = $obj->fk_statut;
  1440. $generic_commande->billed = $obj->billed;
  1441. $generic_commande->date = $db->jdate($obj->date_commande);
  1442. $generic_commande->delivery_date = $db->jdate($obj->date_delivery);
  1443. $generic_commande->ref_client = $obj->ref_client;
  1444. $generic_commande->total_ht = $obj->c_total_ht;
  1445. $generic_commande->total_tva = $obj->c_total_tva;
  1446. $generic_commande->total_ttc = $obj->c_total_ttc;
  1447. $generic_commande->note_public = $obj->note_public;
  1448. $generic_commande->note_private = $obj->note_private;
  1449. $projectstatic->id = $obj->project_id;
  1450. $projectstatic->ref = $obj->project_ref;
  1451. $projectstatic->title = $obj->project_label;
  1452. $marginInfo = array();
  1453. if ($with_margin_info === true) {
  1454. $generic_commande->fetch_lines();
  1455. $marginInfo = $formmargin->getMarginInfosArray($generic_commande);
  1456. $total_ht += $obj->total_ht;
  1457. $total_margin += $marginInfo['total_margin'];
  1458. }
  1459. print '<tr class="oddeven">';
  1460. // Action column
  1461. if (getDolGlobalInt('MAIN_CHECKBOX_LEFT_COLUMN')) {
  1462. print '<td class="nowrap center">';
  1463. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  1464. $selected = 0;
  1465. if (in_array($obj->rowid, $arrayofselected)) {
  1466. $selected = 1;
  1467. }
  1468. print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
  1469. }
  1470. print '</td>';
  1471. if (!$i) {
  1472. $totalarray['nbfield']++;
  1473. }
  1474. }
  1475. // Détail commande
  1476. // ID
  1477. if (!empty($arrayfields['rowid']['checked'])) {
  1478. print '<td class="nowrap right">'.$obj->rowid.'</td>';
  1479. if (!$i) {
  1480. $totalarray['nbfield']++;
  1481. }
  1482. }
  1483. // Product Ref
  1484. if (!empty($arrayfields['pr.ref']['checked'])) {
  1485. if (!empty($obj->product_rowid)) {
  1486. $generic_product->id = $obj->product_rowid;
  1487. $generic_product->ref = $obj->product_ref;
  1488. $generic_product->label = $obj->product_label;
  1489. $generic_product->status = $obj->product_status;
  1490. $generic_product->status_buy = $obj->product_status_buy;
  1491. $generic_product->status_batch = $obj->product_batch;
  1492. $generic_product->barcode = $obj->product_barcode;
  1493. print '<td class="nowrap tdoverflowmax200">'.$generic_product->getNomUrl(1).'</td>';
  1494. } else {
  1495. print '<td class="nowrap tdoverflowmax200">Ligne libre</td>';
  1496. }
  1497. if (!$i) {
  1498. $totalarray['nbfield']++;
  1499. }
  1500. }
  1501. // Product Description
  1502. if (!empty($arrayfields['pr.desc']['checked'])) {
  1503. // print '<td class="nowrap tdoverflowmax200">'.$obj->description.'</td>';
  1504. !empty($obj->product_label) ? $labelproduct = $obj->product_label : $labelproduct = $obj->description;
  1505. print '<td class="nowrap tdoverflowmax200">';
  1506. print dolGetFirstLineOfText(dolPrintHTML($labelproduct), 5);
  1507. print '</td>';
  1508. if (!$i) {
  1509. $totalarray['nbfield']++;
  1510. }
  1511. }
  1512. // Product QtyOrdered
  1513. if (!empty($arrayfields['cdet.qty']['checked'])) {
  1514. print '<td class="nowrap right">'.$obj->qty.'</td>';
  1515. if (isset($totalarray['val']['cdet.qty']) || isset($subtotalarray['val']['cdet.qty'])) {
  1516. $totalarray['val']['cdet.qty'] += $obj->qty;
  1517. $subtotalarray['val']['cdet.qty'] += $obj->qty;
  1518. } else {
  1519. $totalarray['val']['cdet.qty'] = $obj->qty;
  1520. $subtotalarray['val']['cdet.qty'] = $obj->qty;
  1521. }
  1522. if (!$i) {
  1523. $totalarray['nbfield']++;
  1524. }
  1525. if (!$i) {
  1526. $totalarray['pos'][$totalarray['nbfield']] = 'cdet.qty';
  1527. $totalarray['pos'][$subtotalarray['nbfield']] = 'cdet.qty';
  1528. }
  1529. }
  1530. // Ref
  1531. if (!empty($arrayfields['c.ref']['checked'])) {
  1532. print '<td class="nowraponall">';
  1533. print $generic_commande->getNomUrl(1, ($search_status != 2 ? 0 : $obj->fk_statut), 0, 0, 0, 1, 1);
  1534. $filename = dol_sanitizeFileName($obj->ref);
  1535. $filedir = $conf->commande->multidir_output[$conf->entity].'/'.dol_sanitizeFileName($obj->ref);
  1536. $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
  1537. print $formfile->getDocumentsLink($generic_commande->element, $filename, $filedir);
  1538. print '</td>';
  1539. if (!$i) {
  1540. $totalarray['nbfield']++;
  1541. }
  1542. }
  1543. // Ref customer
  1544. if (!empty($arrayfields['c.ref_client']['checked'])) {
  1545. print '<td class="nowrap tdoverflowmax200">'.$obj->ref_client.'</td>';
  1546. if (!$i) {
  1547. $totalarray['nbfield']++;
  1548. }
  1549. }
  1550. // Project ref
  1551. if (!empty($arrayfields['p.ref']['checked'])) {
  1552. print '<td class="nowrap">';
  1553. if ($obj->project_id > 0) {
  1554. print $projectstatic->getNomUrl(1);
  1555. }
  1556. print '</td>';
  1557. if (!$i) {
  1558. $totalarray['nbfield']++;
  1559. }
  1560. }
  1561. // Project label
  1562. if (!empty($arrayfields['p.title']['checked'])) {
  1563. print '<td class="nowrap">';
  1564. if ($obj->project_id > 0) {
  1565. print $projectstatic->title;
  1566. }
  1567. print '</td>';
  1568. if (!$i) {
  1569. $totalarray['nbfield']++;
  1570. }
  1571. }
  1572. // Third party
  1573. if (!empty($arrayfields['s.nom']['checked'])) {
  1574. print '<td class="tdoverflowmax200">';
  1575. print $getNomUrl_cache[$obj->socid];
  1576. // If module invoices enabled and user with invoice creation permissions
  1577. if (isModEnabled('facture') && getDolGlobalString('ORDER_BILLING_ALL_CUSTOMER')) {
  1578. if ($user->hasRight('facture', 'creer')) {
  1579. if (($obj->fk_statut > 0 && $obj->fk_statut < 3) || ($obj->fk_statut == 3 && $obj->billed == 0)) {
  1580. print '&nbsp;<a href="'.DOL_URL_ROOT.'/commande/list.php?socid='.$companystatic->id.'&search_billed=0&autoselectall=1">';
  1581. print img_picto($langs->trans("CreateInvoiceForThisCustomer").' : '.$companystatic->name, 'object_bill', 'hideonsmartphone').'</a>';
  1582. }
  1583. }
  1584. }
  1585. print '</td>';
  1586. if (!$i) {
  1587. $totalarray['nbfield']++;
  1588. }
  1589. }
  1590. // Alias name
  1591. if (!empty($arrayfields['s.name_alias']['checked'])) {
  1592. print '<td class="nocellnopadd">';
  1593. print $obj->alias;
  1594. print '</td>';
  1595. if (!$i) {
  1596. $totalarray['nbfield']++;
  1597. }
  1598. }
  1599. // Town
  1600. if (!empty($arrayfields['s.town']['checked'])) {
  1601. print '<td class="nocellnopadd">';
  1602. print $obj->town;
  1603. print '</td>';
  1604. if (!$i) {
  1605. $totalarray['nbfield']++;
  1606. }
  1607. }
  1608. // Zip
  1609. if (!empty($arrayfields['s.zip']['checked'])) {
  1610. print '<td class="nocellnopadd">';
  1611. print $obj->zip;
  1612. print '</td>';
  1613. if (!$i) {
  1614. $totalarray['nbfield']++;
  1615. }
  1616. }
  1617. // State
  1618. if (!empty($arrayfields['state.nom']['checked'])) {
  1619. print "<td>".$obj->state_name."</td>\n";
  1620. if (!$i) {
  1621. $totalarray['nbfield']++;
  1622. }
  1623. }
  1624. // Country
  1625. if (!empty($arrayfields['country.code_iso']['checked'])) {
  1626. print '<td class="center">';
  1627. $tmparray = getCountry($obj->fk_pays, 'all');
  1628. print $tmparray['label'];
  1629. print '</td>';
  1630. if (!$i) {
  1631. $totalarray['nbfield']++;
  1632. }
  1633. }
  1634. // Type ent
  1635. if (!empty($arrayfields['typent.code']['checked'])) {
  1636. print '<td class="center">';
  1637. if (empty($typenArray)) {
  1638. $typenArray = $formcompany->typent_array(1);
  1639. }
  1640. print $typenArray[$obj->typent_code];
  1641. print '</td>';
  1642. if (!$i) {
  1643. $totalarray['nbfield']++;
  1644. }
  1645. }
  1646. // Order date
  1647. if (!empty($arrayfields['c.date_commande']['checked'])) {
  1648. print '<td class="center">';
  1649. print dol_print_date($db->jdate($obj->date_commande), 'day');
  1650. // Warning late icon and note
  1651. if ($generic_commande->hasDelay()) {
  1652. print img_picto($langs->trans("Late").' : '.$generic_commande->showDelay(), "warning");
  1653. }
  1654. print '</td>';
  1655. if (!$i) {
  1656. $totalarray['nbfield']++;
  1657. }
  1658. }
  1659. // Plannned date of delivery
  1660. if (!empty($arrayfields['c.date_delivery']['checked'])) {
  1661. print '<td class="center">';
  1662. print dol_print_date($db->jdate($obj->date_delivery), 'dayhour');
  1663. print '</td>';
  1664. if (!$i) {
  1665. $totalarray['nbfield']++;
  1666. }
  1667. }
  1668. // Shipping Method
  1669. if (!empty($arrayfields['c.fk_shipping_method']['checked'])) {
  1670. print '<td>';
  1671. $form->formSelectShippingMethod('', $obj->fk_shipping_method, 'none', 1);
  1672. print '</td>';
  1673. if (!$i) {
  1674. $totalarray['nbfield']++;
  1675. }
  1676. }
  1677. // Payment terms
  1678. if (!empty($arrayfields['c.fk_cond_reglement']['checked'])) {
  1679. print '<td>';
  1680. $form->form_conditions_reglement($_SERVER['PHP_SELF'], $obj->fk_cond_reglement, 'none', 0, '', 1, $obj->deposit_percent);
  1681. print '</td>';
  1682. if (!$i) {
  1683. $totalarray['nbfield']++;
  1684. }
  1685. }
  1686. // Payment mode
  1687. if (!empty($arrayfields['c.fk_mode_reglement']['checked'])) {
  1688. print '<td>';
  1689. $form->form_modes_reglement($_SERVER['PHP_SELF'], $obj->fk_mode_reglement, 'none', '', -1);
  1690. print '</td>';
  1691. if (!$i) {
  1692. $totalarray['nbfield']++;
  1693. }
  1694. }
  1695. // Channel
  1696. if (!empty($arrayfields['c.fk_input_reason']['checked'])) {
  1697. print '<td>';
  1698. $form->formInputReason($_SERVER['PHP_SELF'], $obj->fk_input_reason, 'none', '');
  1699. print '</td>';
  1700. if (!$i) {
  1701. $totalarray['nbfield']++;
  1702. }
  1703. }
  1704. // Amount HT
  1705. if (!empty($arrayfields['cdet.total_ht']['checked'])) {
  1706. print '<td class="nowrap right"><span class="amount">'.price($obj->total_ht)."</span></td>\n";
  1707. if (!$i) {
  1708. $totalarray['nbfield']++;
  1709. }
  1710. if (!$i) {
  1711. $totalarray['pos'][$totalarray['nbfield']] = 'cdet.total_ht';
  1712. $totalarray['pos'][$subtotalarray['nbfield']] = 'cdet.total_ht';
  1713. }
  1714. if (isset($totalarray['val']['cdet.total_ht']) || isset($subtotalarray['val']['cdet.total_ht'])) {
  1715. $totalarray['val']['cdet.total_ht'] += $obj->total_ht;
  1716. $subtotalarray['val']['cdet.total_ht'] += $obj->total_ht;
  1717. } else {
  1718. $totalarray['val']['cdet.total_ht'] = $obj->total_ht;
  1719. $subtotalarray['val']['cdet.total_ht'] = $obj->total_ht;
  1720. }
  1721. }
  1722. // Amount VAT
  1723. if (!empty($arrayfields['c.total_vat']['checked'])) {
  1724. print '<td class="nowrap right"><span class="amount">'.price($obj->total_tva)."</span></td>\n";
  1725. if (!$i) {
  1726. $totalarray['nbfield']++;
  1727. }
  1728. if (!$i) {
  1729. $totalarray['pos'][$totalarray['nbfield']] = 'cdet.total_tva';
  1730. $totalarray['pos'][$subtotalarray['nbfield']] = 'cdet.total_tva';
  1731. }
  1732. $totalarray['val']['cdet.total_tva'] += $obj->total_tva;
  1733. $subtotalarray['val']['cdet.total_tva'] += $obj->total_tva;
  1734. }
  1735. // Amount TTC
  1736. if (!empty($arrayfields['cdet.total_ttc']['checked'])) {
  1737. print '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc)."</span></td>\n";
  1738. if (!$i) {
  1739. $totalarray['nbfield']++;
  1740. }
  1741. if (!$i) {
  1742. $totalarray['pos'][$totalarray['nbfield']] = 'cdet.total_ttc';
  1743. $subtotalarray['pos'][$totalarray['nbfield']] = 'cdet.total_ttc';
  1744. }
  1745. $totalarray['val']['cdet.total_ttc'] += $obj->total_ttc;
  1746. $subtotalarray['val']['cdet.total_ttc'] += $obj->total_ttc;
  1747. }
  1748. // Warehouse
  1749. if (!empty($arrayfields['c.fk_warehouse']['checked'])) {
  1750. print '<td class="nowrap">';
  1751. if ($obj->warehouse > 0) {
  1752. print img_picto('', 'stock', 'class="paddingrightonly"');
  1753. }
  1754. $formproduct->formSelectWarehouses($_SERVER['PHP_SELF'], $obj->warehouse, 'none');
  1755. print "</td>\n";
  1756. if (!$i) {
  1757. $totalarray['nbfield']++;
  1758. }
  1759. }
  1760. // Currency
  1761. if (!empty($arrayfields['c.multicurrency_code']['checked'])) {
  1762. print '<td class="nowrap">'.$obj->multicurrency_code.' - '.$langs->trans('Currency'.$obj->multicurrency_code)."</td>\n";
  1763. if (!$i) {
  1764. $totalarray['nbfield']++;
  1765. }
  1766. }
  1767. // Currency rate
  1768. if (!empty($arrayfields['c.multicurrency_tx']['checked'])) {
  1769. print '<td class="nowrap">';
  1770. $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$obj->rowid, $obj->multicurrency_tx, 'none', $obj->multicurrency_code);
  1771. print "</td>\n";
  1772. if (!$i) {
  1773. $totalarray['nbfield']++;
  1774. }
  1775. }
  1776. // Amount HT
  1777. if (!empty($arrayfields['c.multicurrency_total_ht']['checked'])) {
  1778. print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_ht)."</span></td>\n";
  1779. if (!$i) {
  1780. $totalarray['nbfield']++;
  1781. }
  1782. }
  1783. // Amount VAT
  1784. if (!empty($arrayfields['c.multicurrency_total_vat']['checked'])) {
  1785. print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_vat)."</span></td>\n";
  1786. if (!$i) {
  1787. $totalarray['nbfield']++;
  1788. }
  1789. }
  1790. // Amount TTC
  1791. if (!empty($arrayfields['c.multicurrency_total_ttc']['checked'])) {
  1792. print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_ttc)."</span></td>\n";
  1793. if (!$i) {
  1794. $totalarray['nbfield']++;
  1795. }
  1796. }
  1797. $userstatic->id = $obj->fk_user_author;
  1798. $userstatic->login = $obj->login;
  1799. $userstatic->lastname = $obj->lastname;
  1800. $userstatic->firstname = $obj->firstname;
  1801. $userstatic->email = $obj->user_email;
  1802. $userstatic->statut = $obj->user_statut;
  1803. $userstatic->entity = $obj->entity;
  1804. $userstatic->photo = $obj->photo;
  1805. $userstatic->office_phone = $obj->office_phone;
  1806. $userstatic->office_fax = $obj->office_fax;
  1807. $userstatic->user_mobile = $obj->user_mobile;
  1808. $userstatic->job = $obj->job;
  1809. $userstatic->gender = $obj->gender;
  1810. // Author
  1811. if (!empty($arrayfields['u.login']['checked'])) {
  1812. print '<td class="tdoverflowmax200">';
  1813. if ($userstatic->id) {
  1814. print $userstatic->getNomUrl(-1);
  1815. } else {
  1816. print '&nbsp;';
  1817. }
  1818. print "</td>\n";
  1819. if (!$i) {
  1820. $totalarray['nbfield']++;
  1821. }
  1822. }
  1823. if (!empty($arrayfields['sale_representative']['checked'])) {
  1824. // Sales representatives
  1825. print '<td>';
  1826. if ($obj->socid > 0) {
  1827. $listsalesrepresentatives = $companystatic->getSalesRepresentatives($user);
  1828. if ($listsalesrepresentatives < 0) {
  1829. dol_print_error($db);
  1830. }
  1831. $nbofsalesrepresentative = count($listsalesrepresentatives);
  1832. if ($nbofsalesrepresentative > 6) {
  1833. // We print only number
  1834. print $nbofsalesrepresentative;
  1835. } elseif ($nbofsalesrepresentative > 0) {
  1836. $j = 0;
  1837. foreach ($listsalesrepresentatives as $val) {
  1838. $userstatic->id = $val['id'];
  1839. $userstatic->lastname = $val['lastname'];
  1840. $userstatic->firstname = $val['firstname'];
  1841. $userstatic->email = $val['email'];
  1842. $userstatic->statut = $val['statut'];
  1843. $userstatic->entity = $val['entity'];
  1844. $userstatic->photo = $val['photo'];
  1845. $userstatic->login = $val['login'];
  1846. $userstatic->office_phone = $val['office_phone'];
  1847. $userstatic->office_fax = $val['office_fax'];
  1848. $userstatic->user_mobile = $val['user_mobile'];
  1849. $userstatic->job = $val['job'];
  1850. $userstatic->gender = $val['gender'];
  1851. //print '<div class="float">':
  1852. print ($nbofsalesrepresentative < 2) ? $userstatic->getNomUrl(-1, '', 0, 0, 12) : $userstatic->getNomUrl(-2);
  1853. $j++;
  1854. if ($j < $nbofsalesrepresentative) {
  1855. print ' ';
  1856. }
  1857. //print '</div>';
  1858. }
  1859. }
  1860. //else print $langs->trans("NoSalesRepresentativeAffected");
  1861. } else {
  1862. print '&nbsp;';
  1863. }
  1864. print '</td>';
  1865. if (!$i) {
  1866. $totalarray['nbfield']++;
  1867. }
  1868. }
  1869. // Total buying or cost price
  1870. if (!empty($arrayfields['total_pa']['checked'])) {
  1871. print '<td class="right nowrap">'.price($marginInfo['pa_total']).'</td>';
  1872. if (!$i) {
  1873. $totalarray['nbfield']++;
  1874. }
  1875. }
  1876. // Total margin
  1877. if (!empty($arrayfields['total_margin']['checked'])) {
  1878. print '<td class="right nowrap">'.price($marginInfo['total_margin']).'</td>';
  1879. if (!$i) {
  1880. $totalarray['nbfield']++;
  1881. }
  1882. if (!$i) {
  1883. $totalarray['pos'][$totalarray['nbfield']] = 'total_margin';
  1884. $totalarray['pos'][$subtotalarray['nbfield']] = 'total_margin';
  1885. }
  1886. $totalarray['val']['total_margin'] += $marginInfo['total_margin'];
  1887. $subtotalarray['val']['total_margin'] += $marginInfo['total_margin'];
  1888. }
  1889. // Total margin rate
  1890. if (!empty($arrayfields['total_margin_rate']['checked'])) {
  1891. print '<td class="right nowrap">'.(($marginInfo['total_margin_rate'] == '') ? '' : price($marginInfo['total_margin_rate'], null, null, null, null, 2).'%').'</td>';
  1892. if (!$i) {
  1893. $totalarray['nbfield']++;
  1894. }
  1895. }
  1896. // Total mark rate
  1897. if (!empty($arrayfields['total_mark_rate']['checked'])) {
  1898. print '<td class="right nowrap">'.(($marginInfo['total_mark_rate'] == '') ? '' : price($marginInfo['total_mark_rate'], null, null, null, null, 2).'%').'</td>';
  1899. if (!$i) {
  1900. $totalarray['nbfield']++;
  1901. }
  1902. if (!$i) {
  1903. $totalarray['pos'][$totalarray['nbfield']] = 'total_mark_rate';
  1904. $totalarray['pos'][$subtotalarray['nbfield']] = 'total_mark_rate';
  1905. }
  1906. if ($i >= $imaxinloop - 1) {
  1907. if (!empty($total_ht)) {
  1908. $totalarray['val']['total_mark_rate'] = price2num($total_margin * 100 / $total_ht, 'MT');
  1909. $subtotalarray['val']['total_mark_rate'] = price2num($total_margin * 100 / $total_ht, 'MT');
  1910. } else {
  1911. $totalarray['val']['total_mark_rate'] = '';
  1912. $subtotalarray['val']['total_mark_rate'] = '';
  1913. }
  1914. }
  1915. }
  1916. // Extra fields
  1917. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  1918. // Fields from hook
  1919. $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  1920. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  1921. print $hookmanager->resPrint;
  1922. // Date creation
  1923. if (!empty($arrayfields['c.datec']['checked'])) {
  1924. print '<td align="center" class="nowrap">';
  1925. print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
  1926. print '</td>';
  1927. if (!$i) {
  1928. $totalarray['nbfield']++;
  1929. }
  1930. }
  1931. // Date modification
  1932. if (!empty($arrayfields['c.tms']['checked'])) {
  1933. print '<td align="center" class="nowrap">';
  1934. print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser');
  1935. print '</td>';
  1936. if (!$i) {
  1937. $totalarray['nbfield']++;
  1938. }
  1939. }
  1940. // Date cloture
  1941. if (!empty($arrayfields['c.date_cloture']['checked'])) {
  1942. print '<td align="center" class="nowrap">';
  1943. print dol_print_date($db->jdate($obj->date_cloture), 'dayhour', 'tzuser');
  1944. print '</td>';
  1945. if (!$i) {
  1946. $totalarray['nbfield']++;
  1947. }
  1948. }
  1949. // Note public
  1950. if (!empty($arrayfields['c.note_public']['checked'])) {
  1951. print '<td class="center">';
  1952. print dol_string_nohtmltag($obj->note_public);
  1953. print '</td>';
  1954. if (!$i) {
  1955. $totalarray['nbfield']++;
  1956. }
  1957. }
  1958. // Note private
  1959. if (!empty($arrayfields['c.note_private']['checked'])) {
  1960. print '<td class="center">';
  1961. print dol_string_nohtmltag($obj->note_private);
  1962. print '</td>';
  1963. if (!$i) {
  1964. $totalarray['nbfield']++;
  1965. }
  1966. }
  1967. // Show shippable Icon (this creates subloops, so may be slow)
  1968. if (!empty($arrayfields['shippable']['checked'])) {
  1969. print '<td class="center">';
  1970. if (!empty($show_shippable_command) && isModEnabled('stock')) {
  1971. if (($obj->fk_statut > $generic_commande::STATUS_DRAFT) && ($obj->fk_statut < $generic_commande::STATUS_CLOSED)) {
  1972. $generic_commande->loadExpeditions(); // Load array ->expeditions
  1973. if (isset($generic_commande->expeditions[$obj->rowid])) {
  1974. $reliquat = $obj->qty - $generic_commande->expeditions[$obj->rowid];
  1975. } else {
  1976. $reliquat = $obj->qty;
  1977. }
  1978. if ($obj->product_type == 0 && $obj->fk_product > 0) { // If line is a product and not a service
  1979. $nbprod++; // order contains real products
  1980. $generic_product->id = $obj->fk_product;
  1981. // Get local and virtual stock and store it into cache
  1982. if (empty($productstat_cache[$obj->fk_product])) {
  1983. $generic_product->load_stock('nobatch'); // ->load_virtual_stock() is already included into load_stock()
  1984. $productstat_cache[$obj->fk_product]['stock_reel'] = $generic_product->stock_reel;
  1985. $productstat_cachevirtual[$obj->fk_product]['stock_reel'] = $generic_product->stock_theorique;
  1986. } else {
  1987. $generic_product->stock_reel = $productstat_cache[$obj->fk_product]['stock_reel'];
  1988. $generic_product->stock_theorique = $productstat_cachevirtual[$obj->fk_product]['stock_reel'] = $generic_product->stock_theorique;
  1989. }
  1990. if ($reliquat > $generic_product->stock_reel) {
  1991. $notshippable++;
  1992. }
  1993. if (!getDolGlobalString('SHIPPABLE_ORDER_ICON_IN_LIST')) { // Default code. Default should be this case.
  1994. $text_info .= $reliquat.' x '.$obj->product_ref.'&nbsp;'.dol_trunc($obj->product_label, 20);
  1995. $text_info .= ' - '.$langs->trans("Stock").': <span class="'.($generic_product->stock_reel > 0 ? 'ok' : 'error').'">'.$generic_product->stock_reel.'</span>';
  1996. $text_info .= ' - '.$langs->trans("VirtualStock").': <span class="'.($generic_product->stock_theorique > 0 ? 'ok' : 'error').'">'.$generic_product->stock_theorique.'</span>';
  1997. $text_info .= ($reliquat != $obj->qty ? ' <span class="opacitymedium">('.$langs->trans("QtyInOtherShipments").' '.($obj->qty - $reliquat).')</span>' : '');
  1998. $text_info .= '<br>';
  1999. } else { // BUGGED CODE.
  2000. // DOES NOT TAKE INTO ACCOUNT MANUFACTURING. THIS CODE SHOULD BE USELESS. PREVIOUS CODE SEEMS COMPLETE.
  2001. // COUNT STOCK WHEN WE SHOULD ALREADY HAVE VALUE
  2002. // Detailed virtual stock, looks bugged, uncomplete and need heavy load.
  2003. // stock order and stock order_supplier
  2004. $stock_order = 0;
  2005. $stock_order_supplier = 0;
  2006. if (getDolGlobalString('STOCK_CALCULATE_ON_SHIPMENT') || getDolGlobalString('STOCK_CALCULATE_ON_SHIPMENT_CLOSE')) { // What about other options ?
  2007. if (isModEnabled('commande')) {
  2008. if (empty($productstat_cache[$obj->fk_product]['stats_order_customer'])) {
  2009. $generic_product->load_stats_commande(0, '1,2');
  2010. $productstat_cache[$obj->fk_product]['stats_order_customer'] = $generic_product->stats_commande['qty'];
  2011. } else {
  2012. $generic_product->stats_commande['qty'] = $productstat_cache[$obj->fk_product]['stats_order_customer'];
  2013. }
  2014. $stock_order = $generic_product->stats_commande['qty'];
  2015. }
  2016. if (isModEnabled('supplier_order')) {
  2017. if (empty($productstat_cache[$obj->fk_product]['stats_order_supplier'])) {
  2018. $generic_product->load_stats_commande_fournisseur(0, '3');
  2019. $productstat_cache[$obj->fk_product]['stats_order_supplier'] = $generic_product->stats_commande_fournisseur['qty'];
  2020. } else {
  2021. $generic_product->stats_commande_fournisseur['qty'] = $productstat_cache[$obj->fk_product]['stats_order_supplier'];
  2022. }
  2023. $stock_order_supplier = $generic_product->stats_commande_fournisseur['qty'];
  2024. }
  2025. }
  2026. $text_info .= $reliquat.' x '.$obj->product_ref.'&nbsp;'.dol_trunc($obj->product_label, 20);
  2027. $text_stock_reel = $generic_product->stock_reel.'/'.$stock_order;
  2028. if ($stock_order > $generic_product->stock_reel && !($generic_product->stock_reel < $obj->qty)) {
  2029. $warning++;
  2030. $text_warning .= '<span class="warning">'.$langs->trans('Available').'&nbsp;:&nbsp;'.$text_stock_reel.'</span>';
  2031. }
  2032. if ($reliquat > $generic_product->stock_reel) {
  2033. $text_info .= '<span class="warning">'.$langs->trans('Available').'&nbsp;:&nbsp;'.$text_stock_reel.'</span>';
  2034. } else {
  2035. $text_info .= '<span class="ok">'.$langs->trans('Available').'&nbsp;:&nbsp;'.$text_stock_reel.'</span>';
  2036. }
  2037. if (isModEnabled('supplier_order')) {
  2038. $text_info .= '&nbsp;'.$langs->trans('SupplierOrder').'&nbsp;:&nbsp;'.$stock_order_supplier;
  2039. }
  2040. $text_info .= ($reliquat != $obj->qty ? ' <span class="opacitymedium">('.$langs->trans("QtyInOtherShipments").' '.($obj->qty - $reliquat).')</span>' : '');
  2041. $text_info .= '<br>';
  2042. }
  2043. }
  2044. if ($notshippable == 0) {
  2045. $text_icon = img_picto('', 'dolly', '', false, 0, 0, '', 'green paddingleft');
  2046. $text_info = $text_icon.' '.$langs->trans('Shippable').'<br>'.$text_info;
  2047. } else {
  2048. $text_icon = img_picto('', 'dolly', '', false, 0, 0, '', 'error paddingleft');
  2049. $text_info = $text_icon.' '.$langs->trans('NonShippable').'<br>'.$text_info;
  2050. }
  2051. }
  2052. if ($nbprod) {
  2053. print $form->textwithtooltip('', $text_info, 2, 1, $text_icon, '', 2);
  2054. }
  2055. if ($warning) { // Always false in default mode
  2056. print $form->textwithtooltip('', $langs->trans('NotEnoughForAllOrders').'<br>'.$text_warning, 2, 1, img_picto('', 'error'), '', 2);
  2057. }
  2058. }
  2059. print '</td>';
  2060. if (!$i) {
  2061. $totalarray['nbfield']++;
  2062. }
  2063. }
  2064. // Billed
  2065. if (!empty($arrayfields['c.facture']['checked'])) {
  2066. print '<td class="center">'.yn($obj->billed).'</td>';
  2067. if (!$i) {
  2068. $totalarray['nbfield']++;
  2069. }
  2070. }
  2071. // Import key
  2072. if (!empty($arrayfields['c.import_key']['checked'])) {
  2073. print '<td class="nowrap center">'.$obj->import_key.'</td>';
  2074. if (!$i) {
  2075. $totalarray['nbfield']++;
  2076. }
  2077. }
  2078. // Status
  2079. if (!empty($arrayfields['c.fk_statut']['checked'])) {
  2080. print '<td class="nowrap center">'.$generic_commande->LibStatut($obj->fk_statut, $obj->billed, 5, 1).'</td>';
  2081. if (!$i) {
  2082. $totalarray['nbfield']++;
  2083. }
  2084. }
  2085. // Action column
  2086. if (!getDolGlobalInt('MAIN_CHECKBOX_LEFT_COLUMN')) {
  2087. print '<td class="nowrap center">';
  2088. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  2089. $selected = 0;
  2090. if (in_array($obj->rowid, $arrayofselected)) {
  2091. $selected = 1;
  2092. }
  2093. print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
  2094. }
  2095. print '</td>';
  2096. if (!$i) {
  2097. $totalarray['nbfield']++;
  2098. }
  2099. }
  2100. print "</tr>\n";
  2101. $total += $obj->total_ht;
  2102. $subtotal += $obj->total_ht;
  2103. $i++;
  2104. }
  2105. if ($sortfield == 'pr.ref') {
  2106. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_subtotal.tpl.php';
  2107. }
  2108. // Show total line
  2109. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  2110. // If no record found
  2111. if ($num == 0) {
  2112. $colspan = 1;
  2113. foreach ($arrayfields as $key => $val) {
  2114. if (!empty($val['checked'])) {
  2115. $colspan++;
  2116. }
  2117. }
  2118. print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
  2119. }
  2120. $db->free($resql);
  2121. $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  2122. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters); // Note that $action and $object may have been modified by hook
  2123. print $hookmanager->resPrint;
  2124. print '</table>'."\n";
  2125. print '</div>';
  2126. print '</form>'."\n";
  2127. $hidegeneratedfilelistifempty = 1;
  2128. if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
  2129. $hidegeneratedfilelistifempty = 0;
  2130. }
  2131. // Show list of available documents
  2132. $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
  2133. $urlsource .= str_replace('&amp;', '&', $param);
  2134. $filedir = $diroutputmassaction;
  2135. $genallowed = $permissiontoread;
  2136. $delallowed = $permissiontoadd;
  2137. print $formfile->showdocuments('massfilesarea_orders', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
  2138. } else {
  2139. dol_print_error($db);
  2140. }
  2141. // End of page
  2142. llxFooter();
  2143. $db->close();