list.php 90 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129
  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.fk_statut'=>array('label'=>"Status", 'checked'=>1, 'position'=>1000)
  192. );
  193. // Extra fields
  194. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
  195. $object->fields = dol_sort_array($object->fields, 'position');
  196. $arrayfields = dol_sort_array($arrayfields, 'position');
  197. /*
  198. * Actions
  199. */
  200. if (GETPOST('cancel', 'alpha')) {
  201. $action = 'list'; $massaction = '';
  202. }
  203. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend' && $massaction != 'confirm_createbills') {
  204. $massaction = '';
  205. }
  206. $parameters = array('socid'=>$socid);
  207. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  208. if ($reshook < 0) {
  209. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  210. }
  211. if (empty($reshook)) {
  212. // Selection of new fields
  213. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  214. // Purge search criteria
  215. 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
  216. $search_categ = '';
  217. $search_user = '';
  218. $search_sale = '';
  219. $search_product_category = '';
  220. $search_ref = '';
  221. $search_ref_customer = '';
  222. $search_company = '';
  223. $search_company_alias = '';
  224. $search_town = '';
  225. $search_zip = "";
  226. $search_state = "";
  227. $search_type = '';
  228. $search_country = '';
  229. $search_type_thirdparty = '';
  230. $search_total_ht = '';
  231. $search_total_vat = '';
  232. $search_total_ttc = '';
  233. $search_warehouse = '';
  234. $search_multicurrency_code = '';
  235. $search_multicurrency_tx = '';
  236. $search_multicurrency_montant_ht = '';
  237. $search_multicurrency_montant_vat = '';
  238. $search_multicurrency_montant_ttc = '';
  239. $search_login = '';
  240. $search_dateorder_start = '';
  241. $search_dateorder_end = '';
  242. $search_datedelivery_start = '';
  243. $search_datedelivery_end = '';
  244. $search_project_ref = '';
  245. $search_project = '';
  246. $search_status = '';
  247. $search_billed = '';
  248. $toselect = '';
  249. $search_array_options = array();
  250. $search_categ_cus = 0;
  251. $search_datecloture_start = '';
  252. $search_datecloture_end = '';
  253. $search_fk_cond_reglement = '';
  254. $search_fk_shipping_method = '';
  255. $search_fk_mode_reglement = '';
  256. $search_fk_input_reason = '';
  257. }
  258. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
  259. || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
  260. $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
  261. }
  262. // Mass actions
  263. $objectclass = 'Commande';
  264. $objectlabel = 'Orders';
  265. $permissiontoread = $user->rights->commande->lire;
  266. $permissiontoadd = $user->rights->commande->creer;
  267. $permissiontodelete = $user->rights->commande->supprimer;
  268. if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS)) {
  269. $permissiontovalidate = $user->rights->commande->order_advance->validate;
  270. $permissiontoclose = $user->rights->commande->order_advance->close;
  271. $permissiontocancel = $user->rights->commande->order_advance->annuler;
  272. $permissiontosendbymail = $user->rights->commande->order_advance->send;
  273. } else {
  274. $permissiontovalidate = $user->rights->commande->creer;
  275. $permissiontoclose = $user->rights->commande->creer;
  276. $permissiontocancel = $user->rights->commande->creer;
  277. $permissiontosendbymail = $user->rights->commande->creer;
  278. }
  279. $uploaddir = $conf->commande->multidir_output[$conf->entity];
  280. $triggersendname = 'ORDER_SENTBYMAIL';
  281. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  282. }
  283. if ($action == 'validate' && $permissiontoadd) {
  284. if (GETPOST('confirm') == 'yes') {
  285. $objecttmp = new $objectclass($db);
  286. $db->begin();
  287. $error = 0;
  288. foreach ($toselect as $checked) {
  289. if ($objecttmp->fetch($checked)) {
  290. if ($objecttmp->statut == 0) {
  291. if (!empty($objecttmp->fk_warehouse)) {
  292. $idwarehouse = $objecttmp->fk_warehouse;
  293. } else {
  294. $idwarehouse = 0;
  295. }
  296. if ($objecttmp->valid($user, $idwarehouse)) {
  297. setEventMessage($langs->trans('hasBeenValidated', $objecttmp->ref), 'mesgs');
  298. } else {
  299. setEventMessage($objecttmp->error, $objecttmp->errors, 'errors');
  300. $error++;
  301. }
  302. } else {
  303. $langs->load("errors");
  304. setEventMessage($langs->trans('ErrorIsNotADraft', $objecttmp->ref), 'errors');
  305. $error++;
  306. }
  307. } else {
  308. dol_print_error($db);
  309. $error++;
  310. }
  311. }
  312. if ($error) {
  313. $db->rollback();
  314. } else {
  315. $db->commit();
  316. }
  317. }
  318. }
  319. if ($action == 'shipped' && $permissiontoadd) {
  320. if (GETPOST('confirm') == 'yes') {
  321. $objecttmp = new $objectclass($db);
  322. $db->begin();
  323. $error = 0;
  324. foreach ($toselect as $checked) {
  325. if ($objecttmp->fetch($checked)) {
  326. if ($objecttmp->statut == 1 || $objecttmp->statut == 2) {
  327. if ($objecttmp->cloture($user)) {
  328. setEventMessage($langs->trans('PassedInClosedStatus', $objecttmp->ref), 'mesgs');
  329. } else {
  330. setEventMessage($langs->trans('CantBeClosed'), 'errors');
  331. $error++;
  332. }
  333. } else {
  334. $langs->load("errors");
  335. setEventMessage($langs->trans('ErrorIsNotADraft', $objecttmp->ref), 'errors');
  336. $error++;
  337. }
  338. } else {
  339. dol_print_error($db);
  340. $error++;
  341. }
  342. }
  343. if ($error) {
  344. $db->rollback();
  345. } else {
  346. $db->commit();
  347. }
  348. }
  349. }
  350. // Closed records
  351. if (!$error && $massaction === 'setbilled' && $permissiontoclose) {
  352. $db->begin();
  353. $objecttmp = new $objectclass($db);
  354. $nbok = 0;
  355. foreach ($toselect as $toselectid) {
  356. $result = $objecttmp->fetch($toselectid);
  357. if ($result > 0) {
  358. $result = $objecttmp->classifyBilled($user, 0);
  359. if ($result <= 0) {
  360. setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
  361. $error++;
  362. break;
  363. } else {
  364. $nbok++;
  365. }
  366. } else {
  367. setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
  368. $error++;
  369. break;
  370. }
  371. }
  372. if (!$error) {
  373. if ($nbok > 1) {
  374. setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs');
  375. } else {
  376. setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs');
  377. }
  378. $db->commit();
  379. } else {
  380. $db->rollback();
  381. }
  382. }
  383. /*
  384. * View
  385. */
  386. $now = dol_now();
  387. $form = new Form($db);
  388. $formother = new FormOther($db);
  389. $formfile = new FormFile($db);
  390. $formmargin = null;
  391. if (!empty($conf->margin->enabled)) {
  392. $formmargin = new FormMargin($db);
  393. }
  394. $companystatic = new Societe($db);
  395. $formcompany = new FormCompany($db);
  396. $projectstatic = new Project($db);
  397. $title = $langs->trans("Orders");
  398. $help_url = "EN:Module_Customers_Orders|FR:Module_Commandes_Clients|ES:Módulo_Pedidos_de_clientes";
  399. // llxHeader('',$title,$help_url);
  400. $sql = 'SELECT';
  401. if ($sall || $search_product_category > 0 || $search_user > 0) {
  402. $sql = 'SELECT DISTINCT';
  403. }
  404. $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,';
  405. $sql .= " typent.code as typent_code,";
  406. $sql .= " state.code_departement as state_code, state.nom as state_name,";
  407. $sql .= " country.code as country_code,";
  408. $sql .= ' c.rowid, c.ref, c.total_ht, c.total_tva, c.total_ttc, c.ref_client, c.fk_user_author,';
  409. $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,';
  410. $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,';
  411. $sql .= ' c.date_creation as date_creation, c.tms as date_update, c.date_cloture as date_cloture,';
  412. $sql .= ' p.rowid as project_id, p.ref as project_ref, p.title as project_label,';
  413. $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,';
  414. $sql .= ' c.fk_cond_reglement,c.fk_mode_reglement,c.fk_shipping_method,';
  415. $sql .= ' c.fk_input_reason';
  416. if (($search_categ_cus > 0) || ($search_categ_cus == -2)) {
  417. $sql .= ", cc.fk_categorie, cc.fk_soc";
  418. }
  419. // Add fields from extrafields
  420. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  421. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  422. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
  423. }
  424. }
  425. // Add fields from hooks
  426. $parameters = array();
  427. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
  428. $sql .= $hookmanager->resPrint;
  429. $sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s';
  430. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
  431. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
  432. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)";
  433. if (($search_categ_cus > 0) || ($search_categ_cus == -2)) {
  434. $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
  435. }
  436. $sql .= ', '.MAIN_DB_PREFIX.'commande as c';
  437. if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
  438. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."commande_extrafields as ef on (c.rowid = ef.fk_object)";
  439. }
  440. if ($sall || $search_product_category > 0) {
  441. $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'commandedet as pd ON c.rowid=pd.fk_commande';
  442. }
  443. if ($search_product_category > 0) {
  444. $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=pd.fk_product';
  445. }
  446. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as p ON p.rowid = c.fk_projet";
  447. $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as u ON c.fk_user_author = u.rowid';
  448. // We'll need this table joined to the select in order to filter by sale
  449. if ($search_sale > 0 || (empty($user->rights->societe->client->voir) && !$socid)) {
  450. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  451. }
  452. if ($search_user > 0) {
  453. $sql .= ", ".MAIN_DB_PREFIX."element_contact as ec";
  454. $sql .= ", ".MAIN_DB_PREFIX."c_type_contact as tc";
  455. }
  456. // Add table from hooks
  457. $parameters = array();
  458. $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
  459. $sql .= $hookmanager->resPrint;
  460. $sql .= ' WHERE c.fk_soc = s.rowid';
  461. $sql .= ' AND c.entity IN ('.getEntity('commande').')';
  462. if ($search_product_category > 0) {
  463. $sql .= " AND cp.fk_categorie = ".((int) $search_product_category);
  464. }
  465. if ($socid > 0) {
  466. $sql .= ' AND s.rowid = '.((int) $socid);
  467. }
  468. if (empty($user->rights->societe->client->voir) && !$socid) {
  469. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  470. }
  471. if ($search_ref) {
  472. $sql .= natural_search('c.ref', $search_ref);
  473. }
  474. if ($search_ref_customer) {
  475. $sql .= natural_search('c.ref_client', $search_ref_customer);
  476. }
  477. if ($sall) {
  478. $sql .= natural_search(array_keys($fieldstosearchall), $sall);
  479. }
  480. if ($search_billed != '' && $search_billed >= 0) {
  481. $sql .= ' AND c.facture = '.((int) $search_billed);
  482. }
  483. if ($search_status <> '') {
  484. if ($search_status <= 3 && $search_status >= -1) { // status from -1 to 3 are real status (other are virtual combination)
  485. if ($search_status == 1 && empty($conf->expedition->enabled)) {
  486. $sql .= ' AND c.fk_statut IN (1,2)'; // If module expedition disabled, we include order with status 'sending in process' into 'validated'
  487. } else {
  488. $sql .= ' AND c.fk_statut = '.((int) $search_status); // brouillon, validee, en cours, annulee
  489. }
  490. }
  491. if ($search_status == -2) { // To process
  492. //$sql.= ' AND c.fk_statut IN (1,2,3) AND c.facture = 0';
  493. $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
  494. }
  495. if ($search_status == -3) { // To bill
  496. //$sql.= ' AND c.fk_statut in (1,2,3)';
  497. //$sql.= ' AND c.facture = 0'; // invoice not created
  498. $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
  499. }
  500. if ($search_status == -4) { // "validate and in progress"
  501. $sql .= ' AND (c.fk_statut IN (1,2))'; // validated, in process
  502. }
  503. }
  504. if ($search_datecloture_start) {
  505. $sql .= " AND c.date_cloture >= '".$db->idate($search_datecloture_start)."'";
  506. }
  507. if ($search_datecloture_end) {
  508. $sql .= " AND c.date_cloture <= '".$db->idate($search_datecloture_end)."'";
  509. }
  510. if ($search_dateorder_start) {
  511. $sql .= " AND c.date_commande >= '".$db->idate($search_dateorder_start)."'";
  512. }
  513. if ($search_dateorder_end) {
  514. $sql .= " AND c.date_commande <= '".$db->idate($search_dateorder_end)."'";
  515. }
  516. if ($search_datedelivery_start) {
  517. $sql .= " AND c.date_livraison >= '".$db->idate($search_datedelivery_start)."'";
  518. }
  519. if ($search_datedelivery_end) {
  520. $sql .= " AND c.date_livraison <= '".$db->idate($search_datedelivery_end)."'";
  521. }
  522. if ($search_town) {
  523. $sql .= natural_search('s.town', $search_town);
  524. }
  525. if ($search_zip) {
  526. $sql .= natural_search("s.zip", $search_zip);
  527. }
  528. if ($search_state) {
  529. $sql .= natural_search("state.nom", $search_state);
  530. }
  531. if ($search_country) {
  532. $sql .= " AND s.fk_pays IN (".$db->sanitize($search_country).')';
  533. }
  534. if ($search_type_thirdparty && $search_type_thirdparty != '-1') {
  535. $sql .= " AND s.fk_typent IN (".$db->sanitize($search_type_thirdparty).')';
  536. }
  537. if ($search_company) {
  538. $sql .= natural_search('s.nom', $search_company);
  539. }
  540. if ($search_company_alias) {
  541. $sql .= natural_search('s.name_alias', $search_company_alias);
  542. }
  543. if ($search_sale > 0) {
  544. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $search_sale);
  545. }
  546. if ($search_user > 0) {
  547. $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);
  548. }
  549. if ($search_total_ht != '') {
  550. $sql .= natural_search('c.total_ht', $search_total_ht, 1);
  551. }
  552. if ($search_total_vat != '') {
  553. $sql .= natural_search('c.total_tva', $search_total_vat, 1);
  554. }
  555. if ($search_total_ttc != '') {
  556. $sql .= natural_search('c.total_ttc', $search_total_ttc, 1);
  557. }
  558. if ($search_warehouse != '' && $search_warehouse > 0) {
  559. $sql .= natural_search('c.fk_warehouse', $search_warehouse, 1);
  560. }
  561. if ($search_multicurrency_code != '') {
  562. $sql .= " AND c.multicurrency_code = '".$db->escape($search_multicurrency_code)."'";
  563. }
  564. if ($search_multicurrency_tx != '') {
  565. $sql .= natural_search('c.multicurrency_tx', $search_multicurrency_tx, 1);
  566. }
  567. if ($search_multicurrency_montant_ht != '') {
  568. $sql .= natural_search('c.multicurrency_total_ht', $search_multicurrency_montant_ht, 1);
  569. }
  570. if ($search_multicurrency_montant_vat != '') {
  571. $sql .= natural_search('c.multicurrency_total_tva', $search_multicurrency_montant_vat, 1);
  572. }
  573. if ($search_multicurrency_montant_ttc != '') {
  574. $sql .= natural_search('c.multicurrency_total_ttc', $search_multicurrency_montant_ttc, 1);
  575. }
  576. if ($search_login) {
  577. $sql .= natural_search(array("u.login", "u.firstname", "u.lastname"), $search_login);
  578. }
  579. if ($search_project_ref != '') {
  580. $sql .= natural_search("p.ref", $search_project_ref);
  581. }
  582. if ($search_project != '') {
  583. $sql .= natural_search("p.title", $search_project);
  584. }
  585. if ($search_categ_cus > 0) {
  586. $sql .= " AND cc.fk_categorie = ".((int) $search_categ_cus);
  587. }
  588. if ($search_categ_cus == -2) {
  589. $sql .= " AND cc.fk_categorie IS NULL";
  590. }
  591. if ($search_fk_cond_reglement > 0) {
  592. $sql .= " AND c.fk_cond_reglement = ".((int) $search_fk_cond_reglement);
  593. }
  594. if ($search_fk_shipping_method > 0) {
  595. $sql .= " AND c.fk_shipping_method = ".((int) $search_fk_shipping_method);
  596. }
  597. if ($search_fk_mode_reglement > 0) {
  598. $sql .= " AND c.fk_mode_reglement = ".((int) $search_fk_mode_reglement);
  599. }
  600. if ($search_fk_input_reason > 0) {
  601. $sql .= " AND c.fk_input_reason = ".((int) $search_fk_input_reason);
  602. }
  603. // Add where from extra fields
  604. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  605. // Add where from hooks
  606. $parameters = array();
  607. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
  608. $sql .= $hookmanager->resPrint;
  609. // Add HAVING from hooks
  610. $parameters = array();
  611. $reshook = $hookmanager->executeHooks('printFieldListHaving', $parameters, $object); // Note that $action and $object may have been modified by hook
  612. $sql .= empty($hookmanager->resPrint) ? "" : " HAVING 1=1 ".$hookmanager->resPrint;
  613. $sql .= $db->order($sortfield, $sortorder);
  614. // Count total nb of records
  615. $nbtotalofrecords = '';
  616. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
  617. $result = $db->query($sql);
  618. $nbtotalofrecords = $db->num_rows($result);
  619. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
  620. $page = 0;
  621. $offset = 0;
  622. }
  623. }
  624. $sql .= $db->plimit($limit + 1, $offset);
  625. //print $sql;
  626. $resql = $db->query($sql);
  627. if ($resql) {
  628. if ($socid > 0) {
  629. $soc = new Societe($db);
  630. $soc->fetch($socid);
  631. $title = $langs->trans('ListOfOrders').' - '.$soc->name;
  632. if (empty($search_company)) {
  633. $search_company = $soc->name;
  634. }
  635. } else {
  636. $title = $langs->trans('ListOfOrders');
  637. }
  638. if (strval($search_status) == '0') {
  639. $title .= ' - '.$langs->trans('StatusOrderDraftShort');
  640. }
  641. if ($search_status == 1) {
  642. $title .= ' - '.$langs->trans('StatusOrderValidatedShort');
  643. }
  644. if ($search_status == 2) {
  645. $title .= ' - '.$langs->trans('StatusOrderSentShort');
  646. }
  647. if ($search_status == 3) {
  648. $title .= ' - '.$langs->trans('StatusOrderToBillShort');
  649. }
  650. if ($search_status == -1) {
  651. $title .= ' - '.$langs->trans('StatusOrderCanceledShort');
  652. }
  653. if ($search_status == -2) {
  654. $title .= ' - '.$langs->trans('StatusOrderToProcessShort');
  655. }
  656. if ($search_status == -3) {
  657. $title .= ' - '.$langs->trans('StatusOrderValidated').', '.(empty($conf->expedition->enabled) ? '' : $langs->trans("StatusOrderSent").', ').$langs->trans('StatusOrderToBill');
  658. }
  659. if ($search_status == -4) {
  660. $title .= ' - '.$langs->trans("StatusOrderValidatedShort").'+'.$langs->trans("StatusOrderSentShort");
  661. }
  662. $num = $db->num_rows($resql);
  663. $arrayofselected = is_array($toselect) ? $toselect : array();
  664. if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $sall) {
  665. $obj = $db->fetch_object($resql);
  666. $id = $obj->rowid;
  667. header("Location: ".DOL_URL_ROOT.'/commande/card.php?id='.$id);
  668. exit;
  669. }
  670. llxHeader('', $title, $help_url);
  671. $param = '';
  672. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  673. $param .= '&contextpage='.urlencode($contextpage);
  674. }
  675. if ($limit > 0 && $limit != $conf->liste_limit) {
  676. $param .= '&limit='.urlencode($limit);
  677. }
  678. if ($sall) {
  679. $param .= '&sall='.urlencode($sall);
  680. }
  681. if ($socid > 0) {
  682. $param .= '&socid='.urlencode($socid);
  683. }
  684. if ($search_status != '') {
  685. $param .= '&search_status='.urlencode($search_status);
  686. }
  687. if ($search_datecloture_start) {
  688. $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');
  689. }
  690. if ($search_datecloture_end) {
  691. $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');
  692. }
  693. if ($search_dateorder_start) {
  694. $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');
  695. }
  696. if ($search_dateorder_end) {
  697. $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');
  698. }
  699. if ($search_datedelivery_start) {
  700. $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');
  701. }
  702. if ($search_datedelivery_end) {
  703. $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');
  704. }
  705. if ($search_ref) {
  706. $param .= '&search_ref='.urlencode($search_ref);
  707. }
  708. if ($search_company) {
  709. $param .= '&search_company='.urlencode($search_company);
  710. }
  711. if ($search_company_alias) {
  712. $param .= '&search_company_alias='.urlencode($search_company_alias);
  713. }
  714. if ($search_ref_customer) {
  715. $param .= '&search_ref_customer='.urlencode($search_ref_customer);
  716. }
  717. if ($search_user > 0) {
  718. $param .= '&search_user='.urlencode($search_user);
  719. }
  720. if ($search_sale > 0) {
  721. $param .= '&search_sale='.urlencode($search_sale);
  722. }
  723. if ($search_total_ht != '') {
  724. $param .= '&search_total_ht='.urlencode($search_total_ht);
  725. }
  726. if ($search_total_vat != '') {
  727. $param .= '&search_total_vat='.urlencode($search_total_vat);
  728. }
  729. if ($search_total_ttc != '') {
  730. $param .= '&search_total_ttc='.urlencode($search_total_ttc);
  731. }
  732. if ($search_warehouse != '') {
  733. $param .= '&search_warehouse='.urlencode($search_warehouse);
  734. }
  735. if ($search_login) {
  736. $param .= '&search_login='.urlencode($search_login);
  737. }
  738. if ($search_multicurrency_code != '') {
  739. $param .= '&search_multicurrency_code='.urlencode($search_multicurrency_code);
  740. }
  741. if ($search_multicurrency_tx != '') {
  742. $param .= '&search_multicurrency_tx='.urlencode($search_multicurrency_tx);
  743. }
  744. if ($search_multicurrency_montant_ht != '') {
  745. $param .= '&search_multicurrency_montant_ht='.urlencode($search_multicurrency_montant_ht);
  746. }
  747. if ($search_multicurrency_montant_vat != '') {
  748. $param .= '&search_multicurrency_montant_vat='.urlencode($search_multicurrency_montant_vat);
  749. }
  750. if ($search_multicurrency_montant_ttc != '') {
  751. $param .= '&search_multicurrency_montant_ttc='.urlencode($search_multicurrency_montant_ttc);
  752. }
  753. if ($search_project_ref >= 0) {
  754. $param .= "&search_project_ref=".urlencode($search_project_ref);
  755. }
  756. if ($search_town != '') {
  757. $param .= '&search_town='.urlencode($search_town);
  758. }
  759. if ($search_zip != '') {
  760. $param .= '&search_zip='.urlencode($search_zip);
  761. }
  762. if ($search_state != '') {
  763. $param .= '&search_state='.urlencode($search_state);
  764. }
  765. if ($search_country != '') {
  766. $param .= '&search_country='.urlencode($search_country);
  767. }
  768. if ($search_type_thirdparty && $search_type_thirdparty != '-1') {
  769. $param .= '&search_type_thirdparty='.urlencode($search_type_thirdparty);
  770. }
  771. if ($search_product_category != '') {
  772. $param .= '&search_product_category='.urlencode($search_product_category);
  773. }
  774. if (($search_categ_cus > 0) || ($search_categ_cus == -2)) {
  775. $param .= '&search_categ_cus='.urlencode($search_categ_cus);
  776. }
  777. if ($show_files) {
  778. $param .= '&show_files='.urlencode($show_files);
  779. }
  780. if ($optioncss != '') {
  781. $param .= '&optioncss='.urlencode($optioncss);
  782. }
  783. if ($search_billed != '') {
  784. $param .= '&search_billed='.urlencode($search_billed);
  785. }
  786. if ($search_fk_cond_reglement > 0) {
  787. $param .= '&search_fk_cond_reglement='.urlencode($search_fk_cond_reglement);
  788. }
  789. if ($search_fk_shipping_method > 0) {
  790. $param .= '&search_fk_shipping_method='.urlencode($search_fk_shipping_method);
  791. }
  792. if ($search_fk_mode_reglement > 0) {
  793. $param .= '&search_fk_mode_reglement='.urlencode($search_fk_mode_reglement);
  794. }
  795. if ($search_fk_input_reason > 0) {
  796. $param .= '&search_fk_input_reason='.urlencode($search_fk_input_reason);
  797. }
  798. // Add $param from extra fields
  799. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  800. // Add $param from hooks
  801. $parameters = array();
  802. $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
  803. $param .= $hookmanager->resPrint;
  804. // List of mass actions available
  805. $arrayofmassactions = array(
  806. 'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
  807. 'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
  808. );
  809. if ($permissiontovalidate) {
  810. $arrayofmassactions['prevalidate'] = img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate");
  811. }
  812. if ($permissiontosendbymail) {
  813. $arrayofmassactions['presend'] = img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail");
  814. }
  815. if ($permissiontoclose) {
  816. $arrayofmassactions['preshipped'] = img_picto('', 'dollyrevert', 'class="pictofixedwidth"').$langs->trans("ClassifyShipped");
  817. }
  818. if ($permissiontocancel) {
  819. $arrayofmassactions['cancelorders'] = img_picto('', 'close_title', 'class="pictofixedwidth"').$langs->trans("Cancel");
  820. }
  821. if ($user->rights->facture->creer) {
  822. $arrayofmassactions['createbills'] = img_picto('', 'bill', 'class="pictofixedwidth"').$langs->trans("CreateInvoiceForThisCustomer");
  823. }
  824. if ($permissiontoclose) {
  825. $arrayofmassactions['setbilled'] = img_picto('', 'bill', 'class="pictofixedwidth"').$langs->trans("ClassifyBilled");
  826. }
  827. if ($permissiontodelete) {
  828. $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
  829. }
  830. if (in_array($massaction, array('presend', 'predelete', 'createbills'))) {
  831. $arrayofmassactions = array();
  832. }
  833. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  834. $url = DOL_URL_ROOT.'/commande/card.php?action=create';
  835. if (!empty($socid)) {
  836. $url .= '&socid='.$socid;
  837. }
  838. $newcardbutton = dolGetButtonTitle($langs->trans('NewOrder'), '', 'fa fa-plus-circle', $url, '', $contextpage == 'orderlist' && $permissiontoadd);
  839. // Lines of title fields
  840. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
  841. if ($optioncss != '') {
  842. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  843. }
  844. print '<input type="hidden" name="token" value="'.newToken().'">';
  845. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  846. print '<input type="hidden" name="action" value="list">';
  847. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  848. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  849. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  850. print '<input type="hidden" name="search_status" value="'.$search_status.'">';
  851. print '<input type="hidden" name="socid" value="'.$socid.'">';
  852. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'order', 0, $newcardbutton, '', $limit, 0, 0, 1);
  853. $topicmail = "SendOrderRef";
  854. $modelmail = "order_send";
  855. $objecttmp = new Commande($db);
  856. $trackid = 'ord'.$object->id;
  857. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  858. if ($massaction == 'prevalidate') {
  859. print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassValidation"), $langs->trans("ConfirmMassValidationQuestion"), "validate", null, '', 0, 200, 500, 1);
  860. }
  861. if ($massaction == 'preshipped') {
  862. print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("CloseOrder"), $langs->trans("ConfirmCloseOrder"), "shipped", null, '', 0, 200, 500, 1);
  863. }
  864. if ($massaction == 'createbills') {
  865. print '<input type="hidden" name="massaction" value="confirm_createbills">';
  866. print '<table class="noborder" width="100%" >';
  867. print '<tr>';
  868. print '<td class="titlefield">';
  869. print $langs->trans('DateInvoice');
  870. print '</td>';
  871. print '<td>';
  872. print $form->selectDate('', '', '', '', '', '', 1, 1);
  873. print '</td>';
  874. print '</tr>';
  875. print '<tr>';
  876. print '<td>';
  877. print $langs->trans('CreateOneBillByThird');
  878. print '</td>';
  879. print '<td>';
  880. print $form->selectyesno('createbills_onebythird', '', 1);
  881. print '</td>';
  882. print '</tr>';
  883. print '<tr>';
  884. print '<td>';
  885. print $langs->trans('ValidateInvoices');
  886. print '</td>';
  887. print '<td>';
  888. if (!empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_BILL)) {
  889. print $form->selectyesno('validate_invoices', 0, 1, 1);
  890. print ' ('.$langs->trans("AutoValidationNotPossibleWhenStockIsDecreasedOnInvoiceValidation").')';
  891. } else {
  892. print $form->selectyesno('validate_invoices', 0, 1);
  893. }
  894. if (!empty($conf->workflow->enabled) && !empty($conf->global->WORKFLOW_INVOICE_AMOUNT_CLASSIFY_BILLED_ORDER)) {
  895. print ' &nbsp; &nbsp; <span class="opacitymedium">'.$langs->trans("IfValidateInvoiceIsNoOrderStayUnbilled").'</span>';
  896. } else {
  897. print ' &nbsp; &nbsp; <span class="opacitymedium">'.$langs->trans("OptionToSetOrderBilledNotEnabled").'</span>';
  898. }
  899. print '</td>';
  900. print '</tr>';
  901. print '</table>';
  902. print '<br>';
  903. print '<div class="center">';
  904. print '<input type="submit" class="button" id="createbills" name="createbills" value="'.$langs->trans('CreateInvoiceForThisCustomer').'"> ';
  905. print '<input type="submit" class="button button-cancel" id="cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
  906. print '</div>';
  907. print '<br>';
  908. }
  909. if ($sall) {
  910. foreach ($fieldstosearchall as $key => $val) {
  911. $fieldstosearchall[$key] = $langs->trans($val);
  912. }
  913. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'</div>';
  914. }
  915. $moreforfilter = '';
  916. // If the user can view prospects other than his'
  917. if ($user->rights->societe->client->voir || $socid) {
  918. $langs->load("commercial");
  919. $moreforfilter .= '<div class="divsearchfield">';
  920. $tmptitle = $langs->trans('ThirdPartiesOfSaleRepresentative');
  921. $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, $tmptitle, 'maxwidth250 widthcentpercentminusx');
  922. $moreforfilter .= '</div>';
  923. }
  924. // If the user can view other users
  925. if ($user->rights->user->user->lire) {
  926. $moreforfilter .= '<div class="divsearchfield">';
  927. $tmptitle = $langs->trans('LinkedToSpecificUsers');
  928. $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$form->select_dolusers($search_user, 'search_user', $tmptitle, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth250 widthcentpercentminusx');
  929. $moreforfilter .= '</div>';
  930. }
  931. // If the user can view prospects other than his'
  932. if (!empty($conf->categorie->enabled) && $user->rights->categorie->lire && ($user->rights->produit->lire || $user->rights->service->lire)) {
  933. include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  934. $moreforfilter .= '<div class="divsearchfield">';
  935. $tmptitle = $langs->trans('IncludingProductWithTag');
  936. $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, null, 'parent', null, null, 1);
  937. $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);
  938. $moreforfilter .= '</div>';
  939. }
  940. if (!empty($conf->categorie->enabled) && $user->rights->categorie->lire) {
  941. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  942. $moreforfilter .= '<div class="divsearchfield">';
  943. $tmptitle = $langs->trans('CustomersProspectsCategoriesShort');
  944. $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"').$formother->select_categories('customer', $search_categ_cus, 'search_categ_cus', 1, $tmptitle, 'maxwidth300 widthcentpercentminusx');
  945. $moreforfilter .= '</div>';
  946. }
  947. if (!empty($conf->stock->enabled) && !empty($conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER)) {
  948. require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
  949. $formproduct = new FormProduct($db);
  950. $moreforfilter .= '<div class="divsearchfield">';
  951. $tmptitle = $langs->trans('Warehouse');
  952. $moreforfilter .= img_picto($tmptitle, 'stock', 'class="pictofixedwidth"').$formproduct->selectWarehouses($search_warehouse, 'search_warehouse', '', 1, 0, 0, $tmptitle, 0, 0, array(), 'maxwidth250 widthcentpercentminusx');
  953. $moreforfilter .= '</div>';
  954. }
  955. $parameters = array();
  956. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
  957. if (empty($reshook)) {
  958. $moreforfilter .= $hookmanager->resPrint;
  959. } else {
  960. $moreforfilter = $hookmanager->resPrint;
  961. }
  962. if (!empty($moreforfilter)) {
  963. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  964. print $moreforfilter;
  965. print '</div>';
  966. }
  967. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  968. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  969. $selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
  970. if (GETPOST('autoselectall', 'int')) {
  971. $selectedfields .= '<script>';
  972. $selectedfields .= ' $(document).ready(function() {';
  973. $selectedfields .= ' console.log("Autoclick on checkforselects");';
  974. $selectedfields .= ' $("#checkforselects").click();';
  975. $selectedfields .= ' $("#massaction").val("createbills").change();';
  976. $selectedfields .= ' });';
  977. $selectedfields .= '</script>';
  978. }
  979. print '<div class="div-table-responsive">';
  980. print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  981. print '<tr class="liste_titre_filter">';
  982. // Ref
  983. if (!empty($arrayfields['c.ref']['checked'])) {
  984. print '<td class="liste_titre">';
  985. print '<input class="flat" size="6" type="text" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">';
  986. print '</td>';
  987. }
  988. // Ref customer
  989. if (!empty($arrayfields['c.ref_client']['checked'])) {
  990. print '<td class="liste_titre" align="left">';
  991. print '<input class="flat" type="text" size="6" name="search_ref_customer" value="'.dol_escape_htmltag($search_ref_customer).'">';
  992. print '</td>';
  993. }
  994. // Project ref
  995. if (!empty($arrayfields['p.ref']['checked'])) {
  996. print '<td class="liste_titre"><input type="text" class="flat" size="6" name="search_project_ref" value="'.dol_escape_htmltag($search_project_ref).'"></td>';
  997. }
  998. // Project title
  999. if (!empty($arrayfields['p.title']['checked'])) {
  1000. print '<td class="liste_titre"><input type="text" class="flat" size="6" name="search_project" value="'.dol_escape_htmltag($search_project).'"></td>';
  1001. }
  1002. // Thirpdarty
  1003. if (!empty($arrayfields['s.nom']['checked'])) {
  1004. print '<td class="liste_titre" align="left">';
  1005. print '<input class="flat maxwidth100" type="text" name="search_company" value="'.dol_escape_htmltag($search_company).'">';
  1006. print '</td>';
  1007. }
  1008. // Alias
  1009. if (!empty($arrayfields['s.name_alias']['checked'])) {
  1010. print '<td class="liste_titre" align="left">';
  1011. print '<input class="flat maxwidth100" type="text" name="search_company_alias" value="'.dol_escape_htmltag($search_company_alias).'">';
  1012. print '</td>';
  1013. }
  1014. // Town
  1015. if (!empty($arrayfields['s.town']['checked'])) {
  1016. print '<td class="liste_titre"><input class="flat" type="text" size="4" name="search_town" value="'.dol_escape_htmltag($search_town).'"></td>';
  1017. }
  1018. // Zip
  1019. if (!empty($arrayfields['s.zip']['checked'])) {
  1020. print '<td class="liste_titre"><input class="flat" type="text" size="4" name="search_zip" value="'.dol_escape_htmltag($search_zip).'"></td>';
  1021. }
  1022. // State
  1023. if (!empty($arrayfields['state.nom']['checked'])) {
  1024. print '<td class="liste_titre">';
  1025. print '<input class="flat" size="4" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
  1026. print '</td>';
  1027. }
  1028. // Country
  1029. if (!empty($arrayfields['country.code_iso']['checked'])) {
  1030. print '<td class="liste_titre" align="center">';
  1031. print $form->select_country($search_country, 'search_country', '', 0, 'minwidth100imp maxwidth100');
  1032. print '</td>';
  1033. }
  1034. // Company type
  1035. if (!empty($arrayfields['typent.code']['checked'])) {
  1036. print '<td class="liste_titre maxwidthonsmartphone" align="center">';
  1037. 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);
  1038. print '</td>';
  1039. }
  1040. // Date order
  1041. if (!empty($arrayfields['c.date_commande']['checked'])) {
  1042. print '<td class="liste_titre center">';
  1043. print '<div class="nowrap">';
  1044. print $form->selectDate($search_dateorder_start ? $search_dateorder_start : -1, 'search_dateorder_start_', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  1045. print '</div>';
  1046. print '<div class="nowrap">';
  1047. print $form->selectDate($search_dateorder_end ? $search_dateorder_end : -1, 'search_dateorder_end_', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  1048. print '</div>';
  1049. print '</td>';
  1050. }
  1051. if (!empty($arrayfields['c.date_delivery']['checked'])) {
  1052. print '<td class="liste_titre center">';
  1053. print '<div class="nowrap">';
  1054. print $form->selectDate($search_datedelivery_start ? $search_datedelivery_start : -1, 'search_datedelivery_start_', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  1055. print '</div>';
  1056. print '<div class="nowrap">';
  1057. print $form->selectDate($search_datedelivery_end ? $search_datedelivery_end : -1, 'search_datedelivery_end_', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  1058. print '</div>';
  1059. print '</td>';
  1060. }
  1061. // Shipping Method
  1062. if (!empty($arrayfields['c.fk_shipping_method']['checked'])) {
  1063. print '<td class="liste_titre">';
  1064. $form->selectShippingMethod($search_fk_shipping_method, 'search_fk_shipping_method', '', 1, '', 1);
  1065. print '</td>';
  1066. }
  1067. // Payment term
  1068. if (!empty($arrayfields['c.fk_cond_reglement']['checked'])) {
  1069. print '<td class="liste_titre">';
  1070. $form->select_conditions_paiements($search_fk_cond_reglement, 'search_fk_cond_reglement', -1, 1, 1);
  1071. print '</td>';
  1072. }
  1073. // Payment mode
  1074. if (!empty($arrayfields['c.fk_mode_reglement']['checked'])) {
  1075. print '<td class="liste_titre">';
  1076. $form->select_types_paiements($search_fk_mode_reglement, 'search_fk_mode_reglement', '', 0, 1, 1, 0, -1);
  1077. print '</td>';
  1078. }
  1079. // Channel
  1080. if (!empty($arrayfields['c.fk_input_reason']['checked'])) {
  1081. print '<td class="liste_titre">';
  1082. $form->selectInputReason($search_fk_input_reason, 'search_fk_input_reason', '', 1, '', 1);
  1083. print '</td>';
  1084. }
  1085. if (!empty($arrayfields['c.total_ht']['checked'])) {
  1086. // Amount
  1087. print '<td class="liste_titre right">';
  1088. print '<input class="flat" type="text" size="4" name="search_total_ht" value="'.dol_escape_htmltag($search_total_ht).'">';
  1089. print '</td>';
  1090. }
  1091. if (!empty($arrayfields['c.total_vat']['checked'])) {
  1092. // Amount
  1093. print '<td class="liste_titre right">';
  1094. print '<input class="flat" type="text" size="4" name="search_total_vat" value="'.dol_escape_htmltag($search_total_vat).'">';
  1095. print '</td>';
  1096. }
  1097. if (!empty($arrayfields['c.total_ttc']['checked'])) {
  1098. // Amount
  1099. print '<td class="liste_titre right">';
  1100. print '<input class="flat" type="text" size="5" name="search_total_ttc" value="'.$search_total_ttc.'">';
  1101. print '</td>';
  1102. }
  1103. if (!empty($arrayfields['c.multicurrency_code']['checked'])) {
  1104. // Currency
  1105. print '<td class="liste_titre">';
  1106. print $form->selectMultiCurrency($search_multicurrency_code, 'search_multicurrency_code', 1);
  1107. print '</td>';
  1108. }
  1109. if (!empty($arrayfields['c.multicurrency_tx']['checked'])) {
  1110. // Currency rate
  1111. print '<td class="liste_titre">';
  1112. print '<input class="flat" type="text" size="4" name="search_multicurrency_tx" value="'.dol_escape_htmltag($search_multicurrency_tx).'">';
  1113. print '</td>';
  1114. }
  1115. if (!empty($arrayfields['c.multicurrency_total_ht']['checked'])) {
  1116. // Amount
  1117. print '<td class="liste_titre right">';
  1118. print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_ht" value="'.dol_escape_htmltag($search_multicurrency_montant_ht).'">';
  1119. print '</td>';
  1120. }
  1121. if (!empty($arrayfields['c.multicurrency_total_vat']['checked'])) {
  1122. // Amount VAT
  1123. print '<td class="liste_titre right">';
  1124. print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_vat" value="'.dol_escape_htmltag($search_multicurrency_montant_vat).'">';
  1125. print '</td>';
  1126. }
  1127. if (!empty($arrayfields['c.multicurrency_total_ttc']['checked'])) {
  1128. // Amount
  1129. print '<td class="liste_titre right">';
  1130. print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_ttc" value="'.dol_escape_htmltag($search_multicurrency_montant_ttc).'">';
  1131. print '</td>';
  1132. }
  1133. if (!empty($arrayfields['u.login']['checked'])) {
  1134. // Author
  1135. print '<td class="liste_titre" align="center">';
  1136. print '<input class="flat" size="4" type="text" name="search_login" value="'.dol_escape_htmltag($search_login).'">';
  1137. print '</td>';
  1138. }
  1139. if (!empty($arrayfields['sale_representative']['checked'])) {
  1140. print '<td class="liste_titre"></td>';
  1141. }
  1142. if (!empty($arrayfields['total_pa']['checked'])) {
  1143. print '<td class="liste_titre right">';
  1144. print '</td>';
  1145. }
  1146. if (!empty($arrayfields['total_margin']['checked'])) {
  1147. print '<td class="liste_titre right">';
  1148. print '</td>';
  1149. }
  1150. if (!empty($arrayfields['total_margin_rate']['checked'])) {
  1151. print '<td class="liste_titre right">';
  1152. print '</td>';
  1153. }
  1154. if (!empty($arrayfields['total_mark_rate']['checked'])) {
  1155. print '<td class="liste_titre right">';
  1156. print '</td>';
  1157. }
  1158. // Extra fields
  1159. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  1160. // Fields from hook
  1161. $parameters = array('arrayfields'=>$arrayfields);
  1162. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
  1163. print $hookmanager->resPrint;
  1164. // Date creation
  1165. if (!empty($arrayfields['c.datec']['checked'])) {
  1166. print '<td class="liste_titre">';
  1167. print '</td>';
  1168. }
  1169. // Date modification
  1170. if (!empty($arrayfields['c.tms']['checked'])) {
  1171. print '<td class="liste_titre">';
  1172. print '</td>';
  1173. }
  1174. // Date cloture
  1175. if (!empty($arrayfields['c.date_cloture']['checked'])) {
  1176. print '<td class="liste_titre center">';
  1177. print '<div class="nowrap">';
  1178. print $form->selectDate($search_datecloture_start ? $search_datecloture_start : -1, 'search_datecloture_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  1179. print '</div>';
  1180. print '<div class="nowrap">';
  1181. print $form->selectDate($search_datecloture_end ? $search_datecloture_end : -1, 'search_datecloture_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  1182. print '</div>';
  1183. print '</td>';
  1184. }
  1185. // Note public
  1186. if (!empty($arrayfields['c.note_public']['checked'])) {
  1187. print '<td class="liste_titre">';
  1188. print '</td>';
  1189. }
  1190. // Note private
  1191. if (!empty($arrayfields['c.note_private']['checked'])) {
  1192. print '<td class="liste_titre">';
  1193. print '</td>';
  1194. }
  1195. // Shippable
  1196. if (!empty($arrayfields['shippable']['checked'])) {
  1197. print '<td class="liste_titre maxwidthonsmartphone" align="center">';
  1198. //print $form->selectyesno('search_shippable', $search_shippable, 1, 0, 1, 1);
  1199. if (!empty($conf->global->ORDER_SHIPABLE_STATUS_DISABLED_BY_DEFAULT)) {
  1200. print '<input type="checkbox" name="show_shippable_command" value="1"'.($show_shippable_command ? ' checked' : '').'>';
  1201. print $langs->trans('ShowShippableStatus');
  1202. } else {
  1203. $show_shippable_command = 1;
  1204. }
  1205. print '</td>';
  1206. }
  1207. // Status billed
  1208. if (!empty($arrayfields['c.facture']['checked'])) {
  1209. print '<td class="liste_titre maxwidthonsmartphone" align="center">';
  1210. print $form->selectyesno('search_billed', $search_billed, 1, 0, 1, 1);
  1211. print '</td>';
  1212. }
  1213. // Status
  1214. if (!empty($arrayfields['c.fk_statut']['checked'])) {
  1215. print '<td class="liste_titre maxwidthonsmartphone center">';
  1216. $liststatus = array(
  1217. Commande::STATUS_DRAFT=>$langs->trans("StatusOrderDraftShort"),
  1218. Commande::STATUS_VALIDATED=>$langs->trans("StatusOrderValidated"),
  1219. Commande::STATUS_SHIPMENTONPROCESS=>$langs->trans("StatusOrderSentShort"),
  1220. Commande::STATUS_CLOSED=>$langs->trans("StatusOrderDelivered"),
  1221. -3=>$langs->trans("StatusOrderValidatedShort").'+'.$langs->trans("StatusOrderSentShort").'+'.$langs->trans("StatusOrderDelivered"),
  1222. -2=>$langs->trans("StatusOrderValidatedShort").'+'.$langs->trans("StatusOrderSentShort"),
  1223. Commande::STATUS_CANCELED=>$langs->trans("StatusOrderCanceledShort")
  1224. );
  1225. print $form->selectarray('search_status', $liststatus, $search_status, -5, 0, 0, '', 0, 0, 0, '', 'maxwidth125', 1);
  1226. print '</td>';
  1227. }
  1228. // Action column
  1229. print '<td class="liste_titre" align="middle">';
  1230. $searchpicto = $form->showFilterButtons();
  1231. print $searchpicto;
  1232. print '</td>';
  1233. print "</tr>\n";
  1234. // Fields title
  1235. print '<tr class="liste_titre">';
  1236. if (!empty($arrayfields['c.ref']['checked'])) {
  1237. print_liste_field_titre($arrayfields['c.ref']['label'], $_SERVER["PHP_SELF"], 'c.ref', '', $param, '', $sortfield, $sortorder);
  1238. }
  1239. if (!empty($arrayfields['c.ref_client']['checked'])) {
  1240. print_liste_field_titre($arrayfields['c.ref_client']['label'], $_SERVER["PHP_SELF"], 'c.ref_client', '', $param, '', $sortfield, $sortorder);
  1241. }
  1242. if (!empty($arrayfields['p.ref']['checked'])) {
  1243. print_liste_field_titre($arrayfields['p.ref']['label'], $_SERVER["PHP_SELF"], "p.ref", "", $param, '', $sortfield, $sortorder);
  1244. }
  1245. if (!empty($arrayfields['p.title']['checked'])) {
  1246. print_liste_field_titre($arrayfields['p.title']['label'], $_SERVER["PHP_SELF"], "p.title", "", $param, '', $sortfield, $sortorder);
  1247. }
  1248. if (!empty($arrayfields['s.nom']['checked'])) {
  1249. print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], 's.nom', '', $param, '', $sortfield, $sortorder);
  1250. }
  1251. if (!empty($arrayfields['s.name_alias']['checked'])) {
  1252. print_liste_field_titre($arrayfields['s.name_alias']['label'], $_SERVER["PHP_SELF"], 's.name_alias', '', $param, '', $sortfield, $sortorder);
  1253. }
  1254. if (!empty($arrayfields['s.town']['checked'])) {
  1255. print_liste_field_titre($arrayfields['s.town']['label'], $_SERVER["PHP_SELF"], 's.town', '', $param, '', $sortfield, $sortorder);
  1256. }
  1257. if (!empty($arrayfields['s.zip']['checked'])) {
  1258. print_liste_field_titre($arrayfields['s.zip']['label'], $_SERVER["PHP_SELF"], 's.zip', '', $param, '', $sortfield, $sortorder);
  1259. }
  1260. if (!empty($arrayfields['state.nom']['checked'])) {
  1261. print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder);
  1262. }
  1263. if (!empty($arrayfields['country.code_iso']['checked'])) {
  1264. print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, '', $sortfield, $sortorder, 'center ');
  1265. }
  1266. if (!empty($arrayfields['typent.code']['checked'])) {
  1267. print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, '', $sortfield, $sortorder, 'center ');
  1268. }
  1269. if (!empty($arrayfields['c.date_commande']['checked'])) {
  1270. print_liste_field_titre($arrayfields['c.date_commande']['label'], $_SERVER["PHP_SELF"], 'c.date_commande', '', $param, '', $sortfield, $sortorder, 'center ');
  1271. }
  1272. if (!empty($arrayfields['c.date_delivery']['checked'])) {
  1273. print_liste_field_titre($arrayfields['c.date_delivery']['label'], $_SERVER["PHP_SELF"], 'c.date_livraison', '', $param, '', $sortfield, $sortorder, 'center ');
  1274. }
  1275. if (!empty($arrayfields['c.fk_shipping_method']['checked'])) {
  1276. print_liste_field_titre($arrayfields['c.fk_shipping_method']['label'], $_SERVER["PHP_SELF"], "c.fk_shipping_method", "", $param, '', $sortfield, $sortorder);
  1277. }
  1278. if (!empty($arrayfields['c.fk_cond_reglement']['checked'])) {
  1279. print_liste_field_titre($arrayfields['c.fk_cond_reglement']['label'], $_SERVER["PHP_SELF"], "c.fk_cond_reglement", "", $param, '', $sortfield, $sortorder);
  1280. }
  1281. if (!empty($arrayfields['c.fk_mode_reglement']['checked'])) {
  1282. print_liste_field_titre($arrayfields['c.fk_mode_reglement']['label'], $_SERVER["PHP_SELF"], "c.fk_mode_reglement", "", $param, '', $sortfield, $sortorder);
  1283. }
  1284. if (!empty($arrayfields['c.fk_input_reason']['checked'])) {
  1285. print_liste_field_titre($arrayfields['c.fk_input_reason']['label'], $_SERVER["PHP_SELF"], "c.fk_input_reason", "", $param, '', $sortfield, $sortorder);
  1286. }
  1287. if (!empty($arrayfields['c.total_ht']['checked'])) {
  1288. print_liste_field_titre($arrayfields['c.total_ht']['label'], $_SERVER["PHP_SELF"], 'c.total_ht', '', $param, '', $sortfield, $sortorder, 'right ');
  1289. }
  1290. if (!empty($arrayfields['c.total_vat']['checked'])) {
  1291. print_liste_field_titre($arrayfields['c.total_vat']['label'], $_SERVER["PHP_SELF"], 'c.total_tva', '', $param, '', $sortfield, $sortorder, 'right ');
  1292. }
  1293. if (!empty($arrayfields['c.total_ttc']['checked'])) {
  1294. print_liste_field_titre($arrayfields['c.total_ttc']['label'], $_SERVER["PHP_SELF"], 'c.total_ttc', '', $param, '', $sortfield, $sortorder, 'right ');
  1295. }
  1296. if (!empty($arrayfields['c.multicurrency_code']['checked'])) {
  1297. print_liste_field_titre($arrayfields['c.multicurrency_code']['label'], $_SERVER['PHP_SELF'], 'c.multicurrency_code', '', $param, '', $sortfield, $sortorder);
  1298. }
  1299. if (!empty($arrayfields['c.multicurrency_tx']['checked'])) {
  1300. print_liste_field_titre($arrayfields['c.multicurrency_tx']['label'], $_SERVER['PHP_SELF'], 'c.multicurrency_tx', '', $param, '', $sortfield, $sortorder);
  1301. }
  1302. if (!empty($arrayfields['c.multicurrency_total_ht']['checked'])) {
  1303. print_liste_field_titre($arrayfields['c.multicurrency_total_ht']['label'], $_SERVER['PHP_SELF'], 'c.multicurrency_total_ht', '', $param, 'class="right"', $sortfield, $sortorder);
  1304. }
  1305. if (!empty($arrayfields['c.multicurrency_total_vat']['checked'])) {
  1306. print_liste_field_titre($arrayfields['c.multicurrency_total_vat']['label'], $_SERVER['PHP_SELF'], 'c.multicurrency_total_tva', '', $param, 'class="right"', $sortfield, $sortorder);
  1307. }
  1308. if (!empty($arrayfields['c.multicurrency_total_ttc']['checked'])) {
  1309. print_liste_field_titre($arrayfields['c.multicurrency_total_ttc']['label'], $_SERVER['PHP_SELF'], 'c.multicurrency_total_ttc', '', $param, 'class="right"', $sortfield, $sortorder);
  1310. }
  1311. if (!empty($arrayfields['u.login']['checked'])) {
  1312. print_liste_field_titre($arrayfields['u.login']['label'], $_SERVER["PHP_SELF"], 'u.login', '', $param, 'align="center"', $sortfield, $sortorder);
  1313. }
  1314. if (!empty($arrayfields['sale_representative']['checked'])) {
  1315. print_liste_field_titre($arrayfields['sale_representative']['label'], $_SERVER["PHP_SELF"], "", "", "$param", '', $sortfield, $sortorder);
  1316. }
  1317. if (!empty($arrayfields['total_pa']['checked'])) {
  1318. print_liste_field_titre($arrayfields['total_pa']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
  1319. }
  1320. if (!empty($arrayfields['total_margin']['checked'])) {
  1321. print_liste_field_titre($arrayfields['total_margin']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
  1322. }
  1323. if (!empty($arrayfields['total_margin_rate']['checked'])) {
  1324. print_liste_field_titre($arrayfields['total_margin_rate']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
  1325. }
  1326. if (!empty($arrayfields['total_mark_rate']['checked'])) {
  1327. print_liste_field_titre($arrayfields['total_mark_rate']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
  1328. }
  1329. $totalarray = array(
  1330. 'nbfield' => 0,
  1331. 'val' => array(
  1332. 'c.total_ht' => 0,
  1333. 'c.total_tva' => 0,
  1334. 'c.total_ttc' => 0,
  1335. ),
  1336. 'pos' => array(),
  1337. );
  1338. // Extra fields
  1339. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  1340. // Hook fields
  1341. $parameters = array(
  1342. 'arrayfields' => $arrayfields,
  1343. 'param' => $param,
  1344. 'sortfield' => $sortfield,
  1345. 'sortorder' => $sortorder,
  1346. 'totalarray' => &$totalarray,
  1347. );
  1348. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
  1349. print $hookmanager->resPrint;
  1350. if (!empty($arrayfields['c.datec']['checked'])) {
  1351. print_liste_field_titre($arrayfields['c.datec']['label'], $_SERVER["PHP_SELF"], "c.date_creation", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  1352. }
  1353. if (!empty($arrayfields['c.tms']['checked'])) {
  1354. print_liste_field_titre($arrayfields['c.tms']['label'], $_SERVER["PHP_SELF"], "c.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  1355. }
  1356. if (!empty($arrayfields['c.date_cloture']['checked'])) {
  1357. print_liste_field_titre($arrayfields['c.date_cloture']['label'], $_SERVER["PHP_SELF"], "c.date_cloture", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  1358. }
  1359. if (!empty($arrayfields['c.note_public']['checked'])) {
  1360. print_liste_field_titre($arrayfields['c.note_public']['label'], $_SERVER["PHP_SELF"], "c.note_public", "", $param, '', $sortfield, $sortorder, 'right ');
  1361. }
  1362. if (!empty($arrayfields['c.note_private']['checked'])) {
  1363. print_liste_field_titre($arrayfields['c.note_private']['label'], $_SERVER["PHP_SELF"], "c.note_private", "", $param, '', $sortfield, $sortorder, 'right ');
  1364. }
  1365. if (!empty($arrayfields['shippable']['checked'])) {
  1366. print_liste_field_titre($arrayfields['shippable']['label'], $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'center ');
  1367. }
  1368. if (!empty($arrayfields['c.facture']['checked'])) {
  1369. print_liste_field_titre($arrayfields['c.facture']['label'], $_SERVER["PHP_SELF"], 'c.facture', '', $param, '', $sortfield, $sortorder, 'center ');
  1370. }
  1371. if (!empty($arrayfields['c.fk_statut']['checked'])) {
  1372. print_liste_field_titre($arrayfields['c.fk_statut']['label'], $_SERVER["PHP_SELF"], "c.fk_statut", "", $param, '', $sortfield, $sortorder, 'center ');
  1373. }
  1374. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, 'maxwidthsearch center ');
  1375. print '</tr>'."\n";
  1376. $total = 0;
  1377. $subtotal = 0;
  1378. $productstat_cache = array();
  1379. $productstat_cachevirtual = array();
  1380. $getNomUrl_cache = array();
  1381. $generic_commande = new Commande($db);
  1382. $generic_product = new Product($db);
  1383. $userstatic = new User($db);
  1384. $i = 0;
  1385. $with_margin_info = false;
  1386. if (!empty($conf->margin->enabled) && (
  1387. !empty($arrayfields['total_pa']['checked'])
  1388. || !empty($arrayfields['total_margin']['checked'])
  1389. || !empty($arrayfields['total_margin_rate']['checked'])
  1390. || !empty($arrayfields['total_mark_rate']['checked'])
  1391. )
  1392. ) {
  1393. $with_margin_info = true;
  1394. }
  1395. $total_ht = 0;
  1396. $total_margin = 0;
  1397. $last_num = min($num, $limit);
  1398. while ($i < $last_num) {
  1399. $obj = $db->fetch_object($resql);
  1400. $notshippable = 0;
  1401. $warning = 0;
  1402. $text_info = '';
  1403. $text_warning = '';
  1404. $nbprod = 0;
  1405. $companystatic->id = $obj->socid;
  1406. $companystatic->name = $obj->name;
  1407. $companystatic->name_alias = $obj->alias;
  1408. $companystatic->client = $obj->client;
  1409. $companystatic->code_client = $obj->code_client;
  1410. $companystatic->email = $obj->email;
  1411. $companystatic->phone = $obj->phone;
  1412. $companystatic->address = $obj->address;
  1413. $companystatic->zip = $obj->zip;
  1414. $companystatic->town = $obj->town;
  1415. $companystatic->country_code = $obj->country_code;
  1416. if (!isset($getNomUrl_cache[$obj->socid])) {
  1417. $getNomUrl_cache[$obj->socid] = $companystatic->getNomUrl(1, 'customer');
  1418. }
  1419. $generic_commande->id = $obj->rowid;
  1420. $generic_commande->ref = $obj->ref;
  1421. $generic_commande->statut = $obj->fk_statut;
  1422. $generic_commande->billed = $obj->billed;
  1423. $generic_commande->date = $db->jdate($obj->date_commande);
  1424. $generic_commande->date_livraison = $db->jdate($obj->date_delivery); // deprecated
  1425. $generic_commande->delivery_date = $db->jdate($obj->date_delivery);
  1426. $generic_commande->ref_client = $obj->ref_client;
  1427. $generic_commande->total_ht = $obj->total_ht;
  1428. $generic_commande->total_tva = $obj->total_tva;
  1429. $generic_commande->total_ttc = $obj->total_ttc;
  1430. $generic_commande->note_public = $obj->note_public;
  1431. $generic_commande->note_private = $obj->note_private;
  1432. $projectstatic->id = $obj->project_id;
  1433. $projectstatic->ref = $obj->project_ref;
  1434. $projectstatic->title = $obj->project_label;
  1435. $marginInfo = array();
  1436. if ($with_margin_info === true) {
  1437. $generic_commande->fetch_lines();
  1438. $marginInfo = $formmargin->getMarginInfosArray($generic_commande);
  1439. $total_ht += $obj->total_ht;
  1440. $total_margin += $marginInfo['total_margin'];
  1441. }
  1442. print '<tr class="oddeven">';
  1443. // Ref
  1444. if (!empty($arrayfields['c.ref']['checked'])) {
  1445. print '<td class="nowraponall">';
  1446. print $generic_commande->getNomUrl(1, ($search_status != 2 ? 0 : $obj->fk_statut), 0, 0, 0, 1, 1);
  1447. $filename = dol_sanitizeFileName($obj->ref);
  1448. $filedir = $conf->commande->multidir_output[$conf->entity].'/'.dol_sanitizeFileName($obj->ref);
  1449. $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
  1450. print $formfile->getDocumentsLink($generic_commande->element, $filename, $filedir);
  1451. print '</td>';
  1452. if (!$i) {
  1453. $totalarray['nbfield']++;
  1454. }
  1455. }
  1456. // Ref customer
  1457. if (!empty($arrayfields['c.ref_client']['checked'])) {
  1458. print '<td class="nowrap tdoverflowmax200">'.$obj->ref_client.'</td>';
  1459. if (!$i) {
  1460. $totalarray['nbfield']++;
  1461. }
  1462. }
  1463. // Project ref
  1464. if (!empty($arrayfields['p.ref']['checked'])) {
  1465. print '<td class="nowrap">';
  1466. if ($obj->project_id > 0) {
  1467. print $projectstatic->getNomUrl(1);
  1468. }
  1469. print '</td>';
  1470. if (!$i) {
  1471. $totalarray['nbfield']++;
  1472. }
  1473. }
  1474. // Project label
  1475. if (!empty($arrayfields['p.title']['checked'])) {
  1476. print '<td class="nowrap">';
  1477. if ($obj->project_id > 0) {
  1478. print $projectstatic->title;
  1479. }
  1480. print '</td>';
  1481. if (!$i) {
  1482. $totalarray['nbfield']++;
  1483. }
  1484. }
  1485. // Third party
  1486. if (!empty($arrayfields['s.nom']['checked'])) {
  1487. print '<td class="tdoverflowmax200">';
  1488. print $getNomUrl_cache[$obj->socid];
  1489. // If module invoices enabled and user with invoice creation permissions
  1490. if (!empty($conf->facture->enabled) && !empty($conf->global->ORDER_BILLING_ALL_CUSTOMER)) {
  1491. if ($user->rights->facture->creer) {
  1492. if (($obj->fk_statut > 0 && $obj->fk_statut < 3) || ($obj->fk_statut == 3 && $obj->billed == 0)) {
  1493. print '&nbsp;<a href="'.DOL_URL_ROOT.'/commande/list.php?socid='.$companystatic->id.'&search_billed=0&autoselectall=1">';
  1494. print img_picto($langs->trans("CreateInvoiceForThisCustomer").' : '.$companystatic->name, 'object_bill', 'hideonsmartphone').'</a>';
  1495. }
  1496. }
  1497. }
  1498. print '</td>';
  1499. if (!$i) {
  1500. $totalarray['nbfield']++;
  1501. }
  1502. }
  1503. // Alias name
  1504. if (!empty($arrayfields['s.name_alias']['checked'])) {
  1505. print '<td class="nocellnopadd">';
  1506. print $obj->alias;
  1507. print '</td>';
  1508. if (!$i) {
  1509. $totalarray['nbfield']++;
  1510. }
  1511. }
  1512. // Town
  1513. if (!empty($arrayfields['s.town']['checked'])) {
  1514. print '<td class="nocellnopadd">';
  1515. print $obj->town;
  1516. print '</td>';
  1517. if (!$i) {
  1518. $totalarray['nbfield']++;
  1519. }
  1520. }
  1521. // Zip
  1522. if (!empty($arrayfields['s.zip']['checked'])) {
  1523. print '<td class="nocellnopadd">';
  1524. print $obj->zip;
  1525. print '</td>';
  1526. if (!$i) {
  1527. $totalarray['nbfield']++;
  1528. }
  1529. }
  1530. // State
  1531. if (!empty($arrayfields['state.nom']['checked'])) {
  1532. print "<td>".$obj->state_name."</td>\n";
  1533. if (!$i) {
  1534. $totalarray['nbfield']++;
  1535. }
  1536. }
  1537. // Country
  1538. if (!empty($arrayfields['country.code_iso']['checked'])) {
  1539. print '<td class="center">';
  1540. $tmparray = getCountry($obj->fk_pays, 'all');
  1541. print $tmparray['label'];
  1542. print '</td>';
  1543. if (!$i) {
  1544. $totalarray['nbfield']++;
  1545. }
  1546. }
  1547. // Type ent
  1548. if (!empty($arrayfields['typent.code']['checked'])) {
  1549. print '<td class="center">';
  1550. if (empty($typenArray)) {
  1551. $typenArray = $formcompany->typent_array(1);
  1552. }
  1553. print $typenArray[$obj->typent_code];
  1554. print '</td>';
  1555. if (!$i) {
  1556. $totalarray['nbfield']++;
  1557. }
  1558. }
  1559. // Order date
  1560. if (!empty($arrayfields['c.date_commande']['checked'])) {
  1561. print '<td class="center">';
  1562. print dol_print_date($db->jdate($obj->date_commande), 'day');
  1563. // Warning late icon and note
  1564. if ($generic_commande->hasDelay()) {
  1565. print img_picto($langs->trans("Late").' : '.$generic_commande->showDelay(), "warning");
  1566. }
  1567. print '</td>';
  1568. if (!$i) {
  1569. $totalarray['nbfield']++;
  1570. }
  1571. }
  1572. // Plannned date of delivery
  1573. if (!empty($arrayfields['c.date_delivery']['checked'])) {
  1574. print '<td class="center">';
  1575. print dol_print_date($db->jdate($obj->date_delivery), 'dayhour');
  1576. print '</td>';
  1577. if (!$i) {
  1578. $totalarray['nbfield']++;
  1579. }
  1580. }
  1581. // Shipping Method
  1582. if (!empty($arrayfields['c.fk_shipping_method']['checked'])) {
  1583. print '<td>';
  1584. $form->formSelectShippingMethod('', $obj->fk_shipping_method, 'none', 1);
  1585. print '</td>';
  1586. if (!$i) {
  1587. $totalarray['nbfield']++;
  1588. }
  1589. }
  1590. // Payment terms
  1591. if (!empty($arrayfields['c.fk_cond_reglement']['checked'])) {
  1592. print '<td>';
  1593. $form->form_conditions_reglement($_SERVER['PHP_SELF'], $obj->fk_cond_reglement, 'none');
  1594. print '</td>';
  1595. if (!$i) {
  1596. $totalarray['nbfield']++;
  1597. }
  1598. }
  1599. // Payment mode
  1600. if (!empty($arrayfields['c.fk_mode_reglement']['checked'])) {
  1601. print '<td>';
  1602. $form->form_modes_reglement($_SERVER['PHP_SELF'], $obj->fk_mode_reglement, 'none', '', -1);
  1603. print '</td>';
  1604. if (!$i) {
  1605. $totalarray['nbfield']++;
  1606. }
  1607. }
  1608. // Channel
  1609. if (!empty($arrayfields['c.fk_input_reason']['checked'])) {
  1610. print '<td>';
  1611. $form->formInputReason($_SERVER['PHP_SELF'], $obj->fk_input_reason, 'none', '');
  1612. print '</td>';
  1613. if (!$i) {
  1614. $totalarray['nbfield']++;
  1615. }
  1616. }
  1617. // Amount HT
  1618. if (!empty($arrayfields['c.total_ht']['checked'])) {
  1619. print '<td class="nowrap right"><span class="amount">'.price($obj->total_ht)."</span></td>\n";
  1620. if (!$i) {
  1621. $totalarray['nbfield']++;
  1622. }
  1623. if (!$i) {
  1624. $totalarray['pos'][$totalarray['nbfield']] = 'c.total_ht';
  1625. }
  1626. if (isset($totalarray['val']['c.total_ht'])) {
  1627. $totalarray['val']['c.total_ht'] += $obj->total_ht;
  1628. } else {
  1629. $totalarray['val']['c.total_ht'] = $obj->total_ht;
  1630. }
  1631. }
  1632. // Amount VAT
  1633. if (!empty($arrayfields['c.total_vat']['checked'])) {
  1634. print '<td class="nowrap right"><span class="amount">'.price($obj->total_tva)."</span></td>\n";
  1635. if (!$i) {
  1636. $totalarray['nbfield']++;
  1637. }
  1638. if (!$i) {
  1639. $totalarray['pos'][$totalarray['nbfield']] = 'c.total_tva';
  1640. }
  1641. $totalarray['val']['c.total_tva'] += $obj->total_tva;
  1642. }
  1643. // Amount TTC
  1644. if (!empty($arrayfields['c.total_ttc']['checked'])) {
  1645. print '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc)."</span></td>\n";
  1646. if (!$i) {
  1647. $totalarray['nbfield']++;
  1648. }
  1649. if (!$i) {
  1650. $totalarray['pos'][$totalarray['nbfield']] = 'c.total_ttc';
  1651. }
  1652. $totalarray['val']['c.total_ttc'] += $obj->total_ttc;
  1653. }
  1654. // Currency
  1655. if (!empty($arrayfields['c.multicurrency_code']['checked'])) {
  1656. print '<td class="nowrap">'.$obj->multicurrency_code.' - '.$langs->trans('Currency'.$obj->multicurrency_code)."</td>\n";
  1657. if (!$i) {
  1658. $totalarray['nbfield']++;
  1659. }
  1660. }
  1661. // Currency rate
  1662. if (!empty($arrayfields['c.multicurrency_tx']['checked'])) {
  1663. print '<td class="nowrap">';
  1664. $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$obj->rowid, $obj->multicurrency_tx, 'none', $obj->multicurrency_code);
  1665. print "</td>\n";
  1666. if (!$i) {
  1667. $totalarray['nbfield']++;
  1668. }
  1669. }
  1670. // Amount HT
  1671. if (!empty($arrayfields['c.multicurrency_total_ht']['checked'])) {
  1672. print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_ht)."</span></td>\n";
  1673. if (!$i) {
  1674. $totalarray['nbfield']++;
  1675. }
  1676. }
  1677. // Amount VAT
  1678. if (!empty($arrayfields['c.multicurrency_total_vat']['checked'])) {
  1679. print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_vat)."</span></td>\n";
  1680. if (!$i) {
  1681. $totalarray['nbfield']++;
  1682. }
  1683. }
  1684. // Amount TTC
  1685. if (!empty($arrayfields['c.multicurrency_total_ttc']['checked'])) {
  1686. print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_ttc)."</span></td>\n";
  1687. if (!$i) {
  1688. $totalarray['nbfield']++;
  1689. }
  1690. }
  1691. $userstatic->id = $obj->fk_user_author;
  1692. $userstatic->login = $obj->login;
  1693. $userstatic->lastname = $obj->lastname;
  1694. $userstatic->firstname = $obj->firstname;
  1695. $userstatic->email = $obj->user_email;
  1696. $userstatic->statut = $obj->user_statut;
  1697. $userstatic->entity = $obj->entity;
  1698. $userstatic->photo = $obj->photo;
  1699. $userstatic->office_phone = $obj->office_phone;
  1700. $userstatic->office_fax = $obj->office_fax;
  1701. $userstatic->user_mobile = $obj->user_mobile;
  1702. $userstatic->job = $obj->job;
  1703. $userstatic->gender = $obj->gender;
  1704. // Author
  1705. if (!empty($arrayfields['u.login']['checked'])) {
  1706. print '<td class="tdoverflowmax200">';
  1707. if ($userstatic->id) {
  1708. print $userstatic->getNomUrl(-1);
  1709. } else {
  1710. print '&nbsp;';
  1711. }
  1712. print "</td>\n";
  1713. if (!$i) {
  1714. $totalarray['nbfield']++;
  1715. }
  1716. }
  1717. if (!empty($arrayfields['sale_representative']['checked'])) {
  1718. // Sales representatives
  1719. print '<td>';
  1720. if ($obj->socid > 0) {
  1721. $listsalesrepresentatives = $companystatic->getSalesRepresentatives($user);
  1722. if ($listsalesrepresentatives < 0) {
  1723. dol_print_error($db);
  1724. }
  1725. $nbofsalesrepresentative = count($listsalesrepresentatives);
  1726. if ($nbofsalesrepresentative > 6) {
  1727. // We print only number
  1728. print $nbofsalesrepresentative;
  1729. } elseif ($nbofsalesrepresentative > 0) {
  1730. $j = 0;
  1731. foreach ($listsalesrepresentatives as $val) {
  1732. $userstatic->id = $val['id'];
  1733. $userstatic->lastname = $val['lastname'];
  1734. $userstatic->firstname = $val['firstname'];
  1735. $userstatic->email = $val['email'];
  1736. $userstatic->statut = $val['statut'];
  1737. $userstatic->entity = $val['entity'];
  1738. $userstatic->photo = $val['photo'];
  1739. $userstatic->login = $val['login'];
  1740. $userstatic->office_phone = $val['office_phone'];
  1741. $userstatic->office_fax = $val['office_fax'];
  1742. $userstatic->user_mobile = $val['user_mobile'];
  1743. $userstatic->job = $val['job'];
  1744. $userstatic->gender = $val['gender'];
  1745. //print '<div class="float">':
  1746. print ($nbofsalesrepresentative < 2) ? $userstatic->getNomUrl(-1, '', 0, 0, 12) : $userstatic->getNomUrl(-2);
  1747. $j++;
  1748. if ($j < $nbofsalesrepresentative) {
  1749. print ' ';
  1750. }
  1751. //print '</div>';
  1752. }
  1753. }
  1754. //else print $langs->trans("NoSalesRepresentativeAffected");
  1755. } else {
  1756. print '&nbsp;';
  1757. }
  1758. print '</td>';
  1759. if (!$i) {
  1760. $totalarray['nbfield']++;
  1761. }
  1762. }
  1763. // Total buying or cost price
  1764. if (!empty($arrayfields['total_pa']['checked'])) {
  1765. print '<td class="right nowrap">'.price($marginInfo['pa_total']).'</td>';
  1766. if (!$i) {
  1767. $totalarray['nbfield']++;
  1768. }
  1769. }
  1770. // Total margin
  1771. if (!empty($arrayfields['total_margin']['checked'])) {
  1772. print '<td class="right nowrap">'.price($marginInfo['total_margin']).'</td>';
  1773. if (!$i) {
  1774. $totalarray['nbfield']++;
  1775. }
  1776. if (!$i) {
  1777. $totalarray['pos'][$totalarray['nbfield']] = 'total_margin';
  1778. }
  1779. $totalarray['val']['total_margin'] += $marginInfo['total_margin'];
  1780. }
  1781. // Total margin rate
  1782. if (!empty($arrayfields['total_margin_rate']['checked'])) {
  1783. print '<td class="right nowrap">'.(($marginInfo['total_margin_rate'] == '') ? '' : price($marginInfo['total_margin_rate'], null, null, null, null, 2).'%').'</td>';
  1784. if (!$i) {
  1785. $totalarray['nbfield']++;
  1786. }
  1787. }
  1788. // Total mark rate
  1789. if (!empty($arrayfields['total_mark_rate']['checked'])) {
  1790. print '<td class="right nowrap">'.(($marginInfo['total_mark_rate'] == '') ? '' : price($marginInfo['total_mark_rate'], null, null, null, null, 2).'%').'</td>';
  1791. if (!$i) {
  1792. $totalarray['nbfield']++;
  1793. }
  1794. if (!$i) {
  1795. $totalarray['pos'][$totalarray['nbfield']] = 'total_mark_rate';
  1796. }
  1797. if ($i >= $last_num - 1) {
  1798. if (!empty($total_ht)) {
  1799. $totalarray['val']['total_mark_rate'] = price2num($total_margin * 100 / $total_ht, 'MT');
  1800. } else {
  1801. $totalarray['val']['total_mark_rate'] = '';
  1802. }
  1803. }
  1804. }
  1805. // Extra fields
  1806. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  1807. // Fields from hook
  1808. $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  1809. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
  1810. print $hookmanager->resPrint;
  1811. // Date creation
  1812. if (!empty($arrayfields['c.datec']['checked'])) {
  1813. print '<td align="center" class="nowrap">';
  1814. print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
  1815. print '</td>';
  1816. if (!$i) {
  1817. $totalarray['nbfield']++;
  1818. }
  1819. }
  1820. // Date modification
  1821. if (!empty($arrayfields['c.tms']['checked'])) {
  1822. print '<td align="center" class="nowrap">';
  1823. print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser');
  1824. print '</td>';
  1825. if (!$i) {
  1826. $totalarray['nbfield']++;
  1827. }
  1828. }
  1829. // Date cloture
  1830. if (!empty($arrayfields['c.date_cloture']['checked'])) {
  1831. print '<td align="center" class="nowrap">';
  1832. print dol_print_date($db->jdate($obj->date_cloture), 'dayhour', 'tzuser');
  1833. print '</td>';
  1834. if (!$i) {
  1835. $totalarray['nbfield']++;
  1836. }
  1837. }
  1838. // Note public
  1839. if (!empty($arrayfields['c.note_public']['checked'])) {
  1840. print '<td align="center" class="nowrap">';
  1841. print dol_escape_htmltag($obj->note_public);
  1842. print '</td>';
  1843. if (!$i) {
  1844. $totalarray['nbfield']++;
  1845. }
  1846. }
  1847. // Note private
  1848. if (!empty($arrayfields['c.note_private']['checked'])) {
  1849. print '<td align="center" class="nowrap">';
  1850. print dol_escape_htmltag($obj->note_private);
  1851. print '</td>';
  1852. if (!$i) {
  1853. $totalarray['nbfield']++;
  1854. }
  1855. }
  1856. // Show shippable Icon (this creates subloops, so may be slow)
  1857. if (!empty($arrayfields['shippable']['checked'])) {
  1858. print '<td class="center">';
  1859. if (!empty($show_shippable_command) && !empty($conf->stock->enabled)) {
  1860. if (($obj->fk_statut > $generic_commande::STATUS_DRAFT) && ($obj->fk_statut < $generic_commande::STATUS_CLOSED)) {
  1861. $generic_commande->getLinesArray(); // Load array ->lines
  1862. $generic_commande->loadExpeditions(); // Load array ->expeditions
  1863. $numlines = count($generic_commande->lines); // Loop on each line of order
  1864. for ($lig = 0; $lig < $numlines; $lig++) {
  1865. $reliquat = $generic_commande->lines[$lig]->qty - $generic_commande->expeditions[$generic_commande->lines[$lig]->id];
  1866. if ($generic_commande->lines[$lig]->product_type == 0 && $generic_commande->lines[$lig]->fk_product > 0) { // If line is a product and not a service
  1867. $nbprod++; // order contains real products
  1868. $generic_product->id = $generic_commande->lines[$lig]->fk_product;
  1869. // Get local and virtual stock and store it into cache
  1870. if (empty($productstat_cache[$generic_commande->lines[$lig]->fk_product])) {
  1871. $generic_product->load_stock('nobatch'); // ->load_virtual_stock() is already included into load_stock()
  1872. $productstat_cache[$generic_commande->lines[$lig]->fk_product]['stock_reel'] = $generic_product->stock_reel;
  1873. $productstat_cachevirtual[$generic_commande->lines[$lig]->fk_product]['stock_reel'] = $generic_product->stock_theorique;
  1874. } else {
  1875. $generic_product->stock_reel = $productstat_cache[$generic_commande->lines[$lig]->fk_product]['stock_reel'];
  1876. $generic_product->stock_theorique = $productstat_cachevirtual[$generic_commande->lines[$lig]->fk_product]['stock_reel'] = $generic_product->stock_theorique;
  1877. }
  1878. if ($reliquat > $generic_product->stock_reel) {
  1879. $notshippable++;
  1880. }
  1881. if (empty($conf->global->SHIPPABLE_ORDER_ICON_IN_LIST)) { // Default code. Default should be this case.
  1882. $text_info .= $reliquat.' x '.$generic_commande->lines[$lig]->product_ref.'&nbsp;'.dol_trunc($generic_commande->lines[$lig]->product_label, 20);
  1883. $text_info .= ' - '.$langs->trans("Stock").': <span class="'.($generic_product->stock_reel > 0 ? 'ok' : 'error').'">'.$generic_product->stock_reel.'</span>';
  1884. $text_info .= ' - '.$langs->trans("VirtualStock").': <span class="'.($generic_product->stock_theorique > 0 ? 'ok' : 'error').'">'.$generic_product->stock_theorique.'</span>';
  1885. $text_info .= ($reliquat != $generic_commande->lines[$lig]->qty ? ' <span class="opacitymedium">('.$langs->trans("QtyInOtherShipments").' '.($generic_commande->lines[$lig]->qty - $reliquat).')</span>' : '');
  1886. $text_info .= '<br>';
  1887. } else { // BUGGED CODE.
  1888. // DOES NOT TAKE INTO ACCOUNT MANUFACTURING. THIS CODE SHOULD BE USELESS. PREVIOUS CODE SEEMS COMPLETE.
  1889. // COUNT STOCK WHEN WE SHOULD ALREADY HAVE VALUE
  1890. // Detailed virtual stock, looks bugged, uncomplete and need heavy load.
  1891. // stock order and stock order_supplier
  1892. $stock_order = 0;
  1893. $stock_order_supplier = 0;
  1894. if (!empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT) || !empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE)) { // What about other options ?
  1895. if (!empty($conf->commande->enabled)) {
  1896. if (empty($productstat_cache[$generic_commande->lines[$lig]->fk_product]['stats_order_customer'])) {
  1897. $generic_product->load_stats_commande(0, '1,2');
  1898. $productstat_cache[$generic_commande->lines[$lig]->fk_product]['stats_order_customer'] = $generic_product->stats_commande['qty'];
  1899. } else {
  1900. $generic_product->stats_commande['qty'] = $productstat_cache[$generic_commande->lines[$lig]->fk_product]['stats_order_customer'];
  1901. }
  1902. $stock_order = $generic_product->stats_commande['qty'];
  1903. }
  1904. if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_order->enabled)) {
  1905. if (empty($productstat_cache[$generic_commande->lines[$lig]->fk_product]['stats_order_supplier'])) {
  1906. $generic_product->load_stats_commande_fournisseur(0, '3');
  1907. $productstat_cache[$generic_commande->lines[$lig]->fk_product]['stats_order_supplier'] = $generic_product->stats_commande_fournisseur['qty'];
  1908. } else {
  1909. $generic_product->stats_commande_fournisseur['qty'] = $productstat_cache[$generic_commande->lines[$lig]->fk_product]['stats_order_supplier'];
  1910. }
  1911. $stock_order_supplier = $generic_product->stats_commande_fournisseur['qty'];
  1912. }
  1913. }
  1914. $text_info .= $reliquat.' x '.$generic_commande->lines[$lig]->ref.'&nbsp;'.dol_trunc($generic_commande->lines[$lig]->product_label, 20);
  1915. $text_stock_reel = $generic_product->stock_reel.'/'.$stock_order;
  1916. if ($stock_order > $generic_product->stock_reel && !($generic_product->stock_reel < $generic_commande->lines[$lig]->qty)) {
  1917. $warning++;
  1918. $text_warning .= '<span class="warning">'.$langs->trans('Available').'&nbsp;:&nbsp;'.$text_stock_reel.'</span>';
  1919. }
  1920. if ($reliquat > $generic_product->stock_reel) {
  1921. $text_info .= '<span class="warning">'.$langs->trans('Available').'&nbsp;:&nbsp;'.$text_stock_reel.'</span>';
  1922. } else {
  1923. $text_info .= '<span class="ok">'.$langs->trans('Available').'&nbsp;:&nbsp;'.$text_stock_reel.'</span>';
  1924. }
  1925. if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_order->enabled)) {
  1926. $text_info .= '&nbsp;'.$langs->trans('SupplierOrder').'&nbsp;:&nbsp;'.$stock_order_supplier;
  1927. }
  1928. $text_info .= ($reliquat != $generic_commande->lines[$lig]->qty ? ' <span class="opacitymedium">('.$langs->trans("QtyInOtherShipments").' '.($generic_commande->lines[$lig]->qty - $reliquat).')</span>' : '');
  1929. $text_info .= '<br>';
  1930. }
  1931. }
  1932. }
  1933. if ($notshippable == 0) {
  1934. $text_icon = img_picto('', 'dolly', '', false, 0, 0, '', 'green paddingleft');
  1935. $text_info = $text_icon.' '.$langs->trans('Shippable').'<br>'.$text_info;
  1936. } else {
  1937. $text_icon = img_picto('', 'dolly', '', false, 0, 0, '', 'error paddingleft');
  1938. $text_info = $text_icon.' '.$langs->trans('NonShippable').'<br>'.$text_info;
  1939. }
  1940. }
  1941. if ($nbprod) {
  1942. print $form->textwithtooltip('', $text_info, 2, 1, $text_icon, '', 2);
  1943. }
  1944. if ($warning) { // Always false in default mode
  1945. print $form->textwithtooltip('', $langs->trans('NotEnoughForAllOrders').'<br>'.$text_warning, 2, 1, img_picto('', 'error'), '', 2);
  1946. }
  1947. }
  1948. print '</td>';
  1949. if (!$i) {
  1950. $totalarray['nbfield']++;
  1951. }
  1952. }
  1953. // Billed
  1954. if (!empty($arrayfields['c.facture']['checked'])) {
  1955. print '<td class="center">'.yn($obj->billed).'</td>';
  1956. if (!$i) {
  1957. $totalarray['nbfield']++;
  1958. }
  1959. }
  1960. // Status
  1961. if (!empty($arrayfields['c.fk_statut']['checked'])) {
  1962. print '<td class="nowrap center">'.$generic_commande->LibStatut($obj->fk_statut, $obj->billed, 5, 1).'</td>';
  1963. if (!$i) {
  1964. $totalarray['nbfield']++;
  1965. }
  1966. }
  1967. // Action column
  1968. print '<td class="nowrap center">';
  1969. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  1970. $selected = 0;
  1971. if (in_array($obj->rowid, $arrayofselected)) {
  1972. $selected = 1;
  1973. }
  1974. print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
  1975. }
  1976. print '</td>';
  1977. if (!$i) {
  1978. $totalarray['nbfield']++;
  1979. }
  1980. print "</tr>\n";
  1981. $total += $obj->total_ht;
  1982. $subtotal += $obj->total_ht;
  1983. $i++;
  1984. }
  1985. // Show total line
  1986. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  1987. $db->free($resql);
  1988. $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  1989. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters); // Note that $action and $object may have been modified by hook
  1990. print $hookmanager->resPrint;
  1991. print '</table>'."\n";
  1992. print '</div>';
  1993. print '</form>'."\n";
  1994. $hidegeneratedfilelistifempty = 1;
  1995. if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
  1996. $hidegeneratedfilelistifempty = 0;
  1997. }
  1998. // Show list of available documents
  1999. $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
  2000. $urlsource .= str_replace('&amp;', '&', $param);
  2001. $filedir = $diroutputmassaction;
  2002. $genallowed = $permissiontoread;
  2003. $delallowed = $permissiontoadd;
  2004. print $formfile->showdocuments('massfilesarea_orders', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
  2005. } else {
  2006. dol_print_error($db);
  2007. }
  2008. // End of page
  2009. llxFooter();
  2010. $db->close();