list_det.php 96 KB

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