dolibarr 24.0.3
list.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2002-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2019 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2013 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2013-2019 Philippe Grand <philippe.grand@atoo-net.com>
6 * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
7 * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
8 * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
9 * Copyright (C) 2015-2007 Juanjo Menent <jmenent@2byte.es>
10 * Copyright (C) 2015 Abbes Bahfir <bafbes@gmail.com>
11 * Copyright (C) 2015-2016 Ferran Marcet <fmarcet@2byte.es>
12 * Copyright (C) 2017 Josep Lluís Amador <joseplluis@lliuretic.cat>
13 * Copyright (C) 2018-2022 Charlene Benke <charlene@patas-monkey.com>
14 * Copyright (C) 2018-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 = array('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 (is_array($search_status)) {
1091 foreach ($search_status as $key => $val) {
1092 $param .= '&search_status[]='.urlencode($val);
1093 }
1094}
1095if ($search_paymentmode) {
1096 $param .= '&search_paymentmode='.urlencode((string) ($search_paymentmode));
1097}
1098if ($search_paymentcond) {
1099 $param .= '&search_paymentcond='.urlencode((string) ($search_paymentcond));
1100}
1101if ($search_bankaccount > 0) {
1102 $param .= '&search_bankaccount='.urlencode((string) ($search_bankaccount));
1103}
1104if ($search_vat_reverse_charge !== '' && $search_vat_reverse_charge !== '-1') {
1105 $param .= '&search_vat_reverse_charge='.urlencode($search_vat_reverse_charge);
1106}
1107if ($show_files) {
1108 $param .= '&show_files='.urlencode((string) ($show_files));
1109}
1110if ($option) {
1111 $param .= "&search_option=".urlencode($option);
1112}
1113if ($search_categ_sup > 0) {
1114 $param .= '&search_categ_sup='.$search_categ_sup;
1115}
1116if ($search_type_thirdparty != '' && $search_type_thirdparty > 0) {
1117 $param .= '&search_type_thirdparty='.$search_type_thirdparty;
1118}
1119if ($search_fk_fac_rec_source) {
1120 $param .= '&search_fk_fac_rec_source=' . (int) $search_fk_fac_rec_source;
1121}
1122
1123// Add $param from extra fields
1124include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
1125// Add $param from hooks
1126$parameters = array('param' => &$param);
1127$reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1128$param .= $hookmanager->resPrint;
1129
1130// List of mass actions available
1131$arrayofmassactions = array(
1132 'validate' => img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate"),
1133 'generate_doc' => img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
1134 'builddoc' => img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
1135 //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
1136);
1137if (isModEnabled('category') && $user->hasRight("fournisseur", "facture", "lire")) {
1138 $arrayofmassactions['preaffecttag'] = img_picto('', 'category', 'class="pictofixedwidth"').$langs->trans("AffectTag");
1139}
1140if (isModEnabled('paymentbybanktransfer') && $user->hasRight("paymentbybanktransfer", "create")) {
1141 $langs->load('withdrawals');
1142 $arrayofmassactions['banktransfertrequest'] = img_picto('', 'payment', 'class="pictofixedwidth"').$langs->trans("MakeBankTransferOrder");
1143}
1144if (!empty($permissiontodelete)) {
1145 $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
1146}
1147if (GETPOSTINT('nomassaction') || in_array($massaction, array('presend', 'predelete'))) {
1148 $arrayofmassactions = array();
1149}
1150$massactionbutton = $form->selectMassAction('', $arrayofmassactions);
1151
1152$url = DOL_URL_ROOT.'/fourn/facture/card.php?action=create';
1153if (!empty($object->socid)) {
1154 $url .= '&socid='.urlencode((string) ($object->socid));
1155}
1156if (!empty($object->id)) {
1157 $url .= '&fac_rec='.urlencode((string) $object->id);
1158}
1159$i = 0;
1160print '<form method="POST" id="searchFormList" name="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
1161if ($optioncss != '') {
1162 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
1163}
1164print '<input type="hidden" name="token" value="'.newToken().'">';
1165print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
1166print '<input type="hidden" name="action" value="list">';
1167print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
1168print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
1169print '<input type="hidden" name="socid" value="'.$socid.'">';
1170print '<input type="hidden" name="page" value="'.$page.'">';
1171print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
1172print '<input type="hidden" name="page_y" value="">';
1173print '<input type="hidden" name="mode" value="'.$mode.'">';
1174
1175$newcardbutton = '';
1176$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'));
1177$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'));
1178$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'));
1179$newcardbutton .= dolGetButtonTitleSeparator();
1180$newcardbutton .= dolGetButtonTitle($langs->trans('NewBill'), '', 'fa fa-plus-circle', $url, '', (int) ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer")));
1181
1182print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'supplier_invoice', 0, $newcardbutton, '', $limit, 0, 0, 1);
1183
1184// Add code for pre mass action (confirmation or email presend form)
1185$topicmail = "SendBillRef";
1186$modelmail = "invoice_supplier_send";
1187$objecttmp = new FactureFournisseur($db);
1188$trackid = 'sinv'.$object->id;
1189include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
1190
1191if ($search_all) {
1192 $setupstring = '';
1193 foreach ($fieldstosearchall as $key => $val) {
1194 $fieldstosearchall[$key] = $langs->trans($val);
1195 $setupstring .= $key."=".$val.";";
1196 }
1197 print '<!-- Search done like if SUPPLIER_INVOICE_QUICKSEARCH_ON_FIELDS = '.$setupstring.' -->'."\n";
1198 print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).implode(', ', $fieldstosearchall).'</div>'."\n";
1199}
1200
1201// If the user can view prospects other than his'
1202$moreforfilter = '';
1203if (isModEnabled('category') && $user->hasRight('categorie', 'read')) {
1204 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcategory.class.php';
1205 $formcategory = new FormCategory($db);
1206 $moreforfilter .= $formcategory->getFilterBox(Categorie::TYPE_SUPPLIER_INVOICE, $searchCategorySupplierInvoiceList, 'minwidth300', $searchCategorySupplierInvoiceOperator ? $searchCategorySupplierInvoiceOperator : 0);
1207}
1208if ($user->hasRight("user", "user", "lire")) {
1209 $langs->load("commercial");
1210 $moreforfilter .= '<div class="divsearchfield">';
1211 $tmptitle = $langs->trans('ThirdPartiesOfSaleRepresentative');
1212 $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, $tmptitle, 'maxwidth200');
1213 $moreforfilter .= '</div>';
1214}
1215// If the user can view prospects other than his'
1216if ($user->hasRight("user", "user", "lire")) {
1217 $moreforfilter .= '<div class="divsearchfield">';
1218 $tmptitle = $langs->trans('LinkedToSpecificUsers');
1219 $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$form->select_dolusers($search_user, 'search_user', $tmptitle, null, 0, '', '', '', 0, 0, '', 0, '', 'maxwidth200');
1220 $moreforfilter .= '</div>';
1221}
1222// If the user can view prospects other than his'
1223if (isModEnabled('category') && $user->hasRight('categorie', 'lire') && ($user->hasRight('produit', 'lire') || $user->hasRight('service', 'lire'))) {
1224 include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
1225 $moreforfilter .= '<div class="divsearchfield">';
1226 $tmptitle = $langs->trans('IncludingProductWithTag');
1227 $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, '', 'parent', 0, 0, 1);
1228 $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);
1229 $moreforfilter .= '</div>';
1230}
1231
1232if (isModEnabled('category')) {
1233 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
1234 $moreforfilter .= '<div class="divsearchfield">';
1235 $tmptitle = $langs->trans('SuppliersCategoriesShort');
1236 $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"').$formother->select_categories('supplier', $search_categ_sup, 'search_categ_sup', 1, $tmptitle);
1237 $moreforfilter .= '</div>';
1238}
1239$parameters = array();
1240$reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1241if (empty($reshook)) {
1242 $moreforfilter .= $hookmanager->resPrint;
1243} else {
1244 $moreforfilter = $hookmanager->resPrint;
1245}
1246
1247if (!empty($moreforfilter)) {
1248 print '<div class="liste_titre liste_titre_bydiv centpercent">';
1249 print $moreforfilter;
1250 print '</div>';
1251}
1252
1253$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
1254$htmlofselectarray = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, $conf->main_checkbox_left_column); // This also change content of $arrayfields with user setup
1255$selectedfields = ($mode != 'kanban' ? $htmlofselectarray : '');
1256$selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
1257
1258print '<div class="div-table-responsive">';
1259print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
1260
1261// Fields title search
1262// --------------------------------------------------------------------
1263print '<tr class="liste_titre_filter">';
1264// Action column
1265if ($conf->main_checkbox_left_column) {
1266 print '<td class="liste_titre center maxwidthsearch">';
1267 $searchpicto = $form->showFilterButtons('left');
1268 print $searchpicto;
1269 print '</td>';
1270}
1271// Ref
1272if (!empty($arrayfields['f.ref']['checked'])) {
1273 print '<td class="liste_titre left">';
1274 print '<input class="flat maxwidth50" type="text" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">';
1275 print '</td>';
1276}
1277// Ref supplier
1278if (!empty($arrayfields['f.ref_supplier']['checked'])) {
1279 print '<td class="liste_titre">';
1280 print '<input class="flat maxwidth75" type="text" name="search_refsupplier" value="'.dol_escape_htmltag($search_refsupplier).'">';
1281 print '</td>';
1282}
1283// Type
1284if (!empty($arrayfields['f.type']['checked'])) {
1285 print '<td class="liste_titre maxwidthonsmartphone">';
1286 $typearray = array(
1287 FactureFournisseur::TYPE_STANDARD => $langs->trans("InvoiceStandard"),
1288 FactureFournisseur::TYPE_REPLACEMENT => $langs->trans("InvoiceReplacement"),
1289 FactureFournisseur::TYPE_CREDIT_NOTE => $langs->trans("InvoiceAvoir"),
1290 FactureFournisseur::TYPE_DEPOSIT => $langs->trans("InvoiceDeposit"),
1291 );
1292 print $form->selectarray('search_type', $typearray, $search_type, 1, 0, 0, '', 0, 0, 0, 'ASC', 'maxwidth100');
1293 print '</td>';
1294}
1295// Invoice Subtype
1296if (!empty($arrayfields['f.subtype']['checked'])) {
1297 print '<td class="liste_titre maxwidthonsmartphone" align="center">';
1298 print $form->selectarray('search_subtype', $subtypearray, $search_subtype, 1, 0, 0, '', 0, 0, 0, '', 'maxwidth100');
1299 print '</td>';
1300}
1301// Label
1302if (!empty($arrayfields['f.label']['checked'])) {
1303 print '<td class="liste_titre">';
1304 print '<input class="flat maxwidth75" type="text" name="search_label" value="'.dol_escape_htmltag($search_label).'">';
1305 print '</td>';
1306}
1307// Date invoice
1308if (!empty($arrayfields['f.datef']['checked'])) {
1309 print '<td class="liste_titre center">';
1310 print '<div class="nowrapfordate">';
1311 print $form->selectDate($search_date_start ? $search_date_start : -1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
1312 print '</div>';
1313 print '<div class="nowrapfordate">';
1314 print $form->selectDate($search_date_end ? $search_date_end : -1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
1315 print '</div>';
1316 print '</td>';
1317}
1318// Date due
1319if (!empty($arrayfields['f.date_lim_reglement']['checked'])) {
1320 print '<td class="liste_titre center">';
1321 print '<div class="">';
1322 /*
1323 print $langs->trans('From').' ';
1324 print $form->selectDate($search_datelimit_start ? $search_datelimit_start : -1, 'search_datelimit_start', 0, 0, 1);
1325 print '</div>';
1326 print '<div class="nowrap">';
1327 print $langs->trans('to').' ';*/
1328 print $form->selectDate($search_datelimit_end ? $search_datelimit_end : -1, 'search_datelimit_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("Before"));
1329 //print '<br>';
1330 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>';
1331 print '</div>';
1332 print '</td>';
1333}
1334// Project
1335if (!empty($arrayfields['p.ref']['checked'])) {
1336 print '<td class="liste_titre"><input class="flat maxwidth50" type="text" name="search_project" value="'.dol_escape_htmltag($search_project).'"></td>';
1337}
1338// Thirpdarty
1339if (!empty($arrayfields['s.nom']['checked'])) {
1340 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>';
1341}
1342// Alias
1343if (!empty($arrayfields['s.name_alias']['checked'])) {
1344 print '<td class="liste_titre"><input class="flat maxwidth50" type="text" name="search_company_alias" value="'.dol_escape_htmltag($search_company_alias).'"></td>';
1345}
1346// Town
1347if (!empty($arrayfields['s.town']['checked'])) {
1348 print '<td class="liste_titre"><input class="flat maxwidth50" type="text" name="search_town" value="'.dol_escape_htmltag($search_town).'"></td>';
1349}
1350// Zip
1351if (!empty($arrayfields['s.zip']['checked'])) {
1352 print '<td class="liste_titre"><input class="flat maxwidth50" type="text" name="search_zip" value="'.dol_escape_htmltag($search_zip).'"></td>';
1353}
1354// State
1355if (!empty($arrayfields['state.nom']['checked'])) {
1356 print '<td class="liste_titre">';
1357 print '<input class="flat maxwidth50imp" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
1358 print '</td>';
1359}
1360// Country
1361if (!empty($arrayfields['country.code_iso']['checked'])) {
1362 print '<td class="liste_titre center">';
1363 print $form->select_country($search_country, 'search_country', '', 0, 'minwidth150imp maxwidth150', 'code2', 1, 0, 1, array(), 1);
1364 print '</td>';
1365}
1366// Company type
1367if (!empty($arrayfields['typent.code']['checked'])) {
1368 print '<td class="liste_titre maxwidthonsmartphone center">';
1369 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);
1370 print '</td>';
1371}
1372// VAT Reverse Charge
1373if (!empty($arrayfields['f.vat_reverse_charge']['checked'])) {
1374 print '<td class="liste_titre center">';
1375 print $form->selectyesno('search_vat_reverse_charge', $search_vat_reverse_charge, 1, 0, 1, 1);
1376 print '</td>';
1377}
1378// Condition of payment
1379if (!empty($arrayfields['f.fk_cond_reglement']['checked'])) {
1380 print '<td class="liste_titre left">';
1381 print $form->getSelectConditionsPaiements($search_paymentcond, 'search_paymentcond', -1, 1, 1, 'maxwidth100');
1382 print '</td>';
1383}
1384// Bank account
1385if (!empty($arrayfields['ba.label']['checked'])) {
1386 print '<td class="liste_titre">';
1387 $form->select_comptes($search_bankaccount, 'search_bankaccount', 0, '', 1, '', 0, 'maxwidth125');
1388 print '</td>';
1389}
1390// Payment mode
1391if (!empty($arrayfields['f.fk_mode_reglement']['checked'])) {
1392 print '<td class="liste_titre">';
1393 print $form->select_types_paiements($search_paymentmode, 'search_paymentmode', '', 0, 1, 1, 20, 1, 'maxwidth100', 1);
1394 print '</td>';
1395}
1396if (!empty($arrayfields['f.total_ht']['checked'])) {
1397 // Amount without tax
1398 print '<td class="liste_titre right">';
1399 print '<input class="flat" type="text" size="5" name="search_montant_ht" value="'.dol_escape_htmltag($search_montant_ht).'">';
1400 print '</td>';
1401}
1402if (!empty($arrayfields['f.total_vat']['checked'])) {
1403 // Amount vat
1404 print '<td class="liste_titre right">';
1405 print '<input class="flat" type="text" size="5" name="search_montant_vat" value="'.dol_escape_htmltag($search_montant_vat).'">';
1406 print '</td>';
1407}
1408if (!empty($arrayfields['f.total_localtax1']['checked'])) {
1409 // Amount tax 1
1410 print '<td class="liste_titre right">';
1411 print '<input class="flat" type="text" size="5" name="search_montant_localtax1" value="'.dol_escape_htmltag($search_montant_localtax1).'">';
1412 print '</td>';
1413}
1414if (!empty($arrayfields['f.total_localtax2']['checked'])) {
1415 // Amount tax 2
1416 print '<td class="liste_titre right">';
1417 print '<input class="flat" type="text" size="5" name="search_montant_localtax2" value="'.dol_escape_htmltag($search_montant_localtax2).'">';
1418 print '</td>';
1419}
1420if (!empty($arrayfields['f.total_ttc']['checked'])) {
1421 // Amount inc tax
1422 print '<td class="liste_titre right">';
1423 print '<input class="flat" type="text" size="5" name="search_montant_ttc" value="'.dol_escape_htmltag($search_montant_ttc).'">';
1424 print '</td>';
1425}
1426if (!empty($arrayfields['f.nb_docs']['checked'])) {
1427 // Nb of attached documents
1428 print '<td class="liste_titre" align="center">';
1429 print '</td>';
1430}
1431if (!empty($arrayfields['u.login']['checked'])) {
1432 // Author
1433 print '<td class="liste_titre" align="center">';
1434 print '<input class="flat" size="4" type="text" name="search_login" value="'.dol_escape_htmltag($search_login).'">';
1435 print '</td>';
1436}
1437if (!empty($arrayfields['dynamount_payed']['checked'])) {
1438 print '<td class="liste_titre right">';
1439 print '</td>';
1440}
1441if (!empty($arrayfields['rtp']['checked'])) {
1442 print '<td class="liste_titre">';
1443 print '</td>';
1444}
1445if (!empty($arrayfields['f.multicurrency_code']['checked'])) {
1446 // Currency
1447 print '<td class="liste_titre">';
1448 print $form->selectMultiCurrency($search_multicurrency_code, 'search_multicurrency_code', 1);
1449 print '</td>';
1450}
1451if (!empty($arrayfields['f.multicurrency_tx']['checked'])) {
1452 // Currency rate
1453 print '<td class="liste_titre">';
1454 print '<input class="flat" type="text" size="4" name="search_multicurrency_tx" value="'.dol_escape_htmltag($search_multicurrency_tx).'">';
1455 print '</td>';
1456}
1457if (!empty($arrayfields['f.multicurrency_total_ht']['checked'])) {
1458 // Amount
1459 print '<td class="liste_titre right">';
1460 print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_ht" value="'.dol_escape_htmltag($search_multicurrency_montant_ht).'">';
1461 print '</td>';
1462}
1463if (!empty($arrayfields['f.multicurrency_total_vat']['checked'])) {
1464 // Amount
1465 print '<td class="liste_titre right">';
1466 print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_vat" value="'.dol_escape_htmltag($search_multicurrency_montant_vat).'">';
1467 print '</td>';
1468}
1469if (!empty($arrayfields['f.multicurrency_total_ttc']['checked'])) {
1470 // Amount
1471 print '<td class="liste_titre right">';
1472 print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_ttc" value="'.dol_escape_htmltag($search_multicurrency_montant_ttc).'">';
1473 print '</td>';
1474}
1475if (!empty($arrayfields['multicurrency_dynamount_payed']['checked'])) {
1476 print '<td class="liste_titre">';
1477 print '</td>';
1478}
1479if (!empty($arrayfields['multicurrency_rtp']['checked'])) {
1480 print '<td class="liste_titre right">';
1481 print '</td>';
1482}
1483// Extra fields
1484include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
1485
1486// Fields from hook
1487$parameters = array('arrayfields' => $arrayfields);
1488$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1489print $hookmanager->resPrint;
1490// Date creation
1491if (!empty($arrayfields['f.datec']['checked'])) {
1492 print '<td class="liste_titre">';
1493 print '</td>';
1494}
1495// Date modification
1496if (!empty($arrayfields['f.tms']['checked'])) {
1497 print '<td class="liste_titre">';
1498 print '</td>';
1499}
1500if (!empty($arrayfields['f.note_public']['checked'])) {
1501 // Note public
1502 print '<td class="liste_titre">';
1503 print '<input class="flat maxwidth75" type="text" name="search_note_public" value="'.dol_escape_htmltag($search_note_public).'">';
1504 print '</td>';
1505}
1506if (!empty($arrayfields['f.note_private']['checked'])) {
1507 // Note private
1508 print '<td class="liste_titre">';
1509 print '<input class="flat maxwidth75" type="text" name="search_note_private" value="'.dol_escape_htmltag($search_note_private).'">';
1510 print '</td>';
1511}
1512// Status
1513if (!empty($arrayfields['f.fk_statut']['checked'])) {
1514 print '<td class="liste_titre center parentonrightofpage">';
1515 $liststatus = array('0' => $langs->trans("Draft"), '1' => $langs->trans("Unpaid"), '2' => $langs->trans("Paid"));
1516 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
1517 print $form->multiselectarray('search_status', $liststatus, (is_array($search_status) ? $search_status : array()), 0, 0, 'center search_status width125 onrightofpage', 1, 0);
1518 print '</td>';
1519}
1520// Action column
1521if (!$conf->main_checkbox_left_column) {
1522 print '<td class="liste_titre center maxwidthsearch actioncolumn">';
1523 $searchpicto = $form->showFilterButtons();
1524 print $searchpicto;
1525 print '</td>';
1526}
1527
1528print "</tr>\n";
1529
1530$totalarray = array();
1531$totalarray['nbfield'] = 0;
1532
1533// Fields title label
1534// --------------------------------------------------------------------
1535print '<tr class="liste_titre">';
1536// Action column
1537if ($conf->main_checkbox_left_column) {
1538 print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
1539 $totalarray['nbfield']++;
1540}
1541if (!empty($arrayfields['f.ref']['checked'])) {
1542 print_liste_field_titre($arrayfields['f.ref']['label'], $_SERVER['PHP_SELF'], 'f.ref,f.rowid', '', $param, '', $sortfield, $sortorder);
1543 $totalarray['nbfield']++;
1544}
1545if (!empty($arrayfields['f.ref_supplier']['checked'])) {
1546 print_liste_field_titre($arrayfields['f.ref_supplier']['label'], $_SERVER["PHP_SELF"], 'f.ref_supplier', '', $param, '', $sortfield, $sortorder);
1547 $totalarray['nbfield']++;
1548}
1549if (!empty($arrayfields['f.type']['checked'])) {
1550 print_liste_field_titre($arrayfields['f.type']['label'], $_SERVER["PHP_SELF"], 'f.type', '', $param, '', $sortfield, $sortorder);
1551 $totalarray['nbfield']++;
1552}
1553if (!empty($arrayfields['f.subtype']['checked'])) {
1554 print_liste_field_titre($arrayfields['f.subtype']['label'], $_SERVER["PHP_SELF"], 'f.subtype', '', $param, '', $sortfield, $sortorder);
1555}
1556if (!empty($arrayfields['f.label']['checked'])) {
1557 print_liste_field_titre($arrayfields['f.label']['label'], $_SERVER['PHP_SELF'], "f.libelle,f.rowid", '', $param, '', $sortfield, $sortorder);
1558 $totalarray['nbfield']++;
1559}
1560if (!empty($arrayfields['f.datef']['checked'])) {
1561 print_liste_field_titre($arrayfields['f.datef']['label'], $_SERVER['PHP_SELF'], 'f.datef,f.rowid', '', $param, '', $sortfield, $sortorder, 'center ');
1562 $totalarray['nbfield']++;
1563}
1564if (!empty($arrayfields['f.date_lim_reglement']['checked'])) {
1565 print_liste_field_titre($arrayfields['f.date_lim_reglement']['label'], $_SERVER['PHP_SELF'], "f.date_lim_reglement", '', $param, '', $sortfield, $sortorder, 'center ');
1566 $totalarray['nbfield']++;
1567}
1568if (!empty($arrayfields['p.ref']['checked'])) {
1569 print_liste_field_titre($arrayfields['p.ref']['label'], $_SERVER['PHP_SELF'], "p.ref", '', $param, '', $sortfield, $sortorder);
1570 $totalarray['nbfield']++;
1571}
1572if (!empty($arrayfields['s.nom']['checked'])) {
1573 print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER['PHP_SELF'], 's.nom', '', $param, '', $sortfield, $sortorder);
1574 $totalarray['nbfield']++;
1575}
1576if (!empty($arrayfields['s.name_alias']['checked'])) {
1577 // @phan-suppress-next-line PhanTypeInvalidDimOffset
1578 print_liste_field_titre($arrayfields['s.name_alias']['label'], $_SERVER['PHP_SELF'], 's.name_alias', '', $param, '', $sortfield, $sortorder);
1579 $totalarray['nbfield']++;
1580}
1581if (!empty($arrayfields['s.town']['checked'])) {
1582 print_liste_field_titre($arrayfields['s.town']['label'], $_SERVER["PHP_SELF"], 's.town', '', $param, '', $sortfield, $sortorder);
1583 $totalarray['nbfield']++;
1584}
1585if (!empty($arrayfields['s.zip']['checked'])) {
1586 print_liste_field_titre($arrayfields['s.zip']['label'], $_SERVER["PHP_SELF"], 's.zip', '', $param, '', $sortfield, $sortorder);
1587 $totalarray['nbfield']++;
1588}
1589if (!empty($arrayfields['state.nom']['checked'])) {
1590 print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.name_alias", "", $param, '', $sortfield, $sortorder);
1591 $totalarray['nbfield']++;
1592}
1593if (!empty($arrayfields['state.name_alias']['checked'])) {
1594 print_liste_field_titre($arrayfields['state.name_alias']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder);
1595 $totalarray['nbfield']++;
1596}
1597if (!empty($arrayfields['country.code_iso']['checked'])) {
1598 print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, '', $sortfield, $sortorder, 'center ');
1599 $totalarray['nbfield']++;
1600}
1601if (!empty($arrayfields['typent.code']['checked'])) {
1602 print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, '', $sortfield, $sortorder, 'center ');
1603 $totalarray['nbfield']++;
1604}
1605if (!empty($arrayfields['f.vat_reverse_charge']['checked'])) {
1606 print_liste_field_titre($arrayfields['f.vat_reverse_charge']['label'], $_SERVER["PHP_SELF"], "f.vat_reverse_charge", "", $param, "", $sortfield, $sortorder, 'center ');
1607 $totalarray['nbfield']++;
1608}
1609if (!empty($arrayfields['f.fk_cond_reglement']['checked'])) {
1610 print_liste_field_titre($arrayfields['f.fk_cond_reglement']['label'], $_SERVER["PHP_SELF"], "f.fk_cond_reglement", "", $param, "", $sortfield, $sortorder);
1611 $totalarray['nbfield']++;
1612}
1613if (!empty($arrayfields['ba.label']['checked'])) {
1614 print_liste_field_titre($arrayfields['ba.label']['label'], $_SERVER["PHP_SELF"], "ba.label", "", $param, "", $sortfield, $sortorder);
1615 $totalarray['nbfield']++;
1616}
1617if (!empty($arrayfields['f.fk_mode_reglement']['checked'])) {
1618 print_liste_field_titre($arrayfields['f.fk_mode_reglement']['label'], $_SERVER["PHP_SELF"], "f.fk_mode_reglement", "", $param, "", $sortfield, $sortorder);
1619 $totalarray['nbfield']++;
1620}
1621if (!empty($arrayfields['f.total_ht']['checked'])) {
1622 print_liste_field_titre($arrayfields['f.total_ht']['label'], $_SERVER['PHP_SELF'], 'f.total_ht', '', $param, '', $sortfield, $sortorder, 'right ');
1623 $totalarray['nbfield']++;
1624}
1625if (!empty($arrayfields['f.total_vat']['checked'])) {
1626 print_liste_field_titre($arrayfields['f.total_vat']['label'], $_SERVER['PHP_SELF'], 'f.total_tva', '', $param, '', $sortfield, $sortorder, 'right ');
1627 $totalarray['nbfield']++;
1628}
1629if (!empty($arrayfields['f.total_localtax1']['checked'])) {
1630 print_liste_field_titre($arrayfields['f.total_localtax1']['label'], $_SERVER['PHP_SELF'], 'f.localtax1', '', $param, '', $sortfield, $sortorder, 'right ');
1631 $totalarray['nbfield']++;
1632}
1633if (!empty($arrayfields['f.total_localtax2']['checked'])) {
1634 print_liste_field_titre($arrayfields['f.total_localtax2']['label'], $_SERVER['PHP_SELF'], 'f.localtax2', '', $param, '', $sortfield, $sortorder, 'right ');
1635 $totalarray['nbfield']++;
1636}
1637if (!empty($arrayfields['f.total_ttc']['checked'])) {
1638 print_liste_field_titre($arrayfields['f.total_ttc']['label'], $_SERVER['PHP_SELF'], 'f.total_ttc', '', $param, '', $sortfield, $sortorder, 'right ');
1639 $totalarray['nbfield']++;
1640}
1641if (!empty($arrayfields['f.nb_docs']['checked'])) {
1642 print_liste_field_titre($arrayfields['f.nb_docs']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'right ');
1643 $totalarray['nbfield']++;
1644}
1645if (!empty($arrayfields['u.login']['checked'])) {
1646 print_liste_field_titre($arrayfields['u.login']['label'], $_SERVER["PHP_SELF"], 'u.login', '', $param, '', $sortfield, $sortorder);
1647 $totalarray['nbfield']++;
1648}
1649if (!empty($arrayfields['dynamount_payed']['checked'])) {
1650 print_liste_field_titre($arrayfields['dynamount_payed']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'right ');
1651 $totalarray['nbfield']++;
1652}
1653if (!empty($arrayfields['rtp']['checked'])) {
1654 print_liste_field_titre($arrayfields['rtp']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder);
1655 $totalarray['nbfield']++;
1656}
1657if (!empty($arrayfields['f.multicurrency_code']['checked'])) {
1658 print_liste_field_titre($arrayfields['f.multicurrency_code']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_code', '', $param, '', $sortfield, $sortorder);
1659 $totalarray['nbfield']++;
1660}
1661if (!empty($arrayfields['f.multicurrency_tx']['checked'])) {
1662 print_liste_field_titre($arrayfields['f.multicurrency_tx']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_tx', '', $param, '', $sortfield, $sortorder);
1663 $totalarray['nbfield']++;
1664}
1665if (!empty($arrayfields['f.multicurrency_total_ht']['checked'])) {
1666 print_liste_field_titre($arrayfields['f.multicurrency_total_ht']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_total_ht', '', $param, '"', $sortfield, $sortorder, 'right ');
1667 $totalarray['nbfield']++;
1668}
1669if (!empty($arrayfields['f.multicurrency_total_vat']['checked'])) {
1670 print_liste_field_titre($arrayfields['f.multicurrency_total_vat']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_total_tva', '', $param, '', $sortfield, $sortorder, 'right ');
1671 $totalarray['nbfield']++;
1672}
1673if (!empty($arrayfields['f.multicurrency_total_ttc']['checked'])) {
1674 print_liste_field_titre($arrayfields['f.multicurrency_total_ttc']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_total_ttc', '', $param, '', $sortfield, $sortorder, 'right ');
1675 $totalarray['nbfield']++;
1676}
1677if (!empty($arrayfields['multicurrency_dynamount_payed']['checked'])) {
1678 print_liste_field_titre($arrayfields['multicurrency_dynamount_payed']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'right ');
1679 $totalarray['nbfield']++;
1680}
1681if (!empty($arrayfields['multicurrency_rtp']['checked'])) {
1682 print_liste_field_titre($arrayfields['multicurrency_rtp']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'right ');
1683 $totalarray['nbfield']++;
1684}
1685// Extra fields
1686include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
1687// Hook fields
1688$parameters = array('arrayfields' => $arrayfields, 'param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder, 'totalarray' => &$totalarray);
1689$reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1690print $hookmanager->resPrint;
1691if (!empty($arrayfields['f.datec']['checked'])) {
1692 print_liste_field_titre($arrayfields['f.datec']['label'], $_SERVER["PHP_SELF"], "f.datec", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
1693 $totalarray['nbfield']++;
1694}
1695if (!empty($arrayfields['f.tms']['checked'])) {
1696 print_liste_field_titre($arrayfields['f.tms']['label'], $_SERVER["PHP_SELF"], "f.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
1697 $totalarray['nbfield']++;
1698}
1699if (!empty($arrayfields['f.note_public']['checked'])) {
1700 print_liste_field_titre($arrayfields['f.note_public']['label'], $_SERVER["PHP_SELF"], "f.note_public", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
1701 $totalarray['nbfield']++;
1702}
1703if (!empty($arrayfields['f.note_private']['checked'])) {
1704 print_liste_field_titre($arrayfields['f.note_private']['label'], $_SERVER["PHP_SELF"], "f.note_private", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
1705 $totalarray['nbfield']++;
1706}
1707if (!empty($arrayfields['f.fk_statut']['checked'])) {
1708 print_liste_field_titre($arrayfields['f.fk_statut']['label'], $_SERVER["PHP_SELF"], "fk_statut,paye,type", "", $param, '', $sortfield, $sortorder, 'center ');
1709 $totalarray['nbfield']++;
1710}
1711// Action column
1712if (!$conf->main_checkbox_left_column) {
1713 print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
1714 $totalarray['nbfield']++;
1715}
1716print '</tr>'."\n";
1717
1718$facturestatic = new FactureFournisseur($db);
1719$supplierstatic = new Fournisseur($db);
1720$projectstatic = new Project($db);
1721$userstatic = new User($db);
1722$discount = new DiscountAbsolute($db);
1723
1724// Loop on record
1725// --------------------------------------------------------------------
1726$i = 0;
1727$savnbfield = $totalarray['nbfield'];
1728$totalarray = array();
1729$totalarray['nbfield'] = 0;
1730$totalarray['val'] = array();
1731$totalarray['val']['f.total_ht'] = 0;
1732$totalarray['val']['f.total_vat'] = 0;
1733$totalarray['val']['f.total_localtax1'] = 0;
1734$totalarray['val']['f.total_localtax2'] = 0;
1735$totalarray['val']['f.total_ttc'] = 0;
1736$totalarray['val']['totalam'] = 0;
1737$totalarray['val']['rtp'] = 0;
1738
1739$imaxinloop = ($limit ? min($num, $limit) : $num);
1740while ($i < $imaxinloop) {
1741 $obj = $db->fetch_object($resql);
1742 if (empty($obj)) {
1743 break; // Should not happen
1744 }
1745
1746 $datelimit = $db->jdate($obj->datelimite);
1747
1748 $userstatic->id = $obj->fk_user_author;
1749 $userstatic->login = $obj->login;
1750 $userstatic->lastname = $obj->lastname;
1751 $userstatic->firstname = $obj->firstname;
1752 $userstatic->email = $obj->user_email;
1753 $userstatic->statut = $obj->user_statut; // deprecated
1754 $userstatic->status = $obj->user_statut;
1755 $userstatic->entity = $obj->entity;
1756 $userstatic->photo = $obj->photo;
1757 $userstatic->office_phone = $obj->office_phone;
1758 $userstatic->office_fax = $obj->office_fax;
1759 $userstatic->user_mobile = $obj->user_mobile;
1760 $userstatic->job = $obj->job;
1761 $userstatic->gender = $obj->gender;
1762 $facturestatic->id = $obj->facid;
1763 $facturestatic->ref = $obj->ref;
1764 $facturestatic->type = $obj->type;
1765 $facturestatic->subtype = $obj->subtype;
1766 $facturestatic->total_ht = $obj->total_ht;
1767 $facturestatic->total_tva = $obj->total_vat;
1768 $facturestatic->total_ttc = $obj->total_ttc;
1769 $facturestatic->close_code = $obj->close_code;
1770 $facturestatic->ref_supplier = $obj->ref_supplier;
1771 $facturestatic->date_echeance = $db->jdate($obj->datelimite);
1772 $facturestatic->statut = $obj->fk_statut;
1773 $facturestatic->status = $obj->fk_statut;
1774 $facturestatic->note_public = $obj->note_public;
1775 $facturestatic->note_private = $obj->note_private;
1776 $facturestatic->multicurrency_code = $obj->multicurrency_code;
1777 $facturestatic->multicurrency_tx = $obj->multicurrency_tx;
1778 $facturestatic->multicurrency_total_ht = $obj->multicurrency_total_ht;
1779 $facturestatic->multicurrency_total_tva = $obj->multicurrency_total_vat;
1780 $facturestatic->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
1781 $thirdparty->id = $obj->socid;
1782 $thirdparty->name = $obj->name;
1783 $thirdparty->name_alias = $obj->alias;
1784 $thirdparty->client = $obj->client;
1785 $thirdparty->fournisseur = $obj->fournisseur;
1786 $thirdparty->code_client = $obj->code_client;
1787 $thirdparty->code_compta_client = $obj->code_compta_client;
1788 $thirdparty->code_fournisseur = $obj->code_fournisseur;
1789 $thirdparty->code_compta_fournisseur = $obj->code_compta_fournisseur;
1790 $thirdparty->email = $obj->email;
1791 $thirdparty->country_code = $obj->country_code;
1792
1793 $paiement = $facturestatic->getSommePaiement();
1794 $totalcreditnotes = $facturestatic->getSumCreditNotesUsed();
1795 $totaldeposits = $facturestatic->getSumDepositsUsed();
1796 $totalpay = $paiement + $totalcreditnotes + $totaldeposits;
1797 $remaintopay = $obj->total_ttc - $totalpay;
1798
1799 $multicurrency_paiement = $facturestatic->getSommePaiement(1);
1800 $multicurrency_totalcreditnotes = $facturestatic->getSumCreditNotesUsed(1);
1801 $multicurrency_totaldeposits = $facturestatic->getSumDepositsUsed(1);
1802
1803 $totalpay = $paiement + $totalcreditnotes + $totaldeposits;
1804 $remaintopay = price2num($facturestatic->total_ttc - $totalpay);
1805
1806 $multicurrency_totalpay = $multicurrency_paiement + $multicurrency_totalcreditnotes + $multicurrency_totaldeposits;
1807 $multicurrency_remaintopay = (float) price2num($facturestatic->multicurrency_total_ttc - $multicurrency_totalpay);
1808
1809 if ($facturestatic->status == FactureFournisseur::STATUS_CLOSED && $facturestatic->close_code == 'discount_vat') { // If invoice closed with discount for anticipated payment
1810 $remaintopay = 0;
1811 $multicurrency_remaintopay = 0;
1812 }
1813 if ($facturestatic->type == FactureFournisseur::TYPE_CREDIT_NOTE && $obj->paye == 1) { // If credit note closed, we take into account the amount not yet consumed
1814 $remaincreditnote = $discount->getAvailableDiscounts($thirdparty, null, 'rc.fk_facture_source='.$facturestatic->id);
1815 $remaintopay = -$remaincreditnote;
1816 $totalpay = price2num($facturestatic->total_ttc - $remaintopay);
1817 $multicurrency_remaincreditnote = $discount->getAvailableDiscounts($thirdparty, null, 'rc.fk_facture_source='.$facturestatic->id, 0, 0, 1);
1818 $multicurrency_remaintopay = -$multicurrency_remaincreditnote;
1819 $multicurrency_totalpay = (float) price2num($facturestatic->multicurrency_total_ttc - $multicurrency_remaintopay);
1820 }
1821
1822 $facturestatic->alreadypaid = ($paiement ? $paiement : 0);
1823
1824 $facturestatic->paye = $obj->paye;
1825 $facturestatic->paid = $obj->paye;
1826
1827 $facturestatic->date = $db->jdate($obj->datef);
1828
1829 $object = $facturestatic;
1830
1831 //If invoice has been converted and the conversion has been used, we don't have remain to pay on invoice
1832 if ($facturestatic->type == FactureFournisseur::TYPE_CREDIT_NOTE) {
1833 if ($facturestatic->isCreditNoteUsed()) {
1834 $remaintopay = -$facturestatic->getSumFromThisCreditNotesNotUsed();
1835 }
1836 }
1837
1838 if ($mode == 'kanban') {
1839 if ($i == 0) {
1840 print '<tr class="trkanban"><td colspan="'.$savnbfield.'">';
1841 print '<div class="box-flex-container kanban">';
1842 }
1843 // Output Kanban
1844 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
1845 $selected = 0;
1846 if (in_array($object->id, $arrayofselected)) {
1847 $selected = 1;
1848 }
1849 }
1850
1851 $arraydata = array('alreadypaid' => $paiement, 'thirdparty' => $thirdparty->getNomUrl(1, '', 12), 'selected' => in_array($object->id, $arrayofselected));
1852 print $facturestatic->getKanbanView('', $arraydata);
1853 if ($i == ($imaxinloop - 1)) {
1854 print '</div>';
1855 print '</td></tr>';
1856 }
1857 } else {
1858 // Show line of result
1859 $j = 0;
1860 print '<tr data-rowid="'.$object->id.'" class="oddeven row-with-select'.((getDolGlobalInt('MAIN_FINISHED_LINES_OPACITY') == 1 && $obj->fk_statut > 1) ? ' opacitymedium' : '').'">';
1861
1862 // Action column
1863 if ($conf->main_checkbox_left_column) {
1864 print '<td class="nowrap center">';
1865 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
1866 $selected = 0;
1867 if (in_array($obj->facid, $arrayofselected)) {
1868 $selected = 1;
1869 }
1870 print '<input id="cb'.$obj->facid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->facid.'"'.($selected ? ' checked="checked"' : '').'>';
1871 }
1872 print '</td>';
1873 if (!$i) {
1874 $totalarray['nbfield']++;
1875 }
1876 }
1877 if (!empty($arrayfields['f.ref']['checked'])) {
1878 print '<td class="nowraponall">';
1879
1880 print '<table class="nobordernopadding"><tr class="nocellnopadd">';
1881 // Picto + Ref
1882 print '<td class="nobordernopadding nowraponall">';
1883 print $facturestatic->getNomUrl(1, '', 0, 0, '', 0, -1, 1);
1884
1885 $filename = dol_sanitizeFileName($obj->ref);
1886 $filedir = getMultidirOutput($facturestatic) . '/' . get_exdir($obj->facid, 2, 0, 0, $facturestatic, 'invoice_supplier') . dol_sanitizeFileName($obj->ref);
1887 $subdir = get_exdir($obj->facid, 2, 0, 0, $facturestatic, 'invoice_supplier').dol_sanitizeFileName($obj->ref);
1888 print $formfile->getDocumentsLink('facture_fournisseur', $subdir, $filedir);
1889 print '</td></tr></table>';
1890
1891 print "</td>\n";
1892 if (!$i) {
1893 $totalarray['nbfield']++;
1894 }
1895 }
1896
1897 // Supplier ref
1898 if (!empty($arrayfields['f.ref_supplier']['checked'])) {
1899 print '<td class="nowrap tdoverflowmax150" title="'.dol_escape_htmltag($obj->ref_supplier).'">';
1900 print $obj->ref_supplier;
1901 print '</td>';
1902 if (!$i) {
1903 $totalarray['nbfield']++;
1904 }
1905 }
1906
1907 // Type
1908 if (!empty($arrayfields['f.type']['checked'])) {
1909 print '<td class="nowrap">';
1910 print $facturestatic->getLibType();
1911 print "</td>";
1912 if (!$i) {
1913 $totalarray['nbfield']++;
1914 }
1915 }
1916
1917 // Invoice Subtype
1918 if (!empty($arrayfields['f.subtype']['checked'])) {
1919 $labeltoshow = '';
1920 if ($facturestatic->subtype > 0) {
1921 $labeltoshow = $facturestatic->getSubtypeLabel('facture_fourn');
1922 }
1923 print '<td class="nowraponall tdoverflowmax300" title="'.$labeltoshow.'">';
1924 print $labeltoshow;
1925 print "</td>";
1926 if (!$i) {
1927 $totalarray['nbfield']++;
1928 }
1929 }
1930
1931 // Label
1932 if (!empty($arrayfields['f.label']['checked'])) {
1933 print '<td class="nowrap tdoverflowmax125" title="'.dol_escape_htmltag($obj->label).'">';
1934 print dol_escape_htmltag($obj->label);
1935 print '</td>';
1936 if (!$i) {
1937 $totalarray['nbfield']++;
1938 }
1939 }
1940
1941 // Date
1942 if (!empty($arrayfields['f.datef']['checked'])) {
1943 print '<td class="center nowrap">';
1944 print dol_print_date($db->jdate($obj->datef), 'day');
1945 print '</td>';
1946 if (!$i) {
1947 $totalarray['nbfield']++;
1948 }
1949 }
1950
1951 // Date limit
1952 if (!empty($arrayfields['f.date_lim_reglement']['checked'])) {
1953 print '<td class="center nowraponall">'.dol_print_date($datelimit, 'day');
1954 if ($facturestatic->hasDelay()) {
1955 print img_warning($langs->trans('Alert').' - '.$langs->trans('Late'));
1956 }
1957 print '</td>';
1958 if (!$i) {
1959 $totalarray['nbfield']++;
1960 }
1961 }
1962
1963 // Project
1964 if (!empty($arrayfields['p.ref']['checked'])) {
1965 print '<td class="nowrap">';
1966 if ($obj->project_id > 0) {
1967 $projectstatic->id = $obj->project_id;
1968 $projectstatic->ref = $obj->project_ref;
1969 $projectstatic->title = $obj->project_label;
1970 print $projectstatic->getNomUrl(1);
1971 }
1972 print '</td>';
1973 if (!$i) {
1974 $totalarray['nbfield']++;
1975 }
1976 }
1977
1978 // Third party
1979 if (!empty($arrayfields['s.nom']['checked'])) {
1980 print '<td class="tdoverflowmax125">';
1981 print $thirdparty->getNomUrl(1, 'supplier', 0, 0, -1, empty($arrayfields['s.name_alias']['checked']) ? 0 : 1);
1982 print '</td>';
1983 if (!$i) {
1984 $totalarray['nbfield']++;
1985 }
1986 }
1987 // Alias
1988 if (!empty($arrayfields['s.name_alias']['checked'])) {
1989 print '<td class="tdoverflowmax150">';
1990 print dol_escape_htmltag($thirdparty->name_alias);
1991 print '</td>';
1992 if (!$i) {
1993 $totalarray['nbfield']++;
1994 }
1995 }
1996 // Town
1997 if (!empty($arrayfields['s.town']['checked'])) {
1998 print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->town).'">';
1999 print dol_escape_htmltag($obj->town);
2000 print '</td>';
2001 if (!$i) {
2002 $totalarray['nbfield']++;
2003 }
2004 }
2005 // Zip
2006 if (!empty($arrayfields['s.zip']['checked'])) {
2007 print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->zip).'">';
2008 print dol_escape_htmltag($obj->zip);
2009 print '</td>';
2010 if (!$i) {
2011 $totalarray['nbfield']++;
2012 }
2013 }
2014 // State
2015 if (!empty($arrayfields['state.nom']['checked'])) {
2016 print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->state_name).'">';
2017 print dol_escape_htmltag($obj->state_name);
2018 print "</td>\n";
2019 if (!$i) {
2020 $totalarray['nbfield']++;
2021 }
2022 }
2023 // Country
2024 if (!empty($arrayfields['country.code_iso']['checked'])) {
2025 print '<td class="center">';
2026 $tmparray = getCountry($obj->fk_pays, 'all');
2027 print $tmparray['label'];
2028 print '</td>';
2029 if (!$i) {
2030 $totalarray['nbfield']++;
2031 }
2032 }
2033 // Type ent
2034 if (!empty($arrayfields['typent.code']['checked'])) {
2035 print '<td class="center">';
2036 if (empty($typenArray)) {
2037 $typenArray = $formcompany->typent_array(1);
2038 }
2039 print $typenArray[$obj->typent_code];
2040 print '</td>';
2041 if (!$i) {
2042 $totalarray['nbfield']++;
2043 }
2044 }
2045 // VAT Reverse Charge
2046 if (!empty($arrayfields['f.vat_reverse_charge']['checked'])) {
2047 print '<td class="center">';
2048 print yn($obj->vat_reverse_charge);
2049 print '</td>';
2050 if (!$i) {
2051 $totalarray['nbfield']++;
2052 }
2053 }
2054
2055 // Payment condition
2056 if (!empty($arrayfields['f.fk_cond_reglement']['checked'])) {
2057 $s = $form->form_conditions_reglement($_SERVER['PHP_SELF'], $obj->fk_cond_reglement, 'none', 1, '', -1, -1, 1);
2058 print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($s).'">';
2059 print dol_escape_htmltag($s);
2060 print '</td>';
2061 if (!$i) {
2062 $totalarray['nbfield']++;
2063 }
2064 }
2065 // Bank account
2066 if (!empty($arrayfields['ba.label']['checked'])) {
2067 print '<td>';
2068 if (!empty($obj->bid)) {
2069 $accountstatic->id = $obj->bid;
2070 $accountstatic->ref = $obj->bref;
2071 $accountstatic->label = $obj->blabel;
2072 $accountstatic->number = $obj->bnumber;
2073 $accountstatic->account_number = $obj->baccount_number;
2074 $accountstatic->accountancy_journal = $obj->baccountancy_journal;
2075 print $accountstatic->getNomUrl(1);
2076 }
2077 print '</td>';
2078 if (!$i) {
2079 $totalarray['nbfield']++;
2080 }
2081 }
2082 // Payment mode
2083 if (!empty($arrayfields['f.fk_mode_reglement']['checked'])) {
2084 $s = $form->form_modes_reglement($_SERVER['PHP_SELF'], $obj->fk_mode_reglement, 'none', '', -1, 0, '', 1);
2085 print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($s).'">';
2086 print dol_escape_htmltag($s);
2087 print '</td>';
2088 if (!$i) {
2089 $totalarray['nbfield']++;
2090 }
2091 }
2092
2093 // Amount HT
2094 if (!empty($arrayfields['f.total_ht']['checked'])) {
2095 print '<td class="right nowrap"><span class="amount">'.price($obj->total_ht)."</span></td>\n";
2096 if (!$i) {
2097 $totalarray['nbfield']++;
2098 $totalarray['pos'][$totalarray['nbfield']] = 'f.total_ht';
2099 }
2100 $totalarray['val']['f.total_ht'] += $obj->total_ht;
2101 }
2102 // Amount VAT
2103 if (!empty($arrayfields['f.total_vat']['checked'])) {
2104 print '<td class="right nowrap"><span class="amount">'.price($obj->total_vat)."</span></td>\n";
2105 if (!$i) {
2106 $totalarray['nbfield']++;
2107 $totalarray['pos'][$totalarray['nbfield']] = 'f.total_vat';
2108 }
2109 $totalarray['val']['f.total_vat'] += $obj->total_vat;
2110 }
2111 // Amount LocalTax1
2112 if (!empty($arrayfields['f.total_localtax1']['checked'])) {
2113 print '<td class="right nowrap"><span class="amount">'.price($obj->total_localtax1)."</span></td>\n";
2114 if (!$i) {
2115 $totalarray['nbfield']++;
2116 $totalarray['pos'][$totalarray['nbfield']] = 'f.total_localtax1';
2117 }
2118 $totalarray['val']['f.total_localtax1'] += $obj->total_localtax1;
2119 }
2120 // Amount LocalTax2
2121 if (!empty($arrayfields['f.total_localtax2']['checked'])) {
2122 print '<td class="right nowrap"><span class="amount">'.price($obj->total_localtax2)."</span></td>\n";
2123 if (!$i) {
2124 $totalarray['nbfield']++;
2125 $totalarray['pos'][$totalarray['nbfield']] = 'f.total_localtax2';
2126 }
2127 $totalarray['val']['f.total_localtax2'] += $obj->total_localtax2;
2128 }
2129 // Amount TTC
2130 if (!empty($arrayfields['f.total_ttc']['checked'])) {
2131 print '<td class="right nowrap"><span class="amount">'.price($obj->total_ttc)."</span></td>\n";
2132 if (!$i) {
2133 $totalarray['nbfield']++;
2134 $totalarray['pos'][$totalarray['nbfield']] = 'f.total_ttc';
2135 }
2136 $totalarray['val']['f.total_ttc'] += $obj->total_ttc;
2137 }
2138
2139 // Number of attached documents (may slow your application on large lists)
2140 if (!empty($arrayfields['f.nb_docs']['checked'])) {
2141 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
2142 require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
2143 $upload_dir = getMultidirOutput($facturestatic).'/'.get_exdir($facturestatic->id, 2, 0, 0, $facturestatic, 'invoice_supplier').$facturestatic->ref;
2144 $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
2145 $nbLinks = Link::count($db, $facturestatic->element, $facturestatic->id);
2146 $nbTotal = $nbFiles + $nbLinks;
2147 echo '<td class="center">'.(empty($nbTotal) ? '' : $nbTotal).'</td>';
2148 if (!$i) {
2149 $totalarray['nbfield']++;
2150 }
2151 }
2152
2153 // Author
2154 if (!empty($arrayfields['u.login']['checked'])) {
2155 print '<td class="tdoverflowmax100">';
2156 if ($userstatic->id) {
2157 print $userstatic->getNomUrl(-1);
2158 } else {
2159 print '&nbsp;';
2160 }
2161 print "</td>\n";
2162 if (!$i) {
2163 $totalarray['nbfield']++;
2164 }
2165 }
2166
2167 // Dynamic amount paid
2168 if (!empty($arrayfields['dynamount_payed']['checked'])) {
2169 print '<td class="right nowrap"><span class="amount">'.(!empty($totalpay) ? price($totalpay, 0, $langs) : '').'</span></td>'; // TODO Use a denormalized field
2170 if (!$i) {
2171 $totalarray['nbfield']++;
2172 $totalarray['pos'][$totalarray['nbfield']] = 'totalam';
2173 }
2174 $totalarray['val']['totalam'] += $totalpay;
2175 }
2176
2177 // Remain to pay
2178 if (!empty($arrayfields['rtp']['checked'])) {
2179 print '<td class="right nowrap">'.(!empty($remaintopay) ? price($remaintopay, 0, $langs) : '&nbsp;').'</td>'; // TODO Use a denormalized field
2180 if (!$i) {
2181 $totalarray['nbfield']++;
2182 $totalarray['pos'][$totalarray['nbfield']] = 'rtp';
2183 }
2184 $totalarray['val']['rtp'] += $remaintopay;
2185 }
2186
2187 // Currency
2188 if (!empty($arrayfields['f.multicurrency_code']['checked'])) {
2189 print '<td class="nowrap">'.$obj->multicurrency_code.' - '.$langs->trans('Currency'.$obj->multicurrency_code)."</td>\n";
2190 if (!$i) {
2191 $totalarray['nbfield']++;
2192 }
2193 }
2194
2195 // Currency rate
2196 if (!empty($arrayfields['f.multicurrency_tx']['checked'])) {
2197 print '<td class="nowrap">';
2198 $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$obj->facid, $obj->multicurrency_tx, 'none', $obj->multicurrency_code);
2199 print "</td>\n";
2200 if (!$i) {
2201 $totalarray['nbfield']++;
2202 }
2203 }
2204 // Amount HT
2205 if (!empty($arrayfields['f.multicurrency_total_ht']['checked'])) {
2206 print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_ht)."</span></td>\n";
2207 if (!$i) {
2208 $totalarray['nbfield']++;
2209 }
2210 }
2211 // Amount VAT
2212 if (!empty($arrayfields['f.multicurrency_total_vat']['checked'])) {
2213 print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_vat)."</span></td>\n";
2214 if (!$i) {
2215 $totalarray['nbfield']++;
2216 }
2217 }
2218 // Amount TTC
2219 if (!empty($arrayfields['f.multicurrency_total_ttc']['checked'])) {
2220 print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_ttc)."</span></td>\n";
2221 if (!$i) {
2222 $totalarray['nbfield']++;
2223 }
2224 }
2225 // Dynamic amount paid
2226 if (!empty($arrayfields['multicurrency_dynamount_payed']['checked'])) {
2227 print '<td class="right nowrap"><span class="amount">'.(!empty($multicurrency_totalpay) ? price($multicurrency_totalpay, 0, $langs) : '').'</span></td>'; // TODO Use a denormalized field
2228 if (!$i) {
2229 $totalarray['nbfield']++;
2230 }
2231 }
2232
2233 // Pending amount
2234 if (!empty($arrayfields['multicurrency_rtp']['checked'])) {
2235 print '<td class="right nowrap"><span class="amount">';
2236 print(!empty($multicurrency_remaintopay) ? price($multicurrency_remaintopay, 0, $langs) : '');
2237 print '</span></td>'; // TODO Use a denormalized field
2238 if (!$i) {
2239 $totalarray['nbfield']++;
2240 }
2241 }
2242
2243
2244 // Extra fields
2245 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
2246 // Fields from hook
2247 $parameters = array('arrayfields' => $arrayfields, 'object' => $object, 'obj' => $obj, 'i' => $i, 'totalarray' => &$totalarray);
2248 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
2249 print $hookmanager->resPrint;
2250
2251 // Date creation
2252 if (!empty($arrayfields['f.datec']['checked'])) {
2253 print '<td class="center nowraponall">';
2254 print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
2255 print '</td>';
2256 if (!$i) {
2257 $totalarray['nbfield']++;
2258 }
2259 }
2260 // Date modification
2261 if (!empty($arrayfields['f.tms']['checked'])) {
2262 print '<td class="center nowraponall">';
2263 print dol_print_date($db->jdate($obj->date_modification), 'dayhour', 'tzuser');
2264 print '</td>';
2265 if (!$i) {
2266 $totalarray['nbfield']++;
2267 }
2268 }
2269 // Note public
2270 if (!empty($arrayfields['f.note_public']['checked'])) {
2271 print '<td class="sensiblehtmlcontent center">';
2272 print '<div class="small lineheightsmall twolinesmax-normallineheight">'.dolPrintHTML(dolGetFirstLineOfText($obj->note_public, 5)).'</div>';
2273 print '</td>';
2274 if (!$i) {
2275 $totalarray['nbfield']++;
2276 }
2277 }
2278 // Note private
2279 if (!empty($arrayfields['f.note_private']['checked'])) {
2280 print '<td class="sensiblehtmlcontent center">';
2281 print '<div class="small lineheightsmall twolinesmax-normallineheight">'.dolPrintHTML(dolGetFirstLineOfText($obj->note_private, 5)).'</div>';
2282 print '</td>';
2283 if (!$i) {
2284 $totalarray['nbfield']++;
2285 }
2286 }
2287 // Status
2288 if (!empty($arrayfields['f.fk_statut']['checked'])) {
2289 print '<td class="center nowrap">';
2290 print $facturestatic->getLibStatut(5, $paiement);
2291 print "</td>";
2292 if (!$i) {
2293 $totalarray['nbfield']++;
2294 }
2295 }
2296
2297 // Action column
2298 if (!$conf->main_checkbox_left_column) {
2299 print '<td class="nowrap center">';
2300 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
2301 $selected = 0;
2302 if (in_array($obj->facid, $arrayofselected)) {
2303 $selected = 1;
2304 }
2305 print '<input id="cb'.$obj->facid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->facid.'"'.($selected ? ' checked="checked"' : '').'>';
2306 }
2307 print '</td>';
2308 if (!$i) {
2309 $totalarray['nbfield']++;
2310 }
2311 }
2312
2313 print '</tr>'."\n";
2314 }
2315
2316 $i++;
2317}
2318
2319// Show total line
2320include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
2321
2322// If no record found
2323if ($num == 0) {
2324 $colspan = 1;
2325 foreach ($arrayfields as $key => $val) {
2326 if (!empty($val['checked'])) {
2327 $colspan++;
2328 }
2329 }
2330 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
2331}
2332
2333$db->free($resql);
2334
2335$parameters = array('arrayfields' => $arrayfields, 'sql' => $sql);
2336$reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
2337print $hookmanager->resPrint;
2338
2339print '</table>'."\n";
2340print '</div>'."\n";
2341
2342print '</form>'."\n";
2343
2344if (in_array('builddoc', array_keys($arrayofmassactions)) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
2345 $hidegeneratedfilelistifempty = 1;
2346 if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
2347 $hidegeneratedfilelistifempty = 0;
2348 }
2349
2350 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
2351 $formfile = new FormFile($db);
2352
2353 // Show list of available documents
2354 $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
2355 $urlsource .= str_replace('&amp;', '&', $param);
2356
2357 $filedir = $diroutputmassaction;
2358 $genallowed = $permissiontoread;
2359 $delallowed = $permissiontoadd;
2360 $title = '';
2361
2362 print $formfile->showdocuments('massfilesarea_supplier_invoice', '', $filedir, $urlsource, 0, (int) $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
2363}
2364
2365// End of page
2366llxFooter();
2367$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.