list.php 75 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889
  1. <?php
  2. /* Copyright (C) 2001-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
  6. * Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
  7. * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
  8. * Copyright (C) 2016 Ferran Marcet <fmarcet@2byte.es>
  9. * Copyright (C) 2018-2021 Frédéric France <frederic.france@netlogic.fr>
  10. * Copyright (C) 2018-2020 Charlene Benke <charlie@patas-monkey.com>
  11. * Copyright (C) 2019 Nicolas Zabouri <info@inovea-conseil.com>
  12. * Copyright (C) 2021 Alexandre Spangaro <aspangaro@open-dsi.fr>
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation; either version 3 of the License, or
  17. * (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  26. */
  27. /**
  28. * \file htdocs/fourn/commande/list.php
  29. * \ingroup fournisseur
  30. * \brief List of purchase orders
  31. */
  32. require '../../main.inc.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  35. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
  36. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
  37. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
  38. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  39. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formorder.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. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  43. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  44. $langs->loadLangs(array("orders", "sendings", 'deliveries', 'companies', 'compta', 'bills', 'projects', 'suppliers', 'products'));
  45. $action = GETPOST('action', 'aZ09');
  46. $massaction = GETPOST('massaction', 'alpha');
  47. $show_files = GETPOST('show_files', 'int');
  48. $confirm = GETPOST('confirm', 'alpha');
  49. $toselect = GETPOST('toselect', 'array');
  50. $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'supplierorderlist';
  51. $search_date_order_startday = GETPOST('search_date_order_startday', 'int');
  52. $search_date_order_startmonth = GETPOST('search_date_order_startmonth', 'int');
  53. $search_date_order_startyear = GETPOST('search_date_order_startyear', 'int');
  54. $search_date_order_endday = GETPOST('search_date_order_endday', 'int');
  55. $search_date_order_endmonth = GETPOST('search_date_order_endmonth', 'int');
  56. $search_date_order_endyear = GETPOST('search_date_order_endyear', 'int');
  57. $search_date_order_start = dol_mktime(0, 0, 0, $search_date_order_startmonth, $search_date_order_startday, $search_date_order_startyear); // Use tzserver
  58. $search_date_order_end = dol_mktime(23, 59, 59, $search_date_order_endmonth, $search_date_order_endday, $search_date_order_endyear);
  59. $search_date_delivery_startday = GETPOST('search_date_delivery_startday', 'int');
  60. $search_date_delivery_startmonth = GETPOST('search_date_delivery_startmonth', 'int');
  61. $search_date_delivery_startyear = GETPOST('search_date_delivery_startyear', 'int');
  62. $search_date_delivery_endday = GETPOST('search_date_delivery_endday', 'int');
  63. $search_date_delivery_endmonth = GETPOST('search_date_delivery_endmonth', 'int');
  64. $search_date_delivery_endyear = GETPOST('search_date_delivery_endyear', 'int');
  65. $search_date_delivery_start = dol_mktime(0, 0, 0, $search_date_delivery_startmonth, $search_date_delivery_startday, $search_date_delivery_startyear); // Use tzserver
  66. $search_date_delivery_end = dol_mktime(23, 59, 59, $search_date_delivery_endmonth, $search_date_delivery_endday, $search_date_delivery_endyear);
  67. $search_date_valid_startday = GETPOST('search_date_valid_startday', 'int');
  68. $search_date_valid_startmonth = GETPOST('search_date_valid_startmonth', 'int');
  69. $search_date_valid_startyear = GETPOST('search_date_valid_startyear', 'int');
  70. $search_date_valid_endday = GETPOST('search_date_valid_endday', 'int');
  71. $search_date_valid_endmonth = GETPOST('search_date_valid_endmonth', 'int');
  72. $search_date_valid_endyear = GETPOST('search_date_valid_endyear', 'int');
  73. $search_date_valid_start = dol_mktime(0, 0, 0, $search_date_valid_startmonth, $search_date_valid_startday, $search_date_valid_startyear); // Use tzserver
  74. $search_date_valid_end = dol_mktime(23, 59, 59, $search_date_valid_endmonth, $search_date_valid_endday, $search_date_valid_endyear);
  75. $search_date_approve_startday = GETPOST('search_date_approve_startday', 'int');
  76. $search_date_approve_startmonth = GETPOST('search_date_approve_startmonth', 'int');
  77. $search_date_approve_startyear = GETPOST('search_date_approve_startyear', 'int');
  78. $search_date_approve_endday = GETPOST('search_date_approve_endday', 'int');
  79. $search_date_approve_endmonth = GETPOST('search_date_approve_endmonth', 'int');
  80. $search_date_approve_endyear = GETPOST('search_date_approve_endyear', 'int');
  81. $search_date_approve_start = dol_mktime(0, 0, 0, $search_date_approve_startmonth, $search_date_approve_startday, $search_date_approve_startyear); // Use tzserver
  82. $search_date_approve_end = dol_mktime(23, 59, 59, $search_date_approve_endmonth, $search_date_approve_endday, $search_date_approve_endyear);
  83. $sall = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
  84. $search_product_category = GETPOST('search_product_category', 'int');
  85. $search_ref = GETPOST('search_ref', 'alpha');
  86. $search_refsupp = GETPOST('search_refsupp', 'alpha');
  87. $search_company = GETPOST('search_company', 'alpha');
  88. $search_town = GETPOST('search_town', 'alpha');
  89. $search_zip = GETPOST('search_zip', 'alpha');
  90. $search_state = GETPOST("search_state", 'alpha');
  91. $search_country = GETPOST("search_country", 'int');
  92. $search_type_thirdparty = GETPOST("search_type_thirdparty", 'int');
  93. $search_user = GETPOST('search_user', 'int');
  94. $search_request_author = GETPOST('search_request_author', 'alpha');
  95. $search_ht = GETPOST('search_ht', 'alpha');
  96. $search_ttc = GETPOST('search_ttc', 'alpha');
  97. $optioncss = GETPOST('optioncss', 'alpha');
  98. $socid = GETPOST('socid', 'int');
  99. $search_sale = GETPOST('search_sale', 'int');
  100. $search_total_ht = GETPOST('search_total_ht', 'alpha');
  101. $search_total_tva = GETPOST('search_total_tva', 'alpha');
  102. $search_total_ttc = GETPOST('search_total_ttc', 'alpha');
  103. $search_multicurrency_code = GETPOST('search_multicurrency_code', 'alpha');
  104. $search_multicurrency_tx = GETPOST('search_multicurrency_tx', 'alpha');
  105. $search_multicurrency_montant_ht = GETPOST('search_multicurrency_montant_ht', 'alpha');
  106. $search_multicurrency_montant_tva = GETPOST('search_multicurrency_montant_tva', 'alpha');
  107. $search_multicurrency_montant_ttc = GETPOST('search_multicurrency_montant_ttc', 'alpha');
  108. $optioncss = GETPOST('optioncss', 'alpha');
  109. $search_billed = GETPOST('search_billed', 'int');
  110. $search_project_ref = GETPOST('search_project_ref', 'alpha');
  111. $search_btn = GETPOST('button_search', 'alpha');
  112. $search_remove_btn = GETPOST('button_removefilter', 'alpha');
  113. if (is_array(GETPOST('search_status', 'none'))) { // 'none' because we want to know type before sanitizing
  114. $search_status = join(',', GETPOST('search_status', 'array:intcomma'));
  115. } else {
  116. $search_status = (GETPOST('search_status', 'intcomma') != '' ? GETPOST('search_status', 'intcomma') : GETPOST('statut', 'intcomma'));
  117. }
  118. // Security check
  119. $orderid = GETPOST('orderid', 'int');
  120. if ($user->socid) {
  121. $socid = $user->socid;
  122. }
  123. $result = restrictedArea($user, 'fournisseur', $orderid, '', 'commande');
  124. $diroutputmassaction = $conf->fournisseur->commande->dir_output.'/temp/massgeneration/'.$user->id;
  125. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  126. $sortfield = GETPOST('sortfield', 'aZ09comma');
  127. $sortorder = GETPOST('sortorder', 'aZ09comma');
  128. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  129. if (empty($page) || $page == -1 || !empty($search_btn) || !empty($search_remove_btn) || (empty($toselect) && $massaction === '0')) {
  130. $page = 0;
  131. } // If $page is not defined, or '' or -1
  132. $offset = $limit * $page;
  133. $pageprev = $page - 1;
  134. $pagenext = $page + 1;
  135. if (!$sortfield) {
  136. $sortfield = 'cf.ref';
  137. }
  138. if (!$sortorder) {
  139. $sortorder = 'DESC';
  140. }
  141. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  142. $object = new CommandeFournisseur($db);
  143. $hookmanager->initHooks(array('supplierorderlist'));
  144. $extrafields = new ExtraFields($db);
  145. // fetch optionals attributes and labels
  146. $extrafields->fetch_name_optionals_label($object->table_element);
  147. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  148. // List of fields to search into when doing a "search in all"
  149. $fieldstosearchall = array();
  150. foreach ($object->fields as $key => $val) {
  151. if (!empty($val['searchall'])) {
  152. $fieldstosearchall['cf.'.$key] = $val['label'];
  153. }
  154. }
  155. $fieldstosearchall['pd.description'] = 'Description';
  156. $fieldstosearchall['s.nom'] = "ThirdParty";
  157. $fieldstosearchall['s.name_alias'] = "AliasNameShort";
  158. $fieldstosearchall['s.zip'] = "Zip";
  159. $fieldstosearchall['s.town'] = "Town";
  160. if (empty($user->socid)) {
  161. $fieldstosearchall["cf.note_private"] = "NotePrivate";
  162. }
  163. $checkedtypetiers = 0;
  164. // Definition of array of fields for columns
  165. $arrayfields = array(
  166. 's.town'=>array('label'=>"Town", 'enabled'=>1, 'position'=>47, 'checked'=>1),
  167. 's.zip'=>array('label'=>"Zip", 'enabled'=>1, 'position'=>47, 'checked'=>1),
  168. 'state.nom'=>array('label'=>"StateShort", 'enabled'=>1, 'position'=>48),
  169. 'country.code_iso'=>array('label'=>"Country", 'enabled'=>1, 'position'=>49),
  170. 'typent.code'=>array('label'=>"ThirdPartyType", 'enabled'=>$checkedtypetiers, 'position'=>50),
  171. 'u.login'=>array('label'=>"AuthorRequest", 'enabled'=>1, 'position'=>51)
  172. );
  173. foreach ($object->fields as $key => $val) {
  174. // If $val['visible']==0, then we never show the field
  175. if (!empty($val['visible'])) {
  176. $visible = (int) dol_eval($val['visible'], 1);
  177. $arrayfields['cf.'.$key] = array(
  178. 'label'=>$val['label'],
  179. 'checked'=>(($visible < 0) ? 0 : 1),
  180. 'enabled'=>(abs($visible) != 3 && dol_eval($val['enabled'], 1)),
  181. 'position'=>$val['position'],
  182. 'help'=> isset($val['help']) ? $val['help'] : ''
  183. );
  184. }
  185. }
  186. // Extra fields
  187. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
  188. $object->fields = dol_sort_array($object->fields, 'position');
  189. $arrayfields = dol_sort_array($arrayfields, 'position');
  190. $error = 0;
  191. /*
  192. * Actions
  193. */
  194. if (GETPOST('cancel', 'alpha')) {
  195. $action = 'list'; $massaction = '';
  196. }
  197. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend' && $massaction != 'confirm_createsupplierbills') {
  198. $massaction = '';
  199. }
  200. $parameters = array('socid'=>$socid);
  201. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  202. if ($reshook < 0) {
  203. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  204. }
  205. if (empty($reshook)) {
  206. // Selection of new fields
  207. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  208. // Purge search criteria
  209. 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
  210. $search_categ = '';
  211. $search_user = '';
  212. $search_sale = '';
  213. $search_product_category = '';
  214. $search_ref = '';
  215. $search_refsupp = '';
  216. $search_company = '';
  217. $search_town = '';
  218. $search_zip = "";
  219. $search_state = "";
  220. $search_type = '';
  221. $search_country = '';
  222. $search_type_thirdparty = '';
  223. $search_request_author = '';
  224. $search_total_ht = '';
  225. $search_total_tva = '';
  226. $search_total_ttc = '';
  227. $search_multicurrency_code = '';
  228. $search_multicurrency_tx = '';
  229. $search_multicurrency_montant_ht = '';
  230. $search_multicurrency_montant_tva = '';
  231. $search_multicurrency_montant_ttc = '';
  232. $search_project_ref = '';
  233. $search_status = '';
  234. $search_date_order_startday = '';
  235. $search_date_order_startmonth = '';
  236. $search_date_order_startyear = '';
  237. $search_date_order_endday = '';
  238. $search_date_order_endmonth = '';
  239. $search_date_order_endyear = '';
  240. $search_date_order_start = '';
  241. $search_date_order_end = '';
  242. $search_date_delivery_startday = '';
  243. $search_date_delivery_startmonth = '';
  244. $search_date_delivery_startyear = '';
  245. $search_date_delivery_endday = '';
  246. $search_date_delivery_endmonth = '';
  247. $search_date_delivery_endyear = '';
  248. $search_date_delivery_start = '';
  249. $search_date_delivery_end = '';
  250. $search_date_valid_startday = '';
  251. $search_date_valid_startmonth = '';
  252. $search_date_valid_startyear = '';
  253. $search_date_valid_endday = '';
  254. $search_date_valid_endmonth = '';
  255. $search_date_valid_endyear = '';
  256. $search_date_valid_start = '';
  257. $search_date_valid_end = '';
  258. $search_date_approve_startday = '';
  259. $search_date_approve_startmonth = '';
  260. $search_date_approve_startyear = '';
  261. $search_date_approve_endday = '';
  262. $search_date_approve_endmonth = '';
  263. $search_date_approve_endyear = '';
  264. $search_date_approve_start = '';
  265. $search_date_approve_end = '';
  266. $billed = '';
  267. $search_billed = '';
  268. $toselect = array();
  269. $search_array_options = array();
  270. }
  271. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
  272. || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
  273. $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
  274. }
  275. // Mass actions
  276. $objectclass = 'CommandeFournisseur';
  277. $objectlabel = 'SupplierOrders';
  278. $permissiontoread = $user->rights->fournisseur->commande->lire;
  279. $permissiontodelete = $user->rights->fournisseur->commande->supprimer;
  280. $permissiontovalidate = $user->rights->fournisseur->commande->creer;
  281. $uploaddir = $conf->fournisseur->commande->dir_output;
  282. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  283. if ($action == 'validate' && $permissiontovalidate) {
  284. if (GETPOST('confirm') == 'yes') {
  285. $objecttmp = new CommandeFournisseur($db);
  286. $db->begin();
  287. $error = 0;
  288. foreach ($toselect as $checked) {
  289. if ($objecttmp->fetch($checked)) {
  290. if ($objecttmp->statut == 0) {
  291. $objecttmp->date_commande = dol_now();
  292. $result = $objecttmp->valid($user);
  293. if ($result >= 0) {
  294. // If we have permission, and if we don't need to provide the idwarehouse, we go directly on approved step
  295. if (empty($conf->global->SUPPLIER_ORDER_NO_DIRECT_APPROVE) && $user->rights->fournisseur->commande->approuver && !(!empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER) && $objecttmp->hasProductsOrServices(1))) {
  296. $result = $objecttmp->approve($user);
  297. setEventMessages($langs->trans("SupplierOrderValidatedAndApproved"), array($objecttmp->ref));
  298. } else {
  299. setEventMessages($langs->trans("SupplierOrderValidated"), array($objecttmp->ref));
  300. }
  301. } else {
  302. setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
  303. $error++;
  304. }
  305. }
  306. }
  307. }
  308. if (!$error) $db->commit();
  309. else $db->rollback();
  310. }
  311. }
  312. // Mass action to generate vendor bills
  313. if ($massaction == 'confirm_createsupplierbills') {
  314. $orders = GETPOST('toselect', 'array');
  315. $createbills_onebythird = GETPOST('createbills_onebythird', 'int');
  316. $validate_invoices = GETPOST('validate_invoices', 'int');
  317. $TFact = array();
  318. $TFactThird = array();
  319. $nb_bills_created = 0;
  320. $lastid = 0;
  321. $lastref = '';
  322. $db->begin();
  323. $default_ref_supplier=dol_print_date(dol_now(), '%Y%m%d%H%M%S');
  324. foreach ($orders as $id_order) {
  325. $cmd = new CommandeFournisseur($db);
  326. if ($cmd->fetch($id_order) <= 0) {
  327. continue;
  328. }
  329. $objecttmp = new FactureFournisseur($db);
  330. if (!empty($createbills_onebythird) && !empty($TFactThird[$cmd->socid])) {
  331. $objecttmp = $TFactThird[$cmd->socid]; // If option "one bill per third" is set, we use already created order.
  332. } else {
  333. $objecttmp->socid = $cmd->socid;
  334. $objecttmp->type = $objecttmp::TYPE_STANDARD;
  335. $objecttmp->cond_reglement_id = $cmd->cond_reglement_id;
  336. $objecttmp->mode_reglement_id = $cmd->mode_reglement_id;
  337. $objecttmp->fk_project = $cmd->fk_project;
  338. $objecttmp->multicurrency_code = $cmd->multicurrency_code;
  339. $objecttmp->ref_supplier = !empty($cmd->ref_supplier) ? $cmd->ref_supplier : $default_ref_supplier;
  340. $default_ref_supplier+=1;
  341. $datefacture = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
  342. if (empty($datefacture)) {
  343. $datefacture = dol_now();
  344. }
  345. $objecttmp->date = $datefacture;
  346. $objecttmp->origin = 'order_supplier';
  347. $objecttmp->origin_id = $id_order;
  348. $res = $objecttmp->create($user);
  349. if ($res > 0) {
  350. $nb_bills_created++;
  351. $lastref = $objecttmp->ref;
  352. $lastid = $objecttmp->id;
  353. }
  354. }
  355. if ($objecttmp->id > 0) {
  356. $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_element (";
  357. $sql .= "fk_source";
  358. $sql .= ", sourcetype";
  359. $sql .= ", fk_target";
  360. $sql .= ", targettype";
  361. $sql .= ") VALUES (";
  362. $sql .= $id_order;
  363. $sql .= ", '".$db->escape($objecttmp->origin)."'";
  364. $sql .= ", ".((int) $objecttmp->id);
  365. $sql .= ", '".$db->escape($objecttmp->element)."'";
  366. $sql .= ")";
  367. if (!$db->query($sql)) {
  368. $erorr++;
  369. }
  370. if (!$error) {
  371. $lines = $cmd->lines;
  372. if (empty($lines) && method_exists($cmd, 'fetch_lines')) {
  373. $cmd->fetch_lines();
  374. $lines = $cmd->lines;
  375. }
  376. $fk_parent_line = 0;
  377. $num = count($lines);
  378. for ($i = 0; $i < $num; $i++) {
  379. $desc = ($lines[$i]->desc ? $lines[$i]->desc : $lines[$i]->libelle);
  380. if ($lines[$i]->subprice < 0) {
  381. // Negative line, we create a discount line
  382. $discount = new DiscountAbsolute($db);
  383. $discount->fk_soc = $objecttmp->socid;
  384. $discount->amount_ht = abs($lines[$i]->total_ht);
  385. $discount->amount_tva = abs($lines[$i]->total_tva);
  386. $discount->amount_ttc = abs($lines[$i]->total_ttc);
  387. $discount->tva_tx = $lines[$i]->tva_tx;
  388. $discount->fk_user = $user->id;
  389. $discount->description = $desc;
  390. $discountid = $discount->create($user);
  391. if ($discountid > 0) {
  392. $result = $objecttmp->insert_discount($discountid);
  393. //$result=$discount->link_to_invoice($lineid,$id);
  394. } else {
  395. setEventMessages($discount->error, $discount->errors, 'errors');
  396. $error++;
  397. break;
  398. }
  399. } else {
  400. // Positive line
  401. $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : 0);
  402. // Date start
  403. $date_start = false;
  404. if ($lines[$i]->date_debut_prevue) {
  405. $date_start = $lines[$i]->date_debut_prevue;
  406. }
  407. if ($lines[$i]->date_debut_reel) {
  408. $date_start = $lines[$i]->date_debut_reel;
  409. }
  410. if ($lines[$i]->date_start) {
  411. $date_start = $lines[$i]->date_start;
  412. }
  413. //Date end
  414. $date_end = false;
  415. if ($lines[$i]->date_fin_prevue) {
  416. $date_end = $lines[$i]->date_fin_prevue;
  417. }
  418. if ($lines[$i]->date_fin_reel) {
  419. $date_end = $lines[$i]->date_fin_reel;
  420. }
  421. if ($lines[$i]->date_end) {
  422. $date_end = $lines[$i]->date_end;
  423. }
  424. // Reset fk_parent_line for no child products and special product
  425. if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
  426. $fk_parent_line = 0;
  427. }
  428. $result = $objecttmp->addline(
  429. $desc,
  430. $lines[$i]->subprice,
  431. $lines[$i]->tva_tx,
  432. $lines[$i]->localtax1_tx,
  433. $lines[$i]->localtax2_tx,
  434. $lines[$i]->qty,
  435. $lines[$i]->fk_product,
  436. $lines[$i]->remise_percent,
  437. $date_start,
  438. $date_end,
  439. 0,
  440. $lines[$i]->info_bits,
  441. 'HT',
  442. $product_type,
  443. $lines[$i]->rang,
  444. false,
  445. $lines[$i]->array_options,
  446. $lines[$i]->fk_unit,
  447. $objecttmp->origin_id,
  448. $lines[$i]->pa_ht,
  449. $lines[$i]->ref_supplier,
  450. $lines[$i]->special_code,
  451. $fk_parent_line
  452. );
  453. if ($result > 0) {
  454. $lineid = $result;
  455. } else {
  456. $lineid = 0;
  457. $error++;
  458. break;
  459. }
  460. // Defined the new fk_parent_line
  461. if ($result > 0 && $lines[$i]->product_type == 9) {
  462. $fk_parent_line = $result;
  463. }
  464. }
  465. }
  466. }
  467. }
  468. $cmd->classifyBilled($user); // TODO Move this in workflow like done for customer orders
  469. if (!empty($createbills_onebythird) && empty($TFactThird[$cmd->socid])) {
  470. $TFactThird[$cmd->socid] = $objecttmp;
  471. } else {
  472. $TFact[$objecttmp->id] = $objecttmp;
  473. }
  474. }
  475. // Build doc with all invoices
  476. $TAllFact = empty($createbills_onebythird) ? $TFact : $TFactThird;
  477. $toselect = array();
  478. if (!$error && $validate_invoices) {
  479. $massaction = $action = 'builddoc';
  480. foreach ($TAllFact as &$objecttmp) {
  481. $objecttmp->validate($user);
  482. if ($result <= 0) {
  483. $error++;
  484. setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
  485. break;
  486. }
  487. $id = $objecttmp->id; // For builddoc action
  488. // Fac builddoc
  489. $donotredirect = 1;
  490. $upload_dir = $conf->fournisseur->facture->dir_output;
  491. $permissiontoadd = ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer);
  492. //include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
  493. }
  494. $massaction = $action = 'confirm_createsupplierbills';
  495. }
  496. if (!$error) {
  497. $db->commit();
  498. if ($nb_bills_created == 1) {
  499. $texttoshow = $langs->trans('BillXCreated', '{s1}');
  500. $texttoshow = str_replace('{s1}', '<a href="'.DOL_URL_ROOT.'/fourn/facture/card.php?id='.urlencode($lastid).'">'.$lastref.'</a>', $texttoshow);
  501. setEventMessages($texttoshow, null, 'mesgs');
  502. } else {
  503. setEventMessages($langs->trans('BillCreated', $nb_bills_created), null, 'mesgs');
  504. }
  505. // Make a redirect to avoid to bill twice if we make a refresh or back
  506. $param = '';
  507. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  508. $param .= '&contextpage='.urlencode($contextpage);
  509. }
  510. if ($limit > 0 && $limit != $conf->liste_limit) {
  511. $param .= '&limit='.urlencode($limit);
  512. }
  513. if ($sall) {
  514. $param .= '&sall='.urlencode($sall);
  515. }
  516. if ($socid > 0) {
  517. $param .= '&socid='.urlencode($socid);
  518. }
  519. if ($search_status != '') {
  520. $param .= '&search_status='.urlencode($search_status);
  521. }
  522. if ($search_date_order_startday) {
  523. $param .= '&search_date_order_startday='.urlencode($search_date_order_startday);
  524. }
  525. if ($search_date_order_startmonth) {
  526. $param .= '&search_date_order_startmonth='.urlencode($search_date_order_startmonth);
  527. }
  528. if ($search_date_order_startyear) {
  529. $param .= '&search_date_order_startyear='.urlencode($search_date_order_startyear);
  530. }
  531. if ($search_date_order_endday) {
  532. $param .= '&search_date_order_endday='.urlencode($search_date_order_endday);
  533. }
  534. if ($search_date_order_endmonth) {
  535. $param .= '&search_date_order_endmonth='.urlencode($search_date_order_endmonth);
  536. }
  537. if ($search_date_order_endyear) {
  538. $param .= '&search_date_order_endyear='.urlencode($search_date_order_endyear);
  539. }
  540. if ($search_date_delivery_startday) {
  541. $param .= '&search_date_delivery_startday='.urlencode($search_date_delivery_startday);
  542. }
  543. if ($search_date_delivery_startmonth) {
  544. $param .= '&search_date_delivery_startmonth='.urlencode($search_date_delivery_startmonth);
  545. }
  546. if ($search_date_delivery_startyear) {
  547. $param .= '&search_date_delivery_startyear='.urlencode($search_date_delivery_startyear);
  548. }
  549. if ($search_date_delivery_endday) {
  550. $param .= '&search_date_delivery_endday='.urlencode($search_date_delivery_endday);
  551. }
  552. if ($search_date_delivery_endmonth) {
  553. $param .= '&search_date_delivery_endmonth='.urlencode($search_date_delivery_endmonth);
  554. }
  555. if ($search_date_delivery_endyear) {
  556. $param .= '&search_date_delivery_endyear='.urlencode($search_date_delivery_endyear);
  557. }
  558. if ($search_date_valid_startday) {
  559. $param .= '&search_date_valid_startday='.urlencode($search_date_valid_startday);
  560. }
  561. if ($search_date_valid_startmonth) {
  562. $param .= '&search_date_valid_startmonth='.urlencode($search_date_valid_startmonth);
  563. }
  564. if ($search_date_valid_startyear) {
  565. $param .= '&search_date_valid_startyear='.urlencode($search_date_valid_startyear);
  566. }
  567. if ($search_date_valid_endday) {
  568. $param .= '&search_date_valid_endday='.urlencode($search_date_valid_endday);
  569. }
  570. if ($search_date_valid_endmonth) {
  571. $param .= '&search_date_valid_endmonth='.urlencode($search_date_valid_endmonth);
  572. }
  573. if ($search_date_valid_endyear) {
  574. $param .= '&search_date_valid_endyear='.urlencode($search_date_valid_endyear);
  575. }
  576. if ($search_date_approve_startday) {
  577. $param .= '&search_date_approve_startday='.urlencode($search_date_approve_startday);
  578. }
  579. if ($search_date_approve_startmonth) {
  580. $param .= '&search_date_approve_startmonth='.urlencode($search_date_approve_startmonth);
  581. }
  582. if ($search_date_approve_startyear) {
  583. $param .= '&search_date_approve_startyear='.urlencode($search_date_approve_startyear);
  584. }
  585. if ($search_date_approve_endday) {
  586. $param .= '&search_date_approve_endday='.urlencode($search_date_approve_endday);
  587. }
  588. if ($search_date_approve_endmonth) {
  589. $param .= '&search_date_approve_endmonth='.urlencode($search_date_approve_endmonth);
  590. }
  591. if ($search_date_approve_endyear) {
  592. $param .= '&search_date_approve_endyear='.urlencode($search_date_approve_endyear);
  593. }
  594. if ($search_ref) {
  595. $param .= '&search_ref='.urlencode($search_ref);
  596. }
  597. if ($search_company) {
  598. $param .= '&search_company='.urlencode($search_company);
  599. }
  600. //if ($search_ref_customer) $param .= '&search_ref_customer='.urlencode($search_ref_customer);
  601. if ($search_user > 0) {
  602. $param .= '&search_user='.urlencode($search_user);
  603. }
  604. if ($search_sale > 0) {
  605. $param .= '&search_sale='.urlencode($search_sale);
  606. }
  607. if ($search_total_ht != '') {
  608. $param .= '&search_total_ht='.urlencode($search_total_ht);
  609. }
  610. if ($search_total_tva != '') {
  611. $param .= '&search_total_tva='.urlencode($search_total_tva);
  612. }
  613. if ($search_total_ttc != '') {
  614. $param .= '&search_total_ttc='.urlencode($search_total_ttc);
  615. }
  616. if ($search_project_ref >= 0) {
  617. $param .= "&search_project_ref=".urlencode($search_project_ref);
  618. }
  619. if ($show_files) {
  620. $param .= '&show_files='.urlencode($show_files);
  621. }
  622. if ($optioncss != '') {
  623. $param .= '&optioncss='.urlencode($optioncss);
  624. }
  625. if ($billed != '') {
  626. $param .= '&billed='.urlencode($billed);
  627. }
  628. header("Location: ".$_SERVER['PHP_SELF'].'?'.$param);
  629. exit;
  630. } else {
  631. $db->rollback();
  632. $action = 'create';
  633. $_GET["origin"] = $_POST["origin"];
  634. $_GET["originid"] = $_POST["originid"];
  635. setEventMessages("Error", null, 'errors');
  636. $error++;
  637. }
  638. }
  639. }
  640. /*
  641. * View
  642. */
  643. $now = dol_now();
  644. $form = new Form($db);
  645. $thirdpartytmp = new Fournisseur($db);
  646. $commandestatic = new CommandeFournisseur($db);
  647. $formfile = new FormFile($db);
  648. $formorder = new FormOrder($db);
  649. $formother = new FormOther($db);
  650. $formcompany = new FormCompany($db);
  651. $title = $langs->trans("ListOfSupplierOrders");
  652. if ($socid > 0) {
  653. $fourn = new Fournisseur($db);
  654. $fourn->fetch($socid);
  655. $title .= ' - '.$fourn->name;
  656. }
  657. /*if ($search_status)
  658. {
  659. if ($search_status == '1,2') $title .= ' - '.$langs->trans("SuppliersOrdersToProcess");
  660. elseif ($search_status == '3,4') $title .= ' - '.$langs->trans("SuppliersOrdersAwaitingReception");
  661. elseif ($search_status == '1,2,3') $title .= ' - '.$langs->trans("StatusOrderToProcessShort");
  662. elseif ($search_status == '6,7') $title .= ' - '.$langs->trans("StatusOrderCanceled");
  663. elseif (is_numeric($search_status) && $search_status >= 0) $title .= ' - '.$commandestatic->LibStatut($search_status);
  664. }*/
  665. if ($search_billed > 0) {
  666. $title .= ' - '.$langs->trans("Billed");
  667. }
  668. //$help_url="EN:Module_Customers_Orders|FR:Module_Commandes_Clients|ES:Módulo_Pedidos_de_clientes";
  669. $help_url = '';
  670. // llxHeader('',$title,$help_url);
  671. $sql = 'SELECT';
  672. if ($sall || $search_product_category > 0) {
  673. $sql = 'SELECT DISTINCT';
  674. }
  675. $sql .= ' s.rowid as socid, s.nom as name, s.town, s.zip, s.fk_pays, s.client, s.code_client, s.email,';
  676. $sql .= " typent.code as typent_code,";
  677. $sql .= " state.code_departement as state_code, state.nom as state_name,";
  678. $sql .= " cf.rowid, cf.ref, cf.ref_supplier, cf.fk_statut, cf.billed, cf.total_ht, cf.total_tva, cf.total_ttc, cf.fk_user_author, cf.date_commande as date_commande, cf.date_livraison as date_livraison,cf.date_valid, cf.date_approve,";
  679. $sql .= ' cf.fk_multicurrency, cf.multicurrency_code, cf.multicurrency_tx, cf.multicurrency_total_ht, cf.multicurrency_total_tva, cf.multicurrency_total_ttc,';
  680. $sql .= ' cf.date_creation as date_creation, cf.tms as date_update,';
  681. $sql .= ' cf.note_public, cf.note_private,';
  682. $sql .= " p.rowid as project_id, p.ref as project_ref, p.title as project_title,";
  683. $sql .= " u.firstname, u.lastname, u.photo, u.login, u.email as user_email, u.statut as user_status";
  684. // Add fields from extrafields
  685. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  686. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  687. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
  688. }
  689. }
  690. // Add fields from hooks
  691. $parameters = array();
  692. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
  693. $sql .= $hookmanager->resPrint;
  694. $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
  695. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
  696. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
  697. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)";
  698. $sql .= ", ".MAIN_DB_PREFIX."commande_fournisseur as cf";
  699. if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
  700. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (cf.rowid = ef.fk_object)";
  701. }
  702. if ($sall || $search_product_category > 0) {
  703. $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'commande_fournisseurdet as pd ON cf.rowid=pd.fk_commande';
  704. }
  705. if ($search_product_category > 0) {
  706. $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=pd.fk_product';
  707. }
  708. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON cf.fk_user_author = u.rowid";
  709. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as p ON p.rowid = cf.fk_projet";
  710. // We'll need this table joined to the select in order to filter by sale
  711. if ($search_sale > 0 || (empty($user->rights->societe->client->voir) && !$socid)) {
  712. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  713. }
  714. $parameters = array();
  715. $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
  716. $sql .= $hookmanager->resPrint;
  717. $sql .= ' WHERE cf.fk_soc = s.rowid';
  718. $sql .= ' AND cf.entity IN ('.getEntity('supplier_order').')';
  719. if ($socid > 0) {
  720. $sql .= " AND s.rowid = ".((int) $socid);
  721. }
  722. if (empty($user->rights->societe->client->voir) && !$socid) {
  723. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  724. }
  725. if ($search_ref) {
  726. $sql .= natural_search('cf.ref', $search_ref);
  727. }
  728. if ($search_refsupp) {
  729. $sql .= natural_search("cf.ref_supplier", $search_refsupp);
  730. }
  731. if ($sall) {
  732. $sql .= natural_search(array_keys($fieldstosearchall), $sall);
  733. }
  734. if ($search_company) {
  735. $sql .= natural_search('s.nom', $search_company);
  736. }
  737. if ($search_request_author) {
  738. $sql .= natural_search(array('u.lastname', 'u.firstname', 'u.login'), $search_request_author);
  739. }
  740. if ($search_billed != '' && $search_billed >= 0) {
  741. $sql .= " AND cf.billed = ".((int) $search_billed);
  742. }
  743. if ($search_product_category > 0) {
  744. $sql .= " AND cp.fk_categorie = ".((int) $search_product_category);
  745. }
  746. //Required triple check because statut=0 means draft filter
  747. if (GETPOST('statut', 'intcomma') !== '') {
  748. $sql .= " AND cf.fk_statut IN (".$db->sanitize($db->escape($db->escape(GETPOST('statut', 'intcomma')))).")";
  749. }
  750. if ($search_status != '' && $search_status != '-1') {
  751. $sql .= " AND cf.fk_statut IN (".$db->sanitize($db->escape($search_status)).")";
  752. }
  753. if ($search_date_order_start) {
  754. $sql .= " AND cf.date_commande >= '".$db->idate($search_date_order_start)."'";
  755. }
  756. if ($search_date_order_end) {
  757. $sql .= " AND cf.date_commande <= '".$db->idate($search_date_order_end)."'";
  758. }
  759. if ($search_date_delivery_start) {
  760. $sql .= " AND cf.date_livraison >= '".$db->idate($search_date_delivery_start)."'";
  761. }
  762. if ($search_date_delivery_end) {
  763. $sql .= " AND cf.date_livraison <= '".$db->idate($search_date_delivery_end)."'";
  764. }
  765. if ($search_date_valid_start) {
  766. $sql .= " AND cf.date_commande >= '".$db->idate($search_date_valid_start)."'";
  767. }
  768. if ($search_date_valid_end) {
  769. $sql .= " AND cf.date_commande <= '".$db->idate($search_date_valid_end)."'";
  770. }
  771. if ($search_date_approve_start) {
  772. $sql .= " AND cf.date_livraison >= '".$db->idate($search_date_approve_start)."'";
  773. }
  774. if ($search_date_approve_end) {
  775. $sql .= " AND cf.date_livraison <= '".$db->idate($search_date_approve_end)."'";
  776. }
  777. if ($search_town) {
  778. $sql .= natural_search('s.town', $search_town);
  779. }
  780. if ($search_zip) {
  781. $sql .= natural_search("s.zip", $search_zip);
  782. }
  783. if ($search_state) {
  784. $sql .= natural_search("state.nom", $search_state);
  785. }
  786. if ($search_country) {
  787. $sql .= " AND s.fk_pays IN (".$db->sanitize($db->escape($search_country)).')';
  788. }
  789. if ($search_type_thirdparty != '' && $search_type_thirdparty > 0) {
  790. $sql .= " AND s.fk_typent IN (".$db->sanitize($db->escape($search_type_thirdparty)).')';
  791. }
  792. if ($search_company) {
  793. $sql .= natural_search('s.nom', $search_company);
  794. }
  795. if ($search_sale > 0) {
  796. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $search_sale);
  797. }
  798. if ($search_user > 0) {
  799. $sql .= " AND EXISTS (";
  800. $sql .= " SELECT ec.rowid ";
  801. $sql .= " FROM " . MAIN_DB_PREFIX . "element_contact as ec";
  802. $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "c_type_contact as tc ON tc.rowid = ec.fk_c_type_contact";
  803. $sql .= " WHERE ec.element_id = cf.rowid AND ec.fk_socpeople = " . ((int) $search_user);
  804. $sql .= " AND tc.element = 'order_supplier' AND tc.source = 'internal'";
  805. $sql .= ")";
  806. }
  807. if ($search_total_ht != '') {
  808. $sql .= natural_search('cf.total_ht', $search_total_ht, 1);
  809. }
  810. if ($search_total_tva != '') {
  811. $sql .= natural_search('cf.total_tva', $search_total_tva, 1);
  812. }
  813. if ($search_total_ttc != '') {
  814. $sql .= natural_search('cf.total_ttc', $search_total_ttc, 1);
  815. }
  816. if ($search_multicurrency_code != '') {
  817. $sql .= " AND cf.multicurrency_code = '".$db->escape($search_multicurrency_code)."'";
  818. }
  819. if ($search_multicurrency_tx != '') {
  820. $sql .= natural_search('cf.multicurrency_tx', $search_multicurrency_tx, 1);
  821. }
  822. if ($search_multicurrency_montant_ht != '') {
  823. $sql .= natural_search('cf.multicurrency_total_ht', $search_multicurrency_montant_ht, 1);
  824. }
  825. if ($search_multicurrency_montant_tva != '') {
  826. $sql .= natural_search('cf.multicurrency_total_tva', $search_multicurrency_montant_tva, 1);
  827. }
  828. if ($search_multicurrency_montant_ttc != '') {
  829. $sql .= natural_search('cf.multicurrency_total_ttc', $search_multicurrency_montant_ttc, 1);
  830. }
  831. if ($search_project_ref != '') {
  832. $sql .= natural_search("p.ref", $search_project_ref);
  833. }
  834. // Add where from extra fields
  835. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  836. // Add where from hooks
  837. $parameters = array();
  838. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
  839. $sql .= $hookmanager->resPrint;
  840. $sql .= $db->order($sortfield, $sortorder);
  841. // Count total nb of records
  842. $nbtotalofrecords = '';
  843. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
  844. $result = $db->query($sql);
  845. $nbtotalofrecords = $db->num_rows($result);
  846. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
  847. $page = 0;
  848. $offset = 0;
  849. }
  850. }
  851. $sql .= $db->plimit($limit + 1, $offset);
  852. //print $sql;
  853. $resql = $db->query($sql);
  854. if ($resql) {
  855. $num = $db->num_rows($resql);
  856. $arrayofselected = is_array($toselect) ? $toselect : array();
  857. if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $sall) {
  858. $obj = $db->fetch_object($resql);
  859. $id = $obj->rowid;
  860. header("Location: ".DOL_URL_ROOT.'/fourn/commande/card.php?id='.$id);
  861. exit;
  862. }
  863. llxHeader('', $title, $help_url);
  864. $param = '';
  865. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  866. $param .= '&contextpage='.urlencode($contextpage);
  867. }
  868. if ($limit > 0 && $limit != $conf->liste_limit) {
  869. $param .= '&limit='.urlencode($limit);
  870. }
  871. if ($sall) {
  872. $param .= '&sall='.urlencode($sall);
  873. }
  874. if ($socid > 0) {
  875. $param .= '&socid='.urlencode($socid);
  876. }
  877. if ($sall) {
  878. $param .= "&search_all=".urlencode($sall);
  879. }
  880. if ($search_date_order_startday) {
  881. $param .= '&search_date_order_startday='.urlencode($search_date_order_startday);
  882. }
  883. if ($search_date_order_startmonth) {
  884. $param .= '&search_date_order_startmonth='.urlencode($search_date_order_startmonth);
  885. }
  886. if ($search_date_order_startyear) {
  887. $param .= '&search_date_order_startyear='.urlencode($search_date_order_startyear);
  888. }
  889. if ($search_date_order_endday) {
  890. $param .= '&search_date_order_endday='.urlencode($search_date_order_endday);
  891. }
  892. if ($search_date_order_endmonth) {
  893. $param .= '&search_date_order_endmonth='.urlencode($search_date_order_endmonth);
  894. }
  895. if ($search_date_order_endyear) {
  896. $param .= '&search_date_order_endyear='.urlencode($search_date_order_endyear);
  897. }
  898. if ($search_date_delivery_startday) {
  899. $param .= '&search_date_delivery_startday='.urlencode($search_date_delivery_startday);
  900. }
  901. if ($search_date_delivery_startmonth) {
  902. $param .= '&search_date_delivery_startmonth='.urlencode($search_date_delivery_startmonth);
  903. }
  904. if ($search_date_delivery_startyear) {
  905. $param .= '&search_date_delivery_startyear='.urlencode($search_date_delivery_startyear);
  906. }
  907. if ($search_date_delivery_endday) {
  908. $param .= '&search_date_delivery_endday='.urlencode($search_date_delivery_endday);
  909. }
  910. if ($search_date_delivery_endmonth) {
  911. $param .= '&search_date_delivery_endmonth='.urlencode($search_date_delivery_endmonth);
  912. }
  913. if ($search_date_delivery_endyear) {
  914. $param .= '&search_date_delivery_endyear='.urlencode($search_date_delivery_endyear);
  915. }
  916. if ($search_date_valid_startday) {
  917. $param .= '&search_date_valid_startday='.urlencode($search_date_valid_startday);
  918. }
  919. if ($search_date_valid_startmonth) {
  920. $param .= '&search_date_valid_startmonth='.urlencode($search_date_valid_startmonth);
  921. }
  922. if ($search_date_valid_startyear) {
  923. $param .= '&search_date_valid_startyear='.urlencode($search_date_valid_startyear);
  924. }
  925. if ($search_date_valid_endday) {
  926. $param .= '&search_date_valid_endday='.urlencode($search_date_valid_endday);
  927. }
  928. if ($search_date_valid_endmonth) {
  929. $param .= '&search_date_valid_endmonth='.urlencode($search_date_valid_endmonth);
  930. }
  931. if ($search_date_valid_endyear) {
  932. $param .= '&search_date_valid_endyear='.urlencode($search_date_valid_endyear);
  933. }
  934. if ($search_date_approve_startday) {
  935. $param .= '&search_date_approve_startday='.urlencode($search_date_approve_startday);
  936. }
  937. if ($search_date_approve_startmonth) {
  938. $param .= '&search_date_approve_startmonth='.urlencode($search_date_approve_startmonth);
  939. }
  940. if ($search_date_approve_startyear) {
  941. $param .= '&search_date_approve_startyear='.urlencode($search_date_approve_startyear);
  942. }
  943. if ($search_date_approve_endday) {
  944. $param .= '&search_date_approve_endday='.urlencode($search_date_approve_endday);
  945. }
  946. if ($search_date_approve_endmonth) {
  947. $param .= '&search_date_approve_endmonth='.urlencode($search_date_approve_endmonth);
  948. }
  949. if ($search_date_approve_endyear) {
  950. $param .= '&search_date_approve_endyear='.urlencode($search_date_approve_endyear);
  951. }
  952. if ($search_ref) {
  953. $param .= '&search_ref='.urlencode($search_ref);
  954. }
  955. if ($search_company) {
  956. $param .= '&search_company='.urlencode($search_company);
  957. }
  958. if ($search_user > 0) {
  959. $param .= '&search_user='.urlencode($search_user);
  960. }
  961. if ($search_request_author) {
  962. $param .= '&search_request_author='.urlencode($search_request_author);
  963. }
  964. if ($search_sale > 0) {
  965. $param .= '&search_sale='.urlencode($search_sale);
  966. }
  967. if ($search_total_ht != '') {
  968. $param .= '&search_total_ht='.urlencode($search_total_ht);
  969. }
  970. if ($search_total_ttc != '') {
  971. $param .= "&search_total_ttc=".urlencode($search_total_ttc);
  972. }
  973. if ($search_multicurrency_code != '') {
  974. $param .= '&search_multicurrency_code='.urlencode($search_multicurrency_code);
  975. }
  976. if ($search_multicurrency_tx != '') {
  977. $param .= '&search_multicurrency_tx='.urlencode($search_multicurrency_tx);
  978. }
  979. if ($search_multicurrency_montant_ht != '') {
  980. $param .= '&search_multicurrency_montant_ht='.urlencode($search_multicurrency_montant_ht);
  981. }
  982. if ($search_multicurrency_montant_tva != '') {
  983. $param .= '&search_multicurrency_montant_tva='.urlencode($search_multicurrency_montant_tva);
  984. }
  985. if ($search_multicurrency_montant_ttc != '') {
  986. $param .= '&search_multicurrency_montant_ttc='.urlencode($search_multicurrency_montant_ttc);
  987. }
  988. if ($search_refsupp) {
  989. $param .= "&search_refsupp=".urlencode($search_refsupp);
  990. }
  991. if ($search_status != '' && $search_status != '-1') {
  992. $param .= "&search_status=".urlencode($search_status);
  993. }
  994. if ($search_project_ref >= 0) {
  995. $param .= "&search_project_ref=".urlencode($search_project_ref);
  996. }
  997. if ($search_billed != '') {
  998. $param .= "&search_billed=".urlencode($search_billed);
  999. }
  1000. if ($show_files) {
  1001. $param .= '&show_files='.urlencode($show_files);
  1002. }
  1003. if ($optioncss != '') {
  1004. $param .= '&optioncss='.urlencode($optioncss);
  1005. }
  1006. if ($search_type_thirdparty != '' && $search_type_thirdparty > 0) {
  1007. $param .= '&search_type_thirdparty='.urlencode($search_type_thirdparty);
  1008. }
  1009. // Add $param from extra fields
  1010. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  1011. $parameters = array();
  1012. $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
  1013. $param .= $hookmanager->resPrint;
  1014. // List of mass actions available
  1015. $arrayofmassactions = array(
  1016. 'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
  1017. 'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
  1018. 'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
  1019. );
  1020. if ($permissiontovalidate) {
  1021. if ($user->rights->fournisseur->commande->approuver && empty($conf->global->SUPPLIER_ORDER_NO_DIRECT_APPROVE)) {
  1022. $arrayofmassactions['prevalidate'] = img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("ValidateAndApprove");
  1023. } else {
  1024. $arrayofmassactions['prevalidate'] = img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate");
  1025. }
  1026. }
  1027. if ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer) {
  1028. $arrayofmassactions['createbills'] = img_picto('', 'bill', 'class="pictofixedwidth"').$langs->trans("CreateInvoiceForThisSupplier");
  1029. }
  1030. if ($user->rights->fournisseur->commande->supprimer) {
  1031. $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
  1032. }
  1033. if (in_array($massaction, array('presend', 'predelete', 'createbills'))) {
  1034. $arrayofmassactions = array();
  1035. }
  1036. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  1037. $url = DOL_URL_ROOT.'/fourn/commande/card.php?action=create';
  1038. if ($socid > 0) {
  1039. $url .= '&socid='.((int) $socid);
  1040. $url .= '&backtopage='.urlencode(DOL_URL_ROOT.'/fourn/commande/list.php?socid='.((int) $socid));
  1041. }
  1042. $newcardbutton = dolGetButtonTitle($langs->trans('NewSupplierOrderShort'), '', 'fa fa-plus-circle', $url, '', ($user->rights->fournisseur->commande->creer || $user->rights->supplier_order->creer));
  1043. // Lines of title fields
  1044. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
  1045. if ($optioncss != '') {
  1046. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  1047. }
  1048. print '<input type="hidden" name="token" value="'.newToken().'">';
  1049. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  1050. print '<input type="hidden" name="action" value="list">';
  1051. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  1052. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  1053. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  1054. print '<input type="hidden" name="socid" value="'.$socid.'">';
  1055. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'supplier_order', 0, $newcardbutton, '', $limit, 0, 0, 1);
  1056. $topicmail = "SendOrderRef";
  1057. $modelmail = "order_supplier_send";
  1058. $objecttmp = new CommandeFournisseur($db);
  1059. $trackid = 'sord'.$object->id;
  1060. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  1061. if ($massaction == 'prevalidate') {
  1062. print $form->formconfirm($_SERVER["PHP_SELF"].$fieldstosearchall, $langs->trans("ConfirmMassValidation"), $langs->trans("ConfirmMassValidationQuestion"), "validate", null, '', 0, 200, 500, 1);
  1063. }
  1064. if ($massaction == 'createbills') {
  1065. //var_dump($_REQUEST);
  1066. print '<input type="hidden" name="massaction" value="confirm_createsupplierbills">';
  1067. print '<table class="noborder" width="100%" >';
  1068. print '<tr>';
  1069. print '<td class="titlefield">';
  1070. print $langs->trans('DateInvoice');
  1071. print '</td>';
  1072. print '<td>';
  1073. print $form->selectDate('', '', '', '', '', '', 1, 1);
  1074. print '</td>';
  1075. print '</tr>';
  1076. print '<tr>';
  1077. print '<td>';
  1078. print $langs->trans('CreateOneBillByThird');
  1079. print '</td>';
  1080. print '<td>';
  1081. print $form->selectyesno('createbills_onebythird', '', 1);
  1082. print '</td>';
  1083. print '</tr>';
  1084. print '<tr>';
  1085. print '<td>';
  1086. print $langs->trans('ValidateInvoices');
  1087. print '</td>';
  1088. print '<td>';
  1089. print $form->selectyesno('validate_invoices', 1, 1);
  1090. print '</td>';
  1091. print '</tr>';
  1092. print '</table>';
  1093. print '<br>';
  1094. print '<div class="center">';
  1095. print '<input type="submit" class="button" id="createbills" name="createbills" value="'.$langs->trans('CreateInvoiceForThisCustomer').'"> ';
  1096. print '<input type="submit" class="button button-cancel" id="cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
  1097. print '</div>';
  1098. print '<br>';
  1099. }
  1100. if ($sall) {
  1101. foreach ($fieldstosearchall as $key => $val) {
  1102. $fieldstosearchall[$key] = $langs->trans($val);
  1103. }
  1104. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'</div>';
  1105. }
  1106. $moreforfilter = '';
  1107. // If the user can view prospects other than his'
  1108. if ($user->rights->user->user->lire) {
  1109. $langs->load("commercial");
  1110. $moreforfilter .= '<div class="divsearchfield">';
  1111. $tmptitle = $langs->trans('ThirdPartiesOfSaleRepresentative');
  1112. $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, $tmptitle, 'maxwidth250 widthcentpercentminusx');
  1113. $moreforfilter .= '</div>';
  1114. }
  1115. // If the user can view other users
  1116. if ($user->rights->user->user->lire) {
  1117. $moreforfilter .= '<div class="divsearchfield">';
  1118. $tmptitle = $langs->trans('LinkedToSpecificUsers');
  1119. $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$form->select_dolusers($search_user, 'search_user', $tmptitle, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth250 widthcentpercentminusx');
  1120. $moreforfilter .= '</div>';
  1121. }
  1122. // If the user can view prospects other than his'
  1123. if (!empty($conf->categorie->enabled) && $user->rights->categorie->lire && ($user->rights->produit->lire || $user->rights->service->lire)) {
  1124. include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  1125. $moreforfilter .= '<div class="divsearchfield">';
  1126. $tmptitle = $langs->trans('IncludingProductWithTag');
  1127. $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, null, 'parent', null, null, 1);
  1128. $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);
  1129. $moreforfilter .= '</div>';
  1130. }
  1131. $parameters = array();
  1132. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
  1133. if (empty($reshook)) {
  1134. $moreforfilter .= $hookmanager->resPrint;
  1135. } else {
  1136. $moreforfilter = $hookmanager->resPrint;
  1137. }
  1138. if (!empty($moreforfilter)) {
  1139. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  1140. print $moreforfilter;
  1141. print '</div>';
  1142. }
  1143. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  1144. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  1145. $selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
  1146. if (GETPOST('autoselectall', 'int')) {
  1147. $selectedfields .= '<script>';
  1148. $selectedfields .= ' $(document).ready(function() {';
  1149. $selectedfields .= ' console.log("Autoclick on checkforselects");';
  1150. $selectedfields .= ' $("#checkforselects").click();';
  1151. $selectedfields .= ' $("#massaction").val("createbills").change();';
  1152. $selectedfields .= ' });';
  1153. $selectedfields .= '</script>';
  1154. }
  1155. print '<div class="div-table-responsive">';
  1156. print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  1157. print '<tr class="liste_titre_filter">';
  1158. // Ref
  1159. if (!empty($arrayfields['cf.ref']['checked'])) {
  1160. print '<td class="liste_titre"><input size="8" type="text" class="flat maxwidth75" name="search_ref" value="'.$search_ref.'"></td>';
  1161. }
  1162. // Ref customer
  1163. if (!empty($arrayfields['cf.ref_supplier']['checked'])) {
  1164. print '<td class="liste_titre"><input type="text" class="flat maxwidth75" name="search_refsupp" value="'.$search_refsupp.'"></td>';
  1165. }
  1166. // Project ref
  1167. if (!empty($arrayfields['cf.fk_projet']['checked'])) {
  1168. print '<td class="liste_titre"><input type="text" class="flat maxwidth100" name="search_project_ref" value="'.$search_project_ref.'"></td>';
  1169. }
  1170. // Request author
  1171. if (!empty($arrayfields['u.login']['checked'])) {
  1172. print '<td class="liste_titre">';
  1173. print '<input type="text" class="flat" size="6" name="search_request_author" value="'.$search_request_author.'">';
  1174. print '</td>';
  1175. }
  1176. // Thirpdarty
  1177. if (!empty($arrayfields['cf.fk_soc']['checked'])) {
  1178. print '<td class="liste_titre"><input type="text" size="6" class="flat" name="search_company" value="'.$search_company.'"></td>';
  1179. }
  1180. // Town
  1181. if (!empty($arrayfields['s.town']['checked'])) {
  1182. print '<td class="liste_titre"><input class="flat maxwidth50" type="text" name="search_town" value="'.$search_town.'"></td>';
  1183. }
  1184. // Zip
  1185. if (!empty($arrayfields['s.zip']['checked'])) {
  1186. print '<td class="liste_titre"><input class="flat maxwidth50" type="text" name="search_zip" value="'.$search_zip.'"></td>';
  1187. }
  1188. // State
  1189. if (!empty($arrayfields['state.nom']['checked'])) {
  1190. print '<td class="liste_titre">';
  1191. print '<input class="flat maxwidth50" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
  1192. print '</td>';
  1193. }
  1194. // Country
  1195. if (!empty($arrayfields['country.code_iso']['checked'])) {
  1196. print '<td class="liste_titre center">';
  1197. print $form->select_country($search_country, 'search_country', '', 0, 'minwidth100imp maxwidth100');
  1198. print '</td>';
  1199. }
  1200. // Company type
  1201. if (!empty($arrayfields['typent.code']['checked'])) {
  1202. print '<td class="liste_titre maxwidthonsmartphone center">';
  1203. 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);
  1204. print '</td>';
  1205. }
  1206. // Date order
  1207. if (!empty($arrayfields['cf.date_commande']['checked'])) {
  1208. print '<td class="liste_titre center">';
  1209. print '<div class="nowrap">';
  1210. print $form->selectDate($search_date_order_start ? $search_date_order_start : -1, 'search_date_order_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  1211. print '</div>';
  1212. print '<div class="nowrap">';
  1213. print $form->selectDate($search_date_order_end ? $search_date_order_end : -1, 'search_date_order_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  1214. print '</div>';
  1215. print '</td>';
  1216. }
  1217. // Date delivery
  1218. if (!empty($arrayfields['cf.date_livraison']['checked'])) {
  1219. print '<td class="liste_titre center">';
  1220. print '<div class="nowrap">';
  1221. print $form->selectDate($search_date_delivery_start ? $search_date_delivery_start : -1, 'search_date_delivery_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  1222. print '</div>';
  1223. print '<div class="nowrap">';
  1224. print $form->selectDate($search_date_delivery_end ? $search_date_delivery_end : -1, 'search_date_delivery_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  1225. print '</div>';
  1226. print '</td>';
  1227. }
  1228. if (!empty($arrayfields['cf.total_ht']['checked'])) {
  1229. // Amount
  1230. print '<td class="liste_titre right">';
  1231. print '<input class="flat" type="text" size="5" name="search_total_ht" value="'.$search_total_ht.'">';
  1232. print '</td>';
  1233. }
  1234. if (!empty($arrayfields['cf.total_tva']['checked'])) {
  1235. // Amount
  1236. print '<td class="liste_titre right">';
  1237. print '<input class="flat" type="text" size="5" name="search_total_tva" value="'.$search_total_tva.'">';
  1238. print '</td>';
  1239. }
  1240. if (!empty($arrayfields['cf.total_ttc']['checked'])) {
  1241. // Amount
  1242. print '<td class="liste_titre right">';
  1243. print '<input class="flat" type="text" size="5" name="search_total_ttc" value="'.$search_total_ttc.'">';
  1244. print '</td>';
  1245. }
  1246. if (!empty($arrayfields['cf.multicurrency_code']['checked'])) {
  1247. // Currency
  1248. print '<td class="liste_titre">';
  1249. print $form->selectMultiCurrency($search_multicurrency_code, 'search_multicurrency_code', 1);
  1250. print '</td>';
  1251. }
  1252. if (!empty($arrayfields['cf.multicurrency_tx']['checked'])) {
  1253. // Currency rate
  1254. print '<td class="liste_titre">';
  1255. print '<input class="flat" type="text" size="4" name="search_multicurrency_tx" value="'.dol_escape_htmltag($search_multicurrency_tx).'">';
  1256. print '</td>';
  1257. }
  1258. if (!empty($arrayfields['cf.multicurrency_total_ht']['checked'])) {
  1259. // Amount
  1260. print '<td class="liste_titre right">';
  1261. print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_ht" value="'.dol_escape_htmltag($search_multicurrency_montant_ht).'">';
  1262. print '</td>';
  1263. }
  1264. if (!empty($arrayfields['cf.multicurrency_total_tva']['checked'])) {
  1265. // Amount
  1266. print '<td class="liste_titre right">';
  1267. print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_tva" value="'.dol_escape_htmltag($search_multicurrency_montant_tva).'">';
  1268. print '</td>';
  1269. }
  1270. if (!empty($arrayfields['cf.multicurrency_total_ttc']['checked'])) {
  1271. // Amount
  1272. print '<td class="liste_titre right">';
  1273. print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_ttc" value="'.dol_escape_htmltag($search_multicurrency_montant_ttc).'">';
  1274. print '</td>';
  1275. }
  1276. // Extra fields
  1277. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  1278. // Fields from hook
  1279. $parameters = array('arrayfields'=>$arrayfields);
  1280. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
  1281. print $hookmanager->resPrint;
  1282. // Date creation
  1283. if (!empty($arrayfields['cf.date_creation']['checked'])) {
  1284. print '<td class="liste_titre">';
  1285. print '</td>';
  1286. }
  1287. // Date modification
  1288. if (!empty($arrayfields['cf.tms']['checked'])) {
  1289. print '<td class="liste_titre">';
  1290. print '</td>';
  1291. }
  1292. // Status
  1293. if (!empty($arrayfields['cf.fk_statut']['checked'])) {
  1294. print '<td class="liste_titre right">';
  1295. $formorder->selectSupplierOrderStatus($search_status, 1, 'search_status');
  1296. print '</td>';
  1297. }
  1298. // Status billed
  1299. if (!empty($arrayfields['cf.billed']['checked'])) {
  1300. print '<td class="liste_titre center">';
  1301. print $form->selectyesno('search_billed', $search_billed, 1, 0, 1, 1);
  1302. print '</td>';
  1303. }
  1304. // Date valid
  1305. if (!empty($arrayfields['cf.date_valid']['checked'])) {
  1306. print '<td class="liste_titre center">';
  1307. print '<div class="nowrap">';
  1308. print $form->selectDate($search_date_valid_start ? $search_date_valid_start : -1, 'search_date_valid_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  1309. print '</div>';
  1310. print '<div class="nowrap">';
  1311. print $form->selectDate($search_date_valid_end ? $search_date_valid_end : -1, 'search_date_valid_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  1312. print '</div>';
  1313. print '</td>';
  1314. }
  1315. // Date approve
  1316. if (!empty($arrayfields['cf.date_approve']['checked'])) {
  1317. print '<td class="liste_titre center">';
  1318. print '<div class="nowrap">';
  1319. print $form->selectDate($search_date_approve_start ? $search_date_approve_start : -1, 'search_date_approve_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  1320. print '</div>';
  1321. print '<div class="nowrap">';
  1322. print $form->selectDate($search_date_approve_end ? $search_date_approve_end : -1, 'search_date_approve_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  1323. print '</div>';
  1324. print '</td>';
  1325. }
  1326. // Action column
  1327. print '<td class="liste_titre middle">';
  1328. $searchpicto = $form->showFilterButtons();
  1329. print $searchpicto;
  1330. print '</td>';
  1331. print "</tr>\n";
  1332. // Fields title
  1333. print '<tr class="liste_titre">';
  1334. if (!empty($arrayfields['cf.ref']['checked'])) {
  1335. print_liste_field_titre($arrayfields['cf.ref']['label'], $_SERVER["PHP_SELF"], "cf.ref", "", $param, '', $sortfield, $sortorder);
  1336. }
  1337. if (!empty($arrayfields['cf.ref_supplier']['checked'])) {
  1338. print_liste_field_titre($arrayfields['cf.ref_supplier']['label'], $_SERVER["PHP_SELF"], "cf.ref_supplier", "", $param, '', $sortfield, $sortorder, 'tdoverflowmax100imp ');
  1339. }
  1340. if (!empty($arrayfields['cf.fk_projet']['checked'])) {
  1341. print_liste_field_titre($arrayfields['cf.fk_projet']['label'], $_SERVER["PHP_SELF"], "p.ref", "", $param, '', $sortfield, $sortorder);
  1342. }
  1343. if (!empty($arrayfields['u.login']['checked'])) {
  1344. print_liste_field_titre($arrayfields['u.login']['label'], $_SERVER["PHP_SELF"], "u.login", "", $param, '', $sortfield, $sortorder);
  1345. }
  1346. if (!empty($arrayfields['cf.fk_soc']['checked'])) {
  1347. print_liste_field_titre($arrayfields['cf.fk_soc']['label'], $_SERVER["PHP_SELF"], "s.nom", "", $param, '', $sortfield, $sortorder);
  1348. }
  1349. if (!empty($arrayfields['s.town']['checked'])) {
  1350. print_liste_field_titre($arrayfields['s.town']['label'], $_SERVER["PHP_SELF"], 's.town', '', $param, '', $sortfield, $sortorder);
  1351. }
  1352. if (!empty($arrayfields['s.zip']['checked'])) {
  1353. print_liste_field_titre($arrayfields['s.zip']['label'], $_SERVER["PHP_SELF"], 's.zip', '', $param, '', $sortfield, $sortorder);
  1354. }
  1355. if (!empty($arrayfields['state.nom']['checked'])) {
  1356. print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder);
  1357. }
  1358. if (!empty($arrayfields['country.code_iso']['checked'])) {
  1359. print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, '', $sortfield, $sortorder, 'center ');
  1360. }
  1361. if (!empty($arrayfields['typent.code']['checked'])) {
  1362. print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, '', $sortfield, $sortorder, 'center ');
  1363. }
  1364. if (!empty($arrayfields['cf.fk_author']['checked'])) {
  1365. print_liste_field_titre($arrayfields['cf.fk_author']['label'], $_SERVER["PHP_SELF"], "cf.fk_author", "", $param, '', $sortfield, $sortorder);
  1366. }
  1367. if (!empty($arrayfields['cf.date_commande']['checked'])) {
  1368. print_liste_field_titre($arrayfields['cf.date_commande']['label'], $_SERVER["PHP_SELF"], "cf.date_commande", "", $param, '', $sortfield, $sortorder, 'center ');
  1369. }
  1370. if (!empty($arrayfields['cf.date_livraison']['checked'])) {
  1371. print_liste_field_titre($arrayfields['cf.date_livraison']['label'], $_SERVER["PHP_SELF"], 'cf.date_livraison', '', $param, '', $sortfield, $sortorder, 'center ');
  1372. }
  1373. if (!empty($arrayfields['cf.total_ht']['checked'])) {
  1374. print_liste_field_titre($arrayfields['cf.total_ht']['label'], $_SERVER["PHP_SELF"], "cf.total_ht", "", $param, '', $sortfield, $sortorder, 'right ');
  1375. }
  1376. if (!empty($arrayfields['cf.total_tva']['checked'])) {
  1377. print_liste_field_titre($arrayfields['cf.total_tva']['label'], $_SERVER["PHP_SELF"], "cf.total_tva", "", $param, '', $sortfield, $sortorder, 'right ');
  1378. }
  1379. if (!empty($arrayfields['cf.total_ttc']['checked'])) {
  1380. print_liste_field_titre($arrayfields['cf.total_ttc']['label'], $_SERVER["PHP_SELF"], "cf.total_ttc", "", $param, '', $sortfield, $sortorder, 'right ');
  1381. }
  1382. if (!empty($arrayfields['cf.multicurrency_code']['checked'])) {
  1383. print_liste_field_titre($arrayfields['cf.multicurrency_code']['label'], $_SERVER['PHP_SELF'], 'cf.multicurrency_code', '', $param, '', $sortfield, $sortorder);
  1384. }
  1385. if (!empty($arrayfields['cf.multicurrency_tx']['checked'])) {
  1386. print_liste_field_titre($arrayfields['cf.multicurrency_tx']['label'], $_SERVER['PHP_SELF'], 'cf.multicurrency_tx', '', $param, '', $sortfield, $sortorder);
  1387. }
  1388. if (!empty($arrayfields['cf.multicurrency_total_ht']['checked'])) {
  1389. print_liste_field_titre($arrayfields['cf.multicurrency_total_ht']['label'], $_SERVER['PHP_SELF'], 'cf.multicurrency_total_ht', '', $param, 'class="right"', $sortfield, $sortorder);
  1390. }
  1391. if (!empty($arrayfields['cf.multicurrency_total_tva']['checked'])) {
  1392. print_liste_field_titre($arrayfields['cf.multicurrency_total_tva']['label'], $_SERVER['PHP_SELF'], 'cf.multicurrency_total_tva', '', $param, 'class="right"', $sortfield, $sortorder);
  1393. }
  1394. if (!empty($arrayfields['cf.multicurrency_total_ttc']['checked'])) {
  1395. print_liste_field_titre($arrayfields['cf.multicurrency_total_ttc']['label'], $_SERVER['PHP_SELF'], 'cf.multicurrency_total_ttc', '', $param, 'class="right"', $sortfield, $sortorder);
  1396. }
  1397. // Extra fields
  1398. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  1399. // Hook fields
  1400. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
  1401. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
  1402. print $hookmanager->resPrint;
  1403. if (!empty($arrayfields['cf.date_creation']['checked'])) {
  1404. print_liste_field_titre($arrayfields['cf.date_creation']['label'], $_SERVER["PHP_SELF"], "cf.date_creation", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  1405. }
  1406. if (!empty($arrayfields['cf.tms']['checked'])) {
  1407. print_liste_field_titre($arrayfields['cf.tms']['label'], $_SERVER["PHP_SELF"], "cf.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  1408. }
  1409. if (!empty($arrayfields['cf.fk_statut']['checked'])) {
  1410. print_liste_field_titre($arrayfields['cf.fk_statut']['label'], $_SERVER["PHP_SELF"], "cf.fk_statut", "", $param, '', $sortfield, $sortorder, 'right ');
  1411. }
  1412. if (!empty($arrayfields['cf.billed']['checked'])) {
  1413. print_liste_field_titre($arrayfields['cf.billed']['label'], $_SERVER["PHP_SELF"], 'cf.billed', '', $param, '', $sortfield, $sortorder, 'center ');
  1414. }
  1415. if (!empty($arrayfields['cf.date_valid']['checked'])) {
  1416. print_liste_field_titre($arrayfields['cf.date_valid']['label'], $_SERVER["PHP_SELF"], "cf.date_valid", "", $param, '', $sortfield, $sortorder, 'center ');
  1417. }
  1418. if (!empty($arrayfields['cf.date_approve']['checked'])) {
  1419. print_liste_field_titre($arrayfields['cf.date_approve']['label'], $_SERVER["PHP_SELF"], 'cf.date_approve', '', $param, '', $sortfield, $sortorder, 'center ');
  1420. }
  1421. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
  1422. print "</tr>\n";
  1423. $total = 0;
  1424. $subtotal = 0;
  1425. $productstat_cache = array();
  1426. $userstatic = new User($db);
  1427. $objectstatic = new CommandeFournisseur($db);
  1428. $projectstatic = new Project($db);
  1429. $i = 0;
  1430. $totalarray = array('nbfield' => 0, 'val' => array(), 'pos' => array());
  1431. $totalarray['val']['cf.total_ht'] = 0;
  1432. $totalarray['val']['cf.total_ttc'] = 0;
  1433. while ($i < min($num, $limit)) {
  1434. $obj = $db->fetch_object($resql);
  1435. $notshippable = 0;
  1436. $warning = 0;
  1437. $text_info = '';
  1438. $text_warning = '';
  1439. $nbprod = 0;
  1440. $objectstatic->id = $obj->rowid;
  1441. $objectstatic->ref = $obj->ref;
  1442. $objectstatic->socid = $obj->socid;
  1443. $objectstatic->ref_supplier = $obj->ref_supplier;
  1444. $objectstatic->socid = $obj->socid;
  1445. $objectstatic->total_ht = $obj->total_ht;
  1446. $objectstatic->total_tva = $obj->total_tva;
  1447. $objectstatic->total_ttc = $obj->total_ttc;
  1448. $objectstatic->date_commande = $db->jdate($obj->date_commande);
  1449. $objectstatic->delivery_date = $db->jdate($obj->date_livraison);
  1450. $objectstatic->note_public = $obj->note_public;
  1451. $objectstatic->note_private = $obj->note_private;
  1452. $objectstatic->statut = $obj->fk_statut;
  1453. print '<tr class="oddeven">';
  1454. // Ref
  1455. if (!empty($arrayfields['cf.ref']['checked'])) {
  1456. print '<td class="nowrap">';
  1457. // Picto + Ref
  1458. print $objectstatic->getNomUrl(1, '', 0, -1, 1);
  1459. // Other picto tool
  1460. $filename = dol_sanitizeFileName($obj->ref);
  1461. $filedir = $conf->fournisseur->commande->dir_output.'/'.dol_sanitizeFileName($obj->ref);
  1462. print $formfile->getDocumentsLink($objectstatic->element, $filename, $filedir);
  1463. print '</td>'."\n";
  1464. if (!$i) {
  1465. $totalarray['nbfield']++;
  1466. }
  1467. }
  1468. // Ref Supplier
  1469. if (!empty($arrayfields['cf.ref_supplier']['checked'])) {
  1470. print '<td>'.$obj->ref_supplier.'</td>'."\n";
  1471. if (!$i) {
  1472. $totalarray['nbfield']++;
  1473. }
  1474. }
  1475. // Project
  1476. if (!empty($arrayfields['cf.fk_projet']['checked'])) {
  1477. $projectstatic->id = $obj->project_id;
  1478. $projectstatic->ref = $obj->project_ref;
  1479. $projectstatic->title = $obj->project_title;
  1480. print '<td>';
  1481. if ($obj->project_id > 0) {
  1482. print $projectstatic->getNomUrl(1);
  1483. }
  1484. print '</td>';
  1485. if (!$i) {
  1486. $totalarray['nbfield']++;
  1487. }
  1488. }
  1489. // Author
  1490. $userstatic->id = $obj->fk_user_author;
  1491. $userstatic->lastname = $obj->lastname;
  1492. $userstatic->firstname = $obj->firstname;
  1493. $userstatic->login = $obj->login;
  1494. $userstatic->photo = $obj->photo;
  1495. $userstatic->email = $obj->user_email;
  1496. $userstatic->statut = $obj->user_status;
  1497. if (!empty($arrayfields['u.login']['checked'])) {
  1498. print '<td class="tdoverflowmax150">';
  1499. if ($userstatic->id) {
  1500. print $userstatic->getNomUrl(1);
  1501. }
  1502. print "</td>";
  1503. if (!$i) {
  1504. $totalarray['nbfield']++;
  1505. }
  1506. }
  1507. // Thirdparty
  1508. if (!empty($arrayfields['cf.fk_soc']['checked'])) {
  1509. print '<td class="tdoverflowmax150">';
  1510. $thirdpartytmp->id = $obj->socid;
  1511. $thirdpartytmp->name = $obj->name;
  1512. $thirdpartytmp->email = $obj->email;
  1513. print $thirdpartytmp->getNomUrl(1, 'supplier');
  1514. print '</td>'."\n";
  1515. if (!$i) {
  1516. $totalarray['nbfield']++;
  1517. }
  1518. }
  1519. // Town
  1520. if (!empty($arrayfields['s.town']['checked'])) {
  1521. print '<td>';
  1522. print $obj->town;
  1523. print '</td>';
  1524. if (!$i) {
  1525. $totalarray['nbfield']++;
  1526. }
  1527. }
  1528. // Zip
  1529. if (!empty($arrayfields['s.zip']['checked'])) {
  1530. print '<td>';
  1531. print $obj->zip;
  1532. print '</td>';
  1533. if (!$i) {
  1534. $totalarray['nbfield']++;
  1535. }
  1536. }
  1537. // State
  1538. if (!empty($arrayfields['state.nom']['checked'])) {
  1539. print "<td>".$obj->state_name."</td>\n";
  1540. if (!$i) {
  1541. $totalarray['nbfield']++;
  1542. }
  1543. }
  1544. // Country
  1545. if (!empty($arrayfields['country.code_iso']['checked'])) {
  1546. print '<td class="center">';
  1547. $tmparray = getCountry($obj->fk_pays, 'all');
  1548. print $tmparray['label'];
  1549. print '</td>';
  1550. if (!$i) {
  1551. $totalarray['nbfield']++;
  1552. }
  1553. }
  1554. // Type ent
  1555. if (!empty($arrayfields['typent.code']['checked'])) {
  1556. print '<td class="center">';
  1557. if (empty($typenArray)) {
  1558. $typenArray = $formcompany->typent_array(1);
  1559. }
  1560. print $typenArray[$obj->typent_code];
  1561. print '</td>';
  1562. if (!$i) {
  1563. $totalarray['nbfield']++;
  1564. }
  1565. }
  1566. // Order date
  1567. if (!empty($arrayfields['cf.date_commande']['checked'])) {
  1568. print '<td class="center">';
  1569. print dol_print_date($db->jdate($obj->date_commande), 'day');
  1570. if ($objectstatic->statut != $objectstatic::STATUS_ORDERSENT && $objectstatic->statut != $objectstatic::STATUS_RECEIVED_PARTIALLY) {
  1571. if ($objectstatic->hasDelay()) {
  1572. print ' '.img_picto($langs->trans("Late").' : '.$objectstatic->showDelay(), "warning");
  1573. }
  1574. }
  1575. print '</td>';
  1576. if (!$i) {
  1577. $totalarray['nbfield']++;
  1578. }
  1579. }
  1580. // Plannned date of delivery
  1581. if (!empty($arrayfields['cf.date_livraison']['checked'])) {
  1582. print '<td class="center">';
  1583. print dol_print_date($db->jdate($obj->date_livraison), 'day');
  1584. if ($objectstatic->statut == $objectstatic::STATUS_ORDERSENT || $objectstatic->statut == $objectstatic::STATUS_RECEIVED_PARTIALLY) {
  1585. if ($objectstatic->hasDelay()) {
  1586. print ' '.img_picto($langs->trans("Late").' : '.$objectstatic->showDelay(), "warning");
  1587. }
  1588. }
  1589. print '</td>';
  1590. if (!$i) {
  1591. $totalarray['nbfield']++;
  1592. }
  1593. }
  1594. // Amount HT
  1595. if (!empty($arrayfields['cf.total_ht']['checked'])) {
  1596. print '<td class="right"><span class="amount">'.price($obj->total_ht)."</span></td>\n";
  1597. if (!$i) {
  1598. $totalarray['nbfield']++;
  1599. }
  1600. if (!$i) {
  1601. $totalarray['pos'][$totalarray['nbfield']] = 'cf.total_ht';
  1602. }
  1603. $totalarray['val']['cf.total_ht'] += $obj->total_ht;
  1604. }
  1605. // Amount VAT
  1606. if (!empty($arrayfields['cf.total_tva']['checked'])) {
  1607. print '<td class="right"><span class="amount">'.price($obj->total_tva)."</span></td>\n";
  1608. if (!$i) {
  1609. $totalarray['nbfield']++;
  1610. }
  1611. if (!$i) {
  1612. $totalarray['pos'][$totalarray['nbfield']] = 'cf.total_tva';
  1613. }
  1614. $totalarray['val']['cf.total_tva'] += $obj->total_tva;
  1615. }
  1616. // Amount TTC
  1617. if (!empty($arrayfields['cf.total_ttc']['checked'])) {
  1618. print '<td class="right"><span class="amount">'.price($obj->total_ttc)."</span></td>\n";
  1619. if (!$i) {
  1620. $totalarray['nbfield']++;
  1621. }
  1622. if (!$i) {
  1623. $totalarray['pos'][$totalarray['nbfield']] = 'cf.total_ttc';
  1624. }
  1625. $totalarray['val']['cf.total_ttc'] += $obj->total_ttc;
  1626. }
  1627. // Currency
  1628. if (!empty($arrayfields['cf.multicurrency_code']['checked'])) {
  1629. print '<td class="nowrap">'.$obj->multicurrency_code.' - '.$langs->trans('Currency'.$obj->multicurrency_code)."</td>\n";
  1630. if (!$i) {
  1631. $totalarray['nbfield']++;
  1632. }
  1633. }
  1634. // Currency rate
  1635. if (!empty($arrayfields['cf.multicurrency_tx']['checked'])) {
  1636. print '<td class="nowrap">';
  1637. $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$obj->rowid, $obj->multicurrency_tx, 'none', $obj->multicurrency_code);
  1638. print "</td>\n";
  1639. if (!$i) {
  1640. $totalarray['nbfield']++;
  1641. }
  1642. }
  1643. // Amount HT
  1644. if (!empty($arrayfields['cf.multicurrency_total_ht']['checked'])) {
  1645. print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_ht)."</span></td>\n";
  1646. if (!$i) {
  1647. $totalarray['nbfield']++;
  1648. }
  1649. }
  1650. // Amount VAT
  1651. if (!empty($arrayfields['cf.multicurrency_total_tva']['checked'])) {
  1652. print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_tva)."</span></td>\n";
  1653. if (!$i) {
  1654. $totalarray['nbfield']++;
  1655. }
  1656. }
  1657. // Amount TTC
  1658. if (!empty($arrayfields['cf.multicurrency_total_ttc']['checked'])) {
  1659. print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_ttc)."</span></td>\n";
  1660. if (!$i) {
  1661. $totalarray['nbfield']++;
  1662. }
  1663. }
  1664. // Extra fields
  1665. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  1666. // Fields from hook
  1667. $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  1668. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
  1669. print $hookmanager->resPrint;
  1670. // Date creation
  1671. if (!empty($arrayfields['cf.date_creation']['checked'])) {
  1672. print '<td class="center nowrap">';
  1673. print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
  1674. print '</td>';
  1675. if (!$i) {
  1676. $totalarray['nbfield']++;
  1677. }
  1678. }
  1679. // Date modification
  1680. if (!empty($arrayfields['cf.tms']['checked'])) {
  1681. print '<td class="center nowrap">';
  1682. print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser');
  1683. print '</td>';
  1684. if (!$i) {
  1685. $totalarray['nbfield']++;
  1686. }
  1687. }
  1688. // Status
  1689. if (!empty($arrayfields['cf.fk_statut']['checked'])) {
  1690. print '<td class="right nowrap">'.$objectstatic->LibStatut($obj->fk_statut, 5, $obj->billed).'</td>';
  1691. if (!$i) {
  1692. $totalarray['nbfield']++;
  1693. }
  1694. }
  1695. // Billed
  1696. if (!empty($arrayfields['cf.billed']['checked'])) {
  1697. print '<td class="center">'.yn($obj->billed).'</td>';
  1698. if (!$i) {
  1699. $totalarray['nbfield']++;
  1700. }
  1701. }
  1702. // valid date
  1703. if (!empty($arrayfields['cf.date_valid']['checked'])) {
  1704. print '<td class="center">';
  1705. print dol_print_date($db->jdate($obj->date_valid), 'day');
  1706. print '</td>';
  1707. if (!$i) {
  1708. $totalarray['nbfield']++;
  1709. }
  1710. }
  1711. // approve date
  1712. if (!empty($arrayfields['cf.date_approve']['checked'])) {
  1713. print '<td class="center">';
  1714. print dol_print_date($db->jdate($obj->date_approve), 'day');
  1715. print '</td>';
  1716. if (!$i) {
  1717. $totalarray['nbfield']++;
  1718. }
  1719. }
  1720. // Action column
  1721. print '<td class="nowrap center">';
  1722. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  1723. $selected = 0;
  1724. if (in_array($obj->rowid, $arrayofselected)) {
  1725. $selected = 1;
  1726. }
  1727. print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
  1728. }
  1729. print '</td>';
  1730. if (!$i) {
  1731. $totalarray['nbfield']++;
  1732. }
  1733. print "</tr>\n";
  1734. $total += $obj->total_ht;
  1735. $subtotal += $obj->total_ht;
  1736. $i++;
  1737. }
  1738. // Show total line
  1739. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  1740. $db->free($resql);
  1741. $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  1742. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters); // Note that $action and $object may have been modified by hook
  1743. print $hookmanager->resPrint;
  1744. print '</table>'."\n";
  1745. print '</div>';
  1746. print '</form>'."\n";
  1747. $hidegeneratedfilelistifempty = 1;
  1748. if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
  1749. $hidegeneratedfilelistifempty = 0;
  1750. }
  1751. // Show list of available documents
  1752. $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
  1753. $urlsource .= str_replace('&amp;', '&', $param);
  1754. $filedir = $diroutputmassaction;
  1755. $genallowed = ($user->rights->fournisseur->commande->lire || $user->rights->supplier_order->lire);
  1756. $delallowed = ($user->rights->fournisseur->commande->creer || $user->rights->supplier_order->creer);
  1757. print $formfile->showdocuments('massfilesarea_supplier_order', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
  1758. } else {
  1759. dol_print_error($db);
  1760. }
  1761. // End of page
  1762. llxFooter();
  1763. $db->close();