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