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