dolibarr  9.0.0
invoicetemplate_list.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2002-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
6  * Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es>
7  * Copyright (C) 2015 Jean-Fran├žois Ferry <jfefe@aternatik.fr>
8  * Copyright (C) 2012 Cedric Salvador <csalvador@gpcsolutions.fr>
9  * Copyright (C) 2015 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
10  * Copyright (C) 2016 Meziane Sof <virtualsof@yahoo.fr>
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program. If not, see <http://www.gnu.org/licenses/>.
24  */
25 
32 require '../../main.inc.php';
33 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture-rec.class.php';
34 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
35 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
36 if (! empty($conf->projet->enabled)) {
37  require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
38  //require_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.class.php';
39 }
40 require_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.class.php';
41 require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php';
42 require_once DOL_DOCUMENT_ROOT . '/core/lib/invoice.lib.php';
43 require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php';
44 
45 // Load translation files required by the page
46 $langs->loadLangs(array('bills', 'compta', 'admin', 'other'));
47 
48 $action = GETPOST('action','alpha');
49 $massaction = GETPOST('massaction','alpha');
50 $show_files = GETPOST('show_files','int');
51 $confirm = GETPOST('confirm','alpha');
52 $cancel = GETPOST('cancel', 'alpha');
53 $toselect = GETPOST('toselect', 'array');
54 $contextpage= GETPOST('contextpage','aZ')?GETPOST('contextpage','aZ'):'invoicetemplatelist'; // To manage different context of search
55 
56 // Security check
57 $id=(GETPOST('facid','int')?GETPOST('facid','int'):GETPOST('id','int'));
58 $lineid=GETPOST('lineid','int');
59 $ref=GETPOST('ref','alpha');
60 if ($user->societe_id) $socid=$user->societe_id;
61 $objecttype = 'facture_rec';
62 if ($action == "create" || $action == "add") $objecttype = '';
63 $result = restrictedArea($user, 'facture', $id, $objecttype);
64 $projectid = GETPOST('projectid','int');
65 
66 $search_ref=GETPOST('search_ref');
67 $search_societe=GETPOST('search_societe');
68 $search_montant_ht=GETPOST('search_montant_ht');
69 $search_montant_vat=GETPOST('search_montant_vat');
70 $search_montant_ttc=GETPOST('search_montant_ttc');
71 $search_payment_mode=GETPOST('search_payment_mode');
72 $search_payment_term=GETPOST('search_payment_term');
73 $search_day=GETPOST('search_day','int');
74 $search_year=GETPOST('search_year','int');
75 $search_month=GETPOST('search_month','int');
76 $search_day_date_when=GETPOST('search_day_date_when','int');
77 $search_year_date_when=GETPOST('search_year_date_when','int');
78 $search_month_date_when=GETPOST('search_month_date_when','int');
79 $search_recurring=GETPOST('search_recurring','int');
80 $search_frequency=GETPOST('search_frequency','alpha');
81 $search_unit_frequency=GETPOST('search_unit_frequency','alpha');
82 $search_status=GETPOST('search_status','int');
83 
84 $limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
85 $sortfield = GETPOST("sortfield",'alpha');
86 $sortorder = GETPOST("sortorder",'alpha');
87 $page = GETPOST("page",'int');
88 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
89 $offset = $limit * $page;
90 if (! $sortorder) $sortorder='DESC';
91 if (! $sortfield) $sortfield='f.titre';
92 $pageprev = $page - 1;
93 $pagenext = $page + 1;
94 
95 $object = new FactureRec($db);
96 if (($id > 0 || $ref) && $action != 'create' && $action != 'add')
97 {
98  $ret = $object->fetch($id, $ref);
99  if (!$ret)
100  {
101  setEventMessages($langs->trans("ErrorRecordNotFound"), null, 'errors');
102  }
103 }
104 
105 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
106 $hookmanager->initHooks(array('invoicereccard','globalcard'));
107 $extrafields = new ExtraFields($db);
108 
109 // fetch optionals attributes and labels
110 $extralabels = $extrafields->fetch_name_optionals_label('facture_rec');
111 $search_array_options=$extrafields->getOptionalsFromPost($object->table_element,'','search_');
112 
113 $permissionnote = $user->rights->facture->creer; // Used by the include of actions_setnotes.inc.php
114 $permissiondellink=$user->rights->facture->creer; // Used by the include of actions_dellink.inc.php
115 $permissiontoedit = $user->rights->facture->creer; // Used by the include of actions_lineupdonw.inc.php
116 
117 $arrayfields=array(
118  'f.titre'=>array('label'=>$langs->trans("Ref"), 'checked'=>1),
119  's.nom'=>array('label'=>$langs->trans("ThirdParty"), 'checked'=>1),
120  'f.total'=>array('label'=>$langs->trans("AmountHT"), 'checked'=>1),
121  'f.tva'=>array('label'=>$langs->trans("AmountVAT"), 'checked'=>1),
122  'f.total_ttc'=>array('label'=>$langs->trans("AmountTTC"), 'checked'=>1),
123  'f.fk_mode_reglement'=>array('label'=>$langs->trans("PaymentMode"), 'checked'=>0),
124  'f.fk_cond_reglement'=>array('label'=>$langs->trans("PaymentTerm"), 'checked'=>0),
125  'recurring'=>array('label'=>$langs->trans("RecurringInvoiceTemplate"), 'checked'=>1),
126  'f.frequency'=>array('label'=>$langs->trans("Frequency"), 'checked'=>1),
127  'f.unit_frequency'=>array('label'=>$langs->trans("FrequencyUnit"), 'checked'=>1),
128  'f.nb_gen_done'=>array('label'=>$langs->trans("NbOfGenerationDoneShort"), 'checked'=>1),
129  'f.date_last_gen'=>array('label'=>$langs->trans("DateLastGenerationShort"), 'checked'=>1),
130  'f.date_when'=>array('label'=>$langs->trans("NextDateToExecutionShort"), 'checked'=>1),
131  'status'=>array('label'=>$langs->trans("Status"), 'checked'=>1, 'position'=>100),
132  'f.datec'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0, 'position'=>500),
133  'f.tms'=>array('label'=>$langs->trans("DateModificationShort"), 'checked'=>0, 'position'=>500),
134 );
135 // Extra fields
136 if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
137 {
138  foreach($extrafields->attribute_label as $key => $val)
139  {
140  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]));
141  }
142 }
143 
144 
145 /*
146  * Actions
147  */
148 
149 if (GETPOST('cancel','alpha')) { $action='list'; $massaction=''; }
150 if (! GETPOST('confirmmassaction','alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction=''; }
151 
152 $parameters = array('socid' => $socid);
153 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
154 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
155 
156 if (empty($reshook))
157 {
158  if (GETPOST('cancel','alpha')) $action='';
159 
160  // Selection of new fields
161  include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
162 
163  // Do we click on purge search criteria ?
164  if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha')) // All test are required to be compatible with all browsers
165  {
166  $search_ref='';
167  $search_societe='';
168  $search_montant_ht='';
169  $search_montant_vat='';
170  $search_montant_ttc='';
171  $search_payment_mode='';
172  $search_payment_term='';
173  $search_day='';
174  $search_year='';
175  $search_month='';
176  $search_day_date_when='';
177  $search_year_date_when='';
178  $search_month_date_when='';
179  $search_recurring='';
180  $search_frequency='';
181  $search_unit_frequency='';
182  $search_status='';
183  $search_array_options=array();
184  }
185 
186  // Mass actions
187  /*$objectclass='MyObject';
188  $objectlabel='MyObject';
189  $permtoread = $user->rights->mymodule->read;
190  $permtodelete = $user->rights->mymodule->delete;
191  $uploaddir = $conf->mymodule->dir_output;
192  include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';*/
193 }
194 
195 
196 /*
197  * View
198  */
199 
200 llxHeader('',$langs->trans("RepeatableInvoices"),'ch-facture.html#s-fac-facture-rec');
201 
202 $form = new Form($db);
203 $formother = new FormOther($db);
204 if (! empty($conf->projet->enabled)) { $formproject = new FormProjets($db); }
205 $companystatic = new Societe($db);
206 $invoicerectmp = new FactureRec($db);
207 
208 $now = dol_now();
209 $tmparray=dol_getdate($now);
210 $today = dol_mktime(23,59,59,$tmparray['mon'],$tmparray['mday'],$tmparray['year']); // Today is last second of current day
211 
212 
213 /*
214  * List mode
215  */
216 $sql = "SELECT s.nom as name, s.rowid as socid, f.rowid as facid, f.titre, f.total, f.tva as total_vat, f.total_ttc, f.frequency, f.unit_frequency,";
217 $sql.= " f.nb_gen_done, f.nb_gen_max, f.date_last_gen, f.date_when, f.suspended,";
218 $sql.= " f.datec, f.tms,";
219 $sql.= " f.fk_cond_reglement, f.fk_mode_reglement";
220 $sql.= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture_rec as f";
221 if (! $user->rights->societe->client->voir && ! $socid) {
222  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
223 }
224 $sql.= " WHERE f.fk_soc = s.rowid";
225 $sql.= ' AND f.entity IN ('.getEntity('facture').')';
226 if (! $user->rights->societe->client->voir && ! $socid) {
227  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
228 }
229 if ($search_ref) $sql .= natural_search('f.titre', $search_ref);
230 if ($search_societe) $sql .= natural_search('s.nom', $search_societe);
231 if ($search_montant_ht != '') $sql .= natural_search('f.total', $search_montant_ht, 1);
232 if ($search_montant_vat != '') $sql .= natural_search('f.tva', $search_montant_vat, 1);
233 if ($search_montant_ttc != '') $sql .= natural_search('f.total_ttc', $search_montant_ttc, 1);
234 if (! empty($search_payment_mode) && $search_payment_mode != '-1') $sql .= natural_search('f.fk_mode_reglement', $search_payment_mode, 1);
235 if (! empty($search_payment_term) && $search_payment_term != '-1') $sql .= natural_search('f.fk_cond_reglement', $search_payment_term, 1);
236 if ($search_recurring == '1') $sql .= ' AND f.frequency > 0';
237 if ($search_recurring == '0') $sql .= ' AND (f.frequency IS NULL or f.frequency = 0)';
238 if ($search_frequency != '') $sql .= natural_search('f.frequency', $search_frequency, 1);
239 if ($search_unit_frequency != '') $sql .= ' AND f.frequency > 0'.natural_search('f.unit_frequency', $search_unit_frequency);
240 if ($search_status != '' && $search_status >= -1)
241 {
242  if ($search_status == 0) $sql.= ' AND frequency = 0 AND suspended = 0';
243  if ($search_status == 1) $sql.= ' AND frequency != 0 AND suspended = 0';
244  if ($search_status == -1) $sql.= ' AND suspended = 1';
245 }
246 if ($search_month > 0)
247 {
248  if ($search_year > 0 && empty($search_day))
249  $sql.= " AND f.date_last_gen BETWEEN '".$db->idate(dol_get_first_day($search_year,$search_month,false))."' AND '".$db->idate(dol_get_last_day($search_year,$search_month,false))."'";
250  else if ($search_year > 0 && ! empty($search_day))
251  $sql.= " AND f.date_last_gen BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $search_month, $search_day, $search_year))."' AND '".$db->idate(dol_mktime(23, 59, 59, $search_month, $search_day, $search_year))."'";
252  else
253  $sql.= " AND date_format(f.date_last_gen, '%m') = '".$db->escape($search_month)."'";
254 }
255 else if ($search_year > 0)
256 {
257  $sql.= " AND f.date_last_gen BETWEEN '".$db->idate(dol_get_first_day($search_year,1,false))."' AND '".$db->idate(dol_get_last_day($search_year,12,false))."'";
258 }
259 if ($search_month_date_when > 0)
260 {
261  if ($search_year_date_when > 0 && empty($search_day_date_when))
262  $sql.= " AND f.date_when BETWEEN '".$db->idate(dol_get_first_day($search_year_date_when,$search_month_date_when,false))."' AND '".$db->idate(dol_get_last_day($search_year_date_when,$search_month_date_when,false))."'";
263  else if ($search_year_date_when > 0 && ! empty($search_day_date_when))
264  $sql.= " AND f.date_date_when_reglement BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $search_month_date_when, $search_day_date_when, $search_year_date_when))."' AND '".$db->idate(dol_mktime(23, 59, 59, $search_month_date_when, $search_day_date_when, $search_year_date_when))."'";
265  else
266  $sql.= " AND date_format(f.date_when, '%m') = '".$db->escape($search_month_date_when)."'";
267 }
268 else if ($search_year_date_when > 0)
269 {
270  $sql.= " AND f.date_when BETWEEN '".$db->idate(dol_get_first_day($search_year_date_when,1,false))."' AND '".$db->idate(dol_get_last_day($search_year_date_when,12,false))."'";
271 }
272 
273 $sql.= $db->order($sortfield, $sortorder);
274 
275 $nbtotalofrecords = '';
276 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
277 {
278  $result = $db->query($sql);
279  $nbtotalofrecords = $db->num_rows($result);
280  if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0
281  {
282  $page = 0;
283  $offset = 0;
284  }
285 }
286 
287 $sql.= $db->plimit($limit+1,$offset);
288 
289 $resql = $db->query($sql);
290 if ($resql)
291 {
292  $num = $db->num_rows($resql);
293 
294  $param='';
295  if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.urlencode($contextpage);
296  if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.urlencode($limit);
297  if ($socid) $param.='&socid='.urlencode($socid);
298  if ($search_day) $param.='&search_day='.urlencode($search_day);
299  if ($search_month) $param.='&search_month='.urlencode($search_month);
300  if ($search_year) $param.='&search_year=' .urlencode($search_year);
301  if ($search_day_date_when) $param.='&search_day_date_when='.urlencode($search_day_date_when);
302  if ($search_month_date_when) $param.='&search_month_date_when='.urlencode($search_month_date_when);
303  if ($search_year_date_when) $param.='&search_year_date_when=' .urlencode($search_year_date_when);
304  if ($search_ref) $param.='&search_ref=' .urlencode($search_ref);
305  if ($search_societe) $param.='&search_societe=' .urlencode($search_societe);
306  if ($search_montant_ht != '') $param.='&search_montant_ht=' .urlencode($search_montant_ht);
307  if ($search_montant_vat != '') $param.='&search_montant_vat='.urlencode($search_montant_vat);
308  if ($search_montant_ttc != '') $param.='&search_montant_ttc='.urlencode($search_montant_ttc);
309  if ($search_payment_mode != '') $param.='&search_payment_mode='.urlencode($search_payment_mode);
310  if ($search_payment_type != '') $param.='&search_payment_type='.urlencode($search_payment_type);
311  if ($search_recurring != '' && $search_recurrning != '-1') $param.='&search_recurring=' .urlencode($search_recurring);
312  if ($search_frequency > 0) $param.='&search_frequency=' .urlencode($search_frequency);
313  if ($search_unit_frequency != '') $param.='&search_unit_frequency='.urlencode($search_unit_frequency);
314  if ($search_status != '') $param.='&search_status='.urlencode($search_status);
315  if ($option) $param.="&option=".urlencode($option);
316  if ($optioncss != '') $param.='&optioncss='.urlencode($optioncss);
317  // Add $param from extra fields
318  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
319 
320  $massactionbutton=$form->selectMassAction('', $massaction == 'presend' ? array() : array('presend'=>$langs->trans("SendByMail"), 'builddoc'=>$langs->trans("PDFMerge")));
321 
322  $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
323  $selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
324  //$selectedfields.=$form->showCheckAddButtons('checkforselect', 1);
325 
326  print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
327  if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
328  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
329  print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
330  print '<input type="hidden" name="action" value="list">';
331  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
332  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
333  print '<input type="hidden" name="page" value="'.$page.'">';
334  print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
335  print '<input type="hidden" name="viewstatut" value="'.$viewstatut.'">';
336 
337  print_barre_liste($langs->trans("RepeatableInvoices"),$page,$_SERVER['PHP_SELF'],$param,$sortfield,$sortorder,'',$num,$nbtotalofrecords,'title_accountancy.png',0,'','', $limit);
338 
339  print $langs->trans("ToCreateAPredefinedInvoice", $langs->transnoentitiesnoconv("ChangeIntoRepeatableInvoice")).'<br><br>';
340 
341  $i = 0;
342 
343  print '<div class="div-table-responsive">';
344  print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
345 
346  // Filters lines
347  print '<tr class="liste_titre_filter">';
348  // Ref
349  if (! empty($arrayfields['f.titre']['checked']))
350  {
351  print '<td class="liste_titre" align="left">';
352  print '<input class="flat" size="6" type="text" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">';
353  print '</td>';
354  }
355  // Thirpdarty
356  if (! empty($arrayfields['s.nom']['checked']))
357  {
358  print '<td class="liste_titre" align="left"><input class="flat" type="text" size="8" name="search_societe" value="'.dol_escape_htmltag($search_societe).'"></td>';
359  }
360  if (! empty($arrayfields['f.total']['checked']))
361  {
362  // Amount net
363  print '<td class="liste_titre" align="right">';
364  print '<input class="flat" type="text" size="5" name="search_montant_ht" value="'.dol_escape_htmltag($search_montant_ht).'">';
365  print '</td>';
366  }
367  if (! empty($arrayfields['f.tva']['checked']))
368  {
369  // Amount Vat
370  print '<td class="liste_titre" align="right">';
371  print '<input class="flat" type="text" size="5" name="search_montant_vat" value="'.dol_escape_htmltag($search_montant_vat).'">';
372  print '</td>';
373  }
374  if (! empty($arrayfields['f.total_ttc']['checked']))
375  {
376  // Amount
377  print '<td class="liste_titre" align="right">';
378  print '<input class="flat" type="text" size="5" name="search_montant_ttc" value="'.dol_escape_htmltag($search_montant_ttc).'">';
379  print '</td>';
380  }
381  if (! empty($arrayfields['f.fk_cond_reglement']['checked']))
382  {
383  // Payment term
384  print '<td class="liste_titre" align="right">';
385  print $form->select_conditions_paiements($search_payment_term, 'search_payment_term', -1, 1, 1, 'maxwidth100');
386  print "</td>";
387  }
388  if (! empty($arrayfields['f.fk_mode_reglement']['checked']))
389  {
390  // Payment mode
391  print '<td class="liste_titre" align="right">';
392  print $form->select_types_paiements($search_payment_mode, 'search_payment_mode', '', 0, 1, 1, 0, 1, 'maxwidth100');
393  print '</td>';
394  }
395  if (! empty($arrayfields['recurring']['checked']))
396  {
397  // Recurring or not
398  print '<td class="liste_titre" align="center">';
399  print $form->selectyesno('search_recurring', $search_recurring, 1, false, 1);
400  print '</td>';
401  }
402  if (! empty($arrayfields['f.frequency']['checked']))
403  {
404  // Recurring or not
405  print '<td class="liste_titre" align="center">';
406  print '<input class="flat" type="text" size="1" name="search_frequency" value="'.dol_escape_htmltag($search_frequency).'">';
407  print '</td>';
408  }
409  if (! empty($arrayfields['f.unit_frequency']['checked']))
410  {
411  // Frequency unit
412  print '<td class="liste_titre" align="center">';
413  print '<input class="flat" type="text" size="1" name="search_unit_frequency" value="'.dol_escape_htmltag($search_unit_frequency).'">';
414  print '</td>';
415  }
416  if (! empty($arrayfields['f.nb_gen_done']['checked']))
417  {
418  // Nb generation
419  print '<td class="liste_titre" align="center">';
420  print '</td>';
421  }
422  // Date invoice
423  if (! empty($arrayfields['f.date_last_gen']['checked']))
424  {
425  print '<td class="liste_titre nowraponall" align="center">';
426  if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat valignmiddle" type="text" size="1" maxlength="2" name="search_day" value="'.$search_day.'">';
427  print '<input class="flat valignmiddle width25" type="text" size="1" maxlength="2" name="search_month" value="'.$search_month.'">';
428  $formother->select_year($search_year?$search_year:-1,'search_year',1, 20, 5, 0, 0, '', 'witdhauto valignmiddle');
429  print '</td>';
430  }
431  // Date next generation
432  if (! empty($arrayfields['f.date_when']['checked']))
433  {
434  print '<td class="liste_titre nowraponall" align="center">';
435  if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat valignmiddle" type="text" size="1" maxlength="2" name="search_day_date_when" value="'.$search_day_date_when.'">';
436  print '<input class="flat valignmiddle width25" type="text" size="1" maxlength="2" name="search_month_date_when" value="'.$search_month_date_when.'">';
437  $formother->select_year($search_year_date_when?$search_year_date_when:-1,'search_year_date_when',1, 20, 5, 0, 0, '', 'witdhauto valignmiddle');
438  print '</td>';
439  }
440  // Extra fields
441  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
442 
443  // Fields from hook
444  $parameters=array('arrayfields'=>$arrayfields);
445  $reshook=$hookmanager->executeHooks('printFieldListOption',$parameters); // Note that $action and $object may have been modified by hook
446  print $hookmanager->resPrint;
447  // Date creation
448  if (! empty($arrayfields['f.datec']['checked']))
449  {
450  print '<td class="liste_titre">';
451  print '</td>';
452  }
453  // Date modification
454  if (! empty($arrayfields['f.tms']['checked']))
455  {
456  print '<td class="liste_titre">';
457  print '</td>';
458  }
459  // Status
460  if (! empty($arrayfields['status']['checked']))
461  {
462  print '<td class="liste_titre" align="center">';
463  $liststatus=array(
464  0=>$langs->trans("Draft"),
465  1=>$langs->trans("Active"),
466  -1=>$langs->trans("Disabled"),
467  );
468  print $form->selectarray('search_status', $liststatus, $search_status, -2);
469  print '</td>';
470  }
471  // Action column
472  print '<td class="liste_titre" align="middle">';
473  $searchpicto=$form->showFilterAndCheckAddButtons(0, 'checkforselect', 1);
474  print $searchpicto;
475  print '</td>';
476  print "</tr>\n";
477 
478 
479  print '<tr class="liste_titre">';
480  if (! empty($arrayfields['f.titre']['checked'])) print_liste_field_titre($arrayfields['f.titre']['label'],$_SERVER['PHP_SELF'],"f.titre","",$param,"",$sortfield,$sortorder);
481  if (! empty($arrayfields['s.nom']['checked'])) print_liste_field_titre($arrayfields['s.nom']['label'],$_SERVER['PHP_SELF'],"s.nom","",$param,"",$sortfield,$sortorder);
482  if (! empty($arrayfields['f.total']['checked'])) print_liste_field_titre($arrayfields['f.total']['label'],$_SERVER['PHP_SELF'],"f.total","",$param,'align="right"',$sortfield,$sortorder);
483  if (! empty($arrayfields['f.tva']['checked'])) print_liste_field_titre($arrayfields['f.tva']['label'],$_SERVER['PHP_SELF'],"f.tva","",$param,'align="right"',$sortfield,$sortorder);
484  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);
485  if (! empty($arrayfields['f.fk_cond_reglement']['checked'])) print_liste_field_titre($arrayfields['f.fk_cond_reglement']['label'],$_SERVER['PHP_SELF'],"f.fk_cond_reglement","",$param,'',$sortfield,$sortorder);
486  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);
487  if (! empty($arrayfields['recurring']['checked'])) print_liste_field_titre($arrayfields['recurring']['label'],$_SERVER['PHP_SELF'],"recurring","",$param,'align="center"',$sortfield,$sortorder);
488  if (! empty($arrayfields['f.frequency']['checked'])) print_liste_field_titre($arrayfields['f.frequency']['label'],$_SERVER['PHP_SELF'],"f.frequency","",$param,'align="center"',$sortfield,$sortorder);
489  if (! empty($arrayfields['f.unit_frequency']['checked'])) print_liste_field_titre($arrayfields['f.unit_frequency']['label'],$_SERVER['PHP_SELF'],"f.unit_frequency","",$param,'align="center"',$sortfield,$sortorder);
490  if (! empty($arrayfields['f.nb_gen_done']['checked'])) print_liste_field_titre($arrayfields['f.nb_gen_done']['label'],$_SERVER['PHP_SELF'],"f.nb_gen_done","",$param,'align="center"',$sortfield,$sortorder);
491  if (! empty($arrayfields['f.date_last_gen']['checked'])) print_liste_field_titre($arrayfields['f.date_last_gen']['label'],$_SERVER['PHP_SELF'],"f.date_last_gen","",$param,'align="center"',$sortfield,$sortorder);
492  if (! empty($arrayfields['f.date_when']['checked'])) print_liste_field_titre($arrayfields['f.date_when']['label'],$_SERVER['PHP_SELF'],"f.date_when","",$param,'align="center"',$sortfield,$sortorder);
493  if (! empty($arrayfields['f.datec']['checked'])) print_liste_field_titre($arrayfields['f.datec']['label'],$_SERVER['PHP_SELF'],"f.datec","",$param,'align="center"',$sortfield,$sortorder);
494  if (! empty($arrayfields['f.tms']['checked'])) print_liste_field_titre($arrayfields['f.tms']['label'],$_SERVER['PHP_SELF'],"f.tms","",$param,'align="center"',$sortfield,$sortorder);
495  if (! empty($arrayfields['status']['checked'])) print_liste_field_titre($arrayfields['status']['label'],$_SERVER['PHP_SELF'],"f.suspended,f.frequency","",$param,'align="center"',$sortfield,$sortorder);
496  print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'','','align="center"',$sortfield,$sortorder,'nomaxwidthsearch ')."\n";
497  print "</tr>\n";
498 
499  if ($num > 0)
500  {
501  $i=0;
502  $totalarray=array();
503  while ($i < min($num,$limit))
504  {
505  $objp = $db->fetch_object($resql);
506  if (empty($objp)) break;
507 
508  $companystatic->id=$objp->socid;
509  $companystatic->name=$objp->name;
510 
511  $invoicerectmp->id=$objp->id?$objp->id:$objp->facid;
512  $invoicerectmp->frequency=$objp->frequency;
513  $invoicerectmp->suspended=$objp->suspended;
514  $invoicerectmp->unit_frequency=$objp->unit_frequency;
515  $invoicerectmp->nb_gen_max=$objp->nb_gen_max;
516  $invoicerectmp->nb_gen_done=$objp->nb_gen_done;
517  $invoicerectmp->ref=$objp->titre;
518 
519  print '<tr class="oddeven">';
520 
521  if (! empty($arrayfields['f.titre']['checked']))
522  {
523  print '<td>';
524  print $invoicerectmp->getNomUrl(1);
525  print "</a>";
526  print "</td>\n";
527  if (! $i) $totalarray['nbfield']++;
528  }
529  if (! empty($arrayfields['s.nom']['checked']))
530  {
531  print '<td class="tdoverflowmax200">'.$companystatic->getNomUrl(1,'customer').'</td>';
532  if (! $i) $totalarray['nbfield']++;
533  }
534  if (! empty($arrayfields['f.total']['checked']))
535  {
536  print '<td align="right">'.price($objp->total).'</td>'."\n";
537  if (! $i) $totalarray['nbfield']++;
538  if (! $i) $totalarray['pos'][$totalarray['nbfield']]='f.total';
539  $totalarray['val']['f.total'] += $objp->total;
540  }
541  if (! empty($arrayfields['f.tva']['checked']))
542  {
543  print '<td align="right">'.price($objp->total_vat).'</td>'."\n";
544  if (! $i) $totalarray['nbfield']++;
545  if (! $i) $totalarray['pos'][$totalarray['nbfield']]='f.tva';
546  $totalarray['val']['f.tva'] += $objp->total_vat;
547  }
548  if (! empty($arrayfields['f.total_ttc']['checked']))
549  {
550  print '<td align="right">'.price($objp->total_ttc).'</td>'."\n";
551  if (! $i) $totalarray['nbfield']++;
552  if (! $i) $totalarray['pos'][$totalarray['nbfield']]='f.total_ttc';
553  $totalarray['val']['f.total_ttc'] += $objp->total_ttc;
554  }
555  // Payment term
556  if (! empty($arrayfields['f.fk_cond_reglement']['checked']))
557  {
558  print '<td align="right">';
559  print $form->form_conditions_reglement('', $objp->fk_cond_reglement, 'none');
560  print '</td>'."\n";
561  if (! $i) $totalarray['nbfield']++;
562  }
563  // Payment mode
564  if (! empty($arrayfields['f.fk_mode_reglement']['checked']))
565  {
566  print '<td align="right">';
567  print $form->form_modes_reglement('', $objp->fk_mode_reglement, 'none');
568  print '</td>'."\n";
569  if (! $i) $totalarray['nbfield']++;
570  }
571  if (! empty($arrayfields['recurring']['checked']))
572  {
573  print '<td align="center">'.yn($objp->frequency?1:0).'</td>';
574  if (! $i) $totalarray['nbfield']++;
575  }
576  if (! empty($arrayfields['f.frequency']['checked']))
577  {
578  print '<td align="center">'.($objp->frequency > 0 ? $objp->frequency : '').'</td>';
579  if (! $i) $totalarray['nbfield']++;
580  }
581  if (! empty($arrayfields['f.unit_frequency']['checked']))
582  {
583  print '<td align="center">'.($objp->frequency > 0 ? $objp->unit_frequency : '').'</td>';
584  if (! $i) $totalarray['nbfield']++;
585  }
586  if (! empty($arrayfields['f.nb_gen_done']['checked']))
587  {
588  print '<td align="center">';
589  print ($objp->frequency > 0 ? $objp->nb_gen_done.($objp->nb_gen_max>0?' / '. $objp->nb_gen_max:'') : '<span class="opacitymedium">'.$langs->trans('NA').'</span>');
590  print '</td>';
591  if (! $i) $totalarray['nbfield']++;
592  }
593  // Date last generation
594  if (! empty($arrayfields['f.date_last_gen']['checked']))
595  {
596  print '<td align="center">';
597  print ($objp->frequency > 0 ? dol_print_date($db->jdate($objp->date_last_gen),'day') : '<span class="opacitymedium">'.$langs->trans('NA').'</span>');
598  print '</td>';
599  if (! $i) $totalarray['nbfield']++;
600  }
601  // Date next generation
602  if (! empty($arrayfields['f.date_when']['checked']))
603  {
604  print '<td align="center">';
605  print '<div class="nowraponall">';
606  print ($objp->frequency ? ($invoicerectmp->isMaxNbGenReached()?'<strike>':'').dol_print_date($db->jdate($objp->date_when),'day').($invoicerectmp->isMaxNbGenReached()?'</strike>':'') : '<span class="opacitymedium">'.$langs->trans('NA').'</span>');
607  if (! $invoicerectmp->isMaxNbGenReached())
608  {
609  if (! $objp->suspended && $objp->frequency > 0 && $db->jdate($objp->date_when) && $db->jdate($objp->date_when) < $now) print img_warning($langs->trans("Late"));
610  }
611  else
612  {
613  print img_info($langs->trans("MaxNumberOfGenerationReached"));
614  }
615  print '</div>';
616  print '</td>';
617  if (! $i) $totalarray['nbfield']++;
618  }
619  if (! empty($arrayfields['f.datec']['checked']))
620  {
621  print '<td align="center">';
622  print dol_print_date($db->jdate($objp->datec),'dayhour');
623  print '</td>';
624  if (! $i) $totalarray['nbfield']++;
625  }
626  if (! empty($arrayfields['f.tms']['checked']))
627  {
628  print '<td align="center">';
629  print dol_print_date($db->jdate($objp->tms),'dayhour');
630  print '</td>';
631  if (! $i) $totalarray['nbfield']++;
632  }
633  if (! empty($arrayfields['status']['checked']))
634  {
635  print '<td align="center">';
636  print $invoicerectmp->getLibStatut(3,0);
637  print '</td>';
638  if (! $i) $totalarray['nbfield']++;
639  }
640  // Action column
641  print '<td align="center">';
642  if ($user->rights->facture->creer && empty($invoicerectmp->suspended))
643  {
644  if ($invoicerectmp->isMaxNbGenReached())
645  {
646  print $langs->trans("MaxNumberOfGenerationReached");
647  }
648  elseif (empty($objp->frequency) || $db->jdate($objp->date_when) <= $today)
649  {
650  print '<a href="'.DOL_URL_ROOT.'/compta/facture/card.php?action=create&amp;socid='.$objp->socid.'&amp;fac_rec='.$objp->facid.'">';
651  print $langs->trans("CreateBill").'</a>';
652  }
653  else
654  {
655  print $form->textwithpicto('', $langs->trans("DateIsNotEnough"));
656  }
657  }
658  else
659  {
660  print "&nbsp;";
661  }
662  if (! $i) $totalarray['nbfield']++;
663  print "</td>";
664 
665  print "</tr>\n";
666 
667  $i++;
668  }
669  }
670  else
671  {
672  $colspan=1;
673  foreach($arrayfields as $key => $val) { if (! empty($val['checked'])) $colspan++; }
674  print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
675  }
676 
677  //var_dump($totalarray);
678  // Show total line
679  if (isset($totalarray['pos']))
680  {
681  print '<tr class="liste_total">';
682  $i=0;
683  while ($i < $totalarray['nbfield'])
684  {
685  $i++;
686  if (! empty($totalarray['pos'][$i])) print '<td align="right">'.price($totalarray['val'][$totalarray['pos'][$i]]).'</td>';
687  else
688  {
689  if ($i == 1)
690  {
691  if ($num < $limit) print '<td align="left">'.$langs->trans("Total").'</td>';
692  else print '<td align="left">'.$langs->trans("Totalforthispage").'</td>';
693  }
694  else print '<td></td>';
695  }
696  }
697  print '</tr>';
698  }
699 
700  print "</table>";
701  print "</div>";
702  print "</form>";
703 
704  $db->free($resql);
705 }
706 else
707 {
708  dol_print_error($db);
709 }
710 
711 // End of page
712 llxFooter();
713 $db->close();
img_warning($titlealt='default', $moreatt='')
Show warning logo.
llxFooter()
Empty footer.
Definition: wrapper.php:56
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) if(! empty($conf->don->enabled) && $user->rights->societe->lire) if(! empty($conf->tax->enabled) && $user->rights->tax->charges->lire) if(! empty($conf->facture->enabled) &&! empty($conf->commande->enabled) && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1053
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...
Class to manage invoice templates.
img_info($titlealt='default')
Show info logo.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition: date.lib.php:453
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
Class to manage standard extra fields.
Class to manage generation of HTML components Only common components must be here.
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='title_generic.png', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0)
Print a title with navigation controls for pagination.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage building of HTML components.
Classe permettant la generation de composants html autre Only common components are here...
llxHeader()
Empty header.
Definition: wrapper.php:44
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
dol_now($mode='gmt')
Return date for now.
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:467
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="")
Show title line of an array.
dol_getdate($timestamp, $fast=false)
Return an array with locale date info.