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