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