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