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