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