dolibarr  9.0.0
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-2016 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2013 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2013-2018 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 Frédéric France <frederic.france@netlogic.fr>
14  *
15  * This program is free software; you can redistribute it and/or modify
16  * it under the terms of the GNU General Public License as published by
17  * the Free Software Foundation; either version 3 of the License, or
18  * (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program. If not, see <http://www.gnu.org/licenses/>.
27  */
28 
35 require '../../main.inc.php';
36 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
37 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
38 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
39 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
40 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
41 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
42 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
43 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
44 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
45 
46 if (!$user->rights->fournisseur->facture->lire) accessforbidden();
47 
48 // Load translation files required by the page
49 $langs->loadLangs(array('products', 'bills', 'companies', 'projects'));
50 
51 $action=GETPOST('action','alpha');
52 $massaction=GETPOST('massaction','alpha');
53 $show_files=GETPOST('show_files','int');
54 $confirm=GETPOST('confirm','alpha');
55 $toselect = GETPOST('toselect', 'array');
56 $optioncss = GETPOST('optioncss','alpha');
57 $contextpage=GETPOST('contextpage','aZ')?GETPOST('contextpage','aZ'):'supplierinvoicelist';
58 
59 $socid = GETPOST('socid','int');
60 
61 // Security check
62 if ($user->societe_id > 0)
63 {
64  $action='';
65  $_GET["action"] = '';
66  $socid = $user->societe_id;
67 }
68 
69 $mode=GETPOST("mode");
70 
71 $search_all = trim((GETPOST('search_all', 'alphanohtml')!='')?GETPOST('search_all', 'alphanohtml'):GETPOST('sall', 'alphanohtml'));
72 $search_label = GETPOST("search_label","alpha");
73 $search_amount_no_tax = GETPOST("search_amount_no_tax","alpha");
74 $search_amount_all_tax = GETPOST("search_amount_all_tax","alpha");
75 $search_product_category=GETPOST('search_product_category','int');
76 $search_ref=GETPOST('sf_ref')?GETPOST('sf_ref','alpha'):GETPOST('search_ref','alpha');
77 $search_refsupplier=GETPOST('search_refsupplier','alpha');
78 $search_type=GETPOST('search_type','int');
79 $search_project=GETPOST('search_project','alpha');
80 $search_company=GETPOST('search_company','alpha');
81 $search_montant_ht=GETPOST('search_montant_ht','alpha');
82 $search_montant_vat=GETPOST('search_montant_vat','alpha');
83 $search_montant_localtax1=GETPOST('search_montant_localtax1','alpha');
84 $search_montant_localtax2=GETPOST('search_montant_localtax2','alpha');
85 $search_montant_ttc=GETPOST('search_montant_ttc','alpha');
86 $search_status=GETPOST('search_status','int');
87 $search_paymentmode=GETPOST('search_paymentmode','int');
88 $search_town=GETPOST('search_town','alpha');
89 $search_zip=GETPOST('search_zip','alpha');
90 $search_state=trim(GETPOST("search_state"));
91 $search_country=GETPOST("search_country",'int');
92 $search_type_thirdparty=GETPOST("search_type_thirdparty",'int');
93 $search_user = GETPOST('search_user','int');
94 $search_sale = GETPOST('search_sale','int');
95 $day = GETPOST('day','int');
96 $month = GETPOST('month','int');
97 $year = GETPOST('year','int');
98 $day_lim = GETPOST('day_lim','int');
99 $month_lim = GETPOST('month_lim','int');
100 $year_lim = GETPOST('year_lim','int');
101 $toselect = GETPOST('toselect', 'array');
102 $search_btn=GETPOST('button_search','alpha');
103 $search_remove_btn=GETPOST('button_removefilter','alpha');
104 
105 $option = GETPOST('option');
106 if ($option == 'late') {
107  $search_status = '1';
108 }
109 $filter = GETPOST('filtre','alpha');
110 
111 $limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
112 $sortfield = GETPOST("sortfield",'alpha');
113 $sortorder = GETPOST("sortorder",'alpha');
114 $page=GETPOST("page",'int');
115 if ($page == -1 || $page == null || !empty($search_btn) || !empty($search_remove_btn) || (empty($toselect) && $massaction === '0')) { $page = 0 ; }
116 $offset = $limit * $page ;
117 $pageprev = $page - 1;
118 $pagenext = $page + 1;
119 if (! $sortorder) $sortorder="DESC";
120 if (! $sortfield) $sortfield="f.datef,f.rowid";
121 
122 $diroutputmassaction=$conf->fournisseur->facture->dir_output . '/temp/massgeneration/'.$user->id;
123 
124 $now=dol_now();
125 
126 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
127 $object = new FactureFournisseur($db);
128 $hookmanager->initHooks(array('supplierinvoicelist'));
129 $extrafields = new ExtraFields($db);
130 
131 // fetch optionals attributes and labels
132 $extralabels = $extrafields->fetch_name_optionals_label('facture_fourn');
133 $search_array_options=$extrafields->getOptionalsFromPost($object->table_element,'','search_');
134 
135 // List of fields to search into when doing a "search in all"
136 $fieldstosearchall = array(
137  'f.ref'=>'Ref',
138  'f.ref_supplier'=>'RefSupplier',
139  'pd.description'=>'Description',
140  's.nom'=>"ThirdParty",
141  'f.note_public'=>'NotePublic',
142 );
143 if (empty($user->socid)) $fieldstosearchall["f.note_private"]="NotePrivate";
144 
145 $checkedtypetiers=0;
146 $arrayfields=array(
147  'f.ref'=>array('label'=>$langs->trans("Ref"), 'checked'=>1),
148  'f.ref_supplier'=>array('label'=>$langs->trans("RefSupplier"), 'checked'=>1),
149  'f.type'=>array('label'=>$langs->trans("Type"), 'checked'=>0),
150  'f.label'=>array('label'=>$langs->trans("Label"), 'checked'=>0),
151  'f.datef'=>array('label'=>$langs->trans("DateInvoice"), 'checked'=>1),
152  'f.date_lim_reglement'=>array('label'=>$langs->trans("DateDue"), 'checked'=>1),
153  'p.ref'=>array('label'=>$langs->trans("ProjectRef"), 'checked'=>0),
154  's.nom'=>array('label'=>$langs->trans("ThirdParty"), 'checked'=>1),
155  's.town'=>array('label'=>$langs->trans("Town"), 'checked'=>1),
156  's.zip'=>array('label'=>$langs->trans("Zip"), 'checked'=>1),
157  'state.nom'=>array('label'=>$langs->trans("StateShort"), 'checked'=>0),
158  'country.code_iso'=>array('label'=>$langs->trans("Country"), 'checked'=>0),
159  'typent.code'=>array('label'=>$langs->trans("ThirdPartyType"), 'checked'=>$checkedtypetiers),
160  'f.fk_mode_reglement'=>array('label'=>$langs->trans("PaymentMode"), 'checked'=>1),
161  'f.total_ht'=>array('label'=>$langs->trans("AmountHT"), 'checked'=>1),
162  'f.total_vat'=>array('label'=>$langs->trans("AmountVAT"), 'checked'=>0),
163  'f.total_localtax1'=>array('label'=>$langs->transcountry("AmountLT1", $mysoc->country_code), 'checked'=>0, 'enabled'=>$mysoc->localtax1_assuj=="1"),
164  'f.total_localtax2'=>array('label'=>$langs->transcountry("AmountLT2", $mysoc->country_code), 'checked'=>0, 'enabled'=>$mysoc->localtax2_assuj=="1"),
165  'f.total_ttc'=>array('label'=>$langs->trans("AmountTTC"), 'checked'=>0),
166  'dynamount_payed'=>array('label'=>$langs->trans("Payed"), 'checked'=>0),
167  'rtp'=>array('label'=>$langs->trans("Rest"), 'checked'=>0),
168  'f.datec'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0, 'position'=>500),
169  'f.tms'=>array('label'=>$langs->trans("DateModificationShort"), 'checked'=>0, 'position'=>500),
170  'f.fk_statut'=>array('label'=>$langs->trans("Status"), 'checked'=>1, 'position'=>1000),
171 );
172 // Extra fields
173 if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
174 {
175  foreach($extrafields->attribute_label as $key => $val)
176  {
177  if (! empty($extrafields->attribute_list[$key])) $arrayfields["ef.".$key]=array('label'=>$extrafields->attribute_label[$key], 'checked'=>(($extrafields->attribute_list[$key]<0)?0:1), 'position'=>$extrafields->attribute_pos[$key], 'enabled'=>(abs($extrafields->attribute_list[$key])!=3 && $extrafields->attribute_perms[$key]));
178  }
179 }
180 
181 
182 /*
183  * Actions
184  */
185 
186 if (GETPOST('cancel','alpha')) { $action='list'; $massaction=''; }
187 if (! GETPOST('confirmmassaction','alpha') && $massaction != 'presend' && $massaction != 'confirm_presend' && $massaction != 'confirm_createbills') { $massaction=''; }
188 
189 $parameters=array('socid'=>$socid);
190 $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
191 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
192 
193 if (empty($reshook))
194 {
195  include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
196 
197  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
198  {
199  $search_all="";
200  $search_user='';
201  $search_sale='';
202  $search_product_category='';
203  $search_ref="";
204  $search_refsupplier="";
205  $search_type="";
206  $search_label="";
207  $search_project='';
208  $search_company="";
209  $search_amount_no_tax="";
210  $search_amount_all_tax="";
211  $search_montant_ht='';
212  $search_montant_vat='';
213  $search_montant_localtax1='';
214  $search_montant_localtax2='';
215  $search_montant_ttc='';
216  $search_status='';
217  $search_paymentmode='';
218  $search_town='';
219  $search_zip="";
220  $search_state="";
221  $search_type='';
222  $search_country='';
223  $search_type_thirdparty='';
224  $year="";
225  $month="";
226  $day="";
227  $year_lim="";
228  $month_lim="";
229  $day_lim="";
230  $toselect='';
231  $search_array_options=array();
232  $filter='';
233  $option='';
234  }
235 
236  // Mass actions
237  $objectclass='FactureFournisseur';
238  $objectlabel='SupplierInvoices';
239  $permtoread = $user->rights->fournisseur->facture->lire;
240  $permtocreate = $user->rights->fournisseur->facture->creer;
241  $permtodelete = $user->rights->fournisseur->facture->supprimer;
242  $uploaddir = $conf->fournisseur->facture->dir_output;
243  include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
244 }
245 
246 
247 /*
248  * View
249  */
250 
251 $form=new Form($db);
252 $formother=new FormOther($db);
253 $formfile = new FormFile($db);
254 $bankaccountstatic=new Account($db);
255 $facturestatic=new FactureFournisseur($db);
256 $formcompany=new FormCompany($db);
257 $thirdparty=new Societe($db);
258 
259 // llxHeader('',$langs->trans("SuppliersInvoices"),'EN:Suppliers_Invoices|FR:FactureFournisseur|ES:Facturas_de_proveedores');
260 
261 $sql = "SELECT";
262 if ($search_all || $search_product_category > 0) $sql = 'SELECT DISTINCT';
263 $sql.= " f.rowid as facid, f.ref, f.ref_supplier, f.type, f.datef, f.date_lim_reglement as datelimite, f.fk_mode_reglement,";
264 $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,";
265 $sql.= " f.localtax1 as total_localtax1, f.localtax2 as total_localtax2,";
266 $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,";
267 $sql.= " typent.code as typent_code,";
268 $sql.= " state.code_departement as state_code, state.nom as state_name,";
269 $sql.= " country.code as country_code,";
270 $sql.= " p.rowid as project_id, p.ref as project_ref, p.title as project_label";
271 // 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)
272 // TODO Better solution to be able to sort on already payed or remain to pay is to store amount_payed in a denormalized field.
273 if (! $search_all) $sql.= ', SUM(pf.amount) as dynamount_payed';
274 // Add fields from extrafields
275 foreach ($extrafields->attribute_label as $key => $val) $sql.=($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key.' as options_'.$key : '');
276 // Add fields from hooks
277 $parameters=array();
278 $reshook=$hookmanager->executeHooks('printFieldListSelect',$parameters); // Note that $action and $object may have been modified by hook
279 $sql.=$hookmanager->resPrint;
280 $sql.= ' FROM '.MAIN_DB_PREFIX.'societe as s';
281 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
282 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
283 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)";
284 $sql.= ', '.MAIN_DB_PREFIX.'facture_fourn as f';
285 if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture_fourn_extrafields as ef on (f.rowid = ef.fk_object)";
286 if (! $search_all) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf ON pf.fk_facturefourn = f.rowid';
287 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';
288 if ($search_product_category > 0) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=pd.fk_product';
289 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."projet as p ON p.rowid = f.fk_projet";
290 // We'll need this table joined to the select in order to filter by sale
291 if ($search_sale > 0 || (! $user->rights->societe->client->voir && ! $socid)) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
292 if ($search_user > 0)
293 {
294  $sql.=", ".MAIN_DB_PREFIX."element_contact as ec";
295  $sql.=", ".MAIN_DB_PREFIX."c_type_contact as tc";
296 }
297 $sql.= ' WHERE f.fk_soc = s.rowid';
298 $sql.= ' AND f.entity IN ('.getEntity('facture_fourn').')';
299 if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
300 if ($search_product_category > 0) $sql.=" AND cp.fk_categorie = ".$search_product_category;
301 if ($socid > 0) $sql .= ' AND s.rowid = '.$socid;
302 if ($search_ref)
303 {
304  if (is_numeric($search_ref)) $sql .= natural_search(array('f.ref'), $search_ref);
305  else $sql .= natural_search('f.ref', $search_ref);
306 }
307 if ($search_ref) $sql .= natural_search('f.ref', $search_ref);
308 if ($search_refsupplier) $sql .= natural_search('f.ref_supplier', $search_refsupplier);
309 if ($search_type != '' && $search_type >= 0)
310 {
311  if ($search_type == '0') $sql.=" AND f.type = 0"; // standard
312  if ($search_type == '1') $sql.=" AND f.type = 1"; // replacement
313  if ($search_type == '2') $sql.=" AND f.type = 2"; // credit note
314  if ($search_type == '3') $sql.=" AND f.type = 3"; // deposit
315  //if ($search_type == '4') $sql.=" AND f.type = 4"; // proforma
316  //if ($search_type == '5') $sql.=" AND f.type = 5"; // situation
317 }
318 if ($search_project) $sql .= natural_search('p.ref', $search_project);
319 if ($search_company) $sql .= natural_search('s.nom', $search_company);
320 if ($search_town) $sql.= natural_search('s.town', $search_town);
321 if ($search_zip) $sql.= natural_search("s.zip",$search_zip);
322 if ($search_state) $sql.= natural_search("state.nom",$search_state);
323 if ($search_country) $sql .= " AND s.fk_pays IN (".$search_country.')';
324 if ($search_type_thirdparty) $sql .= " AND s.fk_typent IN (".$search_type_thirdparty.')';
325 if ($search_montant_ht != '') $sql.= natural_search('f.total_ht', $search_montant_ht, 1);
326 if ($search_montant_vat != '') $sql.= natural_search('f.total_tva', $search_montant_vat, 1);
327 if ($search_montant_localtax1 != '') $sql.= natural_search('f.localtax1', $search_montant_localtax1, 1);
328 if ($search_montant_localtax2 != '') $sql.= natural_search('f.localtax2', $search_montant_localtax2, 1);
329 if ($search_montant_ttc != '') $sql.= natural_search('f.total_ttc', $search_montant_ttc, 1);
330 if ($search_status != '' && $search_status >= 0) $sql.= " AND f.fk_statut = ".$db->escape($search_status);
331 if ($search_paymentmode > 0) $sql .= " AND f.fk_mode_reglement = ".$search_paymentmode."";
332 if ($month > 0)
333 {
334  if ($year > 0 && empty($day))
335  $sql.= " AND f.datef BETWEEN '".$db->idate(dol_get_first_day($year,$month,false))."' AND '".$db->idate(dol_get_last_day($year,$month,false))."'";
336  else if ($year > 0 && ! empty($day))
337  $sql.= " AND f.datef BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month, $day, $year))."' AND '".$db->idate(dol_mktime(23, 59, 59, $month, $day, $year))."'";
338  else
339  $sql.= " AND date_format(f.datef, '%m') = '".$month."'";
340 }
341 else if ($year > 0)
342 {
343  $sql.= " AND f.datef BETWEEN '".$db->idate(dol_get_first_day($year,1,false))."' AND '".$db->idate(dol_get_last_day($year,12,false))."'";
344 }
345 if ($month_lim > 0)
346 {
347  if ($year_lim > 0 && empty($day_lim))
348  $sql.= " AND f.date_lim_reglement BETWEEN '".$db->idate(dol_get_first_day($year_lim,$month_lim,false))."' AND '".$db->idate(dol_get_last_day($year_lim,$month_lim,false))."'";
349  else if ($year_lim > 0 && ! empty($day_lim))
350  $sql.= " AND f.date_lim_reglement BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month_lim, $day_lim, $year_lim))."' AND '".$db->idate(dol_mktime(23, 59, 59, $month_lim, $day_lim, $year_lim))."'";
351  else
352  $sql.= " AND date_format(f.date_lim_reglement, '%m') = '".$db->escape($month_lim)."'";
353 }
354 else if ($year_lim > 0)
355 {
356  $sql.= " AND f.date_lim_reglement BETWEEN '".$db->idate(dol_get_first_day($year_lim,1,false))."' AND '".$db->idate(dol_get_last_day($year_lim,12,false))."'";
357 }
358 if ($option == 'late') $sql.=" AND f.date_lim_reglement < '".$db->idate(dol_now() - $conf->facture->fournisseur->warning_delay)."'";
359 if ($search_label) $sql .= natural_search('f.libelle', $search_label);
360 if ($search_status != '' && $search_status >= 0)
361 {
362  $sql.= " AND f.fk_statut = ".$search_status;
363 }
364 if ($filter && $filter != -1)
365 {
366  $aFilter = explode(',', $filter);
367  foreach ($aFilter as $fil)
368  {
369  $filt = explode(':', $fil);
370  $sql .= ' AND ' . $db->escape(trim($filt[0])) . ' = ' . $db->escape(trim($filt[1]));
371  }
372 }
373 if ($search_sale > 0) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$db->escape($search_sale);
374 if ($search_user > 0)
375 {
376  $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;
377 }
378 // Add where from extra fields
379 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
380 // Add where from hooks
381 $parameters=array();
382 $reshook=$hookmanager->executeHooks('printFieldListWhere',$parameters); // Note that $action and $object may have been modified by hook
383 $sql.=$hookmanager->resPrint;
384 
385 if (! $search_all)
386 {
387  $sql.= " GROUP BY f.rowid, f.ref, f.ref_supplier, f.type, f.datef, f.date_lim_reglement, f.fk_mode_reglement,";
388  $sql.= " f.total_ht, f.total_ttc, f.total_tva, f.paye, f.fk_statut, f.libelle, f.datec, f.tms,";
389  $sql.= " f.localtax1, f.localtax2,";
390  $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,';
391  $sql.= " typent.code,";
392  $sql.= " state.code_departement, state.nom,";
393  $sql.= ' country.code,';
394  $sql.= " p.rowid, p.ref";
395 
396  foreach ($extrafields->attribute_label as $key => $val) //prevent error with sql_mode=only_full_group_by
397  {
398  $sql.=($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key : '');
399  }
400 }
401 else
402 {
403  $sql.= natural_search(array_keys($fieldstosearchall), $search_all);
404 }
405 
406 $sql.= $db->order($sortfield,$sortorder);
407 
408 $nbtotalofrecords = '';
409 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
410 {
411  $result = $db->query($sql);
412  $nbtotalofrecords = $db->num_rows($result);
413  if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0
414  {
415  $page = 0;
416  $offset = 0;
417  }
418 }
419 
420 $sql.= $db->plimit($limit+1, $offset);
421 //print $sql;
422 
423 $resql = $db->query($sql);
424 if ($resql)
425 {
426  $num = $db->num_rows($resql);
427 
428  $arrayofselected=is_array($toselect)?$toselect:array();
429 
430  if ($num == 1 && ! empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $sall)
431  {
432  $obj = $db->fetch_object($resql);
433  $id = $obj->facid;
434 
435  header("Location: ".DOL_URL_ROOT.'/fourn/facture/card.php?facid='.$id);
436  exit;
437  }
438 
439  llxHeader('',$langs->trans("SuppliersInvoices"),'EN:Suppliers_Invoices|FR:FactureFournisseur|ES:Facturas_de_proveedores');
440 
441  if ($socid)
442  {
443  $soc = new Societe($db);
444  $soc->fetch($socid);
445  if (empty($search_company)) $search_company = $soc->name;
446  }
447 
448  $param='&socid='.$socid;
449  if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
450  if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
451  if ($search_all) $param.='&search_all='.urlencode($search_all);
452  if ($day) $param.='&day='.urlencode($day);
453  if ($month) $param.='&month='.urlencode($month);
454  if ($year) $param.='&year=' .urlencode($year);
455  if ($day_lim) $param.='&day_lim='.urlencode($day_lim);
456  if ($month_lim) $param.='&month_lim='.urlencode($month_lim);
457  if ($year_lim) $param.='&year_lim=' .urlencode($year_lim);
458  if ($search_ref) $param.='&search_ref='.urlencode($search_ref);
459  if ($search_refsupplier) $param.='&search_refsupplier='.urlencode($search_refsupplier);
460  if ($search_type != '') $param.='&search_type='.urlencode($search_type);
461  if ($search_label) $param.='&search_label='.urlencode($search_label);
462  if ($search_company) $param.='&search_company='.urlencode($search_company);
463  if ($search_montant_ht != '') $param.='&search_montant_ht='.urlencode($search_montant_ht);
464  if ($search_montant_vat != '') $param.='&search_montant_vat='.urlencode($search_montant_vat);
465  if ($search_montant_localtax1 != '') $param.='&search_montant_localtax1='.urlencode($search_montant_localtax1);
466  if ($search_montant_localtax2 != '') $param.='&search_montant_localtax2='.urlencode($search_montant_localtax2);
467  if ($search_montant_ttc != '') $param.='&search_montant_ttc='.urlencode($search_montant_ttc);
468  if ($search_amount_no_tax) $param.='&search_amount_no_tax='.urlencode($search_amount_no_tax);
469  if ($search_amount_all_tax) $param.='&search_amount_all_tax='.urlencode($search_amount_all_tax);
470  if ($search_status >= 0) $param.="&search_status=".urlencode($search_status);
471  if ($show_files) $param.='&show_files=' .$show_files;
472  if ($option) $param.="&option=".$option;
473  if ($optioncss != '') $param.='&optioncss='.$optioncss;
474  // Add $param from extra fields
475  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
476 
477  // List of mass actions available
478  $arrayofmassactions = array(
479  'validate'=>$langs->trans("Validate"),
480  //'presend'=>$langs->trans("SendByMail"),
481  //'builddoc'=>$langs->trans("PDFMerge"),
482  );
483  //if($user->rights->fournisseur->facture->creer) $arrayofmassactions['createbills']=$langs->trans("CreateInvoiceForThisCustomer");
484  if ($user->rights->fournisseur->facture->supprimer) $arrayofmassactions['predelete']=$langs->trans("Delete");
485  if (in_array($massaction, array('presend','predelete','createbills'))) $arrayofmassactions=array();
486  $massactionbutton=$form->selectMassAction('', $arrayofmassactions);
487 
488  $newcardbutton='';
489  if ($user->rights->fournisseur->facture->creer)
490  {
491  $newcardbutton='<a class="butActionNew" href="'.DOL_URL_ROOT.'/fourn/facture/card.php?action=create"><span class="valignmiddle">'.$langs->trans('NewBill').'</span>';
492  $newcardbutton.= '<span class="fa fa-plus-circle valignmiddle"></span>';
493  $newcardbutton.= '</a>';
494  }
495 
496  $i = 0;
497  print '<form method="POST" name="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
498  if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
499  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
500  print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
501  print '<input type="hidden" name="action" value="list">';
502  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
503  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
504  print '<input type="hidden" name="page" value="'.$page.'">';
505  print '<input type="hidden" name="viewstatut" value="'.$viewstatut.'">';
506  print '<input type="hidden" name="socid" value="'.$socid.'">';
507 
508  print_barre_liste($langs->trans("BillsSuppliers").($socid?' '.$soc->name:''), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'title_accountancy', 0, $newcardbutton, '', $limit);
509 
510  $topicmail="SendBillRef";
511  $modelmail="supplier_invoice_send";
512  $objecttmp=new FactureFournisseur($db);
513  $trackid='sinv'.$object->id;
514  include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
515 
516  if ($massaction == 'createbills')
517  {
518  //var_dump($_REQUEST);
519  print '<input type="hidden" name="massaction" value="confirm_createbills">';
520 
521  print '<table class="border" width="100%" >';
522  print '<tr>';
523  print '<td class="titlefieldmiddle">';
524  print $langs->trans('DateInvoice');
525  print '</td>';
526  print '<td>';
527  print $form->selectDate('', '', '', '', '', '', 1, 1);
528  print '</td>';
529  print '</tr>';
530  print '<tr>';
531  print '<td>';
532  print $langs->trans('CreateOneBillByThird');
533  print '</td>';
534  print '<td>';
535  print $form->selectyesno('createbills_onebythird', '', 1);
536  print '</td>';
537  print '</tr>';
538  print '<tr>';
539  print '<td>';
540  print $langs->trans('ValidateInvoices');
541  print '</td>';
542  print '<td>';
543  print $form->selectyesno('valdate_invoices', 1, 1);
544  print '</td>';
545  print '</tr>';
546  print '</table>';
547 
548  print '<br>';
549  print '<div class="center">';
550  print '<input type="submit" class="button" id="createbills" name="createbills" value="'.$langs->trans('CreateInvoiceForThisCustomer').'"> ';
551  print '<input type="submit" class="button" id="cancel" name="cancel" value="'.$langs->trans('Cancel').'">';
552  print '</div>';
553  print '<br>';
554  }
555 
556  if ($search_all)
557  {
558  foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val);
559  print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all) . join(', ',$fieldstosearchall).'</div>';
560  }
561 
562  // If the user can view prospects other than his'
563  $moreforfilter='';
564  if ($user->rights->societe->client->voir || $socid)
565  {
566  $langs->load("commercial");
567  $moreforfilter.='<div class="divsearchfield">';
568  $moreforfilter.=$langs->trans('ThirdPartiesOfSaleRepresentative'). ': ';
569  $moreforfilter.=$formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, 1, 'maxwidth200');
570  $moreforfilter.='</div>';
571  }
572  // If the user can view prospects other than his'
573  if ($user->rights->societe->client->voir || $socid)
574  {
575  $moreforfilter.='<div class="divsearchfield">';
576  $moreforfilter.=$langs->trans('LinkedToSpecificUsers'). ': ';
577  $moreforfilter.=$form->select_dolusers($search_user, 'search_user', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth200');
578  $moreforfilter.='</div>';
579  }
580  // If the user can view prospects other than his'
581  if ($conf->categorie->enabled && ($user->rights->produit->lire || $user->rights->service->lire))
582  {
583  include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
584  $moreforfilter.='<div class="divsearchfield">';
585  $moreforfilter.=$langs->trans('IncludingProductWithTag'). ': ';
586  $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, null, 'parent', null, null, 1);
587  $moreforfilter.=$form->selectarray('search_product_category', $cate_arbo, $search_product_category, 1, 0, 0, '', 0, 0, 0, 0, 'maxwidth300', 1);
588  $moreforfilter.='</div>';
589  }
590  $parameters=array();
591  $reshook=$hookmanager->executeHooks('printFieldPreListTitle',$parameters); // Note that $action and $object may have been modified by hook
592  if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint;
593  else $moreforfilter = $hookmanager->resPrint;
594 
595  if ($moreforfilter)
596  {
597  print '<div class="liste_titre liste_titre_bydiv centpercent">';
598  print $moreforfilter;
599  print '</div>';
600  }
601 
602  $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
603  $selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
604  if ($massactionbutton) $selectedfields.=$form->showCheckAddButtons('checkforselect', 1);
605 
606  print '<div class="div-table-responsive">';
607  print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
608 
609  // Line for filters
610  print '<tr class="liste_titre_filter">';
611  // Ref
612  if (! empty($arrayfields['f.ref']['checked']))
613  {
614  print '<td class="liste_titre" align="left">';
615  print '<input class="flat" size="6" type="text" name="search_ref" value="'.$search_ref.'">';
616  print '</td>';
617  }
618  // Ref supplier
619  if (! empty($arrayfields['f.ref_supplier']['checked']))
620  {
621  print '<td class="liste_titre">';
622  print '<input class="flat" size="6" type="text" name="search_refsupplier" value="'.$search_refsupplier.'">';
623  print '</td>';
624  }
625  // Type
626  if (! empty($arrayfields['f.type']['checked']))
627  {
628  print '<td class="liste_titre maxwidthonsmartphone">';
629  $listtype=array(
630  FactureFournisseur::TYPE_STANDARD=>$langs->trans("InvoiceStandard"),
631  FactureFournisseur::TYPE_REPLACEMENT=>$langs->trans("InvoiceReplacement"),
632  FactureFournisseur::TYPE_CREDIT_NOTE=>$langs->trans("InvoiceAvoir"),
633  FactureFournisseur::TYPE_DEPOSIT=>$langs->trans("InvoiceDeposit"),
634  );
635 /*
636  if (! empty($conf->global->INVOICE_USE_SITUATION))
637  {
638  $listtype[Facture::TYPE_SITUATION] = $langs->trans("InvoiceSituation");
639  }
640 */
641  //$listtype[Facture::TYPE_PROFORMA]=$langs->trans("InvoiceProForma"); // A proformat invoice is not an invoice but must be an order.
642  print $form->selectarray('search_type', $listtype, $search_type, 1, 0, 0, '', 0, 0, 0, 'ASC', 'maxwidth100');
643  print '</td>';
644  }
645  // Label
646  if (! empty($arrayfields['f.label']['checked']))
647  {
648  print '<td class="liste_titre">';
649  print '<input class="flat" size="6" type="text" name="search_label" value="'.$search_label.'">';
650  print '</td>';
651  }
652  // Date invoice
653  if (! empty($arrayfields['f.datef']['checked']))
654  {
655  print '<td class="liste_titre nowraponall" align="center">';
656  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).'">';
657  print '<input class="flat width25 valignmiddle" type="text" size="1" maxlength="2" name="month" value="'.$month.'">';
658  $formother->select_year($year?$year:-1,'year',1, 20, 5);
659  print '</td>';
660  }
661  // Date due
662  if (! empty($arrayfields['f.date_lim_reglement']['checked']))
663  {
664  print '<td class="liste_titre nowraponall" align="center">';
665  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).'">';
666  print '<input class="flat width25 valignmiddle" type="text" maxlength="2" name="month_lim" value="'.$month_lim.'">';
667  $formother->select_year($year_lim?$year_lim:-1,'year_lim',1, 20, 5);
668  print '<br><input type="checkbox" name="option" value="late"'.($option == 'late'?' checked':'').'> '.$langs->trans("Late");
669  print '</td>';
670  }
671  // Project
672  if (! empty($arrayfields['p.ref']['checked']))
673  {
674  print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_project" value="'.$search_project.'"></td>';
675  }
676  // Thirpdarty
677  if (! empty($arrayfields['s.nom']['checked']))
678  {
679  print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_company" value="'.$search_company.'"></td>';
680  }
681  // Town
682  if (! empty($arrayfields['s.town']['checked'])) print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_town" value="'.dol_escape_htmltag($search_town).'"></td>';
683  // Zip
684  if (! empty($arrayfields['s.zip']['checked'])) print '<td class="liste_titre"><input class="flat" type="text" size="4" name="search_zip" value="'.dol_escape_htmltag($search_zip).'"></td>';
685  // State
686  if (! empty($arrayfields['state.nom']['checked']))
687  {
688  print '<td class="liste_titre">';
689  print '<input class="flat" size="4" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
690  print '</td>';
691  }
692  // Country
693  if (! empty($arrayfields['country.code_iso']['checked']))
694  {
695  print '<td class="liste_titre" align="center">';
696  print $form->select_country($search_country,'search_country','',0,'maxwidth100');
697  print '</td>';
698  }
699  // Company type
700  if (! empty($arrayfields['typent.code']['checked']))
701  {
702  print '<td class="liste_titre maxwidthonsmartphone" align="center">';
703  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));
704  print '</td>';
705  }
706  // Payment mode
707  if (! empty($arrayfields['f.fk_mode_reglement']['checked']))
708  {
709  print '<td class="liste_titre" align="left">';
710  $form->select_types_paiements($search_paymentmode, 'search_paymentmode', '', 0, 1, 1, 10);
711  print '</td>';
712  }
713  if (! empty($arrayfields['f.total_ht']['checked']))
714  {
715  // Amount
716  print '<td class="liste_titre" align="right">';
717  print '<input class="flat" type="text" size="5" name="search_montant_ht" value="'.dol_escape_htmltag($search_montant_ht).'">';
718  print '</td>';
719  }
720  if (! empty($arrayfields['f.total_vat']['checked']))
721  {
722  // Amount
723  print '<td class="liste_titre" align="right">';
724  print '<input class="flat" type="text" size="5" name="search_montant_vat" value="'.dol_escape_htmltag($search_montant_vat).'">';
725  print '</td>';
726  }
727  if (! empty($arrayfields['f.total_localtax1']['checked']))
728  {
729  // Amount
730  print '<td class="liste_titre" align="right">';
731  print '<input class="flat" type="text" size="5" name="search_montant_localtax1" value="'.$search_montant_localtax1.'">';
732  print '</td>';
733  }
734  if (! empty($arrayfields['f.total_localtax2']['checked']))
735  {
736  // Amount
737  print '<td class="liste_titre" align="right">';
738  print '<input class="flat" type="text" size="5" name="search_montant_localtax2" value="'.$search_montant_localtax2.'">';
739  print '</td>';
740  }
741  if (! empty($arrayfields['f.total_ttc']['checked']))
742  {
743  // Amount
744  print '<td class="liste_titre" align="right">';
745  print '<input class="flat" type="text" size="5" name="search_montant_ttc" value="'.dol_escape_htmltag($search_montant_ttc).'">';
746  print '</td>';
747  }
748  if (! empty($arrayfields['dynamount_payed']['checked']))
749  {
750  print '<td class="liste_titre" align="right">';
751  print '</td>';
752  }
753  if (! empty($arrayfields['rtp']['checked']))
754  {
755  print '<td class="liste_titre" align="right">';
756  print '</td>';
757  }
758  // Extra fields
759  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
760 
761  // Fields from hook
762  $parameters=array('arrayfields'=>$arrayfields);
763  $reshook=$hookmanager->executeHooks('printFieldListOption',$parameters); // Note that $action and $object may have been modified by hook
764  print $hookmanager->resPrint;
765  // Date creation
766  if (! empty($arrayfields['f.datec']['checked']))
767  {
768  print '<td class="liste_titre">';
769  print '</td>';
770  }
771  // Date modification
772  if (! empty($arrayfields['f.tms']['checked']))
773  {
774  print '<td class="liste_titre">';
775  print '</td>';
776  }
777  // Status
778  if (! empty($arrayfields['f.fk_statut']['checked']))
779  {
780  print '<td class="liste_titre maxwidthonsmartphone" align="right">';
781  $liststatus=array('0'=>$langs->trans("Draft"),'1'=>$langs->trans("Unpaid"), '2'=>$langs->trans("Paid"));
782  print $form->selectarray('search_status', $liststatus, $search_status, 1);
783  print '</td>';
784  }
785  // Action column
786  print '<td class="liste_titre" align="middle">';
787  $searchpicto=$form->showFilterButtons();
788  print $searchpicto;
789  print '</td>';
790 
791  print "</tr>\n";
792 
793  print '<tr class="liste_titre">';
794  if (! empty($arrayfields['f.ref']['checked'])) print_liste_field_titre($arrayfields['f.ref']['label'],$_SERVER['PHP_SELF'],'f.ref,f.rowid','',$param,'',$sortfield,$sortorder);
795  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);
796  if (! empty($arrayfields['f.type']['checked'])) print_liste_field_titre($arrayfields['f.type']['label'],$_SERVER["PHP_SELF"],'f.type','',$param,'',$sortfield,$sortorder);
797  if (! empty($arrayfields['f.label']['checked'])) print_liste_field_titre($arrayfields['f.label']['label'],$_SERVER['PHP_SELF'],"f.libelle,f.rowid",'',$param,'',$sortfield,$sortorder);
798  if (! empty($arrayfields['f.datef']['checked'])) print_liste_field_titre($arrayfields['f.datef']['label'],$_SERVER['PHP_SELF'],'f.datef,f.rowid','',$param,'align="center"',$sortfield,$sortorder);
799  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,'align="center"',$sortfield,$sortorder);
800  if (! empty($arrayfields['p.ref']['checked'])) print_liste_field_titre($arrayfields['p.ref']['label'],$_SERVER['PHP_SELF'],"p.ref",'',$param,'',$sortfield,$sortorder);
801  if (! empty($arrayfields['s.nom']['checked'])) print_liste_field_titre($arrayfields['s.nom']['label'],$_SERVER['PHP_SELF'],'s.nom','',$param,'',$sortfield,$sortorder);
802  if (! empty($arrayfields['s.town']['checked'])) print_liste_field_titre($arrayfields['s.town']['label'],$_SERVER["PHP_SELF"],'s.town','',$param,'',$sortfield,$sortorder);
803  if (! empty($arrayfields['s.zip']['checked'])) print_liste_field_titre($arrayfields['s.zip']['label'],$_SERVER["PHP_SELF"],'s.zip','',$param,'',$sortfield,$sortorder);
804  if (! empty($arrayfields['state.nom']['checked'])) print_liste_field_titre($arrayfields['state.nom']['label'],$_SERVER["PHP_SELF"],"state.nom","",$param,'',$sortfield,$sortorder);
805  if (! empty($arrayfields['country.code_iso']['checked'])) print_liste_field_titre($arrayfields['country.code_iso']['label'],$_SERVER["PHP_SELF"],"country.code_iso","",$param,'align="center"',$sortfield,$sortorder);
806  if (! empty($arrayfields['typent.code']['checked'])) print_liste_field_titre($arrayfields['typent.code']['label'],$_SERVER["PHP_SELF"],"typent.code","",$param,'align="center"',$sortfield,$sortorder);
807  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);
808  if (! empty($arrayfields['f.total_ht']['checked'])) print_liste_field_titre($arrayfields['f.total_ht']['label'],$_SERVER['PHP_SELF'],'f.total','',$param,'align="right"',$sortfield,$sortorder);
809  if (! empty($arrayfields['f.total_vat']['checked'])) print_liste_field_titre($arrayfields['f.total_vat']['label'],$_SERVER['PHP_SELF'],'f.tva','',$param,'align="right"',$sortfield,$sortorder);
810  if (! empty($arrayfields['f.total_localtax1']['checked'])) print_liste_field_titre($arrayfields['f.total_localtax1']['label'],$_SERVER['PHP_SELF'],'f.localtax1','',$param,'align="right"',$sortfield,$sortorder);
811  if (! empty($arrayfields['f.total_localtax2']['checked'])) print_liste_field_titre($arrayfields['f.total_localtax2']['label'],$_SERVER['PHP_SELF'],'f.localtax2','',$param,'align="right"',$sortfield,$sortorder);
812  if (! empty($arrayfields['f.total_ttc']['checked'])) print_liste_field_titre($arrayfields['f.total_ttc']['label'],$_SERVER['PHP_SELF'],'f.total_ttc','',$param,'align="right"',$sortfield,$sortorder);
813  if (! empty($arrayfields['dynamount_payed']['checked'])) print_liste_field_titre($arrayfields['dynamount_payed']['label'],$_SERVER['PHP_SELF'],'','',$param,'align="right"',$sortfield,$sortorder);
814  if (! empty($arrayfields['rtp']['checked'])) print_liste_field_titre($arrayfields['rtp']['label'],$_SERVER['PHP_SELF'],'','',$param,'align="right"',$sortfield,$sortorder);
815  // Extra fields
816  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
817  // Hook fields
818  $parameters=array('arrayfields'=>$arrayfields,'param'=>$param,'sortfield'=>$sortfield,'sortorder'=>$sortorder);
819  $reshook=$hookmanager->executeHooks('printFieldListTitle',$parameters); // Note that $action and $object may have been modified by hook
820  print $hookmanager->resPrint;
821  if (! empty($arrayfields['f.datec']['checked'])) print_liste_field_titre($arrayfields['f.datec']['label'],$_SERVER["PHP_SELF"],"f.datec","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
822  if (! empty($arrayfields['f.tms']['checked'])) print_liste_field_titre($arrayfields['f.tms']['label'],$_SERVER["PHP_SELF"],"f.tms","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
823  if (! empty($arrayfields['f.fk_statut']['checked'])) print_liste_field_titre($arrayfields['f.fk_statut']['label'],$_SERVER["PHP_SELF"],"fk_statut,paye,type","",$param,'align="right"',$sortfield,$sortorder);
824  print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'','','align="center"',$sortfield,$sortorder,'maxwidthsearch ');
825  print "</tr>\n";
826 
827  $facturestatic=new FactureFournisseur($db);
828  $supplierstatic=new Fournisseur($db);
829  $projectstatic=new Project($db);
830 
831  if ($num > 0)
832  {
833  $i=0;
834  $totalarray=array();
835  while ($i < min($num,$limit))
836  {
837  $obj = $db->fetch_object($resql);
838 
839  $datelimit=$db->jdate($obj->datelimite);
840  $facturestatic->id=$obj->facid;
841  $facturestatic->ref=$obj->ref;
842  $facturestatic->type=$obj->type;
843  $facturestatic->ref_supplier=$obj->ref_supplier;
844  $facturestatic->date_echeance = $db->jdate($obj->datelimite);
845  $facturestatic->statut = $obj->fk_statut;
846 
847  $thirdparty->id=$obj->socid;
848  $thirdparty->name=$obj->name;
849  $thirdparty->client=$obj->client;
850  $thirdparty->fournisseur=$obj->fournisseur;
851  $thirdparty->code_client=$obj->code_client;
852  $thirdparty->code_compta_client=$obj->code_compta_client;
853  $thirdparty->code_fournisseur=$obj->code_fournisseur;
854  $thirdparty->code_compta_fournisseur=$obj->code_compta_fournisseur;
855  $thirdparty->email=$obj->email;
856  $thirdparty->country_code=$obj->country_code;
857 
858  $paiement = $facturestatic->getSommePaiement();
859  $totalcreditnotes = $facturestatic->getSumCreditNotesUsed();
860  $totaldeposits = $facturestatic->getSumDepositsUsed();
861  $totalpay = $paiement + $totalcreditnotes + $totaldeposits;
862  $remaintopay = $obj->total_ttc - $totalpay;
863 
864  print '<tr class="oddeven">';
865  if (! empty($arrayfields['f.ref']['checked']))
866  {
867  print '<td class="nowrap">';
868 
869  print '<table class="nobordernopadding"><tr class="nocellnopadd">';
870  // Picto + Ref
871  print '<td class="nobordernopadding nowrap">';
872  print $facturestatic->getNomUrl(1);
873  print '</td>';
874  // Warning
875  //print '<td style="min-width: 20px" class="nobordernopadding nowrap">';
876  //print '</td>';
877  // Other picto tool
878  print '<td width="16" align="right" class="nobordernopadding hideonsmartphone">';
879  $filename=dol_sanitizeFileName($obj->ref);
880  $filedir=$conf->fournisseur->facture->dir_output.'/'.get_exdir($obj->facid,2,0,0,$facturestatic,'invoice_supplier').dol_sanitizeFileName($obj->ref);
881  $subdir = get_exdir($obj->facid,2,0,0,$facturestatic,'invoice_supplier').dol_sanitizeFileName($obj->ref);
882  print $formfile->getDocumentsLink('facture_fournisseur', $subdir, $filedir);
883  print '</td></tr></table>';
884 
885  print "</td>\n";
886  if (! $i) $totalarray['nbfield']++;
887  }
888 
889  // Supplier ref
890  if (! empty($arrayfields['f.ref_supplier']['checked']))
891  {
892  print '<td class="nowrap">';
893  print $obj->ref_supplier;
894  print '</td>';
895  if (! $i) $totalarray['nbfield']++;
896  }
897 
898  // Type
899  if (! empty($arrayfields['f.type']['checked']))
900  {
901  print '<td class="nowrap">';
902  print $facturestatic->getLibType();
903  print "</td>";
904  if (! $i) $totalarray['nbfield']++;
905  }
906 
907  // Label
908  if (! empty($arrayfields['f.label']['checked']))
909  {
910  print '<td class="nowrap">';
911  print $obj->label;
912  print '</td>';
913  if (! $i) $totalarray['nbfield']++;
914  }
915 
916  // Date
917  if (! empty($arrayfields['f.datef']['checked']))
918  {
919  print '<td align="center" class="nowrap">';
920  print dol_print_date($db->jdate($obj->datef),'day');
921  print '</td>';
922  if (! $i) $totalarray['nbfield']++;
923  }
924 
925  // Date limit
926  if (! empty($arrayfields['f.date_lim_reglement']['checked']))
927  {
928  print '<td align="center" class="nowrap">'.dol_print_date($datelimit,'day');
929  if ($facturestatic->hasDelay())
930  {
931  print img_warning($langs->trans('Late'));
932  }
933  print '</td>';
934  if (! $i) $totalarray['nbfield']++;
935  }
936 
937  // Project
938  if (! empty($arrayfields['p.ref']['checked']))
939  {
940  print '<td class="nowrap">';
941  if ($obj->project_id > 0)
942  {
943  $projectstatic->id=$obj->project_id;
944  $projectstatic->ref=$obj->project_ref;
945  $projectstatic->title=$obj->project_label;
946  print $projectstatic->getNomUrl(1);
947  }
948  print '</td>';
949  if (! $i) $totalarray['nbfield']++;
950  }
951 
952  // Third party
953  if (! empty($arrayfields['s.nom']['checked']))
954  {
955  print '<td class="tdoverflowmax200">';
956  print $thirdparty->getNomUrl(1,'supplier');
957  print '</td>';
958  if (! $i) $totalarray['nbfield']++;
959  }
960  // Town
961  if (! empty($arrayfields['s.town']['checked']))
962  {
963  print '<td class="nocellnopadd">';
964  print $obj->town;
965  print '</td>';
966  if (! $i) $totalarray['nbfield']++;
967  }
968  // Zip
969  if (! empty($arrayfields['s.zip']['checked']))
970  {
971  print '<td class="nocellnopadd">';
972  print $obj->zip;
973  print '</td>';
974  if (! $i) $totalarray['nbfield']++;
975  }
976  // State
977  if (! empty($arrayfields['state.nom']['checked']))
978  {
979  print "<td>".$obj->state_name."</td>\n";
980  if (! $i) $totalarray['nbfield']++;
981  }
982  // Country
983  if (! empty($arrayfields['country.code_iso']['checked']))
984  {
985  print '<td align="center">';
986  $tmparray=getCountry($obj->fk_pays,'all');
987  print $tmparray['label'];
988  print '</td>';
989  if (! $i) $totalarray['nbfield']++;
990  }
991  // Type ent
992  if (! empty($arrayfields['typent.code']['checked']))
993  {
994  print '<td align="center">';
995  if (count($typenArray)==0) $typenArray = $formcompany->typent_array(1);
996  print $typenArray[$obj->typent_code];
997  print '</td>';
998  if (! $i) $totalarray['nbfield']++;
999  }
1000 
1001  // Payment mode
1002  if (! empty($arrayfields['f.fk_mode_reglement']['checked']))
1003  {
1004  print '<td>';
1005  $form->form_modes_reglement($_SERVER['PHP_SELF'], $obj->fk_mode_reglement, 'none', '', -1);
1006  print '</td>';
1007  if (! $i) $totalarray['nbfield']++;
1008  }
1009 
1010  // Amount HT
1011  if (! empty($arrayfields['f.total_ht']['checked']))
1012  {
1013  print '<td align="right">'.price($obj->total_ht)."</td>\n";
1014  if (! $i) $totalarray['nbfield']++;
1015  if (! $i) $totalarray['totalhtfield']=$totalarray['nbfield'];
1016  $totalarray['totalht'] += $obj->total_ht;
1017  }
1018  // Amount VAT
1019  if (! empty($arrayfields['f.total_vat']['checked']))
1020  {
1021  print '<td align="right">'.price($obj->total_vat)."</td>\n";
1022  if (! $i) $totalarray['nbfield']++;
1023  if (! $i) $totalarray['totalvatfield']=$totalarray['nbfield'];
1024  $totalarray['totalvat'] += $obj->total_vat;
1025  }
1026  // Amount LocalTax1
1027  if (! empty($arrayfields['f.total_localtax1']['checked']))
1028  {
1029  print '<td align="right">'.price($obj->total_localtax1)."</td>\n";
1030  if (! $i) $totalarray['nbfield']++;
1031  if (! $i) $totalarray['totallocaltax1field']=$totalarray['nbfield'];
1032  $totalarray['totallocaltax1'] += $obj->total_localtax1;
1033  }
1034  // Amount LocalTax2
1035  if (! empty($arrayfields['f.total_localtax2']['checked']))
1036  {
1037  print '<td align="right">'.price($obj->total_localtax2)."</td>\n";
1038  if (! $i) $totalarray['nbfield']++;
1039  if (! $i) $totalarray['totallocaltax2field']=$totalarray['nbfield'];
1040  $totalarray['totallocaltax2'] += $obj->total_localtax2;
1041  }
1042  // Amount TTC
1043  if (! empty($arrayfields['f.total_ttc']['checked']))
1044  {
1045  print '<td align="right">'.price($obj->total_ttc)."</td>\n";
1046  if (! $i) $totalarray['nbfield']++;
1047  if (! $i) $totalarray['totalttcfield']=$totalarray['nbfield'];
1048  $totalarray['totalttc'] += $obj->total_ttc;
1049  }
1050 
1051  if (! empty($arrayfields['dynamount_payed']['checked']))
1052  {
1053  print '<td align="right">'.(! empty($totalpay)?price($totalpay,0,$langs):'&nbsp;').'</td>'; // TODO Use a denormalized field
1054  if (! $i) $totalarray['nbfield']++;
1055  if (! $i) $totalarray['totalamfield']=$totalarray['nbfield'];
1056  $totalarray['totalam'] += $totalpay;
1057  }
1058 
1059  if (! empty($arrayfields['rtp']['checked']))
1060  {
1061  print '<td align="right">'.(! empty($remaintopay)?price($remaintopay,0,$langs):'&nbsp;').'</td>'; // TODO Use a denormalized field
1062  if (! $i) $totalarray['nbfield']++;
1063  if (! $i) $totalarray['totalrtpfield']=$totalarray['nbfield'];
1064  $totalarray['totalrtp'] += $remaintopay;
1065  }
1066 
1067 
1068  // Extra fields
1069  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
1070  // Fields from hook
1071  $parameters=array('arrayfields'=>$arrayfields, 'obj'=>$obj);
1072  $reshook=$hookmanager->executeHooks('printFieldListValue',$parameters); // Note that $action and $object may have been modified by hook
1073  print $hookmanager->resPrint;
1074  // Date creation
1075  if (! empty($arrayfields['f.datec']['checked']))
1076  {
1077  print '<td align="center" class="nowrap">';
1078  print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
1079  print '</td>';
1080  if (! $i) $totalarray['nbfield']++;
1081  }
1082  // Date modification
1083  if (! empty($arrayfields['f.tms']['checked']))
1084  {
1085  print '<td align="center" class="nowrap">';
1086  print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser');
1087  print '</td>';
1088  if (! $i) $totalarray['nbfield']++;
1089  }
1090  // Status
1091  if (! empty($arrayfields['f.fk_statut']['checked']))
1092  {
1093  print '<td align="right" class="nowrap">';
1094  // TODO $paiement is not yet defined
1095  print $facturestatic->LibStatut($obj->paye,$obj->fk_statut,5,$paiement,$obj->type);
1096  print "</td>";
1097  if (! $i) $totalarray['nbfield']++;
1098  }
1099 
1100  // Action column
1101  print '<td class="nowrap" align="center">';
1102  if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
1103  {
1104  $selected=0;
1105  if (in_array($obj->facid, $arrayofselected)) $selected=1;
1106  print '<input id="cb'.$obj->facid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->facid.'"'.($selected?' checked="checked"':'').'>';
1107  }
1108  print '</td>';
1109  if (! $i) $totalarray['nbfield']++;
1110 
1111  print "</tr>\n";
1112 
1113  $i++;
1114  }
1115 
1116  // Show total line
1117  if (isset($totalarray['totalhtfield'])
1118  || isset($totalarray['totalvatfield'])
1119  || isset($totalarray['totallocaltax1field'])
1120  || isset($totalarray['totallocaltax2field'])
1121  || isset($totalarray['totalttcfield'])
1122  || isset($totalarray['totalamfield'])
1123  || isset($totalarray['totalrtpfield'])
1124  )
1125  {
1126  print '<tr class="liste_total">';
1127  $i=0;
1128  while ($i < $totalarray['nbfield'])
1129  {
1130  $i++;
1131  if ($i == 1)
1132  {
1133  if ($num < $limit && empty($offset)) print '<td align="left">'.$langs->trans("Total").'</td>';
1134  else print '<td align="left">'.$langs->trans("Totalforthispage").'</td>';
1135  }
1136  elseif ($totalarray['totalhtfield'] == $i) print '<td align="right">'.price($totalarray['totalht']).'</td>';
1137  elseif ($totalarray['totalvatfield'] == $i) print '<td align="right">'.price($totalarray['totalvat']).'</td>';
1138  elseif ($totalarray['totallocaltax1field'] == $i) print '<td align="right">'.price($totalarray['totallocaltax1']).'</td>';
1139  elseif ($totalarray['totallocaltax2field'] == $i) print '<td align="right">'.price($totalarray['totallocaltax2']).'</td>';
1140  elseif ($totalarray['totalttcfield'] == $i) print '<td align="right">'.price($totalarray['totalttc']).'</td>';
1141  elseif ($totalarray['totalamfield'] == $i) print '<td align="right">'.price($totalarray['totalam']).'</td>';
1142  elseif ($totalarray['totalrtpfield'] == $i) print '<td align="right">'.price($totalarray['totalrtp']).'</td>';
1143  else print '<td></td>';
1144  }
1145  print '</tr>';
1146  }
1147  }
1148 
1149  $db->free($resql);
1150 
1151  $parameters=array('arrayfields'=>$arrayfields, 'sql'=>$sql);
1152  $reshook=$hookmanager->executeHooks('printFieldListFooter',$parameters); // Note that $action and $object may have been modified by hook
1153  print $hookmanager->resPrint;
1154 
1155  print "</table>\n";
1156  print '</div>';
1157 
1158  print "</form>\n";
1159 
1160  /*
1161  $hidegeneratedfilelistifempty=1;
1162  if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) $hidegeneratedfilelistifempty=0;
1163 
1164  // Show list of available documents
1165  $urlsource=$_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
1166  $urlsource.=str_replace('&amp;','&',$param);
1167 
1168  $filedir=$diroutputmassaction;
1169  $genallowed=$user->rights->facture->lire;
1170  $delallowed=$user->rights->facture->creer;
1171 
1172  print $formfile->showdocuments('massfilesarea_invoices','',$filedir,$urlsource,0,$delallowed,'',1,1,0,48,1,$param,$title,'','','',null,$hidegeneratedfilelistifempty);
1173  */
1174 }
1175 else
1176 {
1177  dol_print_error($db);
1178 }
1179 
1180 // End of page
1181 llxFooter();
1182 $db->close();
const TYPE_STANDARD
Standard invoice.
img_warning($titlealt='default', $moreatt='')
Show warning logo.
llxFooter()
Empty footer.
Definition: wrapper.php:56
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) if(! empty($conf->don->enabled) && $user->rights->societe->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) && $user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1053
const TYPE_DEPOSIT
Deposit invoice.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm=false, $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart)
Return a path to have a the directory according to object where files are stored. ...
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition: date.lib.php:453
const TYPE_REPLACEMENT
Replacement invoice.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
getCountry($searchkey, $withcode='', $dbtouse=0, $outputlangs='', $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
Class to manage suppliers invoices.
Class to manage bank accounts.
Class to manage suppliers.
Class to build HTML component for third parties management Only common components are here...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Class to manage standard extra fields.
Class to manage generation of HTML components Only common components must be here.
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='title_generic.png', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0)
Print a title with navigation controls for pagination.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage projects.
Classe permettant la generation de composants html autre Only common components are here...
llxHeader()
Empty header.
Definition: wrapper.php:44
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_now($mode='gmt')
Return date for now.
Class to offer components to list and upload files.
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='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
const TYPE_CREDIT_NOTE
Credit note invoice.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition: date.lib.php:467
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="")
Show title line of an array.