list.php 79 KB

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