list.php 101 KB

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