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