dolibarr  20.0.0-beta
index.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2011 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) 2019 Nicolas ZABOURI <info@inovea-conseil.com>
7  * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
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 <https://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 
33 $hookmanager = new HookManager($db);
34 
35 // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
36 $hookmanager->initHooks(array('contractindex'));
37 
38 // Load translation files required by the page
39 $langs->loadLangs(array('products', 'companies', 'contracts'));
40 
41 $sortfield = GETPOST('sortfield', 'aZ09comma');
42 $sortorder = GETPOST('sortorder', 'aZ09comma');
43 $page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
44 
45 $statut = GETPOST('statut') ? GETPOST('statut') : 1;
46 
47 $max = getDolGlobalInt('MAIN_SIZE_SHORTLIST_LIMIT', 5);
48 
49 // Security check
50 $socid = 0;
51 $id = GETPOSTINT('id');
52 if (!empty($user->socid)) {
53  $socid = $user->socid;
54 }
55 $result = restrictedArea($user, 'contrat', $id);
56 
57 $staticcompany = new Societe($db);
58 $staticcontrat = new Contrat($db);
59 $staticcontratligne = new ContratLigne($db);
60 $productstatic = new Product($db);
61 
62 
63 
64 /*
65  * Action
66  */
67 
68 // None
69 
70 
71 /*
72  * View
73  */
74 
75 $now = dol_now();
76 
77 $title = $langs->trans("ContractsArea");
78 $help_url = '';
79 
80 llxHeader('', $title, $help_url);
81 
82 print load_fiche_titre($langs->trans("ContractsArea"), '', 'contract');
83 
84 
85 print '<div class="fichecenter"><div class="fichethirdleft">';
86 
87 
88 /*
89  * Statistics
90  */
91 
92 $nb = array();
93 $total = 0;
94 $totalinprocess = 0;
95 $dataseries = array();
96 $vals = array();
97 
98 // Search by status (except expired)
99 $sql = "SELECT count(cd.rowid) as nb, cd.statut as status";
100 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
101 $sql .= ", ".MAIN_DB_PREFIX."contratdet as cd, ".MAIN_DB_PREFIX."contrat as c";
102 if (!$user->hasRight('societe', 'client', 'voir')) {
103  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
104 }
105 $sql .= " WHERE cd.fk_contrat = c.rowid AND c.fk_soc = s.rowid";
106 $sql .= " AND (cd.statut != 4 OR (cd.statut = 4 AND (cd.date_fin_validite is null or cd.date_fin_validite >= '".$db->idate($now)."')))";
107 $sql .= " AND c.entity IN (".getEntity('contract', 0).")";
108 if ($user->socid) {
109  $sql .= ' AND c.fk_soc = '.((int) $user->socid);
110 }
111 if (!$user->hasRight('societe', 'client', 'voir')) {
112  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
113 }
114 $sql .= " GROUP BY cd.statut";
115 $resql = $db->query($sql);
116 if ($resql) {
117  $num = $db->num_rows($resql);
118  $i = 0;
119  while ($i < $num) {
120  $obj = $db->fetch_object($resql);
121  if ($obj) {
122  $nb[$obj->status] = $obj->nb;
123  if ($obj->status != 5) {
124  $vals[$obj->status] = $obj->nb;
125  $totalinprocess += $obj->nb;
126  }
127  $total += $obj->nb;
128  }
129  $i++;
130  }
131  $db->free($resql);
132 } else {
133  dol_print_error($db);
134 }
135 // Search by status (only expired)
136 $sql = "SELECT count(cd.rowid) as nb, cd.statut as status";
137 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
138 $sql .= ", ".MAIN_DB_PREFIX."contratdet as cd, ".MAIN_DB_PREFIX."contrat as c";
139 if (!$user->hasRight('societe', 'client', 'voir')) {
140  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
141 }
142 $sql .= " WHERE cd.fk_contrat = c.rowid AND c.fk_soc = s.rowid";
143 $sql .= " AND (cd.statut = 4 AND cd.date_fin_validite < '".$db->idate($now)."')";
144 $sql .= " AND c.entity IN (".getEntity('contract', 0).")";
145 if ($user->socid) {
146  $sql .= ' AND c.fk_soc = '.((int) $user->socid);
147 }
148 if (!$user->hasRight('societe', 'client', 'voir')) {
149  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
150 }
151 $sql .= " GROUP BY cd.statut";
152 $resql = $db->query($sql);
153 if ($resql) {
154  $num = $db->num_rows($resql);
155 
156  // 0 inactive, 4 active, 5 closed
157  $i = 0;
158  while ($i < $num) {
159  $obj = $db->fetch_object($resql);
160  if ($obj) {
161  $nb[$obj->status.((string) true)] = $obj->nb;
162  if ($obj->status != 5) {
163  $vals[$obj->status.((string) true)] = $obj->nb;
164  $totalinprocess += $obj->nb;
165  }
166  $total += $obj->nb;
167  }
168  $i++;
169  }
170  $db->free($resql);
171 } else {
172  dol_print_error($db);
173 }
174 
175 $colorseries = array();
176 
177 include DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php';
178 
179 print '<div class="div-table-responsive-no-min">';
180 print '<table class="noborder nohover centpercent">';
181 print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Statistics").' - '.$langs->trans("Services").'</th></tr>'."\n";
182 $listofstatus = array(0, 4, 4, 5);
183 $bool = false;
184 foreach ($listofstatus as $status) {
185  $bool_str = (string) $bool;
186  $dataseries[] = array($staticcontratligne->LibStatut($status, 1, ($bool ? 1 : 0)), (isset($nb[$status.$bool_str]) ? (int) $nb[$status.$bool_str] : 0));
187  if ($status == ContratLigne::STATUS_INITIAL) {
188  $colorseries[$status.$bool_str] = '-'.$badgeStatus0;
189  }
190  if ($status == ContratLigne::STATUS_OPEN && !$bool) {
191  $colorseries[$status.$bool_str] = $badgeStatus4;
192  }
193  if ($status == ContratLigne::STATUS_OPEN && $bool) {
194  $colorseries[$status.$bool_str] = $badgeStatus1;
195  }
196  if ($status == ContratLigne::STATUS_CLOSED) {
197  $colorseries[$status.$bool_str] = $badgeStatus6;
198  }
199 
200  if (empty($conf->use_javascript_ajax)) {
201  print '<tr class="oddeven">';
202  print '<td>'.$staticcontratligne->LibStatut($status, 0, ($bool ? 1 : 0)).'</td>';
203  print '<td class="right"><a href="services_list.php?search_status='.((int) $status).($bool ? '&filter=expired' : '').'">'.($nb[$status.$bool_str] ? $nb[$status.$bool_str] : 0).' '.$staticcontratligne->LibStatut($status, 3, ($bool ? 1 : 0)).'</a></td>';
204  print "</tr>\n";
205  }
206  if ($status == 4 && !$bool) {
207  $bool = true;
208  } else {
209  $bool = false;
210  }
211 }
212 if (!empty($conf->use_javascript_ajax)) {
213  print '<tr class="impair"><td class="center" colspan="2">';
214 
215  include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
216  $dolgraph = new DolGraph();
217  $dolgraph->SetData($dataseries);
218  $dolgraph->SetDataColor(array_values($colorseries));
219  $dolgraph->setShowLegend(2);
220  $dolgraph->setShowPercent(1);
221  $dolgraph->SetType(array('pie'));
222  $dolgraph->setHeight('200');
223  $dolgraph->draw('idgraphstatus');
224  print $dolgraph->show($total ? 0 : 1);
225 
226  print '</td></tr>';
227 }
228 $listofstatus = array(0, 4, 4, 5);
229 $bool = false;
230 foreach ($listofstatus as $status) {
231  $bool_str = (string) $bool;
232  if (empty($conf->use_javascript_ajax)) {
233  print '<tr class="oddeven">';
234  print '<td>'.$staticcontratligne->LibStatut($status, 0, ($bool ? 1 : 0)).'</td>';
235  print '<td class="right"><a href="services_list.php?search_status='.((int) $status).($bool ? '&filter=expired' : '').'">'.($nb[$status.$bool_str] ? $nb[$status.$bool_str] : 0).' '.$staticcontratligne->LibStatut($status, 3, ($bool ? 1 : 0)).'</a></td>';
236  if ($status == 4 && !$bool) {
237  $bool = true;
238  } else {
239  $bool = false;
240  }
241  print "</tr>\n";
242  }
243 }
244 print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td class="right">'.$total.'</td></tr>';
245 print "</table></div><br>";
246 
247 
248 // Draft contracts
249 
250 if (isModEnabled('contract') && $user->hasRight('contrat', 'lire')) {
251  $sql = "SELECT c.rowid, c.ref,";
252  $sql .= " s.nom as name, s.name_alias, s.logo, s.rowid as socid, s.client, s.fournisseur, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur";
253  $sql .= " FROM ".MAIN_DB_PREFIX."contrat as c, ".MAIN_DB_PREFIX."societe as s";
254  if (!$user->hasRight('societe', 'client', 'voir')) {
255  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
256  }
257  $sql .= " WHERE s.rowid = c.fk_soc";
258  $sql .= " AND c.entity IN (".getEntity('contract', 0).")";
259  $sql .= " AND c.statut = 0";
260  if (!$user->hasRight('societe', 'client', 'voir')) {
261  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
262  }
263  if ($socid) {
264  $sql .= " AND c.fk_soc = ".((int) $socid);
265  }
266 
267  $resql = $db->query($sql);
268 
269  if ($resql) {
270  $num = $db->num_rows($resql);
271 
272  print '<div class="div-table-responsive-no-min">';
273  print '<table class="noborder centpercent">';
274  print '<tr class="liste_titre">';
275  print '<th colspan="3">'.$langs->trans("DraftContracts").($num ? '<span class="badge marginleftonlyshort">'.$num.'</span>' : '').'</th></tr>';
276  if ($num) {
277  $i = 0;
278  //$tot_ttc = 0;
279  while ($i < $num) {
280  $obj = $db->fetch_object($resql);
281 
282  $staticcontrat->ref = $obj->ref;
283  $staticcontrat->id = $obj->rowid;
284 
285  $staticcompany->id = $obj->socid;
286  $staticcompany->name = $obj->name;
287  $staticcompany->name_alias = $obj->name_alias;
288  $staticcompany->photo = 1;
289  $staticcompany->code_client = $obj->code_client;
290  $staticcompany->code_fournisseur = $obj->code_fournisseur;
291  $staticcompany->code_compta = $obj->code_compta;
292  $staticcompany->code_compta_fournisseur = $obj->code_compta_fournisseur;
293  $staticcompany->client = $obj->client;
294  $staticcompany->fournisseur = $obj->fournisseur;
295 
296  print '<tr class="oddeven"><td class="nowrap">';
297  print $staticcontrat->getNomUrl(1, '');
298  print '</td>';
299  print '<td>';
300  print $staticcompany->getNomUrl(1, '', 16);
301  print '</td>';
302  print '</tr>';
303  //$tot_ttc+=$obj->total_ttc;
304  $i++;
305  }
306  } else {
307  print '<tr class="oddeven"><td colspan="3"><span class="opacitymedium">'.$langs->trans("NoContracts").'</span></td></tr>';
308  }
309  print "</table></div><br>";
310  $db->free($resql);
311  } else {
312  dol_print_error($db);
313  }
314 }
315 
316 
317 print '</div><div class="fichetwothirdright">';
318 
319 
320 // Last modified contracts
321 $sql = 'SELECT ';
322 $sql .= " sum(".$db->ifsql("cd.statut=0", 1, 0).') as nb_initial,';
323 $sql .= " sum(".$db->ifsql("cd.statut=4 AND (cd.date_fin_validite IS NULL OR cd.date_fin_validite >= '".$db->idate($now)."')", 1, 0).') as nb_running,';
324 $sql .= " sum(".$db->ifsql("cd.statut=4 AND (cd.date_fin_validite IS NOT NULL AND cd.date_fin_validite < '".$db->idate($now)."')", 1, 0).') as nb_expired,';
325 $sql .= " sum(".$db->ifsql("cd.statut=4 AND (cd.date_fin_validite IS NOT NULL AND cd.date_fin_validite < '".$db->idate($now - $conf->contrat->services->expires->warning_delay)."')", 1, 0).') as nb_late,';
326 $sql .= " sum(".$db->ifsql("cd.statut=5", 1, 0).') as nb_closed,';
327 $sql .= " c.rowid as cid, c.ref, c.datec, c.tms, c.statut,";
328 $sql .= " s.nom as name, s.name_alias, s.logo, s.rowid as socid, s.client, s.fournisseur, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur";
329 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,";
330 if (!$user->hasRight('societe', 'client', 'voir')) {
331  $sql .= " ".MAIN_DB_PREFIX."societe_commerciaux as sc,";
332 }
333 $sql .= " ".MAIN_DB_PREFIX."contrat as c";
334 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."contratdet as cd ON c.rowid = cd.fk_contrat";
335 $sql .= " WHERE c.fk_soc = s.rowid";
336 $sql .= " AND c.entity IN (".getEntity('contract', 0).")";
337 $sql .= " AND c.statut > 0";
338 if (!$user->hasRight('societe', 'client', 'voir')) {
339  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
340 }
341 if ($socid) {
342  $sql .= " AND s.rowid = ".((int) $socid);
343 }
344 $sql .= " GROUP BY c.rowid, c.ref, c.datec, c.tms, c.statut,";
345 $sql .= " s.nom, s.name_alias, s.logo, s.rowid, s.client, s.fournisseur, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur";
346 $sql .= " ORDER BY c.tms DESC";
347 $sql .= $db->plimit($max);
348 
349 dol_syslog("contrat/index.php", LOG_DEBUG);
350 $result = $db->query($sql);
351 if ($result) {
352  $num = $db->num_rows($result);
353  $i = 0;
354 
355  print '<div class="div-table-responsive-no-min">';
356  print '<table class="noborder centpercent">';
357 
358  print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("LastContracts", $max).'</th>';
359  print '<th class="center">'.$langs->trans("DateModification").'</th>';
360  //print '<th class="left">'.$langs->trans("Status").'</th>';
361  print '<th class="center" width="80" colspan="4">'.$langs->trans("Services").'</th>';
362  print "</tr>\n";
363 
364  while ($i < $num) {
365  $obj = $db->fetch_object($result);
366  $datem = $db->jdate($obj->tms);
367 
368  $staticcontrat->ref = ($obj->ref ? $obj->ref : $obj->cid);
369  $staticcontrat->id = $obj->cid;
370 
371  $staticcompany->id = $obj->socid;
372  $staticcompany->name = $obj->name;
373  $staticcompany->name_alias = $obj->name_alias;
374  $staticcompany->photo = 1;
375  $staticcompany->code_client = $obj->code_client;
376  $staticcompany->code_fournisseur = $obj->code_fournisseur;
377  $staticcompany->code_compta = $obj->code_compta;
378  $staticcompany->code_compta_fournisseur = $obj->code_compta_fournisseur;
379  $staticcompany->client = $obj->client;
380  $staticcompany->fournisseur = $obj->fournisseur;
381 
382  print '<tr class="oddeven">';
383  print '<td class="nowraponall">';
384  print $staticcontrat->getNomUrl(1, 16);
385  if ($obj->nb_late) {
386  print img_warning($langs->trans("Late"));
387  }
388  print '</td>';
389 
390  print '<td class="tdoverflowmax150">';
391  print $staticcompany->getNomUrl(1, '', 20);
392  print '</td>';
393  print '<td class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'">';
394  print dol_print_date($datem, 'dayhour');
395  print '</td>';
396  //print '<td class="left">'.$staticcontrat->LibStatut($obj->statut,2).'</td>';
397  print '<td class="right nowraponall" width="32">'.($obj->nb_initial > 0 ? '<span class="paddingright">'.$obj->nb_initial.'</span>'.$staticcontratligne->LibStatut(0, 3, -1, 'class="paddingleft"') : '').'</td>';
398  print '<td class="right nowraponall" width="32">'.($obj->nb_running > 0 ? '<span class="paddingright">'.$obj->nb_running.'</span>'.$staticcontratligne->LibStatut(4, 3, 0, 'class="marginleft"') : '').'</td>';
399  print '<td class="right nowraponall" width="32">'.($obj->nb_expired > 0 ? '<span class="paddingright">'.$obj->nb_expired.'</span>'.$staticcontratligne->LibStatut(4, 3, 1, 'class="paddingleft"') : '').'</td>';
400  print '<td class="right nowraponall" width="32">'.($obj->nb_closed > 0 ? '<span class="paddingright">'.$obj->nb_closed.'</span>'.$staticcontratligne->LibStatut(5, 3, -1, 'class="paddingleft"') : '').'</td>';
401  print "</tr>\n";
402  $i++;
403  }
404  $db->free($result);
405 
406  print "</table></div>";
407 } else {
408  dol_print_error($db);
409 }
410 
411 print '<br>';
412 
413 // Last modified services
414 $sql = "SELECT c.ref, c.fk_soc as socid,";
415 $sql .= " cd.rowid as cid, cd.statut, cd.label, cd.fk_product, cd.description as note, cd.fk_contrat, cd.date_fin_validite,";
416 $sql .= " s.nom as name, s.name_alias, s.logo, s.rowid as socid, s.client, s.fournisseur, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur,";
417 $sql .= " p.rowid as pid, p.ref as pref, p.label as plabel, p.fk_product_type as ptype, p.entity as pentity";
418 $sql .= " FROM (".MAIN_DB_PREFIX."contrat as c";
419 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
420 if (!$user->hasRight('societe', 'client', 'voir')) {
421  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
422 }
423 $sql .= ", ".MAIN_DB_PREFIX."contratdet as cd";
424 $sql .= ") LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid";
425 $sql .= " WHERE c.entity IN (".getEntity('contract', 0).")";
426 $sql .= " AND cd.fk_contrat = c.rowid";
427 $sql .= " AND c.fk_soc = s.rowid";
428 if (!$user->hasRight('societe', 'client', 'voir')) {
429  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
430 }
431 if ($socid) {
432  $sql .= " AND s.rowid = ".((int) $socid);
433 }
434 $sql .= " ORDER BY cd.tms DESC";
435 
436 $resql = $db->query($sql);
437 if ($resql) {
438  $num = $db->num_rows($resql);
439  $i = 0;
440 
441  print '<div class="div-table-responsive-no-min">';
442  print '<table class="noborder centpercent">';
443 
444  print '<tr class="liste_titre"><th colspan="4">'.$langs->trans("LastModifiedServices", $max).'</th>';
445  print "</tr>\n";
446 
447  while ($i < min($num, $max)) {
448  $obj = $db->fetch_object($resql);
449 
450  print '<tr class="oddeven">';
451  print '<td class="nowraponall">';
452 
453  $staticcontrat->ref = ($obj->ref ? $obj->ref : $obj->fk_contrat);
454  $staticcontrat->id = $obj->fk_contrat;
455 
456  $staticcompany->id = $obj->socid;
457  $staticcompany->name = $obj->name;
458  $staticcompany->name_alias = $obj->name_alias;
459  $staticcompany->photo = 1;
460  $staticcompany->code_client = $obj->code_client;
461  $staticcompany->code_fournisseur = $obj->code_fournisseur;
462  $staticcompany->code_compta = $obj->code_compta;
463  $staticcompany->code_compta_fournisseur = $obj->code_compta_fournisseur;
464  $staticcompany->client = $obj->client;
465  $staticcompany->fournisseur = $obj->fournisseur;
466 
467  print $staticcontrat->getNomUrl(1, 16);
468 
469  //if (1 == 1) print img_warning($langs->trans("Late"));
470  print '</td>';
471  print '<td>';
472  if ($obj->fk_product > 0) {
473  $productstatic->id = $obj->fk_product;
474  $productstatic->type = $obj->ptype;
475  $productstatic->ref = $obj->pref;
476  $productstatic->entity = $obj->pentity;
477  print $productstatic->getNomUrl(1, '', 20);
478  } else {
479  print '<a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$obj->fk_contrat.'">'.img_object($langs->trans("ShowService"), "service");
480  if ($obj->label) {
481  print ' '.dol_trunc($obj->label, 20).'</a>';
482  } else {
483  print '</a> '.dol_trunc($obj->note, 20);
484  }
485  }
486  print '</td>';
487  print '<td class="tdoverflowmax125">';
488  print $staticcompany->getNomUrl(1, '', 20);
489  print '</td>';
490  print '<td class="nowrap right"><a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$obj->fk_contrat.'&ligne='.$obj->cid.'">';
491  $dateend = $db->jdate($obj->date_fin_validite);
492  print $staticcontratligne->LibStatut($obj->statut, 3, ($dateend && $dateend < $now) ? 1 : 0);
493  print '</a></td>';
494  print "</tr>\n";
495  $i++;
496  }
497  $db->free($resql);
498 
499  print "</table></div>";
500 } else {
501  dol_print_error($db);
502 }
503 
504 print '<br>';
505 
506 // Not activated services
507 $sql = "SELECT c.ref, c.fk_soc as thirdpartyid, cd.rowid as cid, cd.statut, cd.label, cd.fk_product, cd.description as note, cd.fk_contrat,";
508 $sql .= " s.nom as name, s.name_alias, s.logo, s.rowid as socid, s.client, s.fournisseur, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur,";
509 $sql .= " p.rowid as pid, p.ref as pref, p.label as plabel, p.fk_product_type as ptype, p.entity as pentity";
510 $sql .= " FROM (".MAIN_DB_PREFIX."contrat as c";
511 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
512 if (!$user->hasRight('societe', 'client', 'voir')) {
513  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
514 }
515 $sql .= ", ".MAIN_DB_PREFIX."contratdet as cd";
516 $sql .= " ) LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid";
517 $sql .= " WHERE c.entity IN (".getEntity('contract', 0).")";
518 $sql .= " AND c.statut = 1";
519 $sql .= " AND cd.statut = 0";
520 $sql .= " AND cd.fk_contrat = c.rowid";
521 $sql .= " AND c.fk_soc = s.rowid";
522 if (!$user->hasRight('societe', 'client', 'voir')) {
523  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
524 }
525 if ($socid) {
526  $sql .= " AND s.rowid = ".((int) $socid);
527 }
528 $sql .= " ORDER BY cd.tms DESC";
529 
530 $resql = $db->query($sql);
531 if ($resql) {
532  $num = $db->num_rows($resql);
533  $i = 0;
534 
535  print '<div class="div-table-responsive-no-min">';
536  print '<table class="noborder centpercent">';
537 
538  print '<tr class="liste_titre"><th colspan="4">'.$langs->trans("NotActivatedServices").' <a href="'.DOL_URL_ROOT.'/contrat/services_list.php?mode=0"><span class="badge">'.$num.'</span></a></th>';
539  print "</tr>\n";
540 
541  while ($i < $num) {
542  $obj = $db->fetch_object($resql);
543 
544  $staticcompany->id = $obj->thirdpartyid;
545  $staticcompany->name = $obj->name;
546  $staticcompany->name_alias = $obj->name_alias;
547  $staticcompany->photo = 1;
548  $staticcompany->code_client = $obj->code_client;
549  $staticcompany->code_fournisseur = $obj->code_fournisseur;
550  $staticcompany->code_compta = $obj->code_compta;
551  $staticcompany->code_compta_fournisseur = $obj->code_compta_fournisseur;
552  $staticcompany->client = $obj->client;
553  $staticcompany->fournisseur = $obj->fournisseur;
554 
555  $staticcontrat->ref = ($obj->ref ? $obj->ref : $obj->fk_contrat);
556  $staticcontrat->id = $obj->fk_contrat;
557 
558  $productstatic->id = $obj->fk_product;
559  $productstatic->type = $obj->ptype;
560  $productstatic->ref = $obj->pref;
561  $productstatic->entity = $obj->pentity;
562 
563  print '<tr class="oddeven">';
564 
565  print '<td class="nowraponall">';
566  print $staticcontrat->getNomUrl(1, 16);
567  print '</td>';
568  print '<td class="nowrap">';
569  if ($obj->fk_product > 0) {
570  print $productstatic->getNomUrl(1, '', 20);
571  } else {
572  print '<a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$obj->fk_contrat.'">'.img_object($langs->trans("ShowService"), "service");
573  if ($obj->label) {
574  print ' '.dol_trunc($obj->label, 20).'</a>';
575  } else {
576  print '</a> '.dol_trunc($obj->note, 20);
577  }
578  }
579  print '</td>';
580  print '<td class="tdoverflowmax125">';
581  print $staticcompany->getNomUrl(1, '', 20);
582  print '</td>';
583  print '<td width="16" class="right"><a href="line.php?id='.$obj->fk_contrat.'&ligne='.$obj->cid.'">';
584  print $staticcontratligne->LibStatut($obj->statut, 3);
585  print '</a></td>';
586  print "</tr>\n";
587  $i++;
588  }
589 
590  $db->free($resql);
591 
592  print "</table></div>";
593 } else {
594  dol_print_error($db);
595 }
596 
597 print '<br>';
598 
599 // Expired services
600 $sql = "SELECT c.ref, c.fk_soc as thirdpartyid, cd.rowid as cid, cd.statut, cd.label, cd.fk_product, cd.description as note, cd.fk_contrat,";
601 $sql .= " s.nom as name, s.name_alias, s.logo, s.rowid as socid, s.client, s.fournisseur, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur,";
602 $sql .= " p.rowid as pid, p.ref as pref, p.label as plabel, p.fk_product_type as ptype, p.entity as pentity";
603 $sql .= " FROM (".MAIN_DB_PREFIX."contrat as c";
604 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
605 if (!$user->hasRight('societe', 'client', 'voir')) {
606  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
607 }
608 $sql .= ", ".MAIN_DB_PREFIX."contratdet as cd";
609 $sql .= " ) LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid";
610 $sql .= " WHERE c.entity IN (".getEntity('contract', 0).")";
611 $sql .= " AND c.statut = 1";
612 $sql .= " AND cd.statut = 4";
613 $sql .= " AND cd.date_fin_validite < '".$db->idate($now)."'";
614 $sql .= " AND cd.fk_contrat = c.rowid";
615 $sql .= " AND c.fk_soc = s.rowid";
616 if (!$user->hasRight('societe', 'client', 'voir')) {
617  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
618 }
619 if ($socid) {
620  $sql .= " AND s.rowid = ".((int) $socid);
621 }
622 $sql .= " ORDER BY cd.tms DESC";
623 
624 $resql = $db->query($sql);
625 if ($resql) {
626  $num = $db->num_rows($resql);
627  $i = 0;
628 
629  print '<div class="div-table-responsive-no-min">';
630  print '<table class="noborder centpercent">';
631 
632  print '<tr class="liste_titre"><th colspan="4">'.$langs->trans("ListOfExpiredServices").' <a href="'.DOL_URL_ROOT.'/contrat/services_list.php?search_status=4&amp;filter=expired"><span class="badge">'.$num.'</span></a></th>';
633  print "</tr>\n";
634 
635  while ($i < $num) {
636  $obj = $db->fetch_object($resql);
637 
638  $staticcompany->id = $obj->thirdpartyid;
639  $staticcompany->name = $obj->name;
640  $staticcompany->name_alias = $obj->name_alias;
641  $staticcompany->photo = 1;
642  $staticcompany->code_client = $obj->code_client;
643  $staticcompany->code_fournisseur = $obj->code_fournisseur;
644  $staticcompany->code_compta = $obj->code_compta;
645  $staticcompany->code_compta_fournisseur = $obj->code_compta_fournisseur;
646  $staticcompany->client = $obj->client;
647  $staticcompany->fournisseur = $obj->fournisseur;
648 
649  $staticcontrat->ref = ($obj->ref ? $obj->ref : $obj->fk_contrat);
650  $staticcontrat->id = $obj->fk_contrat;
651 
652  $productstatic->id = $obj->fk_product;
653  $productstatic->type = $obj->ptype;
654  $productstatic->ref = $obj->pref;
655  $productstatic->entity = $obj->pentity;
656 
657  print '<tr class="oddeven">';
658 
659  print '<td class="nowraponall">';
660  print $staticcontrat->getNomUrl(1, 16);
661  print '</td>';
662  print '<td class="nowrap">';
663  if ($obj->fk_product > 0) {
664  print $productstatic->getNomUrl(1, '', 20);
665  } else {
666  print '<a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$obj->fk_contrat.'">'.img_object($langs->trans("ShowService"), "service");
667  if ($obj->label) {
668  print ' '.dol_trunc($obj->label, 20).'</a>';
669  } else {
670  print '</a> '.dol_trunc($obj->note, 20);
671  }
672  }
673  print '</td>';
674  print '<td class="tdoverflowmax125">';
675  print $staticcompany->getNomUrl(1, '', 20);
676  print '</td>';
677  print '<td width="16" class="right"><a href="line.php?id='.$obj->fk_contrat.'&ligne='.$obj->cid.'">';
678  print $staticcontratligne->LibStatut($obj->statut, 3, 1);
679  print '</a></td>';
680  print "</tr>\n";
681  $i++;
682  }
683  $db->free($resql);
684 
685  print "</table></div>";
686 } else {
687  dol_print_error($db);
688 }
689 
690 
691 print '</div></div>';
692 
693 $parameters = array('user' => $user);
694 $reshook = $hookmanager->executeHooks('dashboardContracts', $parameters, $object); // Note that $action and $object may have been modified by hook
695 
696 llxFooter();
697 
698 $db->close();
if($user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition: card.php:58
Class to manage contracts.
Class to manage lines of contracts.
Class to build graphs.
Class to manage hooks.
Class to manage products or services.
Class to manage third parties objects (customers, suppliers, prospects...)
if(isModEnabled('invoice') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&!getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') && $user->hasRight('tax', 'charges', 'lire')) if(isModEnabled('invoice') &&isModEnabled('order') && $user->hasRight("commande", "lire") &&!getDolGlobalString('WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')) $sql
Social contributions to pay.
Definition: index.php:745
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
llxFooter()
Footer empty.
Definition: index.php:72
if(!defined('NOTOKENRENEWAL')) if(!defined('NOLOGIN')) if(!defined('NOCSRFCHECK')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) if(!defined('NOIPCHECK')) if(!defined('NOBROWSERNOTIF')) llxHeader()
Header empty.
Definition: index.php:64
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.