list.php 102 KB

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