list.php 103 KB

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