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