list.php 82 KB

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