dolibarr  13.0.2
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@open-dsi.fr>
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 <https://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 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
37 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
38 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
39 require_once DOL_DOCUMENT_ROOT.'/core/lib/invoice.lib.php';
40 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
41 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
42 
43 // Load translation files required by the page
44 $langs->loadLangs(array('bills', 'compta', 'admin', 'other'));
45 
46 $action = GETPOST('action', 'alpha');
47 $massaction = GETPOST('massaction', 'alpha');
48 $show_files = GETPOST('show_files', 'int');
49 $confirm = GETPOST('confirm', 'alpha');
50 $cancel = GETPOST('cancel', 'alpha');
51 $toselect = GETPOST('toselect', 'array');
52 $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'invoicetemplatelist'; // To manage different context of search
53 
54 $socid = GETPOST('socid', 'int');
55 
56 $socid = GETPOST('socid', 'int');
57 
58 // Security check
59 $id = (GETPOST('facid', 'int') ?GETPOST('facid', 'int') : GETPOST('id', 'int'));
60 $lineid = GETPOST('lineid', 'int');
61 $ref = GETPOST('ref', 'alpha');
62 if ($user->socid) $socid = $user->socid;
63 $objecttype = 'facture_rec';
64 if ($action == "create" || $action == "add") $objecttype = '';
65 $result = restrictedArea($user, 'facture', $id, $objecttype);
66 
67 $search_ref = GETPOST('search_ref');
68 $search_societe = GETPOST('search_societe');
69 $search_montant_ht = GETPOST('search_montant_ht');
70 $search_montant_vat = GETPOST('search_montant_vat');
71 $search_montant_ttc = GETPOST('search_montant_ttc');
72 $search_payment_mode = GETPOST('search_payment_mode');
73 $search_payment_term = GETPOST('search_payment_term');
74 $search_day = GETPOST('search_day', 'int');
75 $search_year = GETPOST('search_year', 'int');
76 $search_month = GETPOST('search_month', 'int');
77 $search_day_date_when = GETPOST('search_day_date_when', 'int');
78 $search_year_date_when = GETPOST('search_year_date_when', 'int');
79 $search_month_date_when = GETPOST('search_month_date_when', 'int');
80 $search_recurring = GETPOST('search_recurring', 'int');
81 $search_frequency = GETPOST('search_frequency', 'alpha');
82 $search_unit_frequency = GETPOST('search_unit_frequency', 'alpha');
83 $search_status = GETPOST('search_status', 'int');
84 
85 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
86 $sortfield = GETPOST("sortfield", 'alpha');
87 $sortorder = GETPOST("sortorder", 'alpha');
88 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
89 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
90 $offset = $limit * $page;
91 if (!$sortorder) $sortorder = 'DESC';
92 if (!$sortfield) $sortfield = 'f.titre';
93 $pageprev = $page - 1;
94 $pagenext = $page + 1;
95 
96 $object = new FactureRec($db);
97 if (($id > 0 || $ref) && $action != 'create' && $action != 'add')
98 {
99  $ret = $object->fetch($id, $ref);
100  if (!$ret)
101  {
102  setEventMessages($langs->trans("ErrorRecordNotFound"), null, 'errors');
103  }
104 }
105 
106 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
107 $hookmanager->initHooks(array('invoicereclist'));
108 $extrafields = new ExtraFields($db);
109 
110 // fetch optionals attributes and labels
111 $extrafields->fetch_name_optionals_label($object->table_element);
112 
113 $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
114 
115 $permissionnote = $user->rights->facture->creer; // Used by the include of actions_setnotes.inc.php
116 $permissiondellink = $user->rights->facture->creer; // Used by the include of actions_dellink.inc.php
117 $permissiontoedit = $user->rights->facture->creer; // Used by the include of actions_lineupdonw.inc.php
118 
119 $arrayfields = array(
120  'f.titre'=>array('label'=>$langs->trans("Ref"), 'checked'=>1),
121  's.nom'=>array('label'=>$langs->trans("ThirdParty"), 'checked'=>1),
122  'f.total'=>array('label'=>$langs->trans("AmountHT"), 'checked'=>1),
123  'f.tva'=>array('label'=>$langs->trans("AmountVAT"), 'checked'=>1),
124  'f.total_ttc'=>array('label'=>$langs->trans("AmountTTC"), 'checked'=>1),
125  'f.fk_mode_reglement'=>array('label'=>$langs->trans("PaymentMode"), 'checked'=>0),
126  'f.fk_cond_reglement'=>array('label'=>$langs->trans("PaymentTerm"), 'checked'=>0),
127  'recurring'=>array('label'=>$langs->trans("RecurringInvoiceTemplate"), 'checked'=>1),
128  'f.frequency'=>array('label'=>$langs->trans("Frequency"), 'checked'=>1),
129  'f.unit_frequency'=>array('label'=>$langs->trans("FrequencyUnit"), 'checked'=>1),
130  'f.nb_gen_done'=>array('label'=>$langs->trans("NbOfGenerationDoneShort"), 'checked'=>1),
131  'f.date_last_gen'=>array('label'=>$langs->trans("DateLastGenerationShort"), 'checked'=>1),
132  'f.date_when'=>array('label'=>$langs->trans("NextDateToExecutionShort"), 'checked'=>1),
133  'status'=>array('label'=>$langs->trans("Status"), 'checked'=>1, 'position'=>100),
134  'f.datec'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0, 'position'=>500),
135  'f.tms'=>array('label'=>$langs->trans("DateModificationShort"), 'checked'=>0, 'position'=>500),
136 );
137 // Extra fields
138 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
139 
140 $object->fields = dol_sort_array($object->fields, 'position');
141 $arrayfields = dol_sort_array($arrayfields, 'position');
142 
143 if ($socid > 0) {
144  $tmpthirdparty = new Societe($db);
145  $res = $tmpthirdparty->fetch($socid);
146  if ($res > 0) $search_societe = $tmpthirdparty->name;
147 }
148 
149 
150 if ($socid > 0) {
151  $tmpthirdparty = new Societe($db);
152  $res = $tmpthirdparty->fetch($socid);
153  if ($res > 0) $search_societe = $tmpthirdparty->name;
154 }
155 
156 /*
157  * Actions
158  */
159 
160 if (GETPOST('cancel', 'alpha')) { $action = 'list'; $massaction = ''; }
161 if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction = ''; }
162 
163 $parameters = array('socid' => $socid);
164 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
165 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
166 
167 if (empty($reshook))
168 {
169  if (GETPOST('cancel', 'alpha')) $action = '';
170 
171  // Selection of new fields
172  include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
173 
174  // Do we click on purge search criteria ?
175  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
176  {
177  $search_ref = '';
178  $search_societe = '';
179  $search_montant_ht = '';
180  $search_montant_vat = '';
181  $search_montant_ttc = '';
182  $search_payment_mode = '';
183  $search_payment_term = '';
184  $search_day = '';
185  $search_year = '';
186  $search_month = '';
187  $search_day_date_when = '';
188  $search_year_date_when = '';
189  $search_month_date_when = '';
190  $search_recurring = '';
191  $search_frequency = '';
192  $search_unit_frequency = '';
193  $search_status = '';
194  $search_array_options = array();
195  }
196 
197  // Mass actions
198  /*$objectclass='MyObject';
199  $objectlabel='MyObject';
200  $permissiontoread = $user->rights->mymodule->read;
201  $permissiontodelete = $user->rights->mymodule->delete;
202  $uploaddir = $conf->mymodule->dir_output;
203  include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';*/
204 }
205 
206 
207 /*
208  * View
209  */
210 
211 llxHeader('', $langs->trans("RepeatableInvoices"), 'ch-facture.html#s-fac-facture-rec');
212 
213 $form = new Form($db);
214 $formother = new FormOther($db);
215 if (!empty($conf->projet->enabled)) { $formproject = new FormProjets($db); }
216 $companystatic = new Societe($db);
217 $invoicerectmp = new FactureRec($db);
218 
219 $now = dol_now();
220 $tmparray = dol_getdate($now);
221 $today = dol_mktime(23, 59, 59, $tmparray['mon'], $tmparray['mday'], $tmparray['year']); // Today is last second of current day
222 
223 
224 /*
225  * List mode
226  */
227 
228 $sql = "SELECT s.nom as name, s.rowid as socid, f.rowid as facid, f.titre as title, f.total, f.tva as total_vat, f.total_ttc, f.frequency, f.unit_frequency,";
229 $sql .= " f.nb_gen_done, f.nb_gen_max, f.date_last_gen, f.date_when, f.suspended,";
230 $sql .= " f.datec, f.tms,";
231 $sql .= " f.fk_cond_reglement, f.fk_mode_reglement";
232 // Add fields from extrafields
233 if (!empty($extrafields->attributes[$object->table_element]['label'])) {
234  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key.' as options_'.$key : '');
235 }
236 // Add fields from hooks
237 $parameters = array();
238 $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
239 $sql .= preg_replace('/^,/', '', $hookmanager->resPrint);
240 $sql = preg_replace('/,\s*$/', '', $sql);
241 
242 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture_rec as f";
243 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture_rec_extrafields as ef ON ef.fk_object = f.rowid";
244 if (!$user->rights->societe->client->voir && !$socid) {
245  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
246 }
247 $sql .= " WHERE f.fk_soc = s.rowid";
248 $sql .= ' AND f.entity IN ('.getEntity('invoice').')';
249 if (!$user->rights->societe->client->voir && !$socid) {
250  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
251 }
252 if ($search_ref) $sql .= natural_search('f.titre', $search_ref);
253 if ($socid) $sql .= ' AND s.rowid = '.(int) $socid;
254 if ($search_societe) $sql .= natural_search('s.nom', $search_societe);
255 if ($search_montant_ht != '') $sql .= natural_search('f.total', $search_montant_ht, 1);
256 if ($search_montant_vat != '') $sql .= natural_search('f.tva', $search_montant_vat, 1);
257 if ($search_montant_ttc != '') $sql .= natural_search('f.total_ttc', $search_montant_ttc, 1);
258 if (!empty($search_payment_mode) && $search_payment_mode != '-1') $sql .= natural_search('f.fk_mode_reglement', $search_payment_mode, 1);
259 if (!empty($search_payment_term) && $search_payment_term != '-1') $sql .= natural_search('f.fk_cond_reglement', $search_payment_term, 1);
260 if ($search_recurring == '1') $sql .= ' AND f.frequency > 0';
261 if ($search_recurring == '0') $sql .= ' AND (f.frequency IS NULL or f.frequency = 0)';
262 if ($search_frequency != '') $sql .= natural_search('f.frequency', $search_frequency, 1);
263 if ($search_unit_frequency != '') $sql .= ' AND f.frequency > 0'.natural_search('f.unit_frequency', $search_unit_frequency);
264 if ($search_status != '' && $search_status >= -1)
265 {
266  if ($search_status == 0) $sql .= ' AND frequency = 0 AND suspended = 0';
267  if ($search_status == 1) $sql .= ' AND frequency != 0 AND suspended = 0';
268  if ($search_status == -1) $sql .= ' AND suspended = 1';
269 }
270 $sql .= dolSqlDateFilter('f.date_last_gen', $search_day, $search_month, $search_year);
271 $sql .= dolSqlDateFilter('f.date_when', $search_day_date_when, $search_month_date_when, $search_year_date_when);
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 > 0) $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_term != '') $param .= '&search_payment_term='.urlencode($search_payment_term);
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 ($optioncss != '') $param .= '&optioncss='.urlencode($optioncss);
316  // Add $param from extra fields
317  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
318 
319  $massactionbutton = $form->selectMassAction('', $massaction == 'presend' ? array() : array('presend'=>$langs->trans("SendByMail"), 'builddoc'=>$langs->trans("PDFMerge")));
320 
321  $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
322  $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
323  //$selectedfields.=$form->showCheckAddButtons('checkforselect', 1);
324 
325  print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
326  if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
327  print '<input type="hidden" name="token" value="'.newToken().'">';
328  print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
329  print '<input type="hidden" name="action" value="list">';
330  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
331  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
332  print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
333  print '<input type="hidden" name="search_status" value="'.$search_status.'">';
334 
335  $title = $langs->trans("RepeatableInvoices");
336 
337  print_barre_liste($title, $page, $_SERVER['PHP_SELF'], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'bill', 0, '', '', $limit, 0, 0, 1);
338 
339  print '<span class="opacitymedium">'.$langs->trans("ToCreateAPredefinedInvoice", $langs->transnoentitiesnoconv("ChangeIntoRepeatableInvoice")).'</span><br><br>';
340 
341  $i = 0;
342 
343  $moreforfilter = '';
344 
345  print '<div class="div-table-responsive">';
346  print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
347 
348  // Filters lines
349  print '<tr class="liste_titre_filter">';
350  // Ref
351  if (!empty($arrayfields['f.titre']['checked']))
352  {
353  print '<td class="liste_titre left">';
354  print '<input class="flat maxwidth100" type="text" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">';
355  print '</td>';
356  }
357  // Thirpdarty
358  if (!empty($arrayfields['s.nom']['checked']))
359  {
360  print '<td class="liste_titre left"><input class="flat" type="text" size="8" name="search_societe" value="'.dol_escape_htmltag($search_societe).'"></td>';
361  }
362  if (!empty($arrayfields['f.total']['checked']))
363  {
364  // Amount net
365  print '<td class="liste_titre right">';
366  print '<input class="flat" type="text" size="5" name="search_montant_ht" value="'.dol_escape_htmltag($search_montant_ht).'">';
367  print '</td>';
368  }
369  if (!empty($arrayfields['f.tva']['checked']))
370  {
371  // Amount Vat
372  print '<td class="liste_titre right">';
373  print '<input class="flat" type="text" size="5" name="search_montant_vat" value="'.dol_escape_htmltag($search_montant_vat).'">';
374  print '</td>';
375  }
376  if (!empty($arrayfields['f.total_ttc']['checked']))
377  {
378  // Amount
379  print '<td class="liste_titre right">';
380  print '<input class="flat" type="text" size="5" name="search_montant_ttc" value="'.dol_escape_htmltag($search_montant_ttc).'">';
381  print '</td>';
382  }
383  if (!empty($arrayfields['f.fk_cond_reglement']['checked']))
384  {
385  // Payment term
386  print '<td class="liste_titre right">';
387  $form->select_conditions_paiements($search_payment_term, 'search_payment_term', -1, 1, 1, 'maxwidth100');
388  print "</td>";
389  }
390  if (!empty($arrayfields['f.fk_mode_reglement']['checked']))
391  {
392  // Payment mode
393  print '<td class="liste_titre right">';
394  $form->select_types_paiements($search_payment_mode, 'search_payment_mode', '', 0, 1, 1, 0, 1, 'maxwidth100');
395  print '</td>';
396  }
397  if (!empty($arrayfields['recurring']['checked']))
398  {
399  // Recurring or not
400  print '<td class="liste_titre" align="center">';
401  print $form->selectyesno('search_recurring', $search_recurring, 1, false, 1);
402  print '</td>';
403  }
404  if (!empty($arrayfields['f.frequency']['checked']))
405  {
406  // Recurring or not
407  print '<td class="liste_titre" align="center">';
408  print '<input class="flat" type="text" size="1" name="search_frequency" value="'.dol_escape_htmltag($search_frequency).'">';
409  print '</td>';
410  }
411  if (!empty($arrayfields['f.unit_frequency']['checked']))
412  {
413  // Frequency unit
414  print '<td class="liste_titre" align="center">';
415  print '<input class="flat" type="text" size="1" name="search_unit_frequency" value="'.dol_escape_htmltag($search_unit_frequency).'">';
416  print '</td>';
417  }
418  if (!empty($arrayfields['f.nb_gen_done']['checked']))
419  {
420  // Nb generation
421  print '<td class="liste_titre" align="center">';
422  print '</td>';
423  }
424  // Date invoice
425  if (!empty($arrayfields['f.date_last_gen']['checked']))
426  {
427  print '<td class="liste_titre nowraponall" align="center">';
428  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.'">';
429  print '<input class="flat valignmiddle width25" type="text" size="1" maxlength="2" name="search_month" value="'.$search_month.'">';
430  $formother->select_year($search_year ? $search_year : -1, 'search_year', 1, 20, 5, 0, 0, '', 'widthauto valignmiddle');
431  print '</td>';
432  }
433  // Date next generation
434  if (!empty($arrayfields['f.date_when']['checked']))
435  {
436  print '<td class="liste_titre nowraponall" align="center">';
437  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.'">';
438  print '<input class="flat valignmiddle width25" type="text" size="1" maxlength="2" name="search_month_date_when" value="'.$search_month_date_when.'">';
439  $formother->select_year($search_year_date_when ? $search_year_date_when : -1, 'search_year_date_when', 1, 20, 5, 0, 0, '', 'widthauto valignmiddle');
440  print '</td>';
441  }
442  // Extra fields
443  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
444 
445  // Fields from hook
446  $parameters = array('arrayfields'=>$arrayfields);
447  $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
448  print $hookmanager->resPrint;
449  // Date creation
450  if (!empty($arrayfields['f.datec']['checked']))
451  {
452  print '<td class="liste_titre">';
453  print '</td>';
454  }
455  // Date modification
456  if (!empty($arrayfields['f.tms']['checked']))
457  {
458  print '<td class="liste_titre">';
459  print '</td>';
460  }
461  // Status
462  if (!empty($arrayfields['status']['checked']))
463  {
464  print '<td class="liste_titre" align="center">';
465  $liststatus = array(
466  0=>$langs->trans("Draft"),
467  1=>$langs->trans("Active"),
468  -1=>$langs->trans("Disabled"),
469  );
470  print $form->selectarray('search_status', $liststatus, $search_status, -2);
471  print '</td>';
472  }
473  // Action column
474  print '<td class="liste_titre" align="middle">';
475  $searchpicto = $form->showFilterButtons();
476  print $searchpicto;
477  print '</td>';
478  print "</tr>\n";
479 
480  print '<tr class="liste_titre">';
481  if (!empty($arrayfields['f.titre']['checked'])) print_liste_field_titre($arrayfields['f.titre']['label'], $_SERVER['PHP_SELF'], "f.titre", "", $param, "", $sortfield, $sortorder);
482  if (!empty($arrayfields['s.nom']['checked'])) print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER['PHP_SELF'], "s.nom", "", $param, "", $sortfield, $sortorder);
483  if (!empty($arrayfields['f.total']['checked'])) print_liste_field_titre($arrayfields['f.total']['label'], $_SERVER['PHP_SELF'], "f.total", "", $param, 'class="right"', $sortfield, $sortorder);
484  if (!empty($arrayfields['f.tva']['checked'])) print_liste_field_titre($arrayfields['f.tva']['label'], $_SERVER['PHP_SELF'], "f.tva", "", $param, 'class="right"', $sortfield, $sortorder);
485  if (!empty($arrayfields['f.total_ttc']['checked'])) print_liste_field_titre($arrayfields['f.total_ttc']['label'], $_SERVER['PHP_SELF'], "f.total_ttc", "", $param, 'class="right"', $sortfield, $sortorder);
486  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);
487  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);
488  if (!empty($arrayfields['recurring']['checked'])) print_liste_field_titre($arrayfields['recurring']['label'], $_SERVER['PHP_SELF'], "recurring", "", $param, 'class="center"', $sortfield, $sortorder);
489  if (!empty($arrayfields['f.frequency']['checked'])) print_liste_field_titre($arrayfields['f.frequency']['label'], $_SERVER['PHP_SELF'], "f.frequency", "", $param, 'align="center"', $sortfield, $sortorder);
490  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);
491  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);
492  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);
493  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);
494  if (!empty($arrayfields['f.datec']['checked'])) print_liste_field_titre($arrayfields['f.datec']['label'], $_SERVER['PHP_SELF'], "f.datec", "", $param, 'align="center"', $sortfield, $sortorder);
495  if (!empty($arrayfields['f.tms']['checked'])) print_liste_field_titre($arrayfields['f.tms']['label'], $_SERVER['PHP_SELF'], "f.tms", "", $param, 'align="center"', $sortfield, $sortorder);
496  // Extra fields
497  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
498  if (!empty($arrayfields['status']['checked'])) print_liste_field_titre($arrayfields['status']['label'], $_SERVER['PHP_SELF'], "f.suspended,f.frequency", "", $param, 'align="center"', $sortfield, $sortorder);
499  print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', 'align="center"', $sortfield, $sortorder, 'center maxwidthsearch ');
500  print "</tr>\n";
501 
502  if ($num > 0)
503  {
504  $i = 0;
505  $totalarray = array();
506  while ($i < min($num, $limit))
507  {
508  $objp = $db->fetch_object($resql);
509  if (empty($objp)) break;
510 
511  $companystatic->id = $objp->socid;
512  $companystatic->name = $objp->name;
513 
514  $invoicerectmp->id = $objp->id ? $objp->id : $objp->facid;
515  $invoicerectmp->frequency = $objp->frequency;
516  $invoicerectmp->suspended = $objp->suspended;
517  $invoicerectmp->unit_frequency = $objp->unit_frequency;
518  $invoicerectmp->nb_gen_max = $objp->nb_gen_max;
519  $invoicerectmp->nb_gen_done = $objp->nb_gen_done;
520  $invoicerectmp->ref = $objp->title;
521 
522  print '<tr class="oddeven">';
523 
524  if (!empty($arrayfields['f.titre']['checked']))
525  {
526  print '<td class="nowrap tdoverflowmax200">';
527  print $invoicerectmp->getNomUrl(1);
528  print "</a>";
529  print "</td>\n";
530  if (!$i) $totalarray['nbfield']++;
531  }
532  if (!empty($arrayfields['s.nom']['checked']))
533  {
534  print '<td class="tdoverflowmax200">'.$companystatic->getNomUrl(1, 'customer').'</td>';
535  if (!$i) $totalarray['nbfield']++;
536  }
537  if (!empty($arrayfields['f.total']['checked']))
538  {
539  print '<td class="nowrap right">'.price($objp->total).'</td>'."\n";
540  if (!$i) $totalarray['nbfield']++;
541  if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'f.total';
542  $totalarray['val']['f.total'] += $objp->total;
543  }
544  if (!empty($arrayfields['f.tva']['checked']))
545  {
546  print '<td class="nowrap right">'.price($objp->total_vat).'</td>'."\n";
547  if (!$i) $totalarray['nbfield']++;
548  if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'f.tva';
549  $totalarray['val']['f.tva'] += $objp->total_vat;
550  }
551  if (!empty($arrayfields['f.total_ttc']['checked']))
552  {
553  print '<td class="nowrap right">'.price($objp->total_ttc).'</td>'."\n";
554  if (!$i) $totalarray['nbfield']++;
555  if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'f.total_ttc';
556  $totalarray['val']['f.total_ttc'] += $objp->total_ttc;
557  }
558  // Payment term
559  if (!empty($arrayfields['f.fk_cond_reglement']['checked']))
560  {
561  print '<td class="right">';
562  $form->form_conditions_reglement('', $objp->fk_cond_reglement, 'none');
563  print '</td>'."\n";
564  if (!$i) $totalarray['nbfield']++;
565  }
566  // Payment mode
567  if (!empty($arrayfields['f.fk_mode_reglement']['checked']))
568  {
569  print '<td class="right">';
570  $form->form_modes_reglement('', $objp->fk_mode_reglement, 'none');
571  print '</td>'."\n";
572  if (!$i) $totalarray['nbfield']++;
573  }
574  if (!empty($arrayfields['recurring']['checked']))
575  {
576  print '<td class="center">'.yn($objp->frequency ? 1 : 0).'</td>';
577  if (!$i) $totalarray['nbfield']++;
578  }
579  if (!empty($arrayfields['f.frequency']['checked']))
580  {
581  print '<td class="center">'.($objp->frequency > 0 ? $objp->frequency : '').'</td>';
582  if (!$i) $totalarray['nbfield']++;
583  }
584  if (!empty($arrayfields['f.unit_frequency']['checked']))
585  {
586  print '<td class="center">'.($objp->frequency > 0 ? $objp->unit_frequency : '').'</td>';
587  if (!$i) $totalarray['nbfield']++;
588  }
589  if (!empty($arrayfields['f.nb_gen_done']['checked']))
590  {
591  print '<td class="center">';
592  print ($objp->frequency > 0 ? $objp->nb_gen_done.($objp->nb_gen_max > 0 ? ' / '.$objp->nb_gen_max : '') : '<span class="opacitymedium">'.$langs->trans('NA').'</span>');
593  print '</td>';
594  if (!$i) $totalarray['nbfield']++;
595  }
596  // Date last generation
597  if (!empty($arrayfields['f.date_last_gen']['checked']))
598  {
599  print '<td class="center">';
600  print ($objp->frequency > 0 ? dol_print_date($db->jdate($objp->date_last_gen), 'day') : '<span class="opacitymedium">'.$langs->trans('NA').'</span>');
601  print '</td>';
602  if (!$i) $totalarray['nbfield']++;
603  }
604  // Date next generation
605  if (!empty($arrayfields['f.date_when']['checked']))
606  {
607  print '<td class="center">';
608  print '<div class="nowraponall">';
609  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>');
610  if (!$invoicerectmp->isMaxNbGenReached())
611  {
612  if (!$objp->suspended && $objp->frequency > 0 && $db->jdate($objp->date_when) && $db->jdate($objp->date_when) < $now) print img_warning($langs->trans("Late"));
613  } else {
614  print img_info($langs->trans("MaxNumberOfGenerationReached"));
615  }
616  print '</div>';
617  print '</td>';
618  if (!$i) $totalarray['nbfield']++;
619  }
620  if (!empty($arrayfields['f.datec']['checked']))
621  {
622  print '<td class="center">';
623  print dol_print_date($db->jdate($objp->datec), 'dayhour');
624  print '</td>';
625  if (!$i) $totalarray['nbfield']++;
626  }
627  if (!empty($arrayfields['f.tms']['checked']))
628  {
629  print '<td class="center">';
630  print dol_print_date($db->jdate($objp->tms), 'dayhour');
631  print '</td>';
632  if (!$i) $totalarray['nbfield']++;
633  }
634 
635  $obj = $objp;
636  // Extra fields
637  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
638  // Fields from hook
639  $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$objp, 'i'=>$i, 'totalarray'=>&$totalarray);
640  $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
641  print $hookmanager->resPrint;
642  // Status
643  if (!empty($arrayfields['status']['checked'])) {
644  print '<td class="center">';
645  print $invoicerectmp->getLibStatut(3, 0);
646  print '</td>';
647  if (!$i) $totalarray['nbfield']++;
648  }
649  // Action column
650  print '<td class="center">';
651  if ($user->rights->facture->creer && empty($invoicerectmp->suspended))
652  {
653  if ($invoicerectmp->isMaxNbGenReached())
654  {
655  print $langs->trans("MaxNumberOfGenerationReached");
656  } elseif (empty($objp->frequency) || $db->jdate($objp->date_when) <= $today)
657  {
658  print '<a href="'.DOL_URL_ROOT.'/compta/facture/card.php?action=create&amp;socid='.$objp->socid.'&amp;fac_rec='.$objp->facid.'">';
659  print $langs->trans("CreateBill").'</a>';
660  } else {
661  print $form->textwithpicto('', $langs->trans("DateIsNotEnough"));
662  }
663  } else {
664  print "&nbsp;";
665  }
666  if (!$i) $totalarray['nbfield']++;
667  print "</td>";
668 
669  print "</tr>\n";
670 
671  $i++;
672  }
673  } else {
674  $colspan = 1;
675  foreach ($arrayfields as $key => $val) { if (!empty($val['checked'])) $colspan++; }
676  print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
677  }
678 
679  // Show total line
680  include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
681 
682 
683  print "</table>";
684  print "</div>";
685  print "</form>";
686 
687  $db->free($resql);
688 } else {
689  dol_print_error($db);
690 }
691 
692 // End of page
693 llxFooter();
694 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm= 'auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
dol_now($mode= 'auto')
Return date for now.
Class to manage invoice templates.
img_warning($titlealt= 'default', $moreatt= '', $morecss= 'pictowarning')
Show warning logo.
llxHeader()
Empty header.
Definition: wrapper.php:45
Class to manage standard extra fields.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
print_barre_liste($titre, $page, $file, $options= '', $sortfield= '', $sortorder= '', $morehtmlcenter= '', $num=-1, $totalnboflines= '', $picto= 'generic', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow= '')
Print a title with navigation controls for pagination.
Class to manage generation of HTML components Only common components must be here.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
Class to manage third parties objects (customers, suppliers, prospects...)
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
Class to manage building of HTML components.
Classe permettant la generation de composants html autre Only common components are here...
dol_getdate($timestamp, $fast=false, $forcetimezone= '')
Return an array with locale date info.
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.
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...
dolSqlDateFilter($datefield, $day_date, $month_date, $year_date, $excludefirstand=0)
Generate a SQL string to make a filter into a range (for second of date until last second of date) ...
Definition: date.lib.php:281
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_sort_array(&$array, $index, $order= 'asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by second index function, which produces ascending (default) or descending output...
print
Draft customers invoices.
Definition: index.php:89
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_info($titlealt= 'default')
Show info logo.
llxFooter()
Empty footer.
Definition: wrapper.php:59