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