dolibarr  13.0.2
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 Charlene Benke <charlie@patas-monkey.com>
14  * Copyright (C) 2018-2019 Frédéric France <frederic.france@netlogic.fr>
15  *
16  * This program is free software; you can redistribute it and/or modify
17  * it under the terms of the GNU General Public License as published by
18  * the Free Software Foundation; either version 3 of the License, or
19  * (at your option) any later version.
20  *
21  * This program is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24  * GNU General Public License for more details.
25  *
26  * You should have received a copy of the GNU General Public License
27  * along with this program. If not, see <https://www.gnu.org/licenses/>.
28  */
29 
36 require '../../main.inc.php';
37 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
38 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
39 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
40 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
41 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
42 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
43 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
44 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
45 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
46 
47 if (!$user->rights->fournisseur->facture->lire) accessforbidden();
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 
60 $socid = GETPOST('socid', 'int');
61 
62 // Security check
63 if ($user->socid > 0)
64 {
65  $action = '';
66  $_GET["action"] = '';
67  $socid = $user->socid;
68 }
69 
70 $mode = GETPOST("mode", 'aZ09');
71 
72 $search_all = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
73 $search_label = GETPOST("search_label", "alpha");
74 $search_amount_no_tax = GETPOST("search_amount_no_tax", "alpha");
75 $search_amount_all_tax = GETPOST("search_amount_all_tax", "alpha");
76 $search_product_category = GETPOST('search_product_category', 'int');
77 $search_ref = GETPOST('sf_ref') ?GETPOST('sf_ref', 'alpha') : GETPOST('search_ref', 'alpha');
78 $search_refsupplier = GETPOST('search_refsupplier', 'alpha');
79 $search_type = GETPOST('search_type', 'int');
80 $search_project = GETPOST('search_project', 'alpha');
81 $search_company = GETPOST('search_company', 'alpha');
82 $search_montant_ht = GETPOST('search_montant_ht', 'alpha');
83 $search_montant_vat = GETPOST('search_montant_vat', 'alpha');
84 $search_montant_localtax1 = GETPOST('search_montant_localtax1', 'alpha');
85 $search_montant_localtax2 = GETPOST('search_montant_localtax2', 'alpha');
86 $search_montant_ttc = GETPOST('search_montant_ttc', 'alpha');
87 $search_login = GETPOST('search_login', 'alpha');
88 $search_multicurrency_code = GETPOST('search_multicurrency_code', 'alpha');
89 $search_multicurrency_tx = GETPOST('search_multicurrency_tx', 'alpha');
90 $search_multicurrency_montant_ht = GETPOST('search_multicurrency_montant_ht', 'alpha');
91 $search_multicurrency_montant_vat = GETPOST('search_multicurrency_montant_vat', 'alpha');
92 $search_multicurrency_montant_ttc = GETPOST('search_multicurrency_montant_ttc', 'alpha');
93 $search_status = GETPOST('search_status', 'int');
94 $search_paymentmode = GETPOST('search_paymentmode', 'int');
95 $search_paymentcond = GETPOST('search_paymentcond', 'int');
96 $search_town = GETPOST('search_town', 'alpha');
97 $search_zip = GETPOST('search_zip', 'alpha');
98 $search_state = GETPOST("search_state");
99 $search_country = GETPOST("search_country", 'int');
100 $search_type_thirdparty = GETPOST("search_type_thirdparty", 'int');
101 $search_user = GETPOST('search_user', 'int');
102 $search_sale = GETPOST('search_sale', 'int');
103 $day = GETPOST('day', 'int');
104 $month = GETPOST('month', 'int');
105 $year = GETPOST('year', 'int');
106 $day_lim = GETPOST('day_lim', 'int');
107 $month_lim = GETPOST('month_lim', 'int');
108 $year_lim = GETPOST('year_lim', 'int');
109 $toselect = GETPOST('toselect', 'array');
110 $search_btn = GETPOST('button_search', 'alpha');
111 $search_remove_btn = GETPOST('button_removefilter', 'alpha');
112 $search_categ_sup = trim(GETPOST("search_categ_sup", 'int'));
113 
114 $option = GETPOST('option');
115 if ($option == 'late') {
116  $search_status = '1';
117 }
118 $filter = GETPOST('filtre', 'alpha');
119 
120 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
121 $sortfield = GETPOST("sortfield", 'alpha');
122 $sortorder = GETPOST("sortorder", 'alpha');
123 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
124 if ($page == -1 || $page == null || !empty($search_btn) || !empty($search_remove_btn) || (empty($toselect) && $massaction === '0')) { $page = 0; }
125 $offset = $limit * $page;
126 $pageprev = $page - 1;
127 $pagenext = $page + 1;
128 if (!$sortorder) $sortorder = "DESC";
129 if (!$sortfield) $sortfield = "f.datef,f.rowid";
130 
131 $diroutputmassaction = $conf->fournisseur->facture->dir_output.'/temp/massgeneration/'.$user->id;
132 
133 $now = dol_now();
134 
135 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
136 $object = new FactureFournisseur($db);
137 $hookmanager->initHooks(array('supplierinvoicelist'));
138 $extrafields = new ExtraFields($db);
139 
140 // fetch optionals attributes and labels
141 $extrafields->fetch_name_optionals_label($object->table_element);
142 
143 $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
144 
145 // List of fields to search into when doing a "search in all"
146 $fieldstosearchall = array(
147  'f.ref'=>'Ref',
148  'f.ref_supplier'=>'RefSupplier',
149  'pd.description'=>'Description',
150  's.nom'=>"ThirdParty",
151  'f.note_public'=>'NotePublic',
152 );
153 if (empty($user->socid)) $fieldstosearchall["f.note_private"] = "NotePrivate";
154 
155 $checkedtypetiers = 0;
156 $arrayfields = array(
157  'f.ref'=>array('label'=>$langs->trans("Ref"), 'checked'=>1),
158  'f.ref_supplier'=>array('label'=>$langs->trans("RefSupplier"), 'checked'=>1),
159  'f.type'=>array('label'=>$langs->trans("Type"), 'checked'=>0),
160  'f.label'=>array('label'=>$langs->trans("Label"), 'checked'=>0),
161  'f.datef'=>array('label'=>$langs->trans("DateInvoice"), 'checked'=>1),
162  'f.date_lim_reglement'=>array('label'=>$langs->trans("DateDue"), 'checked'=>1),
163  'p.ref'=>array('label'=>$langs->trans("ProjectRef"), 'checked'=>0),
164  's.nom'=>array('label'=>$langs->trans("ThirdParty"), 'checked'=>1),
165  's.town'=>array('label'=>$langs->trans("Town"), 'checked'=>1),
166  's.zip'=>array('label'=>$langs->trans("Zip"), 'checked'=>1),
167  'state.nom'=>array('label'=>$langs->trans("StateShort"), 'checked'=>0),
168  'country.code_iso'=>array('label'=>$langs->trans("Country"), 'checked'=>0),
169  'typent.code'=>array('label'=>$langs->trans("ThirdPartyType"), 'checked'=>$checkedtypetiers),
170  'f.fk_cond_reglement'=>array('label'=>$langs->trans("PaymentTerm"), 'checked'=>1, 'position'=>50),
171  'f.fk_mode_reglement'=>array('label'=>$langs->trans("PaymentMode"), 'checked'=>1, 'position'=>52),
172  'f.total_ht'=>array('label'=>$langs->trans("AmountHT"), 'checked'=>1, 'position'=>105),
173  'f.total_vat'=>array('label'=>$langs->trans("AmountVAT"), 'checked'=>0, 'position'=>110),
174  'f.total_localtax1'=>array('label'=>$langs->transcountry("AmountLT1", $mysoc->country_code), 'checked'=>0, 'enabled'=>$mysoc->localtax1_assuj == "1", 'position'=>95),
175  'f.total_localtax2'=>array('label'=>$langs->transcountry("AmountLT2", $mysoc->country_code), 'checked'=>0, 'enabled'=>$mysoc->localtax2_assuj == "1", 'position'=>100),
176  'f.total_ttc'=>array('label'=>$langs->trans("AmountTTC"), 'checked'=>0, 'position'=>115),
177  'u.login'=>array('label'=>"Author", 'checked'=>1),
178  'dynamount_payed'=>array('label'=>$langs->trans("Payed"), 'checked'=>0),
179  'rtp'=>array('label'=>$langs->trans("Rest"), 'checked'=>0),
180  'f.multicurrency_code'=>array('label'=>'Currency', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1)),
181  'f.multicurrency_tx'=>array('label'=>'CurrencyRate', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1)),
182  'f.multicurrency_total_ht'=>array('label'=>'MulticurrencyAmountHT', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1)),
183  'f.multicurrency_total_vat'=>array('label'=>'MulticurrencyAmountVAT', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1)),
184  'f.multicurrency_total_ttc'=>array('label'=>'MulticurrencyAmountTTC', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1)),
185  'multicurrency_dynamount_payed'=>array('label'=>'MulticurrencyAlreadyPaid', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1)),
186  'multicurrency_rtp'=>array('label'=>'MulticurrencyRemainderToPay', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1)), // Not enabled by default because slow
187  'f.datec'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0, 'position'=>500),
188  'f.tms'=>array('label'=>$langs->trans("DateModificationShort"), 'checked'=>0, 'position'=>500),
189  'f.fk_statut'=>array('label'=>$langs->trans("Status"), 'checked'=>1, 'position'=>1000),
190 );
191 // Extra fields
192 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
193 
194 $object->fields = dol_sort_array($object->fields, 'position');
195 $arrayfields = dol_sort_array($arrayfields, 'position');
196 
197 
198 /*
199  * Actions
200  */
201 
202 if (GETPOST('cancel', 'alpha')) { $action = 'list'; $massaction = ''; }
203 if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend' && $massaction != 'confirm_createbills') { $massaction = ''; }
204 
205 $parameters = array('socid'=>$socid);
206 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
207 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
208 
209 if (empty($reshook))
210 {
211  include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
212 
213  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
214  {
215  $search_all = "";
216  $search_user = '';
217  $search_sale = '';
218  $search_product_category = '';
219  $search_ref = "";
220  $search_refsupplier = "";
221  $search_type = "";
222  $search_label = "";
223  $search_project = '';
224  $search_company = "";
225  $search_amount_no_tax = "";
226  $search_amount_all_tax = "";
227  $search_montant_ht = '';
228  $search_montant_vat = '';
229  $search_montant_localtax1 = '';
230  $search_montant_localtax2 = '';
231  $search_montant_ttc = '';
232  $search_login = '';
233  $search_multicurrency_code = '';
234  $search_multicurrency_tx = '';
235  $search_multicurrency_montant_ht = '';
236  $search_multicurrency_montant_vat = '';
237  $search_multicurrency_montant_ttc = '';
238  $search_status = '';
239  $search_paymentmode = '';
240  $search_paymentcond = '';
241  $search_town = '';
242  $search_zip = "";
243  $search_state = "";
244  $search_type = '';
245  $search_country = '';
246  $search_type_thirdparty = '';
247  $year = "";
248  $month = "";
249  $day = "";
250  $year_lim = "";
251  $month_lim = "";
252  $day_lim = "";
253  $toselect = '';
254  $search_array_options = array();
255  $filter = '';
256  $option = '';
257  $socid = "";
258  $search_categ_sup = 0;
259  }
260 
261  // Mass actions
262  $objectclass = 'FactureFournisseur';
263  $objectlabel = 'SupplierInvoices';
264  $permissiontoread = $user->rights->fournisseur->facture->lire;
265  $permissiontoadd = $user->rights->fournisseur->facture->creer;
266  $permissiontodelete = $user->rights->fournisseur->facture->supprimer;
267  $uploaddir = $conf->fournisseur->facture->dir_output;
268  include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
269 
270  if ($massaction == 'banktransfertrequest')
271  {
272  $langs->load("withdrawals");
273 
274  if (!$user->rights->paymentbybanktransfer->create)
275  {
276  $error++;
277  setEventMessages($langs->trans("NotEnoughPermissions"), null, 'errors');
278  } else {
279  //Checking error
280  $error = 0;
281 
282  $arrayofselected = is_array($toselect) ? $toselect : array();
283  $listofbills = array();
284  foreach ($arrayofselected as $toselectid)
285  {
286  $objecttmp = new FactureFournisseur($db);
287  $result = $objecttmp->fetch($toselectid);
288  if ($result > 0)
289  {
290  $totalpaye = $objecttmp->getSommePaiement();
291  $totalcreditnotes = $objecttmp->getSumCreditNotesUsed();
292  $totaldeposits = $objecttmp->getSumDepositsUsed();
293  $objecttmp->resteapayer = price2num($objecttmp->total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits, 'MT');
294  if ($objecttmp->paye || $objecttmp->resteapayer == 0) {
295  $error++;
296  setEventMessages($objecttmp->ref.' '.$langs->trans("AlreadyPaid"), $objecttmp->errors, 'errors');
297  } elseif ($objecttmp->resteapayer < 0) {
298  $error++;
299  setEventMessages($objecttmp->ref.' '.$langs->trans("AmountMustBePositive"), $objecttmp->errors, 'errors');
300  }
301  if (!($objecttmp->statut > FactureFournisseur::STATUS_DRAFT)) {
302  $error++;
303  setEventMessages($objecttmp->ref.' '.$langs->trans("Draft"), $objecttmp->errors, 'errors');
304  }
305 
306  $rsql = "SELECT pfd.rowid, pfd.traite, pfd.date_demande as date_demande";
307  $rsql .= " , pfd.date_traite as date_traite";
308  $rsql .= " , pfd.amount";
309  $rsql .= " , u.rowid as user_id, u.lastname, u.firstname, u.login";
310  $rsql .= " FROM ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd";
311  $rsql .= " , ".MAIN_DB_PREFIX."user as u";
312  $rsql .= " WHERE fk_facture_fourn = ".$objecttmp->id;
313  $rsql .= " AND pfd.fk_user_demande = u.rowid";
314  $rsql .= " AND pfd.traite = 0";
315  $rsql .= " ORDER BY pfd.date_demande DESC";
316 
317  $result_sql = $db->query($rsql);
318  if ($result_sql)
319  {
320  $numprlv = $db->num_rows($result_sql);
321  }
322 
323  if ($numprlv > 0) {
324  $error++;
325  setEventMessages($objecttmp->ref.' '.$langs->trans("RequestAlreadyDone"), $objecttmp->errors, 'warnings');
326  } elseif (!empty($objecttmp->mode_reglement_code) && $objecttmp->mode_reglement_code != 'PRE') {
327  $error++;
328  setEventMessages($objecttmp->ref.' '.$langs->trans("BadPaymentMethod"), $objecttmp->errors, 'errors');
329  } else {
330  $listofbills[] = $objecttmp; // $listofbills will only contains invoices with good payment method and no request already done
331  }
332  }
333  }
334 
335  //Massive withdraw request for request with no errors
336  if (!empty($listofbills))
337  {
338  $nbwithdrawrequestok = 0;
339  foreach ($listofbills as $aBill)
340  {
341  $db->begin();
342  $result = $aBill->demande_prelevement($user, $aBill->resteapayer, 'bank-transfer', 'supplier_invoice');
343  if ($result > 0)
344  {
345  $db->commit();
346  $nbwithdrawrequestok++;
347  } else {
348  $db->rollback();
349  setEventMessages($aBill->error, $aBill->errors, 'errors');
350  }
351  }
352  if ($nbwithdrawrequestok > 0)
353  {
354  setEventMessages($langs->trans("WithdrawRequestsDone", $nbwithdrawrequestok), null, 'mesgs');
355  }
356  }
357  }
358  }
359 }
360 
361 
362 /*
363  * View
364  */
365 
366 $form = new Form($db);
367 $formother = new FormOther($db);
368 $formfile = new FormFile($db);
369 $bankaccountstatic = new Account($db);
370 $facturestatic = new FactureFournisseur($db);
371 $formcompany = new FormCompany($db);
372 $thirdparty = new Societe($db);
373 
374 // llxHeader('',$langs->trans("SuppliersInvoices"),'EN:Suppliers_Invoices|FR:FactureFournisseur|ES:Facturas_de_proveedores');
375 
376 $sql = "SELECT";
377 if ($search_all || $search_product_category > 0) $sql = 'SELECT DISTINCT';
378 $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,";
379 $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,";
380 $sql .= " f.localtax1 as total_localtax1, f.localtax2 as total_localtax2,";
381 $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,';
382 $sql .= " f.note_public, f.note_private,";
383 $sql .= " f.fk_user_author,";
384 $sql .= " s.rowid as socid, s.nom as name, 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,";
385 $sql .= " typent.code as typent_code,";
386 $sql .= " state.code_departement as state_code, state.nom as state_name,";
387 $sql .= " country.code as country_code,";
388 $sql .= " p.rowid as project_id, p.ref as project_ref, p.title as project_label,";
389 $sql .= " u.login";
390 // 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)
391 // TODO Better solution to be able to sort on already payed or remain to pay is to store amount_payed in a denormalized field.
392 if (!$search_all) $sql .= ', SUM(pf.amount) as dynamount_payed';
393 if ($search_categ_sup) $sql .= ", cs.fk_categorie, cs.fk_soc";
394 // Add fields from extrafields
395 if (!empty($extrafields->attributes[$object->table_element]['label'])) {
396  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key.' as options_'.$key : '');
397 }
398 // Add fields from hooks
399 $parameters = array();
400 $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
401 $sql .= $hookmanager->resPrint;
402 $sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s';
403 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
404 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
405 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)";
406 if (!empty($search_categ_sup)) $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_fournisseur as cs ON s.rowid = cs.fk_soc";
407 
408 $sql .= ', '.MAIN_DB_PREFIX.'facture_fourn as f';
409 if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (f.rowid = ef.fk_object)";
410 if (!$search_all) $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf ON pf.fk_facturefourn = f.rowid';
411 if ($search_all || $search_product_category > 0) $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture_fourn_det as pd ON f.rowid=pd.fk_facture_fourn';
412 if ($search_product_category > 0) $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=pd.fk_product';
413 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user AS u ON f.fk_user_author = u.rowid';
414 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as p ON p.rowid = f.fk_projet";
415 // We'll need this table joined to the select in order to filter by sale
416 if ($search_sale > 0 || (!$user->rights->societe->client->voir && !$socid)) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
417 if ($search_user > 0)
418 {
419  $sql .= ", ".MAIN_DB_PREFIX."element_contact as ec";
420  $sql .= ", ".MAIN_DB_PREFIX."c_type_contact as tc";
421 }
422 $sql .= ' WHERE f.fk_soc = s.rowid';
423 $sql .= ' AND f.entity IN ('.getEntity('facture_fourn').')';
424 if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
425 if ($search_product_category > 0) $sql .= " AND cp.fk_categorie = ".$search_product_category;
426 if ($socid > 0) $sql .= ' AND s.rowid = '.$socid;
427 if ($search_ref)
428 {
429  if (is_numeric($search_ref)) $sql .= natural_search(array('f.ref'), $search_ref);
430  else $sql .= natural_search('f.ref', $search_ref);
431 }
432 if ($search_ref) $sql .= natural_search('f.ref', $search_ref);
433 if ($search_refsupplier) $sql .= natural_search('f.ref_supplier', $search_refsupplier);
434 if ($search_type != '' && $search_type >= 0)
435 {
436  if ($search_type == '0') $sql .= " AND f.type = 0"; // standard
437  if ($search_type == '1') $sql .= " AND f.type = 1"; // replacement
438  if ($search_type == '2') $sql .= " AND f.type = 2"; // credit note
439  if ($search_type == '3') $sql .= " AND f.type = 3"; // deposit
440  //if ($search_type == '4') $sql.=" AND f.type = 4"; // proforma
441  //if ($search_type == '5') $sql.=" AND f.type = 5"; // situation
442 }
443 if ($search_project) $sql .= natural_search('p.ref', $search_project);
444 if ($search_company) $sql .= natural_search('s.nom', $search_company);
445 if ($search_town) $sql .= natural_search('s.town', $search_town);
446 if ($search_zip) $sql .= natural_search("s.zip", $search_zip);
447 if ($search_state) $sql .= natural_search("state.nom", $search_state);
448 if ($search_country) $sql .= " AND s.fk_pays IN (".$search_country.')';
449 if ($search_type_thirdparty) $sql .= " AND s.fk_typent IN (".$search_type_thirdparty.')';
450 if ($search_montant_ht != '') $sql .= natural_search('f.total_ht', $search_montant_ht, 1);
451 if ($search_montant_vat != '') $sql .= natural_search('f.total_tva', $search_montant_vat, 1);
452 if ($search_montant_localtax1 != '') $sql .= natural_search('f.localtax1', $search_montant_localtax1, 1);
453 if ($search_montant_localtax2 != '') $sql .= natural_search('f.localtax2', $search_montant_localtax2, 1);
454 if ($search_montant_ttc != '') $sql .= natural_search('f.total_ttc', $search_montant_ttc, 1);
455 if ($search_multicurrency_code != '') $sql .= ' AND f.multicurrency_code = "'.$db->escape($search_multicurrency_code).'"';
456 if ($search_multicurrency_tx != '') $sql .= natural_search('f.multicurrency_tx', $search_multicurrency_tx, 1);
457 if ($search_multicurrency_montant_ht != '') $sql .= natural_search('f.multicurrency_total_ht', $search_multicurrency_montant_ht, 1);
458 if ($search_multicurrency_montant_vat != '') $sql .= natural_search('f.multicurrency_total_tva', $search_multicurrency_montant_vat, 1);
459 if ($search_multicurrency_montant_ttc != '') $sql .= natural_search('f.multicurrency_total_ttc', $search_multicurrency_montant_ttc, 1);
460 if ($search_login) $sql .= natural_search('u.login', $search_login);
461 if ($search_status != '' && $search_status >= 0) $sql .= " AND f.fk_statut = ".$db->escape($search_status);
462 if ($search_paymentmode > 0) $sql .= " AND f.fk_mode_reglement = ".((int) $search_paymentmode);
463 if ($search_paymentcond > 0) $sql .= " AND f.fk_cond_reglement = ".((int) $search_paymentcond);
464 $sql .= dolSqlDateFilter("f.datef", $day, $month, $year);
465 $sql .= dolSqlDateFilter("f.date_lim_reglement", $day_lim, $month_lim, $year_lim);
466 if ($option == 'late') $sql .= " AND f.date_lim_reglement < '".$db->idate(dol_now() - $conf->facture->fournisseur->warning_delay)."'";
467 if ($search_label) $sql .= natural_search('f.libelle', $search_label);
468 if ($search_categ_sup > 0) $sql .= " AND cs.fk_categorie = ".$db->escape($search_categ_sup);
469 if ($search_categ_sup == -2) $sql .= " AND cs.fk_categorie IS NULL";
470 if ($search_status != '' && $search_status >= 0)
471 {
472  $sql .= " AND f.fk_statut = ".$search_status;
473 }
474 if ($filter && $filter != -1)
475 {
476  $aFilter = explode(',', $filter);
477  foreach ($aFilter as $fil)
478  {
479  $filt = explode(':', $fil);
480  $sql .= ' AND '.$db->escape(trim($filt[0])).' = '.$db->escape(trim($filt[1]));
481  }
482 }
483 if ($search_sale > 0) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $search_sale);
484 if ($search_user > 0)
485 {
486  $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 = ".$search_user;
487 }
488 // Add where from extra fields
489 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
490 // Add where from hooks
491 $parameters = array();
492 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
493 $sql .= $hookmanager->resPrint;
494 
495 if (!$search_all)
496 {
497  $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,";
498  $sql .= " f.total_ht, f.total_ttc, f.total_tva, f.paye, f.fk_statut, f.libelle, f.datec, f.tms,";
499  $sql .= " f.localtax1, f.localtax2,";
500  $sql .= ' f.fk_multicurrency, f.multicurrency_code, f.multicurrency_tx, f.multicurrency_total_ht, f.multicurrency_total_tva, f.multicurrency_total_ttc,';
501  $sql .= " f.note_public, f.note_private,";
502  $sql .= " f.fk_user_author,";
503  $sql .= ' s.rowid, s.nom, 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,';
504  $sql .= " typent.code,";
505  $sql .= " state.code_departement, state.nom,";
506  $sql .= ' country.code,';
507  $sql .= " p.rowid, p.ref, p.title,";
508  $sql .= " u.login";
509  if (!empty($extrafields->attributes[$object->table_element]['label'])) {
510  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
511  //prevent error with sql_mode=only_full_group_by
512  $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ",ef.".$key : '');
513  }
514  }
515 } else {
516  $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
517 }
518 
519 $sql .= $db->order($sortfield, $sortorder);
520 
521 $nbtotalofrecords = '';
522 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
523 {
524  $result = $db->query($sql);
525  $nbtotalofrecords = $db->num_rows($result);
526  if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0
527  {
528  $page = 0;
529  $offset = 0;
530  }
531 }
532 
533 $sql .= $db->plimit($limit + 1, $offset);
534 //print $sql;
535 
536 $resql = $db->query($sql);
537 if ($resql)
538 {
539  $num = $db->num_rows($resql);
540 
541  $arrayofselected = is_array($toselect) ? $toselect : array();
542 
543  if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $sall)
544  {
545  $obj = $db->fetch_object($resql);
546  $id = $obj->facid;
547 
548  header("Location: ".DOL_URL_ROOT.'/fourn/facture/card.php?facid='.$id);
549  exit;
550  }
551 
552  llxHeader('', $langs->trans("SuppliersInvoices"), 'EN:Suppliers_Invoices|FR:FactureFournisseur|ES:Facturas_de_proveedores');
553 
554  if ($socid)
555  {
556  $soc = new Societe($db);
557  $soc->fetch($socid);
558  if (empty($search_company)) $search_company = $soc->name;
559  }
560 
561  $param = '&socid='.$socid;
562  if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage);
563  if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit);
564  if ($search_all) $param .= '&search_all='.urlencode($search_all);
565  if ($day) $param .= '&day='.urlencode($day);
566  if ($month) $param .= '&month='.urlencode($month);
567  if ($year) $param .= '&year='.urlencode($year);
568  if ($day_lim) $param .= '&day_lim='.urlencode($day_lim);
569  if ($month_lim) $param .= '&month_lim='.urlencode($month_lim);
570  if ($year_lim) $param .= '&year_lim='.urlencode($year_lim);
571  if ($search_ref) $param .= '&search_ref='.urlencode($search_ref);
572  if ($search_refsupplier) $param .= '&search_refsupplier='.urlencode($search_refsupplier);
573  if ($search_type != '') $param .= '&search_type='.urlencode($search_type);
574  if ($search_label) $param .= '&search_label='.urlencode($search_label);
575  if ($search_company) $param .= '&search_company='.urlencode($search_company);
576  if ($search_login) $param .= '&search_login='.urlencode($search_login);
577  if ($search_montant_ht != '') $param .= '&search_montant_ht='.urlencode($search_montant_ht);
578  if ($search_montant_vat != '') $param .= '&search_montant_vat='.urlencode($search_montant_vat);
579  if ($search_montant_localtax1 != '') $param .= '&search_montant_localtax1='.urlencode($search_montant_localtax1);
580  if ($search_montant_localtax2 != '') $param .= '&search_montant_localtax2='.urlencode($search_montant_localtax2);
581  if ($search_montant_ttc != '') $param .= '&search_montant_ttc='.urlencode($search_montant_ttc);
582  if ($search_multicurrency_code != '') $param .= '&search_multicurrency_code='.urlencode($search_multicurrency_code);
583  if ($search_multicurrency_tx != '') $param .= '&search_multicurrency_tx='.urlencode($search_multicurrency_tx);
584  if ($search_multicurrency_montant_ht != '') $param .= '&search_multicurrency_montant_ht='.urlencode($search_multicurrency_montant_ht);
585  if ($search_multicurrency_montant_vat != '') $param .= '&search_multicurrency_montant_vat='.urlencode($search_multicurrency_montant_vat);
586  if ($search_multicurrency_montant_ttc != '') $param .= '&search_multicurrency_montant_ttc='.urlencode($search_multicurrency_montant_ttc);
587  if ($search_amount_no_tax) $param .= '&search_amount_no_tax='.urlencode($search_amount_no_tax);
588  if ($search_amount_all_tax) $param .= '&search_amount_all_tax='.urlencode($search_amount_all_tax);
589  if ($search_status >= 0) $param .= "&search_status=".urlencode($search_status);
590  if ($show_files) $param .= '&show_files='.urlencode($show_files);
591  if ($option) $param .= "&option=".urlencode($option);
592  if ($optioncss != '') $param .= '&optioncss='.urlencode($optioncss);
593  if ($search_categ_sup > 0) $param .= '&search_categ_sup='.urlencode($search_categ_sup);
594 
595  // Add $param from extra fields
596  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
597 
598  // List of mass actions available
599  $arrayofmassactions = array(
600  'validate'=>$langs->trans("Validate"),
601  'generate_doc'=>$langs->trans("ReGeneratePDF"),
602  //'builddoc'=>$langs->trans("PDFMerge"),
603  //'presend'=>$langs->trans("SendByMail"),
604  );
605  //if($user->rights->fournisseur->facture->creer) $arrayofmassactions['createbills']=$langs->trans("CreateInvoiceForThisCustomer");
606  if (!empty($conf->paymentbybanktransfer->enabled) && !empty($user->rights->paymentbybanktransfer->create)) {
607  $langs->load('withdrawals');
608  $arrayofmassactions['banktransfertrequest'] = $langs->trans("MakeBankTransferOrder");
609  }
610  if ($user->rights->fournisseur->facture->supprimer) $arrayofmassactions['predelete'] = '<span class="fa fa-trash paddingrightonly"></span>'.$langs->trans("Delete");
611  if (in_array($massaction, array('presend', 'predelete', 'createbills'))) $arrayofmassactions = array();
612  $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
613 
614  $url = DOL_URL_ROOT.'/fourn/facture/card.php?action=create';
615  if (!empty($socid)) $url .= '&socid='.$socid;
616  $newcardbutton = dolGetButtonTitle($langs->trans('NewBill'), '', 'fa fa-plus-circle', $url, '', $user->rights->fournisseur->facture->creer);
617 
618  $i = 0;
619  print '<form method="POST" name="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
620  if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
621  print '<input type="hidden" name="token" value="'.newToken().'">';
622  print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
623  print '<input type="hidden" name="action" value="list">';
624  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
625  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
626  print '<input type="hidden" name="socid" value="'.$socid.'">';
627 
628  print_barre_liste($langs->trans("BillsSuppliers").($socid ? ' '.$soc->name : ''), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'supplier_invoice', 0, $newcardbutton, '', $limit, 0, 0, 1);
629 
630  $topicmail = "SendBillRef";
631  $modelmail = "invoice_supplier_send";
632  $objecttmp = new FactureFournisseur($db);
633  $trackid = 'sinv'.$object->id;
634  include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
635 
636  if ($massaction == 'createbills')
637  {
638  //var_dump($_REQUEST);
639  print '<input type="hidden" name="massaction" value="confirm_createbills">';
640 
641  print '<table class="border" width="100%" >';
642  print '<tr>';
643  print '<td class="titlefieldmiddle">';
644  print $langs->trans('DateInvoice');
645  print '</td>';
646  print '<td>';
647  print $form->selectDate('', '', '', '', '', '', 1, 1);
648  print '</td>';
649  print '</tr>';
650  print '<tr>';
651  print '<td>';
652  print $langs->trans('CreateOneBillByThird');
653  print '</td>';
654  print '<td>';
655  print $form->selectyesno('createbills_onebythird', '', 1);
656  print '</td>';
657  print '</tr>';
658  print '<tr>';
659  print '<td>';
660  print $langs->trans('ValidateInvoices');
661  print '</td>';
662  print '<td>';
663  print $form->selectyesno('validate_invoices', 1, 1);
664  print '</td>';
665  print '</tr>';
666  print '</table>';
667 
668  print '<br>';
669  print '<div class="center">';
670  print '<input type="submit" class="button" id="createbills" name="createbills" value="'.$langs->trans('CreateInvoiceForThisCustomer').'"> ';
671  print '<input type="submit" class="button button-cancel" id="cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
672  print '</div>';
673  print '<br>';
674  }
675 
676  if ($search_all)
677  {
678  foreach ($fieldstosearchall as $key => $val) $fieldstosearchall[$key] = $langs->trans($val);
679  print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>';
680  }
681 
682  // If the user can view prospects other than his'
683  $moreforfilter = '';
684  if ($user->rights->societe->client->voir || $socid)
685  {
686  $langs->load("commercial");
687  $moreforfilter .= '<div class="divsearchfield">';
688  $moreforfilter .= $langs->trans('ThirdPartiesOfSaleRepresentative').': ';
689  $moreforfilter .= $formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, 1, 'maxwidth200');
690  $moreforfilter .= '</div>';
691  }
692  // If the user can view prospects other than his'
693  if ($user->rights->societe->client->voir || $socid)
694  {
695  $moreforfilter .= '<div class="divsearchfield">';
696  $moreforfilter .= $langs->trans('LinkedToSpecificUsers').': ';
697  $moreforfilter .= $form->select_dolusers($search_user, 'search_user', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth200');
698  $moreforfilter .= '</div>';
699  }
700  // If the user can view prospects other than his'
701  if (!empty($conf->categorie->enabled) && $user->rights->categorie->lire && ($user->rights->produit->lire || $user->rights->service->lire))
702  {
703  include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
704  $moreforfilter .= '<div class="divsearchfield">';
705  $moreforfilter .= $langs->trans('IncludingProductWithTag').': ';
706  $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, null, 'parent', null, null, 1);
707  $moreforfilter .= $form->selectarray('search_product_category', $cate_arbo, $search_product_category, 1, 0, 0, '', 0, 0, 0, 0, 'maxwidth300', 1);
708  $moreforfilter .= '</div>';
709  }
710 
711  if (!empty($conf->categorie->enabled))
712  {
713  require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
714  $moreforfilter .= '<div class="divsearchfield">';
715  $moreforfilter .= $langs->trans('SuppliersCategoriesShort').': ';
716  $moreforfilter .= $formother->select_categories('supplier', $search_categ_sup, 'search_categ_sup', 1);
717  $moreforfilter .= '</div>';
718  }
719  $parameters = array();
720  $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
721  if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint;
722  else $moreforfilter = $hookmanager->resPrint;
723 
724  if ($moreforfilter)
725  {
726  print '<div class="liste_titre liste_titre_bydiv centpercent">';
727  print $moreforfilter;
728  print '</div>';
729  }
730 
731  $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
732  $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
733  if ($massactionbutton) $selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
734 
735  print '<div class="div-table-responsive">';
736  print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
737 
738  // Line for filters
739  print '<tr class="liste_titre_filter">';
740  // Ref
741  if (!empty($arrayfields['f.ref']['checked']))
742  {
743  print '<td class="liste_titre left">';
744  print '<input class="flat maxwidth50" type="text" name="search_ref" value="'.$search_ref.'">';
745  print '</td>';
746  }
747  // Ref supplier
748  if (!empty($arrayfields['f.ref_supplier']['checked']))
749  {
750  print '<td class="liste_titre">';
751  print '<input class="flat maxwidth50" type="text" name="search_refsupplier" value="'.$search_refsupplier.'">';
752  print '</td>';
753  }
754  // Type
755  if (!empty($arrayfields['f.type']['checked']))
756  {
757  print '<td class="liste_titre maxwidthonsmartphone">';
758  $listtype = array(
759  FactureFournisseur::TYPE_STANDARD=>$langs->trans("InvoiceStandard"),
760  FactureFournisseur::TYPE_REPLACEMENT=>$langs->trans("InvoiceReplacement"),
761  FactureFournisseur::TYPE_CREDIT_NOTE=>$langs->trans("InvoiceAvoir"),
762  FactureFournisseur::TYPE_DEPOSIT=>$langs->trans("InvoiceDeposit"),
763  );
764  /*
765  if (! empty($conf->global->INVOICE_USE_SITUATION))
766  {
767  $listtype[Facture::TYPE_SITUATION] = $langs->trans("InvoiceSituation");
768  }
769  */
770  //$listtype[Facture::TYPE_PROFORMA]=$langs->trans("InvoiceProForma"); // A proformat invoice is not an invoice but must be an order.
771  print $form->selectarray('search_type', $listtype, $search_type, 1, 0, 0, '', 0, 0, 0, 'ASC', 'maxwidth100');
772  print '</td>';
773  }
774  // Label
775  if (!empty($arrayfields['f.label']['checked']))
776  {
777  print '<td class="liste_titre">';
778  print '<input class="flat maxwidth75" type="text" name="search_label" value="'.$search_label.'">';
779  print '</td>';
780  }
781  // Date invoice
782  if (!empty($arrayfields['f.datef']['checked']))
783  {
784  print '<td class="liste_titre nowraponall center">';
785  if (!empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat width25 valignmiddle" type="text" maxlength="2" name="day" value="'.dol_escape_htmltag($day).'">';
786  print '<input class="flat width25 valignmiddle" type="text" size="1" maxlength="2" name="month" value="'.$month.'">';
787  $formother->select_year($year ? $year : -1, 'year', 1, 20, 5);
788  print '</td>';
789  }
790  // Date due
791  if (!empty($arrayfields['f.date_lim_reglement']['checked']))
792  {
793  print '<td class="liste_titre nowraponall center">';
794  if (!empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat width25 valignmiddle" type="text" maxlength="2" name="day_lim" value="'.dol_escape_htmltag($day_lim).'">';
795  print '<input class="flat width25 valignmiddle" type="text" maxlength="2" name="month_lim" value="'.$month_lim.'">';
796  $formother->select_year($year_lim ? $year_lim : -1, 'year_lim', 1, 20, 5);
797  print '<br><input type="checkbox" name="option" value="late"'.($option == 'late' ? ' checked' : '').'> '.$langs->trans("Late");
798  print '</td>';
799  }
800  // Project
801  if (!empty($arrayfields['p.ref']['checked']))
802  {
803  print '<td class="liste_titre"><input class="flat maxwidth50" type="text" name="search_project" value="'.$search_project.'"></td>';
804  }
805  // Thirpdarty
806  if (!empty($arrayfields['s.nom']['checked']))
807  {
808  print '<td class="liste_titre"><input class="flat maxwidth50" type="text" name="search_company" value="'.$search_company.'"></td>';
809  }
810  // Town
811  if (!empty($arrayfields['s.town']['checked'])) print '<td class="liste_titre"><input class="flat maxwidth50" type="text" name="search_town" value="'.dol_escape_htmltag($search_town).'"></td>';
812  // Zip
813  if (!empty($arrayfields['s.zip']['checked'])) print '<td class="liste_titre center"><input class="flat maxwidth50" type="text" name="search_zip" value="'.dol_escape_htmltag($search_zip).'"></td>';
814  // State
815  if (!empty($arrayfields['state.nom']['checked']))
816  {
817  print '<td class="liste_titre">';
818  print '<input class="flat" size="4" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
819  print '</td>';
820  }
821  // Country
822  if (!empty($arrayfields['country.code_iso']['checked']))
823  {
824  print '<td class="liste_titre center">';
825  print $form->select_country($search_country, 'search_country', '', 0, 'minwidth100imp maxwidth100');
826  print '</td>';
827  }
828  // Company type
829  if (!empty($arrayfields['typent.code']['checked']))
830  {
831  print '<td class="liste_titre maxwidthonsmartphone center">';
832  print $form->selectarray("search_type_thirdparty", $formcompany->typent_array(0), $search_type_thirdparty, 0, 0, 0, '', 0, 0, 0, (empty($conf->global->SOCIETE_SORT_ON_TYPEENT) ? 'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT));
833  print '</td>';
834  }
835  // Condition of payment
836  if (!empty($arrayfields['f.fk_cond_reglement']['checked']))
837  {
838  print '<td class="liste_titre left">';
839  $form->select_conditions_paiements($search_paymentcond, 'search_paymentcond', -1, 1, 1, 'maxwidth100');
840  print '</td>';
841  }
842  // Payment mode
843  if (!empty($arrayfields['f.fk_mode_reglement']['checked']))
844  {
845  print '<td class="liste_titre left">';
846  $form->select_types_paiements($search_paymentmode, 'search_paymentmode', '', 0, 1, 1, 20, 1, 'maxwidth100');
847  print '</td>';
848  }
849  if (!empty($arrayfields['f.total_ht']['checked']))
850  {
851  // Amount without tax
852  print '<td class="liste_titre right">';
853  print '<input class="flat" type="text" size="5" name="search_montant_ht" value="'.dol_escape_htmltag($search_montant_ht).'">';
854  print '</td>';
855  }
856  if (!empty($arrayfields['f.total_vat']['checked']))
857  {
858  // Amount vat
859  print '<td class="liste_titre right">';
860  print '<input class="flat" type="text" size="5" name="search_montant_vat" value="'.dol_escape_htmltag($search_montant_vat).'">';
861  print '</td>';
862  }
863  if (!empty($arrayfields['f.total_localtax1']['checked']))
864  {
865  // Amount tax 1
866  print '<td class="liste_titre right">';
867  print '<input class="flat" type="text" size="5" name="search_montant_localtax1" value="'.$search_montant_localtax1.'">';
868  print '</td>';
869  }
870  if (!empty($arrayfields['f.total_localtax2']['checked']))
871  {
872  // Amount tax 2
873  print '<td class="liste_titre right">';
874  print '<input class="flat" type="text" size="5" name="search_montant_localtax2" value="'.$search_montant_localtax2.'">';
875  print '</td>';
876  }
877  if (!empty($arrayfields['f.total_ttc']['checked']))
878  {
879  // Amount inc tac
880  print '<td class="liste_titre right">';
881  print '<input class="flat" type="text" size="5" name="search_montant_ttc" value="'.dol_escape_htmltag($search_montant_ttc).'">';
882  print '</td>';
883  }
884  if (!empty($arrayfields['u.login']['checked']))
885  {
886  // Author
887  print '<td class="liste_titre" align="center">';
888  print '<input class="flat" size="4" type="text" name="search_login" value="'.dol_escape_htmltag($search_login).'">';
889  print '</td>';
890  }
891  if (!empty($arrayfields['dynamount_payed']['checked']))
892  {
893  print '<td class="liste_titre right">';
894  print '</td>';
895  }
896  if (!empty($arrayfields['rtp']['checked']))
897  {
898  print '<td class="liste_titre">';
899  print '</td>';
900  }
901  if (!empty($arrayfields['f.multicurrency_code']['checked']))
902  {
903  // Currency
904  print '<td class="liste_titre">';
905  print $form->selectMultiCurrency($search_multicurrency_code, 'search_multicurrency_code', 1);
906  print '</td>';
907  }
908  if (!empty($arrayfields['f.multicurrency_tx']['checked']))
909  {
910  // Currency rate
911  print '<td class="liste_titre">';
912  print '<input class="flat" type="text" size="4" name="search_multicurrency_tx" value="'.dol_escape_htmltag($search_multicurrency_tx).'">';
913  print '</td>';
914  }
915  if (!empty($arrayfields['f.multicurrency_total_ht']['checked']))
916  {
917  // Amount
918  print '<td class="liste_titre right">';
919  print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_ht" value="'.dol_escape_htmltag($search_multicurrency_montant_ht).'">';
920  print '</td>';
921  }
922  if (!empty($arrayfields['f.multicurrency_total_vat']['checked']))
923  {
924  // Amount
925  print '<td class="liste_titre right">';
926  print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_vat" value="'.dol_escape_htmltag($search_multicurrency_montant_vat).'">';
927  print '</td>';
928  }
929  if (!empty($arrayfields['f.multicurrency_total_ttc']['checked']))
930  {
931  // Amount
932  print '<td class="liste_titre right">';
933  print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_ttc" value="'.dol_escape_htmltag($search_multicurrency_montant_ttc).'">';
934  print '</td>';
935  }
936  if (!empty($arrayfields['multicurrency_dynamount_payed']['checked']))
937  {
938  print '<td class="liste_titre">';
939  print '</td>';
940  }
941  if (!empty($arrayfields['multicurrency_rtp']['checked']))
942  {
943  print '<td class="liste_titre right">';
944  print '</td>';
945  }
946  // Extra fields
947  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
948 
949  // Fields from hook
950  $parameters = array('arrayfields'=>$arrayfields);
951  $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
952  print $hookmanager->resPrint;
953  // Date creation
954  if (!empty($arrayfields['f.datec']['checked']))
955  {
956  print '<td class="liste_titre">';
957  print '</td>';
958  }
959  // Date modification
960  if (!empty($arrayfields['f.tms']['checked']))
961  {
962  print '<td class="liste_titre">';
963  print '</td>';
964  }
965  // Status
966  if (!empty($arrayfields['f.fk_statut']['checked']))
967  {
968  print '<td class="liste_titre maxwidthonsmartphone right">';
969  $liststatus = array('0'=>$langs->trans("Draft"), '1'=>$langs->trans("Unpaid"), '2'=>$langs->trans("Paid"));
970  print $form->selectarray('search_status', $liststatus, $search_status, 1, 0, 0, '', 0, 0, 0, '', '', 1);
971  print '</td>';
972  }
973  // Action column
974  print '<td class="liste_titre middle">';
975  $searchpicto = $form->showFilterButtons();
976  print $searchpicto;
977  print '</td>';
978 
979  print "</tr>\n";
980 
981  print '<tr class="liste_titre">';
982  if (!empty($arrayfields['f.ref']['checked'])) print_liste_field_titre($arrayfields['f.ref']['label'], $_SERVER['PHP_SELF'], 'f.ref,f.rowid', '', $param, '', $sortfield, $sortorder);
983  if (!empty($arrayfields['f.ref_supplier']['checked'])) print_liste_field_titre($arrayfields['f.ref_supplier']['label'], $_SERVER["PHP_SELF"], 'f.ref_supplier', '', $param, '', $sortfield, $sortorder);
984  if (!empty($arrayfields['f.type']['checked'])) print_liste_field_titre($arrayfields['f.type']['label'], $_SERVER["PHP_SELF"], 'f.type', '', $param, '', $sortfield, $sortorder);
985  if (!empty($arrayfields['f.label']['checked'])) print_liste_field_titre($arrayfields['f.label']['label'], $_SERVER['PHP_SELF'], "f.libelle,f.rowid", '', $param, '', $sortfield, $sortorder);
986  if (!empty($arrayfields['f.datef']['checked'])) print_liste_field_titre($arrayfields['f.datef']['label'], $_SERVER['PHP_SELF'], 'f.datef,f.rowid', '', $param, '', $sortfield, $sortorder, 'center ');
987  if (!empty($arrayfields['f.date_lim_reglement']['checked'])) print_liste_field_titre($arrayfields['f.date_lim_reglement']['label'], $_SERVER['PHP_SELF'], "f.date_lim_reglement", '', $param, '', $sortfield, $sortorder, 'center ');
988  if (!empty($arrayfields['p.ref']['checked'])) print_liste_field_titre($arrayfields['p.ref']['label'], $_SERVER['PHP_SELF'], "p.ref", '', $param, '', $sortfield, $sortorder);
989  if (!empty($arrayfields['s.nom']['checked'])) print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER['PHP_SELF'], 's.nom', '', $param, '', $sortfield, $sortorder);
990  if (!empty($arrayfields['s.town']['checked'])) print_liste_field_titre($arrayfields['s.town']['label'], $_SERVER["PHP_SELF"], 's.town', '', $param, '', $sortfield, $sortorder);
991  if (!empty($arrayfields['s.zip']['checked'])) print_liste_field_titre($arrayfields['s.zip']['label'], $_SERVER["PHP_SELF"], 's.zip', '', $param, '', $sortfield, $sortorder, 'center ');
992  if (!empty($arrayfields['state.nom']['checked'])) print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder);
993  if (!empty($arrayfields['country.code_iso']['checked'])) print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, '', $sortfield, $sortorder, 'center ');
994  if (!empty($arrayfields['typent.code']['checked'])) print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, '', $sortfield, $sortorder, 'center ');
995  if (!empty($arrayfields['f.fk_cond_reglement']['checked'])) print_liste_field_titre($arrayfields['f.fk_cond_reglement']['label'], $_SERVER["PHP_SELF"], "f.fk_cond_reglement", "", $param, "", $sortfield, $sortorder);
996  if (!empty($arrayfields['f.fk_mode_reglement']['checked'])) print_liste_field_titre($arrayfields['f.fk_mode_reglement']['label'], $_SERVER["PHP_SELF"], "f.fk_mode_reglement", "", $param, "", $sortfield, $sortorder);
997  if (!empty($arrayfields['f.total_ht']['checked'])) print_liste_field_titre($arrayfields['f.total_ht']['label'], $_SERVER['PHP_SELF'], 'f.total_ht', '', $param, '', $sortfield, $sortorder, 'right ');
998  if (!empty($arrayfields['f.total_vat']['checked'])) print_liste_field_titre($arrayfields['f.total_vat']['label'], $_SERVER['PHP_SELF'], 'f.tva', '', $param, '', $sortfield, $sortorder, 'right ');
999  if (!empty($arrayfields['f.total_localtax1']['checked'])) print_liste_field_titre($arrayfields['f.total_localtax1']['label'], $_SERVER['PHP_SELF'], 'f.localtax1', '', $param, '', $sortfield, $sortorder, 'right ');
1000  if (!empty($arrayfields['f.total_localtax2']['checked'])) print_liste_field_titre($arrayfields['f.total_localtax2']['label'], $_SERVER['PHP_SELF'], 'f.localtax2', '', $param, '', $sortfield, $sortorder, 'right ');
1001  if (!empty($arrayfields['f.total_ttc']['checked'])) print_liste_field_titre($arrayfields['f.total_ttc']['label'], $_SERVER['PHP_SELF'], 'f.total_ttc', '', $param, '', $sortfield, $sortorder, 'right ');
1002  if (!empty($arrayfields['u.login']['checked'])) print_liste_field_titre($arrayfields['u.login']['label'], $_SERVER["PHP_SELF"], 'u.login', '', $param, 'align="center"', $sortfield, $sortorder);
1003  if (!empty($arrayfields['dynamount_payed']['checked'])) print_liste_field_titre($arrayfields['dynamount_payed']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'right ');
1004  if (!empty($arrayfields['rtp']['checked'])) print_liste_field_titre($arrayfields['rtp']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'right ');
1005  if (!empty($arrayfields['f.multicurrency_code']['checked'])) print_liste_field_titre($arrayfields['f.multicurrency_code']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_code', '', $param, '', $sortfield, $sortorder);
1006  if (!empty($arrayfields['f.multicurrency_tx']['checked'])) print_liste_field_titre($arrayfields['f.multicurrency_tx']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_tx', '', $param, '', $sortfield, $sortorder);
1007  if (!empty($arrayfields['f.multicurrency_total_ht']['checked'])) print_liste_field_titre($arrayfields['f.multicurrency_total_ht']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_total_ht', '', $param, 'class="right"', $sortfield, $sortorder);
1008  if (!empty($arrayfields['f.multicurrency_total_vat']['checked'])) print_liste_field_titre($arrayfields['f.multicurrency_total_vat']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_total_tva', '', $param, 'class="right"', $sortfield, $sortorder);
1009  if (!empty($arrayfields['f.multicurrency_total_ttc']['checked'])) print_liste_field_titre($arrayfields['f.multicurrency_total_ttc']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_total_ttc', '', $param, 'class="right"', $sortfield, $sortorder);
1010  if (!empty($arrayfields['multicurrency_dynamount_payed']['checked'])) print_liste_field_titre($arrayfields['multicurrency_dynamount_payed']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
1011  if (!empty($arrayfields['multicurrency_rtp']['checked'])) print_liste_field_titre($arrayfields['multicurrency_rtp']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
1012  // Extra fields
1013  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
1014  // Hook fields
1015  $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
1016  $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
1017  print $hookmanager->resPrint;
1018  if (!empty($arrayfields['f.datec']['checked'])) print_liste_field_titre($arrayfields['f.datec']['label'], $_SERVER["PHP_SELF"], "f.datec", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
1019  if (!empty($arrayfields['f.tms']['checked'])) print_liste_field_titre($arrayfields['f.tms']['label'], $_SERVER["PHP_SELF"], "f.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
1020  if (!empty($arrayfields['f.fk_statut']['checked'])) print_liste_field_titre($arrayfields['f.fk_statut']['label'], $_SERVER["PHP_SELF"], "fk_statut,paye,type", "", $param, '', $sortfield, $sortorder, 'right ');
1021  print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
1022  print "</tr>\n";
1023 
1024  $facturestatic = new FactureFournisseur($db);
1025  $supplierstatic = new Fournisseur($db);
1026  $projectstatic = new Project($db);
1027  $userstatic = new User($db);
1028 
1029  if ($num > 0)
1030  {
1031  $i = 0;
1032  $totalarray = array();
1033  while ($i < min($num, $limit))
1034  {
1035  $obj = $db->fetch_object($resql);
1036 
1037  $datelimit = $db->jdate($obj->datelimite);
1038  $facturestatic->id = $obj->facid;
1039  $facturestatic->ref = $obj->ref;
1040  $facturestatic->type = $obj->type;
1041  $facturestatic->ref_supplier = $obj->ref_supplier;
1042  $facturestatic->date_echeance = $db->jdate($obj->datelimite);
1043  $facturestatic->statut = $obj->fk_statut;
1044  $facturestatic->note_public = $obj->note_public;
1045  $facturestatic->note_private = $obj->note_private;
1046  $facturestatic->multicurrency_code = $obj->multicurrency_code;
1047  $facturestatic->multicurrency_tx = $obj->multicurrency_tx;
1048  $facturestatic->multicurrency_total_ht = $obj->multicurrency_total_ht;
1049  $facturestatic->multicurrency_total_tva = $obj->multicurrency_total_vat;
1050  $facturestatic->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
1051 
1052  $thirdparty->id = $obj->socid;
1053  $thirdparty->name = $obj->name;
1054  $thirdparty->client = $obj->client;
1055  $thirdparty->fournisseur = $obj->fournisseur;
1056  $thirdparty->code_client = $obj->code_client;
1057  $thirdparty->code_compta_client = $obj->code_compta_client;
1058  $thirdparty->code_fournisseur = $obj->code_fournisseur;
1059  $thirdparty->code_compta_fournisseur = $obj->code_compta_fournisseur;
1060  $thirdparty->email = $obj->email;
1061  $thirdparty->country_code = $obj->country_code;
1062 
1063  $paiement = $facturestatic->getSommePaiement();
1064  $totalcreditnotes = $facturestatic->getSumCreditNotesUsed();
1065  $totaldeposits = $facturestatic->getSumDepositsUsed();
1066  $totalpay = $paiement + $totalcreditnotes + $totaldeposits;
1067  $remaintopay = $obj->total_ttc - $totalpay;
1068  $multicurrency_paiement = $facturestatic->getSommePaiement(1);
1069  $multicurrency_totalcreditnotes = $facturestatic->getSumCreditNotesUsed(1);
1070  $multicurrency_totaldeposits = $facturestatic->getSumDepositsUsed(1);
1071  $multicurrency_totalpay = $multicurrency_paiement + $multicurrency_totalcreditnotes + $multicurrency_totaldeposits;
1072  $multicurrency_remaintopay = price2num($facturestatic->multicurrency_total_ttc - $multicurrency_totalpay);
1073 
1074  $facturestatic->alreadypaid = ($paiement ? $paiement : 0);
1075  $facturestatic->paye = $obj->paye;
1076  $facturestatic->statut = $obj->fk_statut;
1077  $facturestatic->type = $obj->type;
1078 
1079 
1080  //If invoice has been converted and the conversion has been used, we dont have remain to pay on invoice
1081  if ($facturestatic->type == FactureFournisseur::TYPE_CREDIT_NOTE) {
1082  if ($facturestatic->isCreditNoteUsed()) {
1083  $remaintopay = -$facturestatic->getSumFromThisCreditNotesNotUsed();
1084  }
1085  }
1086 
1087  print '<tr class="oddeven">';
1088  if (!empty($arrayfields['f.ref']['checked']))
1089  {
1090  print '<td class="nowrap">';
1091 
1092  print '<table class="nobordernopadding"><tr class="nocellnopadd">';
1093  // Picto + Ref
1094  print '<td class="nobordernopadding nowrap">';
1095  print $facturestatic->getNomUrl(1, '', 0, 0, '', 0, -1, 1);
1096 
1097  $filename = dol_sanitizeFileName($obj->ref);
1098  $filedir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($obj->facid, 2, 0, 0, $facturestatic, 'invoice_supplier').dol_sanitizeFileName($obj->ref);
1099  $subdir = get_exdir($obj->facid, 2, 0, 0, $facturestatic, 'invoice_supplier').dol_sanitizeFileName($obj->ref);
1100  print $formfile->getDocumentsLink('facture_fournisseur', $subdir, $filedir);
1101  print '</td></tr></table>';
1102 
1103  print "</td>\n";
1104  if (!$i) $totalarray['nbfield']++;
1105  }
1106 
1107  // Supplier ref
1108  if (!empty($arrayfields['f.ref_supplier']['checked']))
1109  {
1110  print '<td class="nowrap tdoverflowmax200">';
1111  print $obj->ref_supplier;
1112  print '</td>';
1113  if (!$i) $totalarray['nbfield']++;
1114  }
1115 
1116  // Type
1117  if (!empty($arrayfields['f.type']['checked']))
1118  {
1119  print '<td class="nowrap">';
1120  print $facturestatic->getLibType();
1121  print "</td>";
1122  if (!$i) $totalarray['nbfield']++;
1123  }
1124 
1125  // Label
1126  if (!empty($arrayfields['f.label']['checked']))
1127  {
1128  print '<td class="nowrap">';
1129  print $obj->label;
1130  print '</td>';
1131  if (!$i) $totalarray['nbfield']++;
1132  }
1133 
1134  // Date
1135  if (!empty($arrayfields['f.datef']['checked']))
1136  {
1137  print '<td class="center nowrap">';
1138  print dol_print_date($db->jdate($obj->datef), 'day');
1139  print '</td>';
1140  if (!$i) $totalarray['nbfield']++;
1141  }
1142 
1143  // Date limit
1144  if (!empty($arrayfields['f.date_lim_reglement']['checked']))
1145  {
1146  print '<td class="center nowrap">'.dol_print_date($datelimit, 'day');
1147  if ($facturestatic->hasDelay())
1148  {
1149  print img_warning($langs->trans('Late'));
1150  }
1151  print '</td>';
1152  if (!$i) $totalarray['nbfield']++;
1153  }
1154 
1155  // Project
1156  if (!empty($arrayfields['p.ref']['checked']))
1157  {
1158  print '<td class="nowrap">';
1159  if ($obj->project_id > 0)
1160  {
1161  $projectstatic->id = $obj->project_id;
1162  $projectstatic->ref = $obj->project_ref;
1163  $projectstatic->title = $obj->project_label;
1164  print $projectstatic->getNomUrl(1);
1165  }
1166  print '</td>';
1167  if (!$i) $totalarray['nbfield']++;
1168  }
1169 
1170  // Third party
1171  if (!empty($arrayfields['s.nom']['checked']))
1172  {
1173  print '<td class="tdoverflowmax200">';
1174  print $thirdparty->getNomUrl(1, 'supplier');
1175  print '</td>';
1176  if (!$i) $totalarray['nbfield']++;
1177  }
1178  // Town
1179  if (!empty($arrayfields['s.town']['checked']))
1180  {
1181  print '<td class="nocellnopadd">';
1182  print $obj->town;
1183  print '</td>';
1184  if (!$i) $totalarray['nbfield']++;
1185  }
1186  // Zip
1187  if (!empty($arrayfields['s.zip']['checked']))
1188  {
1189  print '<td class="nocellnopadd center">';
1190  print $obj->zip;
1191  print '</td>';
1192  if (!$i) $totalarray['nbfield']++;
1193  }
1194  // State
1195  if (!empty($arrayfields['state.nom']['checked']))
1196  {
1197  print "<td>".$obj->state_name."</td>\n";
1198  if (!$i) $totalarray['nbfield']++;
1199  }
1200  // Country
1201  if (!empty($arrayfields['country.code_iso']['checked']))
1202  {
1203  print '<td class="center">';
1204  $tmparray = getCountry($obj->fk_pays, 'all');
1205  print $tmparray['label'];
1206  print '</td>';
1207  if (!$i) $totalarray['nbfield']++;
1208  }
1209  // Type ent
1210  if (!empty($arrayfields['typent.code']['checked']))
1211  {
1212  print '<td class="center">';
1213  if (count($typenArray) == 0) $typenArray = $formcompany->typent_array(1);
1214  print $typenArray[$obj->typent_code];
1215  print '</td>';
1216  if (!$i) $totalarray['nbfield']++;
1217  }
1218 
1219  // Payment condition
1220  if (!empty($arrayfields['f.fk_cond_reglement']['checked']))
1221  {
1222  print '<td>';
1223  $form->form_conditions_reglement($_SERVER['PHP_SELF'], $obj->fk_cond_reglement, 'none', '', -1);
1224  print '</td>';
1225  if (!$i) $totalarray['nbfield']++;
1226  }
1227  // Payment mode
1228  if (!empty($arrayfields['f.fk_mode_reglement']['checked']))
1229  {
1230  print '<td>';
1231  $form->form_modes_reglement($_SERVER['PHP_SELF'], $obj->fk_mode_reglement, 'none', '', -1);
1232  print '</td>';
1233  if (!$i) $totalarray['nbfield']++;
1234  }
1235 
1236  // Amount HT
1237  if (!empty($arrayfields['f.total_ht']['checked']))
1238  {
1239  print '<td class="right nowrap">'.price($obj->total_ht)."</td>\n";
1240  if (!$i) $totalarray['nbfield']++;
1241  if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'f.total_ht';
1242  $totalarray['val']['f.total_ht'] += $obj->total_ht;
1243  }
1244  // Amount VAT
1245  if (!empty($arrayfields['f.total_vat']['checked']))
1246  {
1247  print '<td class="right nowrap">'.price($obj->total_vat)."</td>\n";
1248  if (!$i) $totalarray['nbfield']++;
1249  if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'f.total_vat';
1250  $totalarray['val']['f.total_vat'] += $obj->total_vat;
1251  }
1252  // Amount LocalTax1
1253  if (!empty($arrayfields['f.total_localtax1']['checked']))
1254  {
1255  print '<td class="right nowrap">'.price($obj->total_localtax1)."</td>\n";
1256  if (!$i) $totalarray['nbfield']++;
1257  if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'f.total_localtax1';
1258  $totalarray['val']['f.total_localtax1'] += $obj->total_localtax1;
1259  }
1260  // Amount LocalTax2
1261  if (!empty($arrayfields['f.total_localtax2']['checked']))
1262  {
1263  print '<td class="right nowrap">'.price($obj->total_localtax2)."</td>\n";
1264  if (!$i) $totalarray['nbfield']++;
1265  if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'f.total_localtax2';
1266  $totalarray['val']['f.total_localtax2'] += $obj->total_localtax2;
1267  }
1268  // Amount TTC
1269  if (!empty($arrayfields['f.total_ttc']['checked']))
1270  {
1271  print '<td class="right nowrap">'.price($obj->total_ttc)."</td>\n";
1272  if (!$i) $totalarray['nbfield']++;
1273  if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'f.total_ttc';
1274  $totalarray['val']['f.total_ttc'] += $obj->total_ttc;
1275  }
1276 
1277  // Author
1278  if (!empty($arrayfields['u.login']['checked']))
1279  {
1280  $userstatic->id = $obj->fk_user_author;
1281  $userstatic->login = $obj->login;
1282  print '<td align="center">';
1283  if ($userstatic->id) print $userstatic->getLoginUrl(1);
1284  else print '&nbsp;';
1285  print "</td>\n";
1286  if (!$i) $totalarray['nbfield']++;
1287  }
1288 
1289  if (!empty($arrayfields['dynamount_payed']['checked']))
1290  {
1291  print '<td class="right nowrap">'.(!empty($totalpay) ?price($totalpay, 0, $langs) : '&nbsp;').'</td>'; // TODO Use a denormalized field
1292  if (!$i) $totalarray['nbfield']++;
1293  if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'totalam';
1294  $totalarray['val']['totalam'] += $totalpay;
1295  }
1296 
1297  if (!empty($arrayfields['rtp']['checked']))
1298  {
1299  print '<td class="right nowrap">'.(!empty($remaintopay) ?price($remaintopay, 0, $langs) : '&nbsp;').'</td>'; // TODO Use a denormalized field
1300  if (!$i) $totalarray['nbfield']++;
1301  if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'rtp';
1302  $totalarray['val']['rtp'] += $remaintopay;
1303  }
1304 
1305  // Currency
1306  if (!empty($arrayfields['f.multicurrency_code']['checked']))
1307  {
1308  print '<td class="nowrap">'.$obj->multicurrency_code.' - '.$langs->trans('Currency'.$obj->multicurrency_code)."</td>\n";
1309  if (!$i) $totalarray['nbfield']++;
1310  }
1311 
1312  // Currency rate
1313  if (!empty($arrayfields['f.multicurrency_tx']['checked']))
1314  {
1315  print '<td class="nowrap">';
1316  $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$obj->rowid, $obj->multicurrency_tx, 'none', $obj->multicurrency_code);
1317  print "</td>\n";
1318  if (!$i) $totalarray['nbfield']++;
1319  }
1320  // Amount HT
1321  if (!empty($arrayfields['f.multicurrency_total_ht']['checked']))
1322  {
1323  print '<td class="right nowrap">'.price($obj->multicurrency_total_ht)."</td>\n";
1324  if (!$i) $totalarray['nbfield']++;
1325  }
1326  // Amount VAT
1327  if (!empty($arrayfields['f.multicurrency_total_vat']['checked']))
1328  {
1329  print '<td class="right nowrap">'.price($obj->multicurrency_total_vat)."</td>\n";
1330  if (!$i) $totalarray['nbfield']++;
1331  }
1332  // Amount TTC
1333  if (!empty($arrayfields['f.multicurrency_total_ttc']['checked']))
1334  {
1335  print '<td class="right nowrap">'.price($obj->multicurrency_total_ttc)."</td>\n";
1336  if (!$i) $totalarray['nbfield']++;
1337  }
1338  if (!empty($arrayfields['multicurrency_dynamount_payed']['checked']))
1339  {
1340  print '<td class="right nowrap">'.(!empty($multicurrency_totalpay) ?price($multicurrency_totalpay, 0, $langs) : '&nbsp;').'</td>'; // TODO Use a denormalized field
1341  if (!$i) $totalarray['nbfield']++;
1342  }
1343 
1344  // Pending amount
1345  if (!empty($arrayfields['multicurrency_rtp']['checked']))
1346  {
1347  print '<td class="right nowrap">';
1348  print (!empty($multicurrency_remaintopay) ? price($multicurrency_remaintopay, 0, $langs) : '&nbsp;');
1349  print '</td>'; // TODO Use a denormalized field
1350  if (!$i) $totalarray['nbfield']++;
1351  }
1352 
1353 
1354  // Extra fields
1355  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
1356  // Fields from hook
1357  $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
1358  $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
1359  print $hookmanager->resPrint;
1360  // Date creation
1361  if (!empty($arrayfields['f.datec']['checked']))
1362  {
1363  print '<td class="center nowrap">';
1364  print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
1365  print '</td>';
1366  if (!$i) $totalarray['nbfield']++;
1367  }
1368  // Date modification
1369  if (!empty($arrayfields['f.tms']['checked']))
1370  {
1371  print '<td class="center nowrap">';
1372  print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser');
1373  print '</td>';
1374  if (!$i) $totalarray['nbfield']++;
1375  }
1376  // Status
1377  if (!empty($arrayfields['f.fk_statut']['checked']))
1378  {
1379  print '<td class="right nowrap">';
1380  print $facturestatic->LibStatut($obj->paye, $obj->fk_statut, 5, $paiement, $obj->type);
1381  print "</td>";
1382  if (!$i) $totalarray['nbfield']++;
1383  }
1384 
1385  // Action column
1386  print '<td class="nowrap center">';
1387  if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
1388  {
1389  $selected = 0;
1390  if (in_array($obj->facid, $arrayofselected)) $selected = 1;
1391  print '<input id="cb'.$obj->facid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->facid.'"'.($selected ? ' checked="checked"' : '').'>';
1392  }
1393  print '</td>';
1394  if (!$i) $totalarray['nbfield']++;
1395 
1396  print "</tr>\n";
1397 
1398  $i++;
1399  }
1400 
1401  // Show total line
1402  include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
1403  }
1404 
1405  $db->free($resql);
1406 
1407  $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
1408  $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters); // Note that $action and $object may have been modified by hook
1409  print $hookmanager->resPrint;
1410 
1411  print "</table>\n";
1412  print '</div>';
1413 
1414  print "</form>\n";
1415 
1416  $hidegeneratedfilelistifempty = 1;
1417  if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) $hidegeneratedfilelistifempty = 0;
1418 
1419  // Show list of available documents
1420  $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
1421  $urlsource .= str_replace('&amp;', '&', $param);
1422 
1423  $filedir = $diroutputmassaction;
1424  $genallowed = $user->rights->facture->lire;
1425  $delallowed = $user->rights->facture->creer;
1426  $title = '';
1427 
1428  print $formfile->showdocuments('massfilesarea_supplier_invoice', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
1429 } else {
1430  dol_print_error($db);
1431 }
1432 
1433 // End of page
1434 llxFooter();
1435 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
const TYPE_STANDARD
Standard invoice.
const TYPE_DEPOSIT
Deposit invoice.
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.
dol_now($mode= 'auto')
Return date for now.
Class to manage Dolibarr users.
Definition: user.class.php:44
const TYPE_REPLACEMENT
Replacement invoice.
Class to manage suppliers invoices.
Class to manage bank accounts.
Class to manage suppliers.
img_warning($titlealt= 'default', $moreatt= '', $morecss= 'pictowarning')
Show warning logo.
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...
llxHeader()
Empty header.
Definition: wrapper.php:45
Class to build HTML component for third parties management Only common components are here...
Class to manage standard extra fields.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
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.
Class to manage generation of HTML components Only common components must be here.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
Class to manage third parties objects (customers, suppliers, prospects...)
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
Class to manage projects.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is &#39;...
Classe permettant la generation de composants html autre Only common components are here...
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart= '')
Return a path to have a the directory according to object where files are stored. ...
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
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...
dol_sanitizeFileName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a file name.
dolSqlDateFilter($datefield, $day_date, $month_date, $year_date, $excludefirstand=0)
Generate a SQL string to make a filter into a range (for second of date until last second of date) ...
Definition: date.lib.php:281
Class to offer components to list and upload files.
print $_SERVER["PHP_SELF"]
Edit parameters.
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...
const TYPE_CREDIT_NOTE
Credit note invoice.
print
Draft customers invoices.
Definition: index.php:89
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
llxFooter()
Empty footer.
Definition: wrapper.php:59
getCountry($searchkey, $withcode= '', $dbtouse=0, $outputlangs= '', $entconv=1, $searchlabel= '')
Return country label, code or id from an id, code or label.