dolibarr  13.0.2
services_list.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2001-2004 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) 2015 Jean-François Ferry <jfefe@aternatik.fr>
6  * Copyright (C) 2018 Ferran Marcet <fmarcet@2byte.es>
7  * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
8  * Copyright (C) 2019 Juanjo Menent <jmenent@2byte.es>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <https://www.gnu.org/licenses/>.
22  */
23 
30 require "../main.inc.php";
31 require_once DOL_DOCUMENT_ROOT."/contrat/class/contrat.class.php";
32 require_once DOL_DOCUMENT_ROOT."/product/class/product.class.php";
33 require_once DOL_DOCUMENT_ROOT."/societe/class/societe.class.php";
34 
35 // Load translation files required by the page
36 $langs->loadLangs(array('products', 'contracts', 'companies'));
37 
38 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
39 $sortfield = GETPOST("sortfield", 'alpha');
40 $sortorder = GETPOST("sortorder", 'alpha');
41 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
42 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
43 $offset = $limit * $page;
44 $pageprev = $page - 1;
45 $pagenext = $page + 1;
46 if (!$sortfield) $sortfield = "c.rowid";
47 if (!$sortorder) $sortorder = "ASC";
48 
49 $mode = GETPOST("mode");
50 $filter = GETPOST("filter");
51 $search_name = GETPOST("search_name", 'alpha');
52 $search_contract = GETPOST("search_contract", 'alpha');
53 $search_service = GETPOST("search_service", 'alpha');
54 $search_status = GETPOST("search_status", 'alpha');
55 $statut = GETPOST('statut', 'int') ?GETPOST('statut', 'int') : 1;
56 $search_product_category = GETPOST('search_product_category', 'int');
57 $socid = GETPOST('socid', 'int');
58 $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'contractservicelist'.$mode;
59 
60 $opouvertureprevuemonth = GETPOST('opouvertureprevuemonth');
61 $opouvertureprevueday = GETPOST('opouvertureprevueday');
62 $opouvertureprevueyear = GETPOST('opouvertureprevueyear');
63 $filter_opouvertureprevue = GETPOST('filter_opouvertureprevue');
64 
65 $op1month = GETPOST('op1month', 'int');
66 $op1day = GETPOST('op1day', 'int');
67 $op1year = GETPOST('op1year', 'int');
68 $filter_op1 = GETPOST('filter_op1', 'alpha');
69 
70 $op2month = GETPOST('op2month', 'int');
71 $op2day = GETPOST('op2day', 'int');
72 $op2year = GETPOST('op2year', 'int');
73 $filter_op2 = GETPOST('filter_op2', 'alpha');
74 
75 $opcloturemonth = GETPOST('opcloturemonth', 'int');
76 $opclotureday = GETPOST('opclotureday', 'int');
77 $opclotureyear = GETPOST('opclotureyear', 'int');
78 $filter_opcloture = GETPOST('filter_opcloture', 'alpha');
79 
80 
81 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
82 $object = new ContratLigne($db);
83 $hookmanager->initHooks(array('contractservicelist'));
84 $extrafields = new ExtraFields($db);
85 
86 // fetch optionals attributes and labels
87 $extrafields->fetch_name_optionals_label($object->table_element);
88 
89 $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
90 
91 // Security check
92 $contratid = GETPOST('id', 'int');
93 if (!empty($user->socid)) $socid = $user->socid;
94 $result = restrictedArea($user, 'contrat', $contratid);
95 
96 if ($search_status != '')
97 {
98  $tmp = explode('&', $search_status);
99  $mode = $tmp[0];
100  if (empty($tmp[1])) $filter = '';
101  else {
102  if ($tmp[1] == 'filter=notexpired') $filter = 'notexpired';
103  if ($tmp[1] == 'filter=expired') $filter = 'expired';
104  }
105 } else {
106  $search_status = $mode;
107  if ($filter == 'expired') $search_status .= '&filter=expired';
108  if ($filter == 'notexpired') $search_status .= '&filter=notexpired';
109 }
110 
111 $staticcontrat = new Contrat($db);
112 $staticcontratligne = new ContratLigne($db);
113 $companystatic = new Societe($db);
114 
115 $arrayfields = array(
116  'c.ref'=>array('label'=>$langs->trans("Contract"), 'checked'=>1, 'position'=>80),
117  'p.description'=>array('label'=>$langs->trans("Service"), 'checked'=>1, 'position'=>80),
118  'cd.qty'=>array('label'=>$langs->trans("Qty"), 'checked'=>0, 'position'=>100),
119  'cd.total_ht'=>array('label'=>$langs->trans("TotalHT"), 'checked'=>0, 'position'=>100),
120  'cd.total_tva'=>array('label'=>$langs->trans("TotalVAT"), 'checked'=>0, 'position'=>100),
121  'cd.tva_tx'=>array('label'=>$langs->trans("VAT"), 'checked'=>0, 'position'=>100),
122  'cd.subprice'=>array('label'=>$langs->trans("PriceUHT"), 'checked'=>0, 'position'=>100),
123  's.nom'=>array('label'=>$langs->trans("ThirdParty"), 'checked'=>1, 'position'=>100),
124  'cd.date_ouverture_prevue'=>array('label'=>$langs->trans("DateStartPlannedShort"), 'checked'=>(($mode == "" || $mode == -1) || $mode == "0")),
125  'cd.date_ouverture'=>array('label'=>$langs->trans("DateStartRealShort"), 'checked'=>(($mode == "" || $mode == -1) || $mode > 0)),
126  'cd.date_fin_validite'=>array('label'=>$langs->trans("DateEndPlannedShort"), 'checked'=>(($mode == "" || $mode == -1) || $mode < 5)),
127  'cd.date_cloture'=>array('label'=>$langs->trans("DateEndRealShort"), 'checked'=>(($mode == "" || $mode == -1) || $mode >= 5)),
128  'status'=>array('label'=>$langs->trans("Status"), 'checked'=>1),
129  //'cd.datec'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0, 'position'=>500),
130  'cd.tms'=>array('label'=>$langs->trans("DateModificationShort"), 'checked'=>0, 'position'=>500)
131 );
132 // Extra fields
133 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
134 
135 $object->fields = dol_sort_array($object->fields, 'position');
136 $arrayfields = dol_sort_array($arrayfields, 'position');
137 
138 
139 
140 
141 /*
142  * Actions
143  */
144 
145 if (GETPOST('cancel', 'alpha')) { $action = 'list'; $massaction = ''; }
146 if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend' && $massaction != 'confirm_createbills') { $massaction = ''; }
147 
148 $parameters = array('socid'=>$socid);
149 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
150 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
151 
152 if (empty($reshook))
153 {
154  // Selection of new fields
155  include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
156 
157  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
158  {
159  $search_product_category = 0;
160  $search_name = "";
161  $search_contract = "";
162  $search_service = "";
163  $search_status = -1;
164  $opouvertureprevuemonth = "";
165  $opouvertureprevueday = "";
166  $opouvertureprevueyear = "";
167  $filter_opouvertureprevue = "";
168  $op1month = "";
169  $op1day = "";
170  $op1year = "";
171  $filter_op1 = "";
172  $op2month = "";
173  $op2day = "";
174  $op2year = "";
175  $filter_op2 = "";
176  $opcloturemonth = "";
177  $opclotureday = "";
178  $opclotureyear = "";
179  $filter_opcloture = "";
180  $mode = '';
181  $filter = '';
182  $toselect = '';
183  $search_array_options = array();
184  }
185 }
186 
187 
188 /*
189  * View
190  */
191 
192 $now = dol_now();
193 
194 $form = new Form($db);
195 
196 $sql = "SELECT c.rowid as cid, c.ref, c.statut as cstatut, c.ref_customer, c.ref_supplier,";
197 $sql .= " s.rowid as socid, s.nom as name, s.email, s.client, s.fournisseur,";
198 $sql .= " cd.rowid, cd.description, cd.statut,";
199 $sql .= " p.rowid as pid, p.ref as pref, p.label as label, p.fk_product_type as ptype, p.entity as pentity,";
200 if (!$user->rights->societe->client->voir && !$socid) $sql .= " sc.fk_soc, sc.fk_user,";
201 $sql .= " cd.date_ouverture_prevue,";
202 $sql .= " cd.date_ouverture,";
203 $sql .= " cd.date_fin_validite,";
204 $sql .= " cd.date_cloture,";
205 $sql .= " cd.qty,";
206 $sql .= " cd.total_ht,";
207 $sql .= " cd.total_tva,";
208 $sql .= " cd.tva_tx,";
209 $sql .= " cd.subprice,";
210 //$sql.= " cd.date_c as date_creation,";
211 $sql .= " cd.tms as date_update";
212 // Add fields from extrafields
213 if (!empty($extrafields->attributes[$object->table_element]['label'])) {
214  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key.' as options_'.$key : '');
215 }
216 // Add fields from hooks
217 $parameters = array();
218 $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
219 $sql .= $hookmanager->resPrint;
220 $sql .= " FROM ".MAIN_DB_PREFIX."contrat as c,";
221 $sql .= " ".MAIN_DB_PREFIX."societe as s,";
222 if (!$user->rights->societe->client->voir && !$socid) $sql .= " ".MAIN_DB_PREFIX."societe_commerciaux as sc,";
223 $sql .= " ".MAIN_DB_PREFIX."contratdet as cd";
224 if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (cd.rowid = ef.fk_object)";
225 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid";
226 if ($search_product_category > 0) $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=cd.fk_product';
227 $sql .= " WHERE c.entity = ".$conf->entity;
228 $sql .= " AND c.rowid = cd.fk_contrat";
229 if ($search_product_category > 0) $sql .= " AND cp.fk_categorie = ".$search_product_category;
230 $sql .= " AND c.fk_soc = s.rowid";
231 if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
232 if ($mode == "0") $sql .= " AND cd.statut = 0";
233 if ($mode == "4") $sql .= " AND cd.statut = 4";
234 if ($mode == "5") $sql .= " AND cd.statut = 5";
235 if ($filter == "expired") $sql .= " AND cd.date_fin_validite < '".$db->idate($now)."'";
236 if ($filter == "notexpired") $sql .= " AND cd.date_fin_validite >= '".$db->idate($now)."'";
237 if ($search_name) $sql .= " AND s.nom LIKE '%".$db->escape($search_name)."%'";
238 if ($search_contract) $sql .= " AND c.ref LIKE '%".$db->escape($search_contract)."%' ";
239 if ($search_service) $sql .= " AND (p.ref LIKE '%".$db->escape($search_service)."%' OR p.description LIKE '%".$db->escape($search_service)."%' OR cd.description LIKE '%".$db->escape($search_service)."%')";
240 if ($socid > 0) $sql .= " AND s.rowid = ".$socid;
241 
242 $filter_dateouvertureprevue_start = dol_mktime(0, 0, 0, $opouvertureprevuemonth, $opouvertureprevueday, $opouvertureprevueyear);
243 $filter_dateouvertureprevue_end = dol_mktime(23, 59, 59, $opouvertureprevuemonth, $opouvertureprevueday, $opouvertureprevueyear);
244 if ($filter_dateouvertureprevue_start != '' && $filter_opouvertureprevue == -1) $filter_opouvertureprevue = ' BETWEEN ';
245 
246 $filter_date1_start = dol_mktime(0, 0, 0, $op1month, $op1day, $op1year);
247 $filter_date1_end = dol_mktime(23, 59, 59, $op1month, $op1day, $op1year);
248 if ($filter_date1_start != '' && $filter_op1 == -1) $filter_op1 = ' BETWEEN ';
249 
250 $filter_date2_start = dol_mktime(0, 0, 0, $op2month, $op2day, $op2year);
251 $filter_date2_end = dol_mktime(23, 59, 59, $op2month, $op2day, $op2year);
252 if ($filter_date2_start != '' && $filter_op2 == -1) $filter_op2 = ' BETWEEN ';
253 
254 $filter_datecloture_start = dol_mktime(0, 0, 0, $opcloturemonth, $opclotureday, $opclotureyear);
255 $filter_datecloture_end = dol_mktime(23, 59, 59, $opcloturemonth, $opclotureday, $opclotureyear);
256 if ($filter_datecloture_start != '' && $filter_opcloture == -1) $filter_opcloture = ' BETWEEN ';
257 
258 if (!empty($filter_opouvertureprevue) && $filter_opouvertureprevue != -1 && $filter_opouvertureprevue != ' BETWEEN ' && $filter_dateouvertureprevue_start != '') $sql .= " AND cd.date_ouverture_prevue ".$filter_opouvertureprevue." '".$db->idate($filter_dateouvertureprevue_start)."'";
259 if (!empty($filter_opouvertureprevue) && $filter_opouvertureprevue == ' BETWEEN ') $sql .= " AND '".$db->idate($filter_dateouvertureprevue_end)."'";
260 if (!empty($filter_op1) && $filter_op1 != -1 && $filter_op1 != ' BETWEEN ' && $filter_date1_start != '') $sql .= " AND cd.date_ouverture ".$filter_op1." '".$db->idate($filter_date1_start)."'";
261 if (!empty($filter_op1) && $filter_op1 == ' BETWEEN ') $sql .= " AND '".$db->idate($filter_date1_end)."'";
262 if (!empty($filter_op2) && $filter_op2 != -1 && $filter_op2 != ' BETWEEN ' && $filter_date2_start != '') $sql .= " AND cd.date_fin_validite ".$filter_op2." '".$db->idate($filter_date2_start)."'";
263 if (!empty($filter_op2) && $filter_op2 == ' BETWEEN ') $sql .= " AND '".$db->idate($filter_date2_end)."'";
264 if (!empty($filter_opcloture) && $filter_opcloture != ' BETWEEN ' && $filter_opcloture != -1 && $filter_datecloture_start != '') $sql .= " AND cd.date_cloture ".$filter_opcloture." '".$db->idate($filter_datecloture_start)."'";
265 if (!empty($filter_opcloture) && $filter_opcloture == ' BETWEEN ') $sql .= " AND '".$db->idate($filter_datecloture_end)."'";
266 // Add where from extra fields
267 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
268 $sql .= $db->order($sortfield, $sortorder);
269 
270 //print $sql;
271 
272 $nbtotalofrecords = '';
273 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
274 {
275  $result = $db->query($sql);
276  $nbtotalofrecords = $db->num_rows($result);
277  if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0
278  {
279  $page = 0;
280  $offset = 0;
281  }
282 }
283 
284 $sql .= $db->plimit($limit + 1, $offset);
285 
286 //print $sql;
287 dol_syslog("contrat/services_list.php", LOG_DEBUG);
288 $resql = $db->query($sql);
289 if (!$resql)
290 {
291  dol_print_error($db);
292  exit;
293 }
294 
295 $num = $db->num_rows($resql);
296 
297 /*
298 if ($num == 1 && ! empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all)
299 {
300  $obj = $db->fetch_object($resql);
301  $id = $obj->id;
302  header("Location: ".DOL_URL_ROOT.'/projet/tasks/task.php?id='.$id.'&withprojet=1');
303  exit;
304 }*/
305 
306 llxHeader(null, $langs->trans("Services"));
307 
308 $param = '';
309 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage);
310 if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.$limit;
311 if ($search_contract) $param .= '&amp;search_contract='.urlencode($search_contract);
312 if ($search_name) $param .= '&amp;search_name='.urlencode($search_name);
313 if ($search_service) $param .= '&amp;search_service='.urlencode($search_service);
314 if ($mode) $param .= '&amp;mode='.urlencode($mode);
315 if ($filter) $param .= '&amp;filter='.urlencode($filter);
316 if (!empty($filter_opouvertureprevue) && $filter_opouvertureprevue != -1) $param .= '&amp;filter_opouvertureprevue='.urlencode($filter_opouvertureprevue);
317 if (!empty($filter_op1) && $filter_op1 != -1) $param .= '&amp;filter_op1='.urlencode($filter_op1);
318 if (!empty($filter_op2) && $filter_op2 != -1) $param .= '&amp;filter_op2='.urlencode($filter_op2);
319 if (!empty($filter_opcloture) && $filter_opcloture != -1) $param .= '&amp;filter_opcloture='.urlencode($filter_opcloture);
320 if ($filter_dateouvertureprevue != '') $param .= '&amp;opouvertureprevueday='.$opouvertureprevueday.'&amp;opouvertureprevuemonth='.$opouvertureprevuemonth.'&amp;opouvertureprevueyear='.$opouvertureprevueyear;
321 if ($filter_date1 != '') $param .= '&amp;op1day='.$op1day.'&amp;op1month='.$op1month.'&amp;op1year='.$op1year;
322 if ($filter_date2 != '') $param .= '&amp;op2day='.$op2day.'&amp;op2month='.$op2month.'&amp;op2year='.$op2year;
323 if ($filter_datecloture != '') $param .= '&amp;opclotureday='.$op2day.'&amp;opcloturemonth='.$op2month.'&amp;opclotureyear='.$op2year;
324 if ($optioncss != '') $param .= '&optioncss='.$optioncss;
325 // Add $param from extra fields
326 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
327 
328 // List of mass actions available
329 $arrayofmassactions = array(
330  //'presend'=>$langs->trans("SendByMail"),
331  //'builddoc'=>$langs->trans("PDFMerge"),
332 );
333 //if ($user->rights->contrat->supprimer) $arrayofmassactions['predelete']='<span class="fa fa-trash paddingrightonly"></span>'.$langs->trans("Delete");
334 //if (in_array($massaction, array('presend','predelete'))) $arrayofmassactions=array();
335 $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
336 
337 print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
338 if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
339 print '<input type="hidden" name="token" value="'.newToken().'">';
340 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
341 print '<input type="hidden" name="action" value="list">';
342 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
343 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
344 print '<input type="hidden" name="page" value="'.$page.'">';
345 print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
346 
347 $title = $langs->trans("ListOfServices");
348 if ($mode == "0") $title = $langs->trans("ListOfInactiveServices"); // Must use == "0"
349 if ($mode == "4" && $filter != "expired") $title = $langs->trans("ListOfRunningServices");
350 if ($mode == "4" && $filter == "expired") $title = $langs->trans("ListOfExpiredServices");
351 if ($mode == "5") $title = $langs->trans("ListOfClosedServices");
352 
353 print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'contract', 0, '', '', $limit);
354 
355 if ($sall)
356 {
357  foreach ($fieldstosearchall as $key => $val) $fieldstosearchall[$key] = $langs->trans($val);
358  print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'</div>';
359 }
360 
361 $morefilter = '';
362 
363 // If the user can view categories of products
364 if ($conf->categorie->enabled && ($user->rights->produit->lire || $user->rights->service->lire))
365 {
366  include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
367  $moreforfilter .= '<div class="divsearchfield">';
368  $moreforfilter .= $langs->trans('IncludingProductWithTag').': ';
369  $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, null, 'parent', null, null, 1);
370  $moreforfilter .= $form->selectarray('search_product_category', $cate_arbo, $search_product_category, 1, 0, 0, '', 0, 0, 0, 0, 'maxwidth300', 1);
371  $moreforfilter .= '</div>';
372 }
373 
374 $parameters = array();
375 $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
376 if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint;
377 else $moreforfilter = $hookmanager->resPrint;
378 
379 
380 if (!empty($moreforfilter))
381 {
382  print '<div class="liste_titre liste_titre_bydiv centpercent">';
383  print $moreforfilter;
384  print '</div>';
385 }
386 
387 $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
388 $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
389 
390 
391 print '<div class="div-table-responsive">';
392 print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
393 
394 print '<tr class="liste_titre">';
395 if (!empty($arrayfields['c.ref']['checked'])) print_liste_field_titre($arrayfields['c.ref']['label'], $_SERVER["PHP_SELF"], "c.ref", "", $param, "", $sortfield, $sortorder);
396 if (!empty($arrayfields['p.description']['checked'])) print_liste_field_titre($arrayfields['p.description']['label'], $_SERVER["PHP_SELF"], "p.description", "", $param, "", $sortfield, $sortorder);
397 if (!empty($arrayfields['cd.qty']['checked'])) print_liste_field_titre($arrayfields['cd.qty']['label'], $_SERVER["PHP_SELF"], "cd.qty", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
398 if (!empty($arrayfields['cd.total_ht']['checked'])) print_liste_field_titre($arrayfields['cd.total_ht']['label'], $_SERVER["PHP_SELF"], "cd.total_ht", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
399 if (!empty($arrayfields['cd.total_tva']['checked'])) print_liste_field_titre($arrayfields['cd.total_tva']['label'], $_SERVER["PHP_SELF"], "cd.total_tva", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
400 if (!empty($arrayfields['cd.tva_tx']['checked'])) print_liste_field_titre($arrayfields['cd.tva_tx']['label'], $_SERVER["PHP_SELF"], "cd.tva_tx", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
401 if (!empty($arrayfields['cd.subprice']['checked'])) print_liste_field_titre($arrayfields['cd.subprice']['label'], $_SERVER["PHP_SELF"], "cd.subprice", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
402 if (!empty($arrayfields['s.nom']['checked'])) print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", "", $param, "", $sortfield, $sortorder);
403 if (!empty($arrayfields['cd.date_ouverture_prevue']['checked'])) print_liste_field_titre($arrayfields['cd.date_ouverture_prevue']['label'], $_SERVER["PHP_SELF"], "cd.date_ouverture_prevue", "", $param, '', $sortfield, $sortorder, 'center ');
404 if (!empty($arrayfields['cd.date_ouverture']['checked'])) print_liste_field_titre($arrayfields['cd.date_ouverture']['label'], $_SERVER["PHP_SELF"], "cd.date_ouverture", "", $param, '', $sortfield, $sortorder, 'center ');
405 if (!empty($arrayfields['cd.date_fin_validite']['checked'])) print_liste_field_titre($arrayfields['cd.date_fin_validite']['label'], $_SERVER["PHP_SELF"], "cd.date_fin_validite", "", $param, '', $sortfield, $sortorder, 'center ');
406 if (!empty($arrayfields['cd.date_cloture']['checked'])) print_liste_field_titre($arrayfields['cd.date_cloture']['label'], $_SERVER["PHP_SELF"], "cd.date_cloture", "", $param, '', $sortfield, $sortorder, 'center ');
407 // Extra fields
408 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
409 // Hook fields
410 $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
411 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
412 print $hookmanager->resPrint;
413 if (!empty($arrayfields['cd.datec']['checked'])) print_liste_field_titre($arrayfields['cd.datec']['label'], $_SERVER["PHP_SELF"], "cd.datec", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
414 if (!empty($arrayfields['cd.tms']['checked'])) print_liste_field_titre($arrayfields['cd.tms']['label'], $_SERVER["PHP_SELF"], "cd.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
415 if (!empty($arrayfields['status']['checked'])) print_liste_field_titre($arrayfields['status']['label'], $_SERVER["PHP_SELF"], "cd.statut,c.statut", "", $param, '', $sortfield, $sortorder, 'right ');
416 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
417 print "</tr>\n";
418 
419 print '<tr class="liste_titre">';
420 if (!empty($arrayfields['c.ref']['checked']))
421 {
422  print '<td class="liste_titre">';
423  print '<input type="hidden" name="filter" value="'.$filter.'">';
424  print '<input type="hidden" name="mode" value="'.$mode.'">';
425  print '<input type="text" class="flat" size="3" name="search_contract" value="'.dol_escape_htmltag($search_contract).'">';
426  print '</td>';
427 }
428 // Service label
429 if (!empty($arrayfields['p.description']['checked']))
430 {
431  print '<td class="liste_titre">';
432  print '<input type="text" class="flat maxwidth100" name="search_service" value="'.dol_escape_htmltag($search_service).'">';
433  print '</td>';
434 }
435 // detail lines
436 if (!empty($arrayfields['cd.qty']['checked']))
437 {
438  print '<td class="liste_titre">';
439  print '</td>';
440 }
441 if (!empty($arrayfields['cd.total_ht']['checked']))
442 {
443  print '<td class="liste_titre">';
444  print '</td>';
445 }
446 if (!empty($arrayfields['cd.total_tva']['checked']))
447 {
448  print '<td class="liste_titre">';
449  print '</td>';
450 }
451 if (!empty($arrayfields['cd.tva_tx']['checked']))
452 {
453  print '<td class="liste_titre">';
454  print '</td>';
455 }
456 if (!empty($arrayfields['cd.subprice']['checked']))
457 {
458  print '<td class="liste_titre">';
459  print '</td>';
460 }
461 // Third party
462 if (!empty($arrayfields['s.nom']['checked']))
463 {
464  print '<td class="liste_titre">';
465  print '<input type="text" class="flat maxwidth100" name="search_name" value="'.dol_escape_htmltag($search_name).'">';
466  print '</td>';
467 }
468 
469 
470 if (!empty($arrayfields['cd.date_ouverture_prevue']['checked']))
471 {
472  print '<td class="liste_titre center">';
473  $arrayofoperators = array('<'=>'<', '>'=>'>');
474  print $form->selectarray('filter_opouvertureprevue', $arrayofoperators, $filter_opouvertureprevue, 1);
475  print ' ';
476  $filter_dateouvertureprevue = dol_mktime(0, 0, 0, $opouvertureprevuemonth, $opouvertureprevueday, $opouvertureprevueyear);
477  print $form->selectDate($filter_dateouvertureprevue, 'opouvertureprevue', 0, 0, 1, '', 1, 0);
478  print '</td>';
479 }
480 if (!empty($arrayfields['cd.date_ouverture']['checked']))
481 {
482  print '<td class="liste_titre center">';
483  $arrayofoperators = array('<'=>'<', '>'=>'>');
484  print $form->selectarray('filter_op1', $arrayofoperators, $filter_op1, 1);
485  print ' ';
486  $filter_date1 = dol_mktime(0, 0, 0, $op1month, $op1day, $op1year);
487  print $form->selectDate($filter_date1, 'op1', 0, 0, 1, '', 1, 0);
488  print '</td>';
489 }
490 if (!empty($arrayfields['cd.date_fin_validite']['checked']))
491 {
492  print '<td class="liste_titre center">';
493  $arrayofoperators = array('<'=>'<', '>'=>'>');
494  print $form->selectarray('filter_op2', $arrayofoperators, $filter_op2, 1);
495  print ' ';
496  $filter_date2 = dol_mktime(0, 0, 0, $op2month, $op2day, $op2year);
497  print $form->selectDate($filter_date2, 'op2', 0, 0, 1, '', 1, 0);
498  print '</td>';
499 }
500 if (!empty($arrayfields['cd.date_cloture']['checked']))
501 {
502  print '<td class="liste_titre center">';
503  $arrayofoperators = array('<'=>'<', '>'=>'>');
504  print $form->selectarray('filter_opcloture', $arrayofoperators, $filter_opcloture, 1);
505  print ' ';
506  $filter_date_cloture = dol_mktime(0, 0, 0, $opcloturemonth, $opclotureday, $opclotureyear);
507  print $form->selectDate($filter_date_cloture, 'opcloture', 0, 0, 1, '', 1, 0);
508  print '</td>';
509 }
510 // Extra fields
511 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
512 
513 // Fields from hook
514 $parameters = array('arrayfields'=>$arrayfields);
515 $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
516 print $hookmanager->resPrint;
517 if (!empty($arrayfields['cd.datec']['checked']))
518 {
519  // Date creation
520  print '<td class="liste_titre">';
521  print '</td>';
522 }
523 if (!empty($arrayfields['cd.tms']['checked']))
524 {
525  // Date modification
526  print '<td class="liste_titre">';
527  print '</td>';
528 }
529 if (!empty($arrayfields['status']['checked']))
530 {
531  // Status
532  print '<td class="liste_titre right">';
533  $arrayofstatus = array(
534  '0'=>$langs->trans("ServiceStatusInitial"),
535  '4'=>$langs->trans("ServiceStatusRunning"),
536  '4&filter=notexpired'=>$langs->trans("ServiceStatusNotLate"),
537  '4&filter=expired'=>$langs->trans("ServiceStatusLate"),
538  '5'=>$langs->trans("ServiceStatusClosed")
539  );
540  print $form->selectarray('search_status', $arrayofstatus, (strstr($search_status, ',') ?-1 : $search_status), 1, 0, '', 0, 0, 0, '', 'maxwidth100onsmartphone');
541  print '</td>';
542 }
543 // Action column
544 print '<td class="liste_titre maxwidthsearch">';
545 $searchpicto = $form->showFilterAndCheckAddButtons(0);
546 print $searchpicto;
547 print '</td>';
548 print "</tr>\n";
549 
550 $contractstatic = new Contrat($db);
551 $productstatic = new Product($db);
552 
553 $i = 0;
554 $totalarray = array();
555 while ($i < min($num, $limit))
556 {
557  $obj = $db->fetch_object($resql);
558 
559  $contractstatic->id = $obj->cid;
560  $contractstatic->ref = $obj->ref ? $obj->ref : $obj->cid;
561  $contractstatic->ref_customer = $obj->ref_customer;
562  $contractstatic->ref_supplier = $obj->ref_supplier;
563 
564  $companystatic->id = $obj->socid;
565  $companystatic->name = $obj->name;
566  $companystatic->email = $obj->email;
567  $companystatic->client = $obj->client;
568  $companystatic->fournisseur = $obj->fournisseur;
569 
570  print '<tr class="oddeven">';
571 
572  // Ref
573  if (!empty($arrayfields['c.ref']['checked']))
574  {
575  print '<td class="nowraponall">';
576  print $contractstatic->getNomUrl(1, 16);
577  print '</td>';
578  if (!$i) $totalarray['nbfield']++;
579  }
580  // Service
581  if (!empty($arrayfields['p.description']['checked']))
582  {
583  print '<td>';
584  if ($obj->pid > 0)
585  {
586  $productstatic->id = $obj->pid;
587  $productstatic->type = $obj->ptype;
588  $productstatic->ref = $obj->pref;
589  $productstatic->entity = $obj->pentity;
590  print $productstatic->getNomUrl(1, '', 24);
591  print $obj->label ? ' - '.dol_trunc($obj->label, 16) : '';
592  if (!empty($obj->description) && !empty($conf->global->PRODUCT_DESC_IN_LIST)) print '<br>'.dol_nl2br($obj->description);
593  } else {
594  if ($obj->type == 0) print img_object($obj->description, 'product').' '.dol_trunc($obj->description, 24);
595  if ($obj->type == 1) print img_object($obj->description, 'service').' '.dol_trunc($obj->description, 24);
596  }
597  print '</td>';
598  if (!$i) $totalarray['nbfield']++;
599  }
600 
601  if (!empty($arrayfields['cd.qty']['checked']))
602  {
603  print '<td>';
604  print $obj->qty;
605  print '</td>';
606  if (!$i) $totalarray['nbfield']++;
607  }
608  if (!empty($arrayfields['cd.total_ht']['checked']))
609  {
610  print '<td class="right">';
611  print price($obj->total_ht);
612  print '</td>';
613  if (!$i) $totalarray['nbfield']++;
614  if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'cd.total_ht';
615  $totalarray['val']['cd.total_ht'] += $obj->total_ht;
616  }
617  if (!empty($arrayfields['cd.total_tva']['checked']))
618  {
619  print '<td class="right">';
620  print price($obj->total_tva);
621  print '</td>';
622  if (!$i) $totalarray['nbfield']++;
623  if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'cd.total_tva';
624  $totalarray['val']['cd.total_tva'] += $obj->total_tva;
625  }
626  if (!empty($arrayfields['cd.tva_tx']['checked']))
627  {
628  print '<td class="right">';
629  print price2num($obj->tva_tx).'%';
630  print '</td>';
631  if (!$i) $totalarray['nbfield']++;
632  }
633  if (!empty($arrayfields['cd.subprice']['checked']))
634  {
635  print '<td class="right">';
636  print price($obj->subprice);
637  print '</td>';
638  if (!$i) $totalarray['nbfield']++;
639  }
640 
641 
642  // Third party
643  if (!empty($arrayfields['s.nom']['checked']))
644  {
645  print '<td>';
646  print $companystatic->getNomUrl(1, 'customer', 28);
647  print '</td>';
648  if (!$i) $totalarray['nbfield']++;
649  }
650 
651  // Start date
652  if (!empty($arrayfields['cd.date_ouverture_prevue']['checked']))
653  {
654  print '<td class="center">';
655  print ($obj->date_ouverture_prevue ?dol_print_date($db->jdate($obj->date_ouverture_prevue), 'dayhour') : '&nbsp;');
656  if ($db->jdate($obj->date_ouverture_prevue) && ($db->jdate($obj->date_ouverture_prevue) < ($now - $conf->contrat->services->inactifs->warning_delay)) && $obj->statut == 0)
657  print ' '.img_picto($langs->trans("Late"), "warning");
658  else print '&nbsp;&nbsp;&nbsp;&nbsp;';
659  print '</td>';
660  if (!$i) $totalarray['nbfield']++;
661  }
662  if (!empty($arrayfields['cd.date_ouverture']['checked']))
663  {
664  print '<td class="center">'.($obj->date_ouverture ?dol_print_date($db->jdate($obj->date_ouverture), 'dayhour') : '&nbsp;').'</td>';
665  if (!$i) $totalarray['nbfield']++;
666  }
667  // End date
668  if (!empty($arrayfields['cd.date_fin_validite']['checked']))
669  {
670  print '<td class="center">'.($obj->date_fin_validite ?dol_print_date($db->jdate($obj->date_fin_validite), 'dayhour') : '&nbsp;');
671  if ($obj->date_fin_validite && $db->jdate($obj->date_fin_validite) < ($now - $conf->contrat->services->expires->warning_delay) && $obj->statut < 5)
672  {
673  $warning_delay = $conf->contrat->services->expires->warning_delay / 3600 / 24;
674  $textlate = $langs->trans("Late").' = '.$langs->trans("DateReference").' > '.$langs->trans("DateToday").' '.(ceil($warning_delay) >= 0 ? '+' : '').ceil($warning_delay).' '.$langs->trans("days");
675  print img_warning($textlate);
676  } else print '&nbsp;&nbsp;&nbsp;&nbsp;';
677  print '</td>';
678  if (!$i) $totalarray['nbfield']++;
679  }
680  // Close date (real end date)
681  if (!empty($arrayfields['cd.date_cloture']['checked']))
682  {
683  print '<td class="center">'.dol_print_date($db->jdate($obj->date_cloture), 'dayhour').'</td>';
684  if (!$i) $totalarray['nbfield']++;
685  }
686 
687  // Extra fields
688  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
689  // Fields from hook
690  $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
691  $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
692  print $hookmanager->resPrint;
693  // Date creation
694  if (!empty($arrayfields['cd.datec']['checked']))
695  {
696  print '<td class="center">';
697  print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
698  print '</td>';
699  if (!$i) $totalarray['nbfield']++;
700  }
701  // Date modification
702  if (!empty($arrayfields['cd.tms']['checked']))
703  {
704  print '<td class="center">';
705  print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser');
706  print '</td>';
707  if (!$i) $totalarray['nbfield']++;
708  }
709  // Status
710  if (!empty($arrayfields['status']['checked']))
711  {
712  print '<td class="right">';
713  if ($obj->cstatut == 0)
714  {
715  // If contract is draft, we say line is also draft
716  print $contractstatic->LibStatut(0, 5);
717  } else {
718  print $staticcontratligne->LibStatut($obj->statut, 5, ($obj->date_fin_validite && $db->jdate($obj->date_fin_validite) < $now) ? 1 : 0);
719  }
720  print '</td>';
721  if (!$i) $totalarray['nbfield']++;
722  }
723  // Action column
724  print '<td class="nowrap center">';
725  if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
726  {
727  $selected = 0;
728  if (in_array($obj->rowid, $arrayofselected)) $selected = 1;
729  print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
730  }
731  print '</td>';
732  if (!$i) $totalarray['nbfield']++;
733 
734  print "</tr>\n";
735  $i++;
736 }
737 
738 // Show total line
739 include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
740 
741 $db->free($resql);
742 
743 $parameters = array('sql' => $sql);
744 $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters); // Note that $action and $object may have been modified by hook
745 print $hookmanager->resPrint;
746 
747 print '</table>';
748 print '</div>';
749 
750 print '</form>';
751 
752 
753 
754 llxFooter();
755 
756 $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...
Class to manage products or services.
dol_now($mode= 'auto')
Return date for now.
Class to manage contracts.
Class to manage lines of contracts.
img_warning($titlealt= 'default', $moreatt= '', $morecss= 'pictowarning')
Show warning logo.
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...
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.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is &#39;...
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it&#39;s its name (generic function)
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
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 $_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...
dol_trunc($string, $size=40, $trunc= 'right', $stringencoding= 'UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding &#39;...&#39; if string larger than length.
llxFooter()
Empty footer.
Definition: wrapper.php:59