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