list.php 113 KB

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