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