dolibarr 21.0.0-beta
list.php
Go to the documentation of this file.
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-2024 Frédéric France <frederic.france@free.fr>
15 * Copyright (C) 2019-2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
16 * Copyright (C) 2023 Nick Fragoulis
17 * Copyright (C) 2023 Joachim Kueter <git-jk@bloxera.com>
18 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
19 *
20 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation; either version 3 of the License, or
23 * (at your option) any later version.
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
29 *
30 * You should have received a copy of the GNU General Public License
31 * along with this program. If not, see <https://www.gnu.org/licenses/>.
32 */
33
40// Load Dolibarr environment
41require '../../main.inc.php';
42require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
43require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
44require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
45require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
46require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
47require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
48require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
49require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
50require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
51require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
52
62// Load translation files required by the page
63$langs->loadLangs(array('products', 'bills', 'companies', 'projects'));
64
65$action = GETPOST('action', 'aZ09');
66$massaction = GETPOST('massaction', 'alpha');
67$show_files = GETPOSTINT('show_files');
68$confirm = GETPOST('confirm', 'alpha');
69$toselect = GETPOST('toselect', 'array');
70$optioncss = GETPOST('optioncss', 'alpha');
71$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'supplierinvoicelist';
72$mode = GETPOST('mode', 'aZ'); // The output mode ('list', 'kanban', 'hierarchy', 'calendar', ...)
73
74$search_all = trim(GETPOST('search_all', 'alphanohtml'));
75$search_label = GETPOST("search_label", "alpha");
76$search_amount_no_tax = GETPOST("search_amount_no_tax", "alpha");
77$search_amount_all_tax = GETPOST("search_amount_all_tax", "alpha");
78$search_ref = GETPOST('sf_ref') ? GETPOST('sf_ref', 'alpha') : GETPOST('search_ref', 'alpha');
79$search_refsupplier = GETPOST('search_refsupplier', 'alpha');
80$search_type = GETPOST('search_type', 'intcomma');
81$search_subtype = GETPOST('search_subtype', 'intcomma');
82$search_project = GETPOST('search_project', 'alpha');
83$search_company = GETPOST('search_company', 'alpha');
84$search_company_alias = GETPOST('search_company_alias', 'alpha');
85$search_montant_ht = GETPOST('search_montant_ht', 'alpha');
86$search_montant_vat = GETPOST('search_montant_vat', 'alpha');
87$search_montant_localtax1 = GETPOST('search_montant_localtax1', 'alpha');
88$search_montant_localtax2 = GETPOST('search_montant_localtax2', 'alpha');
89$search_montant_ttc = GETPOST('search_montant_ttc', 'alpha');
90$search_login = GETPOST('search_login', 'alpha');
91$search_multicurrency_code = GETPOST('search_multicurrency_code', 'alpha');
92$search_multicurrency_tx = GETPOST('search_multicurrency_tx', 'alpha');
93$search_multicurrency_montant_ht = GETPOST('search_multicurrency_montant_ht', 'alpha');
94$search_multicurrency_montant_vat = GETPOST('search_multicurrency_montant_vat', 'alpha');
95$search_multicurrency_montant_ttc = GETPOST('search_multicurrency_montant_ttc', 'alpha');
96$search_status = GETPOST('search_status', 'intcomma'); // Can be '' or a numeric
97$search_paymentmode = GETPOST('search_paymentmode', 'intcomma');
98$search_paymentcond = GETPOST('search_paymentcond', 'intcomma');
99$search_town = GETPOST('search_town', 'alpha');
100$search_zip = GETPOST('search_zip', 'alpha');
101$search_state = GETPOST("search_state");
102$search_country = GETPOST("search_country", 'aZ09');
103$search_type_thirdparty = GETPOST("search_type_thirdparty", 'intcomma');
104$search_user = GETPOST('search_user', 'intcomma');
105$search_sale = GETPOST('search_sale', 'intcomma');
106$search_date_start = GETPOSTDATE('search_date_start', '', 'tzserver');
107$search_date_end = GETPOSTDATE('search_date_end', '23:59:59', 'tzserver');
108$search_datelimit_startday = GETPOSTINT('search_datelimit_startday');
109$search_datelimit_startmonth = GETPOSTINT('search_datelimit_startmonth');
110$search_datelimit_startyear = GETPOSTINT('search_datelimit_startyear');
111$search_datelimit_endday = GETPOSTINT('search_datelimit_endday');
112$search_datelimit_endmonth = GETPOSTINT('search_datelimit_endmonth');
113$search_datelimit_endyear = GETPOSTINT('search_datelimit_endyear');
114$search_datelimit_start = dol_mktime(0, 0, 0, $search_datelimit_startmonth, $search_datelimit_startday, $search_datelimit_startyear);
115$search_datelimit_end = dol_mktime(23, 59, 59, $search_datelimit_endmonth, $search_datelimit_endday, $search_datelimit_endyear);
116$search_categ_sup = GETPOST("search_categ_sup", 'intcomma');
117$search_product_category = GETPOST('search_product_category', 'intcomma');
118$search_fk_fac_rec_source = GETPOST('search_fk_fac_rec_source', 'int');
119
120$option = GETPOST('search_option');
121if ($option == 'late') {
122 $search_status = '1';
123}
124$filter = GETPOST('filtre', 'alpha');
125
126// Load variable for pagination
127$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
128$sortfield = GETPOST('sortfield', 'aZ09comma');
129$sortorder = GETPOST('sortorder', 'aZ09comma');
130$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
131if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
132 // If $page is not defined, or '' or -1 or if we click on clear filters
133 $page = 0;
134}
135$offset = $limit * $page;
136if (!$sortorder) {
137 $sortorder = "DESC";
138}
139if (!$sortfield) {
140 $sortfield = "f.datef,f.rowid";
141}
142$pageprev = $page - 1;
143$pagenext = $page + 1;
144
145$socid = GETPOSTINT('socid');
146
147// Security check
148if ($user->socid > 0) {
149 $action = '';
150 $socid = $user->socid;
151}
152
153$diroutputmassaction = $conf->fournisseur->facture->dir_output.'/temp/massgeneration/'.$user->id;
154
155$now = dol_now();
156
157// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
158$object = new FactureFournisseur($db);
159$hookmanager->initHooks(array('supplierinvoicelist'));
160$extrafields = new ExtraFields($db);
161
162// Fetch optionals attributes and labels
163$extrafields->fetch_name_optionals_label($object->table_element);
164
165$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
166
167// List of fields to search into when doing a "search in all"
168$fieldstosearchall = array(
169 'f.ref' => 'Ref',
170 'f.ref_supplier' => 'RefSupplier',
171 'f.note_public' => 'NotePublic',
172 's.nom' => "ThirdParty",
173 's.code_fournisseur' => "SupplierCodeShort",
174 'pd.description' => 'Description',
175);
176if (empty($user->socid)) {
177 $fieldstosearchall["f.note_private"] = "NotePrivate";
178}
179
180$checkedtypetiers = 0;
181$arrayfields = array(
182 'f.ref' => array('label' => "Ref", 'checked' => 1, 'position' => 5),
183 'f.ref_supplier' => array('label' => "RefSupplier", 'checked' => 1, 'position' => 7),
184 'f.type' => array('label' => "Type", 'checked' => 0, 'position' => 15),
185 'f.subtype' => array('label' => "InvoiceSubtype", 'checked' => 0, 'position' => 17),
186 'f.label' => array('label' => "Label", 'checked' => 0, 'position' => 20),
187 'f.datef' => array('label' => "DateInvoice", 'checked' => 1, 'position' => 25),
188 'f.date_lim_reglement' => array('label' => "DateDue", 'checked' => 1, 'position' => 27),
189 'p.ref' => array('label' => "ProjectRef", 'checked' => 0, 'position' => 30),
190 's.nom' => array('label' => "ThirdParty", 'checked' => 1, 'position' => 41),
191 's.name_alias' => array('label' => "AliasNameShort", 'checked' => 0, 'position' => 42),
192 's.town' => array('label' => "Town", 'checked' => -1, 'position' => 43),
193 's.zip' => array('label' => "Zip", 'checked' => -1, 'position' => 44),
194 'state.nom' => array('label' => "StateShort", 'checked' => 0, 'position' => 45),
195 'country.code_iso' => array('label' => "Country", 'checked' => 0, 'position' => 46),
196 'typent.code' => array('label' => "ThirdPartyType", 'checked' => $checkedtypetiers, 'position' => 49),
197 'f.fk_mode_reglement' => array('label' => "PaymentMode", 'checked' => 1, 'position' => 52),
198 'f.fk_cond_reglement' => array('label' => "PaymentConditionsShort", 'checked' => 1, 'position' => 50),
199 'f.total_ht' => array('label' => "AmountHT", 'checked' => 1, 'position' => 105),
200 'f.total_vat' => array('label' => "AmountVAT", 'checked' => 0, 'position' => 110),
201 'f.total_localtax1' => array('label' => $langs->transcountry("AmountLT1", $mysoc->country_code), 'checked' => 0, 'enabled' => $mysoc->localtax1_assuj == "1", 'position' => 95),
202 'f.total_localtax2' => array('label' => $langs->transcountry("AmountLT2", $mysoc->country_code), 'checked' => 0, 'enabled' => $mysoc->localtax2_assuj == "1", 'position' => 100),
203 'f.total_ttc' => array('label' => "AmountTTC", 'checked' => 1, 'position' => 115),
204 'dynamount_payed' => array('label' => "Paid", 'checked' => 0, 'position' => 116),
205 'rtp' => array('label' => "Rest", 'checked' => 0, 'position' => 117),
206 'f.multicurrency_code' => array('label' => 'Currency', 'checked' => 0, 'position' => 205, 'enabled' => (!isModEnabled("multicurrency") ? 0 : 1)),
207 'f.multicurrency_tx' => array('label' => 'CurrencyRate', 'checked' => 0, 'position' => 206, 'enabled' => (!isModEnabled("multicurrency") ? 0 : 1)),
208 'f.multicurrency_total_ht' => array('label' => 'MulticurrencyAmountHT', 'position' => 207, 'checked' => 0, 'enabled' => (!isModEnabled("multicurrency") ? 0 : 1)),
209 'f.multicurrency_total_vat' => array('label' => 'MulticurrencyAmountVAT', 'position' => 208, 'checked' => 0, 'enabled' => (!isModEnabled("multicurrency") ? 0 : 1)),
210 'f.multicurrency_total_ttc' => array('label' => 'MulticurrencyAmountTTC', 'position' => 209, 'checked' => 0, 'enabled' => (!isModEnabled("multicurrency") ? 0 : 1)),
211 'multicurrency_dynamount_payed' => array('label' => 'MulticurrencyAlreadyPaid', 'position' => 210, 'checked' => 0, 'enabled' => (!isModEnabled("multicurrency") ? 0 : 1)),
212 'multicurrency_rtp' => array('label' => 'MulticurrencyRemainderToPay', 'checked' => 0, 'position' => 211, 'enabled' => (!isModEnabled("multicurrency") ? 0 : 1)), // Not enabled by default because slow
213 'u.login' => array('label' => "Author", 'checked' => -1, 'position' => 500),
214 'f.datec' => array('label' => "DateCreation", 'checked' => 0, 'position' => 501),
215 'f.tms' => array('label' => "DateModificationShort", 'checked' => 0, 'position' => 502),
216 'f.nb_docs' => array('label' => "Documents", 'checked' => -1, 'position' => 510),
217 'f.fk_statut' => array('label' => "Status", 'checked' => 1, 'position' => 1000),
218);
219// Extra fields
220include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
221
222$subtypearray = $object->getArrayOfInvoiceSubtypes(0);
223if (empty($subtypearray)) {
224 unset($arrayfields['f.subtype']);
225}
226
227$object->fields = dol_sort_array($object->fields, 'position');
228$arrayfields = dol_sort_array($arrayfields, 'position');
229'@phan-var-force array<string,array{label:string,checked?:int<0,1>,position?:int,help?:string}> $arrayfields'; // dol_sort_array looses type for Phan
230
231if (!isModEnabled('supplier_invoice')) {
233}
234if ((!$user->hasRight("fournisseur", "facture", "lire") && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD'))
235 || (!$user->hasRight("supplier_invoice", "lire") && getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD'))) {
237}
238
239if (!$user->hasRight('societe', 'client', 'voir')) {
240 $search_sale = $user->id;
241}
242
243$permissiontoread = ($user->hasRight("fournisseur", "facture", "lire") || $user->hasRight("supplier_invoice", "lire"));
244$permissiontoadd = ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer"));
245$permissiontodelete = ($user->hasRight("fournisseur", "facture", "supprimer") || $user->hasRight("supplier_invoice", "supprimer"));
246
247
248/*
249 * Actions
250 */
251$error = 0;
252if (GETPOST('cancel', 'alpha')) {
253 $action = 'list';
254 $massaction = '';
255}
256if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
257 $massaction = '';
258}
259
260$parameters = array('socid' => $socid, 'arrayfields' => &$arrayfields);
261$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
262if ($reshook < 0) {
263 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
264}
265
266if (empty($reshook)) {
267 // Selection of new fields
268 include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
269
270 // Purge search criteria
271 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
272 $search_all = "";
273 $search_user = '';
274 $search_sale = '';
275 $search_product_category = '';
276 $search_ref = "";
277 $search_refsupplier = "";
278 $search_type = "";
279 $search_subtype = '';
280 $search_label = "";
281 $search_project = '';
282 $search_company = "";
283 $search_company_alias = "";
284 $search_amount_no_tax = "";
285 $search_amount_all_tax = "";
286 $search_montant_ht = '';
287 $search_montant_vat = '';
288 $search_montant_localtax1 = '';
289 $search_montant_localtax2 = '';
290 $search_montant_ttc = '';
291 $search_login = '';
292 $search_multicurrency_code = '';
293 $search_multicurrency_tx = '';
294 $search_multicurrency_montant_ht = '';
295 $search_multicurrency_montant_vat = '';
296 $search_multicurrency_montant_ttc = '';
297 $search_status = '';
298 $search_paymentmode = '';
299 $search_paymentcond = '';
300 $search_town = '';
301 $search_zip = "";
302 $search_state = "";
303 $search_country = '';
304 $search_type_thirdparty = '';
305 $search_date_start = '';
306 $search_date_end = '';
307 $search_datelimit_startday = '';
308 $search_datelimit_startmonth = '';
309 $search_datelimit_startyear = '';
310 $search_datelimit_endday = '';
311 $search_datelimit_endmonth = '';
312 $search_datelimit_endyear = '';
313 $search_datelimit_start = '';
314 $search_datelimit_end = '';
315 $toselect = array();
316 $search_array_options = array();
317 $search_categ_sup = 0;
318 $filter = '';
319 $option = '';
320 $socid = "";
321 }
322
323 // Mass actions
324 $objectclass = 'FactureFournisseur';
325 $objectlabel = 'SupplierInvoices';
326
327 $uploaddir = $conf->fournisseur->facture->dir_output;
328
329 include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
330
331 if ($massaction == 'banktransfertrequest') {
332 $langs->load("withdrawals");
333
334 if (!$user->hasRight("paymentbybanktransfer", "create")) {
335 $error++;
336 setEventMessages($langs->trans("NotEnoughPermissions"), null, 'errors');
337 } else {
338 //Checking error
339 $error = 0;
340
341 $arrayofselected = is_array($toselect) ? $toselect : array();
342 $listofbills = array();
343 foreach ($arrayofselected as $toselectid) {
344 $objecttmp = new FactureFournisseur($db);
345 $result = $objecttmp->fetch($toselectid);
346 if ($result > 0) {
347 $totalpaid = $objecttmp->getSommePaiement();
348 $totalcreditnotes = $objecttmp->getSumCreditNotesUsed();
349 $totaldeposits = $objecttmp->getSumDepositsUsed();
350 $objecttmp->resteapayer = price2num($objecttmp->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits, 'MT');
351
352 // hook to finalize the remaining amount, considering e.g. cash discount agreements
353 $parameters = array('remaintopay' => $objecttmp->resteapayer);
354 $reshook = $hookmanager->executeHooks('finalizeAmountOfInvoice', $parameters, $objecttmp, $action); // Note that $action and $object may have been modified by some hooks
355 if ($reshook > 0) {
356 // print $hookmanager->resPrint;
357 if (!empty($remaintopay = $hookmanager->resArray['remaintopay'])) {
358 $objecttmp->resteapayer = $remaintopay;
359 }
360 } elseif ($reshook < 0) {
361 $error++;
362 setEventMessages($objecttmp->ref.' '.$langs->trans("ProcessingError"), $hookmanager->errors, 'errors');
363 }
364
365 if ($objecttmp->status == FactureFournisseur::STATUS_DRAFT) {
366 $error++;
367 setEventMessages($objecttmp->ref.' '.$langs->trans("Draft"), $objecttmp->errors, 'errors');
368 } elseif ($objecttmp->paid || $objecttmp->resteapayer == 0) {
369 $error++;
370 setEventMessages($objecttmp->ref.' '.$langs->trans("AlreadyPaid"), $objecttmp->errors, 'errors');
371 } elseif ($objecttmp->resteapayer < 0) {
372 $error++;
373 setEventMessages($objecttmp->ref.' '.$langs->trans("AmountMustBePositive"), $objecttmp->errors, 'errors');
374 }
375
376 $rsql = "SELECT pfd.rowid, pfd.traite, pfd.date_demande as date_demande";
377 $rsql .= " , pfd.date_traite as date_traite";
378 $rsql .= " , pfd.amount";
379 $rsql .= " , u.rowid as user_id, u.lastname, u.firstname, u.login";
380 $rsql .= " FROM ".MAIN_DB_PREFIX."prelevement_demande as pfd";
381 $rsql .= " , ".MAIN_DB_PREFIX."user as u";
382 $rsql .= " WHERE fk_facture_fourn = ".((int) $objecttmp->id);
383 $rsql .= " AND pfd.fk_user_demande = u.rowid";
384 $rsql .= " AND pfd.traite = 0";
385 $rsql .= " ORDER BY pfd.date_demande DESC";
386
387 $result_sql = $db->query($rsql);
388 if ($result_sql) {
389 $numprlv = $db->num_rows($result_sql);
390 }
391
392 if ($numprlv > 0) {
393 $error++;
394 setEventMessages($objecttmp->ref.' '.$langs->trans("RequestAlreadyDone"), $objecttmp->errors, 'warnings');
395 } elseif (!empty($objecttmp->mode_reglement_code) && $objecttmp->mode_reglement_code != 'VIR') {
396 $langs->load("errors");
397 $error++;
398 setEventMessages($objecttmp->ref.' '.$langs->trans("ErrorThisPaymentModeIsNotCreditTransfer"), $objecttmp->errors, 'errors');
399 } else {
400 $listofbills[] = $objecttmp; // $listofbills will only contains invoices with good payment method and no request already done
401 }
402 }
403 }
404
405 // Massive withdraw request for request with no errors
406 if (!empty($listofbills)) {
407 $nbwithdrawrequestok = 0;
408 foreach ($listofbills as $aBill) {
409 $db->begin();
410 $result = $aBill->demande_prelevement($user, $aBill->resteapayer, 'bank-transfer', 'supplier_invoice');
411 if ($result > 0) {
412 $db->commit();
413 $nbwithdrawrequestok++;
414 } else {
415 $db->rollback();
416 setEventMessages($aBill->error, $aBill->errors, 'errors');
417 }
418 }
419 if ($nbwithdrawrequestok > 0) {
420 setEventMessages($langs->trans("WithdrawRequestsDone", $nbwithdrawrequestok), null, 'mesgs');
421 }
422 }
423 }
424 }
425}
426
427
428/*
429 * View
430 */
431
432$form = new Form($db);
433$formother = new FormOther($db);
434$formfile = new FormFile($db);
435$bankaccountstatic = new Account($db);
436$facturestatic = new FactureFournisseur($db);
437$formcompany = new FormCompany($db);
438$thirdparty = new Societe($db);
439$subtypearray = $object->getArrayOfInvoiceSubtypes(0);
440$now = dol_now();
441
442if ($socid > 0) {
443 $soc = new Societe($db);
444 $soc->fetch($socid);
445 if (empty($search_company)) {
446 $search_company = $soc->name;
447 }
448}
449
450$title = $langs->trans("BillsSuppliers").($socid ? ' - '.$soc->name : '');
451$help_url = 'EN:Suppliers_Invoices|FR:FactureFournisseur|ES:Facturas_de_proveedores';
452
453// Build and execute select
454// --------------------------------------------------------------------
455$sql = "SELECT";
456if ($search_all) {
457 $sql = 'SELECT DISTINCT';
458}
459$sql .= " f.rowid as facid, f.ref, f.ref_supplier, f.type, f.subtype, f.datef, f.date_lim_reglement as datelimite, f.fk_mode_reglement, f.fk_cond_reglement,";
460$sql .= " f.total_ht, f.total_ttc, f.total_tva as total_vat, f.paye as paye, f.close_code, f.fk_statut as fk_statut, f.libelle as label, f.datec as date_creation, f.tms as date_modification,";
461$sql .= " f.localtax1 as total_localtax1, f.localtax2 as total_localtax2,";
462$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,';
463$sql .= " f.note_public, f.note_private,";
464$sql .= " f.fk_user_author,";
465$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,";
466$sql .= " typent.code as typent_code,";
467$sql .= " state.code_departement as state_code, state.nom as state_name,";
468$sql .= " country.code as country_code,";
469$sql .= " p.rowid as project_id, p.ref as project_ref, p.title as project_label,";
470$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';
471// Add fields from extrafields
472if (!empty($extrafields->attributes[$object->table_element]['label'])) {
473 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
474 $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
475 }
476}
477// Add fields from hooks
478$parameters = array();
479$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
480$sql .= $hookmanager->resPrint;
481$sql = preg_replace('/,\s*$/', '', $sql);
482
483// 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)
484// TODO Better solution to be able to sort on already paid or remain to pay is to store amount_payed in a denormalized field.
485if (!$search_all) {
486 $sql .= ', SUM(pf.amount) as dynamount_payed';
487}
488
489$sqlfields = $sql; // $sql fields to remove for count total
490
491$sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s';
492$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
493$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
494$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)";
495$sql .= ', '.MAIN_DB_PREFIX.'facture_fourn as f';
496if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
497 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (f.rowid = ef.fk_object)";
498}
499if (!$search_all) {
500 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf ON pf.fk_facturefourn = f.rowid';
501}
502if ($search_all) {
503 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture_fourn_det as pd ON f.rowid=pd.fk_facture_fourn';
504}
505$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user AS u ON f.fk_user_author = u.rowid';
506$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as p ON p.rowid = f.fk_projet";
507if ($search_user > 0) {
508 $sql .= ", ".MAIN_DB_PREFIX."element_contact as ec";
509 $sql .= ", ".MAIN_DB_PREFIX."c_type_contact as tc";
510}
511// Add table from hooks
512$parameters = array();
513$reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
514$sql .= $hookmanager->resPrint;
515$sql .= ' WHERE f.fk_soc = s.rowid';
516$sql .= ' AND f.entity IN ('.getEntity('facture_fourn').')';
517if ($socid > 0) {
518 $sql .= ' AND s.rowid = '.((int) $socid);
519}
520if ($search_ref) {
521 if (is_numeric($search_ref)) {
522 $sql .= natural_search(array('f.ref'), $search_ref);
523 } else {
524 $sql .= natural_search('f.ref', $search_ref);
525 }
526}
527if ($search_ref) {
528 $sql .= natural_search('f.ref', $search_ref);
529}
530if ($search_refsupplier) {
531 $sql .= natural_search('f.ref_supplier', $search_refsupplier);
532}
533if ($search_type != '' && $search_type >= 0) {
534 if ($search_type == '0') {
535 $sql .= " AND f.type = 0"; // standard
536 }
537 if ($search_type == '1') {
538 $sql .= " AND f.type = 1"; // replacement
539 }
540 if ($search_type == '2') {
541 $sql .= " AND f.type = 2"; // credit note
542 }
543 if ($search_type == '3') {
544 $sql .= " AND f.type = 3"; // deposit
545 }
546 //if ($search_type == '4') $sql.=" AND f.type = 4"; // proforma
547 //if ($search_type == '5') $sql.=" AND f.type = 5"; // situation
548}
549if ($search_subtype != '' && $search_subtype != '-1') {
550 $sql .= " AND f.subtype IN (".$db->sanitize($db->escape($search_subtype)).")";
551}
552if ($search_project) {
553 $sql .= natural_search('p.ref', $search_project);
554}
555if (empty($arrayfields['s.name_alias']['checked']) && $search_company) {
556 $sql .= natural_search(array("s.nom", "s.name_alias"), $search_company);
557} else {
558 if ($search_company) {
559 $sql .= natural_search('s.nom', $search_company);
560 }
561 if ($search_company_alias) {
562 $sql .= natural_search('s.name_alias', $search_company_alias);
563 }
564}
565if ($search_town) {
566 $sql .= natural_search('s.town', $search_town);
567}
568if ($search_zip) {
569 $sql .= natural_search("s.zip", $search_zip);
570}
571if ($search_state) {
572 $sql .= natural_search("state.nom", $search_state);
573}
574if (strlen(trim($search_country))) {
575 $arrayofcode = getCountriesInEEC();
576 $country_code_in_EEC = $country_code_in_EEC_without_me = '';
577 foreach ($arrayofcode as $key => $value) {
578 $country_code_in_EEC .= ($country_code_in_EEC ? "," : "")."'".$value."'";
579 if ($value != $mysoc->country_code) {
580 $country_code_in_EEC_without_me .= ($country_code_in_EEC_without_me ? "," : "")."'".$value."'";
581 }
582 }
583 if ($search_country == 'special_allnotme') {
584 $sql .= " AND country.code <> '".$db->escape($mysoc->country_code)."'";
585 } elseif ($search_country == 'special_eec') {
586 $sql .= " AND country.code IN (".$db->sanitize($country_code_in_EEC, 1).")";
587 } elseif ($search_country == 'special_eecnotme') {
588 $sql .= " AND country.code IN (".$db->sanitize($country_code_in_EEC_without_me, 1).")";
589 } elseif ($search_country == 'special_noteec') {
590 $sql .= " AND country.code NOT IN (".$db->sanitize($country_code_in_EEC, 1).")";
591 } else {
592 $sql .= natural_search("country.code", $search_country);
593 }
594}
595if ($search_type_thirdparty != '' && $search_type_thirdparty >= 0) {
596 $sql .= " AND s.fk_typent IN (".$db->sanitize($search_type_thirdparty).')';
597}
598if ($search_montant_ht != '') {
599 $sql .= natural_search('f.total_ht', $search_montant_ht, 1);
600}
601if ($search_montant_vat != '') {
602 $sql .= natural_search('f.total_tva', $search_montant_vat, 1);
603}
604if ($search_montant_localtax1 != '') {
605 $sql .= natural_search('f.localtax1', $search_montant_localtax1, 1);
606}
607if ($search_montant_localtax2 != '') {
608 $sql .= natural_search('f.localtax2', $search_montant_localtax2, 1);
609}
610if ($search_montant_ttc != '') {
611 $sql .= natural_search('f.total_ttc', $search_montant_ttc, 1);
612}
613if ($search_multicurrency_code != '') {
614 $sql .= " AND f.multicurrency_code = '".$db->escape($search_multicurrency_code)."'";
615}
616if ($search_multicurrency_tx != '') {
617 $sql .= natural_search('f.multicurrency_tx', $search_multicurrency_tx, 1);
618}
619if ($search_multicurrency_montant_ht != '') {
620 $sql .= natural_search('f.multicurrency_total_ht', $search_multicurrency_montant_ht, 1);
621}
622if ($search_multicurrency_montant_vat != '') {
623 $sql .= natural_search('f.multicurrency_total_tva', $search_multicurrency_montant_vat, 1);
624}
625if ($search_multicurrency_montant_ttc != '') {
626 $sql .= natural_search('f.multicurrency_total_ttc', $search_multicurrency_montant_ttc, 1);
627}
628if ($search_login) {
629 $sql .= natural_search(array('u.login', 'u.lastname', 'u.firstname'), $search_login);
630}
631if ($search_status != '' && $search_status >= 0) {
632 $sql .= " AND f.fk_statut = ".((int) $search_status);
633}
634if ($search_paymentmode > 0) {
635 $sql .= " AND f.fk_mode_reglement = ".((int) $search_paymentmode);
636}
637if ($search_paymentcond > 0) {
638 $sql .= " AND f.fk_cond_reglement = ".((int) $search_paymentcond);
639}
640if ($search_date_start) {
641 $sql .= " AND f.datef >= '" . $db->idate($search_date_start) . "'";
642}
643if ($search_date_end) {
644 $sql .= " AND f.datef <= '" . $db->idate($search_date_end) . "'";
645}
646if ($search_datelimit_start) {
647 $sql .= " AND f.date_lim_reglement >= '" . $db->idate($search_datelimit_start) . "'";
648}
649if ($search_datelimit_end) {
650 $sql .= " AND f.date_lim_reglement <= '" . $db->idate($search_datelimit_end) . "'";
651}
652if ($option == 'late') {
653 $sql .= " AND f.date_lim_reglement < '".$db->idate(dol_now() - $conf->facture->fournisseur->warning_delay)."'";
654}
655if ($search_label) {
656 $sql .= natural_search('f.libelle', $search_label);
657}
658if ($search_fk_fac_rec_source) {
659 $sql .= " AND f.fk_fac_rec_source = ".(int) $search_fk_fac_rec_source;
660}
661// Search on sale representative
662if ($search_sale && $search_sale != '-1') {
663 if ($search_sale == -2) {
664 $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = f.fk_soc)";
665 } elseif ($search_sale > 0) {
666 $sql .= " AND EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = f.fk_soc AND sc.fk_user = ".((int) $search_sale).")";
667 }
668}
669$searchCategorySupplierList = $search_categ_sup ? array($search_categ_sup) : array();
670$searchCategorySupplierOperator = 0;
671// Search for tag/category ($searchCategorySupplierList is an array of ID)
672if (!empty($searchCategorySupplierList)) {
673 $searchCategorySupplierSqlList = array();
674 $listofcategoryid = '';
675 foreach ($searchCategorySupplierList as $searchCategorySupplier) {
676 if (intval($searchCategorySupplier) == -2) {
677 $searchCategorySupplierSqlList[] = "NOT EXISTS (SELECT ck.fk_soc FROM ".MAIN_DB_PREFIX."categorie_fournisseur as ck WHERE s.rowid = ck.fk_soc)";
678 } elseif (intval($searchCategorySupplier) > 0) {
679 if ($searchCategorySupplierOperator == 0) {
680 $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).")";
681 } else {
682 $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategorySupplier);
683 }
684 }
685 }
686 if ($listofcategoryid) {
687 $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)."))";
688 }
689 if ($searchCategorySupplierOperator == 1) {
690 if (!empty($searchCategorySupplierSqlList)) {
691 $sql .= " AND (".implode(' OR ', $searchCategorySupplierSqlList).")";
692 }
693 } else {
694 if (!empty($searchCategorySupplierSqlList)) {
695 $sql .= " AND (".implode(' AND ', $searchCategorySupplierSqlList).")";
696 }
697 }
698}
699// Search for tag/category ($searchCategoryProductList is an array of ID)
700$searchCategoryProductList = $search_product_category ? array($search_product_category) : array();
701$searchCategoryProductOperator = 0;
702if (!empty($searchCategoryProductList)) {
703 $searchCategoryProductSqlList = array();
704 $listofcategoryid = '';
705 foreach ($searchCategoryProductList as $searchCategoryProduct) {
706 if (intval($searchCategoryProduct) == -2) {
707 $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 fd.fk_product = ck.fk_product)";
708 } elseif (intval($searchCategoryProduct) > 0) {
709 if ($searchCategoryProductOperator == 0) {
710 $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 fd.fk_product = ck.fk_product AND ck.fk_categorie = ".((int) $searchCategoryProduct).")";
711 } else {
712 $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryProduct);
713 }
714 }
715 }
716 if ($listofcategoryid) {
717 $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 fd.fk_product = ck.fk_product AND ck.fk_categorie IN (".$db->sanitize($listofcategoryid)."))";
718 }
719 if ($searchCategoryProductOperator == 1) {
720 if (!empty($searchCategoryProductSqlList)) {
721 $sql .= " AND (".implode(' OR ', $searchCategoryProductSqlList).")";
722 }
723 } else {
724 if (!empty($searchCategoryProductSqlList)) {
725 $sql .= " AND (".implode(' AND ', $searchCategoryProductSqlList).")";
726 }
727 }
728}
729if ($filter && $filter != -1) {
730 $aFilter = explode(',', $filter);
731 foreach ($aFilter as $fil) {
732 $filt = explode(':', $fil);
733 $sql .= " AND ".$db->escape(trim($filt[0]))." = '".$db->escape(trim($filt[1]))."'";
734 }
735}
736/*
737if ($search_sale > 0) {
738 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $search_sale);
739}*/
740if ($search_user > 0) {
741 $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);
742}
743// Add where from extra fields
744include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
745// Add where from hooks
746$parameters = array();
747$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
748$sql .= $hookmanager->resPrint;
749
750if (!$search_all) {
751 $sql .= " GROUP BY f.rowid, f.ref, f.ref_supplier, f.type, f.subtype, f.datef, f.date_lim_reglement, f.fk_mode_reglement, f.fk_cond_reglement,";
752 $sql .= " f.total_ht, f.total_ttc, f.total_tva, f.paye, f.close_code, f.fk_statut, f.libelle, f.datec, f.tms,";
753 $sql .= " f.localtax1, f.localtax2,";
754 $sql .= ' f.fk_multicurrency, f.multicurrency_code, f.multicurrency_tx, f.multicurrency_total_ht, f.multicurrency_total_tva, f.multicurrency_total_ttc,';
755 $sql .= " f.note_public, f.note_private,";
756 $sql .= " f.fk_user_author,";
757 $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,';
758 $sql .= " typent.code,";
759 $sql .= " state.code_departement, state.nom,";
760 $sql .= ' country.code,';
761 $sql .= " p.rowid, p.ref, p.title,";
762 $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";
763 if (!empty($extrafields->attributes[$object->table_element]['label'])) {
764 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
765 //prevent error with sql_mode=only_full_group_by
766 $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ",ef.".$key : '');
767 }
768 }
769 // Add GroupBy from hooks
770 $parameters = array('all' => $search_all, 'fieldstosearchall' => $fieldstosearchall);
771 $reshook = $hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
772 $sql .= $hookmanager->resPrint;
773} else {
774 $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
775}
776
777// Add HAVING from hooks
778$parameters = array();
779$reshook = $hookmanager->executeHooks('printFieldListHaving', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
780$sql .= empty($hookmanager->resPrint) ? "" : " HAVING 1=1 ".$hookmanager->resPrint;
781
782// Count total nb of records
783$nbtotalofrecords = '';
784if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
785 /* The fast and low memory method to get and count full list converts the sql into a sql count */
786 $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
787 $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
788 $sqlforcount = preg_replace('/LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf ON pf.fk_facturefourn = f.rowid/', '', $sqlforcount);
789
790 $resql = $db->query($sqlforcount);
791 if ($resql) {
792 $objforcount = $db->fetch_object($resql);
793 $nbtotalofrecords = $objforcount->nbtotalofrecords;
794 } else {
795 dol_print_error($db);
796 }
797
798 if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller than the paging size (filtering), goto and load page 0
799 $page = 0;
800 $offset = 0;
801 }
802 $db->free($resql);
803}
804
805// Complete request and execute it with limit
806$sql .= $db->order($sortfield, $sortorder);
807if ($limit) {
808 $sql .= $db->plimit($limit + 1, $offset);
809}
810//print $sql;
811
812$resql = $db->query($sql);
813if (!$resql) {
814 dol_print_error($db);
815 exit;
816}
817
818$num = $db->num_rows($resql);
819
820// Direct jump if only one record found
821if ($num == 1 && getDolGlobalInt('MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE') && $search_all && !$page) {
822 $obj = $db->fetch_object($resql);
823 $id = $obj->facid;
824 header("Location: ".DOL_URL_ROOT.'/fourn/facture/card.php?facid='.$id);
825 exit;
826}
827
828// Output page
829// --------------------------------------------------------------------
830
831llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'bodyforlist mod-fourn-facture page-list');
832
833if ($search_fk_fac_rec_source) {
834 require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.facture-rec.class.php';
835 require_once DOL_DOCUMENT_ROOT . '/core/lib/invoice.lib.php';
837 $object->fetch((int) $search_fk_fac_rec_source);
838
839 $head = supplier_invoice_rec_prepare_head($object);
840 print dol_get_fiche_head($head, 'generated', $langs->trans('InvoicesGeneratedFromRec'), -1, 'bill'); // Add a div
841}
842
843if ($socid) {
844 $soc = new Societe($db);
845 $soc->fetch($socid);
846 if (empty($search_company)) {
847 $search_company = $soc->name;
848 $search_company_alias = $soc->name_alias;
849 }
850}
851
852$arrayofselected = is_array($toselect) ? $toselect : array();
853
854$param = '&socid='.$socid;
855if (!empty($mode)) {
856 $param .= '&mode='.urlencode($mode);
857}
858if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
859 $param .= '&contextpage='.urlencode($contextpage);
860}
861if ($limit > 0 && $limit != $conf->liste_limit) {
862 $param .= '&limit='.((int) $limit);
863}
864if ($optioncss != '') {
865 $param .= '&optioncss='.urlencode($optioncss);
866}
867if ($search_all) {
868 $param .= '&search_all='.urlencode($search_all);
869}
870if ($search_date_start) {
871 $param .= buildParamDate('search_date_start', null, '', 'tzserver');
872}
873if ($search_date_end) {
874 $param .= buildParamDate('search_date_end', null, '', 'tzserver');
875}
876if ($search_datelimit_startday) {
877 $param .= '&search_datelimit_startday='.urlencode((string) ($search_datelimit_startday));
878}
879if ($search_datelimit_startmonth) {
880 $param .= '&search_datelimit_startmonth='.urlencode((string) ($search_datelimit_startmonth));
881}
882if ($search_datelimit_startyear) {
883 $param .= '&search_datelimit_startyear='.urlencode((string) ($search_datelimit_startyear));
884}
885if ($search_datelimit_endday) {
886 $param .= '&search_datelimit_endday='.urlencode((string) ($search_datelimit_endday));
887}
888if ($search_datelimit_endmonth) {
889 $param .= '&search_datelimit_endmonth='.urlencode((string) ($search_datelimit_endmonth));
890}
891if ($search_datelimit_endyear) {
892 $param .= '&search_datelimit_endyear='.urlencode((string) ($search_datelimit_endyear));
893}
894if ($search_ref) {
895 $param .= '&search_ref='.urlencode($search_ref);
896}
897if ($search_refsupplier) {
898 $param .= '&search_refsupplier='.urlencode($search_refsupplier);
899}
900if ($search_type != '') {
901 $param .= '&search_type='.urlencode($search_type);
902}
903if ($search_subtype != '') {
904 $param .= '&search_subtype='.urlencode($search_subtype);
905}
906if ($search_label) {
907 $param .= '&search_label='.urlencode($search_label);
908}
909if ($search_company) {
910 $param .= '&search_company='.urlencode($search_company);
911}
912if ($search_company_alias) {
913 $param .= '&search_company_alias='.urlencode($search_company_alias);
914}
915if ($search_login) {
916 $param .= '&search_login='.urlencode($search_login);
917}
918if ($search_montant_ht != '') {
919 $param .= '&search_montant_ht='.urlencode($search_montant_ht);
920}
921if ($search_montant_vat != '') {
922 $param .= '&search_montant_vat='.urlencode($search_montant_vat);
923}
924if ($search_montant_localtax1 != '') {
925 $param .= '&search_montant_localtax1='.urlencode($search_montant_localtax1);
926}
927if ($search_montant_localtax2 != '') {
928 $param .= '&search_montant_localtax2='.urlencode($search_montant_localtax2);
929}
930if ($search_montant_ttc != '') {
931 $param .= '&search_montant_ttc='.urlencode($search_montant_ttc);
932}
933if ($search_multicurrency_code != '') {
934 $param .= '&search_multicurrency_code='.urlencode($search_multicurrency_code);
935}
936if ($search_multicurrency_tx != '') {
937 $param .= '&search_multicurrency_tx='.urlencode($search_multicurrency_tx);
938}
939if ($search_multicurrency_montant_ht != '') {
940 $param .= '&search_multicurrency_montant_ht='.urlencode($search_multicurrency_montant_ht);
941}
942if ($search_multicurrency_montant_vat != '') {
943 $param .= '&search_multicurrency_montant_vat='.urlencode($search_multicurrency_montant_vat);
944}
945if ($search_multicurrency_montant_ttc != '') {
946 $param .= '&search_multicurrency_montant_ttc='.urlencode($search_multicurrency_montant_ttc);
947}
948if ($search_amount_no_tax) {
949 $param .= '&search_amount_no_tax='.urlencode($search_amount_no_tax);
950}
951if ($search_amount_all_tax) {
952 $param .= '&search_amount_all_tax='.urlencode($search_amount_all_tax);
953}
954if ($search_status >= 0) {
955 $param .= "&search_status=".urlencode($search_status);
956}
957if ($search_paymentmode) {
958 $param .= '&search_paymentmode='.urlencode((string) ($search_paymentmode));
959}
960if ($search_paymentcond) {
961 $param .= '&search_paymentcond='.urlencode((string) ($search_paymentcond));
962}
963if ($show_files) {
964 $param .= '&show_files='.urlencode((string) ($show_files));
965}
966if ($option) {
967 $param .= "&search_option=".urlencode($option);
968}
969if ($search_categ_sup > 0) {
970 $param .= '&search_categ_sup='.$search_categ_sup;
971}
972if ($search_type_thirdparty != '' && $search_type_thirdparty > 0) {
973 $param .= '&search_type_thirdparty='.$search_type_thirdparty;
974}
975if ($search_fk_fac_rec_source) {
976 $param .= '&search_fk_fac_rec_source=' . (int) $search_fk_fac_rec_source;
977}
978
979// Add $param from extra fields
980include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
981// Add $param from hooks
982$parameters = array('param' => &$param);
983$reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
984$param .= $hookmanager->resPrint;
985
986// List of mass actions available
987$arrayofmassactions = array(
988 'validate' => img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate"),
989 'generate_doc' => img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
990 'builddoc' => img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
991 //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
992);
993
994if (isModEnabled('paymentbybanktransfer') && $user->hasRight("paymentbybanktransfer", "create")) {
995 $langs->load('withdrawals');
996 $arrayofmassactions['banktransfertrequest'] = img_picto('', 'payment', 'class="pictofixedwidth"').$langs->trans("MakeBankTransferOrder");
997}
998if (!empty($permissiontodelete)) {
999 $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
1000}
1001if (GETPOSTINT('nomassaction') || in_array($massaction, array('presend', 'predelete'))) {
1002 $arrayofmassactions = array();
1003}
1004$massactionbutton = $form->selectMassAction('', $arrayofmassactions);
1005
1006$url = DOL_URL_ROOT.'/fourn/facture/card.php?action=create';
1007if (!empty($object->socid)) {
1008 $url .= '&socid='.urlencode((string) ($object->socid));
1009}
1010if (!empty($object->id)) {
1011 $url .= '&fac_rec='.urlencode((string) $object->id);
1012}
1013$i = 0;
1014print '<form method="POST" id="searchFormList" name="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
1015if ($optioncss != '') {
1016 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
1017}
1018print '<input type="hidden" name="token" value="'.newToken().'">';
1019print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
1020print '<input type="hidden" name="action" value="list">';
1021print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
1022print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
1023print '<input type="hidden" name="socid" value="'.$socid.'">';
1024print '<input type="hidden" name="page" value="'.$page.'">';
1025print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
1026print '<input type="hidden" name="page_y" value="">';
1027print '<input type="hidden" name="mode" value="'.$mode.'">';
1028
1029$newcardbutton = '';
1030$newcardbutton .= dolGetButtonTitle($langs->trans('ViewList'), '', 'fa fa-bars imgforviewmode', $_SERVER["PHP_SELF"].'?mode=common'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ((empty($mode) || $mode == 'common') ? 2 : 1), array('morecss' => 'reposition'));
1031$newcardbutton .= dolGetButtonTitle($langs->trans('ViewKanban'), '', 'fa fa-th-list imgforviewmode', $_SERVER["PHP_SELF"].'?mode=kanban'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ($mode == 'kanban' ? 2 : 1), array('morecss' => 'reposition'));
1032$newcardbutton .= dolGetButtonTitleSeparator();
1033$newcardbutton .= dolGetButtonTitle($langs->trans('NewBill'), '', 'fa fa-plus-circle', $url, '', (int) ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer")));
1034
1035print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'supplier_invoice', 0, $newcardbutton, '', $limit, 0, 0, 1);
1036
1037// Add code for pre mass action (confirmation or email presend form)
1038$topicmail = "SendBillRef";
1039$modelmail = "invoice_supplier_send";
1040$objecttmp = new FactureFournisseur($db);
1041$trackid = 'sinv'.$object->id;
1042include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
1043
1044if ($search_all) {
1045 $setupstring = '';
1046 foreach ($fieldstosearchall as $key => $val) {
1047 $fieldstosearchall[$key] = $langs->trans($val);
1048 $setupstring .= $key."=".$val.";";
1049 }
1050 print '<!-- Search done like if SUPPLIER_INVOICE_QUICKSEARCH_ON_FIELDS = '.$setupstring.' -->'."\n";
1051 print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).implode(', ', $fieldstosearchall).'</div>'."\n";
1052}
1053
1054// If the user can view prospects other than his'
1055$moreforfilter = '';
1056if ($user->hasRight("user", "user", "lire")) {
1057 $langs->load("commercial");
1058 $moreforfilter .= '<div class="divsearchfield">';
1059 $tmptitle = $langs->trans('ThirdPartiesOfSaleRepresentative');
1060 $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, $tmptitle, 'maxwidth200');
1061 $moreforfilter .= '</div>';
1062}
1063// If the user can view prospects other than his'
1064if ($user->hasRight("user", "user", "lire")) {
1065 $moreforfilter .= '<div class="divsearchfield">';
1066 $tmptitle = $langs->trans('LinkedToSpecificUsers');
1067 $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$form->select_dolusers($search_user, 'search_user', $tmptitle, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth200');
1068 $moreforfilter .= '</div>';
1069}
1070// If the user can view prospects other than his'
1071if (isModEnabled('category') && $user->hasRight('categorie', 'lire') && ($user->hasRight('produit', 'lire') || $user->hasRight('service', 'lire'))) {
1072 include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
1073 $moreforfilter .= '<div class="divsearchfield">';
1074 $tmptitle = $langs->trans('IncludingProductWithTag');
1075 $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, null, 'parent', null, null, 1);
1076 $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);
1077 $moreforfilter .= '</div>';
1078}
1079
1080if (isModEnabled('category')) {
1081 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
1082 $moreforfilter .= '<div class="divsearchfield">';
1083 $tmptitle = $langs->trans('SuppliersCategoriesShort');
1084 $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"').$formother->select_categories('supplier', $search_categ_sup, 'search_categ_sup', 1, $tmptitle);
1085 $moreforfilter .= '</div>';
1086}
1087$parameters = array();
1088$reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1089if (empty($reshook)) {
1090 $moreforfilter .= $hookmanager->resPrint;
1091} else {
1092 $moreforfilter = $hookmanager->resPrint;
1093}
1094
1095if (!empty($moreforfilter)) {
1096 print '<div class="liste_titre liste_titre_bydiv centpercent">';
1097 print $moreforfilter;
1098 print '</div>';
1099}
1100
1101$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
1102$htmlofselectarray = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')); // This also change content of $arrayfields with user setup
1103$selectedfields = ($mode != 'kanban' ? $htmlofselectarray : '');
1104$selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
1105
1106print '<div class="div-table-responsive">';
1107print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
1108
1109// Fields title search
1110// --------------------------------------------------------------------
1111print '<tr class="liste_titre_filter">';
1112// Action column
1113if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1114 print '<td class="liste_titre center maxwidthsearch">';
1115 $searchpicto = $form->showFilterButtons('left');
1116 print $searchpicto;
1117 print '</td>';
1118}
1119// Ref
1120if (!empty($arrayfields['f.ref']['checked'])) {
1121 print '<td class="liste_titre left">';
1122 print '<input class="flat maxwidth50" type="text" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">';
1123 print '</td>';
1124}
1125// Ref supplier
1126if (!empty($arrayfields['f.ref_supplier']['checked'])) {
1127 print '<td class="liste_titre">';
1128 print '<input class="flat maxwidth75" type="text" name="search_refsupplier" value="'.dol_escape_htmltag($search_refsupplier).'">';
1129 print '</td>';
1130}
1131// Type
1132if (!empty($arrayfields['f.type']['checked'])) {
1133 print '<td class="liste_titre maxwidthonsmartphone">';
1134 $typearray = array(
1135 FactureFournisseur::TYPE_STANDARD => $langs->trans("InvoiceStandard"),
1136 FactureFournisseur::TYPE_REPLACEMENT => $langs->trans("InvoiceReplacement"),
1137 FactureFournisseur::TYPE_CREDIT_NOTE => $langs->trans("InvoiceAvoir"),
1138 FactureFournisseur::TYPE_DEPOSIT => $langs->trans("InvoiceDeposit"),
1139 );
1140 print $form->selectarray('search_type', $typearray, $search_type, 1, 0, 0, '', 0, 0, 0, 'ASC', 'maxwidth100');
1141 print '</td>';
1142}
1143// Invoice Subtype
1144if (!empty($arrayfields['f.subtype']['checked'])) {
1145 print '<td class="liste_titre maxwidthonsmartphone" align="center">';
1146 print $form->selectarray('search_subtype', $subtypearray, $search_subtype, 1, 0, 0, '', 0, 0, 0, '', 'maxwidth100');
1147 print '</td>';
1148}
1149// Label
1150if (!empty($arrayfields['f.label']['checked'])) {
1151 print '<td class="liste_titre">';
1152 print '<input class="flat maxwidth75" type="text" name="search_label" value="'.dol_escape_htmltag($search_label).'">';
1153 print '</td>';
1154}
1155// Date invoice
1156if (!empty($arrayfields['f.datef']['checked'])) {
1157 print '<td class="liste_titre center">';
1158 print '<div class="nowrapfordate">';
1159 print $form->selectDate($search_date_start ? $search_date_start : -1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
1160 print '</div>';
1161 print '<div class="nowrapfordate">';
1162 print $form->selectDate($search_date_end ? $search_date_end : -1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
1163 print '</div>';
1164 print '</td>';
1165}
1166// Date due
1167if (!empty($arrayfields['f.date_lim_reglement']['checked'])) {
1168 print '<td class="liste_titre center">';
1169 print '<div class="">';
1170 /*
1171 print $langs->trans('From').' ';
1172 print $form->selectDate($search_datelimit_start ? $search_datelimit_start : -1, 'search_datelimit_start', 0, 0, 1);
1173 print '</div>';
1174 print '<div class="nowrap">';
1175 print $langs->trans('to').' ';*/
1176 print $form->selectDate($search_datelimit_end ? $search_datelimit_end : -1, 'search_datelimit_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("Before"));
1177 //print '<br>';
1178 print '<div class="nowraponall inline-block valignmiddle"><input type="checkbox" class="valignmiddle" name="search_option" id="search_option" value="late"'.($option == 'late' ? ' checked' : '').'><label for="search_option" class="valignmiddle">'.$langs->trans("Alert").'</label></div>';
1179 print '</div>';
1180 print '</td>';
1181}
1182// Project
1183if (!empty($arrayfields['p.ref']['checked'])) {
1184 print '<td class="liste_titre"><input class="flat maxwidth50" type="text" name="search_project" value="'.dol_escape_htmltag($search_project).'"></td>';
1185}
1186// Thirpdarty
1187if (!empty($arrayfields['s.nom']['checked'])) {
1188 print '<td class="liste_titre"><input class="flat maxwidth50" type="text" name="search_company" value="'.dol_escape_htmltag($search_company).'"'.($socid > 0 ? " disabled" : "").'></td>';
1189}
1190// Alias
1191if (!empty($arrayfields['s.name_alias']['checked'])) {
1192 print '<td class="liste_titre"><input class="flat maxwidth50" type="text" name="search_company_alias" value="'.dol_escape_htmltag($search_company_alias).'"></td>';
1193}
1194// Town
1195if (!empty($arrayfields['s.town']['checked'])) {
1196 print '<td class="liste_titre"><input class="flat maxwidth50" type="text" name="search_town" value="'.dol_escape_htmltag($search_town).'"></td>';
1197}
1198// Zip
1199if (!empty($arrayfields['s.zip']['checked'])) {
1200 print '<td class="liste_titre"><input class="flat maxwidth50" type="text" name="search_zip" value="'.dol_escape_htmltag($search_zip).'"></td>';
1201}
1202// State
1203if (!empty($arrayfields['state.nom']['checked'])) {
1204 print '<td class="liste_titre">';
1205 print '<input class="flat maxwidth50imp" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
1206 print '</td>';
1207}
1208// Country
1209if (!empty($arrayfields['country.code_iso']['checked'])) {
1210 print '<td class="liste_titre center">';
1211 print $form->select_country($search_country, 'search_country', '', 0, 'minwidth150imp maxwidth150', 'code2', 1, 0, 1, null, 1);
1212 print '</td>';
1213}
1214// Company type
1215if (!empty($arrayfields['typent.code']['checked'])) {
1216 print '<td class="liste_titre maxwidthonsmartphone center">';
1217 print $form->selectarray("search_type_thirdparty", $formcompany->typent_array(0), $search_type_thirdparty, 1, 0, 0, '', 0, 0, 0, (!getDolGlobalString('SOCIETE_SORT_ON_TYPEENT') ? 'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT), '', 1);
1218 print '</td>';
1219}
1220// Condition of payment
1221if (!empty($arrayfields['f.fk_cond_reglement']['checked'])) {
1222 print '<td class="liste_titre left">';
1223 print $form->getSelectConditionsPaiements($search_paymentcond, 'search_paymentcond', -1, 1, 1, 'maxwidth100');
1224 print '</td>';
1225}
1226// Payment mode
1227if (!empty($arrayfields['f.fk_mode_reglement']['checked'])) {
1228 print '<td class="liste_titre">';
1229 print $form->select_types_paiements($search_paymentmode, 'search_paymentmode', '', 0, 1, 1, 20, 1, 'maxwidth100', 1);
1230 print '</td>';
1231}
1232if (!empty($arrayfields['f.total_ht']['checked'])) {
1233 // Amount without tax
1234 print '<td class="liste_titre right">';
1235 print '<input class="flat" type="text" size="5" name="search_montant_ht" value="'.dol_escape_htmltag($search_montant_ht).'">';
1236 print '</td>';
1237}
1238if (!empty($arrayfields['f.total_vat']['checked'])) {
1239 // Amount vat
1240 print '<td class="liste_titre right">';
1241 print '<input class="flat" type="text" size="5" name="search_montant_vat" value="'.dol_escape_htmltag($search_montant_vat).'">';
1242 print '</td>';
1243}
1244if (!empty($arrayfields['f.total_localtax1']['checked'])) {
1245 // Amount tax 1
1246 print '<td class="liste_titre right">';
1247 print '<input class="flat" type="text" size="5" name="search_montant_localtax1" value="'.dol_escape_htmltag($search_montant_localtax1).'">';
1248 print '</td>';
1249}
1250if (!empty($arrayfields['f.total_localtax2']['checked'])) {
1251 // Amount tax 2
1252 print '<td class="liste_titre right">';
1253 print '<input class="flat" type="text" size="5" name="search_montant_localtax2" value="'.dol_escape_htmltag($search_montant_localtax2).'">';
1254 print '</td>';
1255}
1256if (!empty($arrayfields['f.total_ttc']['checked'])) {
1257 // Amount inc tac
1258 print '<td class="liste_titre right">';
1259 print '<input class="flat" type="text" size="5" name="search_montant_ttc" value="'.dol_escape_htmltag($search_montant_ttc).'">';
1260 print '</td>';
1261}
1262if (!empty($arrayfields['f.nb_docs']['checked'])) {
1263 // Nb of attached documents
1264 print '<td class="liste_titre" align="center">';
1265 print '</td>';
1266}
1267if (!empty($arrayfields['u.login']['checked'])) {
1268 // Author
1269 print '<td class="liste_titre" align="center">';
1270 print '<input class="flat" size="4" type="text" name="search_login" value="'.dol_escape_htmltag($search_login).'">';
1271 print '</td>';
1272}
1273if (!empty($arrayfields['dynamount_payed']['checked'])) {
1274 print '<td class="liste_titre right">';
1275 print '</td>';
1276}
1277if (!empty($arrayfields['rtp']['checked'])) {
1278 print '<td class="liste_titre">';
1279 print '</td>';
1280}
1281if (!empty($arrayfields['f.multicurrency_code']['checked'])) {
1282 // Currency
1283 print '<td class="liste_titre">';
1284 print $form->selectMultiCurrency($search_multicurrency_code, 'search_multicurrency_code', 1);
1285 print '</td>';
1286}
1287if (!empty($arrayfields['f.multicurrency_tx']['checked'])) {
1288 // Currency rate
1289 print '<td class="liste_titre">';
1290 print '<input class="flat" type="text" size="4" name="search_multicurrency_tx" value="'.dol_escape_htmltag($search_multicurrency_tx).'">';
1291 print '</td>';
1292}
1293if (!empty($arrayfields['f.multicurrency_total_ht']['checked'])) {
1294 // Amount
1295 print '<td class="liste_titre right">';
1296 print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_ht" value="'.dol_escape_htmltag($search_multicurrency_montant_ht).'">';
1297 print '</td>';
1298}
1299if (!empty($arrayfields['f.multicurrency_total_vat']['checked'])) {
1300 // Amount
1301 print '<td class="liste_titre right">';
1302 print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_vat" value="'.dol_escape_htmltag($search_multicurrency_montant_vat).'">';
1303 print '</td>';
1304}
1305if (!empty($arrayfields['f.multicurrency_total_ttc']['checked'])) {
1306 // Amount
1307 print '<td class="liste_titre right">';
1308 print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_ttc" value="'.dol_escape_htmltag($search_multicurrency_montant_ttc).'">';
1309 print '</td>';
1310}
1311if (!empty($arrayfields['multicurrency_dynamount_payed']['checked'])) {
1312 print '<td class="liste_titre">';
1313 print '</td>';
1314}
1315if (!empty($arrayfields['multicurrency_rtp']['checked'])) {
1316 print '<td class="liste_titre right">';
1317 print '</td>';
1318}
1319// Extra fields
1320include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
1321
1322// Fields from hook
1323$parameters = array('arrayfields' => $arrayfields);
1324$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1325print $hookmanager->resPrint;
1326// Date creation
1327if (!empty($arrayfields['f.datec']['checked'])) {
1328 print '<td class="liste_titre">';
1329 print '</td>';
1330}
1331// Date modification
1332if (!empty($arrayfields['f.tms']['checked'])) {
1333 print '<td class="liste_titre">';
1334 print '</td>';
1335}
1336// Status
1337if (!empty($arrayfields['f.fk_statut']['checked'])) {
1338 print '<td class="liste_titre center parentonrightofpage">';
1339 $liststatus = array('0' => $langs->trans("Draft"), '1' => $langs->trans("Unpaid"), '2' => $langs->trans("Paid"));
1340 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
1341 print $form->selectarray('search_status', $liststatus, $search_status, 1, 0, 0, '', 0, 0, 0, '', 'center search_status width100 onrightofpage', 1);
1342 print '</td>';
1343}
1344// Action column
1345if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1346 print '<td class="liste_titre center maxwidthsearch">';
1347 $searchpicto = $form->showFilterButtons();
1348 print $searchpicto;
1349 print '</td>';
1350}
1351
1352print "</tr>\n";
1353
1354$totalarray = array();
1355$totalarray['nbfield'] = 0;
1356
1357// Fields title label
1358// --------------------------------------------------------------------
1359print '<tr class="liste_titre">';
1360// Action column
1361if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1362 print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
1363 $totalarray['nbfield']++;
1364}
1365if (!empty($arrayfields['f.ref']['checked'])) {
1366 print_liste_field_titre($arrayfields['f.ref']['label'], $_SERVER['PHP_SELF'], 'f.ref,f.rowid', '', $param, '', $sortfield, $sortorder);
1367 $totalarray['nbfield']++;
1368}
1369if (!empty($arrayfields['f.ref_supplier']['checked'])) {
1370 print_liste_field_titre($arrayfields['f.ref_supplier']['label'], $_SERVER["PHP_SELF"], 'f.ref_supplier', '', $param, '', $sortfield, $sortorder);
1371 $totalarray['nbfield']++;
1372}
1373if (!empty($arrayfields['f.type']['checked'])) {
1374 print_liste_field_titre($arrayfields['f.type']['label'], $_SERVER["PHP_SELF"], 'f.type', '', $param, '', $sortfield, $sortorder);
1375 $totalarray['nbfield']++;
1376}
1377if (!empty($arrayfields['f.subtype']['checked'])) {
1378 print_liste_field_titre($arrayfields['f.subtype']['label'], $_SERVER["PHP_SELF"], 'f.subtype', '', $param, '', $sortfield, $sortorder);
1379}
1380if (!empty($arrayfields['f.label']['checked'])) {
1381 print_liste_field_titre($arrayfields['f.label']['label'], $_SERVER['PHP_SELF'], "f.libelle,f.rowid", '', $param, '', $sortfield, $sortorder);
1382 $totalarray['nbfield']++;
1383}
1384if (!empty($arrayfields['f.datef']['checked'])) {
1385 print_liste_field_titre($arrayfields['f.datef']['label'], $_SERVER['PHP_SELF'], 'f.datef,f.rowid', '', $param, '', $sortfield, $sortorder, 'center ');
1386 $totalarray['nbfield']++;
1387}
1388if (!empty($arrayfields['f.date_lim_reglement']['checked'])) {
1389 print_liste_field_titre($arrayfields['f.date_lim_reglement']['label'], $_SERVER['PHP_SELF'], "f.date_lim_reglement", '', $param, '', $sortfield, $sortorder, 'center ');
1390 $totalarray['nbfield']++;
1391}
1392if (!empty($arrayfields['p.ref']['checked'])) {
1393 print_liste_field_titre($arrayfields['p.ref']['label'], $_SERVER['PHP_SELF'], "p.ref", '', $param, '', $sortfield, $sortorder);
1394 $totalarray['nbfield']++;
1395}
1396if (!empty($arrayfields['s.nom']['checked'])) {
1397 print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER['PHP_SELF'], 's.nom', '', $param, '', $sortfield, $sortorder);
1398 $totalarray['nbfield']++;
1399}
1400if (!empty($arrayfields['s.name_alias']['checked'])) {
1401 // @phan-suppress-next-line PhanTypeInvalidDimOffset
1402 print_liste_field_titre($arrayfields['s.name_alias']['label'], $_SERVER['PHP_SELF'], 's.name_alias', '', $param, '', $sortfield, $sortorder);
1403 $totalarray['nbfield']++;
1404}
1405if (!empty($arrayfields['s.town']['checked'])) {
1406 print_liste_field_titre($arrayfields['s.town']['label'], $_SERVER["PHP_SELF"], 's.town', '', $param, '', $sortfield, $sortorder);
1407 $totalarray['nbfield']++;
1408}
1409if (!empty($arrayfields['s.zip']['checked'])) {
1410 print_liste_field_titre($arrayfields['s.zip']['label'], $_SERVER["PHP_SELF"], 's.zip', '', $param, '', $sortfield, $sortorder);
1411 $totalarray['nbfield']++;
1412}
1413if (!empty($arrayfields['state.nom']['checked'])) {
1414 print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.name_alias", "", $param, '', $sortfield, $sortorder);
1415 $totalarray['nbfield']++;
1416}
1417if (!empty($arrayfields['state.name_alias']['checked'])) {
1418 print_liste_field_titre($arrayfields['state.name_alias']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder);
1419 $totalarray['nbfield']++;
1420}
1421if (!empty($arrayfields['country.code_iso']['checked'])) {
1422 print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, '', $sortfield, $sortorder, 'center ');
1423 $totalarray['nbfield']++;
1424}
1425if (!empty($arrayfields['typent.code']['checked'])) {
1426 print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, '', $sortfield, $sortorder, 'center ');
1427 $totalarray['nbfield']++;
1428}
1429if (!empty($arrayfields['f.fk_cond_reglement']['checked'])) {
1430 print_liste_field_titre($arrayfields['f.fk_cond_reglement']['label'], $_SERVER["PHP_SELF"], "f.fk_cond_reglement", "", $param, "", $sortfield, $sortorder);
1431 $totalarray['nbfield']++;
1432}
1433if (!empty($arrayfields['f.fk_mode_reglement']['checked'])) {
1434 print_liste_field_titre($arrayfields['f.fk_mode_reglement']['label'], $_SERVER["PHP_SELF"], "f.fk_mode_reglement", "", $param, "", $sortfield, $sortorder);
1435 $totalarray['nbfield']++;
1436}
1437if (!empty($arrayfields['f.total_ht']['checked'])) {
1438 print_liste_field_titre($arrayfields['f.total_ht']['label'], $_SERVER['PHP_SELF'], 'f.total_ht', '', $param, '', $sortfield, $sortorder, 'right ');
1439 $totalarray['nbfield']++;
1440}
1441if (!empty($arrayfields['f.total_vat']['checked'])) {
1442 print_liste_field_titre($arrayfields['f.total_vat']['label'], $_SERVER['PHP_SELF'], 'f.total_tva', '', $param, '', $sortfield, $sortorder, 'right ');
1443 $totalarray['nbfield']++;
1444}
1445if (!empty($arrayfields['f.total_localtax1']['checked'])) {
1446 print_liste_field_titre($arrayfields['f.total_localtax1']['label'], $_SERVER['PHP_SELF'], 'f.localtax1', '', $param, '', $sortfield, $sortorder, 'right ');
1447 $totalarray['nbfield']++;
1448}
1449if (!empty($arrayfields['f.total_localtax2']['checked'])) {
1450 print_liste_field_titre($arrayfields['f.total_localtax2']['label'], $_SERVER['PHP_SELF'], 'f.localtax2', '', $param, '', $sortfield, $sortorder, 'right ');
1451 $totalarray['nbfield']++;
1452}
1453if (!empty($arrayfields['f.total_ttc']['checked'])) {
1454 print_liste_field_titre($arrayfields['f.total_ttc']['label'], $_SERVER['PHP_SELF'], 'f.total_ttc', '', $param, '', $sortfield, $sortorder, 'right ');
1455 $totalarray['nbfield']++;
1456}
1457if (!empty($arrayfields['f.nb_docs']['checked'])) {
1458 print_liste_field_titre($arrayfields['f.nb_docs']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'right ');
1459 $totalarray['nbfield']++;
1460}
1461if (!empty($arrayfields['u.login']['checked'])) {
1462 print_liste_field_titre($arrayfields['u.login']['label'], $_SERVER["PHP_SELF"], 'u.login', '', $param, '', $sortfield, $sortorder);
1463 $totalarray['nbfield']++;
1464}
1465if (!empty($arrayfields['dynamount_payed']['checked'])) {
1466 print_liste_field_titre($arrayfields['dynamount_payed']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'right ');
1467 $totalarray['nbfield']++;
1468}
1469if (!empty($arrayfields['rtp']['checked'])) {
1470 print_liste_field_titre($arrayfields['rtp']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder);
1471 $totalarray['nbfield']++;
1472}
1473if (!empty($arrayfields['f.multicurrency_code']['checked'])) {
1474 print_liste_field_titre($arrayfields['f.multicurrency_code']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_code', '', $param, '', $sortfield, $sortorder);
1475 $totalarray['nbfield']++;
1476}
1477if (!empty($arrayfields['f.multicurrency_tx']['checked'])) {
1478 print_liste_field_titre($arrayfields['f.multicurrency_tx']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_tx', '', $param, '', $sortfield, $sortorder);
1479 $totalarray['nbfield']++;
1480}
1481if (!empty($arrayfields['f.multicurrency_total_ht']['checked'])) {
1482 print_liste_field_titre($arrayfields['f.multicurrency_total_ht']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_total_ht', '', $param, '"', $sortfield, $sortorder, 'right ');
1483 $totalarray['nbfield']++;
1484}
1485if (!empty($arrayfields['f.multicurrency_total_vat']['checked'])) {
1486 print_liste_field_titre($arrayfields['f.multicurrency_total_vat']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_total_tva', '', $param, '', $sortfield, $sortorder, 'right ');
1487 $totalarray['nbfield']++;
1488}
1489if (!empty($arrayfields['f.multicurrency_total_ttc']['checked'])) {
1490 print_liste_field_titre($arrayfields['f.multicurrency_total_ttc']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_total_ttc', '', $param, '', $sortfield, $sortorder, 'right ');
1491 $totalarray['nbfield']++;
1492}
1493if (!empty($arrayfields['multicurrency_dynamount_payed']['checked'])) {
1494 print_liste_field_titre($arrayfields['multicurrency_dynamount_payed']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'right ');
1495 $totalarray['nbfield']++;
1496}
1497if (!empty($arrayfields['multicurrency_rtp']['checked'])) {
1498 print_liste_field_titre($arrayfields['multicurrency_rtp']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'right ');
1499 $totalarray['nbfield']++;
1500}
1501// Extra fields
1502include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
1503// Hook fields
1504$parameters = array('arrayfields' => $arrayfields, 'param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder, 'totalarray' => &$totalarray);
1505$reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1506print $hookmanager->resPrint;
1507if (!empty($arrayfields['f.datec']['checked'])) {
1508 print_liste_field_titre($arrayfields['f.datec']['label'], $_SERVER["PHP_SELF"], "f.datec", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
1509 $totalarray['nbfield']++;
1510}
1511if (!empty($arrayfields['f.tms']['checked'])) {
1512 print_liste_field_titre($arrayfields['f.tms']['label'], $_SERVER["PHP_SELF"], "f.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
1513 $totalarray['nbfield']++;
1514}
1515if (!empty($arrayfields['f.fk_statut']['checked'])) {
1516 print_liste_field_titre($arrayfields['f.fk_statut']['label'], $_SERVER["PHP_SELF"], "fk_statut,paye,type", "", $param, '', $sortfield, $sortorder, 'center ');
1517 $totalarray['nbfield']++;
1518}
1519// Action column
1520if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1521 print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
1522 $totalarray['nbfield']++;
1523}
1524print '</tr>'."\n";
1525
1526$facturestatic = new FactureFournisseur($db);
1527$supplierstatic = new Fournisseur($db);
1528$projectstatic = new Project($db);
1529$userstatic = new User($db);
1530$discount = new DiscountAbsolute($db);
1531
1532// Loop on record
1533// --------------------------------------------------------------------
1534$i = 0;
1535$savnbfield = $totalarray['nbfield'];
1536$totalarray = array();
1537$totalarray['nbfield'] = 0;
1538$totalarray['val'] = array();
1539$totalarray['val']['f.total_ht'] = 0;
1540$totalarray['val']['f.total_vat'] = 0;
1541$totalarray['val']['f.total_localtax1'] = 0;
1542$totalarray['val']['f.total_localtax1'] = 0;
1543$totalarray['val']['f.total_ttc'] = 0;
1544$totalarray['val']['totalam'] = 0;
1545$totalarray['val']['rtp'] = 0;
1546
1547$imaxinloop = ($limit ? min($num, $limit) : $num);
1548while ($i < $imaxinloop) {
1549 $obj = $db->fetch_object($resql);
1550 if (empty($obj)) {
1551 break; // Should not happen
1552 }
1553
1554 $datelimit = $db->jdate($obj->datelimite);
1555
1556 $userstatic->id = $obj->fk_user_author;
1557 $userstatic->login = $obj->login;
1558 $userstatic->lastname = $obj->lastname;
1559 $userstatic->firstname = $obj->firstname;
1560 $userstatic->email = $obj->user_email;
1561 $userstatic->statut = $obj->user_statut;
1562 $userstatic->status = $obj->user_statut;
1563 $userstatic->entity = $obj->entity;
1564 $userstatic->photo = $obj->photo;
1565 $userstatic->office_phone = $obj->office_phone;
1566 $userstatic->office_fax = $obj->office_fax;
1567 $userstatic->user_mobile = $obj->user_mobile;
1568 $userstatic->job = $obj->job;
1569 $userstatic->gender = $obj->gender;
1570 $facturestatic->id = $obj->facid;
1571 $facturestatic->ref = $obj->ref;
1572 $facturestatic->type = $obj->type;
1573 $facturestatic->subtype = $obj->subtype;
1574 $facturestatic->total_ht = $obj->total_ht;
1575 $facturestatic->total_tva = $obj->total_vat;
1576 $facturestatic->total_ttc = $obj->total_ttc;
1577 $facturestatic->close_code = $obj->close_code;
1578 $facturestatic->ref_supplier = $obj->ref_supplier;
1579 $facturestatic->date_echeance = $db->jdate($obj->datelimite);
1580 $facturestatic->statut = $obj->fk_statut;
1581 $facturestatic->status = $obj->fk_statut;
1582 $facturestatic->note_public = $obj->note_public;
1583 $facturestatic->note_private = $obj->note_private;
1584 $facturestatic->multicurrency_code = $obj->multicurrency_code;
1585 $facturestatic->multicurrency_tx = $obj->multicurrency_tx;
1586 $facturestatic->multicurrency_total_ht = $obj->multicurrency_total_ht;
1587 $facturestatic->multicurrency_total_tva = $obj->multicurrency_total_vat;
1588 $facturestatic->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
1589 $thirdparty->id = $obj->socid;
1590 $thirdparty->name = $obj->name;
1591 $thirdparty->name_alias = $obj->alias;
1592 $thirdparty->client = $obj->client;
1593 $thirdparty->fournisseur = $obj->fournisseur;
1594 $thirdparty->code_client = $obj->code_client;
1595 $thirdparty->code_compta_client = $obj->code_compta_client;
1596 $thirdparty->code_fournisseur = $obj->code_fournisseur;
1597 $thirdparty->code_compta_fournisseur = $obj->code_compta_fournisseur;
1598 $thirdparty->email = $obj->email;
1599 $thirdparty->country_code = $obj->country_code;
1600
1601 $paiement = $facturestatic->getSommePaiement();
1602 $totalcreditnotes = $facturestatic->getSumCreditNotesUsed();
1603 $totaldeposits = $facturestatic->getSumDepositsUsed();
1604 $totalpay = $paiement + $totalcreditnotes + $totaldeposits;
1605 $remaintopay = $obj->total_ttc - $totalpay;
1606
1607 $multicurrency_paiement = $facturestatic->getSommePaiement(1);
1608 $multicurrency_totalcreditnotes = $facturestatic->getSumCreditNotesUsed(1);
1609 $multicurrency_totaldeposits = $facturestatic->getSumDepositsUsed(1);
1610
1611 $totalpay = $paiement + $totalcreditnotes + $totaldeposits;
1612 $remaintopay = price2num($facturestatic->total_ttc - $totalpay);
1613
1614 $multicurrency_totalpay = $multicurrency_paiement + $multicurrency_totalcreditnotes + $multicurrency_totaldeposits;
1615 $multicurrency_remaintopay = price2num($facturestatic->multicurrency_total_ttc - $multicurrency_totalpay);
1616
1617 if ($facturestatic->status == FactureFournisseur::STATUS_CLOSED && $facturestatic->close_code == 'discount_vat') { // If invoice closed with discount for anticipated payment
1618 $remaintopay = 0;
1619 $multicurrency_remaintopay = 0;
1620 }
1621 if ($facturestatic->type == FactureFournisseur::TYPE_CREDIT_NOTE && $obj->paye == 1) { // If credit note closed, we take into account the amount not yet consumed
1622 $remaincreditnote = $discount->getAvailableDiscounts($thirdparty, '', 'rc.fk_facture_source='.$facturestatic->id);
1623 $remaintopay = -$remaincreditnote;
1624 $totalpay = price2num($facturestatic->total_ttc - $remaintopay);
1625 $multicurrency_remaincreditnote = $discount->getAvailableDiscounts($thirdparty, '', 'rc.fk_facture_source='.$facturestatic->id, 0, 0, 1);
1626 $multicurrency_remaintopay = -$multicurrency_remaincreditnote;
1627 $multicurrency_totalpay = price2num($facturestatic->multicurrency_total_ttc - $multicurrency_remaintopay);
1628 }
1629
1630 $facturestatic->alreadypaid = ($paiement ? $paiement : 0);
1631
1632 $facturestatic->paye = $obj->paye;
1633 $facturestatic->paid = $obj->paye;
1634
1635 $facturestatic->date = $db->jdate($obj->datef);
1636
1637 $object = $facturestatic;
1638
1639 //If invoice has been converted and the conversion has been used, we don't have remain to pay on invoice
1640 if ($facturestatic->type == FactureFournisseur::TYPE_CREDIT_NOTE) {
1641 if ($facturestatic->isCreditNoteUsed()) {
1642 $remaintopay = -$facturestatic->getSumFromThisCreditNotesNotUsed();
1643 }
1644 }
1645
1646 if ($mode == 'kanban') {
1647 if ($i == 0) {
1648 print '<tr class="trkanban"><td colspan="'.$savnbfield.'">';
1649 print '<div class="box-flex-container kanban">';
1650 }
1651 // Output Kanban
1652 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
1653 $selected = 0;
1654 if (in_array($object->id, $arrayofselected)) {
1655 $selected = 1;
1656 }
1657 }
1658
1659 $arraydata = array('alreadypaid' => $paiement, 'thirdparty' => $thirdparty->getNomUrl(1, '', 12), 'selected' => in_array($object->id, $arrayofselected));
1660 print $facturestatic->getKanbanView('', $arraydata);
1661 if ($i == ($imaxinloop - 1)) {
1662 print '</div>';
1663 print '</td></tr>';
1664 }
1665 } else {
1666 // Show line of result
1667 $j = 0;
1668 print '<tr data-rowid="'.$object->id.'" class="oddeven '.((getDolGlobalInt('MAIN_FINISHED_LINES_OPACITY') == 1 && $obj->fk_statut > 1) ? 'opacitymedium' : '').'">';
1669
1670 // Action column
1671 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1672 print '<td class="nowrap center">';
1673 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
1674 $selected = 0;
1675 if (in_array($obj->facid, $arrayofselected)) {
1676 $selected = 1;
1677 }
1678 print '<input id="cb'.$obj->facid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->facid.'"'.($selected ? ' checked="checked"' : '').'>';
1679 }
1680 print '</td>';
1681 if (!$i) {
1682 $totalarray['nbfield']++;
1683 }
1684 }
1685 if (!empty($arrayfields['f.ref']['checked'])) {
1686 print '<td class="nowraponall">';
1687
1688 print '<table class="nobordernopadding"><tr class="nocellnopadd">';
1689 // Picto + Ref
1690 print '<td class="nobordernopadding nowraponall">';
1691 print $facturestatic->getNomUrl(1, '', 0, 0, '', 0, -1, 1);
1692
1693 $filename = dol_sanitizeFileName($obj->ref);
1694 $filedir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($obj->facid, 2, 0, 0, $facturestatic, 'invoice_supplier').dol_sanitizeFileName($obj->ref);
1695 $subdir = get_exdir($obj->facid, 2, 0, 0, $facturestatic, 'invoice_supplier').dol_sanitizeFileName($obj->ref);
1696 print $formfile->getDocumentsLink('facture_fournisseur', $subdir, $filedir);
1697 print '</td></tr></table>';
1698
1699 print "</td>\n";
1700 if (!$i) {
1701 $totalarray['nbfield']++;
1702 }
1703 }
1704
1705 // Supplier ref
1706 if (!empty($arrayfields['f.ref_supplier']['checked'])) {
1707 print '<td class="nowrap tdoverflowmax150" title="'.dol_escape_htmltag($obj->ref_supplier).'">';
1708 print $obj->ref_supplier;
1709 print '</td>';
1710 if (!$i) {
1711 $totalarray['nbfield']++;
1712 }
1713 }
1714
1715 // Type
1716 if (!empty($arrayfields['f.type']['checked'])) {
1717 print '<td class="nowrap">';
1718 print $facturestatic->getLibType();
1719 print "</td>";
1720 if (!$i) {
1721 $totalarray['nbfield']++;
1722 }
1723 }
1724
1725 // Invoice Subtype
1726 if (!empty($arrayfields['f.subtype']['checked'])) {
1727 $labeltoshow = '';
1728 if ($facturestatic->subtype > 0) {
1729 $labeltoshow = $facturestatic->getSubtypeLabel('facture_fourn');
1730 }
1731 print '<td class="nowraponall tdoverflowmax300" title="'.$labeltoshow.'">';
1732 print $labeltoshow;
1733 print "</td>";
1734 if (!$i) {
1735 $totalarray['nbfield']++;
1736 }
1737 }
1738
1739 // Label
1740 if (!empty($arrayfields['f.label']['checked'])) {
1741 print '<td class="nowrap tdoverflowmax125" title="'.dol_escape_htmltag($obj->label).'">';
1742 print dol_escape_htmltag($obj->label);
1743 print '</td>';
1744 if (!$i) {
1745 $totalarray['nbfield']++;
1746 }
1747 }
1748
1749 // Date
1750 if (!empty($arrayfields['f.datef']['checked'])) {
1751 print '<td class="center nowrap">';
1752 print dol_print_date($db->jdate($obj->datef), 'day');
1753 print '</td>';
1754 if (!$i) {
1755 $totalarray['nbfield']++;
1756 }
1757 }
1758
1759 // Date limit
1760 if (!empty($arrayfields['f.date_lim_reglement']['checked'])) {
1761 print '<td class="center nowraponall">'.dol_print_date($datelimit, 'day');
1762 if ($facturestatic->hasDelay()) {
1763 print img_warning($langs->trans('Alert').' - '.$langs->trans('Late'));
1764 }
1765 print '</td>';
1766 if (!$i) {
1767 $totalarray['nbfield']++;
1768 }
1769 }
1770
1771 // Project
1772 if (!empty($arrayfields['p.ref']['checked'])) {
1773 print '<td class="nowrap">';
1774 if ($obj->project_id > 0) {
1775 $projectstatic->id = $obj->project_id;
1776 $projectstatic->ref = $obj->project_ref;
1777 $projectstatic->title = $obj->project_label;
1778 print $projectstatic->getNomUrl(1);
1779 }
1780 print '</td>';
1781 if (!$i) {
1782 $totalarray['nbfield']++;
1783 }
1784 }
1785
1786 // Third party
1787 if (!empty($arrayfields['s.nom']['checked'])) {
1788 print '<td class="tdoverflowmax125">';
1789 print $thirdparty->getNomUrl(1, 'supplier', 0, 0, -1, empty($arrayfields['s.name_alias']['checked']) ? 0 : 1);
1790 print '</td>';
1791 if (!$i) {
1792 $totalarray['nbfield']++;
1793 }
1794 }
1795 // Alias
1796 if (!empty($arrayfields['s.name_alias']['checked'])) {
1797 print '<td class="tdoverflowmax150">';
1798 print dol_escape_htmltag($thirdparty->name_alias);
1799 print '</td>';
1800 if (!$i) {
1801 $totalarray['nbfield']++;
1802 }
1803 }
1804 // Town
1805 if (!empty($arrayfields['s.town']['checked'])) {
1806 print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->town).'">';
1807 print dol_escape_htmltag($obj->town);
1808 print '</td>';
1809 if (!$i) {
1810 $totalarray['nbfield']++;
1811 }
1812 }
1813 // Zip
1814 if (!empty($arrayfields['s.zip']['checked'])) {
1815 print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->zip).'">';
1816 print dol_escape_htmltag($obj->zip);
1817 print '</td>';
1818 if (!$i) {
1819 $totalarray['nbfield']++;
1820 }
1821 }
1822 // State
1823 if (!empty($arrayfields['state.nom']['checked'])) {
1824 print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->state_name).'">';
1825 print dol_escape_htmltag($obj->state_name);
1826 print "</td>\n";
1827 if (!$i) {
1828 $totalarray['nbfield']++;
1829 }
1830 }
1831 // Country
1832 if (!empty($arrayfields['country.code_iso']['checked'])) {
1833 print '<td class="center">';
1834 $tmparray = getCountry($obj->fk_pays, 'all');
1835 print $tmparray['label'];
1836 print '</td>';
1837 if (!$i) {
1838 $totalarray['nbfield']++;
1839 }
1840 }
1841 // Type ent
1842 if (!empty($arrayfields['typent.code']['checked'])) {
1843 print '<td class="center">';
1844 if (empty($typenArray)) {
1845 $typenArray = $formcompany->typent_array(1);
1846 }
1847 print $typenArray[$obj->typent_code];
1848 print '</td>';
1849 if (!$i) {
1850 $totalarray['nbfield']++;
1851 }
1852 }
1853
1854 // Payment condition
1855 if (!empty($arrayfields['f.fk_cond_reglement']['checked'])) {
1856 $s = $form->form_conditions_reglement($_SERVER['PHP_SELF'], $obj->fk_cond_reglement, 'none', 1, '', -1, -1, 1);
1857 print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($s).'">';
1858 print dol_escape_htmltag($s);
1859 print '</td>';
1860 if (!$i) {
1861 $totalarray['nbfield']++;
1862 }
1863 }
1864 // Payment mode
1865 if (!empty($arrayfields['f.fk_mode_reglement']['checked'])) {
1866 $s = $form->form_modes_reglement($_SERVER['PHP_SELF'], $obj->fk_mode_reglement, 'none', '', -1, 0, '', 1);
1867 print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($s).'">';
1868 print dol_escape_htmltag($s);
1869 print '</td>';
1870 if (!$i) {
1871 $totalarray['nbfield']++;
1872 }
1873 }
1874
1875 // Amount HT
1876 if (!empty($arrayfields['f.total_ht']['checked'])) {
1877 print '<td class="right nowrap"><span class="amount">'.price($obj->total_ht)."</span></td>\n";
1878 if (!$i) {
1879 $totalarray['nbfield']++;
1880 $totalarray['pos'][$totalarray['nbfield']] = 'f.total_ht';
1881 }
1882 $totalarray['val']['f.total_ht'] += $obj->total_ht;
1883 }
1884 // Amount VAT
1885 if (!empty($arrayfields['f.total_vat']['checked'])) {
1886 print '<td class="right nowrap"><span class="amount">'.price($obj->total_vat)."</span></td>\n";
1887 if (!$i) {
1888 $totalarray['nbfield']++;
1889 $totalarray['pos'][$totalarray['nbfield']] = 'f.total_vat';
1890 }
1891 $totalarray['val']['f.total_vat'] += $obj->total_vat;
1892 }
1893 // Amount LocalTax1
1894 if (!empty($arrayfields['f.total_localtax1']['checked'])) {
1895 print '<td class="right nowrap"><span class="amount">'.price($obj->total_localtax1)."</span></td>\n";
1896 if (!$i) {
1897 $totalarray['nbfield']++;
1898 $totalarray['pos'][$totalarray['nbfield']] = 'f.total_localtax1';
1899 }
1900 $totalarray['val']['f.total_localtax1'] += $obj->total_localtax1;
1901 }
1902 // Amount LocalTax2
1903 if (!empty($arrayfields['f.total_localtax2']['checked'])) {
1904 print '<td class="right nowrap"><span class="amount">'.price($obj->total_localtax2)."</span></td>\n";
1905 if (!$i) {
1906 $totalarray['nbfield']++;
1907 $totalarray['pos'][$totalarray['nbfield']] = 'f.total_localtax2';
1908 }
1909 $totalarray['val']['f.total_localtax2'] += $obj->total_localtax2;
1910 }
1911 // Amount TTC
1912 if (!empty($arrayfields['f.total_ttc']['checked'])) {
1913 print '<td class="right nowrap"><span class="amount">'.price($obj->total_ttc)."</span></td>\n";
1914 if (!$i) {
1915 $totalarray['nbfield']++;
1916 $totalarray['pos'][$totalarray['nbfield']] = 'f.total_ttc';
1917 }
1918 $totalarray['val']['f.total_ttc'] += $obj->total_ttc;
1919 }
1920
1921 // Number of attached documents (may slow your application on large lists)
1922 if (!empty($arrayfields['f.nb_docs']['checked'])) {
1923 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
1924 require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
1925 $upload_dir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($facturestatic->id, 2, 0, 0, $facturestatic, 'invoice_supplier').$facturestatic->ref;
1926 $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
1927 $nbLinks = Link::count($db, $facturestatic->element, $facturestatic->id);
1928 $nbTotal = $nbFiles + $nbLinks;
1929 echo '<td class="center">'.(empty($nbTotal) ? '' : $nbTotal).'</td>';
1930 if (!$i) {
1931 $totalarray['nbfield']++;
1932 }
1933 }
1934
1935 // Author
1936 if (!empty($arrayfields['u.login']['checked'])) {
1937 print '<td class="tdoverflowmax100">';
1938 if ($userstatic->id) {
1939 print $userstatic->getNomUrl(-1);
1940 } else {
1941 print '&nbsp;';
1942 }
1943 print "</td>\n";
1944 if (!$i) {
1945 $totalarray['nbfield']++;
1946 }
1947 }
1948
1949 // Dynamic amount paid
1950 if (!empty($arrayfields['dynamount_payed']['checked'])) {
1951 print '<td class="right nowrap"><span class="amount">'.(!empty($totalpay) ? price($totalpay, 0, $langs) : '').'</span></td>'; // TODO Use a denormalized field
1952 if (!$i) {
1953 $totalarray['nbfield']++;
1954 $totalarray['pos'][$totalarray['nbfield']] = 'totalam';
1955 }
1956 if (empty($totalarray['val']['totalam'])) {
1957 $totalarray['val']['totalam'] = 0; // avoid PHP Warning: Undefined array key "totalam" on line 1891
1958 }
1959 $totalarray['val']['totalam'] += $totalpay;
1960 }
1961
1962 // Remain to pay
1963 if (!empty($arrayfields['rtp']['checked'])) {
1964 print '<td class="right nowrap">'.(!empty($remaintopay) ? price($remaintopay, 0, $langs) : '&nbsp;').'</td>'; // TODO Use a denormalized field
1965 if (!$i) {
1966 $totalarray['nbfield']++;
1967 $totalarray['pos'][$totalarray['nbfield']] = 'rtp';
1968 }
1969 $totalarray['val']['rtp'] += $remaintopay;
1970 }
1971
1972 // Currency
1973 if (!empty($arrayfields['f.multicurrency_code']['checked'])) {
1974 print '<td class="nowrap">'.$obj->multicurrency_code.' - '.$langs->trans('Currency'.$obj->multicurrency_code)."</td>\n";
1975 if (!$i) {
1976 $totalarray['nbfield']++;
1977 }
1978 }
1979
1980 // Currency rate
1981 if (!empty($arrayfields['f.multicurrency_tx']['checked'])) {
1982 print '<td class="nowrap">';
1983 $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$obj->rowid, $obj->multicurrency_tx, 'none', $obj->multicurrency_code);
1984 print "</td>\n";
1985 if (!$i) {
1986 $totalarray['nbfield']++;
1987 }
1988 }
1989 // Amount HT
1990 if (!empty($arrayfields['f.multicurrency_total_ht']['checked'])) {
1991 print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_ht)."</span></td>\n";
1992 if (!$i) {
1993 $totalarray['nbfield']++;
1994 }
1995 }
1996 // Amount VAT
1997 if (!empty($arrayfields['f.multicurrency_total_vat']['checked'])) {
1998 print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_vat)."</span></td>\n";
1999 if (!$i) {
2000 $totalarray['nbfield']++;
2001 }
2002 }
2003 // Amount TTC
2004 if (!empty($arrayfields['f.multicurrency_total_ttc']['checked'])) {
2005 print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_ttc)."</span></td>\n";
2006 if (!$i) {
2007 $totalarray['nbfield']++;
2008 }
2009 }
2010 // Dynamic amount paid
2011 if (!empty($arrayfields['multicurrency_dynamount_payed']['checked'])) {
2012 print '<td class="right nowrap"><span class="amount">'.(!empty($multicurrency_totalpay) ? price($multicurrency_totalpay, 0, $langs) : '').'</span></td>'; // TODO Use a denormalized field
2013 if (!$i) {
2014 $totalarray['nbfield']++;
2015 }
2016 }
2017
2018 // Pending amount
2019 if (!empty($arrayfields['multicurrency_rtp']['checked'])) {
2020 print '<td class="right nowrap"><span class="amount">';
2021 print(!empty($multicurrency_remaintopay) ? price($multicurrency_remaintopay, 0, $langs) : '');
2022 print '</span></td>'; // TODO Use a denormalized field
2023 if (!$i) {
2024 $totalarray['nbfield']++;
2025 }
2026 }
2027
2028
2029 // Extra fields
2030 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
2031 // Fields from hook
2032 $parameters = array('arrayfields' => $arrayfields, 'object' => $object, 'obj' => $obj, 'i' => $i, 'totalarray' => &$totalarray);
2033 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
2034 print $hookmanager->resPrint;
2035
2036 // Date creation
2037 if (!empty($arrayfields['f.datec']['checked'])) {
2038 print '<td class="center nowraponall">';
2039 print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
2040 print '</td>';
2041 if (!$i) {
2042 $totalarray['nbfield']++;
2043 }
2044 }
2045 // Date modification
2046 if (!empty($arrayfields['f.tms']['checked'])) {
2047 print '<td class="center nowraponall">';
2048 print dol_print_date($db->jdate($obj->date_modification), 'dayhour', 'tzuser');
2049 print '</td>';
2050 if (!$i) {
2051 $totalarray['nbfield']++;
2052 }
2053 }
2054 // Status
2055 if (!empty($arrayfields['f.fk_statut']['checked'])) {
2056 print '<td class="center nowrap">';
2057 print $facturestatic->getLibStatut(5, $paiement);
2058 print "</td>";
2059 if (!$i) {
2060 $totalarray['nbfield']++;
2061 }
2062 }
2063
2064 // Action column
2065 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
2066 print '<td class="nowrap center">';
2067 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
2068 $selected = 0;
2069 if (in_array($obj->facid, $arrayofselected)) {
2070 $selected = 1;
2071 }
2072 print '<input id="cb'.$obj->facid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->facid.'"'.($selected ? ' checked="checked"' : '').'>';
2073 }
2074 print '</td>';
2075 if (!$i) {
2076 $totalarray['nbfield']++;
2077 }
2078 }
2079
2080 print '</tr>'."\n";
2081 }
2082
2083 $i++;
2084}
2085
2086// Show total line
2087include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
2088
2089// If no record found
2090if ($num == 0) {
2091 $colspan = 1;
2092 foreach ($arrayfields as $key => $val) {
2093 if (!empty($val['checked'])) {
2094 $colspan++;
2095 }
2096 }
2097 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
2098}
2099
2100$db->free($resql);
2101
2102$parameters = array('arrayfields' => $arrayfields, 'sql' => $sql);
2103$reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
2104print $hookmanager->resPrint;
2105
2106print '</table>'."\n";
2107print '</div>'."\n";
2108
2109print '</form>'."\n";
2110
2111if (in_array('builddoc', array_keys($arrayofmassactions)) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
2112 $hidegeneratedfilelistifempty = 1;
2113 if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
2114 $hidegeneratedfilelistifempty = 0;
2115 }
2116
2117 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
2118 $formfile = new FormFile($db);
2119
2120 // Show list of available documents
2121 $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
2122 $urlsource .= str_replace('&amp;', '&', $param);
2123
2124 $filedir = $diroutputmassaction;
2125 $genallowed = $permissiontoread;
2126 $delallowed = $permissiontoadd;
2127 $title = '';
2128
2129 print $formfile->showdocuments('massfilesarea_supplier_invoice', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
2130}
2131
2132// End of page
2133llxFooter();
2134$db->close();
$id
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:71
Class to manage bank accounts.
Class to manage absolute discounts.
Class to manage standard extra fields.
Class to manage suppliers invoices.
const TYPE_DEPOSIT
Deposit invoice.
const TYPE_CREDIT_NOTE
Credit note invoice.
const TYPE_REPLACEMENT
Replacement invoice.
const TYPE_STANDARD
Standard invoice.
const STATUS_CLOSED
Classified paid.
Class to manage invoice templates.
Class to build HTML component for third parties management Only common components are here.
Class to offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
Class permettant la generation de composants html autre Only common components are here.
Class to manage suppliers.
Class to manage projects.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
getCountry($searchkey, $withcode='', $dbtouse=null, $outputlangs=null, $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
getCountriesInEEC()
Return list of countries that are inside the EEC (European Economic Community) Note: Try to keep this...
llxFooter()
Footer empty.
Definition document.php:107
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition files.lib.php:63
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
GETPOSTDATE($prefix, $hourTime='', $gm='auto')
Helper function that combines values of a dolibarr DatePicker (such as Form\selectDate) for year,...
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip='', $forcenowrapcolumntitle=0)
Get title line of an array.
dolGetButtonTitleSeparator($moreClass="")
Add space between dolGetButtonTitle.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
buildParamDate($prefix, $timestamp=null, $hourTime='', $gm='auto')
Helper function that combines values of a dolibarr DatePicker (such as Form\selectDate) for year,...
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
supplier_invoice_rec_prepare_head($object)
Return array head with list of tabs to view object information.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.