dolibarr 21.0.0-alpha
list.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2002-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2019 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2013 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2013-2019 Philippe Grand <philippe.grand@atoo-net.com>
6 * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
7 * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
8 * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
9 * Copyright (C) 2015-2007 Juanjo Menent <jmenent@2byte.es>
10 * Copyright (C) 2015 Abbes Bahfir <bafbes@gmail.com>
11 * Copyright (C) 2015-2016 Ferran Marcet <fmarcet@2byte.es>
12 * Copyright (C) 2017 Josep Lluís Amador <joseplluis@lliuretic.cat>
13 * Copyright (C) 2018-2022 Charlene Benke <charlene@patas-monkey.com>
14 * Copyright (C) 2018-2024 Frédéric France <frederic.france@free.fr>
15 * Copyright (C) 2019-2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
16 * Copyright (C) 2023 Nick Fragoulis
17 * Copyright (C) 2023 Joachim Kueter <git-jk@bloxera.com>
18 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
19 *
20 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation; either version 3 of the License, or
23 * (at your option) any later version.
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
29 *
30 * You should have received a copy of the GNU General Public License
31 * along with this program. If not, see <https://www.gnu.org/licenses/>.
32 */
33
40// Load Dolibarr environment
41require '../../main.inc.php';
42require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
43require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
44require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
45require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
46require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
47require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
48require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
49require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
50require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
51require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
52
53// Load translation files required by the page
54$langs->loadLangs(array('products', 'bills', 'companies', 'projects'));
55
56$action = GETPOST('action', 'aZ09');
57$massaction = GETPOST('massaction', 'alpha');
58$show_files = GETPOSTINT('show_files');
59$confirm = GETPOST('confirm', 'alpha');
60$toselect = GETPOST('toselect', 'array');
61$optioncss = GETPOST('optioncss', 'alpha');
62$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'supplierinvoicelist';
63$mode = GETPOST('mode', 'aZ'); // The output mode ('list', 'kanban', 'hierarchy', 'calendar', ...)
64
65$search_all = trim((GETPOST('search_all', 'alphanohtml') != '') ? GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
66$search_label = GETPOST("search_label", "alpha");
67$search_amount_no_tax = GETPOST("search_amount_no_tax", "alpha");
68$search_amount_all_tax = GETPOST("search_amount_all_tax", "alpha");
69$search_ref = GETPOST('sf_ref') ? GETPOST('sf_ref', 'alpha') : GETPOST('search_ref', 'alpha');
70$search_refsupplier = GETPOST('search_refsupplier', 'alpha');
71$search_type = GETPOST('search_type', 'intcomma');
72$search_subtype = GETPOST('search_subtype', 'intcomma');
73$search_project = GETPOST('search_project', 'alpha');
74$search_company = GETPOST('search_company', 'alpha');
75$search_company_alias = GETPOST('search_company_alias', 'alpha');
76$search_montant_ht = GETPOST('search_montant_ht', 'alpha');
77$search_montant_vat = GETPOST('search_montant_vat', 'alpha');
78$search_montant_localtax1 = GETPOST('search_montant_localtax1', 'alpha');
79$search_montant_localtax2 = GETPOST('search_montant_localtax2', 'alpha');
80$search_montant_ttc = GETPOST('search_montant_ttc', 'alpha');
81$search_login = GETPOST('search_login', 'alpha');
82$search_multicurrency_code = GETPOST('search_multicurrency_code', 'alpha');
83$search_multicurrency_tx = GETPOST('search_multicurrency_tx', 'alpha');
84$search_multicurrency_montant_ht = GETPOST('search_multicurrency_montant_ht', 'alpha');
85$search_multicurrency_montant_vat = GETPOST('search_multicurrency_montant_vat', 'alpha');
86$search_multicurrency_montant_ttc = GETPOST('search_multicurrency_montant_ttc', 'alpha');
87$search_status = GETPOST('search_status', 'intcomma'); // Can be '' or a numeric
88$search_paymentmode = GETPOST('search_paymentmode', 'intcomma');
89$search_paymentcond = GETPOST('search_paymentcond', 'intcomma');
90$search_town = GETPOST('search_town', 'alpha');
91$search_zip = GETPOST('search_zip', 'alpha');
92$search_state = GETPOST("search_state");
93$search_country = GETPOST("search_country", 'aZ09');
94$search_type_thirdparty = GETPOST("search_type_thirdparty", 'intcomma');
95$search_user = GETPOST('search_user', 'intcomma');
96$search_sale = GETPOST('search_sale', 'intcomma');
97$search_date_start = GETPOSTDATE('search_date_start', '', 'tzserver');
98$search_date_end = GETPOSTDATE('search_date_end', '23:59:59', 'tzserver');
99$search_datelimit_startday = GETPOSTINT('search_datelimit_startday');
100$search_datelimit_startmonth = GETPOSTINT('search_datelimit_startmonth');
101$search_datelimit_startyear = GETPOSTINT('search_datelimit_startyear');
102$search_datelimit_endday = GETPOSTINT('search_datelimit_endday');
103$search_datelimit_endmonth = GETPOSTINT('search_datelimit_endmonth');
104$search_datelimit_endyear = GETPOSTINT('search_datelimit_endyear');
105$search_datelimit_start = dol_mktime(0, 0, 0, $search_datelimit_startmonth, $search_datelimit_startday, $search_datelimit_startyear);
106$search_datelimit_end = dol_mktime(23, 59, 59, $search_datelimit_endmonth, $search_datelimit_endday, $search_datelimit_endyear);
107$search_categ_sup = GETPOST("search_categ_sup", 'intcomma');
108$search_product_category = GETPOST('search_product_category', 'intcomma');
109
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 a technical object to manage hooks of page. Note that conf->hooks_modules contains an 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 mod-fourn-facture page-list');
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, '', (int) ($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 // @phan-suppress-next-line PhanTypeInvalidDimOffset
1374 print_liste_field_titre($arrayfields['s.name_alias']['label'], $_SERVER['PHP_SELF'], 's.name_alias', '', $param, '', $sortfield, $sortorder);
1375 $totalarray['nbfield']++;
1376}
1377if (!empty($arrayfields['s.town']['checked'])) {
1378 print_liste_field_titre($arrayfields['s.town']['label'], $_SERVER["PHP_SELF"], 's.town', '', $param, '', $sortfield, $sortorder);
1379 $totalarray['nbfield']++;
1380}
1381if (!empty($arrayfields['s.zip']['checked'])) {
1382 print_liste_field_titre($arrayfields['s.zip']['label'], $_SERVER["PHP_SELF"], 's.zip', '', $param, '', $sortfield, $sortorder);
1383 $totalarray['nbfield']++;
1384}
1385if (!empty($arrayfields['state.nom']['checked'])) {
1386 print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.name_alias", "", $param, '', $sortfield, $sortorder);
1387 $totalarray['nbfield']++;
1388}
1389if (!empty($arrayfields['state.name_alias']['checked'])) {
1390 print_liste_field_titre($arrayfields['state.name_alias']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder);
1391 $totalarray['nbfield']++;
1392}
1393if (!empty($arrayfields['country.code_iso']['checked'])) {
1394 print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, '', $sortfield, $sortorder, 'center ');
1395 $totalarray['nbfield']++;
1396}
1397if (!empty($arrayfields['typent.code']['checked'])) {
1398 print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, '', $sortfield, $sortorder, 'center ');
1399 $totalarray['nbfield']++;
1400}
1401if (!empty($arrayfields['f.fk_cond_reglement']['checked'])) {
1402 print_liste_field_titre($arrayfields['f.fk_cond_reglement']['label'], $_SERVER["PHP_SELF"], "f.fk_cond_reglement", "", $param, "", $sortfield, $sortorder);
1403 $totalarray['nbfield']++;
1404}
1405if (!empty($arrayfields['f.fk_mode_reglement']['checked'])) {
1406 print_liste_field_titre($arrayfields['f.fk_mode_reglement']['label'], $_SERVER["PHP_SELF"], "f.fk_mode_reglement", "", $param, "", $sortfield, $sortorder);
1407 $totalarray['nbfield']++;
1408}
1409if (!empty($arrayfields['f.total_ht']['checked'])) {
1410 print_liste_field_titre($arrayfields['f.total_ht']['label'], $_SERVER['PHP_SELF'], 'f.total_ht', '', $param, '', $sortfield, $sortorder, 'right ');
1411 $totalarray['nbfield']++;
1412}
1413if (!empty($arrayfields['f.total_vat']['checked'])) {
1414 print_liste_field_titre($arrayfields['f.total_vat']['label'], $_SERVER['PHP_SELF'], 'f.total_tva', '', $param, '', $sortfield, $sortorder, 'right ');
1415 $totalarray['nbfield']++;
1416}
1417if (!empty($arrayfields['f.total_localtax1']['checked'])) {
1418 print_liste_field_titre($arrayfields['f.total_localtax1']['label'], $_SERVER['PHP_SELF'], 'f.localtax1', '', $param, '', $sortfield, $sortorder, 'right ');
1419 $totalarray['nbfield']++;
1420}
1421if (!empty($arrayfields['f.total_localtax2']['checked'])) {
1422 print_liste_field_titre($arrayfields['f.total_localtax2']['label'], $_SERVER['PHP_SELF'], 'f.localtax2', '', $param, '', $sortfield, $sortorder, 'right ');
1423 $totalarray['nbfield']++;
1424}
1425if (!empty($arrayfields['f.total_ttc']['checked'])) {
1426 print_liste_field_titre($arrayfields['f.total_ttc']['label'], $_SERVER['PHP_SELF'], 'f.total_ttc', '', $param, '', $sortfield, $sortorder, 'right ');
1427 $totalarray['nbfield']++;
1428}
1429if (!empty($arrayfields['f.nb_docs']['checked'])) {
1430 print_liste_field_titre($arrayfields['f.nb_docs']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'right ');
1431 $totalarray['nbfield']++;
1432}
1433if (!empty($arrayfields['u.login']['checked'])) {
1434 print_liste_field_titre($arrayfields['u.login']['label'], $_SERVER["PHP_SELF"], 'u.login', '', $param, '', $sortfield, $sortorder);
1435 $totalarray['nbfield']++;
1436}
1437if (!empty($arrayfields['dynamount_payed']['checked'])) {
1438 print_liste_field_titre($arrayfields['dynamount_payed']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'right ');
1439 $totalarray['nbfield']++;
1440}
1441if (!empty($arrayfields['rtp']['checked'])) {
1442 print_liste_field_titre($arrayfields['rtp']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder);
1443 $totalarray['nbfield']++;
1444}
1445if (!empty($arrayfields['f.multicurrency_code']['checked'])) {
1446 print_liste_field_titre($arrayfields['f.multicurrency_code']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_code', '', $param, '', $sortfield, $sortorder);
1447 $totalarray['nbfield']++;
1448}
1449if (!empty($arrayfields['f.multicurrency_tx']['checked'])) {
1450 print_liste_field_titre($arrayfields['f.multicurrency_tx']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_tx', '', $param, '', $sortfield, $sortorder);
1451 $totalarray['nbfield']++;
1452}
1453if (!empty($arrayfields['f.multicurrency_total_ht']['checked'])) {
1454 print_liste_field_titre($arrayfields['f.multicurrency_total_ht']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_total_ht', '', $param, '"', $sortfield, $sortorder, 'right ');
1455 $totalarray['nbfield']++;
1456}
1457if (!empty($arrayfields['f.multicurrency_total_vat']['checked'])) {
1458 print_liste_field_titre($arrayfields['f.multicurrency_total_vat']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_total_tva', '', $param, '', $sortfield, $sortorder, 'right ');
1459 $totalarray['nbfield']++;
1460}
1461if (!empty($arrayfields['f.multicurrency_total_ttc']['checked'])) {
1462 print_liste_field_titre($arrayfields['f.multicurrency_total_ttc']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_total_ttc', '', $param, '', $sortfield, $sortorder, 'right ');
1463 $totalarray['nbfield']++;
1464}
1465if (!empty($arrayfields['multicurrency_dynamount_payed']['checked'])) {
1466 print_liste_field_titre($arrayfields['multicurrency_dynamount_payed']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'right ');
1467 $totalarray['nbfield']++;
1468}
1469if (!empty($arrayfields['multicurrency_rtp']['checked'])) {
1470 print_liste_field_titre($arrayfields['multicurrency_rtp']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'right ');
1471 $totalarray['nbfield']++;
1472}
1473// Extra fields
1474include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
1475// Hook fields
1476$parameters = array('arrayfields' => $arrayfields, 'param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder, 'totalarray' => &$totalarray);
1477$reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1478print $hookmanager->resPrint;
1479if (!empty($arrayfields['f.datec']['checked'])) {
1480 print_liste_field_titre($arrayfields['f.datec']['label'], $_SERVER["PHP_SELF"], "f.datec", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
1481 $totalarray['nbfield']++;
1482}
1483if (!empty($arrayfields['f.tms']['checked'])) {
1484 print_liste_field_titre($arrayfields['f.tms']['label'], $_SERVER["PHP_SELF"], "f.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
1485 $totalarray['nbfield']++;
1486}
1487if (!empty($arrayfields['f.fk_statut']['checked'])) {
1488 print_liste_field_titre($arrayfields['f.fk_statut']['label'], $_SERVER["PHP_SELF"], "fk_statut,paye,type", "", $param, '', $sortfield, $sortorder, 'center ');
1489 $totalarray['nbfield']++;
1490}
1491// Action column
1492if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1493 print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
1494 $totalarray['nbfield']++;
1495}
1496print '</tr>'."\n";
1497
1498$facturestatic = new FactureFournisseur($db);
1499$supplierstatic = new Fournisseur($db);
1500$projectstatic = new Project($db);
1501$userstatic = new User($db);
1502$discount = new DiscountAbsolute($db);
1503
1504// Loop on record
1505// --------------------------------------------------------------------
1506$i = 0;
1507$savnbfield = $totalarray['nbfield'];
1508$totalarray = array();
1509$totalarray['nbfield'] = 0;
1510$totalarray['val'] = array();
1511$totalarray['val']['f.total_ht'] = 0;
1512$totalarray['val']['f.total_vat'] = 0;
1513$totalarray['val']['f.total_localtax1'] = 0;
1514$totalarray['val']['f.total_localtax1'] = 0;
1515$totalarray['val']['f.total_ttc'] = 0;
1516$totalarray['val']['totalam'] = 0;
1517$totalarray['val']['rtp'] = 0;
1518
1519$imaxinloop = ($limit ? min($num, $limit) : $num);
1520while ($i < $imaxinloop) {
1521 $obj = $db->fetch_object($resql);
1522 if (empty($obj)) {
1523 break; // Should not happen
1524 }
1525
1526 $datelimit = $db->jdate($obj->datelimite);
1527
1528 $userstatic->id = $obj->fk_user_author;
1529 $userstatic->login = $obj->login;
1530 $userstatic->lastname = $obj->lastname;
1531 $userstatic->firstname = $obj->firstname;
1532 $userstatic->email = $obj->user_email;
1533 $userstatic->statut = $obj->user_statut;
1534 $userstatic->status = $obj->user_statut;
1535 $userstatic->entity = $obj->entity;
1536 $userstatic->photo = $obj->photo;
1537 $userstatic->office_phone = $obj->office_phone;
1538 $userstatic->office_fax = $obj->office_fax;
1539 $userstatic->user_mobile = $obj->user_mobile;
1540 $userstatic->job = $obj->job;
1541 $userstatic->gender = $obj->gender;
1542 $facturestatic->id = $obj->facid;
1543 $facturestatic->ref = $obj->ref;
1544 $facturestatic->type = $obj->type;
1545 $facturestatic->subtype = $obj->subtype;
1546 $facturestatic->total_ht = $obj->total_ht;
1547 $facturestatic->total_tva = $obj->total_vat;
1548 $facturestatic->total_ttc = $obj->total_ttc;
1549 $facturestatic->close_code = $obj->close_code;
1550 $facturestatic->ref_supplier = $obj->ref_supplier;
1551 $facturestatic->date_echeance = $db->jdate($obj->datelimite);
1552 $facturestatic->statut = $obj->fk_statut;
1553 $facturestatic->status = $obj->fk_statut;
1554 $facturestatic->note_public = $obj->note_public;
1555 $facturestatic->note_private = $obj->note_private;
1556 $facturestatic->multicurrency_code = $obj->multicurrency_code;
1557 $facturestatic->multicurrency_tx = $obj->multicurrency_tx;
1558 $facturestatic->multicurrency_total_ht = $obj->multicurrency_total_ht;
1559 $facturestatic->multicurrency_total_tva = $obj->multicurrency_total_vat;
1560 $facturestatic->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
1561 $thirdparty->id = $obj->socid;
1562 $thirdparty->name = $obj->name;
1563 $thirdparty->name_alias = $obj->alias;
1564 $thirdparty->client = $obj->client;
1565 $thirdparty->fournisseur = $obj->fournisseur;
1566 $thirdparty->code_client = $obj->code_client;
1567 $thirdparty->code_compta_client = $obj->code_compta_client;
1568 $thirdparty->code_fournisseur = $obj->code_fournisseur;
1569 $thirdparty->code_compta_fournisseur = $obj->code_compta_fournisseur;
1570 $thirdparty->email = $obj->email;
1571 $thirdparty->country_code = $obj->country_code;
1572
1573 $paiement = $facturestatic->getSommePaiement();
1574 $totalcreditnotes = $facturestatic->getSumCreditNotesUsed();
1575 $totaldeposits = $facturestatic->getSumDepositsUsed();
1576 $totalpay = $paiement + $totalcreditnotes + $totaldeposits;
1577 $remaintopay = $obj->total_ttc - $totalpay;
1578
1579 $multicurrency_paiement = $facturestatic->getSommePaiement(1);
1580 $multicurrency_totalcreditnotes = $facturestatic->getSumCreditNotesUsed(1);
1581 $multicurrency_totaldeposits = $facturestatic->getSumDepositsUsed(1);
1582
1583 $totalpay = $paiement + $totalcreditnotes + $totaldeposits;
1584 $remaintopay = price2num($facturestatic->total_ttc - $totalpay);
1585
1586 $multicurrency_totalpay = $multicurrency_paiement + $multicurrency_totalcreditnotes + $multicurrency_totaldeposits;
1587 $multicurrency_remaintopay = price2num($facturestatic->multicurrency_total_ttc - $multicurrency_totalpay);
1588
1589 if ($facturestatic->status == FactureFournisseur::STATUS_CLOSED && $facturestatic->close_code == 'discount_vat') { // If invoice closed with discount for anticipated payment
1590 $remaintopay = 0;
1591 $multicurrency_remaintopay = 0;
1592 }
1593 if ($facturestatic->type == FactureFournisseur::TYPE_CREDIT_NOTE && $obj->paye == 1) { // If credit note closed, we take into account the amount not yet consumed
1594 $remaincreditnote = $discount->getAvailableDiscounts($thirdparty, '', 'rc.fk_facture_source='.$facturestatic->id);
1595 $remaintopay = -$remaincreditnote;
1596 $totalpay = price2num($facturestatic->total_ttc - $remaintopay);
1597 $multicurrency_remaincreditnote = $discount->getAvailableDiscounts($thirdparty, '', 'rc.fk_facture_source='.$facturestatic->id, 0, 0, 1);
1598 $multicurrency_remaintopay = -$multicurrency_remaincreditnote;
1599 $multicurrency_totalpay = price2num($facturestatic->multicurrency_total_ttc - $multicurrency_remaintopay);
1600 }
1601
1602 $facturestatic->alreadypaid = ($paiement ? $paiement : 0);
1603
1604 $facturestatic->paye = $obj->paye;
1605 $facturestatic->paid = $obj->paye;
1606
1607 $facturestatic->date = $db->jdate($obj->datef);
1608
1609 $object = $facturestatic;
1610
1611 //If invoice has been converted and the conversion has been used, we don't have remain to pay on invoice
1612 if ($facturestatic->type == FactureFournisseur::TYPE_CREDIT_NOTE) {
1613 if ($facturestatic->isCreditNoteUsed()) {
1614 $remaintopay = -$facturestatic->getSumFromThisCreditNotesNotUsed();
1615 }
1616 }
1617
1618 if ($mode == 'kanban') {
1619 if ($i == 0) {
1620 print '<tr class="trkanban"><td colspan="'.$savnbfield.'">';
1621 print '<div class="box-flex-container kanban">';
1622 }
1623 // Output Kanban
1624 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
1625 $selected = 0;
1626 if (in_array($object->id, $arrayofselected)) {
1627 $selected = 1;
1628 }
1629 }
1630
1631 $arraydata = array('alreadypaid' => $paiement, 'thirdparty' => $thirdparty->getNomUrl(1, '', 12), 'selected' => in_array($object->id, $arrayofselected));
1632 print $facturestatic->getKanbanView('', $arraydata);
1633 if ($i == ($imaxinloop - 1)) {
1634 print '</div>';
1635 print '</td></tr>';
1636 }
1637 } else {
1638 // Show line of result
1639 $j = 0;
1640 print '<tr data-rowid="'.$object->id.'" class="oddeven '.((getDolGlobalInt('MAIN_FINISHED_LINES_OPACITY') == 1 && $obj->fk_statut > 1) ? 'opacitymedium' : '').'">';
1641
1642 // Action column
1643 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1644 print '<td class="nowrap center">';
1645 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
1646 $selected = 0;
1647 if (in_array($obj->facid, $arrayofselected)) {
1648 $selected = 1;
1649 }
1650 print '<input id="cb'.$obj->facid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->facid.'"'.($selected ? ' checked="checked"' : '').'>';
1651 }
1652 print '</td>';
1653 if (!$i) {
1654 $totalarray['nbfield']++;
1655 }
1656 }
1657 if (!empty($arrayfields['f.ref']['checked'])) {
1658 print '<td class="nowraponall">';
1659
1660 print '<table class="nobordernopadding"><tr class="nocellnopadd">';
1661 // Picto + Ref
1662 print '<td class="nobordernopadding nowraponall">';
1663 print $facturestatic->getNomUrl(1, '', 0, 0, '', 0, -1, 1);
1664
1665 $filename = dol_sanitizeFileName($obj->ref);
1666 $filedir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($obj->facid, 2, 0, 0, $facturestatic, 'invoice_supplier').dol_sanitizeFileName($obj->ref);
1667 $subdir = get_exdir($obj->facid, 2, 0, 0, $facturestatic, 'invoice_supplier').dol_sanitizeFileName($obj->ref);
1668 print $formfile->getDocumentsLink('facture_fournisseur', $subdir, $filedir);
1669 print '</td></tr></table>';
1670
1671 print "</td>\n";
1672 if (!$i) {
1673 $totalarray['nbfield']++;
1674 }
1675 }
1676
1677 // Supplier ref
1678 if (!empty($arrayfields['f.ref_supplier']['checked'])) {
1679 print '<td class="nowrap tdoverflowmax150" title="'.dol_escape_htmltag($obj->ref_supplier).'">';
1680 print $obj->ref_supplier;
1681 print '</td>';
1682 if (!$i) {
1683 $totalarray['nbfield']++;
1684 }
1685 }
1686
1687 // Type
1688 if (!empty($arrayfields['f.type']['checked'])) {
1689 print '<td class="nowrap">';
1690 print $facturestatic->getLibType();
1691 print "</td>";
1692 if (!$i) {
1693 $totalarray['nbfield']++;
1694 }
1695 }
1696
1697 // Invoice Subtype
1698 if (!empty($arrayfields['f.subtype']['checked'])) {
1699 $labeltoshow = '';
1700 if ($facturestatic->subtype > 0) {
1701 $labeltoshow = $facturestatic->getSubtypeLabel('facture_fourn');
1702 }
1703 print '<td class="nowraponall tdoverflowmax300" title="'.$labeltoshow.'">';
1704 print $labeltoshow;
1705 print "</td>";
1706 if (!$i) {
1707 $totalarray['nbfield']++;
1708 }
1709 }
1710
1711 // Label
1712 if (!empty($arrayfields['f.label']['checked'])) {
1713 print '<td class="nowrap tdoverflowmax125" title="'.dol_escape_htmltag($obj->label).'">';
1714 print dol_escape_htmltag($obj->label);
1715 print '</td>';
1716 if (!$i) {
1717 $totalarray['nbfield']++;
1718 }
1719 }
1720
1721 // Date
1722 if (!empty($arrayfields['f.datef']['checked'])) {
1723 print '<td class="center nowrap">';
1724 print dol_print_date($db->jdate($obj->datef), 'day');
1725 print '</td>';
1726 if (!$i) {
1727 $totalarray['nbfield']++;
1728 }
1729 }
1730
1731 // Date limit
1732 if (!empty($arrayfields['f.date_lim_reglement']['checked'])) {
1733 print '<td class="center nowraponall">'.dol_print_date($datelimit, 'day');
1734 if ($facturestatic->hasDelay()) {
1735 print img_warning($langs->trans('Alert').' - '.$langs->trans('Late'));
1736 }
1737 print '</td>';
1738 if (!$i) {
1739 $totalarray['nbfield']++;
1740 }
1741 }
1742
1743 // Project
1744 if (!empty($arrayfields['p.ref']['checked'])) {
1745 print '<td class="nowrap">';
1746 if ($obj->project_id > 0) {
1747 $projectstatic->id = $obj->project_id;
1748 $projectstatic->ref = $obj->project_ref;
1749 $projectstatic->title = $obj->project_label;
1750 print $projectstatic->getNomUrl(1);
1751 }
1752 print '</td>';
1753 if (!$i) {
1754 $totalarray['nbfield']++;
1755 }
1756 }
1757
1758 // Third party
1759 if (!empty($arrayfields['s.nom']['checked'])) {
1760 print '<td class="tdoverflowmax125">';
1761 print $thirdparty->getNomUrl(1, 'supplier', 0, 0, -1, empty($arrayfields['s.name_alias']['checked']) ? 0 : 1);
1762 print '</td>';
1763 if (!$i) {
1764 $totalarray['nbfield']++;
1765 }
1766 }
1767 // Alias
1768 if (!empty($arrayfields['s.name_alias']['checked'])) {
1769 print '<td class="tdoverflowmax150">';
1770 print dol_escape_htmltag($thirdparty->name_alias);
1771 print '</td>';
1772 if (!$i) {
1773 $totalarray['nbfield']++;
1774 }
1775 }
1776 // Town
1777 if (!empty($arrayfields['s.town']['checked'])) {
1778 print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->town).'">';
1779 print dol_escape_htmltag($obj->town);
1780 print '</td>';
1781 if (!$i) {
1782 $totalarray['nbfield']++;
1783 }
1784 }
1785 // Zip
1786 if (!empty($arrayfields['s.zip']['checked'])) {
1787 print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->zip).'">';
1788 print dol_escape_htmltag($obj->zip);
1789 print '</td>';
1790 if (!$i) {
1791 $totalarray['nbfield']++;
1792 }
1793 }
1794 // State
1795 if (!empty($arrayfields['state.nom']['checked'])) {
1796 print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->state_name).'">';
1797 print dol_escape_htmltag($obj->state_name);
1798 print "</td>\n";
1799 if (!$i) {
1800 $totalarray['nbfield']++;
1801 }
1802 }
1803 // Country
1804 if (!empty($arrayfields['country.code_iso']['checked'])) {
1805 print '<td class="center">';
1806 $tmparray = getCountry($obj->fk_pays, 'all');
1807 print $tmparray['label'];
1808 print '</td>';
1809 if (!$i) {
1810 $totalarray['nbfield']++;
1811 }
1812 }
1813 // Type ent
1814 if (!empty($arrayfields['typent.code']['checked'])) {
1815 print '<td class="center">';
1816 if (empty($typenArray)) {
1817 $typenArray = $formcompany->typent_array(1);
1818 }
1819 print $typenArray[$obj->typent_code];
1820 print '</td>';
1821 if (!$i) {
1822 $totalarray['nbfield']++;
1823 }
1824 }
1825
1826 // Payment condition
1827 if (!empty($arrayfields['f.fk_cond_reglement']['checked'])) {
1828 $s = $form->form_conditions_reglement($_SERVER['PHP_SELF'], $obj->fk_cond_reglement, 'none', 1, '', -1, -1, 1);
1829 print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($s).'">';
1830 print dol_escape_htmltag($s);
1831 print '</td>';
1832 if (!$i) {
1833 $totalarray['nbfield']++;
1834 }
1835 }
1836 // Payment mode
1837 if (!empty($arrayfields['f.fk_mode_reglement']['checked'])) {
1838 $s = $form->form_modes_reglement($_SERVER['PHP_SELF'], $obj->fk_mode_reglement, 'none', '', -1, 0, '', 1);
1839 print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($s).'">';
1840 print dol_escape_htmltag($s);
1841 print '</td>';
1842 if (!$i) {
1843 $totalarray['nbfield']++;
1844 }
1845 }
1846
1847 // Amount HT
1848 if (!empty($arrayfields['f.total_ht']['checked'])) {
1849 print '<td class="right nowrap"><span class="amount">'.price($obj->total_ht)."</span></td>\n";
1850 if (!$i) {
1851 $totalarray['nbfield']++;
1852 $totalarray['pos'][$totalarray['nbfield']] = 'f.total_ht';
1853 }
1854 $totalarray['val']['f.total_ht'] += $obj->total_ht;
1855 }
1856 // Amount VAT
1857 if (!empty($arrayfields['f.total_vat']['checked'])) {
1858 print '<td class="right nowrap"><span class="amount">'.price($obj->total_vat)."</span></td>\n";
1859 if (!$i) {
1860 $totalarray['nbfield']++;
1861 $totalarray['pos'][$totalarray['nbfield']] = 'f.total_vat';
1862 }
1863 $totalarray['val']['f.total_vat'] += $obj->total_vat;
1864 }
1865 // Amount LocalTax1
1866 if (!empty($arrayfields['f.total_localtax1']['checked'])) {
1867 print '<td class="right nowrap"><span class="amount">'.price($obj->total_localtax1)."</span></td>\n";
1868 if (!$i) {
1869 $totalarray['nbfield']++;
1870 $totalarray['pos'][$totalarray['nbfield']] = 'f.total_localtax1';
1871 }
1872 $totalarray['val']['f.total_localtax1'] += $obj->total_localtax1;
1873 }
1874 // Amount LocalTax2
1875 if (!empty($arrayfields['f.total_localtax2']['checked'])) {
1876 print '<td class="right nowrap"><span class="amount">'.price($obj->total_localtax2)."</span></td>\n";
1877 if (!$i) {
1878 $totalarray['nbfield']++;
1879 $totalarray['pos'][$totalarray['nbfield']] = 'f.total_localtax2';
1880 }
1881 $totalarray['val']['f.total_localtax2'] += $obj->total_localtax2;
1882 }
1883 // Amount TTC
1884 if (!empty($arrayfields['f.total_ttc']['checked'])) {
1885 print '<td class="right nowrap"><span class="amount">'.price($obj->total_ttc)."</span></td>\n";
1886 if (!$i) {
1887 $totalarray['nbfield']++;
1888 $totalarray['pos'][$totalarray['nbfield']] = 'f.total_ttc';
1889 }
1890 $totalarray['val']['f.total_ttc'] += $obj->total_ttc;
1891 }
1892
1893 // Number of attached documents (may slow your application on large lists)
1894 if (!empty($arrayfields['f.nb_docs']['checked'])) {
1895 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
1896 require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
1897 $upload_dir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($facturestatic->id, 2, 0, 0, $facturestatic, 'invoice_supplier').$facturestatic->ref;
1898 $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
1899 $nbLinks = Link::count($db, $facturestatic->element, $facturestatic->id);
1900 $nbTotal = $nbFiles + $nbLinks;
1901 echo '<td class="center">'.(empty($nbTotal) ? '' : $nbTotal).'</td>';
1902 if (!$i) {
1903 $totalarray['nbfield']++;
1904 }
1905 }
1906
1907 // Author
1908 if (!empty($arrayfields['u.login']['checked'])) {
1909 print '<td class="tdoverflowmax100">';
1910 if ($userstatic->id) {
1911 print $userstatic->getNomUrl(-1);
1912 } else {
1913 print '&nbsp;';
1914 }
1915 print "</td>\n";
1916 if (!$i) {
1917 $totalarray['nbfield']++;
1918 }
1919 }
1920
1921 // Dynamic amount paid
1922 if (!empty($arrayfields['dynamount_payed']['checked'])) {
1923 print '<td class="right nowrap"><span class="amount">'.(!empty($totalpay) ? price($totalpay, 0, $langs) : '').'</span></td>'; // TODO Use a denormalized field
1924 if (!$i) {
1925 $totalarray['nbfield']++;
1926 $totalarray['pos'][$totalarray['nbfield']] = 'totalam';
1927 }
1928 if (empty($totalarray['val']['totalam'])) {
1929 $totalarray['val']['totalam'] = 0; // avoid PHP Warning: Undefined array key "totalam" on line 1891
1930 }
1931 $totalarray['val']['totalam'] += $totalpay;
1932 }
1933
1934 // Remain to pay
1935 if (!empty($arrayfields['rtp']['checked'])) {
1936 print '<td class="right nowrap">'.(!empty($remaintopay) ? price($remaintopay, 0, $langs) : '&nbsp;').'</td>'; // TODO Use a denormalized field
1937 if (!$i) {
1938 $totalarray['nbfield']++;
1939 $totalarray['pos'][$totalarray['nbfield']] = 'rtp';
1940 }
1941 $totalarray['val']['rtp'] += $remaintopay;
1942 }
1943
1944 // Currency
1945 if (!empty($arrayfields['f.multicurrency_code']['checked'])) {
1946 print '<td class="nowrap">'.$obj->multicurrency_code.' - '.$langs->trans('Currency'.$obj->multicurrency_code)."</td>\n";
1947 if (!$i) {
1948 $totalarray['nbfield']++;
1949 }
1950 }
1951
1952 // Currency rate
1953 if (!empty($arrayfields['f.multicurrency_tx']['checked'])) {
1954 print '<td class="nowrap">';
1955 $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$obj->rowid, $obj->multicurrency_tx, 'none', $obj->multicurrency_code);
1956 print "</td>\n";
1957 if (!$i) {
1958 $totalarray['nbfield']++;
1959 }
1960 }
1961 // Amount HT
1962 if (!empty($arrayfields['f.multicurrency_total_ht']['checked'])) {
1963 print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_ht)."</span></td>\n";
1964 if (!$i) {
1965 $totalarray['nbfield']++;
1966 }
1967 }
1968 // Amount VAT
1969 if (!empty($arrayfields['f.multicurrency_total_vat']['checked'])) {
1970 print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_vat)."</span></td>\n";
1971 if (!$i) {
1972 $totalarray['nbfield']++;
1973 }
1974 }
1975 // Amount TTC
1976 if (!empty($arrayfields['f.multicurrency_total_ttc']['checked'])) {
1977 print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_ttc)."</span></td>\n";
1978 if (!$i) {
1979 $totalarray['nbfield']++;
1980 }
1981 }
1982 // Dynamic amount paid
1983 if (!empty($arrayfields['multicurrency_dynamount_payed']['checked'])) {
1984 print '<td class="right nowrap"><span class="amount">'.(!empty($multicurrency_totalpay) ? price($multicurrency_totalpay, 0, $langs) : '').'</span></td>'; // TODO Use a denormalized field
1985 if (!$i) {
1986 $totalarray['nbfield']++;
1987 }
1988 }
1989
1990 // Pending amount
1991 if (!empty($arrayfields['multicurrency_rtp']['checked'])) {
1992 print '<td class="right nowrap"><span class="amount">';
1993 print(!empty($multicurrency_remaintopay) ? price($multicurrency_remaintopay, 0, $langs) : '');
1994 print '</span></td>'; // TODO Use a denormalized field
1995 if (!$i) {
1996 $totalarray['nbfield']++;
1997 }
1998 }
1999
2000
2001 // Extra fields
2002 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
2003 // Fields from hook
2004 $parameters = array('arrayfields' => $arrayfields, 'object' => $object, 'obj' => $obj, 'i' => $i, 'totalarray' => &$totalarray);
2005 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
2006 print $hookmanager->resPrint;
2007
2008 // Date creation
2009 if (!empty($arrayfields['f.datec']['checked'])) {
2010 print '<td class="center nowraponall">';
2011 print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
2012 print '</td>';
2013 if (!$i) {
2014 $totalarray['nbfield']++;
2015 }
2016 }
2017 // Date modification
2018 if (!empty($arrayfields['f.tms']['checked'])) {
2019 print '<td class="center nowraponall">';
2020 print dol_print_date($db->jdate($obj->date_modification), 'dayhour', 'tzuser');
2021 print '</td>';
2022 if (!$i) {
2023 $totalarray['nbfield']++;
2024 }
2025 }
2026 // Status
2027 if (!empty($arrayfields['f.fk_statut']['checked'])) {
2028 print '<td class="center nowrap">';
2029 print $facturestatic->getLibStatut(5, $paiement);
2030 print "</td>";
2031 if (!$i) {
2032 $totalarray['nbfield']++;
2033 }
2034 }
2035
2036 // Action column
2037 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
2038 print '<td class="nowrap center">';
2039 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
2040 $selected = 0;
2041 if (in_array($obj->facid, $arrayofselected)) {
2042 $selected = 1;
2043 }
2044 print '<input id="cb'.$obj->facid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->facid.'"'.($selected ? ' checked="checked"' : '').'>';
2045 }
2046 print '</td>';
2047 if (!$i) {
2048 $totalarray['nbfield']++;
2049 }
2050 }
2051
2052 print '</tr>'."\n";
2053 }
2054
2055 $i++;
2056}
2057
2058// Show total line
2059include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
2060
2061// If no record found
2062if ($num == 0) {
2063 $colspan = 1;
2064 foreach ($arrayfields as $key => $val) {
2065 if (!empty($val['checked'])) {
2066 $colspan++;
2067 }
2068 }
2069 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
2070}
2071
2072$db->free($resql);
2073
2074$parameters = array('arrayfields' => $arrayfields, 'sql' => $sql);
2075$reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
2076print $hookmanager->resPrint;
2077
2078print '</table>'."\n";
2079print '</div>'."\n";
2080
2081print '</form>'."\n";
2082
2083if (in_array('builddoc', array_keys($arrayofmassactions)) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
2084 $hidegeneratedfilelistifempty = 1;
2085 if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
2086 $hidegeneratedfilelistifempty = 0;
2087 }
2088
2089 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
2090 $formfile = new FormFile($db);
2091
2092 // Show list of available documents
2093 $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
2094 $urlsource .= str_replace('&amp;', '&', $param);
2095
2096 $filedir = $diroutputmassaction;
2097 $genallowed = $permissiontoread;
2098 $delallowed = $permissiontoadd;
2099 $title = '';
2100
2101 print $formfile->showdocuments('massfilesarea_supplier_invoice', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
2102}
2103
2104// End of page
2105llxFooter();
2106$db->close();
$id
Definition account.php:39
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:70
Class to manage bank accounts.
Class to manage absolute discounts.
Class to manage standard extra fields.
Class to manage suppliers invoices.
const TYPE_DEPOSIT
Deposit invoice.
const TYPE_CREDIT_NOTE
Credit note invoice.
const TYPE_REPLACEMENT
Replacement invoice.
const TYPE_STANDARD
Standard invoice.
const STATUS_CLOSED
Classified paid.
Class to build HTML component for third parties management Only common components are here.
Class to offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
Class permettant la generation de composants html autre Only common components are here.
Class to manage suppliers.
Class to manage projects.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
getCountry($searchkey, $withcode='', $dbtouse=null, $outputlangs=null, $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
getCountriesInEEC()
Return list of countries that are inside the EEC (European Economic Community) Note: Try to keep this...
llxFooter()
Footer empty.
Definition document.php:107
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition files.lib.php:63
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
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.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
buildParamDate($prefix, $timestamp=null, $hourTime='', $gm='auto')
Helper function that combines values of a dolibarr DatePicker (such as Form\selectDate) for year,...
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.