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