list.php 103 KB

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