dolibarr 20.0.5
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
229// Check only if it' an internal user
230if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
231 $search_sale = $user->id;
232}
233
234$permissiontoread = ($user->hasRight("fournisseur", "facture", "lire") || $user->hasRight("supplier_invoice", "lire"));
235$permissiontoadd = ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer"));
236$permissiontodelete = ($user->hasRight("fournisseur", "facture", "supprimer") || $user->hasRight("supplier_invoice", "supprimer"));
237
238
239/*
240 * Actions
241 */
242
243if (GETPOST('cancel', 'alpha')) {
244 $action = 'list';
245 $massaction = '';
246}
247if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
248 $massaction = '';
249}
250
251$parameters = array('socid' => $socid, 'arrayfields' => &$arrayfields);
252$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
253if ($reshook < 0) {
254 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
255}
256
257if (empty($reshook)) {
258 // Selection of new fields
259 include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
260
261 // Purge search criteria
262 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
263 $search_all = "";
264 $search_user = '';
265 $search_sale = '';
266 $search_product_category = '';
267 $search_ref = "";
268 $search_refsupplier = "";
269 $search_type = "";
270 $search_subtype = '';
271 $search_label = "";
272 $search_project = '';
273 $search_company = "";
274 $search_company_alias = "";
275 $search_amount_no_tax = "";
276 $search_amount_all_tax = "";
277 $search_montant_ht = '';
278 $search_montant_vat = '';
279 $search_montant_localtax1 = '';
280 $search_montant_localtax2 = '';
281 $search_montant_ttc = '';
282 $search_login = '';
283 $search_multicurrency_code = '';
284 $search_multicurrency_tx = '';
285 $search_multicurrency_montant_ht = '';
286 $search_multicurrency_montant_vat = '';
287 $search_multicurrency_montant_ttc = '';
288 $search_status = '';
289 $search_paymentmode = '';
290 $search_paymentcond = '';
291 $search_town = '';
292 $search_zip = "";
293 $search_state = "";
294 $search_country = '';
295 $search_type_thirdparty = '';
296 $search_date_start = '';
297 $search_date_end = '';
298 $search_datelimit_startday = '';
299 $search_datelimit_startmonth = '';
300 $search_datelimit_startyear = '';
301 $search_datelimit_endday = '';
302 $search_datelimit_endmonth = '';
303 $search_datelimit_endyear = '';
304 $search_datelimit_start = '';
305 $search_datelimit_end = '';
306 $toselect = array();
307 $search_array_options = array();
308 $search_categ_sup = 0;
309 $filter = '';
310 $option = '';
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(DISTINCT f.rowid) as nbtotalofrecords', $sql);
774
775 $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
776 $sqlforcount = preg_replace('/LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf ON pf.fk_facturefourn = f.rowid/', '', $sqlforcount);
777
778 $resql = $db->query($sqlforcount);
779 if ($resql) {
780 $objforcount = $db->fetch_object($resql);
781 $nbtotalofrecords = $objforcount->nbtotalofrecords;
782 } else {
783 dol_print_error($db);
784 }
785
786 if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller than the paging size (filtering), goto and load page 0
787 $page = 0;
788 $offset = 0;
789 }
790 $db->free($resql);
791}
792
793// Complete request and execute it with limit
794$sql .= $db->order($sortfield, $sortorder);
795if ($limit) {
796 $sql .= $db->plimit($limit + 1, $offset);
797}
798//print $sql;
799
800$resql = $db->query($sql);
801if (!$resql) {
802 dol_print_error($db);
803 exit;
804}
805
806$num = $db->num_rows($resql);
807
808// Direct jump if only one record found
809if ($num == 1 && getDolGlobalInt('MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE') && $search_all && !$page) {
810 $obj = $db->fetch_object($resql);
811 $id = $obj->facid;
812 header("Location: ".DOL_URL_ROOT.'/fourn/facture/card.php?facid='.$id);
813 exit;
814}
815
816// Output page
817// --------------------------------------------------------------------
818
819llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'bodyforlist');
820
821if ($socid) {
822 $soc = new Societe($db);
823 $soc->fetch($socid);
824 if (empty($search_company)) {
825 $search_company = $soc->name;
826 $search_company_alias = $soc->name_alias;
827 }
828}
829
830$arrayofselected = is_array($toselect) ? $toselect : array();
831
832$param = '&socid='.$socid;
833if (!empty($mode)) {
834 $param .= '&mode='.urlencode($mode);
835}
836if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
837 $param .= '&contextpage='.urlencode($contextpage);
838}
839if ($limit > 0 && $limit != $conf->liste_limit) {
840 $param .= '&limit='.((int) $limit);
841}
842if ($optioncss != '') {
843 $param .= '&optioncss='.urlencode($optioncss);
844}
845if ($search_all) {
846 $param .= '&search_all='.urlencode($search_all);
847}
848if ($search_date_start) {
849 $param .= buildParamDate('search_date_start', null, '', 'tzserver');
850}
851if ($search_date_end) {
852 $param .= buildParamDate('search_date_end', null, '', 'tzserver');
853}
854if ($search_datelimit_startday) {
855 $param .= '&search_datelimit_startday='.urlencode((string) ($search_datelimit_startday));
856}
857if ($search_datelimit_startmonth) {
858 $param .= '&search_datelimit_startmonth='.urlencode((string) ($search_datelimit_startmonth));
859}
860if ($search_datelimit_startyear) {
861 $param .= '&search_datelimit_startyear='.urlencode((string) ($search_datelimit_startyear));
862}
863if ($search_datelimit_endday) {
864 $param .= '&search_datelimit_endday='.urlencode((string) ($search_datelimit_endday));
865}
866if ($search_datelimit_endmonth) {
867 $param .= '&search_datelimit_endmonth='.urlencode((string) ($search_datelimit_endmonth));
868}
869if ($search_datelimit_endyear) {
870 $param .= '&search_datelimit_endyear='.urlencode((string) ($search_datelimit_endyear));
871}
872if ($search_ref) {
873 $param .= '&search_ref='.urlencode($search_ref);
874}
875if ($search_refsupplier) {
876 $param .= '&search_refsupplier='.urlencode($search_refsupplier);
877}
878if ($search_type != '') {
879 $param .= '&search_type='.urlencode($search_type);
880}
881if ($search_subtype != '') {
882 $param .= '&search_subtype='.urlencode($search_subtype);
883}
884if ($search_label) {
885 $param .= '&search_label='.urlencode($search_label);
886}
887if ($search_company) {
888 $param .= '&search_company='.urlencode($search_company);
889}
890if ($search_company_alias) {
891 $param .= '&search_company_alias='.urlencode($search_company_alias);
892}
893if ($search_login) {
894 $param .= '&search_login='.urlencode($search_login);
895}
896if ($search_montant_ht != '') {
897 $param .= '&search_montant_ht='.urlencode($search_montant_ht);
898}
899if ($search_montant_vat != '') {
900 $param .= '&search_montant_vat='.urlencode($search_montant_vat);
901}
902if ($search_montant_localtax1 != '') {
903 $param .= '&search_montant_localtax1='.urlencode($search_montant_localtax1);
904}
905if ($search_montant_localtax2 != '') {
906 $param .= '&search_montant_localtax2='.urlencode($search_montant_localtax2);
907}
908if ($search_montant_ttc != '') {
909 $param .= '&search_montant_ttc='.urlencode($search_montant_ttc);
910}
911if ($search_multicurrency_code != '') {
912 $param .= '&search_multicurrency_code='.urlencode($search_multicurrency_code);
913}
914if ($search_multicurrency_tx != '') {
915 $param .= '&search_multicurrency_tx='.urlencode($search_multicurrency_tx);
916}
917if ($search_multicurrency_montant_ht != '') {
918 $param .= '&search_multicurrency_montant_ht='.urlencode($search_multicurrency_montant_ht);
919}
920if ($search_multicurrency_montant_vat != '') {
921 $param .= '&search_multicurrency_montant_vat='.urlencode($search_multicurrency_montant_vat);
922}
923if ($search_multicurrency_montant_ttc != '') {
924 $param .= '&search_multicurrency_montant_ttc='.urlencode($search_multicurrency_montant_ttc);
925}
926if ($search_amount_no_tax) {
927 $param .= '&search_amount_no_tax='.urlencode($search_amount_no_tax);
928}
929if ($search_amount_all_tax) {
930 $param .= '&search_amount_all_tax='.urlencode($search_amount_all_tax);
931}
932if ($search_status >= 0) {
933 $param .= "&search_status=".urlencode($search_status);
934}
935if ($search_paymentmode) {
936 $param .= '&search_paymentmode='.urlencode((string) ($search_paymentmode));
937}
938if ($search_paymentcond) {
939 $param .= '&search_paymentcond='.urlencode((string) ($search_paymentcond));
940}
941if ($show_files) {
942 $param .= '&show_files='.urlencode((string) ($show_files));
943}
944if ($option) {
945 $param .= "&search_option=".urlencode($option);
946}
947if ($search_categ_sup > 0) {
948 $param .= '&search_categ_sup='.$search_categ_sup;
949}
950if ($search_type_thirdparty != '' && $search_type_thirdparty > 0) {
951 $param .= '&search_type_thirdparty='.$search_type_thirdparty;
952}
953
954// Add $param from extra fields
955include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
956// Add $param from hooks
957$parameters = array('param' => &$param);
958$reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
959$param .= $hookmanager->resPrint;
960
961// List of mass actions available
962$arrayofmassactions = array(
963 'validate' => img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate"),
964 'generate_doc' => img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
965 'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
966 //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
967);
968
969if (isModEnabled('paymentbybanktransfer') && $user->hasRight("paymentbybanktransfer", "create")) {
970 $langs->load('withdrawals');
971 $arrayofmassactions['banktransfertrequest'] = img_picto('', 'payment', 'class="pictofixedwidth"').$langs->trans("MakeBankTransferOrder");
972}
973if (!empty($permissiontodelete)) {
974 $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
975}
976if (GETPOSTINT('nomassaction') || in_array($massaction, array('presend', 'predelete'))) {
977 $arrayofmassactions = array();
978}
979$massactionbutton = $form->selectMassAction('', $arrayofmassactions);
980
981$url = DOL_URL_ROOT.'/fourn/facture/card.php?action=create';
982if (!empty($socid)) {
983 $url .= '&socid='.urlencode((string) ($socid));
984}
985
986$i = 0;
987print '<form method="POST" id="searchFormList" name="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
988if ($optioncss != '') {
989 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
990}
991print '<input type="hidden" name="token" value="'.newToken().'">';
992print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
993print '<input type="hidden" name="action" value="list">';
994print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
995print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
996print '<input type="hidden" name="socid" value="'.$socid.'">';
997print '<input type="hidden" name="page" value="'.$page.'">';
998print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
999print '<input type="hidden" name="page_y" value="">';
1000print '<input type="hidden" name="mode" value="'.$mode.'">';
1001
1002$newcardbutton = '';
1003$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'));
1004$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'));
1005$newcardbutton .= dolGetButtonTitleSeparator();
1006$newcardbutton .= dolGetButtonTitle($langs->trans('NewBill'), '', 'fa fa-plus-circle', $url, '', ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer")));
1007
1008print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'supplier_invoice', 0, $newcardbutton, '', $limit, 0, 0, 1);
1009
1010// Add code for pre mass action (confirmation or email presend form)
1011$topicmail = "SendBillRef";
1012$modelmail = "invoice_supplier_send";
1013$objecttmp = new FactureFournisseur($db);
1014$trackid = 'sinv'.$object->id;
1015include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
1016
1017if ($search_all) {
1018 $setupstring = '';
1019 foreach ($fieldstosearchall as $key => $val) {
1020 $fieldstosearchall[$key] = $langs->trans($val);
1021 $setupstring .= $key."=".$val.";";
1022 }
1023 print '<!-- Search done like if SUPPLIER_INVOICE_QUICKSEARCH_ON_FIELDS = '.$setupstring.' -->'."\n";
1024 print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).implode(', ', $fieldstosearchall).'</div>'."\n";
1025}
1026
1027// If the user can view prospects other than his'
1028$moreforfilter = '';
1029if ($user->hasRight("user", "user", "lire")) {
1030 $langs->load("commercial");
1031 $moreforfilter .= '<div class="divsearchfield">';
1032 $tmptitle = $langs->trans('ThirdPartiesOfSaleRepresentative');
1033 $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, $tmptitle, 'maxwidth200');
1034 $moreforfilter .= '</div>';
1035}
1036// If the user can view prospects other than his'
1037if ($user->hasRight("user", "user", "lire")) {
1038 $moreforfilter .= '<div class="divsearchfield">';
1039 $tmptitle = $langs->trans('LinkedToSpecificUsers');
1040 $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$form->select_dolusers($search_user, 'search_user', $tmptitle, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth200');
1041 $moreforfilter .= '</div>';
1042}
1043// If the user can view prospects other than his'
1044if (isModEnabled('category') && $user->hasRight('categorie', 'lire') && ($user->hasRight('produit', 'lire') || $user->hasRight('service', 'lire'))) {
1045 include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
1046 $moreforfilter .= '<div class="divsearchfield">';
1047 $tmptitle = $langs->trans('IncludingProductWithTag');
1048 $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, null, 'parent', null, null, 1);
1049 $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);
1050 $moreforfilter .= '</div>';
1051}
1052
1053if (isModEnabled('category')) {
1054 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
1055 $moreforfilter .= '<div class="divsearchfield">';
1056 $tmptitle = $langs->trans('SuppliersCategoriesShort');
1057 $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"').$formother->select_categories('supplier', $search_categ_sup, 'search_categ_sup', 1, $tmptitle);
1058 $moreforfilter .= '</div>';
1059}
1060$parameters = array();
1061$reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1062if (empty($reshook)) {
1063 $moreforfilter .= $hookmanager->resPrint;
1064} else {
1065 $moreforfilter = $hookmanager->resPrint;
1066}
1067
1068if (!empty($moreforfilter)) {
1069 print '<div class="liste_titre liste_titre_bydiv centpercent">';
1070 print $moreforfilter;
1071 print '</div>';
1072}
1073
1074$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
1075$htmlofselectarray = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')); // This also change content of $arrayfields with user setup
1076$selectedfields = ($mode != 'kanban' ? $htmlofselectarray : '');
1077$selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
1078
1079print '<div class="div-table-responsive">';
1080print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
1081
1082// Fields title search
1083// --------------------------------------------------------------------
1084print '<tr class="liste_titre_filter">';
1085// Action column
1086if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1087 print '<td class="liste_titre center maxwidthsearch">';
1088 $searchpicto = $form->showFilterButtons('left');
1089 print $searchpicto;
1090 print '</td>';
1091}
1092// Ref
1093if (!empty($arrayfields['f.ref']['checked'])) {
1094 print '<td class="liste_titre left">';
1095 print '<input class="flat maxwidth50" type="text" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">';
1096 print '</td>';
1097}
1098// Ref supplier
1099if (!empty($arrayfields['f.ref_supplier']['checked'])) {
1100 print '<td class="liste_titre">';
1101 print '<input class="flat maxwidth75" type="text" name="search_refsupplier" value="'.dol_escape_htmltag($search_refsupplier).'">';
1102 print '</td>';
1103}
1104// Type
1105if (!empty($arrayfields['f.type']['checked'])) {
1106 print '<td class="liste_titre maxwidthonsmartphone">';
1107 $typearray = array(
1108 FactureFournisseur::TYPE_STANDARD => $langs->trans("InvoiceStandard"),
1109 FactureFournisseur::TYPE_REPLACEMENT => $langs->trans("InvoiceReplacement"),
1110 FactureFournisseur::TYPE_CREDIT_NOTE => $langs->trans("InvoiceAvoir"),
1111 FactureFournisseur::TYPE_DEPOSIT => $langs->trans("InvoiceDeposit"),
1112 );
1113 print $form->selectarray('search_type', $typearray, $search_type, 1, 0, 0, '', 0, 0, 0, 'ASC', 'maxwidth100');
1114 print '</td>';
1115}
1116// Invoice Subtype
1117if (!empty($arrayfields['f.subtype']['checked'])) {
1118 print '<td class="liste_titre maxwidthonsmartphone" align="center">';
1119 print $form->selectarray('search_subtype', $subtypearray, $search_subtype, 1, 0, 0, '', 0, 0, 0, '', 'maxwidth100');
1120 print '</td>';
1121}
1122// Label
1123if (!empty($arrayfields['f.label']['checked'])) {
1124 print '<td class="liste_titre">';
1125 print '<input class="flat maxwidth75" type="text" name="search_label" value="'.dol_escape_htmltag($search_label).'">';
1126 print '</td>';
1127}
1128// Date invoice
1129if (!empty($arrayfields['f.datef']['checked'])) {
1130 print '<td class="liste_titre center">';
1131 print '<div class="nowrapfordate">';
1132 print $form->selectDate($search_date_start ? $search_date_start : -1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
1133 print '</div>';
1134 print '<div class="nowrapfordate">';
1135 print $form->selectDate($search_date_end ? $search_date_end : -1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
1136 print '</div>';
1137 print '</td>';
1138}
1139// Date due
1140if (!empty($arrayfields['f.date_lim_reglement']['checked'])) {
1141 print '<td class="liste_titre center">';
1142 print '<div class="">';
1143 /*
1144 print $langs->trans('From').' ';
1145 print $form->selectDate($search_datelimit_start ? $search_datelimit_start : -1, 'search_datelimit_start', 0, 0, 1);
1146 print '</div>';
1147 print '<div class="nowrap">';
1148 print $langs->trans('to').' ';*/
1149 print $form->selectDate($search_datelimit_end ? $search_datelimit_end : -1, 'search_datelimit_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("Before"));
1150 //print '<br>';
1151 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>';
1152 print '</div>';
1153 print '</td>';
1154}
1155// Project
1156if (!empty($arrayfields['p.ref']['checked'])) {
1157 print '<td class="liste_titre"><input class="flat maxwidth50" type="text" name="search_project" value="'.dol_escape_htmltag($search_project).'"></td>';
1158}
1159// Thirpdarty
1160if (!empty($arrayfields['s.nom']['checked'])) {
1161 print '<td class="liste_titre"><input class="flat maxwidth50" type="text" name="search_company" value="'.dol_escape_htmltag($search_company).'"'.($socid > 0 ? " disabled" : "").'></td>';
1162}
1163// Alias
1164if (!empty($arrayfields['s.name_alias']['checked'])) {
1165 print '<td class="liste_titre"><input class="flat maxwidth50" type="text" name="search_company_alias" value="'.dol_escape_htmltag($search_company_alias).'"></td>';
1166}
1167// Town
1168if (!empty($arrayfields['s.town']['checked'])) {
1169 print '<td class="liste_titre"><input class="flat maxwidth50" type="text" name="search_town" value="'.dol_escape_htmltag($search_town).'"></td>';
1170}
1171// Zip
1172if (!empty($arrayfields['s.zip']['checked'])) {
1173 print '<td class="liste_titre"><input class="flat maxwidth50" type="text" name="search_zip" value="'.dol_escape_htmltag($search_zip).'"></td>';
1174}
1175// State
1176if (!empty($arrayfields['state.nom']['checked'])) {
1177 print '<td class="liste_titre">';
1178 print '<input class="flat maxwidth50imp" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
1179 print '</td>';
1180}
1181// Country
1182if (!empty($arrayfields['country.code_iso']['checked'])) {
1183 print '<td class="liste_titre center">';
1184 print $form->select_country($search_country, 'search_country', '', 0, 'minwidth150imp maxwidth150', 'code2', 1, 0, 1, null, 1);
1185 print '</td>';
1186}
1187// Company type
1188if (!empty($arrayfields['typent.code']['checked'])) {
1189 print '<td class="liste_titre maxwidthonsmartphone center">';
1190 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);
1191 print '</td>';
1192}
1193// Condition of payment
1194if (!empty($arrayfields['f.fk_cond_reglement']['checked'])) {
1195 print '<td class="liste_titre left">';
1196 print $form->getSelectConditionsPaiements($search_paymentcond, 'search_paymentcond', -1, 1, 1, 'maxwidth100');
1197 print '</td>';
1198}
1199// Payment mode
1200if (!empty($arrayfields['f.fk_mode_reglement']['checked'])) {
1201 print '<td class="liste_titre">';
1202 print $form->select_types_paiements($search_paymentmode, 'search_paymentmode', '', 0, 1, 1, 20, 1, 'maxwidth100', 1);
1203 print '</td>';
1204}
1205if (!empty($arrayfields['f.total_ht']['checked'])) {
1206 // Amount without tax
1207 print '<td class="liste_titre right">';
1208 print '<input class="flat" type="text" size="5" name="search_montant_ht" value="'.dol_escape_htmltag($search_montant_ht).'">';
1209 print '</td>';
1210}
1211if (!empty($arrayfields['f.total_vat']['checked'])) {
1212 // Amount vat
1213 print '<td class="liste_titre right">';
1214 print '<input class="flat" type="text" size="5" name="search_montant_vat" value="'.dol_escape_htmltag($search_montant_vat).'">';
1215 print '</td>';
1216}
1217if (!empty($arrayfields['f.total_localtax1']['checked'])) {
1218 // Amount tax 1
1219 print '<td class="liste_titre right">';
1220 print '<input class="flat" type="text" size="5" name="search_montant_localtax1" value="'.dol_escape_htmltag($search_montant_localtax1).'">';
1221 print '</td>';
1222}
1223if (!empty($arrayfields['f.total_localtax2']['checked'])) {
1224 // Amount tax 2
1225 print '<td class="liste_titre right">';
1226 print '<input class="flat" type="text" size="5" name="search_montant_localtax2" value="'.dol_escape_htmltag($search_montant_localtax2).'">';
1227 print '</td>';
1228}
1229if (!empty($arrayfields['f.total_ttc']['checked'])) {
1230 // Amount inc tac
1231 print '<td class="liste_titre right">';
1232 print '<input class="flat" type="text" size="5" name="search_montant_ttc" value="'.dol_escape_htmltag($search_montant_ttc).'">';
1233 print '</td>';
1234}
1235if (!empty($arrayfields['f.nb_docs']['checked'])) {
1236 // Nb of attached documents
1237 print '<td class="liste_titre" align="center">';
1238 print '</td>';
1239}
1240if (!empty($arrayfields['u.login']['checked'])) {
1241 // Author
1242 print '<td class="liste_titre" align="center">';
1243 print '<input class="flat" size="4" type="text" name="search_login" value="'.dol_escape_htmltag($search_login).'">';
1244 print '</td>';
1245}
1246if (!empty($arrayfields['dynamount_payed']['checked'])) {
1247 print '<td class="liste_titre right">';
1248 print '</td>';
1249}
1250if (!empty($arrayfields['rtp']['checked'])) {
1251 print '<td class="liste_titre">';
1252 print '</td>';
1253}
1254if (!empty($arrayfields['f.multicurrency_code']['checked'])) {
1255 // Currency
1256 print '<td class="liste_titre">';
1257 print $form->selectMultiCurrency($search_multicurrency_code, 'search_multicurrency_code', 1);
1258 print '</td>';
1259}
1260if (!empty($arrayfields['f.multicurrency_tx']['checked'])) {
1261 // Currency rate
1262 print '<td class="liste_titre">';
1263 print '<input class="flat" type="text" size="4" name="search_multicurrency_tx" value="'.dol_escape_htmltag($search_multicurrency_tx).'">';
1264 print '</td>';
1265}
1266if (!empty($arrayfields['f.multicurrency_total_ht']['checked'])) {
1267 // Amount
1268 print '<td class="liste_titre right">';
1269 print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_ht" value="'.dol_escape_htmltag($search_multicurrency_montant_ht).'">';
1270 print '</td>';
1271}
1272if (!empty($arrayfields['f.multicurrency_total_vat']['checked'])) {
1273 // Amount
1274 print '<td class="liste_titre right">';
1275 print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_vat" value="'.dol_escape_htmltag($search_multicurrency_montant_vat).'">';
1276 print '</td>';
1277}
1278if (!empty($arrayfields['f.multicurrency_total_ttc']['checked'])) {
1279 // Amount
1280 print '<td class="liste_titre right">';
1281 print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_ttc" value="'.dol_escape_htmltag($search_multicurrency_montant_ttc).'">';
1282 print '</td>';
1283}
1284if (!empty($arrayfields['multicurrency_dynamount_payed']['checked'])) {
1285 print '<td class="liste_titre">';
1286 print '</td>';
1287}
1288if (!empty($arrayfields['multicurrency_rtp']['checked'])) {
1289 print '<td class="liste_titre right">';
1290 print '</td>';
1291}
1292// Extra fields
1293include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
1294
1295// Fields from hook
1296$parameters = array('arrayfields' => $arrayfields);
1297$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1298print $hookmanager->resPrint;
1299// Date creation
1300if (!empty($arrayfields['f.datec']['checked'])) {
1301 print '<td class="liste_titre">';
1302 print '</td>';
1303}
1304// Date modification
1305if (!empty($arrayfields['f.tms']['checked'])) {
1306 print '<td class="liste_titre">';
1307 print '</td>';
1308}
1309// Status
1310if (!empty($arrayfields['f.fk_statut']['checked'])) {
1311 print '<td class="liste_titre center parentonrightofpage">';
1312 $liststatus = array('0' => $langs->trans("Draft"), '1' => $langs->trans("Unpaid"), '2' => $langs->trans("Paid"));
1313 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
1314 print $form->selectarray('search_status', $liststatus, $search_status, 1, 0, 0, '', 0, 0, 0, '', 'center search_status width100 onrightofpage', 1);
1315 print '</td>';
1316}
1317// Action column
1318if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1319 print '<td class="liste_titre center maxwidthsearch">';
1320 $searchpicto = $form->showFilterButtons();
1321 print $searchpicto;
1322 print '</td>';
1323}
1324
1325print "</tr>\n";
1326
1327$totalarray = array();
1328$totalarray['nbfield'] = 0;
1329
1330// Fields title label
1331// --------------------------------------------------------------------
1332print '<tr class="liste_titre">';
1333// Action column
1334if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1335 print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
1336 $totalarray['nbfield']++;
1337}
1338if (!empty($arrayfields['f.ref']['checked'])) {
1339 print_liste_field_titre($arrayfields['f.ref']['label'], $_SERVER['PHP_SELF'], 'f.ref,f.rowid', '', $param, '', $sortfield, $sortorder);
1340 $totalarray['nbfield']++;
1341}
1342if (!empty($arrayfields['f.ref_supplier']['checked'])) {
1343 print_liste_field_titre($arrayfields['f.ref_supplier']['label'], $_SERVER["PHP_SELF"], 'f.ref_supplier', '', $param, '', $sortfield, $sortorder);
1344 $totalarray['nbfield']++;
1345}
1346if (!empty($arrayfields['f.type']['checked'])) {
1347 print_liste_field_titre($arrayfields['f.type']['label'], $_SERVER["PHP_SELF"], 'f.type', '', $param, '', $sortfield, $sortorder);
1348 $totalarray['nbfield']++;
1349}
1350if (!empty($arrayfields['f.subtype']['checked'])) {
1351 print_liste_field_titre($arrayfields['f.subtype']['label'], $_SERVER["PHP_SELF"], 'f.subtype', '', $param, '', $sortfield, $sortorder);
1352}
1353if (!empty($arrayfields['f.label']['checked'])) {
1354 print_liste_field_titre($arrayfields['f.label']['label'], $_SERVER['PHP_SELF'], "f.libelle,f.rowid", '', $param, '', $sortfield, $sortorder);
1355 $totalarray['nbfield']++;
1356}
1357if (!empty($arrayfields['f.datef']['checked'])) {
1358 print_liste_field_titre($arrayfields['f.datef']['label'], $_SERVER['PHP_SELF'], 'f.datef,f.rowid', '', $param, '', $sortfield, $sortorder, 'center ');
1359 $totalarray['nbfield']++;
1360}
1361if (!empty($arrayfields['f.date_lim_reglement']['checked'])) {
1362 print_liste_field_titre($arrayfields['f.date_lim_reglement']['label'], $_SERVER['PHP_SELF'], "f.date_lim_reglement", '', $param, '', $sortfield, $sortorder, 'center ');
1363 $totalarray['nbfield']++;
1364}
1365if (!empty($arrayfields['p.ref']['checked'])) {
1366 print_liste_field_titre($arrayfields['p.ref']['label'], $_SERVER['PHP_SELF'], "p.ref", '', $param, '', $sortfield, $sortorder);
1367 $totalarray['nbfield']++;
1368}
1369if (!empty($arrayfields['s.nom']['checked'])) {
1370 print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER['PHP_SELF'], 's.nom', '', $param, '', $sortfield, $sortorder);
1371 $totalarray['nbfield']++;
1372}
1373if (!empty($arrayfields['s.name_alias']['checked'])) {
1374 print_liste_field_titre($arrayfields['s.name_alias']['label'], $_SERVER['PHP_SELF'], 's.name_alias', '', $param, '', $sortfield, $sortorder);
1375 $totalarray['nbfield']++;
1376}
1377if (!empty($arrayfields['s.town']['checked'])) {
1378 print_liste_field_titre($arrayfields['s.town']['label'], $_SERVER["PHP_SELF"], 's.town', '', $param, '', $sortfield, $sortorder);
1379 $totalarray['nbfield']++;
1380}
1381if (!empty($arrayfields['s.zip']['checked'])) {
1382 print_liste_field_titre($arrayfields['s.zip']['label'], $_SERVER["PHP_SELF"], 's.zip', '', $param, '', $sortfield, $sortorder);
1383 $totalarray['nbfield']++;
1384}
1385if (!empty($arrayfields['state.nom']['checked'])) {
1386 print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.name_alias", "", $param, '', $sortfield, $sortorder);
1387 $totalarray['nbfield']++;
1388}
1389if (!empty($arrayfields['state.name_alias']['checked'])) {
1390 print_liste_field_titre($arrayfields['state.name_alias']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder);
1391 $totalarray['nbfield']++;
1392}
1393if (!empty($arrayfields['country.code_iso']['checked'])) {
1394 print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, '', $sortfield, $sortorder, 'center ');
1395 $totalarray['nbfield']++;
1396}
1397if (!empty($arrayfields['typent.code']['checked'])) {
1398 print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, '', $sortfield, $sortorder, 'center ');
1399 $totalarray['nbfield']++;
1400}
1401if (!empty($arrayfields['f.fk_cond_reglement']['checked'])) {
1402 print_liste_field_titre($arrayfields['f.fk_cond_reglement']['label'], $_SERVER["PHP_SELF"], "f.fk_cond_reglement", "", $param, "", $sortfield, $sortorder);
1403 $totalarray['nbfield']++;
1404}
1405if (!empty($arrayfields['f.fk_mode_reglement']['checked'])) {
1406 print_liste_field_titre($arrayfields['f.fk_mode_reglement']['label'], $_SERVER["PHP_SELF"], "f.fk_mode_reglement", "", $param, "", $sortfield, $sortorder);
1407 $totalarray['nbfield']++;
1408}
1409if (!empty($arrayfields['f.total_ht']['checked'])) {
1410 print_liste_field_titre($arrayfields['f.total_ht']['label'], $_SERVER['PHP_SELF'], 'f.total_ht', '', $param, '', $sortfield, $sortorder, 'right ');
1411 $totalarray['nbfield']++;
1412}
1413if (!empty($arrayfields['f.total_vat']['checked'])) {
1414 print_liste_field_titre($arrayfields['f.total_vat']['label'], $_SERVER['PHP_SELF'], 'f.total_tva', '', $param, '', $sortfield, $sortorder, 'right ');
1415 $totalarray['nbfield']++;
1416}
1417if (!empty($arrayfields['f.total_localtax1']['checked'])) {
1418 print_liste_field_titre($arrayfields['f.total_localtax1']['label'], $_SERVER['PHP_SELF'], 'f.localtax1', '', $param, '', $sortfield, $sortorder, 'right ');
1419 $totalarray['nbfield']++;
1420}
1421if (!empty($arrayfields['f.total_localtax2']['checked'])) {
1422 print_liste_field_titre($arrayfields['f.total_localtax2']['label'], $_SERVER['PHP_SELF'], 'f.localtax2', '', $param, '', $sortfield, $sortorder, 'right ');
1423 $totalarray['nbfield']++;
1424}
1425if (!empty($arrayfields['f.total_ttc']['checked'])) {
1426 print_liste_field_titre($arrayfields['f.total_ttc']['label'], $_SERVER['PHP_SELF'], 'f.total_ttc', '', $param, '', $sortfield, $sortorder, 'right ');
1427 $totalarray['nbfield']++;
1428}
1429if (!empty($arrayfields['f.nb_docs']['checked'])) {
1430 print_liste_field_titre($arrayfields['f.nb_docs']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'right ');
1431 $totalarray['nbfield']++;
1432}
1433if (!empty($arrayfields['u.login']['checked'])) {
1434 print_liste_field_titre($arrayfields['u.login']['label'], $_SERVER["PHP_SELF"], 'u.login', '', $param, '', $sortfield, $sortorder);
1435 $totalarray['nbfield']++;
1436}
1437if (!empty($arrayfields['dynamount_payed']['checked'])) {
1438 print_liste_field_titre($arrayfields['dynamount_payed']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'right ');
1439 $totalarray['nbfield']++;
1440}
1441if (!empty($arrayfields['rtp']['checked'])) {
1442 print_liste_field_titre($arrayfields['rtp']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder);
1443 $totalarray['nbfield']++;
1444}
1445if (!empty($arrayfields['f.multicurrency_code']['checked'])) {
1446 print_liste_field_titre($arrayfields['f.multicurrency_code']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_code', '', $param, '', $sortfield, $sortorder);
1447 $totalarray['nbfield']++;
1448}
1449if (!empty($arrayfields['f.multicurrency_tx']['checked'])) {
1450 print_liste_field_titre($arrayfields['f.multicurrency_tx']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_tx', '', $param, '', $sortfield, $sortorder);
1451 $totalarray['nbfield']++;
1452}
1453if (!empty($arrayfields['f.multicurrency_total_ht']['checked'])) {
1454 print_liste_field_titre($arrayfields['f.multicurrency_total_ht']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_total_ht', '', $param, '"', $sortfield, $sortorder, 'right ');
1455 $totalarray['nbfield']++;
1456}
1457if (!empty($arrayfields['f.multicurrency_total_vat']['checked'])) {
1458 print_liste_field_titre($arrayfields['f.multicurrency_total_vat']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_total_tva', '', $param, '', $sortfield, $sortorder, 'right ');
1459 $totalarray['nbfield']++;
1460}
1461if (!empty($arrayfields['f.multicurrency_total_ttc']['checked'])) {
1462 print_liste_field_titre($arrayfields['f.multicurrency_total_ttc']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_total_ttc', '', $param, '', $sortfield, $sortorder, 'right ');
1463 $totalarray['nbfield']++;
1464}
1465if (!empty($arrayfields['multicurrency_dynamount_payed']['checked'])) {
1466 print_liste_field_titre($arrayfields['multicurrency_dynamount_payed']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'right ');
1467 $totalarray['nbfield']++;
1468}
1469if (!empty($arrayfields['multicurrency_rtp']['checked'])) {
1470 print_liste_field_titre($arrayfields['multicurrency_rtp']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'right ');
1471 $totalarray['nbfield']++;
1472}
1473// Extra fields
1474include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
1475// Hook fields
1476$parameters = array('arrayfields' => $arrayfields, 'param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder, 'totalarray' => &$totalarray);
1477$reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1478print $hookmanager->resPrint;
1479if (!empty($arrayfields['f.datec']['checked'])) {
1480 print_liste_field_titre($arrayfields['f.datec']['label'], $_SERVER["PHP_SELF"], "f.datec", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
1481 $totalarray['nbfield']++;
1482}
1483if (!empty($arrayfields['f.tms']['checked'])) {
1484 print_liste_field_titre($arrayfields['f.tms']['label'], $_SERVER["PHP_SELF"], "f.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
1485 $totalarray['nbfield']++;
1486}
1487if (!empty($arrayfields['f.fk_statut']['checked'])) {
1488 print_liste_field_titre($arrayfields['f.fk_statut']['label'], $_SERVER["PHP_SELF"], "fk_statut,paye,type", "", $param, '', $sortfield, $sortorder, 'center ');
1489 $totalarray['nbfield']++;
1490}
1491// Action column
1492if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1493 print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
1494 $totalarray['nbfield']++;
1495}
1496print '</tr>'."\n";
1497
1498$facturestatic = new FactureFournisseur($db);
1499$supplierstatic = new Fournisseur($db);
1500$projectstatic = new Project($db);
1501$userstatic = new User($db);
1502$discount = new DiscountAbsolute($db);
1503
1504// Loop on record
1505// --------------------------------------------------------------------
1506$i = 0;
1507$savnbfield = $totalarray['nbfield'];
1508$totalarray = array();
1509$totalarray['nbfield'] = 0;
1510$totalarray['val'] = array();
1511$totalarray['val']['f.total_ht'] = 0;
1512$totalarray['val']['f.total_vat'] = 0;
1513$totalarray['val']['f.total_localtax1'] = 0;
1514$totalarray['val']['f.total_localtax1'] = 0;
1515$totalarray['val']['f.total_ttc'] = 0;
1516$totalarray['val']['totalam']=0;
1517$totalarray['val']['rtp']=0;
1518
1519$imaxinloop = ($limit ? min($num, $limit) : $num);
1520while ($i < $imaxinloop) {
1521 $obj = $db->fetch_object($resql);
1522 if (empty($obj)) {
1523 break; // Should not happen
1524 }
1525
1526 $datelimit = $db->jdate($obj->datelimite);
1527
1528 $userstatic->id = $obj->fk_user_author;
1529 $userstatic->login = $obj->login;
1530 $userstatic->lastname = $obj->lastname;
1531 $userstatic->firstname = $obj->firstname;
1532 $userstatic->email = $obj->user_email;
1533 $userstatic->statut = $obj->user_statut;
1534 $userstatic->status = $obj->user_statut;
1535 $userstatic->entity = $obj->entity;
1536 $userstatic->photo = $obj->photo;
1537 $userstatic->office_phone = $obj->office_phone;
1538 $userstatic->office_fax = $obj->office_fax;
1539 $userstatic->user_mobile = $obj->user_mobile;
1540 $userstatic->job = $obj->job;
1541 $userstatic->gender = $obj->gender;
1542 $facturestatic->id = $obj->facid;
1543 $facturestatic->ref = $obj->ref;
1544 $facturestatic->type = $obj->type;
1545 $facturestatic->subtype = $obj->subtype;
1546 $facturestatic->total_ht = $obj->total_ht;
1547 $facturestatic->total_tva = $obj->total_vat;
1548 $facturestatic->total_ttc = $obj->total_ttc;
1549 $facturestatic->close_code = $obj->close_code;
1550 $facturestatic->ref_supplier = $obj->ref_supplier;
1551 $facturestatic->date_echeance = $db->jdate($obj->datelimite);
1552 $facturestatic->statut = $obj->fk_statut;
1553 $facturestatic->status = $obj->fk_statut;
1554 $facturestatic->note_public = $obj->note_public;
1555 $facturestatic->note_private = $obj->note_private;
1556 $facturestatic->multicurrency_code = $obj->multicurrency_code;
1557 $facturestatic->multicurrency_tx = $obj->multicurrency_tx;
1558 $facturestatic->multicurrency_total_ht = $obj->multicurrency_total_ht;
1559 $facturestatic->multicurrency_total_tva = $obj->multicurrency_total_vat;
1560 $facturestatic->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
1561 $thirdparty->id = $obj->socid;
1562 $thirdparty->name = $obj->name;
1563 $thirdparty->name_alias = $obj->alias;
1564 $thirdparty->client = $obj->client;
1565 $thirdparty->fournisseur = $obj->fournisseur;
1566 $thirdparty->code_client = $obj->code_client;
1567 $thirdparty->code_compta_client = $obj->code_compta_client;
1568 $thirdparty->code_fournisseur = $obj->code_fournisseur;
1569 $thirdparty->code_compta_fournisseur = $obj->code_compta_fournisseur;
1570 $thirdparty->email = $obj->email;
1571 $thirdparty->country_code = $obj->country_code;
1572
1573 $paiement = $facturestatic->getSommePaiement();
1574 $totalcreditnotes = $facturestatic->getSumCreditNotesUsed();
1575 $totaldeposits = $facturestatic->getSumDepositsUsed();
1576 $totalpay = $paiement + $totalcreditnotes + $totaldeposits;
1577 $remaintopay = $obj->total_ttc - $totalpay;
1578
1579 $multicurrency_paiement = $facturestatic->getSommePaiement(1);
1580 $multicurrency_totalcreditnotes = $facturestatic->getSumCreditNotesUsed(1);
1581 $multicurrency_totaldeposits = $facturestatic->getSumDepositsUsed(1);
1582
1583 $totalpay = $paiement + $totalcreditnotes + $totaldeposits;
1584 $remaintopay = price2num($facturestatic->total_ttc - $totalpay);
1585
1586 $multicurrency_totalpay = $multicurrency_paiement + $multicurrency_totalcreditnotes + $multicurrency_totaldeposits;
1587 $multicurrency_remaintopay = price2num($facturestatic->multicurrency_total_ttc - $multicurrency_totalpay);
1588
1589 if ($facturestatic->status == FactureFournisseur::STATUS_CLOSED && $facturestatic->close_code == 'discount_vat') { // If invoice closed with discount for anticipated payment
1590 $remaintopay = 0;
1591 $multicurrency_remaintopay = 0;
1592 }
1593 if ($facturestatic->type == FactureFournisseur::TYPE_CREDIT_NOTE && $obj->paye == 1) { // If credit note closed, we take into account the amount not yet consumed
1594 $remaincreditnote = $discount->getAvailableDiscounts($thirdparty, '', 'rc.fk_facture_source='.$facturestatic->id);
1595 $remaintopay = -$remaincreditnote;
1596 $totalpay = price2num($facturestatic->total_ttc - $remaintopay);
1597 $multicurrency_remaincreditnote = $discount->getAvailableDiscounts($thirdparty, '', 'rc.fk_facture_source='.$facturestatic->id, 0, 0, 1);
1598 $multicurrency_remaintopay = -$multicurrency_remaincreditnote;
1599 $multicurrency_totalpay = price2num($facturestatic->multicurrency_total_ttc - $multicurrency_remaintopay);
1600 }
1601
1602 $facturestatic->alreadypaid = ($paiement ? $paiement : 0);
1603
1604 $facturestatic->paye = $obj->paye;
1605 $facturestatic->paid = $obj->paye;
1606
1607 $facturestatic->date = $db->jdate($obj->datef);
1608
1609 $object = $facturestatic;
1610
1611 //If invoice has been converted and the conversion has been used, we don't have remain to pay on invoice
1612 if ($facturestatic->type == FactureFournisseur::TYPE_CREDIT_NOTE) {
1613 if ($facturestatic->isCreditNoteUsed()) {
1614 $remaintopay = -$facturestatic->getSumFromThisCreditNotesNotUsed();
1615 }
1616 }
1617
1618 if ($mode == 'kanban') {
1619 if ($i == 0) {
1620 print '<tr class="trkanban"><td colspan="'.$savnbfield.'">';
1621 print '<div class="box-flex-container kanban">';
1622 }
1623 // Output Kanban
1624 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
1625 $selected = 0;
1626 if (in_array($object->id, $arrayofselected)) {
1627 $selected = 1;
1628 }
1629 }
1630
1631 $arraydata = array('alreadypaid' => $paiement, 'thirdparty' => $thirdparty->getNomUrl(1, '', 12), 'selected' => in_array($object->id, $arrayofselected));
1632 print $facturestatic->getKanbanView('', $arraydata);
1633 if ($i == ($imaxinloop - 1)) {
1634 print '</div>';
1635 print '</td></tr>';
1636 }
1637 } else {
1638 // Show line of result
1639 $j = 0;
1640 print '<tr data-rowid="'.$object->id.'" class="oddeven">';
1641
1642 // Action column
1643 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1644 print '<td class="nowrap center">';
1645 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
1646 $selected = 0;
1647 if (in_array($obj->facid, $arrayofselected)) {
1648 $selected = 1;
1649 }
1650 print '<input id="cb'.$obj->facid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->facid.'"'.($selected ? ' checked="checked"' : '').'>';
1651 }
1652 print '</td>';
1653 if (!$i) {
1654 $totalarray['nbfield']++;
1655 }
1656 }
1657 if (!empty($arrayfields['f.ref']['checked'])) {
1658 print '<td class="nowraponall">';
1659
1660 print '<table class="nobordernopadding"><tr class="nocellnopadd">';
1661 // Picto + Ref
1662 print '<td class="nobordernopadding nowraponall">';
1663 print $facturestatic->getNomUrl(1, '', 0, 0, '', 0, -1, 1);
1664
1665 $filename = dol_sanitizeFileName($obj->ref);
1666 $filedir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($obj->facid, 2, 0, 0, $facturestatic, 'invoice_supplier').dol_sanitizeFileName($obj->ref);
1667 $subdir = get_exdir($obj->facid, 2, 0, 0, $facturestatic, 'invoice_supplier').dol_sanitizeFileName($obj->ref);
1668 print $formfile->getDocumentsLink('facture_fournisseur', $subdir, $filedir);
1669 print '</td></tr></table>';
1670
1671 print "</td>\n";
1672 if (!$i) {
1673 $totalarray['nbfield']++;
1674 }
1675 }
1676
1677 // Supplier ref
1678 if (!empty($arrayfields['f.ref_supplier']['checked'])) {
1679 print '<td class="nowrap tdoverflowmax150" title="'.dol_escape_htmltag($obj->ref_supplier).'">';
1680 print $obj->ref_supplier;
1681 print '</td>';
1682 if (!$i) {
1683 $totalarray['nbfield']++;
1684 }
1685 }
1686
1687 // Type
1688 if (!empty($arrayfields['f.type']['checked'])) {
1689 print '<td class="nowrap">';
1690 print $facturestatic->getLibType();
1691 print "</td>";
1692 if (!$i) {
1693 $totalarray['nbfield']++;
1694 }
1695 }
1696
1697 // Invoice Subtype
1698 if (!empty($arrayfields['f.subtype']['checked'])) {
1699 $labeltoshow = '';
1700 if ($facturestatic->subtype > 0) {
1701 $labeltoshow = $facturestatic->getSubtypeLabel('facture_fourn');
1702 }
1703 print '<td class="nowraponall tdoverflowmax300" title="'.$labeltoshow.'">';
1704 print $labeltoshow;
1705 print "</td>";
1706 if (!$i) {
1707 $totalarray['nbfield']++;
1708 }
1709 }
1710
1711 // Label
1712 if (!empty($arrayfields['f.label']['checked'])) {
1713 print '<td class="nowrap tdoverflowmax125" title="'.dol_escape_htmltag($obj->label).'">';
1714 print dol_escape_htmltag($obj->label);
1715 print '</td>';
1716 if (!$i) {
1717 $totalarray['nbfield']++;
1718 }
1719 }
1720
1721 // Date
1722 if (!empty($arrayfields['f.datef']['checked'])) {
1723 print '<td class="center nowrap">';
1724 print dol_print_date($db->jdate($obj->datef), 'day');
1725 print '</td>';
1726 if (!$i) {
1727 $totalarray['nbfield']++;
1728 }
1729 }
1730
1731 // Date limit
1732 if (!empty($arrayfields['f.date_lim_reglement']['checked'])) {
1733 print '<td class="center nowraponall">'.dol_print_date($datelimit, 'day');
1734 if ($facturestatic->hasDelay()) {
1735 print img_warning($langs->trans('Alert').' - '.$langs->trans('Late'));
1736 }
1737 print '</td>';
1738 if (!$i) {
1739 $totalarray['nbfield']++;
1740 }
1741 }
1742
1743 // Project
1744 if (!empty($arrayfields['p.ref']['checked'])) {
1745 print '<td class="nowrap">';
1746 if ($obj->project_id > 0) {
1747 $projectstatic->id = $obj->project_id;
1748 $projectstatic->ref = $obj->project_ref;
1749 $projectstatic->title = $obj->project_label;
1750 print $projectstatic->getNomUrl(1);
1751 }
1752 print '</td>';
1753 if (!$i) {
1754 $totalarray['nbfield']++;
1755 }
1756 }
1757
1758 // Third party
1759 if (!empty($arrayfields['s.nom']['checked'])) {
1760 print '<td class="tdoverflowmax125">';
1761 print $thirdparty->getNomUrl(1, 'supplier', 0, 0, -1, empty($arrayfields['s.name_alias']['checked']) ? 0 : 1);
1762 print '</td>';
1763 if (!$i) {
1764 $totalarray['nbfield']++;
1765 }
1766 }
1767 // Alias
1768 if (!empty($arrayfields['s.name_alias']['checked'])) {
1769 print '<td class="tdoverflowmax150">';
1770 print dol_escape_htmltag($thirdparty->name_alias);
1771 print '</td>';
1772 if (!$i) {
1773 $totalarray['nbfield']++;
1774 }
1775 }
1776 // Town
1777 if (!empty($arrayfields['s.town']['checked'])) {
1778 print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->town).'">';
1779 print dol_escape_htmltag($obj->town);
1780 print '</td>';
1781 if (!$i) {
1782 $totalarray['nbfield']++;
1783 }
1784 }
1785 // Zip
1786 if (!empty($arrayfields['s.zip']['checked'])) {
1787 print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->zip).'">';
1788 print dol_escape_htmltag($obj->zip);
1789 print '</td>';
1790 if (!$i) {
1791 $totalarray['nbfield']++;
1792 }
1793 }
1794 // State
1795 if (!empty($arrayfields['state.nom']['checked'])) {
1796 print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->state_name).'">';
1797 print dol_escape_htmltag($obj->state_name);
1798 print "</td>\n";
1799 if (!$i) {
1800 $totalarray['nbfield']++;
1801 }
1802 }
1803 // Country
1804 if (!empty($arrayfields['country.code_iso']['checked'])) {
1805 print '<td class="center">';
1806 $tmparray = getCountry($obj->fk_pays, 'all');
1807 print $tmparray['label'];
1808 print '</td>';
1809 if (!$i) {
1810 $totalarray['nbfield']++;
1811 }
1812 }
1813 // Type ent
1814 if (!empty($arrayfields['typent.code']['checked'])) {
1815 print '<td class="center">';
1816 if (empty($typenArray)) {
1817 $typenArray = $formcompany->typent_array(1);
1818 }
1819 print $typenArray[$obj->typent_code];
1820 print '</td>';
1821 if (!$i) {
1822 $totalarray['nbfield']++;
1823 }
1824 }
1825
1826 // Payment condition
1827 if (!empty($arrayfields['f.fk_cond_reglement']['checked'])) {
1828 $s = $form->form_conditions_reglement($_SERVER['PHP_SELF'], $obj->fk_cond_reglement, 'none', 1, '', -1, -1, 1);
1829 print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($s).'">';
1830 print dol_escape_htmltag($s);
1831 print '</td>';
1832 if (!$i) {
1833 $totalarray['nbfield']++;
1834 }
1835 }
1836 // Payment mode
1837 if (!empty($arrayfields['f.fk_mode_reglement']['checked'])) {
1838 $s = $form->form_modes_reglement($_SERVER['PHP_SELF'], $obj->fk_mode_reglement, 'none', '', -1, 0, '', 1);
1839 print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($s).'">';
1840 print dol_escape_htmltag($s);
1841 print '</td>';
1842 if (!$i) {
1843 $totalarray['nbfield']++;
1844 }
1845 }
1846
1847 // Amount HT
1848 if (!empty($arrayfields['f.total_ht']['checked'])) {
1849 print '<td class="right nowrap"><span class="amount">'.price($obj->total_ht)."</span></td>\n";
1850 if (!$i) {
1851 $totalarray['nbfield']++;
1852 $totalarray['pos'][$totalarray['nbfield']] = 'f.total_ht';
1853 }
1854 $totalarray['val']['f.total_ht'] += $obj->total_ht;
1855 }
1856 // Amount VAT
1857 if (!empty($arrayfields['f.total_vat']['checked'])) {
1858 print '<td class="right nowrap"><span class="amount">'.price($obj->total_vat)."</span></td>\n";
1859 if (!$i) {
1860 $totalarray['nbfield']++;
1861 $totalarray['pos'][$totalarray['nbfield']] = 'f.total_vat';
1862 }
1863 $totalarray['val']['f.total_vat'] += $obj->total_vat;
1864 }
1865 // Amount LocalTax1
1866 if (!empty($arrayfields['f.total_localtax1']['checked'])) {
1867 print '<td class="right nowrap"><span class="amount">'.price($obj->total_localtax1)."</span></td>\n";
1868 if (!$i) {
1869 $totalarray['nbfield']++;
1870 $totalarray['pos'][$totalarray['nbfield']] = 'f.total_localtax1';
1871 }
1872 $totalarray['val']['f.total_localtax1'] += $obj->total_localtax1;
1873 }
1874 // Amount LocalTax2
1875 if (!empty($arrayfields['f.total_localtax2']['checked'])) {
1876 print '<td class="right nowrap"><span class="amount">'.price($obj->total_localtax2)."</span></td>\n";
1877 if (!$i) {
1878 $totalarray['nbfield']++;
1879 $totalarray['pos'][$totalarray['nbfield']] = 'f.total_localtax2';
1880 }
1881 $totalarray['val']['f.total_localtax2'] += $obj->total_localtax2;
1882 }
1883 // Amount TTC
1884 if (!empty($arrayfields['f.total_ttc']['checked'])) {
1885 print '<td class="right nowrap"><span class="amount">'.price($obj->total_ttc)."</span></td>\n";
1886 if (!$i) {
1887 $totalarray['nbfield']++;
1888 $totalarray['pos'][$totalarray['nbfield']] = 'f.total_ttc';
1889 }
1890 $totalarray['val']['f.total_ttc'] += $obj->total_ttc;
1891 }
1892
1893 // Number of attached documents (may slow your application on large lists)
1894 if (!empty($arrayfields['f.nb_docs']['checked'])) {
1895 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
1896 require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
1897 $upload_dir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($facturestatic->id, 2, 0, 0, $facturestatic, 'invoice_supplier').$facturestatic->ref;
1898 $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
1899 $nbLinks = Link::count($db, $facturestatic->element, $facturestatic->id);
1900 $nbTotal = $nbFiles + $nbLinks;
1901 echo '<td class="center">'.(empty($nbTotal) ? '' : $nbTotal).'</td>';
1902 if (!$i) {
1903 $totalarray['nbfield']++;
1904 }
1905 }
1906
1907 // Author
1908 if (!empty($arrayfields['u.login']['checked'])) {
1909 print '<td class="tdoverflowmax100">';
1910 if ($userstatic->id) {
1911 print $userstatic->getNomUrl(-1);
1912 } else {
1913 print '&nbsp;';
1914 }
1915 print "</td>\n";
1916 if (!$i) {
1917 $totalarray['nbfield']++;
1918 }
1919 }
1920
1921 // Dynamic amount paid
1922 if (!empty($arrayfields['dynamount_payed']['checked'])) {
1923 print '<td class="right nowrap"><span class="amount">'.(!empty($totalpay) ? price($totalpay, 0, $langs) : '').'</span></td>'; // TODO Use a denormalized field
1924 if (!$i) {
1925 $totalarray['nbfield']++;
1926 $totalarray['pos'][$totalarray['nbfield']] = 'totalam';
1927 }
1928 if (empty($totalarray['val']['totalam'])) {
1929 $totalarray['val']['totalam'] = 0; // avoid PHP Warning: Undefined array key "totalam" on line 1891
1930 }
1931 $totalarray['val']['totalam'] += $totalpay;
1932 }
1933
1934 // Remain to pay
1935 if (!empty($arrayfields['rtp']['checked'])) {
1936 print '<td class="right nowrap">'.(!empty($remaintopay) ? price($remaintopay, 0, $langs) : '&nbsp;').'</td>'; // TODO Use a denormalized field
1937 if (!$i) {
1938 $totalarray['nbfield']++;
1939 $totalarray['pos'][$totalarray['nbfield']] = 'rtp';
1940 }
1941 $totalarray['val']['rtp'] += $remaintopay;
1942 }
1943
1944 // Currency
1945 if (!empty($arrayfields['f.multicurrency_code']['checked'])) {
1946 print '<td class="nowrap">'.$obj->multicurrency_code.' - '.$langs->trans('Currency'.$obj->multicurrency_code)."</td>\n";
1947 if (!$i) {
1948 $totalarray['nbfield']++;
1949 }
1950 }
1951
1952 // Currency rate
1953 if (!empty($arrayfields['f.multicurrency_tx']['checked'])) {
1954 print '<td class="nowrap">';
1955 $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$obj->rowid, $obj->multicurrency_tx, 'none', $obj->multicurrency_code);
1956 print "</td>\n";
1957 if (!$i) {
1958 $totalarray['nbfield']++;
1959 }
1960 }
1961 // Amount HT
1962 if (!empty($arrayfields['f.multicurrency_total_ht']['checked'])) {
1963 print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_ht)."</span></td>\n";
1964 if (!$i) {
1965 $totalarray['nbfield']++;
1966 }
1967 }
1968 // Amount VAT
1969 if (!empty($arrayfields['f.multicurrency_total_vat']['checked'])) {
1970 print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_vat)."</span></td>\n";
1971 if (!$i) {
1972 $totalarray['nbfield']++;
1973 }
1974 }
1975 // Amount TTC
1976 if (!empty($arrayfields['f.multicurrency_total_ttc']['checked'])) {
1977 print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_ttc)."</span></td>\n";
1978 if (!$i) {
1979 $totalarray['nbfield']++;
1980 }
1981 }
1982 // Dynamic amount paid
1983 if (!empty($arrayfields['multicurrency_dynamount_payed']['checked'])) {
1984 print '<td class="right nowrap"><span class="amount">'.(!empty($multicurrency_totalpay) ? price($multicurrency_totalpay, 0, $langs) : '').'</span></td>'; // TODO Use a denormalized field
1985 if (!$i) {
1986 $totalarray['nbfield']++;
1987 }
1988 }
1989
1990 // Pending amount
1991 if (!empty($arrayfields['multicurrency_rtp']['checked'])) {
1992 print '<td class="right nowrap"><span class="amount">';
1993 print(!empty($multicurrency_remaintopay) ? price($multicurrency_remaintopay, 0, $langs) : '');
1994 print '</span></td>'; // TODO Use a denormalized field
1995 if (!$i) {
1996 $totalarray['nbfield']++;
1997 }
1998 }
1999
2000
2001 // Extra fields
2002 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
2003 // Fields from hook
2004 $parameters = array('arrayfields' => $arrayfields, 'object' => $object, 'obj' => $obj, 'i' => $i, 'totalarray' => &$totalarray);
2005 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
2006 print $hookmanager->resPrint;
2007
2008 // Date creation
2009 if (!empty($arrayfields['f.datec']['checked'])) {
2010 print '<td class="center nowraponall">';
2011 print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
2012 print '</td>';
2013 if (!$i) {
2014 $totalarray['nbfield']++;
2015 }
2016 }
2017 // Date modification
2018 if (!empty($arrayfields['f.tms']['checked'])) {
2019 print '<td class="center nowraponall">';
2020 print dol_print_date($db->jdate($obj->date_modification), 'dayhour', 'tzuser');
2021 print '</td>';
2022 if (!$i) {
2023 $totalarray['nbfield']++;
2024 }
2025 }
2026 // Status
2027 if (!empty($arrayfields['f.fk_statut']['checked'])) {
2028 print '<td class="center nowrap">';
2029 print $facturestatic->getLibStatut(5, $paiement);
2030 print "</td>";
2031 if (!$i) {
2032 $totalarray['nbfield']++;
2033 }
2034 }
2035
2036 // Action column
2037 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
2038 print '<td class="nowrap center">';
2039 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
2040 $selected = 0;
2041 if (in_array($obj->facid, $arrayofselected)) {
2042 $selected = 1;
2043 }
2044 print '<input id="cb'.$obj->facid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->facid.'"'.($selected ? ' checked="checked"' : '').'>';
2045 }
2046 print '</td>';
2047 if (!$i) {
2048 $totalarray['nbfield']++;
2049 }
2050 }
2051
2052 print '</tr>'."\n";
2053 }
2054
2055 $i++;
2056}
2057
2058// Show total line
2059include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
2060
2061// If no record found
2062if ($num == 0) {
2063 $colspan = 1;
2064 foreach ($arrayfields as $key => $val) {
2065 if (!empty($val['checked'])) {
2066 $colspan++;
2067 }
2068 }
2069 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
2070}
2071
2072$db->free($resql);
2073
2074$parameters = array('arrayfields' => $arrayfields, 'sql' => $sql);
2075$reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
2076print $hookmanager->resPrint;
2077
2078print '</table>'."\n";
2079print '</div>'."\n";
2080
2081print '</form>'."\n";
2082
2083if (in_array('builddoc', array_keys($arrayofmassactions)) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
2084 $hidegeneratedfilelistifempty = 1;
2085 if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
2086 $hidegeneratedfilelistifempty = 0;
2087 }
2088
2089 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
2090 $formfile = new FormFile($db);
2091
2092 // Show list of available documents
2093 $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
2094 $urlsource .= str_replace('&amp;', '&', $param);
2095
2096 $filedir = $diroutputmassaction;
2097 $genallowed = $permissiontoread;
2098 $delallowed = $permissiontoadd;
2099 $title = '';
2100
2101 print $formfile->showdocuments('massfilesarea_supplier_invoice', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
2102}
2103
2104// End of page
2105llxFooter();
2106$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.