list_det.php 92 KB

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