list.php 74 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784
  1. <?php
  2. /* Copyright (C) 2002-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2019 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2013 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2013-2019 Philippe Grand <philippe.grand@atoo-net.com>
  6. * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
  7. * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
  8. * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
  9. * Copyright (C) 2015-2007 Juanjo Menent <jmenent@2byte.es>
  10. * Copyright (C) 2015 Abbes Bahfir <bafbes@gmail.com>
  11. * Copyright (C) 2015-2016 Ferran Marcet <fmarcet@2byte.es>
  12. * Copyright (C) 2017 Josep Lluís Amador <joseplluis@lliuretic.cat>
  13. * Copyright (C) 2018 Charlene Benke <charlie@patas-monkey.com>
  14. * Copyright (C) 2018-2020 Frédéric France <frederic.france@netlogic.fr>
  15. * Copyright (C) 2019-2021 Alexandre Spangaro <aspangaro@open-dsi.fr>
  16. *
  17. * This program is free software; you can redistribute it and/or modify
  18. * it under the terms of the GNU General Public License as published by
  19. * the Free Software Foundation; either version 3 of the License, or
  20. * (at your option) any later version.
  21. *
  22. * This program is distributed in the hope that it will be useful,
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. * GNU General Public License for more details.
  26. *
  27. * You should have received a copy of the GNU General Public License
  28. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  29. */
  30. /**
  31. * \file htdocs/fourn/facture/list.php
  32. * \ingroup fournisseur,facture
  33. * \brief List of suppliers invoices
  34. */
  35. require '../../main.inc.php';
  36. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  37. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  38. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  39. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  40. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
  41. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
  42. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  43. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  44. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  45. // Load translation files required by the page
  46. $langs->loadLangs(array('products', 'bills', 'companies', 'projects'));
  47. $action = GETPOST('action', 'aZ09');
  48. $massaction = GETPOST('massaction', 'alpha');
  49. $show_files = GETPOST('show_files', 'int');
  50. $confirm = GETPOST('confirm', 'alpha');
  51. $toselect = GETPOST('toselect', 'array');
  52. $optioncss = GETPOST('optioncss', 'alpha');
  53. $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'supplierinvoicelist';
  54. $socid = GETPOST('socid', 'int');
  55. // Security check
  56. if ($user->socid > 0) {
  57. $action = '';
  58. $_GET["action"] = '';
  59. $socid = $user->socid;
  60. }
  61. $mode = GETPOST("mode", 'aZ09');
  62. $search_all = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
  63. $search_label = GETPOST("search_label", "alpha");
  64. $search_amount_no_tax = GETPOST("search_amount_no_tax", "alpha");
  65. $search_amount_all_tax = GETPOST("search_amount_all_tax", "alpha");
  66. $search_product_category = GETPOST('search_product_category', 'int');
  67. $search_ref = GETPOST('sf_ref') ?GETPOST('sf_ref', 'alpha') : GETPOST('search_ref', 'alpha');
  68. $search_refsupplier = GETPOST('search_refsupplier', 'alpha');
  69. $search_type = GETPOST('search_type', 'int');
  70. $search_project = GETPOST('search_project', 'alpha');
  71. $search_company = GETPOST('search_company', 'alpha');
  72. $search_montant_ht = GETPOST('search_montant_ht', 'alpha');
  73. $search_montant_vat = GETPOST('search_montant_vat', 'alpha');
  74. $search_montant_localtax1 = GETPOST('search_montant_localtax1', 'alpha');
  75. $search_montant_localtax2 = GETPOST('search_montant_localtax2', 'alpha');
  76. $search_montant_ttc = GETPOST('search_montant_ttc', 'alpha');
  77. $search_login = GETPOST('search_login', 'alpha');
  78. $search_multicurrency_code = GETPOST('search_multicurrency_code', 'alpha');
  79. $search_multicurrency_tx = GETPOST('search_multicurrency_tx', 'alpha');
  80. $search_multicurrency_montant_ht = GETPOST('search_multicurrency_montant_ht', 'alpha');
  81. $search_multicurrency_montant_vat = GETPOST('search_multicurrency_montant_vat', 'alpha');
  82. $search_multicurrency_montant_ttc = GETPOST('search_multicurrency_montant_ttc', 'alpha');
  83. $search_status = GETPOST('search_status', 'int');
  84. $search_paymentmode = GETPOST('search_paymentmode', 'int');
  85. $search_paymentcond = GETPOST('search_paymentcond', 'int');
  86. $search_town = GETPOST('search_town', 'alpha');
  87. $search_zip = GETPOST('search_zip', 'alpha');
  88. $search_state = GETPOST("search_state");
  89. $search_country = GETPOST("search_country", 'int');
  90. $search_type_thirdparty = GETPOST("search_type_thirdparty", 'int');
  91. $search_user = GETPOST('search_user', 'int');
  92. $search_sale = GETPOST('search_sale', 'int');
  93. $search_date_startday = GETPOST('search_date_startday', 'int');
  94. $search_date_startmonth = GETPOST('search_date_startmonth', 'int');
  95. $search_date_startyear = GETPOST('search_date_startyear', 'int');
  96. $search_date_endday = GETPOST('search_date_endday', 'int');
  97. $search_date_endmonth = GETPOST('search_date_endmonth', 'int');
  98. $search_date_endyear = GETPOST('search_date_endyear', 'int');
  99. $search_date_start = dol_mktime(0, 0, 0, $search_date_startmonth, $search_date_startday, $search_date_startyear); // Use tzserver
  100. $search_date_end = dol_mktime(23, 59, 59, $search_date_endmonth, $search_date_endday, $search_date_endyear);
  101. $search_datelimit_startday = GETPOST('search_datelimit_startday', 'int');
  102. $search_datelimit_startmonth = GETPOST('search_datelimit_startmonth', 'int');
  103. $search_datelimit_startyear = GETPOST('search_datelimit_startyear', 'int');
  104. $search_datelimit_endday = GETPOST('search_datelimit_endday', 'int');
  105. $search_datelimit_endmonth = GETPOST('search_datelimit_endmonth', 'int');
  106. $search_datelimit_endyear = GETPOST('search_datelimit_endyear', 'int');
  107. $search_datelimit_start = dol_mktime(0, 0, 0, $search_datelimit_startmonth, $search_datelimit_startday, $search_datelimit_startyear);
  108. $search_datelimit_end = dol_mktime(23, 59, 59, $search_datelimit_endmonth, $search_datelimit_endday, $search_datelimit_endyear);
  109. $toselect = GETPOST('toselect', 'array');
  110. $search_btn = GETPOST('button_search', 'alpha');
  111. $search_remove_btn = GETPOST('button_removefilter', 'alpha');
  112. $search_categ_sup = trim(GETPOST("search_categ_sup", 'int'));
  113. $option = GETPOST('search_option');
  114. if ($option == 'late') {
  115. $search_status = '1';
  116. }
  117. $filter = GETPOST('filtre', 'alpha');
  118. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  119. $sortfield = GETPOST('sortfield', 'aZ09comma');
  120. $sortorder = GETPOST('sortorder', 'aZ09comma');
  121. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  122. if ($page == -1 || $page == null || !empty($search_btn) || !empty($search_remove_btn) || (empty($toselect) && $massaction === '0')) {
  123. $page = 0;
  124. }
  125. $offset = $limit * $page;
  126. $pageprev = $page - 1;
  127. $pagenext = $page + 1;
  128. if (!$sortorder) {
  129. $sortorder = "DESC";
  130. }
  131. if (!$sortfield) {
  132. $sortfield = "f.datef,f.rowid";
  133. }
  134. $diroutputmassaction = $conf->fournisseur->facture->dir_output.'/temp/massgeneration/'.$user->id;
  135. $now = dol_now();
  136. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  137. $object = new FactureFournisseur($db);
  138. $hookmanager->initHooks(array('supplierinvoicelist'));
  139. $extrafields = new ExtraFields($db);
  140. // fetch optionals attributes and labels
  141. $extrafields->fetch_name_optionals_label($object->table_element);
  142. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  143. // List of fields to search into when doing a "search in all"
  144. $fieldstosearchall = array(
  145. 'f.ref'=>'Ref',
  146. 'f.ref_supplier'=>'RefSupplier',
  147. 'pd.description'=>'Description',
  148. 's.nom'=>"ThirdParty",
  149. 'f.note_public'=>'NotePublic',
  150. );
  151. if (empty($user->socid)) {
  152. $fieldstosearchall["f.note_private"] = "NotePrivate";
  153. }
  154. $checkedtypetiers = 0;
  155. $arrayfields = array(
  156. 'f.ref'=>array('label'=>"Ref", 'checked'=>1),
  157. 'f.ref_supplier'=>array('label'=>"RefSupplier", 'checked'=>1),
  158. 'f.type'=>array('label'=>"Type", 'checked'=>0),
  159. 'f.label'=>array('label'=>"Label", 'checked'=>0),
  160. 'f.datef'=>array('label'=>"DateInvoice", 'checked'=>1),
  161. 'f.date_lim_reglement'=>array('label'=>"DateDue", 'checked'=>1),
  162. 'p.ref'=>array('label'=>"ProjectRef", 'checked'=>0),
  163. 's.nom'=>array('label'=>"ThirdParty", 'checked'=>1),
  164. 's.town'=>array('label'=>"Town", 'checked'=>-1),
  165. 's.zip'=>array('label'=>"Zip", 'checked'=>1),
  166. 'state.nom'=>array('label'=>"StateShort", 'checked'=>0),
  167. 'country.code_iso'=>array('label'=>"Country", 'checked'=>0),
  168. 'typent.code'=>array('label'=>"ThirdPartyType", 'checked'=>$checkedtypetiers),
  169. 'f.fk_cond_reglement'=>array('label'=>"PaymentTerm", 'checked'=>1, 'position'=>50),
  170. 'f.fk_mode_reglement'=>array('label'=>"PaymentMode", 'checked'=>1, 'position'=>52),
  171. 'f.total_ht'=>array('label'=>"AmountHT", 'checked'=>1, 'position'=>105),
  172. 'f.total_vat'=>array('label'=>"AmountVAT", 'checked'=>0, 'position'=>110),
  173. 'f.total_localtax1'=>array('label'=>$langs->transcountry("AmountLT1", $mysoc->country_code), 'checked'=>0, 'enabled'=>$mysoc->localtax1_assuj == "1", 'position'=>95),
  174. 'f.total_localtax2'=>array('label'=>$langs->transcountry("AmountLT2", $mysoc->country_code), 'checked'=>0, 'enabled'=>$mysoc->localtax2_assuj == "1", 'position'=>100),
  175. 'f.total_ttc'=>array('label'=>"AmountTTC", 'checked'=>0, 'position'=>115),
  176. 'u.login'=>array('label'=>"Author", 'checked'=>1),
  177. 'dynamount_payed'=>array('label'=>"Paid", 'checked'=>0),
  178. 'rtp'=>array('label'=>"Rest", 'checked'=>0),
  179. 'f.multicurrency_code'=>array('label'=>'Currency', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1)),
  180. 'f.multicurrency_tx'=>array('label'=>'CurrencyRate', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1)),
  181. 'f.multicurrency_total_ht'=>array('label'=>'MulticurrencyAmountHT', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1)),
  182. 'f.multicurrency_total_vat'=>array('label'=>'MulticurrencyAmountVAT', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1)),
  183. 'f.multicurrency_total_ttc'=>array('label'=>'MulticurrencyAmountTTC', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1)),
  184. 'multicurrency_dynamount_payed'=>array('label'=>'MulticurrencyAlreadyPaid', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1)),
  185. 'multicurrency_rtp'=>array('label'=>'MulticurrencyRemainderToPay', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1)), // Not enabled by default because slow
  186. 'f.datec'=>array('label'=>"DateCreation", 'checked'=>0, 'position'=>500),
  187. 'f.tms'=>array('label'=>"DateModificationShort", 'checked'=>0, 'position'=>500),
  188. 'f.fk_statut'=>array('label'=>"Status", 'checked'=>1, 'position'=>1000),
  189. );
  190. // Extra fields
  191. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
  192. $object->fields = dol_sort_array($object->fields, 'position');
  193. $arrayfields = dol_sort_array($arrayfields, 'position');
  194. if ((empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD))
  195. || (empty($conf->supplier_invoice->enabled) && !empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD))) {
  196. accessforbidden();
  197. }
  198. if ((empty($user->rights->fournisseur->facture->lire) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD))
  199. || (empty($user->rights->supplier_invoice->lire) && !empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD))) {
  200. accessforbidden();
  201. }
  202. /*
  203. * Actions
  204. */
  205. if (GETPOST('cancel', 'alpha')) {
  206. $action = 'list'; $massaction = '';
  207. }
  208. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend' && $massaction != 'confirm_createbills') {
  209. $massaction = '';
  210. }
  211. $parameters = array('socid'=>$socid);
  212. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  213. if ($reshook < 0) {
  214. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  215. }
  216. if (empty($reshook)) {
  217. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  218. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter', 'alpha') || GETPOST('button_removefilter.x', 'alpha')) { // All tests must be present to be compatible with all browsers
  219. $search_all = "";
  220. $search_user = '';
  221. $search_sale = '';
  222. $search_product_category = '';
  223. $search_ref = "";
  224. $search_refsupplier = "";
  225. $search_type = "";
  226. $search_label = "";
  227. $search_project = '';
  228. $search_company = "";
  229. $search_amount_no_tax = "";
  230. $search_amount_all_tax = "";
  231. $search_montant_ht = '';
  232. $search_montant_vat = '';
  233. $search_montant_localtax1 = '';
  234. $search_montant_localtax2 = '';
  235. $search_montant_ttc = '';
  236. $search_login = '';
  237. $search_multicurrency_code = '';
  238. $search_multicurrency_tx = '';
  239. $search_multicurrency_montant_ht = '';
  240. $search_multicurrency_montant_vat = '';
  241. $search_multicurrency_montant_ttc = '';
  242. $search_status = '';
  243. $search_paymentmode = '';
  244. $search_paymentcond = '';
  245. $search_town = '';
  246. $search_zip = "";
  247. $search_state = "";
  248. $search_type = '';
  249. $search_country = '';
  250. $search_type_thirdparty = '';
  251. $search_date_startday = '';
  252. $search_date_startmonth = '';
  253. $search_date_startyear = '';
  254. $search_date_endday = '';
  255. $search_date_endmonth = '';
  256. $search_date_endyear = '';
  257. $search_date_start = '';
  258. $search_date_end = '';
  259. $search_datelimit_startday = '';
  260. $search_datelimit_startmonth = '';
  261. $search_datelimit_startyear = '';
  262. $search_datelimit_endday = '';
  263. $search_datelimit_endmonth = '';
  264. $search_datelimit_endyear = '';
  265. $search_datelimit_start = '';
  266. $search_datelimit_end = '';
  267. $toselect = '';
  268. $search_array_options = array();
  269. $filter = '';
  270. $option = '';
  271. $socid = "";
  272. $search_categ_sup = 0;
  273. }
  274. // Mass actions
  275. $objectclass = 'FactureFournisseur';
  276. $objectlabel = 'SupplierInvoices';
  277. $permissiontoread = ($user->rights->fournisseur->facture->lire || $user->rights->supplier_invoice->lire);
  278. $permissiontoadd = ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer);
  279. $permissiontodelete = ($user->rights->fournisseur->facture->supprimer || $user->rights->supplier_invoice->supprimer);
  280. $uploaddir = $conf->fournisseur->facture->dir_output;
  281. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  282. if ($massaction == 'banktransfertrequest') {
  283. $langs->load("withdrawals");
  284. if (!$user->rights->paymentbybanktransfer->create) {
  285. $error++;
  286. setEventMessages($langs->trans("NotEnoughPermissions"), null, 'errors');
  287. } else {
  288. //Checking error
  289. $error = 0;
  290. $arrayofselected = is_array($toselect) ? $toselect : array();
  291. $listofbills = array();
  292. foreach ($arrayofselected as $toselectid) {
  293. $objecttmp = new FactureFournisseur($db);
  294. $result = $objecttmp->fetch($toselectid);
  295. if ($result > 0) {
  296. $totalpaye = $objecttmp->getSommePaiement();
  297. $totalcreditnotes = $objecttmp->getSumCreditNotesUsed();
  298. $totaldeposits = $objecttmp->getSumDepositsUsed();
  299. $objecttmp->resteapayer = price2num($objecttmp->total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits, 'MT');
  300. if ($objecttmp->statut == FactureFournisseur::STATUS_DRAFT) {
  301. $error++;
  302. setEventMessages($objecttmp->ref.' '.$langs->trans("Draft"), $objecttmp->errors, 'errors');
  303. } elseif ($objecttmp->paye || $objecttmp->resteapayer == 0) {
  304. $error++;
  305. setEventMessages($objecttmp->ref.' '.$langs->trans("AlreadyPaid"), $objecttmp->errors, 'errors');
  306. } elseif ($objecttmp->resteapayer < 0) {
  307. $error++;
  308. setEventMessages($objecttmp->ref.' '.$langs->trans("AmountMustBePositive"), $objecttmp->errors, 'errors');
  309. }
  310. $rsql = "SELECT pfd.rowid, pfd.traite, pfd.date_demande as date_demande";
  311. $rsql .= " , pfd.date_traite as date_traite";
  312. $rsql .= " , pfd.amount";
  313. $rsql .= " , u.rowid as user_id, u.lastname, u.firstname, u.login";
  314. $rsql .= " FROM ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd";
  315. $rsql .= " , ".MAIN_DB_PREFIX."user as u";
  316. $rsql .= " WHERE fk_facture_fourn = ".((int) $objecttmp->id);
  317. $rsql .= " AND pfd.fk_user_demande = u.rowid";
  318. $rsql .= " AND pfd.traite = 0";
  319. $rsql .= " ORDER BY pfd.date_demande DESC";
  320. $result_sql = $db->query($rsql);
  321. if ($result_sql) {
  322. $numprlv = $db->num_rows($result_sql);
  323. }
  324. if ($numprlv > 0) {
  325. $error++;
  326. setEventMessages($objecttmp->ref.' '.$langs->trans("RequestAlreadyDone"), $objecttmp->errors, 'warnings');
  327. } elseif (!empty($objecttmp->mode_reglement_code) && $objecttmp->mode_reglement_code != 'VIR') {
  328. $error++;
  329. setEventMessages($objecttmp->ref.' '.$langs->trans("BadPaymentMethod"), $objecttmp->errors, 'errors');
  330. } else {
  331. $listofbills[] = $objecttmp; // $listofbills will only contains invoices with good payment method and no request already done
  332. }
  333. }
  334. }
  335. // Massive withdraw request for request with no errors
  336. if (!empty($listofbills)) {
  337. $nbwithdrawrequestok = 0;
  338. foreach ($listofbills as $aBill) {
  339. $db->begin();
  340. $result = $aBill->demande_prelevement($user, $aBill->resteapayer, 'bank-transfer', 'supplier_invoice');
  341. if ($result > 0) {
  342. $db->commit();
  343. $nbwithdrawrequestok++;
  344. } else {
  345. $db->rollback();
  346. setEventMessages($aBill->error, $aBill->errors, 'errors');
  347. }
  348. }
  349. if ($nbwithdrawrequestok > 0) {
  350. setEventMessages($langs->trans("WithdrawRequestsDone", $nbwithdrawrequestok), null, 'mesgs');
  351. }
  352. }
  353. }
  354. }
  355. }
  356. /*
  357. * View
  358. */
  359. $form = new Form($db);
  360. $formother = new FormOther($db);
  361. $formfile = new FormFile($db);
  362. $bankaccountstatic = new Account($db);
  363. $facturestatic = new FactureFournisseur($db);
  364. $formcompany = new FormCompany($db);
  365. $thirdparty = new Societe($db);
  366. // llxHeader('',$langs->trans("SuppliersInvoices"),'EN:Suppliers_Invoices|FR:FactureFournisseur|ES:Facturas_de_proveedores');
  367. $sql = "SELECT";
  368. if ($search_all || $search_product_category > 0) {
  369. $sql = 'SELECT DISTINCT';
  370. }
  371. $sql .= " f.rowid as facid, f.ref, f.ref_supplier, f.type, f.datef, f.date_lim_reglement as datelimite, f.fk_mode_reglement, f.fk_cond_reglement,";
  372. $sql .= " f.total_ht, f.total_ttc, f.total_tva as total_vat, f.paye as paye, f.fk_statut as fk_statut, f.libelle as label, f.datec as date_creation, f.tms as date_update,";
  373. $sql .= " f.localtax1 as total_localtax1, f.localtax2 as total_localtax2,";
  374. $sql .= ' f.fk_multicurrency, f.multicurrency_code, f.multicurrency_tx, f.multicurrency_total_ht, f.multicurrency_total_tva as multicurrency_total_vat, f.multicurrency_total_ttc,';
  375. $sql .= " f.note_public, f.note_private,";
  376. $sql .= " f.fk_user_author,";
  377. $sql .= " s.rowid as socid, s.nom as name, s.email, s.town, s.zip, s.fk_pays, s.client, s.fournisseur, s.code_client, s.code_fournisseur, s.code_compta as code_compta_client, s.code_compta_fournisseur,";
  378. $sql .= " typent.code as typent_code,";
  379. $sql .= " state.code_departement as state_code, state.nom as state_name,";
  380. $sql .= " country.code as country_code,";
  381. $sql .= " p.rowid as project_id, p.ref as project_ref, p.title as project_label,";
  382. $sql .= ' u.login, u.lastname, u.firstname, u.email as user_email, u.statut as user_statut, u.entity, u.photo, u.office_phone, u.office_fax, u.user_mobile, u.job, u.gender';
  383. if ($search_categ_sup && $search_categ_sup != '-1') {
  384. $sql .= ", cs.fk_categorie, cs.fk_soc";
  385. }
  386. // We need dynamount_payed to be able to sort on status (value is surely wrong because we can count several lines several times due to other left join or link with contacts. But what we need is just 0 or > 0)
  387. // TODO Better solution to be able to sort on already payed or remain to pay is to store amount_payed in a denormalized field.
  388. if (!$search_all) {
  389. $sql .= ', SUM(pf.amount) as dynamount_payed';
  390. }
  391. // Add fields from extrafields
  392. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  393. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  394. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
  395. }
  396. }
  397. // Add fields from hooks
  398. $parameters = array();
  399. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
  400. $sql .= $hookmanager->resPrint;
  401. $sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s';
  402. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
  403. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
  404. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)";
  405. if (!empty($search_categ_sup) && $search_categ_supplier != '-1') {
  406. $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_fournisseur as cs ON s.rowid = cs.fk_soc";
  407. }
  408. $sql .= ', '.MAIN_DB_PREFIX.'facture_fourn as f';
  409. if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
  410. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (f.rowid = ef.fk_object)";
  411. }
  412. if (!$search_all) {
  413. $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf ON pf.fk_facturefourn = f.rowid';
  414. }
  415. if ($search_all || $search_product_category > 0) {
  416. $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture_fourn_det as pd ON f.rowid=pd.fk_facture_fourn';
  417. }
  418. if ($search_product_category > 0) {
  419. $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=pd.fk_product';
  420. }
  421. $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user AS u ON f.fk_user_author = u.rowid';
  422. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as p ON p.rowid = f.fk_projet";
  423. // We'll need this table joined to the select in order to filter by sale
  424. if ($search_sale > 0 || (empty($user->rights->societe->client->voir) && !$socid)) {
  425. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  426. }
  427. if ($search_user > 0) {
  428. $sql .= ", ".MAIN_DB_PREFIX."element_contact as ec";
  429. $sql .= ", ".MAIN_DB_PREFIX."c_type_contact as tc";
  430. }
  431. // Add table from hooks
  432. $parameters = array();
  433. $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
  434. $sql .= $hookmanager->resPrint;
  435. $sql .= ' WHERE f.fk_soc = s.rowid';
  436. $sql .= ' AND f.entity IN ('.getEntity('facture_fourn').')';
  437. if (empty($user->rights->societe->client->voir) && !$socid) {
  438. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  439. }
  440. if ($search_product_category > 0) {
  441. $sql .= " AND cp.fk_categorie = ".((int) $search_product_category);
  442. }
  443. if ($socid > 0) {
  444. $sql .= ' AND s.rowid = '.((int) $socid);
  445. }
  446. if ($search_ref) {
  447. if (is_numeric($search_ref)) {
  448. $sql .= natural_search(array('f.ref'), $search_ref);
  449. } else {
  450. $sql .= natural_search('f.ref', $search_ref);
  451. }
  452. }
  453. if ($search_ref) {
  454. $sql .= natural_search('f.ref', $search_ref);
  455. }
  456. if ($search_refsupplier) {
  457. $sql .= natural_search('f.ref_supplier', $search_refsupplier);
  458. }
  459. if ($search_type != '' && $search_type >= 0) {
  460. if ($search_type == '0') {
  461. $sql .= " AND f.type = 0"; // standard
  462. }
  463. if ($search_type == '1') {
  464. $sql .= " AND f.type = 1"; // replacement
  465. }
  466. if ($search_type == '2') {
  467. $sql .= " AND f.type = 2"; // credit note
  468. }
  469. if ($search_type == '3') {
  470. $sql .= " AND f.type = 3"; // deposit
  471. }
  472. //if ($search_type == '4') $sql.=" AND f.type = 4"; // proforma
  473. //if ($search_type == '5') $sql.=" AND f.type = 5"; // situation
  474. }
  475. if ($search_project) {
  476. $sql .= natural_search('p.ref', $search_project);
  477. }
  478. if ($search_company) {
  479. $sql .= natural_search('s.nom', $search_company);
  480. }
  481. if ($search_town) {
  482. $sql .= natural_search('s.town', $search_town);
  483. }
  484. if ($search_zip) {
  485. $sql .= natural_search("s.zip", $search_zip);
  486. }
  487. if ($search_state) {
  488. $sql .= natural_search("state.nom", $search_state);
  489. }
  490. if ($search_country) {
  491. $sql .= " AND s.fk_pays IN (".$db->sanitize($search_country).')';
  492. }
  493. if ($search_type_thirdparty != '' && $search_type_thirdparty >= 0) {
  494. $sql .= " AND s.fk_typent IN (".$db->sanitize($search_type_thirdparty).')';
  495. }
  496. if ($search_montant_ht != '') {
  497. $sql .= natural_search('f.total_ht', $search_montant_ht, 1);
  498. }
  499. if ($search_montant_vat != '') {
  500. $sql .= natural_search('f.total_tva', $search_montant_vat, 1);
  501. }
  502. if ($search_montant_localtax1 != '') {
  503. $sql .= natural_search('f.localtax1', $search_montant_localtax1, 1);
  504. }
  505. if ($search_montant_localtax2 != '') {
  506. $sql .= natural_search('f.localtax2', $search_montant_localtax2, 1);
  507. }
  508. if ($search_montant_ttc != '') {
  509. $sql .= natural_search('f.total_ttc', $search_montant_ttc, 1);
  510. }
  511. if ($search_multicurrency_code != '') {
  512. $sql .= " AND f.multicurrency_code = '".$db->escape($search_multicurrency_code)."'";
  513. }
  514. if ($search_multicurrency_tx != '') {
  515. $sql .= natural_search('f.multicurrency_tx', $search_multicurrency_tx, 1);
  516. }
  517. if ($search_multicurrency_montant_ht != '') {
  518. $sql .= natural_search('f.multicurrency_total_ht', $search_multicurrency_montant_ht, 1);
  519. }
  520. if ($search_multicurrency_montant_vat != '') {
  521. $sql .= natural_search('f.multicurrency_total_tva', $search_multicurrency_montant_vat, 1);
  522. }
  523. if ($search_multicurrency_montant_ttc != '') {
  524. $sql .= natural_search('f.multicurrency_total_ttc', $search_multicurrency_montant_ttc, 1);
  525. }
  526. if ($search_login) {
  527. $sql .= natural_search(array('u.lastname', 'u.firstname', 'u.login'), $search_login);
  528. }
  529. if ($search_status != '' && $search_status >= 0) {
  530. $sql .= " AND f.fk_statut = ".((int) $search_status);
  531. }
  532. if ($search_paymentmode > 0) {
  533. $sql .= " AND f.fk_mode_reglement = ".((int) $search_paymentmode);
  534. }
  535. if ($search_paymentcond > 0) {
  536. $sql .= " AND f.fk_cond_reglement = ".((int) $search_paymentcond);
  537. }
  538. if ($search_date_start) {
  539. $sql .= " AND f.datef >= '" . $db->idate($search_date_start) . "'";
  540. }
  541. if ($search_date_end) {
  542. $sql .= " AND f.datef <= '" . $db->idate($search_date_end) . "'";
  543. }
  544. if ($search_datelimit_start) {
  545. $sql .= " AND f.date_lim_reglement >= '" . $db->idate($search_datelimit_start) . "'";
  546. }
  547. if ($search_datelimit_end) {
  548. $sql .= " AND f.date_lim_reglement <= '" . $db->idate($search_datelimit_end) . "'";
  549. }
  550. if ($option == 'late') {
  551. $sql .= " AND f.date_lim_reglement < '".$db->idate(dol_now() - $conf->facture->fournisseur->warning_delay)."'";
  552. }
  553. if ($search_label) {
  554. $sql .= natural_search('f.libelle', $search_label);
  555. }
  556. if ($search_categ_sup > 0) {
  557. $sql .= " AND cs.fk_categorie = ".((int) $search_categ_sup);
  558. }
  559. if ($search_categ_sup == -2) {
  560. $sql .= " AND cs.fk_categorie IS NULL";
  561. }
  562. if ($search_status != '' && $search_status >= 0) {
  563. $sql .= " AND f.fk_statut = ".((int) $search_status);
  564. }
  565. if ($filter && $filter != -1) {
  566. $aFilter = explode(',', $filter);
  567. foreach ($aFilter as $fil) {
  568. $filt = explode(':', $fil);
  569. $sql .= " AND ".$db->escape(trim($filt[0]))." = '".$db->escape(trim($filt[1]))."'";
  570. }
  571. }
  572. if ($search_sale > 0) {
  573. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $search_sale);
  574. }
  575. if ($search_user > 0) {
  576. $sql .= " AND ec.fk_c_type_contact = tc.rowid AND tc.element='invoice_supplier' AND tc.source='internal' AND ec.element_id = f.rowid AND ec.fk_socpeople = ".((int) $search_user);
  577. }
  578. // Add where from extra fields
  579. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  580. // Add where from hooks
  581. $parameters = array();
  582. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
  583. $sql .= $hookmanager->resPrint;
  584. if (!$search_all) {
  585. $sql .= " GROUP BY f.rowid, f.ref, f.ref_supplier, f.type, f.datef, f.date_lim_reglement, f.fk_mode_reglement, f.fk_cond_reglement,";
  586. $sql .= " f.total_ht, f.total_ttc, f.total_tva, f.paye, f.fk_statut, f.libelle, f.datec, f.tms,";
  587. $sql .= " f.localtax1, f.localtax2,";
  588. $sql .= ' f.fk_multicurrency, f.multicurrency_code, f.multicurrency_tx, f.multicurrency_total_ht, f.multicurrency_total_tva, f.multicurrency_total_ttc,';
  589. $sql .= " f.note_public, f.note_private,";
  590. $sql .= " f.fk_user_author,";
  591. $sql .= ' s.rowid, s.nom, s.email, s.town, s.zip, s.fk_pays, s.client, s.fournisseur, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur,';
  592. $sql .= " typent.code,";
  593. $sql .= " state.code_departement, state.nom,";
  594. $sql .= ' country.code,';
  595. $sql .= " p.rowid, p.ref, p.title,";
  596. $sql .= " u.login, u.lastname, u.firstname, u.email, u.statut, u.entity, u.photo, u.office_phone, u.office_fax, u.user_mobile, u.job, u.gender";
  597. if ($search_categ_sup && $search_categ_sup != '-1') {
  598. $sql .= ", cs.fk_categorie, cs.fk_soc";
  599. }
  600. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  601. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  602. //prevent error with sql_mode=only_full_group_by
  603. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ",ef.".$key : '');
  604. }
  605. }
  606. // Add GroupBy from hooks
  607. $parameters = array('all' => $all, 'fieldstosearchall' => $fieldstosearchall);
  608. $reshook = $hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object); // Note that $action and $object may have been modified by hook
  609. $sql .= $hookmanager->resPrint;
  610. } else {
  611. $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
  612. }
  613. // Add HAVING from hooks
  614. $parameters = array();
  615. $reshook = $hookmanager->executeHooks('printFieldListHaving', $parameters, $object); // Note that $action and $object may have been modified by hook
  616. $sql .= empty($hookmanager->resPrint) ? "" : " HAVING 1=1 ".$hookmanager->resPrint;
  617. $sql .= $db->order($sortfield, $sortorder);
  618. $nbtotalofrecords = '';
  619. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
  620. $result = $db->query($sql);
  621. $nbtotalofrecords = $db->num_rows($result);
  622. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
  623. $page = 0;
  624. $offset = 0;
  625. }
  626. }
  627. $sql .= $db->plimit($limit + 1, $offset);
  628. //print $sql;
  629. $resql = $db->query($sql);
  630. if ($resql) {
  631. $num = $db->num_rows($resql);
  632. $arrayofselected = is_array($toselect) ? $toselect : array();
  633. if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $sall) {
  634. $obj = $db->fetch_object($resql);
  635. $id = $obj->facid;
  636. header("Location: ".DOL_URL_ROOT.'/fourn/facture/card.php?facid='.$id);
  637. exit;
  638. }
  639. llxHeader('', $langs->trans("SuppliersInvoices"), 'EN:Suppliers_Invoices|FR:FactureFournisseur|ES:Facturas_de_proveedores');
  640. if ($socid) {
  641. $soc = new Societe($db);
  642. $soc->fetch($socid);
  643. if (empty($search_company)) {
  644. $search_company = $soc->name;
  645. }
  646. }
  647. $param = '&socid='.$socid;
  648. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  649. $param .= '&contextpage='.urlencode($contextpage);
  650. }
  651. if ($limit > 0 && $limit != $conf->liste_limit) {
  652. $param .= '&limit='.urlencode($limit);
  653. }
  654. if ($search_all) {
  655. $param .= '&search_all='.urlencode($search_all);
  656. }
  657. if ($search_date_startday) {
  658. $param .= '&search_date_startday='.urlencode($search_date_startday);
  659. }
  660. if ($search_date_startmonth) {
  661. $param .= '&search_date_startmonth='.urlencode($search_date_startmonth);
  662. }
  663. if ($search_date_startyear) {
  664. $param .= '&search_date_startyear='.urlencode($search_date_startyear);
  665. }
  666. if ($search_date_endday) {
  667. $param .= '&search_date_endday='.urlencode($search_date_endday);
  668. }
  669. if ($search_date_endmonth) {
  670. $param .= '&search_date_endmonth='.urlencode($search_date_endmonth);
  671. }
  672. if ($search_date_endyear) {
  673. $param .= '&search_date_endyear='.urlencode($search_date_endyear);
  674. }
  675. if ($search_datelimit_startday) {
  676. $param .= '&search_datelimit_startday='.urlencode($search_datelimit_startday);
  677. }
  678. if ($search_datelimit_startmonth) {
  679. $param .= '&search_datelimit_startmonth='.urlencode($search_datelimit_startmonth);
  680. }
  681. if ($search_datelimit_startyear) {
  682. $param .= '&search_datelimit_startyear='.urlencode($search_datelimit_startyear);
  683. }
  684. if ($search_datelimit_endday) {
  685. $param .= '&search_datelimit_endday='.urlencode($search_datelimit_endday);
  686. }
  687. if ($search_datelimit_endmonth) {
  688. $param .= '&search_datelimit_endmonth='.urlencode($search_datelimit_endmonth);
  689. }
  690. if ($search_datelimit_endyear) {
  691. $param .= '&search_datelimit_endyear='.urlencode($search_datelimit_endyear);
  692. }
  693. if ($search_ref) {
  694. $param .= '&search_ref='.urlencode($search_ref);
  695. }
  696. if ($search_refsupplier) {
  697. $param .= '&search_refsupplier='.urlencode($search_refsupplier);
  698. }
  699. if ($search_type != '') {
  700. $param .= '&search_type='.urlencode($search_type);
  701. }
  702. if ($search_label) {
  703. $param .= '&search_label='.urlencode($search_label);
  704. }
  705. if ($search_company) {
  706. $param .= '&search_company='.urlencode($search_company);
  707. }
  708. if ($search_login) {
  709. $param .= '&search_login='.urlencode($search_login);
  710. }
  711. if ($search_montant_ht != '') {
  712. $param .= '&search_montant_ht='.urlencode($search_montant_ht);
  713. }
  714. if ($search_montant_vat != '') {
  715. $param .= '&search_montant_vat='.urlencode($search_montant_vat);
  716. }
  717. if ($search_montant_localtax1 != '') {
  718. $param .= '&search_montant_localtax1='.urlencode($search_montant_localtax1);
  719. }
  720. if ($search_montant_localtax2 != '') {
  721. $param .= '&search_montant_localtax2='.urlencode($search_montant_localtax2);
  722. }
  723. if ($search_montant_ttc != '') {
  724. $param .= '&search_montant_ttc='.urlencode($search_montant_ttc);
  725. }
  726. if ($search_multicurrency_code != '') {
  727. $param .= '&search_multicurrency_code='.urlencode($search_multicurrency_code);
  728. }
  729. if ($search_multicurrency_tx != '') {
  730. $param .= '&search_multicurrency_tx='.urlencode($search_multicurrency_tx);
  731. }
  732. if ($search_multicurrency_montant_ht != '') {
  733. $param .= '&search_multicurrency_montant_ht='.urlencode($search_multicurrency_montant_ht);
  734. }
  735. if ($search_multicurrency_montant_vat != '') {
  736. $param .= '&search_multicurrency_montant_vat='.urlencode($search_multicurrency_montant_vat);
  737. }
  738. if ($search_multicurrency_montant_ttc != '') {
  739. $param .= '&search_multicurrency_montant_ttc='.urlencode($search_multicurrency_montant_ttc);
  740. }
  741. if ($search_amount_no_tax) {
  742. $param .= '&search_amount_no_tax='.urlencode($search_amount_no_tax);
  743. }
  744. if ($search_amount_all_tax) {
  745. $param .= '&search_amount_all_tax='.urlencode($search_amount_all_tax);
  746. }
  747. if ($search_status >= 0) {
  748. $param .= "&search_status=".urlencode($search_status);
  749. }
  750. if ($show_files) {
  751. $param .= '&show_files='.urlencode($show_files);
  752. }
  753. if ($option) {
  754. $param .= "&search_option=".urlencode($option);
  755. }
  756. if ($optioncss != '') {
  757. $param .= '&optioncss='.urlencode($optioncss);
  758. }
  759. if ($search_categ_sup > 0) {
  760. $param .= '&search_categ_sup='.urlencode($search_categ_sup);
  761. }
  762. if ($search_type_thirdparty != '' && $search_type_thirdparty > 0) {
  763. $param .= '&search_type_thirdparty='.urlencode($search_type_thirdparty);
  764. }
  765. // Add $param from extra fields
  766. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  767. // Add $param from hooks
  768. $parameters = array();
  769. $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
  770. $param .= $hookmanager->resPrint;
  771. // List of mass actions available
  772. $arrayofmassactions = array(
  773. 'validate'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate"),
  774. 'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
  775. //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
  776. //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
  777. );
  778. //if($user->rights->fournisseur->facture->creer) $arrayofmassactions['createbills']=$langs->trans("CreateInvoiceForThisCustomer");
  779. if (!empty($conf->paymentbybanktransfer->enabled) && !empty($user->rights->paymentbybanktransfer->create)) {
  780. $langs->load('withdrawals');
  781. $arrayofmassactions['banktransfertrequest'] = img_picto('', 'payment', 'class="pictofixedwidth"').$langs->trans("MakeBankTransferOrder");
  782. }
  783. if ($user->rights->fournisseur->facture->supprimer) {
  784. $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
  785. }
  786. if (in_array($massaction, array('presend', 'predelete', 'createbills'))) {
  787. $arrayofmassactions = array();
  788. }
  789. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  790. $url = DOL_URL_ROOT.'/fourn/facture/card.php?action=create';
  791. if (!empty($socid)) {
  792. $url .= '&socid='.urlencode($socid);
  793. }
  794. $newcardbutton = dolGetButtonTitle($langs->trans('NewBill'), '', 'fa fa-plus-circle', $url, '', ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer));
  795. $i = 0;
  796. print '<form method="POST" name="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  797. if ($optioncss != '') {
  798. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  799. }
  800. print '<input type="hidden" name="token" value="'.newToken().'">';
  801. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  802. print '<input type="hidden" name="action" value="list">';
  803. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  804. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  805. print '<input type="hidden" name="socid" value="'.$socid.'">';
  806. print_barre_liste($langs->trans("BillsSuppliers").($socid ? ' '.$soc->name : ''), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'supplier_invoice', 0, $newcardbutton, '', $limit, 0, 0, 1);
  807. $topicmail = "SendBillRef";
  808. $modelmail = "invoice_supplier_send";
  809. $objecttmp = new FactureFournisseur($db);
  810. $trackid = 'sinv'.$object->id;
  811. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  812. if ($massaction == 'createbills') {
  813. //var_dump($_REQUEST);
  814. print '<input type="hidden" name="massaction" value="confirm_createbills">';
  815. print '<table class="border" width="100%" >';
  816. print '<tr>';
  817. print '<td class="titlefieldmiddle">';
  818. print $langs->trans('DateInvoice');
  819. print '</td>';
  820. print '<td>';
  821. print $form->selectDate('', '', '', '', '', '', 1, 1);
  822. print '</td>';
  823. print '</tr>';
  824. print '<tr>';
  825. print '<td>';
  826. print $langs->trans('CreateOneBillByThird');
  827. print '</td>';
  828. print '<td>';
  829. print $form->selectyesno('createbills_onebythird', '', 1);
  830. print '</td>';
  831. print '</tr>';
  832. print '<tr>';
  833. print '<td>';
  834. print $langs->trans('ValidateInvoices');
  835. print '</td>';
  836. print '<td>';
  837. print $form->selectyesno('validate_invoices', 1, 1);
  838. print '</td>';
  839. print '</tr>';
  840. print '</table>';
  841. print '<br>';
  842. print '<div class="center">';
  843. print '<input type="submit" class="button" id="createbills" name="createbills" value="'.$langs->trans('CreateInvoiceForThisCustomer').'"> ';
  844. print '<input type="submit" class="button button-cancel" id="cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
  845. print '</div>';
  846. print '<br>';
  847. }
  848. if ($search_all) {
  849. foreach ($fieldstosearchall as $key => $val) {
  850. $fieldstosearchall[$key] = $langs->trans($val);
  851. }
  852. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>';
  853. }
  854. // If the user can view prospects other than his'
  855. $moreforfilter = '';
  856. if ($user->rights->societe->client->voir || $socid) {
  857. $langs->load("commercial");
  858. $moreforfilter .= '<div class="divsearchfield">';
  859. $tmptitle = $langs->trans('ThirdPartiesOfSaleRepresentative');
  860. $moreforfilter .= img_picto($tmptitle, 'company', 'class="pictofixedwidth"').$formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, $tmptitle, 'maxwidth200');
  861. $moreforfilter .= '</div>';
  862. }
  863. // If the user can view prospects other than his'
  864. if ($user->rights->societe->client->voir || $socid) {
  865. $moreforfilter .= '<div class="divsearchfield">';
  866. $tmptitle = $langs->trans('LinkedToSpecificUsers');
  867. $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$form->select_dolusers($search_user, 'search_user', $tmptitle, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth200');
  868. $moreforfilter .= '</div>';
  869. }
  870. // If the user can view prospects other than his'
  871. if (!empty($conf->categorie->enabled) && $user->rights->categorie->lire && ($user->rights->produit->lire || $user->rights->service->lire)) {
  872. include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  873. $moreforfilter .= '<div class="divsearchfield">';
  874. $tmptitle = $langs->trans('IncludingProductWithTag');
  875. $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, null, 'parent', null, null, 1);
  876. $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);
  877. $moreforfilter .= '</div>';
  878. }
  879. if (!empty($conf->categorie->enabled)) {
  880. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  881. $moreforfilter .= '<div class="divsearchfield">';
  882. $tmptitle = $langs->trans('SuppliersCategoriesShort');
  883. $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"').$formother->select_categories('supplier', $search_categ_sup, 'search_categ_sup', 1, $tmptitle);
  884. $moreforfilter .= '</div>';
  885. }
  886. $parameters = array();
  887. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
  888. if (empty($reshook)) {
  889. $moreforfilter .= $hookmanager->resPrint;
  890. } else {
  891. $moreforfilter = $hookmanager->resPrint;
  892. }
  893. if ($moreforfilter) {
  894. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  895. print $moreforfilter;
  896. print '</div>';
  897. }
  898. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  899. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  900. if ($massactionbutton) {
  901. $selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
  902. }
  903. print '<div class="div-table-responsive">';
  904. print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  905. // Line for filters
  906. print '<tr class="liste_titre_filter">';
  907. // Ref
  908. if (!empty($arrayfields['f.ref']['checked'])) {
  909. print '<td class="liste_titre left">';
  910. print '<input class="flat maxwidth50" type="text" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">';
  911. print '</td>';
  912. }
  913. // Ref supplier
  914. if (!empty($arrayfields['f.ref_supplier']['checked'])) {
  915. print '<td class="liste_titre">';
  916. print '<input class="flat maxwidth75" type="text" name="search_refsupplier" value="'.dol_escape_htmltag($search_refsupplier).'">';
  917. print '</td>';
  918. }
  919. // Type
  920. if (!empty($arrayfields['f.type']['checked'])) {
  921. print '<td class="liste_titre maxwidthonsmartphone">';
  922. $listtype = array(
  923. FactureFournisseur::TYPE_STANDARD=>$langs->trans("InvoiceStandard"),
  924. FactureFournisseur::TYPE_REPLACEMENT=>$langs->trans("InvoiceReplacement"),
  925. FactureFournisseur::TYPE_CREDIT_NOTE=>$langs->trans("InvoiceAvoir"),
  926. FactureFournisseur::TYPE_DEPOSIT=>$langs->trans("InvoiceDeposit"),
  927. );
  928. /*
  929. if (! empty($conf->global->INVOICE_USE_SITUATION))
  930. {
  931. $listtype[Facture::TYPE_SITUATION] = $langs->trans("InvoiceSituation");
  932. }
  933. */
  934. //$listtype[Facture::TYPE_PROFORMA]=$langs->trans("InvoiceProForma"); // A proformat invoice is not an invoice but must be an order.
  935. print $form->selectarray('search_type', $listtype, $search_type, 1, 0, 0, '', 0, 0, 0, 'ASC', 'maxwidth100');
  936. print '</td>';
  937. }
  938. // Label
  939. if (!empty($arrayfields['f.label']['checked'])) {
  940. print '<td class="liste_titre">';
  941. print '<input class="flat maxwidth75" type="text" name="search_label" value="'.dol_escape_htmltag($search_label).'">';
  942. print '</td>';
  943. }
  944. // Date invoice
  945. if (!empty($arrayfields['f.datef']['checked'])) {
  946. print '<td class="liste_titre center">';
  947. print '<div class="nowrap">';
  948. print $form->selectDate($search_date_start ? $search_date_start : -1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  949. print '</div>';
  950. print '<div class="nowrap">';
  951. print $form->selectDate($search_date_end ? $search_date_end : -1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  952. print '</div>';
  953. print '</td>';
  954. }
  955. // Date due
  956. if (!empty($arrayfields['f.date_lim_reglement']['checked'])) {
  957. print '<td class="liste_titre center">';
  958. print '<div class="nowrap">';
  959. /*
  960. print $langs->trans('From').' ';
  961. print $form->selectDate($search_datelimit_start ? $search_datelimit_start : -1, 'search_datelimit_start', 0, 0, 1);
  962. print '</div>';
  963. print '<div class="nowrap">';
  964. print $langs->trans('to').' ';*/
  965. print $form->selectDate($search_datelimit_end ? $search_datelimit_end : -1, 'search_datelimit_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("Before"));
  966. print '<br><input type="checkbox" name="search_option" value="late"'.($option == 'late' ? ' checked' : '').'> '.$langs->trans("Alert");
  967. print '</div>';
  968. print '</td>';
  969. }
  970. // Project
  971. if (!empty($arrayfields['p.ref']['checked'])) {
  972. print '<td class="liste_titre"><input class="flat maxwidth50" type="text" name="search_project" value="'.dol_escape_htmltag($search_project).'"></td>';
  973. }
  974. // Thirpdarty
  975. if (!empty($arrayfields['s.nom']['checked'])) {
  976. print '<td class="liste_titre"><input class="flat maxwidth50" type="text" name="search_company" value="'.dol_escape_htmltag($search_company).'"></td>';
  977. }
  978. // Town
  979. if (!empty($arrayfields['s.town']['checked'])) {
  980. print '<td class="liste_titre"><input class="flat maxwidth50" type="text" name="search_town" value="'.dol_escape_htmltag($search_town).'"></td>';
  981. }
  982. // Zip
  983. if (!empty($arrayfields['s.zip']['checked'])) {
  984. print '<td class="liste_titre center"><input class="flat maxwidth50" type="text" name="search_zip" value="'.dol_escape_htmltag($search_zip).'"></td>';
  985. }
  986. // State
  987. if (!empty($arrayfields['state.nom']['checked'])) {
  988. print '<td class="liste_titre">';
  989. print '<input class="flat" size="4" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
  990. print '</td>';
  991. }
  992. // Country
  993. if (!empty($arrayfields['country.code_iso']['checked'])) {
  994. print '<td class="liste_titre center">';
  995. print $form->select_country($search_country, 'search_country', '', 0, 'minwidth100imp maxwidth100');
  996. print '</td>';
  997. }
  998. // Company type
  999. if (!empty($arrayfields['typent.code']['checked'])) {
  1000. print '<td class="liste_titre maxwidthonsmartphone center">';
  1001. 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);
  1002. print '</td>';
  1003. }
  1004. // Condition of payment
  1005. if (!empty($arrayfields['f.fk_cond_reglement']['checked'])) {
  1006. print '<td class="liste_titre left">';
  1007. $form->select_conditions_paiements($search_paymentcond, 'search_paymentcond', -1, 1, 1, 'maxwidth100');
  1008. print '</td>';
  1009. }
  1010. // Payment mode
  1011. if (!empty($arrayfields['f.fk_mode_reglement']['checked'])) {
  1012. print '<td class="liste_titre left">';
  1013. $form->select_types_paiements($search_paymentmode, 'search_paymentmode', '', 0, 1, 1, 20, 1, 'maxwidth100');
  1014. print '</td>';
  1015. }
  1016. if (!empty($arrayfields['f.total_ht']['checked'])) {
  1017. // Amount without tax
  1018. print '<td class="liste_titre right">';
  1019. print '<input class="flat" type="text" size="5" name="search_montant_ht" value="'.dol_escape_htmltag($search_montant_ht).'">';
  1020. print '</td>';
  1021. }
  1022. if (!empty($arrayfields['f.total_vat']['checked'])) {
  1023. // Amount vat
  1024. print '<td class="liste_titre right">';
  1025. print '<input class="flat" type="text" size="5" name="search_montant_vat" value="'.dol_escape_htmltag($search_montant_vat).'">';
  1026. print '</td>';
  1027. }
  1028. if (!empty($arrayfields['f.total_localtax1']['checked'])) {
  1029. // Amount tax 1
  1030. print '<td class="liste_titre right">';
  1031. print '<input class="flat" type="text" size="5" name="search_montant_localtax1" value="'.dol_escape_htmltag($search_montant_localtax1).'">';
  1032. print '</td>';
  1033. }
  1034. if (!empty($arrayfields['f.total_localtax2']['checked'])) {
  1035. // Amount tax 2
  1036. print '<td class="liste_titre right">';
  1037. print '<input class="flat" type="text" size="5" name="search_montant_localtax2" value="'.dol_escape_htmltag($search_montant_localtax2).'">';
  1038. print '</td>';
  1039. }
  1040. if (!empty($arrayfields['f.total_ttc']['checked'])) {
  1041. // Amount inc tac
  1042. print '<td class="liste_titre right">';
  1043. print '<input class="flat" type="text" size="5" name="search_montant_ttc" value="'.dol_escape_htmltag($search_montant_ttc).'">';
  1044. print '</td>';
  1045. }
  1046. if (!empty($arrayfields['u.login']['checked'])) {
  1047. // Author
  1048. print '<td class="liste_titre" align="center">';
  1049. print '<input class="flat" size="4" type="text" name="search_login" value="'.dol_escape_htmltag($search_login).'">';
  1050. print '</td>';
  1051. }
  1052. if (!empty($arrayfields['dynamount_payed']['checked'])) {
  1053. print '<td class="liste_titre right">';
  1054. print '</td>';
  1055. }
  1056. if (!empty($arrayfields['rtp']['checked'])) {
  1057. print '<td class="liste_titre">';
  1058. print '</td>';
  1059. }
  1060. if (!empty($arrayfields['f.multicurrency_code']['checked'])) {
  1061. // Currency
  1062. print '<td class="liste_titre">';
  1063. print $form->selectMultiCurrency($search_multicurrency_code, 'search_multicurrency_code', 1);
  1064. print '</td>';
  1065. }
  1066. if (!empty($arrayfields['f.multicurrency_tx']['checked'])) {
  1067. // Currency rate
  1068. print '<td class="liste_titre">';
  1069. print '<input class="flat" type="text" size="4" name="search_multicurrency_tx" value="'.dol_escape_htmltag($search_multicurrency_tx).'">';
  1070. print '</td>';
  1071. }
  1072. if (!empty($arrayfields['f.multicurrency_total_ht']['checked'])) {
  1073. // Amount
  1074. print '<td class="liste_titre right">';
  1075. print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_ht" value="'.dol_escape_htmltag($search_multicurrency_montant_ht).'">';
  1076. print '</td>';
  1077. }
  1078. if (!empty($arrayfields['f.multicurrency_total_vat']['checked'])) {
  1079. // Amount
  1080. print '<td class="liste_titre right">';
  1081. print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_vat" value="'.dol_escape_htmltag($search_multicurrency_montant_vat).'">';
  1082. print '</td>';
  1083. }
  1084. if (!empty($arrayfields['f.multicurrency_total_ttc']['checked'])) {
  1085. // Amount
  1086. print '<td class="liste_titre right">';
  1087. print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_ttc" value="'.dol_escape_htmltag($search_multicurrency_montant_ttc).'">';
  1088. print '</td>';
  1089. }
  1090. if (!empty($arrayfields['multicurrency_dynamount_payed']['checked'])) {
  1091. print '<td class="liste_titre">';
  1092. print '</td>';
  1093. }
  1094. if (!empty($arrayfields['multicurrency_rtp']['checked'])) {
  1095. print '<td class="liste_titre right">';
  1096. print '</td>';
  1097. }
  1098. // Extra fields
  1099. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  1100. // Fields from hook
  1101. $parameters = array('arrayfields'=>$arrayfields);
  1102. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
  1103. print $hookmanager->resPrint;
  1104. // Date creation
  1105. if (!empty($arrayfields['f.datec']['checked'])) {
  1106. print '<td class="liste_titre">';
  1107. print '</td>';
  1108. }
  1109. // Date modification
  1110. if (!empty($arrayfields['f.tms']['checked'])) {
  1111. print '<td class="liste_titre">';
  1112. print '</td>';
  1113. }
  1114. // Status
  1115. if (!empty($arrayfields['f.fk_statut']['checked'])) {
  1116. print '<td class="liste_titre maxwidthonsmartphone right">';
  1117. $liststatus = array('0'=>$langs->trans("Draft"), '1'=>$langs->trans("Unpaid"), '2'=>$langs->trans("Paid"));
  1118. print $form->selectarray('search_status', $liststatus, $search_status, 1, 0, 0, '', 0, 0, 0, '', '', 1);
  1119. print '</td>';
  1120. }
  1121. // Action column
  1122. print '<td class="liste_titre middle">';
  1123. $searchpicto = $form->showFilterButtons();
  1124. print $searchpicto;
  1125. print '</td>';
  1126. print "</tr>\n";
  1127. print '<tr class="liste_titre">';
  1128. if (!empty($arrayfields['f.ref']['checked'])) {
  1129. print_liste_field_titre($arrayfields['f.ref']['label'], $_SERVER['PHP_SELF'], 'f.ref,f.rowid', '', $param, '', $sortfield, $sortorder);
  1130. }
  1131. if (!empty($arrayfields['f.ref_supplier']['checked'])) {
  1132. print_liste_field_titre($arrayfields['f.ref_supplier']['label'], $_SERVER["PHP_SELF"], 'f.ref_supplier', '', $param, '', $sortfield, $sortorder);
  1133. }
  1134. if (!empty($arrayfields['f.type']['checked'])) {
  1135. print_liste_field_titre($arrayfields['f.type']['label'], $_SERVER["PHP_SELF"], 'f.type', '', $param, '', $sortfield, $sortorder);
  1136. }
  1137. if (!empty($arrayfields['f.label']['checked'])) {
  1138. print_liste_field_titre($arrayfields['f.label']['label'], $_SERVER['PHP_SELF'], "f.libelle,f.rowid", '', $param, '', $sortfield, $sortorder);
  1139. }
  1140. if (!empty($arrayfields['f.datef']['checked'])) {
  1141. print_liste_field_titre($arrayfields['f.datef']['label'], $_SERVER['PHP_SELF'], 'f.datef,f.rowid', '', $param, '', $sortfield, $sortorder, 'center ');
  1142. }
  1143. if (!empty($arrayfields['f.date_lim_reglement']['checked'])) {
  1144. print_liste_field_titre($arrayfields['f.date_lim_reglement']['label'], $_SERVER['PHP_SELF'], "f.date_lim_reglement", '', $param, '', $sortfield, $sortorder, 'center ');
  1145. }
  1146. if (!empty($arrayfields['p.ref']['checked'])) {
  1147. print_liste_field_titre($arrayfields['p.ref']['label'], $_SERVER['PHP_SELF'], "p.ref", '', $param, '', $sortfield, $sortorder);
  1148. }
  1149. if (!empty($arrayfields['s.nom']['checked'])) {
  1150. print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER['PHP_SELF'], 's.nom', '', $param, '', $sortfield, $sortorder);
  1151. }
  1152. if (!empty($arrayfields['s.town']['checked'])) {
  1153. print_liste_field_titre($arrayfields['s.town']['label'], $_SERVER["PHP_SELF"], 's.town', '', $param, '', $sortfield, $sortorder);
  1154. }
  1155. if (!empty($arrayfields['s.zip']['checked'])) {
  1156. print_liste_field_titre($arrayfields['s.zip']['label'], $_SERVER["PHP_SELF"], 's.zip', '', $param, '', $sortfield, $sortorder, 'center ');
  1157. }
  1158. if (!empty($arrayfields['state.nom']['checked'])) {
  1159. print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder);
  1160. }
  1161. if (!empty($arrayfields['country.code_iso']['checked'])) {
  1162. print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, '', $sortfield, $sortorder, 'center ');
  1163. }
  1164. if (!empty($arrayfields['typent.code']['checked'])) {
  1165. print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, '', $sortfield, $sortorder, 'center ');
  1166. }
  1167. if (!empty($arrayfields['f.fk_cond_reglement']['checked'])) {
  1168. print_liste_field_titre($arrayfields['f.fk_cond_reglement']['label'], $_SERVER["PHP_SELF"], "f.fk_cond_reglement", "", $param, "", $sortfield, $sortorder);
  1169. }
  1170. if (!empty($arrayfields['f.fk_mode_reglement']['checked'])) {
  1171. print_liste_field_titre($arrayfields['f.fk_mode_reglement']['label'], $_SERVER["PHP_SELF"], "f.fk_mode_reglement", "", $param, "", $sortfield, $sortorder);
  1172. }
  1173. if (!empty($arrayfields['f.total_ht']['checked'])) {
  1174. print_liste_field_titre($arrayfields['f.total_ht']['label'], $_SERVER['PHP_SELF'], 'f.total_ht', '', $param, '', $sortfield, $sortorder, 'right ');
  1175. }
  1176. if (!empty($arrayfields['f.total_vat']['checked'])) {
  1177. print_liste_field_titre($arrayfields['f.total_vat']['label'], $_SERVER['PHP_SELF'], 'f.total_tva', '', $param, '', $sortfield, $sortorder, 'right ');
  1178. }
  1179. if (!empty($arrayfields['f.total_localtax1']['checked'])) {
  1180. print_liste_field_titre($arrayfields['f.total_localtax1']['label'], $_SERVER['PHP_SELF'], 'f.localtax1', '', $param, '', $sortfield, $sortorder, 'right ');
  1181. }
  1182. if (!empty($arrayfields['f.total_localtax2']['checked'])) {
  1183. print_liste_field_titre($arrayfields['f.total_localtax2']['label'], $_SERVER['PHP_SELF'], 'f.localtax2', '', $param, '', $sortfield, $sortorder, 'right ');
  1184. }
  1185. if (!empty($arrayfields['f.total_ttc']['checked'])) {
  1186. print_liste_field_titre($arrayfields['f.total_ttc']['label'], $_SERVER['PHP_SELF'], 'f.total_ttc', '', $param, '', $sortfield, $sortorder, 'right ');
  1187. }
  1188. if (!empty($arrayfields['u.login']['checked'])) {
  1189. print_liste_field_titre($arrayfields['u.login']['label'], $_SERVER["PHP_SELF"], 'u.login', '', $param, 'align="center"', $sortfield, $sortorder);
  1190. }
  1191. if (!empty($arrayfields['dynamount_payed']['checked'])) {
  1192. print_liste_field_titre($arrayfields['dynamount_payed']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'right ');
  1193. }
  1194. if (!empty($arrayfields['rtp']['checked'])) {
  1195. print_liste_field_titre($arrayfields['rtp']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'right ');
  1196. }
  1197. if (!empty($arrayfields['f.multicurrency_code']['checked'])) {
  1198. print_liste_field_titre($arrayfields['f.multicurrency_code']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_code', '', $param, '', $sortfield, $sortorder);
  1199. }
  1200. if (!empty($arrayfields['f.multicurrency_tx']['checked'])) {
  1201. print_liste_field_titre($arrayfields['f.multicurrency_tx']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_tx', '', $param, '', $sortfield, $sortorder);
  1202. }
  1203. if (!empty($arrayfields['f.multicurrency_total_ht']['checked'])) {
  1204. print_liste_field_titre($arrayfields['f.multicurrency_total_ht']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_total_ht', '', $param, 'class="right"', $sortfield, $sortorder);
  1205. }
  1206. if (!empty($arrayfields['f.multicurrency_total_vat']['checked'])) {
  1207. print_liste_field_titre($arrayfields['f.multicurrency_total_vat']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_total_tva', '', $param, 'class="right"', $sortfield, $sortorder);
  1208. }
  1209. if (!empty($arrayfields['f.multicurrency_total_ttc']['checked'])) {
  1210. print_liste_field_titre($arrayfields['f.multicurrency_total_ttc']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_total_ttc', '', $param, 'class="right"', $sortfield, $sortorder);
  1211. }
  1212. if (!empty($arrayfields['multicurrency_dynamount_payed']['checked'])) {
  1213. print_liste_field_titre($arrayfields['multicurrency_dynamount_payed']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
  1214. }
  1215. if (!empty($arrayfields['multicurrency_rtp']['checked'])) {
  1216. print_liste_field_titre($arrayfields['multicurrency_rtp']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
  1217. }
  1218. // Extra fields
  1219. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  1220. // Hook fields
  1221. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
  1222. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
  1223. print $hookmanager->resPrint;
  1224. if (!empty($arrayfields['f.datec']['checked'])) {
  1225. print_liste_field_titre($arrayfields['f.datec']['label'], $_SERVER["PHP_SELF"], "f.datec", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  1226. }
  1227. if (!empty($arrayfields['f.tms']['checked'])) {
  1228. print_liste_field_titre($arrayfields['f.tms']['label'], $_SERVER["PHP_SELF"], "f.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  1229. }
  1230. if (!empty($arrayfields['f.fk_statut']['checked'])) {
  1231. print_liste_field_titre($arrayfields['f.fk_statut']['label'], $_SERVER["PHP_SELF"], "fk_statut,paye,type", "", $param, '', $sortfield, $sortorder, 'right ');
  1232. }
  1233. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
  1234. print "</tr>\n";
  1235. $facturestatic = new FactureFournisseur($db);
  1236. $supplierstatic = new Fournisseur($db);
  1237. $projectstatic = new Project($db);
  1238. $userstatic = new User($db);
  1239. if ($num > 0) {
  1240. $i = 0;
  1241. $totalarray = array();
  1242. while ($i < min($num, $limit)) {
  1243. $obj = $db->fetch_object($resql);
  1244. $datelimit = $db->jdate($obj->datelimite);
  1245. $facturestatic->id = $obj->facid;
  1246. $facturestatic->ref = $obj->ref;
  1247. $facturestatic->type = $obj->type;
  1248. $facturestatic->ref_supplier = $obj->ref_supplier;
  1249. $facturestatic->date_echeance = $db->jdate($obj->datelimite);
  1250. $facturestatic->statut = $obj->fk_statut;
  1251. $facturestatic->note_public = $obj->note_public;
  1252. $facturestatic->note_private = $obj->note_private;
  1253. $facturestatic->multicurrency_code = $obj->multicurrency_code;
  1254. $facturestatic->multicurrency_tx = $obj->multicurrency_tx;
  1255. $facturestatic->multicurrency_total_ht = $obj->multicurrency_total_ht;
  1256. $facturestatic->multicurrency_total_tva = $obj->multicurrency_total_vat;
  1257. $facturestatic->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
  1258. $thirdparty->id = $obj->socid;
  1259. $thirdparty->name = $obj->name;
  1260. $thirdparty->client = $obj->client;
  1261. $thirdparty->fournisseur = $obj->fournisseur;
  1262. $thirdparty->code_client = $obj->code_client;
  1263. $thirdparty->code_compta_client = $obj->code_compta_client;
  1264. $thirdparty->code_fournisseur = $obj->code_fournisseur;
  1265. $thirdparty->code_compta_fournisseur = $obj->code_compta_fournisseur;
  1266. $thirdparty->email = $obj->email;
  1267. $thirdparty->country_code = $obj->country_code;
  1268. $paiement = $facturestatic->getSommePaiement();
  1269. $totalcreditnotes = $facturestatic->getSumCreditNotesUsed();
  1270. $totaldeposits = $facturestatic->getSumDepositsUsed();
  1271. $totalpay = $paiement + $totalcreditnotes + $totaldeposits;
  1272. $remaintopay = $obj->total_ttc - $totalpay;
  1273. $multicurrency_paiement = $facturestatic->getSommePaiement(1);
  1274. $multicurrency_totalcreditnotes = $facturestatic->getSumCreditNotesUsed(1);
  1275. $multicurrency_totaldeposits = $facturestatic->getSumDepositsUsed(1);
  1276. $multicurrency_totalpay = $multicurrency_paiement + $multicurrency_totalcreditnotes + $multicurrency_totaldeposits;
  1277. $multicurrency_remaintopay = price2num($facturestatic->multicurrency_total_ttc - $multicurrency_totalpay);
  1278. $facturestatic->alreadypaid = ($paiement ? $paiement : 0);
  1279. $facturestatic->paye = $obj->paye;
  1280. $facturestatic->statut = $obj->fk_statut;
  1281. $facturestatic->type = $obj->type;
  1282. //If invoice has been converted and the conversion has been used, we dont have remain to pay on invoice
  1283. if ($facturestatic->type == FactureFournisseur::TYPE_CREDIT_NOTE) {
  1284. if ($facturestatic->isCreditNoteUsed()) {
  1285. $remaintopay = -$facturestatic->getSumFromThisCreditNotesNotUsed();
  1286. }
  1287. }
  1288. print '<tr class="oddeven">';
  1289. if (!empty($arrayfields['f.ref']['checked'])) {
  1290. print '<td class="nowraponall">';
  1291. print '<table class="nobordernopadding"><tr class="nocellnopadd">';
  1292. // Picto + Ref
  1293. print '<td class="nobordernopadding nowraponall">';
  1294. print $facturestatic->getNomUrl(1, '', 0, 0, '', 0, -1, 1);
  1295. $filename = dol_sanitizeFileName($obj->ref);
  1296. $filedir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($obj->facid, 2, 0, 0, $facturestatic, 'invoice_supplier').dol_sanitizeFileName($obj->ref);
  1297. $subdir = get_exdir($obj->facid, 2, 0, 0, $facturestatic, 'invoice_supplier').dol_sanitizeFileName($obj->ref);
  1298. print $formfile->getDocumentsLink('facture_fournisseur', $subdir, $filedir);
  1299. print '</td></tr></table>';
  1300. print "</td>\n";
  1301. if (!$i) {
  1302. $totalarray['nbfield']++;
  1303. }
  1304. }
  1305. // Supplier ref
  1306. if (!empty($arrayfields['f.ref_supplier']['checked'])) {
  1307. print '<td class="nowrap tdoverflowmax150" title="'.dol_escape_htmltag($obj->ref_supplier).'">';
  1308. print $obj->ref_supplier;
  1309. print '</td>';
  1310. if (!$i) {
  1311. $totalarray['nbfield']++;
  1312. }
  1313. }
  1314. // Type
  1315. if (!empty($arrayfields['f.type']['checked'])) {
  1316. print '<td class="nowrap">';
  1317. print $facturestatic->getLibType();
  1318. print "</td>";
  1319. if (!$i) {
  1320. $totalarray['nbfield']++;
  1321. }
  1322. }
  1323. // Label
  1324. if (!empty($arrayfields['f.label']['checked'])) {
  1325. print '<td class="nowrap">';
  1326. print $obj->label;
  1327. print '</td>';
  1328. if (!$i) {
  1329. $totalarray['nbfield']++;
  1330. }
  1331. }
  1332. // Date
  1333. if (!empty($arrayfields['f.datef']['checked'])) {
  1334. print '<td class="center nowrap">';
  1335. print dol_print_date($db->jdate($obj->datef), 'day');
  1336. print '</td>';
  1337. if (!$i) {
  1338. $totalarray['nbfield']++;
  1339. }
  1340. }
  1341. // Date limit
  1342. if (!empty($arrayfields['f.date_lim_reglement']['checked'])) {
  1343. print '<td class="center nowraponall">'.dol_print_date($datelimit, 'day');
  1344. if ($facturestatic->hasDelay()) {
  1345. print img_warning($langs->trans('Alert').' - '.$langs->trans('Late'));
  1346. }
  1347. print '</td>';
  1348. if (!$i) {
  1349. $totalarray['nbfield']++;
  1350. }
  1351. }
  1352. // Project
  1353. if (!empty($arrayfields['p.ref']['checked'])) {
  1354. print '<td class="nowrap">';
  1355. if ($obj->project_id > 0) {
  1356. $projectstatic->id = $obj->project_id;
  1357. $projectstatic->ref = $obj->project_ref;
  1358. $projectstatic->title = $obj->project_label;
  1359. print $projectstatic->getNomUrl(1);
  1360. }
  1361. print '</td>';
  1362. if (!$i) {
  1363. $totalarray['nbfield']++;
  1364. }
  1365. }
  1366. // Third party
  1367. if (!empty($arrayfields['s.nom']['checked'])) {
  1368. print '<td class="tdoverflowmax200">';
  1369. print $thirdparty->getNomUrl(1, 'supplier');
  1370. print '</td>';
  1371. if (!$i) {
  1372. $totalarray['nbfield']++;
  1373. }
  1374. }
  1375. // Town
  1376. if (!empty($arrayfields['s.town']['checked'])) {
  1377. print '<td class="nocellnopadd">';
  1378. print $obj->town;
  1379. print '</td>';
  1380. if (!$i) {
  1381. $totalarray['nbfield']++;
  1382. }
  1383. }
  1384. // Zip
  1385. if (!empty($arrayfields['s.zip']['checked'])) {
  1386. print '<td class="nocellnopadd center">';
  1387. print $obj->zip;
  1388. print '</td>';
  1389. if (!$i) {
  1390. $totalarray['nbfield']++;
  1391. }
  1392. }
  1393. // State
  1394. if (!empty($arrayfields['state.nom']['checked'])) {
  1395. print "<td>".$obj->state_name."</td>\n";
  1396. if (!$i) {
  1397. $totalarray['nbfield']++;
  1398. }
  1399. }
  1400. // Country
  1401. if (!empty($arrayfields['country.code_iso']['checked'])) {
  1402. print '<td class="center">';
  1403. $tmparray = getCountry($obj->fk_pays, 'all');
  1404. print $tmparray['label'];
  1405. print '</td>';
  1406. if (!$i) {
  1407. $totalarray['nbfield']++;
  1408. }
  1409. }
  1410. // Type ent
  1411. if (!empty($arrayfields['typent.code']['checked'])) {
  1412. print '<td class="center">';
  1413. if (empty($typenArray)) {
  1414. $typenArray = $formcompany->typent_array(1);
  1415. }
  1416. print $typenArray[$obj->typent_code];
  1417. print '</td>';
  1418. if (!$i) {
  1419. $totalarray['nbfield']++;
  1420. }
  1421. }
  1422. // Payment condition
  1423. if (!empty($arrayfields['f.fk_cond_reglement']['checked'])) {
  1424. print '<td class="tdoverflowmax125">';
  1425. $form->form_conditions_reglement($_SERVER['PHP_SELF'], $obj->fk_cond_reglement, 'none', '', -1);
  1426. print '</td>';
  1427. if (!$i) {
  1428. $totalarray['nbfield']++;
  1429. }
  1430. }
  1431. // Payment mode
  1432. if (!empty($arrayfields['f.fk_mode_reglement']['checked'])) {
  1433. print '<td class="tdoverflowmax125">';
  1434. $form->form_modes_reglement($_SERVER['PHP_SELF'], $obj->fk_mode_reglement, 'none', '', -1);
  1435. print '</td>';
  1436. if (!$i) {
  1437. $totalarray['nbfield']++;
  1438. }
  1439. }
  1440. // Amount HT
  1441. if (!empty($arrayfields['f.total_ht']['checked'])) {
  1442. print '<td class="right nowrap"><span class="amount">'.price($obj->total_ht)."</span></td>\n";
  1443. if (!$i) {
  1444. $totalarray['nbfield']++;
  1445. }
  1446. if (!$i) {
  1447. $totalarray['pos'][$totalarray['nbfield']] = 'f.total_ht';
  1448. }
  1449. $totalarray['val']['f.total_ht'] += $obj->total_ht;
  1450. }
  1451. // Amount VAT
  1452. if (!empty($arrayfields['f.total_vat']['checked'])) {
  1453. print '<td class="right nowrap"><span class="amount">'.price($obj->total_vat)."</span></td>\n";
  1454. if (!$i) {
  1455. $totalarray['nbfield']++;
  1456. }
  1457. if (!$i) {
  1458. $totalarray['pos'][$totalarray['nbfield']] = 'f.total_vat';
  1459. }
  1460. $totalarray['val']['f.total_vat'] += $obj->total_vat;
  1461. }
  1462. // Amount LocalTax1
  1463. if (!empty($arrayfields['f.total_localtax1']['checked'])) {
  1464. print '<td class="right nowrap"><span class="amount">'.price($obj->total_localtax1)."</span></td>\n";
  1465. if (!$i) {
  1466. $totalarray['nbfield']++;
  1467. }
  1468. if (!$i) {
  1469. $totalarray['pos'][$totalarray['nbfield']] = 'f.total_localtax1';
  1470. }
  1471. $totalarray['val']['f.total_localtax1'] += $obj->total_localtax1;
  1472. }
  1473. // Amount LocalTax2
  1474. if (!empty($arrayfields['f.total_localtax2']['checked'])) {
  1475. print '<td class="right nowrap"><span class="amount">'.price($obj->total_localtax2)."</span></td>\n";
  1476. if (!$i) {
  1477. $totalarray['nbfield']++;
  1478. }
  1479. if (!$i) {
  1480. $totalarray['pos'][$totalarray['nbfield']] = 'f.total_localtax2';
  1481. }
  1482. $totalarray['val']['f.total_localtax2'] += $obj->total_localtax2;
  1483. }
  1484. // Amount TTC
  1485. if (!empty($arrayfields['f.total_ttc']['checked'])) {
  1486. print '<td class="right nowrap"><span class="amount">'.price($obj->total_ttc)."</span></td>\n";
  1487. if (!$i) {
  1488. $totalarray['nbfield']++;
  1489. }
  1490. if (!$i) {
  1491. $totalarray['pos'][$totalarray['nbfield']] = 'f.total_ttc';
  1492. }
  1493. $totalarray['val']['f.total_ttc'] += $obj->total_ttc;
  1494. }
  1495. $userstatic->id = $obj->fk_user_author;
  1496. $userstatic->login = $obj->login;
  1497. $userstatic->lastname = $obj->lastname;
  1498. $userstatic->firstname = $obj->firstname;
  1499. $userstatic->email = $obj->user_email;
  1500. $userstatic->statut = $obj->user_statut;
  1501. $userstatic->entity = $obj->entity;
  1502. $userstatic->photo = $obj->photo;
  1503. $userstatic->office_phone = $obj->office_phone;
  1504. $userstatic->office_fax = $obj->office_fax;
  1505. $userstatic->user_mobile = $obj->user_mobile;
  1506. $userstatic->job = $obj->job;
  1507. $userstatic->gender = $obj->gender;
  1508. // Author
  1509. if (!empty($arrayfields['u.login']['checked'])) {
  1510. print '<td class="tdoverflowmax200">';
  1511. if ($userstatic->id) {
  1512. print $userstatic->getLoginUrl(-1);
  1513. } else {
  1514. print '&nbsp;';
  1515. }
  1516. print "</td>\n";
  1517. if (!$i) {
  1518. $totalarray['nbfield']++;
  1519. }
  1520. }
  1521. if (!empty($arrayfields['dynamount_payed']['checked'])) {
  1522. print '<td class="right nowrap"><span class="amount">'.(!empty($totalpay) ?price($totalpay, 0, $langs) : '').'</span></td>'; // TODO Use a denormalized field
  1523. if (!$i) {
  1524. $totalarray['nbfield']++;
  1525. }
  1526. if (!$i) {
  1527. $totalarray['pos'][$totalarray['nbfield']] = 'totalam';
  1528. }
  1529. $totalarray['val']['totalam'] += $totalpay;
  1530. }
  1531. if (!empty($arrayfields['rtp']['checked'])) {
  1532. print '<td class="right nowrap">'.(!empty($remaintopay) ?price($remaintopay, 0, $langs) : '&nbsp;').'</td>'; // TODO Use a denormalized field
  1533. if (!$i) {
  1534. $totalarray['nbfield']++;
  1535. }
  1536. if (!$i) {
  1537. $totalarray['pos'][$totalarray['nbfield']] = 'rtp';
  1538. }
  1539. $totalarray['val']['rtp'] += $remaintopay;
  1540. }
  1541. // Currency
  1542. if (!empty($arrayfields['f.multicurrency_code']['checked'])) {
  1543. print '<td class="nowrap">'.$obj->multicurrency_code.' - '.$langs->trans('Currency'.$obj->multicurrency_code)."</td>\n";
  1544. if (!$i) {
  1545. $totalarray['nbfield']++;
  1546. }
  1547. }
  1548. // Currency rate
  1549. if (!empty($arrayfields['f.multicurrency_tx']['checked'])) {
  1550. print '<td class="nowrap">';
  1551. $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$obj->rowid, $obj->multicurrency_tx, 'none', $obj->multicurrency_code);
  1552. print "</td>\n";
  1553. if (!$i) {
  1554. $totalarray['nbfield']++;
  1555. }
  1556. }
  1557. // Amount HT
  1558. if (!empty($arrayfields['f.multicurrency_total_ht']['checked'])) {
  1559. print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_ht)."</span></td>\n";
  1560. if (!$i) {
  1561. $totalarray['nbfield']++;
  1562. }
  1563. }
  1564. // Amount VAT
  1565. if (!empty($arrayfields['f.multicurrency_total_vat']['checked'])) {
  1566. print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_vat)."</span></td>\n";
  1567. if (!$i) {
  1568. $totalarray['nbfield']++;
  1569. }
  1570. }
  1571. // Amount TTC
  1572. if (!empty($arrayfields['f.multicurrency_total_ttc']['checked'])) {
  1573. print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_ttc)."</span></td>\n";
  1574. if (!$i) {
  1575. $totalarray['nbfield']++;
  1576. }
  1577. }
  1578. if (!empty($arrayfields['multicurrency_dynamount_payed']['checked'])) {
  1579. print '<td class="right nowrap"><span class="amount">'.(!empty($multicurrency_totalpay) ?price($multicurrency_totalpay, 0, $langs) : '').'</span></td>'; // TODO Use a denormalized field
  1580. if (!$i) {
  1581. $totalarray['nbfield']++;
  1582. }
  1583. }
  1584. // Pending amount
  1585. if (!empty($arrayfields['multicurrency_rtp']['checked'])) {
  1586. print '<td class="right nowrap"><span class="amount">';
  1587. print (!empty($multicurrency_remaintopay) ? price($multicurrency_remaintopay, 0, $langs) : '');
  1588. print '</span></td>'; // TODO Use a denormalized field
  1589. if (!$i) {
  1590. $totalarray['nbfield']++;
  1591. }
  1592. }
  1593. // Extra fields
  1594. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  1595. // Fields from hook
  1596. $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  1597. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
  1598. print $hookmanager->resPrint;
  1599. // Date creation
  1600. if (!empty($arrayfields['f.datec']['checked'])) {
  1601. print '<td class="center nowrap">';
  1602. print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
  1603. print '</td>';
  1604. if (!$i) {
  1605. $totalarray['nbfield']++;
  1606. }
  1607. }
  1608. // Date modification
  1609. if (!empty($arrayfields['f.tms']['checked'])) {
  1610. print '<td class="center nowrap">';
  1611. print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser');
  1612. print '</td>';
  1613. if (!$i) {
  1614. $totalarray['nbfield']++;
  1615. }
  1616. }
  1617. // Status
  1618. if (!empty($arrayfields['f.fk_statut']['checked'])) {
  1619. print '<td class="right nowrap">';
  1620. print $facturestatic->LibStatut($obj->paye, $obj->fk_statut, 5, $paiement, $obj->type);
  1621. print "</td>";
  1622. if (!$i) {
  1623. $totalarray['nbfield']++;
  1624. }
  1625. }
  1626. // Action column
  1627. print '<td class="nowrap center">';
  1628. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  1629. $selected = 0;
  1630. if (in_array($obj->facid, $arrayofselected)) {
  1631. $selected = 1;
  1632. }
  1633. print '<input id="cb'.$obj->facid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->facid.'"'.($selected ? ' checked="checked"' : '').'>';
  1634. }
  1635. print '</td>';
  1636. if (!$i) {
  1637. $totalarray['nbfield']++;
  1638. }
  1639. print "</tr>\n";
  1640. $i++;
  1641. }
  1642. // Show total line
  1643. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  1644. }
  1645. $db->free($resql);
  1646. $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  1647. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters); // Note that $action and $object may have been modified by hook
  1648. print $hookmanager->resPrint;
  1649. print "</table>\n";
  1650. print '</div>';
  1651. print "</form>\n";
  1652. $hidegeneratedfilelistifempty = 1;
  1653. if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
  1654. $hidegeneratedfilelistifempty = 0;
  1655. }
  1656. // Show list of available documents
  1657. $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
  1658. $urlsource .= str_replace('&amp;', '&', $param);
  1659. $filedir = $diroutputmassaction;
  1660. $genallowed = $user->rights->facture->lire;
  1661. $delallowed = $user->rights->facture->creer;
  1662. $title = '';
  1663. print $formfile->showdocuments('massfilesarea_supplier_invoice', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
  1664. } else {
  1665. dol_print_error($db);
  1666. }
  1667. // End of page
  1668. llxFooter();
  1669. $db->close();