list.php 111 KB

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