list.php 112 KB

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