list.php 109 KB

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