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 $sql .= " AND ".$db->escape(trim($filt[0]))." = '".$db->escape(trim($filt[1]))."'";
768 }
769}
770
771if ($search_all) {
772 unset($fieldstosearchall['pd.description']);
773 $sql .= "AND (";
774 $sql .= natural_search(array_keys($fieldstosearchall), $search_all, 0, 1);
775 $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))."%')";
776 $sql .= ")";
777 $fieldstosearchall['pd.description'] = 'Description';
778}
779
780if ($search_user > 0) {
781 $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);
782}
783// Add where from extra fields
784include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
785// Add where from hooks
786$parameters = array();
787$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
788$sql .= $hookmanager->resPrint;
789
790// Add HAVING from hooks
791$parameters = array();
792$reshook = $hookmanager->executeHooks('printFieldListHaving', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
793$sql .= empty($hookmanager->resPrint) ? "" : " HAVING 1=1 ".$hookmanager->resPrint;
794
795// Count total nb of records
796$nbtotalofrecords = '';
797if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
798 /* The fast and low memory method to get and count full list converts the sql into a sql count */
799 $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
800
801 $resql = $db->query($sqlforcount);
802 if ($resql) {
803 $objforcount = $db->fetch_object($resql);
804 $nbtotalofrecords = $objforcount->nbtotalofrecords;
805 } else {
806 dol_print_error($db);
807 }
808
809 if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller than the paging size (filtering), goto and load page 0
810 $page = 0;
811 $offset = 0;
812 }
813 $db->free($resql);
814}
815
816// Complete request and execute it with limit
817$sql .= $db->order($sortfield, $sortorder);
818if ($limit) {
819 $sql .= $db->plimit($limit + 1, $offset);
820}
821//print $sql;
822
823$resql = $db->query($sql);
824if (!$resql) {
825 dol_print_error($db);
826 exit;
827}
828
829$num = $db->num_rows($resql);
830
831// Direct jump if only one record found
832if ($num == 1 && getDolGlobalInt('MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE') && $search_all && !$page) {
833 $obj = $db->fetch_object($resql);
834 $id = $obj->facid;
835 header("Location: ".DOL_URL_ROOT.'/fourn/facture/card.php?facid='.$id);
836 exit;
837}
838
839// Output page
840// --------------------------------------------------------------------
841
842llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'bodyforlist mod-fourn-facture page-list');
843
844if ($search_fk_fac_rec_source) {
845 require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.facture-rec.class.php';
846 require_once DOL_DOCUMENT_ROOT . '/core/lib/invoice.lib.php';
848 $object->fetch((int) $search_fk_fac_rec_source);
849
850 $head = supplier_invoice_rec_prepare_head($object);
851 print dol_get_fiche_head($head, 'generated', $langs->trans('InvoicesGeneratedFromRec'), -1, 'bill'); // Add a div
852}
853
854if ($socid) {
855 $soc = new Societe($db);
856 $soc->fetch($socid);
857 if (empty($search_company)) {
858 $search_company = $soc->name;
859 $search_company_alias = $soc->name_alias;
860 }
861}
862
863$arrayofselected = is_array($toselect) ? $toselect : array();
864
865$param = '&socid='.$socid;
866if (!empty($mode)) {
867 $param .= '&mode='.urlencode($mode);
868}
869if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
870 $param .= '&contextpage='.urlencode($contextpage);
871}
872if ($limit > 0 && $limit != $conf->liste_limit) {
873 $param .= '&limit='.((int) $limit);
874}
875if ($optioncss != '') {
876 $param .= '&optioncss='.urlencode($optioncss);
877}
878if ($search_all) {
879 $param .= '&search_all='.urlencode($search_all);
880}
881if ($search_date_start) {
882 $param .= buildParamDate('search_date_start', null, '', 'tzserver');
883}
884if ($search_date_end) {
885 $param .= buildParamDate('search_date_end', null, '', 'tzserver');
886}
887if ($search_datelimit_startday) {
888 $param .= '&search_datelimit_startday='.urlencode((string) ($search_datelimit_startday));
889}
890if ($search_datelimit_startmonth) {
891 $param .= '&search_datelimit_startmonth='.urlencode((string) ($search_datelimit_startmonth));
892}
893if ($search_datelimit_startyear) {
894 $param .= '&search_datelimit_startyear='.urlencode((string) ($search_datelimit_startyear));
895}
896if ($search_datelimit_endday) {
897 $param .= '&search_datelimit_endday='.urlencode((string) ($search_datelimit_endday));
898}
899if ($search_datelimit_endmonth) {
900 $param .= '&search_datelimit_endmonth='.urlencode((string) ($search_datelimit_endmonth));
901}
902if ($search_datelimit_endyear) {
903 $param .= '&search_datelimit_endyear='.urlencode((string) ($search_datelimit_endyear));
904}
905if ($search_ref) {
906 $param .= '&search_ref='.urlencode($search_ref);
907}
908if ($search_refsupplier) {
909 $param .= '&search_refsupplier='.urlencode($search_refsupplier);
910}
911if ($search_type != '') {
912 $param .= '&search_type='.urlencode($search_type);
913}
914if ($search_subtype != '') {
915 $param .= '&search_subtype='.urlencode($search_subtype);
916}
917if ($search_label) {
918 $param .= '&search_label='.urlencode($search_label);
919}
920if ($search_company) {
921 $param .= '&search_company='.urlencode($search_company);
922}
923if ($search_company_alias) {
924 $param .= '&search_company_alias='.urlencode($search_company_alias);
925}
926if ($search_login) {
927 $param .= '&search_login='.urlencode($search_login);
928}
929if ($search_montant_ht != '') {
930 $param .= '&search_montant_ht='.urlencode($search_montant_ht);
931}
932if ($search_montant_vat != '') {
933 $param .= '&search_montant_vat='.urlencode($search_montant_vat);
934}
935if ($search_montant_localtax1 != '') {
936 $param .= '&search_montant_localtax1='.urlencode($search_montant_localtax1);
937}
938if ($search_montant_localtax2 != '') {
939 $param .= '&search_montant_localtax2='.urlencode($search_montant_localtax2);
940}
941if ($search_montant_ttc != '') {
942 $param .= '&search_montant_ttc='.urlencode($search_montant_ttc);
943}
944if ($search_multicurrency_code != '') {
945 $param .= '&search_multicurrency_code='.urlencode($search_multicurrency_code);
946}
947if ($search_multicurrency_tx != '') {
948 $param .= '&search_multicurrency_tx='.urlencode($search_multicurrency_tx);
949}
950if ($search_multicurrency_montant_ht != '') {
951 $param .= '&search_multicurrency_montant_ht='.urlencode($search_multicurrency_montant_ht);
952}
953if ($search_multicurrency_montant_vat != '') {
954 $param .= '&search_multicurrency_montant_vat='.urlencode($search_multicurrency_montant_vat);
955}
956if ($search_multicurrency_montant_ttc != '') {
957 $param .= '&search_multicurrency_montant_ttc='.urlencode($search_multicurrency_montant_ttc);
958}
959if ($search_amount_no_tax) {
960 $param .= '&search_amount_no_tax='.urlencode($search_amount_no_tax);
961}
962if ($search_amount_all_tax) {
963 $param .= '&search_amount_all_tax='.urlencode($search_amount_all_tax);
964}
965if ($search_status >= 0) {
966 $param .= "&search_status=".urlencode($search_status);
967}
968if ($search_paymentmode) {
969 $param .= '&search_paymentmode='.urlencode((string) ($search_paymentmode));
970}
971if ($search_paymentcond) {
972 $param .= '&search_paymentcond='.urlencode((string) ($search_paymentcond));
973}
974if ($show_files) {
975 $param .= '&show_files='.urlencode((string) ($show_files));
976}
977if ($option) {
978 $param .= "&search_option=".urlencode($option);
979}
980if ($search_categ_sup > 0) {
981 $param .= '&search_categ_sup='.$search_categ_sup;
982}
983if ($search_type_thirdparty != '' && $search_type_thirdparty > 0) {
984 $param .= '&search_type_thirdparty='.$search_type_thirdparty;
985}
986if ($search_fk_fac_rec_source) {
987 $param .= '&search_fk_fac_rec_source=' . (int) $search_fk_fac_rec_source;
988}
989
990// Add $param from extra fields
991include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
992// Add $param from hooks
993$parameters = array('param' => &$param);
994$reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
995$param .= $hookmanager->resPrint;
996
997// List of mass actions available
998$arrayofmassactions = array(
999 'validate' => img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate"),
1000 'generate_doc' => img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
1001 'builddoc' => img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
1002 //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
1003);
1004
1005if (isModEnabled('paymentbybanktransfer') && $user->hasRight("paymentbybanktransfer", "create")) {
1006 $langs->load('withdrawals');
1007 $arrayofmassactions['banktransfertrequest'] = img_picto('', 'payment', 'class="pictofixedwidth"').$langs->trans("MakeBankTransferOrder");
1008}
1009if (!empty($permissiontodelete)) {
1010 $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
1011}
1012if (GETPOSTINT('nomassaction') || in_array($massaction, array('presend', 'predelete'))) {
1013 $arrayofmassactions = array();
1014}
1015$massactionbutton = $form->selectMassAction('', $arrayofmassactions);
1016
1017$url = DOL_URL_ROOT.'/fourn/facture/card.php?action=create';
1018if (!empty($object->socid)) {
1019 $url .= '&socid='.urlencode((string) ($object->socid));
1020}
1021if (!empty($object->id)) {
1022 $url .= '&fac_rec='.urlencode((string) $object->id);
1023}
1024$i = 0;
1025print '<form method="POST" id="searchFormList" name="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
1026if ($optioncss != '') {
1027 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
1028}
1029print '<input type="hidden" name="token" value="'.newToken().'">';
1030print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
1031print '<input type="hidden" name="action" value="list">';
1032print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
1033print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
1034print '<input type="hidden" name="socid" value="'.$socid.'">';
1035print '<input type="hidden" name="page" value="'.$page.'">';
1036print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
1037print '<input type="hidden" name="page_y" value="">';
1038print '<input type="hidden" name="mode" value="'.$mode.'">';
1039
1040$newcardbutton = '';
1041$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'));
1042$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'));
1043$newcardbutton .= dolGetButtonTitleSeparator();
1044$newcardbutton .= dolGetButtonTitle($langs->trans('NewBill'), '', 'fa fa-plus-circle', $url, '', (int) ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer")));
1045
1046print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'supplier_invoice', 0, $newcardbutton, '', $limit, 0, 0, 1);
1047
1048// Add code for pre mass action (confirmation or email presend form)
1049$topicmail = "SendBillRef";
1050$modelmail = "invoice_supplier_send";
1051$objecttmp = new FactureFournisseur($db);
1052$trackid = 'sinv'.$object->id;
1053include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
1054
1055if ($search_all) {
1056 $setupstring = '';
1057 foreach ($fieldstosearchall as $key => $val) {
1058 $fieldstosearchall[$key] = $langs->trans($val);
1059 $setupstring .= $key."=".$val.";";
1060 }
1061 print '<!-- Search done like if SUPPLIER_INVOICE_QUICKSEARCH_ON_FIELDS = '.$setupstring.' -->'."\n";
1062 print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).implode(', ', $fieldstosearchall).'</div>'."\n";
1063}
1064
1065// If the user can view prospects other than his'
1066$moreforfilter = '';
1067if ($user->hasRight("user", "user", "lire")) {
1068 $langs->load("commercial");
1069 $moreforfilter .= '<div class="divsearchfield">';
1070 $tmptitle = $langs->trans('ThirdPartiesOfSaleRepresentative');
1071 $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, $tmptitle, 'maxwidth200');
1072 $moreforfilter .= '</div>';
1073}
1074// If the user can view prospects other than his'
1075if ($user->hasRight("user", "user", "lire")) {
1076 $moreforfilter .= '<div class="divsearchfield">';
1077 $tmptitle = $langs->trans('LinkedToSpecificUsers');
1078 $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$form->select_dolusers($search_user, 'search_user', $tmptitle, null, 0, '', '', '', 0, 0, '', 0, '', 'maxwidth200');
1079 $moreforfilter .= '</div>';
1080}
1081// If the user can view prospects other than his'
1082if (isModEnabled('category') && $user->hasRight('categorie', 'lire') && ($user->hasRight('produit', 'lire') || $user->hasRight('service', 'lire'))) {
1083 include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
1084 $moreforfilter .= '<div class="divsearchfield">';
1085 $tmptitle = $langs->trans('IncludingProductWithTag');
1086 $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, '', 'parent', 0, 0, 1);
1087 $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);
1088 $moreforfilter .= '</div>';
1089}
1090
1091if (isModEnabled('category')) {
1092 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
1093 $moreforfilter .= '<div class="divsearchfield">';
1094 $tmptitle = $langs->trans('SuppliersCategoriesShort');
1095 $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"').$formother->select_categories('supplier', $search_categ_sup, 'search_categ_sup', 1, $tmptitle);
1096 $moreforfilter .= '</div>';
1097}
1098$parameters = array();
1099$reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1100if (empty($reshook)) {
1101 $moreforfilter .= $hookmanager->resPrint;
1102} else {
1103 $moreforfilter = $hookmanager->resPrint;
1104}
1105
1106if (!empty($moreforfilter)) {
1107 print '<div class="liste_titre liste_titre_bydiv centpercent">';
1108 print $moreforfilter;
1109 print '</div>';
1110}
1111
1112$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
1113$htmlofselectarray = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')); // This also change content of $arrayfields with user setup
1114$selectedfields = ($mode != 'kanban' ? $htmlofselectarray : '');
1115$selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
1116
1117print '<div class="div-table-responsive">';
1118print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
1119
1120// Fields title search
1121// --------------------------------------------------------------------
1122print '<tr class="liste_titre_filter">';
1123// Action column
1124if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1125 print '<td class="liste_titre center maxwidthsearch">';
1126 $searchpicto = $form->showFilterButtons('left');
1127 print $searchpicto;
1128 print '</td>';
1129}
1130// Ref
1131if (!empty($arrayfields['f.ref']['checked'])) {
1132 print '<td class="liste_titre left">';
1133 print '<input class="flat maxwidth50" type="text" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">';
1134 print '</td>';
1135}
1136// Ref supplier
1137if (!empty($arrayfields['f.ref_supplier']['checked'])) {
1138 print '<td class="liste_titre">';
1139 print '<input class="flat maxwidth75" type="text" name="search_refsupplier" value="'.dol_escape_htmltag($search_refsupplier).'">';
1140 print '</td>';
1141}
1142// Type
1143if (!empty($arrayfields['f.type']['checked'])) {
1144 print '<td class="liste_titre maxwidthonsmartphone">';
1145 $typearray = array(
1146 FactureFournisseur::TYPE_STANDARD => $langs->trans("InvoiceStandard"),
1147 FactureFournisseur::TYPE_REPLACEMENT => $langs->trans("InvoiceReplacement"),
1148 FactureFournisseur::TYPE_CREDIT_NOTE => $langs->trans("InvoiceAvoir"),
1149 FactureFournisseur::TYPE_DEPOSIT => $langs->trans("InvoiceDeposit"),
1150 );
1151 print $form->selectarray('search_type', $typearray, $search_type, 1, 0, 0, '', 0, 0, 0, 'ASC', 'maxwidth100');
1152 print '</td>';
1153}
1154// Invoice Subtype
1155if (!empty($arrayfields['f.subtype']['checked'])) {
1156 print '<td class="liste_titre maxwidthonsmartphone" align="center">';
1157 print $form->selectarray('search_subtype', $subtypearray, $search_subtype, 1, 0, 0, '', 0, 0, 0, '', 'maxwidth100');
1158 print '</td>';
1159}
1160// Label
1161if (!empty($arrayfields['f.label']['checked'])) {
1162 print '<td class="liste_titre">';
1163 print '<input class="flat maxwidth75" type="text" name="search_label" value="'.dol_escape_htmltag($search_label).'">';
1164 print '</td>';
1165}
1166// Date invoice
1167if (!empty($arrayfields['f.datef']['checked'])) {
1168 print '<td class="liste_titre center">';
1169 print '<div class="nowrapfordate">';
1170 print $form->selectDate($search_date_start ? $search_date_start : -1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
1171 print '</div>';
1172 print '<div class="nowrapfordate">';
1173 print $form->selectDate($search_date_end ? $search_date_end : -1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
1174 print '</div>';
1175 print '</td>';
1176}
1177// Date due
1178if (!empty($arrayfields['f.date_lim_reglement']['checked'])) {
1179 print '<td class="liste_titre center">';
1180 print '<div class="">';
1181 /*
1182 print $langs->trans('From').' ';
1183 print $form->selectDate($search_datelimit_start ? $search_datelimit_start : -1, 'search_datelimit_start', 0, 0, 1);
1184 print '</div>';
1185 print '<div class="nowrap">';
1186 print $langs->trans('to').' ';*/
1187 print $form->selectDate($search_datelimit_end ? $search_datelimit_end : -1, 'search_datelimit_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("Before"));
1188 //print '<br>';
1189 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>';
1190 print '</div>';
1191 print '</td>';
1192}
1193// Project
1194if (!empty($arrayfields['p.ref']['checked'])) {
1195 print '<td class="liste_titre"><input class="flat maxwidth50" type="text" name="search_project" value="'.dol_escape_htmltag($search_project).'"></td>';
1196}
1197// Thirpdarty
1198if (!empty($arrayfields['s.nom']['checked'])) {
1199 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>';
1200}
1201// Alias
1202if (!empty($arrayfields['s.name_alias']['checked'])) {
1203 print '<td class="liste_titre"><input class="flat maxwidth50" type="text" name="search_company_alias" value="'.dol_escape_htmltag($search_company_alias).'"></td>';
1204}
1205// Town
1206if (!empty($arrayfields['s.town']['checked'])) {
1207 print '<td class="liste_titre"><input class="flat maxwidth50" type="text" name="search_town" value="'.dol_escape_htmltag($search_town).'"></td>';
1208}
1209// Zip
1210if (!empty($arrayfields['s.zip']['checked'])) {
1211 print '<td class="liste_titre"><input class="flat maxwidth50" type="text" name="search_zip" value="'.dol_escape_htmltag($search_zip).'"></td>';
1212}
1213// State
1214if (!empty($arrayfields['state.nom']['checked'])) {
1215 print '<td class="liste_titre">';
1216 print '<input class="flat maxwidth50imp" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
1217 print '</td>';
1218}
1219// Country
1220if (!empty($arrayfields['country.code_iso']['checked'])) {
1221 print '<td class="liste_titre center">';
1222 print $form->select_country($search_country, 'search_country', '', 0, 'minwidth150imp maxwidth150', 'code2', 1, 0, 1, array(), 1);
1223 print '</td>';
1224}
1225// Company type
1226if (!empty($arrayfields['typent.code']['checked'])) {
1227 print '<td class="liste_titre maxwidthonsmartphone center">';
1228 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);
1229 print '</td>';
1230}
1231// Condition of payment
1232if (!empty($arrayfields['f.fk_cond_reglement']['checked'])) {
1233 print '<td class="liste_titre left">';
1234 print $form->getSelectConditionsPaiements($search_paymentcond, 'search_paymentcond', -1, 1, 1, 'maxwidth100');
1235 print '</td>';
1236}
1237// Payment mode
1238if (!empty($arrayfields['f.fk_mode_reglement']['checked'])) {
1239 print '<td class="liste_titre">';
1240 print $form->select_types_paiements($search_paymentmode, 'search_paymentmode', '', 0, 1, 1, 20, 1, 'maxwidth100', 1);
1241 print '</td>';
1242}
1243if (!empty($arrayfields['f.total_ht']['checked'])) {
1244 // Amount without tax
1245 print '<td class="liste_titre right">';
1246 print '<input class="flat" type="text" size="5" name="search_montant_ht" value="'.dol_escape_htmltag($search_montant_ht).'">';
1247 print '</td>';
1248}
1249if (!empty($arrayfields['f.total_vat']['checked'])) {
1250 // Amount vat
1251 print '<td class="liste_titre right">';
1252 print '<input class="flat" type="text" size="5" name="search_montant_vat" value="'.dol_escape_htmltag($search_montant_vat).'">';
1253 print '</td>';
1254}
1255if (!empty($arrayfields['f.total_localtax1']['checked'])) {
1256 // Amount tax 1
1257 print '<td class="liste_titre right">';
1258 print '<input class="flat" type="text" size="5" name="search_montant_localtax1" value="'.dol_escape_htmltag($search_montant_localtax1).'">';
1259 print '</td>';
1260}
1261if (!empty($arrayfields['f.total_localtax2']['checked'])) {
1262 // Amount tax 2
1263 print '<td class="liste_titre right">';
1264 print '<input class="flat" type="text" size="5" name="search_montant_localtax2" value="'.dol_escape_htmltag($search_montant_localtax2).'">';
1265 print '</td>';
1266}
1267if (!empty($arrayfields['f.total_ttc']['checked'])) {
1268 // Amount inc tac
1269 print '<td class="liste_titre right">';
1270 print '<input class="flat" type="text" size="5" name="search_montant_ttc" value="'.dol_escape_htmltag($search_montant_ttc).'">';
1271 print '</td>';
1272}
1273if (!empty($arrayfields['f.nb_docs']['checked'])) {
1274 // Nb of attached documents
1275 print '<td class="liste_titre" align="center">';
1276 print '</td>';
1277}
1278if (!empty($arrayfields['u.login']['checked'])) {
1279 // Author
1280 print '<td class="liste_titre" align="center">';
1281 print '<input class="flat" size="4" type="text" name="search_login" value="'.dol_escape_htmltag($search_login).'">';
1282 print '</td>';
1283}
1284if (!empty($arrayfields['dynamount_payed']['checked'])) {
1285 print '<td class="liste_titre right">';
1286 print '</td>';
1287}
1288if (!empty($arrayfields['rtp']['checked'])) {
1289 print '<td class="liste_titre">';
1290 print '</td>';
1291}
1292if (!empty($arrayfields['f.multicurrency_code']['checked'])) {
1293 // Currency
1294 print '<td class="liste_titre">';
1295 print $form->selectMultiCurrency($search_multicurrency_code, 'search_multicurrency_code', 1);
1296 print '</td>';
1297}
1298if (!empty($arrayfields['f.multicurrency_tx']['checked'])) {
1299 // Currency rate
1300 print '<td class="liste_titre">';
1301 print '<input class="flat" type="text" size="4" name="search_multicurrency_tx" value="'.dol_escape_htmltag($search_multicurrency_tx).'">';
1302 print '</td>';
1303}
1304if (!empty($arrayfields['f.multicurrency_total_ht']['checked'])) {
1305 // Amount
1306 print '<td class="liste_titre right">';
1307 print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_ht" value="'.dol_escape_htmltag($search_multicurrency_montant_ht).'">';
1308 print '</td>';
1309}
1310if (!empty($arrayfields['f.multicurrency_total_vat']['checked'])) {
1311 // Amount
1312 print '<td class="liste_titre right">';
1313 print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_vat" value="'.dol_escape_htmltag($search_multicurrency_montant_vat).'">';
1314 print '</td>';
1315}
1316if (!empty($arrayfields['f.multicurrency_total_ttc']['checked'])) {
1317 // Amount
1318 print '<td class="liste_titre right">';
1319 print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_ttc" value="'.dol_escape_htmltag($search_multicurrency_montant_ttc).'">';
1320 print '</td>';
1321}
1322if (!empty($arrayfields['multicurrency_dynamount_payed']['checked'])) {
1323 print '<td class="liste_titre">';
1324 print '</td>';
1325}
1326if (!empty($arrayfields['multicurrency_rtp']['checked'])) {
1327 print '<td class="liste_titre right">';
1328 print '</td>';
1329}
1330// Extra fields
1331include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
1332
1333// Fields from hook
1334$parameters = array('arrayfields' => $arrayfields);
1335$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1336print $hookmanager->resPrint;
1337// Date creation
1338if (!empty($arrayfields['f.datec']['checked'])) {
1339 print '<td class="liste_titre">';
1340 print '</td>';
1341}
1342// Date modification
1343if (!empty($arrayfields['f.tms']['checked'])) {
1344 print '<td class="liste_titre">';
1345 print '</td>';
1346}
1347// Status
1348if (!empty($arrayfields['f.fk_statut']['checked'])) {
1349 print '<td class="liste_titre center parentonrightofpage">';
1350 $liststatus = array('0' => $langs->trans("Draft"), '1' => $langs->trans("Unpaid"), '2' => $langs->trans("Paid"));
1351 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
1352 print $form->selectarray('search_status', $liststatus, $search_status, 1, 0, 0, '', 0, 0, 0, '', 'center search_status width100 onrightofpage', 1);
1353 print '</td>';
1354}
1355// Action column
1356if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1357 print '<td class="liste_titre center maxwidthsearch">';
1358 $searchpicto = $form->showFilterButtons();
1359 print $searchpicto;
1360 print '</td>';
1361}
1362
1363print "</tr>\n";
1364
1365$totalarray = array();
1366$totalarray['nbfield'] = 0;
1367
1368// Fields title label
1369// --------------------------------------------------------------------
1370print '<tr class="liste_titre">';
1371// Action column
1372if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1373 print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
1374 $totalarray['nbfield']++;
1375}
1376if (!empty($arrayfields['f.ref']['checked'])) {
1377 print_liste_field_titre($arrayfields['f.ref']['label'], $_SERVER['PHP_SELF'], 'f.ref,f.rowid', '', $param, '', $sortfield, $sortorder);
1378 $totalarray['nbfield']++;
1379}
1380if (!empty($arrayfields['f.ref_supplier']['checked'])) {
1381 print_liste_field_titre($arrayfields['f.ref_supplier']['label'], $_SERVER["PHP_SELF"], 'f.ref_supplier', '', $param, '', $sortfield, $sortorder);
1382 $totalarray['nbfield']++;
1383}
1384if (!empty($arrayfields['f.type']['checked'])) {
1385 print_liste_field_titre($arrayfields['f.type']['label'], $_SERVER["PHP_SELF"], 'f.type', '', $param, '', $sortfield, $sortorder);
1386 $totalarray['nbfield']++;
1387}
1388if (!empty($arrayfields['f.subtype']['checked'])) {
1389 print_liste_field_titre($arrayfields['f.subtype']['label'], $_SERVER["PHP_SELF"], 'f.subtype', '', $param, '', $sortfield, $sortorder);
1390}
1391if (!empty($arrayfields['f.label']['checked'])) {
1392 print_liste_field_titre($arrayfields['f.label']['label'], $_SERVER['PHP_SELF'], "f.libelle,f.rowid", '', $param, '', $sortfield, $sortorder);
1393 $totalarray['nbfield']++;
1394}
1395if (!empty($arrayfields['f.datef']['checked'])) {
1396 print_liste_field_titre($arrayfields['f.datef']['label'], $_SERVER['PHP_SELF'], 'f.datef,f.rowid', '', $param, '', $sortfield, $sortorder, 'center ');
1397 $totalarray['nbfield']++;
1398}
1399if (!empty($arrayfields['f.date_lim_reglement']['checked'])) {
1400 print_liste_field_titre($arrayfields['f.date_lim_reglement']['label'], $_SERVER['PHP_SELF'], "f.date_lim_reglement", '', $param, '', $sortfield, $sortorder, 'center ');
1401 $totalarray['nbfield']++;
1402}
1403if (!empty($arrayfields['p.ref']['checked'])) {
1404 print_liste_field_titre($arrayfields['p.ref']['label'], $_SERVER['PHP_SELF'], "p.ref", '', $param, '', $sortfield, $sortorder);
1405 $totalarray['nbfield']++;
1406}
1407if (!empty($arrayfields['s.nom']['checked'])) {
1408 print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER['PHP_SELF'], 's.nom', '', $param, '', $sortfield, $sortorder);
1409 $totalarray['nbfield']++;
1410}
1411if (!empty($arrayfields['s.name_alias']['checked'])) {
1412 // @phan-suppress-next-line PhanTypeInvalidDimOffset
1413 print_liste_field_titre($arrayfields['s.name_alias']['label'], $_SERVER['PHP_SELF'], 's.name_alias', '', $param, '', $sortfield, $sortorder);
1414 $totalarray['nbfield']++;
1415}
1416if (!empty($arrayfields['s.town']['checked'])) {
1417 print_liste_field_titre($arrayfields['s.town']['label'], $_SERVER["PHP_SELF"], 's.town', '', $param, '', $sortfield, $sortorder);
1418 $totalarray['nbfield']++;
1419}
1420if (!empty($arrayfields['s.zip']['checked'])) {
1421 print_liste_field_titre($arrayfields['s.zip']['label'], $_SERVER["PHP_SELF"], 's.zip', '', $param, '', $sortfield, $sortorder);
1422 $totalarray['nbfield']++;
1423}
1424if (!empty($arrayfields['state.nom']['checked'])) {
1425 print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.name_alias", "", $param, '', $sortfield, $sortorder);
1426 $totalarray['nbfield']++;
1427}
1428if (!empty($arrayfields['state.name_alias']['checked'])) {
1429 print_liste_field_titre($arrayfields['state.name_alias']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder);
1430 $totalarray['nbfield']++;
1431}
1432if (!empty($arrayfields['country.code_iso']['checked'])) {
1433 print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, '', $sortfield, $sortorder, 'center ');
1434 $totalarray['nbfield']++;
1435}
1436if (!empty($arrayfields['typent.code']['checked'])) {
1437 print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, '', $sortfield, $sortorder, 'center ');
1438 $totalarray['nbfield']++;
1439}
1440if (!empty($arrayfields['f.fk_cond_reglement']['checked'])) {
1441 print_liste_field_titre($arrayfields['f.fk_cond_reglement']['label'], $_SERVER["PHP_SELF"], "f.fk_cond_reglement", "", $param, "", $sortfield, $sortorder);
1442 $totalarray['nbfield']++;
1443}
1444if (!empty($arrayfields['f.fk_mode_reglement']['checked'])) {
1445 print_liste_field_titre($arrayfields['f.fk_mode_reglement']['label'], $_SERVER["PHP_SELF"], "f.fk_mode_reglement", "", $param, "", $sortfield, $sortorder);
1446 $totalarray['nbfield']++;
1447}
1448if (!empty($arrayfields['f.total_ht']['checked'])) {
1449 print_liste_field_titre($arrayfields['f.total_ht']['label'], $_SERVER['PHP_SELF'], 'f.total_ht', '', $param, '', $sortfield, $sortorder, 'right ');
1450 $totalarray['nbfield']++;
1451}
1452if (!empty($arrayfields['f.total_vat']['checked'])) {
1453 print_liste_field_titre($arrayfields['f.total_vat']['label'], $_SERVER['PHP_SELF'], 'f.total_tva', '', $param, '', $sortfield, $sortorder, 'right ');
1454 $totalarray['nbfield']++;
1455}
1456if (!empty($arrayfields['f.total_localtax1']['checked'])) {
1457 print_liste_field_titre($arrayfields['f.total_localtax1']['label'], $_SERVER['PHP_SELF'], 'f.localtax1', '', $param, '', $sortfield, $sortorder, 'right ');
1458 $totalarray['nbfield']++;
1459}
1460if (!empty($arrayfields['f.total_localtax2']['checked'])) {
1461 print_liste_field_titre($arrayfields['f.total_localtax2']['label'], $_SERVER['PHP_SELF'], 'f.localtax2', '', $param, '', $sortfield, $sortorder, 'right ');
1462 $totalarray['nbfield']++;
1463}
1464if (!empty($arrayfields['f.total_ttc']['checked'])) {
1465 print_liste_field_titre($arrayfields['f.total_ttc']['label'], $_SERVER['PHP_SELF'], 'f.total_ttc', '', $param, '', $sortfield, $sortorder, 'right ');
1466 $totalarray['nbfield']++;
1467}
1468if (!empty($arrayfields['f.nb_docs']['checked'])) {
1469 print_liste_field_titre($arrayfields['f.nb_docs']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'right ');
1470 $totalarray['nbfield']++;
1471}
1472if (!empty($arrayfields['u.login']['checked'])) {
1473 print_liste_field_titre($arrayfields['u.login']['label'], $_SERVER["PHP_SELF"], 'u.login', '', $param, '', $sortfield, $sortorder);
1474 $totalarray['nbfield']++;
1475}
1476if (!empty($arrayfields['dynamount_payed']['checked'])) {
1477 print_liste_field_titre($arrayfields['dynamount_payed']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'right ');
1478 $totalarray['nbfield']++;
1479}
1480if (!empty($arrayfields['rtp']['checked'])) {
1481 print_liste_field_titre($arrayfields['rtp']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder);
1482 $totalarray['nbfield']++;
1483}
1484if (!empty($arrayfields['f.multicurrency_code']['checked'])) {
1485 print_liste_field_titre($arrayfields['f.multicurrency_code']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_code', '', $param, '', $sortfield, $sortorder);
1486 $totalarray['nbfield']++;
1487}
1488if (!empty($arrayfields['f.multicurrency_tx']['checked'])) {
1489 print_liste_field_titre($arrayfields['f.multicurrency_tx']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_tx', '', $param, '', $sortfield, $sortorder);
1490 $totalarray['nbfield']++;
1491}
1492if (!empty($arrayfields['f.multicurrency_total_ht']['checked'])) {
1493 print_liste_field_titre($arrayfields['f.multicurrency_total_ht']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_total_ht', '', $param, '"', $sortfield, $sortorder, 'right ');
1494 $totalarray['nbfield']++;
1495}
1496if (!empty($arrayfields['f.multicurrency_total_vat']['checked'])) {
1497 print_liste_field_titre($arrayfields['f.multicurrency_total_vat']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_total_tva', '', $param, '', $sortfield, $sortorder, 'right ');
1498 $totalarray['nbfield']++;
1499}
1500if (!empty($arrayfields['f.multicurrency_total_ttc']['checked'])) {
1501 print_liste_field_titre($arrayfields['f.multicurrency_total_ttc']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_total_ttc', '', $param, '', $sortfield, $sortorder, 'right ');
1502 $totalarray['nbfield']++;
1503}
1504if (!empty($arrayfields['multicurrency_dynamount_payed']['checked'])) {
1505 print_liste_field_titre($arrayfields['multicurrency_dynamount_payed']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'right ');
1506 $totalarray['nbfield']++;
1507}
1508if (!empty($arrayfields['multicurrency_rtp']['checked'])) {
1509 print_liste_field_titre($arrayfields['multicurrency_rtp']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'right ');
1510 $totalarray['nbfield']++;
1511}
1512// Extra fields
1513include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
1514// Hook fields
1515$parameters = array('arrayfields' => $arrayfields, 'param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder, 'totalarray' => &$totalarray);
1516$reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1517print $hookmanager->resPrint;
1518if (!empty($arrayfields['f.datec']['checked'])) {
1519 print_liste_field_titre($arrayfields['f.datec']['label'], $_SERVER["PHP_SELF"], "f.datec", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
1520 $totalarray['nbfield']++;
1521}
1522if (!empty($arrayfields['f.tms']['checked'])) {
1523 print_liste_field_titre($arrayfields['f.tms']['label'], $_SERVER["PHP_SELF"], "f.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
1524 $totalarray['nbfield']++;
1525}
1526if (!empty($arrayfields['f.fk_statut']['checked'])) {
1527 print_liste_field_titre($arrayfields['f.fk_statut']['label'], $_SERVER["PHP_SELF"], "fk_statut,paye,type", "", $param, '', $sortfield, $sortorder, 'center ');
1528 $totalarray['nbfield']++;
1529}
1530// Action column
1531if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1532 print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
1533 $totalarray['nbfield']++;
1534}
1535print '</tr>'."\n";
1536
1537$facturestatic = new FactureFournisseur($db);
1538$supplierstatic = new Fournisseur($db);
1539$projectstatic = new Project($db);
1540$userstatic = new User($db);
1541$discount = new DiscountAbsolute($db);
1542
1543// Loop on record
1544// --------------------------------------------------------------------
1545$i = 0;
1546$savnbfield = $totalarray['nbfield'];
1547$totalarray = array();
1548$totalarray['nbfield'] = 0;
1549$totalarray['val'] = array();
1550$totalarray['val']['f.total_ht'] = 0;
1551$totalarray['val']['f.total_vat'] = 0;
1552$totalarray['val']['f.total_localtax1'] = 0;
1553$totalarray['val']['f.total_localtax2'] = 0;
1554$totalarray['val']['f.total_ttc'] = 0;
1555$totalarray['val']['totalam'] = 0;
1556$totalarray['val']['rtp'] = 0;
1557
1558$imaxinloop = ($limit ? min($num, $limit) : $num);
1559while ($i < $imaxinloop) {
1560 $obj = $db->fetch_object($resql);
1561 if (empty($obj)) {
1562 break; // Should not happen
1563 }
1564
1565 $datelimit = $db->jdate($obj->datelimite);
1566
1567 $userstatic->id = $obj->fk_user_author;
1568 $userstatic->login = $obj->login;
1569 $userstatic->lastname = $obj->lastname;
1570 $userstatic->firstname = $obj->firstname;
1571 $userstatic->email = $obj->user_email;
1572 $userstatic->statut = $obj->user_statut;
1573 $userstatic->status = $obj->user_statut;
1574 $userstatic->entity = $obj->entity;
1575 $userstatic->photo = $obj->photo;
1576 $userstatic->office_phone = $obj->office_phone;
1577 $userstatic->office_fax = $obj->office_fax;
1578 $userstatic->user_mobile = $obj->user_mobile;
1579 $userstatic->job = $obj->job;
1580 $userstatic->gender = $obj->gender;
1581 $facturestatic->id = $obj->facid;
1582 $facturestatic->ref = $obj->ref;
1583 $facturestatic->type = $obj->type;
1584 $facturestatic->subtype = $obj->subtype;
1585 $facturestatic->total_ht = $obj->total_ht;
1586 $facturestatic->total_tva = $obj->total_vat;
1587 $facturestatic->total_ttc = $obj->total_ttc;
1588 $facturestatic->close_code = $obj->close_code;
1589 $facturestatic->ref_supplier = $obj->ref_supplier;
1590 $facturestatic->date_echeance = $db->jdate($obj->datelimite);
1591 $facturestatic->statut = $obj->fk_statut;
1592 $facturestatic->status = $obj->fk_statut;
1593 $facturestatic->note_public = $obj->note_public;
1594 $facturestatic->note_private = $obj->note_private;
1595 $facturestatic->multicurrency_code = $obj->multicurrency_code;
1596 $facturestatic->multicurrency_tx = $obj->multicurrency_tx;
1597 $facturestatic->multicurrency_total_ht = $obj->multicurrency_total_ht;
1598 $facturestatic->multicurrency_total_tva = $obj->multicurrency_total_vat;
1599 $facturestatic->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
1600 $thirdparty->id = $obj->socid;
1601 $thirdparty->name = $obj->name;
1602 $thirdparty->name_alias = $obj->alias;
1603 $thirdparty->client = $obj->client;
1604 $thirdparty->fournisseur = $obj->fournisseur;
1605 $thirdparty->code_client = $obj->code_client;
1606 $thirdparty->code_compta_client = $obj->code_compta_client;
1607 $thirdparty->code_fournisseur = $obj->code_fournisseur;
1608 $thirdparty->code_compta_fournisseur = $obj->code_compta_fournisseur;
1609 $thirdparty->email = $obj->email;
1610 $thirdparty->country_code = $obj->country_code;
1611
1612 $paiement = $facturestatic->getSommePaiement();
1613 $totalcreditnotes = $facturestatic->getSumCreditNotesUsed();
1614 $totaldeposits = $facturestatic->getSumDepositsUsed();
1615 $totalpay = $paiement + $totalcreditnotes + $totaldeposits;
1616 $remaintopay = $obj->total_ttc - $totalpay;
1617
1618 $multicurrency_paiement = $facturestatic->getSommePaiement(1);
1619 $multicurrency_totalcreditnotes = $facturestatic->getSumCreditNotesUsed(1);
1620 $multicurrency_totaldeposits = $facturestatic->getSumDepositsUsed(1);
1621
1622 $totalpay = $paiement + $totalcreditnotes + $totaldeposits;
1623 $remaintopay = price2num($facturestatic->total_ttc - $totalpay);
1624
1625 $multicurrency_totalpay = $multicurrency_paiement + $multicurrency_totalcreditnotes + $multicurrency_totaldeposits;
1626 $multicurrency_remaintopay = price2num($facturestatic->multicurrency_total_ttc - $multicurrency_totalpay);
1627
1628 if ($facturestatic->status == FactureFournisseur::STATUS_CLOSED && $facturestatic->close_code == 'discount_vat') { // If invoice closed with discount for anticipated payment
1629 $remaintopay = 0;
1630 $multicurrency_remaintopay = 0;
1631 }
1632 if ($facturestatic->type == FactureFournisseur::TYPE_CREDIT_NOTE && $obj->paye == 1) { // If credit note closed, we take into account the amount not yet consumed
1633 $remaincreditnote = $discount->getAvailableDiscounts($thirdparty, null, 'rc.fk_facture_source='.$facturestatic->id);
1634 $remaintopay = -$remaincreditnote;
1635 $totalpay = price2num($facturestatic->total_ttc - $remaintopay);
1636 $multicurrency_remaincreditnote = $discount->getAvailableDiscounts($thirdparty, null, 'rc.fk_facture_source='.$facturestatic->id, 0, 0, 1);
1637 $multicurrency_remaintopay = -$multicurrency_remaincreditnote;
1638 $multicurrency_totalpay = price2num($facturestatic->multicurrency_total_ttc - $multicurrency_remaintopay);
1639 }
1640
1641 $facturestatic->alreadypaid = ($paiement ? $paiement : 0);
1642
1643 $facturestatic->paye = $obj->paye;
1644 $facturestatic->paid = $obj->paye;
1645
1646 $facturestatic->date = $db->jdate($obj->datef);
1647
1648 $object = $facturestatic;
1649
1650 //If invoice has been converted and the conversion has been used, we don't have remain to pay on invoice
1651 if ($facturestatic->type == FactureFournisseur::TYPE_CREDIT_NOTE) {
1652 if ($facturestatic->isCreditNoteUsed()) {
1653 $remaintopay = -$facturestatic->getSumFromThisCreditNotesNotUsed();
1654 }
1655 }
1656
1657 if ($mode == 'kanban') {
1658 if ($i == 0) {
1659 print '<tr class="trkanban"><td colspan="'.$savnbfield.'">';
1660 print '<div class="box-flex-container kanban">';
1661 }
1662 // Output Kanban
1663 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
1664 $selected = 0;
1665 if (in_array($object->id, $arrayofselected)) {
1666 $selected = 1;
1667 }
1668 }
1669
1670 $arraydata = array('alreadypaid' => $paiement, 'thirdparty' => $thirdparty->getNomUrl(1, '', 12), 'selected' => in_array($object->id, $arrayofselected));
1671 print $facturestatic->getKanbanView('', $arraydata);
1672 if ($i == ($imaxinloop - 1)) {
1673 print '</div>';
1674 print '</td></tr>';
1675 }
1676 } else {
1677 // Show line of result
1678 $j = 0;
1679 print '<tr data-rowid="'.$object->id.'" class="oddeven '.((getDolGlobalInt('MAIN_FINISHED_LINES_OPACITY') == 1 && $obj->fk_statut > 1) ? 'opacitymedium' : '').'">';
1680
1681 // Action column
1682 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1683 print '<td class="nowrap center">';
1684 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
1685 $selected = 0;
1686 if (in_array($obj->facid, $arrayofselected)) {
1687 $selected = 1;
1688 }
1689 print '<input id="cb'.$obj->facid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->facid.'"'.($selected ? ' checked="checked"' : '').'>';
1690 }
1691 print '</td>';
1692 if (!$i) {
1693 $totalarray['nbfield']++;
1694 }
1695 }
1696 if (!empty($arrayfields['f.ref']['checked'])) {
1697 print '<td class="nowraponall">';
1698
1699 print '<table class="nobordernopadding"><tr class="nocellnopadd">';
1700 // Picto + Ref
1701 print '<td class="nobordernopadding nowraponall">';
1702 print $facturestatic->getNomUrl(1, '', 0, 0, '', 0, -1, 1);
1703
1704 $filename = dol_sanitizeFileName($obj->ref);
1705 $filedir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($obj->facid, 2, 0, 0, $facturestatic, 'invoice_supplier').dol_sanitizeFileName($obj->ref);
1706 $subdir = get_exdir($obj->facid, 2, 0, 0, $facturestatic, 'invoice_supplier').dol_sanitizeFileName($obj->ref);
1707 print $formfile->getDocumentsLink('facture_fournisseur', $subdir, $filedir);
1708 print '</td></tr></table>';
1709
1710 print "</td>\n";
1711 if (!$i) {
1712 $totalarray['nbfield']++;
1713 }
1714 }
1715
1716 // Supplier ref
1717 if (!empty($arrayfields['f.ref_supplier']['checked'])) {
1718 print '<td class="nowrap tdoverflowmax150" title="'.dol_escape_htmltag($obj->ref_supplier).'">';
1719 print $obj->ref_supplier;
1720 print '</td>';
1721 if (!$i) {
1722 $totalarray['nbfield']++;
1723 }
1724 }
1725
1726 // Type
1727 if (!empty($arrayfields['f.type']['checked'])) {
1728 print '<td class="nowrap">';
1729 print $facturestatic->getLibType();
1730 print "</td>";
1731 if (!$i) {
1732 $totalarray['nbfield']++;
1733 }
1734 }
1735
1736 // Invoice Subtype
1737 if (!empty($arrayfields['f.subtype']['checked'])) {
1738 $labeltoshow = '';
1739 if ($facturestatic->subtype > 0) {
1740 $labeltoshow = $facturestatic->getSubtypeLabel('facture_fourn');
1741 }
1742 print '<td class="nowraponall tdoverflowmax300" title="'.$labeltoshow.'">';
1743 print $labeltoshow;
1744 print "</td>";
1745 if (!$i) {
1746 $totalarray['nbfield']++;
1747 }
1748 }
1749
1750 // Label
1751 if (!empty($arrayfields['f.label']['checked'])) {
1752 print '<td class="nowrap tdoverflowmax125" title="'.dol_escape_htmltag($obj->label).'">';
1753 print dol_escape_htmltag($obj->label);
1754 print '</td>';
1755 if (!$i) {
1756 $totalarray['nbfield']++;
1757 }
1758 }
1759
1760 // Date
1761 if (!empty($arrayfields['f.datef']['checked'])) {
1762 print '<td class="center nowrap">';
1763 print dol_print_date($db->jdate($obj->datef), 'day');
1764 print '</td>';
1765 if (!$i) {
1766 $totalarray['nbfield']++;
1767 }
1768 }
1769
1770 // Date limit
1771 if (!empty($arrayfields['f.date_lim_reglement']['checked'])) {
1772 print '<td class="center nowraponall">'.dol_print_date($datelimit, 'day');
1773 if ($facturestatic->hasDelay()) {
1774 print img_warning($langs->trans('Alert').' - '.$langs->trans('Late'));
1775 }
1776 print '</td>';
1777 if (!$i) {
1778 $totalarray['nbfield']++;
1779 }
1780 }
1781
1782 // Project
1783 if (!empty($arrayfields['p.ref']['checked'])) {
1784 print '<td class="nowrap">';
1785 if ($obj->project_id > 0) {
1786 $projectstatic->id = $obj->project_id;
1787 $projectstatic->ref = $obj->project_ref;
1788 $projectstatic->title = $obj->project_label;
1789 print $projectstatic->getNomUrl(1);
1790 }
1791 print '</td>';
1792 if (!$i) {
1793 $totalarray['nbfield']++;
1794 }
1795 }
1796
1797 // Third party
1798 if (!empty($arrayfields['s.nom']['checked'])) {
1799 print '<td class="tdoverflowmax125">';
1800 print $thirdparty->getNomUrl(1, 'supplier', 0, 0, -1, empty($arrayfields['s.name_alias']['checked']) ? 0 : 1);
1801 print '</td>';
1802 if (!$i) {
1803 $totalarray['nbfield']++;
1804 }
1805 }
1806 // Alias
1807 if (!empty($arrayfields['s.name_alias']['checked'])) {
1808 print '<td class="tdoverflowmax150">';
1809 print dol_escape_htmltag($thirdparty->name_alias);
1810 print '</td>';
1811 if (!$i) {
1812 $totalarray['nbfield']++;
1813 }
1814 }
1815 // Town
1816 if (!empty($arrayfields['s.town']['checked'])) {
1817 print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->town).'">';
1818 print dol_escape_htmltag($obj->town);
1819 print '</td>';
1820 if (!$i) {
1821 $totalarray['nbfield']++;
1822 }
1823 }
1824 // Zip
1825 if (!empty($arrayfields['s.zip']['checked'])) {
1826 print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->zip).'">';
1827 print dol_escape_htmltag($obj->zip);
1828 print '</td>';
1829 if (!$i) {
1830 $totalarray['nbfield']++;
1831 }
1832 }
1833 // State
1834 if (!empty($arrayfields['state.nom']['checked'])) {
1835 print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->state_name).'">';
1836 print dol_escape_htmltag($obj->state_name);
1837 print "</td>\n";
1838 if (!$i) {
1839 $totalarray['nbfield']++;
1840 }
1841 }
1842 // Country
1843 if (!empty($arrayfields['country.code_iso']['checked'])) {
1844 print '<td class="center">';
1845 $tmparray = getCountry($obj->fk_pays, 'all');
1846 print $tmparray['label'];
1847 print '</td>';
1848 if (!$i) {
1849 $totalarray['nbfield']++;
1850 }
1851 }
1852 // Type ent
1853 if (!empty($arrayfields['typent.code']['checked'])) {
1854 print '<td class="center">';
1855 if (empty($typenArray)) {
1856 $typenArray = $formcompany->typent_array(1);
1857 }
1858 print $typenArray[$obj->typent_code];
1859 print '</td>';
1860 if (!$i) {
1861 $totalarray['nbfield']++;
1862 }
1863 }
1864
1865 // Payment condition
1866 if (!empty($arrayfields['f.fk_cond_reglement']['checked'])) {
1867 $s = $form->form_conditions_reglement($_SERVER['PHP_SELF'], $obj->fk_cond_reglement, 'none', 1, '', -1, -1, 1);
1868 print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($s).'">';
1869 print dol_escape_htmltag($s);
1870 print '</td>';
1871 if (!$i) {
1872 $totalarray['nbfield']++;
1873 }
1874 }
1875 // Payment mode
1876 if (!empty($arrayfields['f.fk_mode_reglement']['checked'])) {
1877 $s = $form->form_modes_reglement($_SERVER['PHP_SELF'], $obj->fk_mode_reglement, 'none', '', -1, 0, '', 1);
1878 print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($s).'">';
1879 print dol_escape_htmltag($s);
1880 print '</td>';
1881 if (!$i) {
1882 $totalarray['nbfield']++;
1883 }
1884 }
1885
1886 // Amount HT
1887 if (!empty($arrayfields['f.total_ht']['checked'])) {
1888 print '<td class="right nowrap"><span class="amount">'.price($obj->total_ht)."</span></td>\n";
1889 if (!$i) {
1890 $totalarray['nbfield']++;
1891 $totalarray['pos'][$totalarray['nbfield']] = 'f.total_ht';
1892 }
1893 $totalarray['val']['f.total_ht'] += $obj->total_ht;
1894 }
1895 // Amount VAT
1896 if (!empty($arrayfields['f.total_vat']['checked'])) {
1897 print '<td class="right nowrap"><span class="amount">'.price($obj->total_vat)."</span></td>\n";
1898 if (!$i) {
1899 $totalarray['nbfield']++;
1900 $totalarray['pos'][$totalarray['nbfield']] = 'f.total_vat';
1901 }
1902 $totalarray['val']['f.total_vat'] += $obj->total_vat;
1903 }
1904 // Amount LocalTax1
1905 if (!empty($arrayfields['f.total_localtax1']['checked'])) {
1906 print '<td class="right nowrap"><span class="amount">'.price($obj->total_localtax1)."</span></td>\n";
1907 if (!$i) {
1908 $totalarray['nbfield']++;
1909 $totalarray['pos'][$totalarray['nbfield']] = 'f.total_localtax1';
1910 }
1911 $totalarray['val']['f.total_localtax1'] += $obj->total_localtax1;
1912 }
1913 // Amount LocalTax2
1914 if (!empty($arrayfields['f.total_localtax2']['checked'])) {
1915 print '<td class="right nowrap"><span class="amount">'.price($obj->total_localtax2)."</span></td>\n";
1916 if (!$i) {
1917 $totalarray['nbfield']++;
1918 $totalarray['pos'][$totalarray['nbfield']] = 'f.total_localtax2';
1919 }
1920 $totalarray['val']['f.total_localtax2'] += $obj->total_localtax2;
1921 }
1922 // Amount TTC
1923 if (!empty($arrayfields['f.total_ttc']['checked'])) {
1924 print '<td class="right nowrap"><span class="amount">'.price($obj->total_ttc)."</span></td>\n";
1925 if (!$i) {
1926 $totalarray['nbfield']++;
1927 $totalarray['pos'][$totalarray['nbfield']] = 'f.total_ttc';
1928 }
1929 $totalarray['val']['f.total_ttc'] += $obj->total_ttc;
1930 }
1931
1932 // Number of attached documents (may slow your application on large lists)
1933 if (!empty($arrayfields['f.nb_docs']['checked'])) {
1934 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
1935 require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
1936 $upload_dir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($facturestatic->id, 2, 0, 0, $facturestatic, 'invoice_supplier').$facturestatic->ref;
1937 $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
1938 $nbLinks = Link::count($db, $facturestatic->element, $facturestatic->id);
1939 $nbTotal = $nbFiles + $nbLinks;
1940 echo '<td class="center">'.(empty($nbTotal) ? '' : $nbTotal).'</td>';
1941 if (!$i) {
1942 $totalarray['nbfield']++;
1943 }
1944 }
1945
1946 // Author
1947 if (!empty($arrayfields['u.login']['checked'])) {
1948 print '<td class="tdoverflowmax100">';
1949 if ($userstatic->id) {
1950 print $userstatic->getNomUrl(-1);
1951 } else {
1952 print '&nbsp;';
1953 }
1954 print "</td>\n";
1955 if (!$i) {
1956 $totalarray['nbfield']++;
1957 }
1958 }
1959
1960 // Dynamic amount paid
1961 if (!empty($arrayfields['dynamount_payed']['checked'])) {
1962 print '<td class="right nowrap"><span class="amount">'.(!empty($totalpay) ? price($totalpay, 0, $langs) : '').'</span></td>'; // TODO Use a denormalized field
1963 if (!$i) {
1964 $totalarray['nbfield']++;
1965 $totalarray['pos'][$totalarray['nbfield']] = 'totalam';
1966 }
1967 $totalarray['val']['totalam'] += $totalpay;
1968 }
1969
1970 // Remain to pay
1971 if (!empty($arrayfields['rtp']['checked'])) {
1972 print '<td class="right nowrap">'.(!empty($remaintopay) ? price($remaintopay, 0, $langs) : '&nbsp;').'</td>'; // TODO Use a denormalized field
1973 if (!$i) {
1974 $totalarray['nbfield']++;
1975 $totalarray['pos'][$totalarray['nbfield']] = 'rtp';
1976 }
1977 $totalarray['val']['rtp'] += $remaintopay;
1978 }
1979
1980 // Currency
1981 if (!empty($arrayfields['f.multicurrency_code']['checked'])) {
1982 print '<td class="nowrap">'.$obj->multicurrency_code.' - '.$langs->trans('Currency'.$obj->multicurrency_code)."</td>\n";
1983 if (!$i) {
1984 $totalarray['nbfield']++;
1985 }
1986 }
1987
1988 // Currency rate
1989 if (!empty($arrayfields['f.multicurrency_tx']['checked'])) {
1990 print '<td class="nowrap">';
1991 $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$obj->rowid, $obj->multicurrency_tx, 'none', $obj->multicurrency_code);
1992 print "</td>\n";
1993 if (!$i) {
1994 $totalarray['nbfield']++;
1995 }
1996 }
1997 // Amount HT
1998 if (!empty($arrayfields['f.multicurrency_total_ht']['checked'])) {
1999 print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_ht)."</span></td>\n";
2000 if (!$i) {
2001 $totalarray['nbfield']++;
2002 }
2003 }
2004 // Amount VAT
2005 if (!empty($arrayfields['f.multicurrency_total_vat']['checked'])) {
2006 print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_vat)."</span></td>\n";
2007 if (!$i) {
2008 $totalarray['nbfield']++;
2009 }
2010 }
2011 // Amount TTC
2012 if (!empty($arrayfields['f.multicurrency_total_ttc']['checked'])) {
2013 print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_ttc)."</span></td>\n";
2014 if (!$i) {
2015 $totalarray['nbfield']++;
2016 }
2017 }
2018 // Dynamic amount paid
2019 if (!empty($arrayfields['multicurrency_dynamount_payed']['checked'])) {
2020 print '<td class="right nowrap"><span class="amount">'.(!empty($multicurrency_totalpay) ? price($multicurrency_totalpay, 0, $langs) : '').'</span></td>'; // TODO Use a denormalized field
2021 if (!$i) {
2022 $totalarray['nbfield']++;
2023 }
2024 }
2025
2026 // Pending amount
2027 if (!empty($arrayfields['multicurrency_rtp']['checked'])) {
2028 print '<td class="right nowrap"><span class="amount">';
2029 print(!empty($multicurrency_remaintopay) ? price($multicurrency_remaintopay, 0, $langs) : '');
2030 print '</span></td>'; // TODO Use a denormalized field
2031 if (!$i) {
2032 $totalarray['nbfield']++;
2033 }
2034 }
2035
2036
2037 // Extra fields
2038 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
2039 // Fields from hook
2040 $parameters = array('arrayfields' => $arrayfields, 'object' => $object, 'obj' => $obj, 'i' => $i, 'totalarray' => &$totalarray);
2041 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
2042 print $hookmanager->resPrint;
2043
2044 // Date creation
2045 if (!empty($arrayfields['f.datec']['checked'])) {
2046 print '<td class="center nowraponall">';
2047 print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
2048 print '</td>';
2049 if (!$i) {
2050 $totalarray['nbfield']++;
2051 }
2052 }
2053 // Date modification
2054 if (!empty($arrayfields['f.tms']['checked'])) {
2055 print '<td class="center nowraponall">';
2056 print dol_print_date($db->jdate($obj->date_modification), 'dayhour', 'tzuser');
2057 print '</td>';
2058 if (!$i) {
2059 $totalarray['nbfield']++;
2060 }
2061 }
2062 // Status
2063 if (!empty($arrayfields['f.fk_statut']['checked'])) {
2064 print '<td class="center nowrap">';
2065 print $facturestatic->getLibStatut(5, $paiement);
2066 print "</td>";
2067 if (!$i) {
2068 $totalarray['nbfield']++;
2069 }
2070 }
2071
2072 // Action column
2073 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
2074 print '<td class="nowrap center">';
2075 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
2076 $selected = 0;
2077 if (in_array($obj->facid, $arrayofselected)) {
2078 $selected = 1;
2079 }
2080 print '<input id="cb'.$obj->facid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->facid.'"'.($selected ? ' checked="checked"' : '').'>';
2081 }
2082 print '</td>';
2083 if (!$i) {
2084 $totalarray['nbfield']++;
2085 }
2086 }
2087
2088 print '</tr>'."\n";
2089 }
2090
2091 $i++;
2092}
2093
2094// Show total line
2095include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
2096
2097// If no record found
2098if ($num == 0) {
2099 $colspan = 1;
2100 foreach ($arrayfields as $key => $val) {
2101 if (!empty($val['checked'])) {
2102 $colspan++;
2103 }
2104 }
2105 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
2106}
2107
2108$db->free($resql);
2109
2110$parameters = array('arrayfields' => $arrayfields, 'sql' => $sql);
2111$reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
2112print $hookmanager->resPrint;
2113
2114print '</table>'."\n";
2115print '</div>'."\n";
2116
2117print '</form>'."\n";
2118
2119if (in_array('builddoc', array_keys($arrayofmassactions)) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
2120 $hidegeneratedfilelistifempty = 1;
2121 if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
2122 $hidegeneratedfilelistifempty = 0;
2123 }
2124
2125 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
2126 $formfile = new FormFile($db);
2127
2128 // Show list of available documents
2129 $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
2130 $urlsource .= str_replace('&amp;', '&', $param);
2131
2132 $filedir = $diroutputmassaction;
2133 $genallowed = $permissiontoread;
2134 $delallowed = $permissiontoadd;
2135 $title = '';
2136
2137 print $formfile->showdocuments('massfilesarea_supplier_invoice', '', $filedir, $urlsource, 0, (int) $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
2138}
2139
2140// End of page
2141llxFooter();
2142$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.