dolibarr 20.0.0
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
29require "../main.inc.php";
30require_once DOL_DOCUMENT_ROOT."/contrat/class/contrat.class.php";
31require_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');
52if (!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
80llxHeader('', $title, $help_url);
81
82print load_fiche_titre($langs->trans("ContractsArea"), '', 'contract');
83
84
85print '<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";
102if (!$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).")";
108if ($user->socid) {
109 $sql .= ' AND c.fk_soc = '.((int) $user->socid);
110}
111if (!$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);
116if ($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";
139if (!$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).")";
145if ($user->socid) {
146 $sql .= ' AND c.fk_soc = '.((int) $user->socid);
147}
148if (!$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);
153if ($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
177include DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php';
178
179print '<div class="div-table-responsive-no-min">';
180print '<table class="noborder nohover centpercent">';
181print '<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;
184foreach ($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}
212if (!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;
230foreach ($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}
244print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td class="right">'.$total.'</td></tr>';
245print "</table></div><br>";
246
247
248// Draft contracts
249
250if (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->logo = $obj->logo;
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_client = $obj->code_compta;
293 $staticcompany->code_compta_fournisseur = $obj->code_compta_fournisseur;
294 $staticcompany->client = $obj->client;
295 $staticcompany->fournisseur = $obj->fournisseur;
296
297 print '<tr class="oddeven"><td class="nowrap">';
298 print $staticcontrat->getNomUrl(1, '');
299 print '</td>';
300 print '<td>';
301 print $staticcompany->getNomUrl(1, '', 16);
302 print '</td>';
303 print '</tr>';
304 //$tot_ttc+=$obj->total_ttc;
305 $i++;
306 }
307 } else {
308 print '<tr class="oddeven"><td colspan="3"><span class="opacitymedium">'.$langs->trans("NoContracts").'</span></td></tr>';
309 }
310 print "</table></div><br>";
311 $db->free($resql);
312 } else {
313 dol_print_error($db);
314 }
315}
316
317
318print '</div><div class="fichetwothirdright">';
319
320
321// Last modified contracts
322$sql = 'SELECT ';
323$sql .= " sum(".$db->ifsql("cd.statut=0", 1, 0).') as nb_initial,';
324$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,';
325$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,';
326$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,';
327$sql .= " sum(".$db->ifsql("cd.statut=5", 1, 0).') as nb_closed,';
328$sql .= " c.rowid as cid, c.ref, c.datec, c.tms, c.statut,";
329$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";
330$sql .= " FROM ".MAIN_DB_PREFIX."societe as s,";
331if (!$user->hasRight('societe', 'client', 'voir')) {
332 $sql .= " ".MAIN_DB_PREFIX."societe_commerciaux as sc,";
333}
334$sql .= " ".MAIN_DB_PREFIX."contrat as c";
335$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."contratdet as cd ON c.rowid = cd.fk_contrat";
336$sql .= " WHERE c.fk_soc = s.rowid";
337$sql .= " AND c.entity IN (".getEntity('contract', 0).")";
338$sql .= " AND c.statut > 0";
339if (!$user->hasRight('societe', 'client', 'voir')) {
340 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
341}
342if ($socid) {
343 $sql .= " AND s.rowid = ".((int) $socid);
344}
345$sql .= " GROUP BY c.rowid, c.ref, c.datec, c.tms, c.statut,";
346$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";
347$sql .= " ORDER BY c.tms DESC";
348$sql .= $db->plimit($max);
349
350dol_syslog("contrat/index.php", LOG_DEBUG);
351$result = $db->query($sql);
352if ($result) {
353 $num = $db->num_rows($result);
354 $i = 0;
355
356 print '<div class="div-table-responsive-no-min">';
357 print '<table class="noborder centpercent">';
358
359 print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("LastContracts", $max).'</th>';
360 print '<th class="center">'.$langs->trans("DateModification").'</th>';
361 //print '<th class="left">'.$langs->trans("Status").'</th>';
362 print '<th class="center" width="80" colspan="4">'.$langs->trans("Services").'</th>';
363 print "</tr>\n";
364
365 while ($i < $num) {
366 $obj = $db->fetch_object($result);
367 $datem = $db->jdate($obj->tms);
368
369 $staticcontrat->ref = ($obj->ref ? $obj->ref : $obj->cid);
370 $staticcontrat->id = $obj->cid;
371
372 $staticcompany->id = $obj->socid;
373 $staticcompany->name = $obj->name;
374 $staticcompany->name_alias = $obj->name_alias;
375 $staticcompany->photo = 1;
376 $staticcompany->code_client = $obj->code_client;
377 $staticcompany->code_fournisseur = $obj->code_fournisseur;
378 $staticcompany->code_compta = $obj->code_compta;
379 $staticcompany->code_compta_fournisseur = $obj->code_compta_fournisseur;
380 $staticcompany->client = $obj->client;
381 $staticcompany->fournisseur = $obj->fournisseur;
382
383 print '<tr class="oddeven">';
384 print '<td class="nowraponall">';
385 print $staticcontrat->getNomUrl(1, 16);
386 if ($obj->nb_late) {
387 print img_warning($langs->trans("Late"));
388 }
389 print '</td>';
390
391 print '<td class="tdoverflowmax150">';
392 print $staticcompany->getNomUrl(1, '', 20);
393 print '</td>';
394 print '<td class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'">';
395 print dol_print_date($datem, 'dayhour');
396 print '</td>';
397 //print '<td class="left">'.$staticcontrat->LibStatut($obj->statut,2).'</td>';
398 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>';
399 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>';
400 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>';
401 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>';
402 print "</tr>\n";
403 $i++;
404 }
405 $db->free($result);
406
407 print "</table></div>";
408} else {
409 dol_print_error($db);
410}
411
412print '<br>';
413
414// Last modified services
415$sql = "SELECT c.ref, c.fk_soc as socid,";
416$sql .= " cd.rowid as cid, cd.statut, cd.label, cd.fk_product, cd.description as note, cd.fk_contrat, cd.date_fin_validite,";
417$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,";
418$sql .= " p.rowid as pid, p.ref as pref, p.label as plabel, p.fk_product_type as ptype, p.entity as pentity";
419$sql .= " FROM (".MAIN_DB_PREFIX."contrat as c";
420$sql .= ", ".MAIN_DB_PREFIX."societe as s";
421if (!$user->hasRight('societe', 'client', 'voir')) {
422 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
423}
424$sql .= ", ".MAIN_DB_PREFIX."contratdet as cd";
425$sql .= ") LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid";
426$sql .= " WHERE c.entity IN (".getEntity('contract', 0).")";
427$sql .= " AND cd.fk_contrat = c.rowid";
428$sql .= " AND c.fk_soc = s.rowid";
429if (!$user->hasRight('societe', 'client', 'voir')) {
430 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
431}
432if ($socid) {
433 $sql .= " AND s.rowid = ".((int) $socid);
434}
435$sql .= " ORDER BY cd.tms DESC";
436
437$resql = $db->query($sql);
438if ($resql) {
439 $num = $db->num_rows($resql);
440 $i = 0;
441
442 print '<div class="div-table-responsive-no-min">';
443 print '<table class="noborder centpercent">';
444
445 print '<tr class="liste_titre"><th colspan="4">'.$langs->trans("LastModifiedServices", $max).'</th>';
446 print "</tr>\n";
447
448 while ($i < min($num, $max)) {
449 $obj = $db->fetch_object($resql);
450
451 print '<tr class="oddeven">';
452 print '<td class="nowraponall">';
453
454 $staticcontrat->ref = ($obj->ref ? $obj->ref : $obj->fk_contrat);
455 $staticcontrat->id = $obj->fk_contrat;
456
457 $staticcompany->id = $obj->socid;
458 $staticcompany->name = $obj->name;
459 $staticcompany->name_alias = $obj->name_alias;
460 $staticcompany->photo = 1;
461 $staticcompany->code_client = $obj->code_client;
462 $staticcompany->code_fournisseur = $obj->code_fournisseur;
463 $staticcompany->code_compta = $obj->code_compta;
464 $staticcompany->code_compta_fournisseur = $obj->code_compta_fournisseur;
465 $staticcompany->client = $obj->client;
466 $staticcompany->fournisseur = $obj->fournisseur;
467
468 print $staticcontrat->getNomUrl(1, 16);
469
470 //if (1 == 1) print img_warning($langs->trans("Late"));
471 print '</td>';
472 print '<td>';
473 if ($obj->fk_product > 0) {
474 $productstatic->id = $obj->fk_product;
475 $productstatic->type = $obj->ptype;
476 $productstatic->ref = $obj->pref;
477 $productstatic->entity = $obj->pentity;
478 print $productstatic->getNomUrl(1, '', 20);
479 } else {
480 print '<a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$obj->fk_contrat.'">'.img_object($langs->trans("ShowService"), "service");
481 if ($obj->label) {
482 print ' '.dol_trunc($obj->label, 20).'</a>';
483 } else {
484 print '</a> '.dol_trunc($obj->note, 20);
485 }
486 }
487 print '</td>';
488 print '<td class="tdoverflowmax125">';
489 print $staticcompany->getNomUrl(1, '', 20);
490 print '</td>';
491 print '<td class="nowrap right"><a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$obj->fk_contrat.'&ligne='.$obj->cid.'">';
492 $dateend = $db->jdate($obj->date_fin_validite);
493 print $staticcontratligne->LibStatut($obj->statut, 3, ($dateend && $dateend < $now) ? 1 : 0);
494 print '</a></td>';
495 print "</tr>\n";
496 $i++;
497 }
498 $db->free($resql);
499
500 print "</table></div>";
501} else {
502 dol_print_error($db);
503}
504
505print '<br>';
506
507// Not activated services
508$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,";
509$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,";
510$sql .= " p.rowid as pid, p.ref as pref, p.label as plabel, p.fk_product_type as ptype, p.entity as pentity";
511$sql .= " FROM (".MAIN_DB_PREFIX."contrat as c";
512$sql .= ", ".MAIN_DB_PREFIX."societe as s";
513if (!$user->hasRight('societe', 'client', 'voir')) {
514 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
515}
516$sql .= ", ".MAIN_DB_PREFIX."contratdet as cd";
517$sql .= " ) LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid";
518$sql .= " WHERE c.entity IN (".getEntity('contract', 0).")";
519$sql .= " AND c.statut = 1";
520$sql .= " AND cd.statut = 0";
521$sql .= " AND cd.fk_contrat = c.rowid";
522$sql .= " AND c.fk_soc = s.rowid";
523if (!$user->hasRight('societe', 'client', 'voir')) {
524 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
525}
526if ($socid) {
527 $sql .= " AND s.rowid = ".((int) $socid);
528}
529$sql .= " ORDER BY cd.tms DESC";
530
531$resql = $db->query($sql);
532if ($resql) {
533 $num = $db->num_rows($resql);
534 $i = 0;
535
536 print '<div class="div-table-responsive-no-min">';
537 print '<table class="noborder centpercent">';
538
539 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>';
540 print "</tr>\n";
541
542 while ($i < $num) {
543 $obj = $db->fetch_object($resql);
544
545 $staticcompany->id = $obj->thirdpartyid;
546 $staticcompany->name = $obj->name;
547 $staticcompany->name_alias = $obj->name_alias;
548 $staticcompany->photo = 1;
549 $staticcompany->code_client = $obj->code_client;
550 $staticcompany->code_fournisseur = $obj->code_fournisseur;
551 $staticcompany->code_compta = $obj->code_compta;
552 $staticcompany->code_compta_fournisseur = $obj->code_compta_fournisseur;
553 $staticcompany->client = $obj->client;
554 $staticcompany->fournisseur = $obj->fournisseur;
555
556 $staticcontrat->ref = ($obj->ref ? $obj->ref : $obj->fk_contrat);
557 $staticcontrat->id = $obj->fk_contrat;
558
559 $productstatic->id = $obj->fk_product;
560 $productstatic->type = $obj->ptype;
561 $productstatic->ref = $obj->pref;
562 $productstatic->entity = $obj->pentity;
563
564 print '<tr class="oddeven">';
565
566 print '<td class="nowraponall">';
567 print $staticcontrat->getNomUrl(1, 16);
568 print '</td>';
569 print '<td class="nowrap">';
570 if ($obj->fk_product > 0) {
571 print $productstatic->getNomUrl(1, '', 20);
572 } else {
573 print '<a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$obj->fk_contrat.'">'.img_object($langs->trans("ShowService"), "service");
574 if ($obj->label) {
575 print ' '.dol_trunc($obj->label, 20).'</a>';
576 } else {
577 print '</a> '.dol_trunc($obj->note, 20);
578 }
579 }
580 print '</td>';
581 print '<td class="tdoverflowmax125">';
582 print $staticcompany->getNomUrl(1, '', 20);
583 print '</td>';
584 print '<td width="16" class="right"><a href="line.php?id='.$obj->fk_contrat.'&ligne='.$obj->cid.'">';
585 print $staticcontratligne->LibStatut($obj->statut, 3);
586 print '</a></td>';
587 print "</tr>\n";
588 $i++;
589 }
590
591 $db->free($resql);
592
593 print "</table></div>";
594} else {
595 dol_print_error($db);
596}
597
598print '<br>';
599
600// Expired services
601$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,";
602$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,";
603$sql .= " p.rowid as pid, p.ref as pref, p.label as plabel, p.fk_product_type as ptype, p.entity as pentity";
604$sql .= " FROM (".MAIN_DB_PREFIX."contrat as c";
605$sql .= ", ".MAIN_DB_PREFIX."societe as s";
606if (!$user->hasRight('societe', 'client', 'voir')) {
607 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
608}
609$sql .= ", ".MAIN_DB_PREFIX."contratdet as cd";
610$sql .= " ) LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid";
611$sql .= " WHERE c.entity IN (".getEntity('contract', 0).")";
612$sql .= " AND c.statut = 1";
613$sql .= " AND cd.statut = 4";
614$sql .= " AND cd.date_fin_validite < '".$db->idate($now)."'";
615$sql .= " AND cd.fk_contrat = c.rowid";
616$sql .= " AND c.fk_soc = s.rowid";
617if (!$user->hasRight('societe', 'client', 'voir')) {
618 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
619}
620if ($socid) {
621 $sql .= " AND s.rowid = ".((int) $socid);
622}
623$sql .= " ORDER BY cd.tms DESC";
624
625$resql = $db->query($sql);
626if ($resql) {
627 $num = $db->num_rows($resql);
628 $i = 0;
629
630 print '<div class="div-table-responsive-no-min">';
631 print '<table class="noborder centpercent">';
632
633 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>';
634 print "</tr>\n";
635
636 while ($i < $num) {
637 $obj = $db->fetch_object($resql);
638
639 $staticcompany->id = $obj->thirdpartyid;
640 $staticcompany->name = $obj->name;
641 $staticcompany->name_alias = $obj->name_alias;
642 $staticcompany->photo = 1;
643 $staticcompany->code_client = $obj->code_client;
644 $staticcompany->code_fournisseur = $obj->code_fournisseur;
645 $staticcompany->code_compta = $obj->code_compta;
646 $staticcompany->code_compta_fournisseur = $obj->code_compta_fournisseur;
647 $staticcompany->client = $obj->client;
648 $staticcompany->fournisseur = $obj->fournisseur;
649
650 $staticcontrat->ref = ($obj->ref ? $obj->ref : $obj->fk_contrat);
651 $staticcontrat->id = $obj->fk_contrat;
652
653 $productstatic->id = $obj->fk_product;
654 $productstatic->type = $obj->ptype;
655 $productstatic->ref = $obj->pref;
656 $productstatic->entity = $obj->pentity;
657
658 print '<tr class="oddeven">';
659
660 print '<td class="nowraponall">';
661 print $staticcontrat->getNomUrl(1, 16);
662 print '</td>';
663 print '<td class="nowrap">';
664 if ($obj->fk_product > 0) {
665 print $productstatic->getNomUrl(1, '', 20);
666 } else {
667 print '<a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$obj->fk_contrat.'">'.img_object($langs->trans("ShowService"), "service");
668 if ($obj->label) {
669 print ' '.dol_trunc($obj->label, 20).'</a>';
670 } else {
671 print '</a> '.dol_trunc($obj->note, 20);
672 }
673 }
674 print '</td>';
675 print '<td class="tdoverflowmax125">';
676 print $staticcompany->getNomUrl(1, '', 20);
677 print '</td>';
678 print '<td width="16" class="right"><a href="line.php?id='.$obj->fk_contrat.'&ligne='.$obj->cid.'">';
679 print $staticcontratligne->LibStatut($obj->statut, 3, 1);
680 print '</a></td>';
681 print "</tr>\n";
682 $i++;
683 }
684 $db->free($resql);
685
686 print "</table></div>";
687} else {
688 dol_print_error($db);
689}
690
691
692print '</div></div>';
693
694$parameters = array('user' => $user);
695$reshook = $hookmanager->executeHooks('dashboardContracts', $parameters, $object); // Note that $action and $object may have been modified by hook
696
697llxFooter();
698
699$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($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...
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.