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