list.php 85 KB

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