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