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