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