list_det.php 96 KB

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