list.php 109 KB

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