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 Eric Seigne <eric.seigne@ryxeo.com>
4  * Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
5  * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
6  * Copyright (C) 2005-2015 Regis Houssin <regis.houssin@capnetworks.com>
7  * Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
8  * Copyright (C) 2010-2012 Juanjo Menent <jmenent@2byte.es>
9  * Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
10  * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
11  * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
12  * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
13  * Copyright (C) 2015-2016 Ferran Marcet <fmarcet@2byte.es>
14  * Copyright (C) 2017 Josep Lluís Amador <joseplluis@lliuretic.cat>
15  *
16  * This program is free software; you can redistribute it and/or modify
17  * it under the terms of the GNU General Public License as published by
18  * the Free Software Foundation; either version 3 of the License, or
19  * (at your option) any later version.
20  *
21  * This program is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24  * GNU General Public License for more details.
25  *
26  * You should have received a copy of the GNU General Public License
27  * along with this program. If not, see <http://www.gnu.org/licenses/>.
28  */
29 
36 require '../../main.inc.php';
37 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
38 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
39 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
40 require_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php';
41 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
42 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
43 require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
44 require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
45 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
46 require_once DOL_DOCUMENT_ROOT.'/core/lib/invoice.lib.php';
47 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
48 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
49 if (! empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
50 if (! empty($conf->projet->enabled)) require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
51 
52 $langs->load('bills');
53 $langs->load('companies');
54 $langs->load('products');
55 
56 $sall=trim((GETPOST('search_all', 'alphanohtml')!='')?GETPOST('search_all', 'alphanohtml'):GETPOST('sall', 'alphanohtml'));
57 $projectid=(GETPOST('projectid')?GETPOST('projectid','int'):0);
58 
59 $id=(GETPOST('id','int')?GETPOST('id','int'):GETPOST('facid','int')); // For backward compatibility
60 $ref=GETPOST('ref','alpha');
61 $socid=GETPOST('socid','int');
62 
63 $action=GETPOST('action','alpha');
64 $massaction=GETPOST('massaction','alpha');
65 $show_files=GETPOST('show_files','int');
66 $confirm=GETPOST('confirm','alpha');
67 $toselect = GETPOST('toselect', 'array');
68 
69 $lineid=GETPOST('lineid','int');
70 $userid=GETPOST('userid','int');
71 $search_product_category=GETPOST('search_product_category','int');
72 $search_ref=GETPOST('sf_ref')?GETPOST('sf_ref','alpha'):GETPOST('search_ref','alpha');
73 $search_refcustomer=GETPOST('search_refcustomer','alpha');
74 $search_type=GETPOST('search_type','int');
75 $search_societe=GETPOST('search_societe','alpha');
76 $search_montant_ht=GETPOST('search_montant_ht','alpha');
77 $search_montant_vat=GETPOST('search_montant_vat','alpha');
78 $search_montant_localtax1=GETPOST('search_montant_localtax1','alpha');
79 $search_montant_localtax2=GETPOST('search_montant_localtax2','alpha');
80 $search_montant_ttc=GETPOST('search_montant_ttc','alpha');
81 $search_status=GETPOST('search_status','int');
82 $search_paymentmode=GETPOST('search_paymentmode','int');
83 $search_town=GETPOST('search_town','alpha');
84 $search_zip=GETPOST('search_zip','alpha');
85 $search_state=trim(GETPOST("search_state"));
86 $search_country=GETPOST("search_country",'int');
87 $search_type_thirdparty=GETPOST("search_type_thirdparty",'int');
88 $search_user = GETPOST('search_user','int');
89 $search_sale = GETPOST('search_sale','int');
90 $day = GETPOST('day','int');
91 $month = GETPOST('month','int');
92 $year = GETPOST('year','int');
93 $day_lim = GETPOST('day_lim','int');
94 $month_lim = GETPOST('month_lim','int');
95 $year_lim = GETPOST('year_lim','int');
96 
97 $option = GETPOST('option');
98 if ($option == 'late') {
99  $search_status = '1';
100 }
101 $filtre = GETPOST('filtre','alpha');
102 
103 $limit = GETPOST('limit')?GETPOST('limit','int'):$conf->liste_limit;
104 $sortfield = GETPOST("sortfield",'alpha');
105 $sortorder = GETPOST("sortorder",'alpha');
106 $page = GETPOST("page",'int');
107 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
108 $offset = $limit * $page;
109 if (! $sortorder && ! empty($conf->global->INVOICE_DEFAULT_UNPAYED_SORT_ORDER) && $search_status == 1) $sortorder=$conf->global->INVOICE_DEFAULT_UNPAYED_SORT_ORDER;
110 if (! $sortorder) $sortorder='DESC';
111 if (! $sortfield) $sortfield='f.datef';
112 $pageprev = $page - 1;
113 $pagenext = $page + 1;
114 
115 // Initialize technical object to manage context to save list fields
116 $contextpage=GETPOST('contextpage','aZ')?GETPOST('contextpage','aZ'):'invoicelist';
117 
118 // Security check
119 $fieldid = (! empty($ref)?'facnumber':'rowid');
120 if (! empty($user->societe_id)) $socid=$user->societe_id;
121 $result = restrictedArea($user, 'facture', $id,'','','fk_soc',$fieldid);
122 
123 $diroutputmassaction=$conf->facture->dir_output . '/temp/massgeneration/'.$user->id;
124 
125 $object=new Facture($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('invoicelist'));
131 $extrafields = new ExtraFields($db);
132 
133 // fetch optionals attributes and labels
134 $extralabels = $extrafields->fetch_name_optionals_label('facture');
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.facnumber'=>'Ref',
140  'f.ref_client'=>'RefCustomer',
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.facnumber'=>array('label'=>$langs->trans("Ref"), 'checked'=>1),
150  'f.ref_client'=>array('label'=>$langs->trans("RefCustomer"), 'checked'=>1),
151  'f.type'=>array('label'=>$langs->trans("Type"), 'checked'=>0),
152  'f.date'=>array('label'=>$langs->trans("DateInvoice"), 'checked'=>1),
153  'f.date_lim_reglement'=>array('label'=>$langs->trans("DateDue"), 'checked'=>1),
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("Received"), '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=''; }
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 include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
194 
195 // Do we click on purge search criteria ?
196 if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter','alpha') || GETPOST('button_removefilter.x','alpha')) // All tests are required to be compatible with all browsers
197 {
198  $search_user='';
199  $search_sale='';
200  $search_product_category='';
201  $search_ref='';
202  $search_refcustomer='';
203  $search_type='';
204  $search_project='';
205  $search_societe='';
206  $search_montant_ht='';
207  $search_montant_vat='';
208  $search_montant_localtax1='';
209  $search_montant_localtax2='';
210  $search_montant_ttc='';
211  $search_status='';
212  $search_paymentmode='';
213  $search_town='';
214  $search_zip="";
215  $search_state="";
216  $search_type='';
217  $search_country='';
218  $search_type_thirdparty='';
219  $day='';
220  $year='';
221  $month='';
222  $option='';
223  $filter='';
224  $day_lim='';
225  $year_lim='';
226  $month_lim='';
227  $toselect='';
228  $search_array_options=array();
229 }
230 
231 if (empty($reshook))
232 {
233  $objectclass='Facture';
234  $objectlabel='Invoices';
235  $permtoread = $user->rights->facture->lire;
236  $permtocreate = $user->rights->facture->creer;
237  $permtodelete = $user->rights->facture->supprimer;
238  $uploaddir = $conf->facture->dir_output;
239  include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
240 }
241 
242 if ($massaction == 'withdrawrequest')
243 {
244  $langs->load("withdrawals");
245 
246  if (!$user->rights->prelevement->bons->creer)
247  {
248  $error++;
249  setEventMessages($langs->trans("NotEnoughPermissions"), null, 'errors');
250  }
251  else
252  {
253  //Checking error
254  $error = 0;
255 
256  $arrayofselected=is_array($toselect)?$toselect:array();
257  $listofbills=array();
258  foreach($arrayofselected as $toselectid)
259  {
260  $objecttmp=new Facture($db);
261  $result=$objecttmp->fetch($toselectid);
262  if ($result > 0)
263  {
264  $totalpaye = $objecttmp->getSommePaiement();
265  $totalcreditnotes = $objecttmp->getSumCreditNotesUsed();
266  $totaldeposits = $objecttmp->getSumDepositsUsed();
267  $objecttmp->resteapayer = price2num($objecttmp->total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits,'MT');
268  $listofbills[] = $objecttmp;
269  if($objecttmp->paye || $objecttmp->resteapayer==0){
270  $error++;
271  setEventMessages($objecttmp->ref.' '.$langs->trans("AlreadyPaid"), $objecttmp->errors, 'errors');
272  } else if($objecttmp->resteapayer<0){
273  $error++;
274  setEventMessages($objecttmp->ref.' '.$langs->trans("AmountMustBePositive"), $objecttmp->errors, 'errors');
275  }
276  if(!($objecttmp->statut > Facture::STATUS_DRAFT)){
277  $error++;
278  setEventMessages($objecttmp->ref.' '.$langs->trans("Draft"), $objecttmp->errors, 'errors');
279  }
280 
281  $rsql = "SELECT pfd.rowid, pfd.traite, pfd.date_demande as date_demande";
282  $rsql .= " , pfd.date_traite as date_traite";
283  $rsql .= " , pfd.amount";
284  $rsql .= " , u.rowid as user_id, u.lastname, u.firstname, u.login";
285  $rsql .= " FROM ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd";
286  $rsql .= " , ".MAIN_DB_PREFIX."user as u";
287  $rsql .= " WHERE fk_facture = ".$objecttmp->id;
288  $rsql .= " AND pfd.fk_user_demande = u.rowid";
289  $rsql .= " AND pfd.traite = 0";
290  $rsql .= " ORDER BY pfd.date_demande DESC";
291 
292  $result_sql = $db->query($rsql);
293  if ($result_sql)
294  {
295  $numprlv = $db->num_rows($result_sql);
296  }
297 
298  if($numprlv>0){
299  $error++;
300  setEventMessages($objecttmp->ref.' '.$langs->trans("RequestAlreadyDone"), $objecttmp->errors, 'errors');
301  }
302  if(!empty($objecttmp->mode_reglement_id ) && $objecttmp->mode_reglement_id != 3){
303  $error++;
304  setEventMessages($objecttmp->ref.' '.$langs->trans("BadPaymentMethod"), $objecttmp->errors, 'errors');
305  }
306 
307  }
308  }
309 
310  //Massive withdraw request
311  if(!empty($listofbills) && empty($error))
312  {
313  $nbwithdrawrequestok=0;
314  foreach($listofbills as $aBill)
315  {
316  $db->begin();
317  $result = $aBill->demande_prelevement($user, $aBill->resteapayer);
318  if ($result > 0)
319  {
320  $db->commit();
321  $nbwithdrawrequestok++;
322  }
323  else
324  {
325 
326  $db->rollback();
327  setEventMessages($aBill->error, $aBill->errors, 'errors');
328  }
329  }
330  if ($nbwithdrawrequestok > 0)
331  {
332  setEventMessages($langs->trans("WithdrawRequestsDone", $nbwithdrawrequestok), null, 'mesgs');
333  }
334  }
335  }
336 
337 }
338 
339 
340 
341 /*
342  * View
343  */
344 
345 $form = new Form($db);
346 $formother = new FormOther($db);
347 $formfile = new FormFile($db);
348 $bankaccountstatic=new Account($db);
349 $facturestatic=new Facture($db);
350 $formcompany=new FormCompany($db);
351 $thirdpartystatic=new Societe($db);
352 
353 llxHeader('',$langs->trans('CustomersInvoices'),'EN:Customers_Invoices|FR:Factures_Clients|ES:Facturas_a_clientes');
354 
355 $sql = 'SELECT';
356 if ($sall || $search_product_category > 0) $sql = 'SELECT DISTINCT';
357 $sql.= ' f.rowid as id, f.facnumber as ref, f.ref_client, f.type, f.note_private, f.note_public, f.increment, f.fk_mode_reglement, f.total as total_ht, f.tva as total_vat, f.total_ttc,';
358 $sql.= ' f.localtax1 as total_localtax1, f.localtax2 as total_localtax2,';
359 $sql.= ' f.datef as df, f.date_lim_reglement as datelimite,';
360 $sql.= ' f.paye as paye, f.fk_statut,';
361 $sql.= ' f.datec as date_creation, f.tms as date_update,';
362 $sql.= ' s.rowid as socid, s.nom as name, s.email, s.town, s.zip, s.fk_pays, s.client, s.code_client, ';
363 $sql.= " typent.code as typent_code,";
364 $sql.= " state.code_departement as state_code, state.nom as state_name";
365 // 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)
366 // TODO Better solution to be able to sort on already payed or remain to pay is to store amount_payed in a denormalized field.
367 if (! $sall) $sql.= ', SUM(pf.amount) as dynamount_payed';
368 // Add fields from extrafields
369 foreach ($extrafields->attribute_label as $key => $val) $sql.=($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key.' as options_'.$key : '');
370 // Add fields from hooks
371 $parameters=array();
372 $reshook=$hookmanager->executeHooks('printFieldListSelect',$parameters); // Note that $action and $object may have been modified by hook
373 $sql.=$hookmanager->resPrint;
374 $sql.= ' FROM '.MAIN_DB_PREFIX.'societe as s';
375 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
376 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
377 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)";
378 $sql.= ', '.MAIN_DB_PREFIX.'facture as f';
379 if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture_extrafields as ef on (f.rowid = ef.fk_object)";
380 if (! $sall) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiement_facture as pf ON pf.fk_facture = f.rowid';
381 if ($sall || $search_product_category > 0) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'facturedet as pd ON f.rowid=pd.fk_facture';
382 if ($search_product_category > 0) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=pd.fk_product';
383 // We'll need this table joined to the select in order to filter by sale
384 if ($search_sale > 0 || (! $user->rights->societe->client->voir && ! $socid)) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
385 if ($search_user > 0)
386 {
387  $sql.=", ".MAIN_DB_PREFIX."element_contact as ec";
388  $sql.=", ".MAIN_DB_PREFIX."c_type_contact as tc";
389 }
390 $sql.= ' WHERE f.fk_soc = s.rowid';
391 $sql.= ' AND f.entity IN ('.getEntity('facture').')';
392 if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
393 if ($search_product_category > 0) $sql.=" AND cp.fk_categorie = ".$db->escape($search_product_category);
394 if ($socid > 0) $sql.= ' AND s.rowid = '.$socid;
395 if ($userid)
396 {
397  if ($userid == -1) $sql.=' AND f.fk_user_author IS NULL';
398  else $sql.=' AND f.fk_user_author = '.$userid;
399 }
400 if ($filtre)
401 {
402  $aFilter = explode(',', $filtre);
403  foreach ($aFilter as $filter)
404  {
405  $filt = explode(':', $filter);
406  $sql .= ' AND ' . $db->escape(trim($filt[0])) . ' = ' . $db->escape(trim($filt[1]));
407  }
408 }
409 if ($search_ref) $sql .= natural_search('f.facnumber', $search_ref);
410 if ($search_refcustomer) $sql .= natural_search('f.ref_client', $search_refcustomer);
411 if ($search_type != '' && $search_type >= 0)
412 {
413  if ($search_type == '0') $sql.=" AND f.type = 0"; // standard
414  if ($search_type == '1') $sql.=" AND f.type = 1"; // replacement
415  if ($search_type == '2') $sql.=" AND f.type = 2"; // credit note
416  if ($search_type == '3') $sql.=" AND f.type = 3"; // deposit
417  if ($search_type == '4') $sql.=" AND f.type = 4"; // proforma
418  if ($search_type == '5') $sql.=" AND f.type = 5"; // situation
419 }
420 if ($search_project) $sql .= natural_search('p.ref', $search_project);
421 if ($search_societe) $sql .= natural_search('s.nom', $search_societe);
422 if ($search_town) $sql.= natural_search('s.town', $search_town);
423 if ($search_zip) $sql.= natural_search("s.zip",$search_zip);
424 if ($search_state) $sql.= natural_search("state.nom",$search_state);
425 if ($search_country) $sql .= " AND s.fk_pays IN (".$search_country.')';
426 if ($search_type_thirdparty) $sql .= " AND s.fk_typent IN (".$search_type_thirdparty.')';
427 if ($search_company) $sql .= natural_search('s.nom', $search_company);
428 if ($search_montant_ht != '') $sql.= natural_search('f.total', $search_montant_ht, 1);
429 if ($search_montant_vat != '') $sql.= natural_search('f.tva', $search_montant_vat, 1);
430 if ($search_montant_localtax1 != '') $sql.= natural_search('f.localtax1', $search_montant_localtax1, 1);
431 if ($search_montant_localtax2 != '') $sql.= natural_search('f.localtax2', $search_montant_localtax2, 1);
432 if ($search_montant_ttc != '') $sql.= natural_search('f.total_ttc', $search_montant_ttc, 1);
433 if ($search_status != '' && $search_status >= 0)
434 {
435  if ($search_status == '0') $sql.=" AND f.fk_statut = 0"; // draft
436  if ($search_status == '1') $sql.=" AND f.fk_statut = 1"; // unpayed
437  if ($search_status == '2') $sql.=" AND f.fk_statut = 2"; // payed Not that some corrupted data may contains f.fk_statut = 1 AND f.paye = 1 (it means payed too but should not happend. If yes, reopen and reclassify billed)
438  if ($search_status == '3') $sql.=" AND f.fk_statut = 3"; // abandonned
439 }
440 if ($search_paymentmode > 0) $sql .= " AND f.fk_mode_reglement = ".$db->escape($search_paymentmode);
441 if ($month > 0)
442 {
443  if ($year > 0 && empty($day))
444  $sql.= " AND f.datef BETWEEN '".$db->idate(dol_get_first_day($year,$month,false))."' AND '".$db->idate(dol_get_last_day($year,$month,false))."'";
445  else if ($year > 0 && ! empty($day))
446  $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))."'";
447  else
448  $sql.= " AND date_format(f.datef, '%m') = '".$month."'";
449 }
450 else if ($year > 0)
451 {
452  $sql.= " AND f.datef BETWEEN '".$db->idate(dol_get_first_day($year,1,false))."' AND '".$db->idate(dol_get_last_day($year,12,false))."'";
453 }
454 if ($month_lim > 0)
455 {
456  if ($year_lim > 0 && empty($day_lim))
457  $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))."'";
458  else if ($year_lim > 0 && ! empty($day_lim))
459  $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))."'";
460  else
461  $sql.= " AND date_format(f.date_lim_reglement, '%m') = '".$db->escape($month_lim)."'";
462 }
463 else if ($year_lim > 0)
464 {
465  $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))."'";
466 }
467 if ($option == 'late') $sql.=" AND f.date_lim_reglement < '".$db->idate(dol_now() - $conf->facture->client->warning_delay)."'";
468 if ($search_sale > 0) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$search_sale;
469 if ($search_user > 0)
470 {
471  $sql.= " AND ec.fk_c_type_contact = tc.rowid AND tc.element='facture' AND tc.source='internal' AND ec.element_id = f.rowid AND ec.fk_socpeople = ".$search_user;
472 }
473 // Add where from extra fields
474 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
475 // Add where from hooks
476 $parameters=array();
477 $reshook=$hookmanager->executeHooks('printFieldListWhere',$parameters); // Note that $action and $object may have been modified by hook
478 $sql.=$hookmanager->resPrint;
479 
480 if (! $sall)
481 {
482  $sql.= ' GROUP BY f.rowid, f.facnumber, ref_client, f.type, f.note_private, f.note_public, f.increment, f.fk_mode_reglement, f.total, f.tva, f.total_ttc,';
483  $sql.= ' f.localtax1, f.localtax2,';
484  $sql.= ' f.datef, f.date_lim_reglement,';
485  $sql.= ' f.paye, f.fk_statut,';
486  $sql.= ' f.datec, f.tms,';
487  $sql.= ' s.rowid, s.nom, s.email, s.town, s.zip, s.fk_pays, s.code_client, s.client, typent.code,';
488  $sql.= ' state.code_departement, state.nom';
489 
490  foreach ($extrafields->attribute_label as $key => $val) //prevent error with sql_mode=only_full_group_by
491  {
492  $sql.=($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key : '');
493  }
494 }
495 else
496 {
497  $sql .= natural_search(array_keys($fieldstosearchall), $sall);
498 }
499 
500 $sql.= ' ORDER BY ';
501 $listfield=explode(',',$sortfield);
502 foreach ($listfield as $key => $value) $sql.= $listfield[$key].' '.$sortorder.',';
503 $sql.= ' f.rowid DESC ';
504 
505 $nbtotalofrecords = '';
506 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
507 {
508  $result = $db->query($sql);
509  $nbtotalofrecords = $db->num_rows($result);
510 }
511 
512 $sql.= $db->plimit($limit+1,$offset);
513 //print $sql;
514 
515 $resql = $db->query($sql);
516 if ($resql)
517 {
518  $num = $db->num_rows($resql);
519 
520  $arrayofselected=is_array($toselect)?$toselect:array();
521 
522  if ($socid)
523  {
524  $soc = new Societe($db);
525  $soc->fetch($socid);
526  if (empty($search_societe)) $search_societe = $soc->name;
527  }
528 
529  $param='&socid='.$socid;
530  if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
531  if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
532  if ($sall) $param.='&sall='.urlencode($sall);
533  if ($day) $param.='&day='.urlencode($day);
534  if ($month) $param.='&month='.urlencode($month);
535  if ($year) $param.='&year=' .urlencode($year);
536  if ($day_lim) $param.='&day_lim='.urlencode($day_lim);
537  if ($month_lim) $param.='&month_lim='.urlencode($month_lim);
538  if ($year_lim) $param.='&year_lim=' .urlencode($year_lim);
539  if ($search_ref) $param.='&search_ref=' .urlencode($search_ref);
540  if ($search_refcustomer) $param.='&search_refcustomer=' .urlencode($search_refcustomer);
541  if ($search_type != '') $param.='&search_type='.urlencode($search_type);
542  if ($search_societe) $param.='&search_societe=' .urlencode($search_societe);
543  if ($search_sale > 0) $param.='&search_sale=' .urlencode($search_sale);
544  if ($search_user > 0) $param.='&search_user=' .urlencode($search_user);
545  if ($search_product_category > 0) $param.='$search_product_category=' .urlencode($search_product_category);
546  if ($search_montant_ht != '') $param.='&search_montant_ht='.urlencode($search_montant_ht);
547  if ($search_montant_vat != '') $param.='&search_montant_vat='.urlencode($search_montant_vat);
548  if ($search_montant_localtax1 != '') $param.='&search_montant_localtax1='.urlencode($search_montant_localtax1);
549  if ($search_montant_localtax2 != '') $param.='&search_montant_localtax2='.urlencode($search_montant_localtax2);
550  if ($search_montant_ttc != '') $param.='&search_montant_ttc='.urlencode($search_montant_ttc);
551  if ($search_status != '') $param.='&search_status='.urlencode($search_status);
552  if ($search_paymentmode > 0) $param.='search_paymentmode='.urlencode($search_paymentmode);
553  if ($show_files) $param.='&show_files=' .$show_files;
554  if ($option) $param.="&option=".$option;
555  if ($optioncss != '') $param.='&optioncss='.$optioncss;
556  // Add $param from extra fields
557  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
558 
559  $arrayofmassactions=array(
560  'validate'=>$langs->trans("Validate"),
561  'presend'=>$langs->trans("SendByMail"),
562  'builddoc'=>$langs->trans("PDFMerge"),
563  );
564  if ($conf->prelevement->enabled)
565  {
566  $langs->load("withdrawals");
567  $arrayofmassactions['withdrawrequest']=$langs->trans("MakeWithdrawRequest");
568  }
569  if ($user->rights->facture->supprimer)
570  {
571  //if (! empty($conf->global->STOCK_CALCULATE_ON_BILL) || empty($conf->global->INVOICE_CAN_ALWAYS_BE_REMOVED))
572  if (empty($conf->global->INVOICE_CAN_ALWAYS_BE_REMOVED))
573  {
574  // mass deletion never possible on invoices on such situation
575  }
576  else
577  {
578  $arrayofmassactions['predelete']=$langs->trans("Delete");
579  }
580  }
581  if (in_array($massaction, array('presend','predelete'))) $arrayofmassactions=array();
582  $massactionbutton=$form->selectMassAction('', $arrayofmassactions);
583 
584  $i = 0;
585  print '<form method="POST" name="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
586 
587  if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
588  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
589  print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
590  print '<input type="hidden" name="action" value="list">';
591  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
592  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
593  print '<input type="hidden" name="page" value="'.$page.'">';
594  print '<input type="hidden" name="viewstatut" value="'.$viewstatut.'">';
595  print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
596 
597  print_barre_liste($langs->trans('BillsCustomers').' '.($socid?' '.$soc->name:''), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'title_accountancy.png', 0, '', '', $limit);
598 
599  $topicmail="SendBillRef";
600  $modelmail="facture_send";
601  $objecttmp=new Facture($db);
602  $trackid='inv'.$object->id;
603  include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
604 
605  if ($sall)
606  {
607  foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val);
608  print $langs->trans("FilterOnInto", $sall) . join(', ',$fieldstosearchall);
609  }
610 
611  // If the user can view prospects other than his'
612  $moreforfilter='';
613  if ($user->rights->societe->client->voir || $socid)
614  {
615  $langs->load("commercial");
616  $moreforfilter.='<div class="divsearchfield">';
617  $moreforfilter.=$langs->trans('ThirdPartiesOfSaleRepresentative'). ': ';
618  $moreforfilter.=$formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, 1, 'maxwidth200');
619  $moreforfilter.='</div>';
620  }
621  // If the user can view prospects other than his'
622  if ($user->rights->societe->client->voir || $socid)
623  {
624  $moreforfilter.='<div class="divsearchfield">';
625  $moreforfilter.=$langs->trans('LinkedToSpecificUsers'). ': ';
626  $moreforfilter.=$form->select_dolusers($search_user, 'search_user', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth200');
627  $moreforfilter.='</div>';
628  }
629  // If the user can view prospects other than his'
630  if ($conf->categorie->enabled && ($user->rights->produit->lire || $user->rights->service->lire))
631  {
632  include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
633  $moreforfilter.='<div class="divsearchfield">';
634  $moreforfilter.=$langs->trans('IncludingProductWithTag'). ': ';
635  $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, null, 'parent', null, null, 1);
636  $moreforfilter.=$form->selectarray('search_product_category', $cate_arbo, $search_product_category, 1, 0, 0, '', 0, 0, 0, 0, 'maxwidth300', 1);
637  $moreforfilter.='</div>';
638  }
639  $parameters=array();
640  $reshook=$hookmanager->executeHooks('printFieldPreListTitle',$parameters); // Note that $action and $object may have been modified by hook
641  if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint;
642  else $moreforfilter = $hookmanager->resPrint;
643 
644  if ($moreforfilter)
645  {
646  print '<div class="liste_titre liste_titre_bydiv centpercent">';
647  print $moreforfilter;
648  print '</div>';
649  }
650 
651  $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
652  $selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
653  if ($massactionbutton) $selectedfields.=$form->showCheckAddButtons('checkforselect', 1);
654 
655  print '<div class="div-table-responsive">';
656  print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
657 
658  // Filters lines
659  print '<tr class="liste_titre_filter">';
660  // Ref
661  if (! empty($arrayfields['f.facnumber']['checked']))
662  {
663  print '<td class="liste_titre" align="left">';
664  print '<input class="flat" size="6" type="text" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">';
665  print '</td>';
666  }
667  // Ref customer
668  if (! empty($arrayfields['f.ref_client']['checked']))
669  {
670  print '<td class="liste_titre">';
671  print '<input class="flat" size="6" type="text" name="search_refcustomer" value="'.dol_escape_htmltag($search_refcustomer).'">';
672  print '</td>';
673  }
674  // Type
675  if (! empty($arrayfields['f.type']['checked']))
676  {
677  print '<td class="liste_titre maxwidthonsmartphone">';
678  $listtype=array(
679  Facture::TYPE_STANDARD=>$langs->trans("InvoiceStandard"),
680  Facture::TYPE_REPLACEMENT=>$langs->trans("InvoiceReplacement"),
681  Facture::TYPE_CREDIT_NOTE=>$langs->trans("InvoiceAvoir"),
682  Facture::TYPE_DEPOSIT=>$langs->trans("InvoiceDeposit"),
683  );
684  if (! empty($conf->global->INVOICE_USE_SITUATION))
685  {
686  $listtype[Facture::TYPE_SITUATION] = $langs->trans("InvoiceSituation");
687  }
688  //$listtype[Facture::TYPE_PROFORMA]=$langs->trans("InvoiceProForma"); // A proformat invoice is not an invoice but must be an order.
689  print $form->selectarray('search_type', $listtype, $search_type, 1, 0, 0, '', 0, 0, 0, 'ASC', 'maxwidth100');
690  print '</td>';
691  }
692  // Date invoice
693  if (! empty($arrayfields['f.date']['checked']))
694  {
695  print '<td class="liste_titre" align="center">';
696  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).'">';
697  print '<input class="flat" type="text" size="1" maxlength="2" name="month" value="'.dol_escape_htmltag($month).'">';
698  $formother->select_year($year?$year:-1,'year',1, 20, 5);
699  print '</td>';
700  }
701  // Date due
702  if (! empty($arrayfields['f.date_lim_reglement']['checked']))
703  {
704  print '<td class="liste_titre" align="center">';
705  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).'">';
706  print '<input class="flat" type="text" size="1" maxlength="2" name="month_lim" value="'.dol_escape_htmltag($month_lim).'">';
707  $formother->select_year($year_lim?$year_lim:-1,'year_lim',1, 20, 5);
708  print '<br><input type="checkbox" name="option" value="late"'.($option == 'late'?' checked':'').'> '.$langs->trans("Late");
709  print '</td>';
710  }
711  // Project
712  if (! empty($arrayfields['p.ref']['checked']))
713  {
714  print '<td class="liste_titre" align="left"><input class="flat" type="text" size="6" name="search_project" value="'.$search_project.'"></td>';
715  }
716  // Thirpdarty
717  if (! empty($arrayfields['s.nom']['checked']))
718  {
719  print '<td class="liste_titre" align="left"><input class="flat" type="text" size="6" name="search_societe" value="'.$search_societe.'"></td>';
720  }
721  // Town
722  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>';
723  // Zip
724  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>';
725  // State
726  if (! empty($arrayfields['state.nom']['checked']))
727  {
728  print '<td class="liste_titre">';
729  print '<input class="flat" size="4" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
730  print '</td>';
731  }
732  // Country
733  if (! empty($arrayfields['country.code_iso']['checked']))
734  {
735  print '<td class="liste_titre" align="center">';
736  print $form->select_country($search_country,'search_country','',0,'maxwidth100');
737  print '</td>';
738  }
739  // Company type
740  if (! empty($arrayfields['typent.code']['checked']))
741  {
742  print '<td class="liste_titre maxwidthonsmartphone" align="center">';
743  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), 'maxwidth100');
744  print '</td>';
745  }
746  // Payment mode
747  if (! empty($arrayfields['f.fk_mode_reglement']['checked']))
748  {
749  print '<td class="liste_titre" align="left">';
750  $form->select_types_paiements($search_paymentmode, 'search_paymentmode', '', 0, 0, 1, 10);
751  print '</td>';
752  }
753  if (! empty($arrayfields['f.total_ht']['checked']))
754  {
755  // Amount
756  print '<td class="liste_titre" align="right">';
757  print '<input class="flat" type="text" size="5" name="search_montant_ht" value="'.dol_escape_htmltag($search_montant_ht).'">';
758  print '</td>';
759  }
760  if (! empty($arrayfields['f.total_vat']['checked']))
761  {
762  // Amount
763  print '<td class="liste_titre" align="right">';
764  print '<input class="flat" type="text" size="5" name="search_montant_vat" value="'.dol_escape_htmltag($search_montant_vat).'">';
765  print '</td>';
766  }
767  if (! empty($arrayfields['f.total_localtax1']['checked']))
768  {
769  // Amount
770  print '<td class="liste_titre" align="right">';
771  print '<input class="flat" type="text" size="5" name="search_montant_localtax1" value="'.$search_montant_localtax1.'">';
772  print '</td>';
773  }
774  if (! empty($arrayfields['f.total_localtax2']['checked']))
775  {
776  // Amount
777  print '<td class="liste_titre" align="right">';
778  print '<input class="flat" type="text" size="5" name="search_montant_localtax2" value="'.$search_montant_localtax2.'">';
779  print '</td>';
780  }
781  if (! empty($arrayfields['f.total_ttc']['checked']))
782  {
783  // Amount
784  print '<td class="liste_titre" align="right">';
785  print '<input class="flat" type="text" size="5" name="search_montant_ttc" value="'.dol_escape_htmltag($search_montant_ttc).'">';
786  print '</td>';
787  }
788  if (! empty($arrayfields['dynamount_payed']['checked']))
789  {
790  print '<td class="liste_titre" align="right">';
791  print '</td>';
792  }
793  if (! empty($arrayfields['rtp']['checked']))
794  {
795  print '<td class="liste_titre" align="right">';
796  print '</td>';
797  }
798  // Extra fields
799  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
800 
801  // Fields from hook
802  $parameters=array('arrayfields'=>$arrayfields);
803  $reshook=$hookmanager->executeHooks('printFieldListOption',$parameters); // Note that $action and $object may have been modified by hook
804  print $hookmanager->resPrint;
805  // Date creation
806  if (! empty($arrayfields['f.datec']['checked']))
807  {
808  print '<td class="liste_titre">';
809  print '</td>';
810  }
811  // Date modification
812  if (! empty($arrayfields['f.tms']['checked']))
813  {
814  print '<td class="liste_titre">';
815  print '</td>';
816  }
817  // Status
818  if (! empty($arrayfields['f.fk_statut']['checked']))
819  {
820  print '<td class="liste_titre maxwidthonsmartphone" align="right">';
821  $liststatus=array('0'=>$langs->trans("BillShortStatusDraft"), '1'=>$langs->trans("BillShortStatusNotPaid"), '2'=>$langs->trans("BillShortStatusPaid"), '3'=>$langs->trans("BillShortStatusCanceled"));
822  print $form->selectarray('search_status', $liststatus, $search_status, 1);
823  print '</td>';
824  }
825  // Action column
826  print '<td class="liste_titre" align="middle">';
827  $searchpicto=$form->showFilterButtons();
828  print $searchpicto;
829  print '</td>';
830  print "</tr>\n";
831 
832  print '<tr class="liste_titre">';
833  if (! empty($arrayfields['f.facnumber']['checked'])) print_liste_field_titre($arrayfields['f.facnumber']['label'],$_SERVER['PHP_SELF'],'f.facnumber','',$param,'',$sortfield,$sortorder);
834  if (! empty($arrayfields['f.ref_client']['checked'])) print_liste_field_titre($arrayfields['f.ref_client']['label'],$_SERVER["PHP_SELF"],'f.ref_client','',$param,'',$sortfield,$sortorder);
835  if (! empty($arrayfields['f.type']['checked'])) print_liste_field_titre($arrayfields['f.type']['label'],$_SERVER["PHP_SELF"],'f.type','',$param,'',$sortfield,$sortorder);
836  if (! empty($arrayfields['f.date']['checked'])) print_liste_field_titre($arrayfields['f.date']['label'],$_SERVER['PHP_SELF'],'f.datef','',$param,'align="center"',$sortfield,$sortorder);
837  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);
838  if (! empty($arrayfields['s.nom']['checked'])) print_liste_field_titre($arrayfields['s.nom']['label'],$_SERVER['PHP_SELF'],'s.nom','',$param,'',$sortfield,$sortorder);
839  if (! empty($arrayfields['s.town']['checked'])) print_liste_field_titre($arrayfields['s.town']['label'],$_SERVER["PHP_SELF"],'s.town','',$param,'',$sortfield,$sortorder);
840  if (! empty($arrayfields['s.zip']['checked'])) print_liste_field_titre($arrayfields['s.zip']['label'],$_SERVER["PHP_SELF"],'s.zip','',$param,'',$sortfield,$sortorder);
841  if (! empty($arrayfields['state.nom']['checked'])) print_liste_field_titre($arrayfields['state.nom']['label'],$_SERVER["PHP_SELF"],"state.nom","",$param,'',$sortfield,$sortorder);
842  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);
843  if (! empty($arrayfields['typent.code']['checked'])) print_liste_field_titre($arrayfields['typent.code']['label'],$_SERVER["PHP_SELF"],"typent.code","",$param,'align="center"',$sortfield,$sortorder);
844  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);
845  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);
846  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);
847  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);
848  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);
849  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);
850  if (! empty($arrayfields['dynamount_payed']['checked'])) print_liste_field_titre($arrayfields['dynamount_payed']['label'],$_SERVER['PHP_SELF'],'','',$param,'align="right"',$sortfield,$sortorder);
851  if (! empty($arrayfields['rtp']['checked'])) print_liste_field_titre($arrayfields['rtp']['label'],$_SERVER['PHP_SELF'],'','',$param,'align="right"',$sortfield,$sortorder);
852  // Extra fields
853  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
854  // Hook fields
855  $parameters=array('arrayfields'=>$arrayfields);
856  $reshook=$hookmanager->executeHooks('printFieldListTitle',$parameters); // Note that $action and $object may have been modified by hook
857  print $hookmanager->resPrint;
858  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);
859  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);
860  if (! empty($arrayfields['f.fk_statut']['checked'])) print_liste_field_titre($arrayfields['f.fk_statut']['label'],$_SERVER["PHP_SELF"],"fk_statut,paye,type,dynamount_payed","",$param,'align="right"',$sortfield,$sortorder);
861  print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'','','align="center"',$sortfield,$sortorder,'maxwidthsearch ');
862  print "</tr>\n";
863 
864  if ($num > 0)
865  {
866  $i=0;
867  $totalarray=array();
868  while ($i < min($num,$limit))
869  {
870  $obj = $db->fetch_object($resql);
871 
872  $datelimit=$db->jdate($obj->datelimite);
873  $facturestatic->id=$obj->id;
874  $facturestatic->ref=$obj->ref;
875  $facturestatic->type=$obj->type;
876  $facturestatic->statut=$obj->fk_statut;
877  $facturestatic->date_lim_reglement=$db->jdate($obj->datelimite);
878  $facturestatic->note_public=$obj->note_public;
879  $facturestatic->note_private=$obj->note_private;
880 
881  $paiement = $facturestatic->getSommePaiement();
882  $totalcreditnotes = $facturestatic->getSumCreditNotesUsed();
883  $totaldeposits = $facturestatic->getSumDepositsUsed();
884  $totalpay = $paiement + $totalcreditnotes + $totaldeposits;
885  $remaintopay = $obj->total_ttc - $totalpay;
886 
887  print '<tr class="oddeven">';
888  if (! empty($arrayfields['f.facnumber']['checked']))
889  {
890  print '<td class="nowrap">';
891 
892  print '<table class="nobordernopadding"><tr class="nocellnopadd">';
893 
894  print '<td class="nobordernopadding nowrap">';
895  print $facturestatic->getNomUrl(1,'',200,0,'',0,1);
896  print empty($obj->increment)?'':' ('.$obj->increment.')';
897  print '</td>';
898 
899  print '<td style="min-width: 20px" class="nobordernopadding nowrap">';
900  $filename=dol_sanitizeFileName($obj->ref);
901  $filedir=$conf->facture->dir_output . '/' . dol_sanitizeFileName($obj->ref);
902  $urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->id;
903  print $formfile->getDocumentsLink($facturestatic->element, $filename, $filedir);
904  print '</td>';
905  print '</tr>';
906  print '</table>';
907 
908  print "</td>\n";
909  if (! $i) $totalarray['nbfield']++;
910  }
911 
912  // Customer ref
913  if (! empty($arrayfields['f.ref_client']['checked']))
914  {
915  print '<td class="nowrap">';
916  print $obj->ref_client;
917  print '</td>';
918  if (! $i) $totalarray['nbfield']++;
919  }
920 
921  // Type
922  if (! empty($arrayfields['f.type']['checked']))
923  {
924  print '<td class="nowrap">';
925  print $facturestatic->getLibType();
926  print "</td>";
927  if (! $i) $totalarray['nbfield']++;
928  }
929 
930  // Date
931  if (! empty($arrayfields['f.date']['checked']))
932  {
933  print '<td align="center" class="nowrap">';
934  print dol_print_date($db->jdate($obj->df),'day');
935  print '</td>';
936  if (! $i) $totalarray['nbfield']++;
937  }
938 
939  // Date limit
940  if (! empty($arrayfields['f.date_lim_reglement']['checked']))
941  {
942  print '<td align="center" class="nowrap">'.dol_print_date($datelimit,'day');
943  if ($facturestatic->hasDelay())
944  {
945  print img_warning($langs->trans('Late'));
946  }
947  print '</td>';
948  if (! $i) $totalarray['nbfield']++;
949  }
950 
951  // Project
952  if (! empty($arrayfields['p.ref']['checked']))
953  {
954  print '<td class="nowrap">';
955  if ($obj->project_id > 0)
956  {
957  $projectstatic->id=$obj->project_id;
958  $projectstatic->ref=$obj->project_ref;
959  print $projectstatic->getNomUrl(1);
960  }
961  print '</td>';
962  if (! $i) $totalarray['nbfield']++;
963  }
964 
965  // Third party
966  if (! empty($arrayfields['s.nom']['checked']))
967  {
968  print '<td class="tdoverflowmax200">';
969  $thirdpartystatic->id=$obj->socid;
970  $thirdpartystatic->name=$obj->name;
971  $thirdpartystatic->client=$obj->client;
972  $thirdpartystatic->code_client=$obj->code_client;
973  $thirdpartystatic->email=$obj->email;
974  print $thirdpartystatic->getNomUrl(1,'customer');
975  print '</td>';
976  if (! $i) $totalarray['nbfield']++;
977  }
978  // Town
979  if (! empty($arrayfields['s.town']['checked']))
980  {
981  print '<td class="nocellnopadd">';
982  print $obj->town;
983  print '</td>';
984  if (! $i) $totalarray['nbfield']++;
985  }
986  // Zip
987  if (! empty($arrayfields['s.zip']['checked']))
988  {
989  print '<td class="nocellnopadd">';
990  print $obj->zip;
991  print '</td>';
992  if (! $i) $totalarray['nbfield']++;
993  }
994  // State
995  if (! empty($arrayfields['state.nom']['checked']))
996  {
997  print "<td>".$obj->state_name."</td>\n";
998  if (! $i) $totalarray['nbfield']++;
999  }
1000  // Country
1001  if (! empty($arrayfields['country.code_iso']['checked']))
1002  {
1003  print '<td align="center">';
1004  $tmparray=getCountry($obj->fk_pays,'all');
1005  print $tmparray['label'];
1006  print '</td>';
1007  if (! $i) $totalarray['nbfield']++;
1008  }
1009  // Type ent
1010  if (! empty($arrayfields['typent.code']['checked']))
1011  {
1012  print '<td align="center">';
1013  if (count($typenArray)==0) $typenArray = $formcompany->typent_array(1);
1014  print $typenArray[$obj->typent_code];
1015  print '</td>';
1016  if (! $i) $totalarray['nbfield']++;
1017  }
1018 
1019  // Payment mode
1020  if (! empty($arrayfields['f.fk_mode_reglement']['checked']))
1021  {
1022  print '<td>';
1023  $form->form_modes_reglement($_SERVER['PHP_SELF'], $obj->fk_mode_reglement, 'none', '', -1);
1024  print '</td>';
1025  if (! $i) $totalarray['nbfield']++;
1026  }
1027 
1028  // Amount HT
1029  if (! empty($arrayfields['f.total_ht']['checked']))
1030  {
1031  print '<td align="right">'.price($obj->total_ht)."</td>\n";
1032  if (! $i) $totalarray['nbfield']++;
1033  if (! $i) $totalarray['totalhtfield']=$totalarray['nbfield'];
1034  $totalarray['totalht'] += $obj->total_ht;
1035  }
1036  // Amount VAT
1037  if (! empty($arrayfields['f.total_vat']['checked']))
1038  {
1039  print '<td align="right">'.price($obj->total_vat)."</td>\n";
1040  if (! $i) $totalarray['nbfield']++;
1041  if (! $i) $totalarray['totalvatfield']=$totalarray['nbfield'];
1042  $totalarray['totalvat'] += $obj->total_vat;
1043  }
1044  // Amount LocalTax1
1045  if (! empty($arrayfields['f.total_localtax1']['checked']))
1046  {
1047  print '<td align="right">'.price($obj->total_localtax1)."</td>\n";
1048  if (! $i) $totalarray['nbfield']++;
1049  if (! $i) $totalarray['totallocaltax1field']=$totalarray['nbfield'];
1050  $totalarray['totallocaltax1'] += $obj->total_localtax1;
1051  }
1052  // Amount LocalTax2
1053  if (! empty($arrayfields['f.total_localtax2']['checked']))
1054  {
1055  print '<td align="right">'.price($obj->total_localtax2)."</td>\n";
1056  if (! $i) $totalarray['nbfield']++;
1057  if (! $i) $totalarray['totallocaltax2field']=$totalarray['nbfield'];
1058  $totalarray['totallocaltax2'] += $obj->total_localtax2;
1059  }
1060  // Amount TTC
1061  if (! empty($arrayfields['f.total_ttc']['checked']))
1062  {
1063  print '<td align="right">'.price($obj->total_ttc)."</td>\n";
1064  if (! $i) $totalarray['nbfield']++;
1065  if (! $i) $totalarray['totalttcfield']=$totalarray['nbfield'];
1066  $totalarray['totalttc'] += $obj->total_ttc;
1067  }
1068 
1069  if (! empty($arrayfields['dynamount_payed']['checked']))
1070  {
1071  print '<td align="right">'.(! empty($totalpay)?price($totalpay,0,$langs):'&nbsp;').'</td>'; // TODO Use a denormalized field
1072  if (! $i) $totalarray['nbfield']++;
1073  if (! $i) $totalarray['totalamfield']=$totalarray['nbfield'];
1074  $totalarray['totalam'] += $totalpay;
1075  }
1076 
1077  if (! empty($arrayfields['rtp']['checked']))
1078  {
1079  print '<td align="right">'.(! empty($remaintopay)?price($remaintopay,0,$langs):'&nbsp;').'</td>'; // TODO Use a denormalized field
1080  if (! $i) $totalarray['nbfield']++;
1081  if (! $i) $totalarray['totalrtpfield']=$totalarray['nbfield'];
1082  $totalarray['totalrtp'] += $remaintopay;
1083  }
1084 
1085  // Extra fields
1086  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
1087  // Fields from hook
1088  $parameters=array('arrayfields'=>$arrayfields, 'obj'=>$obj);
1089  $reshook=$hookmanager->executeHooks('printFieldListValue',$parameters); // Note that $action and $object may have been modified by hook
1090  print $hookmanager->resPrint;
1091  // Date creation
1092  if (! empty($arrayfields['f.datec']['checked']))
1093  {
1094  print '<td align="center" class="nowrap">';
1095  print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
1096  print '</td>';
1097  if (! $i) $totalarray['nbfield']++;
1098  }
1099  // Date modification
1100  if (! empty($arrayfields['f.tms']['checked']))
1101  {
1102  print '<td align="center" class="nowrap">';
1103  print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser');
1104  print '</td>';
1105  if (! $i) $totalarray['nbfield']++;
1106  }
1107  // Status
1108  if (! empty($arrayfields['f.fk_statut']['checked']))
1109  {
1110  print '<td align="right" class="nowrap">';
1111  print $facturestatic->LibStatut($obj->paye,$obj->fk_statut,5,$paiement,$obj->type);
1112  print "</td>";
1113  if (! $i) $totalarray['nbfield']++;
1114  }
1115 
1116  // Action column
1117  print '<td class="nowrap" align="center">';
1118  if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
1119  {
1120  $selected=0;
1121  if (in_array($obj->id, $arrayofselected)) $selected=1;
1122  print '<input id="cb'.$obj->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->id.'"'.($selected?' checked="checked"':'').'>';
1123  }
1124  print '</td>' ;
1125  if (! $i) $totalarray['nbfield']++;
1126 
1127  print "</tr>\n";
1128 
1129  $i++;
1130  }
1131 
1132  // Show total line
1133  if (isset($totalarray['totalhtfield'])
1134  || isset($totalarray['totalvatfield'])
1135  || isset($totalarray['totallocaltax1field'])
1136  || isset($totalarray['totallocaltax2field'])
1137  || isset($totalarray['totalttcfield'])
1138  || isset($totalarray['totalamfield'])
1139  || isset($totalarray['totalrtpfield'])
1140  )
1141  {
1142  print '<tr class="liste_total">';
1143  $i=0;
1144  while ($i < $totalarray['nbfield'])
1145  {
1146  $i++;
1147  if ($i == 1)
1148  {
1149  if ($num < $limit && empty($offset)) print '<td align="left">'.$langs->trans("Total").'</td>';
1150  else print '<td align="left">'.$langs->trans("Totalforthispage").'</td>';
1151  }
1152  elseif ($totalarray['totalhtfield'] == $i) print '<td align="right">'.price($totalarray['totalht']).'</td>';
1153  elseif ($totalarray['totalvatfield'] == $i) print '<td align="right">'.price($totalarray['totalvat']).'</td>';
1154  elseif ($totalarray['totallocaltax1field'] == $i) print '<td align="right">'.price($totalarray['totallocaltax1']).'</td>';
1155  elseif ($totalarray['totallocaltax2field'] == $i) print '<td align="right">'.price($totalarray['totallocaltax2']).'</td>';
1156  elseif ($totalarray['totalttcfield'] == $i) print '<td align="right">'.price($totalarray['totalttc']).'</td>';
1157  elseif ($totalarray['totalamfield'] == $i) print '<td align="right">'.price($totalarray['totalam']).'</td>';
1158  elseif ($totalarray['totalrtpfield'] == $i) print '<td align="right">'.price($totalarray['totalrtp']).'</td>';
1159  else print '<td></td>';
1160  }
1161  print '</tr>';
1162 
1163  }
1164  }
1165 
1166  $db->free($resql);
1167 
1168  $parameters=array('arrayfields'=>$arrayfields, 'sql'=>$sql);
1169  $reshook=$hookmanager->executeHooks('printFieldListFooter',$parameters); // Note that $action and $object may have been modified by hook
1170  print $hookmanager->resPrint;
1171 
1172  print "</table>\n";
1173  print '</div>';
1174 
1175  print "</form>\n";
1176 
1177  if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files)
1178  {
1179  // Show list of available documents
1180  $urlsource=$_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
1181  $urlsource.=str_replace('&amp;','&',$param);
1182 
1183  $filedir=$diroutputmassaction;
1184  $genallowed=$user->rights->facture->lire;
1185  $delallowed=$user->rights->facture->creer;
1186 
1187  print $formfile->showdocuments('massfilesarea_invoices','',$filedir,$urlsource,0,$delallowed,'',1,1,0,48,1,$param,$title,'');
1188  }
1189  else
1190  {
1191  print '<br><a name="show_files"></a><a href="'.$_SERVER["PHP_SELF"].'?show_files=1'.$param.'#show_files">'.$langs->trans("ShowTempMassFilesArea").'</a>';
1192  }
1193 }
1194 else
1195 {
1196  dol_print_error($db);
1197 }
1198 
1199 llxFooter();
1200 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:58
const TYPE_STANDARD
Standard invoice.
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.
if(GETPOST('cancel','alpha')) if(!GETPOST('confirmmassaction','alpha')&&$massaction!= 'presend'&&$massaction!= 'confirm_presend')
Draft customers invoices.
Definition: list.php:147
const TYPE_REPLACEMENT
Replacement invoice.
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.
if(empty($reshook)) $form
View.
Definition: perms.php:103
const TYPE_SITUATION
Situation invoice.
Class to manage bank accounts.
const TYPE_CREDIT_NOTE
Credit note invoice.
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...
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.
if($_POST["cancel"]==$langs->trans("Cancel")&&!$id) if($action== 'setdatev'&&$user->rights->tax->charges->creer) if($action== 'add'&&$_POST["cancel"]<> $langs->trans("Cancel")) if($action== 'delete') $title
Actions.
Definition: card.php:183
const STATUS_DRAFT
Draft.
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).
const TYPE_DEPOSIT
Deposit 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: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.
Class to manage invoices.
price2num($amount, $rounding='', $alreadysqlnb=0)
Function that return a number with universal decimal format (decimal separator is '...
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $objcanvas=null)
Check permissions of a user to show a page and an object.