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