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