dolibarr 22.0.5
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 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";
34
43// Load translation files required by the page
44$langs->loadLangs(array('products', 'companies', 'contracts'));
45
46// Initialize a technical object to manage hooks. Note that conf->hooks_modules contains array
47$hookmanager->initHooks(array('contractindex'));
48
49$sortfield = GETPOST('sortfield', 'aZ09comma');
50$sortorder = GETPOST('sortorder', 'aZ09comma');
51$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
52
53$statut = GETPOST('statut') ? GETPOST('statut') : 1;
54
55$max = getDolGlobalInt('MAIN_SIZE_SHORTLIST_LIMIT', 5);
56
57// Security check
58$socid = 0;
59$id = GETPOSTINT('id');
60if (!empty($user->socid)) {
61 $socid = $user->socid;
62}
63$result = restrictedArea($user, 'contrat', $id);
64
65$staticcompany = new Societe($db);
66$staticcontrat = new Contrat($db);
67$staticcontratligne = new ContratLigne($db);
68$productstatic = new Product($db);
69
70
71
72/*
73 * Action
74 */
75
76// None
77
78
79/*
80 * View
81 */
82
83$now = dol_now();
84
85$title = $langs->trans("ContractsArea");
86$help_url = 'EN:Module_Contracts|FR:Module_Contrat|ES:Contratos_de_servicio';
87
88llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-contrat page-index');
89
90print load_fiche_titre($langs->trans("ContractsArea"), '', 'contract');
91
92
93print '<div class="fichecenter"><div class="fichethirdleft">';
94
95
96/*
97 * Statistics
98 */
99
100$nb = array();
101$total = 0;
102$totalinprocess = 0;
103$dataseries = array();
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$colorseries = array();
184
185include DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php';
186
187print '<div class="div-table-responsive-no-min">';
188print '<table class="noborder nohover centpercent">';
189print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Statistics").' - '.$langs->trans("Services").'</th></tr>'."\n";
190$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.
191if (!getDolGlobalString('CONTRACT_HIDE_CLOSED_SERVICES_IN_GRAPH')) {
192 $listofstatus[] = 5; // We add this status too (even if useless
193}
194$bool = false;
195foreach ($listofstatus as $status) {
196 $bool_str = (string) $bool;
197 $dataseries[] = array($staticcontratligne->LibStatut($status, 1, ($bool ? 1 : 0)), (isset($nb[$status.$bool_str]) ? (int) $nb[$status.$bool_str] : 0));
198 if ($status == ContratLigne::STATUS_INITIAL) {
199 $colorseries[$status.$bool_str] = '-'.$badgeStatus0;
200 }
201 if ($status == ContratLigne::STATUS_OPEN && !$bool) {
202 $colorseries[$status.$bool_str] = $badgeStatus4;
203 }
204 if ($status == ContratLigne::STATUS_OPEN && $bool) {
205 $colorseries[$status.$bool_str] = $badgeStatus1;
206 }
207 if ($status == ContratLigne::STATUS_CLOSED) {
208 $colorseries[$status.$bool_str] = $badgeStatus6;
209 }
210
211 if (empty($conf->use_javascript_ajax)) {
212 print '<tr class="oddeven">';
213 print '<td>'.$staticcontratligne->LibStatut($status, 0, ($bool ? 1 : 0)).'</td>';
214 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>';
215 print "</tr>\n";
216 }
217 if ($status == 4 && !$bool) {
218 $bool = true;
219 } else {
220 $bool = false;
221 }
222}
223if (!empty($conf->use_javascript_ajax)) {
224 print '<tr class="impair"><td class="center" colspan="2">';
225
226 include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
227 $dolgraph = new DolGraph();
228 $dolgraph->SetData($dataseries);
229 $dolgraph->SetDataColor(array_values($colorseries));
230 $dolgraph->setShowLegend(2);
231 $dolgraph->setShowPercent(1);
232 $dolgraph->SetType(array('pie'));
233 $dolgraph->setHeight('200');
234 $dolgraph->draw('idgraphstatus');
235 print $dolgraph->show($total ? 0 : 1);
236
237 print '</td></tr>';
238}
239$listofstatus = array(0, 4, 4, 5);
240$bool = false;
241foreach ($listofstatus as $status) {
242 $bool_str = (string) $bool;
243 if (empty($conf->use_javascript_ajax)) {
244 print '<tr class="oddeven">';
245 print '<td>'.$staticcontratligne->LibStatut($status, 0, ($bool ? 1 : 0)).'</td>';
246 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>';
247 if ($status == 4 && !$bool) {
248 $bool = true;
249 } else {
250 $bool = false;
251 }
252 print "</tr>\n";
253 }
254}
255print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td class="right">'.$total.'</td></tr>';
256print "</table></div><br>";
257
258
259// Draft contracts
260
261if (isModEnabled('contract') && $user->hasRight('contrat', 'lire')) {
262 $sql = "SELECT c.rowid, c.ref,";
263 $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";
264 $sql .= " FROM ".MAIN_DB_PREFIX."contrat as c, ".MAIN_DB_PREFIX."societe as s";
265 if (!$user->hasRight('societe', 'client', 'voir')) {
266 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
267 }
268 $sql .= " WHERE s.rowid = c.fk_soc";
269 $sql .= " AND c.entity IN (".getEntity('contract', 0).")";
270 $sql .= " AND c.statut = 0";
271 if (!$user->hasRight('societe', 'client', 'voir')) {
272 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
273 }
274 if ($socid) {
275 $sql .= " AND c.fk_soc = ".((int) $socid);
276 }
277
278 $resql = $db->query($sql);
279
280 if ($resql) {
281 $num = $db->num_rows($resql);
282
283 print '<div class="div-table-responsive-no-min">';
284 print '<table class="noborder centpercent">';
285 print '<tr class="liste_titre">';
286 print '<th colspan="3">'.$langs->trans("DraftContracts").($num ? '<span class="badge marginleftonlyshort">'.$num.'</span>' : '').'</th></tr>';
287 if ($num) {
288 $i = 0;
289 //$tot_ttc = 0;
290 while ($i < $num) {
291 $obj = $db->fetch_object($resql);
292
293 $staticcontrat->ref = $obj->ref;
294 $staticcontrat->id = $obj->rowid;
295
296 $staticcompany->id = $obj->socid;
297 $staticcompany->name = $obj->name;
298 $staticcompany->name_alias = $obj->name_alias;
299 $staticcompany->logo = $obj->logo;
300 $staticcompany->code_client = $obj->code_client;
301 $staticcompany->code_fournisseur = $obj->code_fournisseur;
302 $staticcompany->code_compta = $obj->code_compta_client;
303 $staticcompany->code_compta_client = $obj->code_compta_client;
304 $staticcompany->code_compta_fournisseur = $obj->code_compta_fournisseur;
305 $staticcompany->client = $obj->client;
306 $staticcompany->fournisseur = $obj->fournisseur;
307
308 print '<tr class="oddeven"><td class="nowrap">';
309 print $staticcontrat->getNomUrl(1, 0);
310 print '</td>';
311 print '<td>';
312 print $staticcompany->getNomUrl(1, '', 16);
313 print '</td>';
314 print '</tr>';
315 //$tot_ttc+=$obj->total_ttc;
316 $i++;
317 }
318 } else {
319 print '<tr class="oddeven"><td colspan="3"><span class="opacitymedium">'.$langs->trans("NoContracts").'</span></td></tr>';
320 }
321 print "</table></div><br>";
322 $db->free($resql);
323 } else {
324 dol_print_error($db);
325 }
326}
327
328
329print '</div><div class="fichetwothirdright">';
330
331
332// Last modified contracts
333$sql = 'SELECT ';
334$sql .= " sum(".$db->ifsql("cd.statut=0", '1', '0').') as nb_initial,';
335$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,';
336$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,';
337$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,';
338$sql .= " sum(".$db->ifsql("cd.statut=5", '1', '0').') as nb_closed,';
339$sql .= " c.rowid as cid, c.ref, c.datec, c.tms, c.statut,";
340$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";
341$sql .= " FROM ".MAIN_DB_PREFIX."societe as s,";
342if (!$user->hasRight('societe', 'client', 'voir')) {
343 $sql .= " ".MAIN_DB_PREFIX."societe_commerciaux as sc,";
344}
345$sql .= " ".MAIN_DB_PREFIX."contrat as c";
346$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."contratdet as cd ON c.rowid = cd.fk_contrat";
347$sql .= " WHERE c.fk_soc = s.rowid";
348$sql .= " AND c.entity IN (".getEntity('contract', 0).")";
349$sql .= " AND c.statut > 0";
350if (!$user->hasRight('societe', 'client', 'voir')) {
351 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
352}
353if ($socid) {
354 $sql .= " AND s.rowid = ".((int) $socid);
355}
356$sql .= " GROUP BY c.rowid, c.ref, c.datec, c.tms, c.statut,";
357$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";
358$sql .= " ORDER BY c.tms DESC";
359$sql .= $db->plimit($max);
360
361dol_syslog("contrat/index.php", LOG_DEBUG);
362$result = $db->query($sql);
363if ($result) {
364 $num = $db->num_rows($result);
365 $i = 0;
366
367 print '<div class="div-table-responsive-no-min">';
368 print '<table class="noborder centpercent">';
369
370 print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("LastContracts", $max).'</th>';
371 print '<th class="center">'.$langs->trans("DateModification").'</th>';
372 //print '<th class="left">'.$langs->trans("Status").'</th>';
373 print '<th class="center" width="80" colspan="4">'.$langs->trans("Services").'</th>';
374 print "</tr>\n";
375
376 while ($i < $num) {
377 $obj = $db->fetch_object($result);
378 $datem = $db->jdate($obj->tms);
379
380 $staticcontrat->ref = ($obj->ref ? $obj->ref : $obj->cid);
381 $staticcontrat->id = $obj->cid;
382
383 $staticcompany->id = $obj->socid;
384 $staticcompany->name = $obj->name;
385 $staticcompany->name_alias = $obj->name_alias;
386 $staticcompany->photo = 1;
387 $staticcompany->code_client = $obj->code_client;
388 $staticcompany->code_fournisseur = $obj->code_fournisseur;
389 $staticcompany->code_compta = $obj->code_compta_client;
390 $staticcompany->code_compta_client = $obj->code_compta_client;
391 $staticcompany->code_compta_fournisseur = $obj->code_compta_fournisseur;
392 $staticcompany->client = $obj->client;
393 $staticcompany->fournisseur = $obj->fournisseur;
394
395 print '<tr class="oddeven">';
396 print '<td class="nowraponall">';
397 print $staticcontrat->getNomUrl(1, 16);
398 if ($obj->nb_late) {
399 print img_warning($langs->trans("Late"));
400 }
401 print '</td>';
402
403 print '<td class="tdoverflowmax150">';
404 print $staticcompany->getNomUrl(1, '', 20);
405 print '</td>';
406 print '<td class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'">';
407 print dol_print_date($datem, 'dayhour');
408 print '</td>';
409 //print '<td class="left">'.$staticcontrat->LibStatut($obj->statut,2).'</td>';
410 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>';
411 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>';
412 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>';
413 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>';
414 print "</tr>\n";
415 $i++;
416 }
417 $db->free($result);
418
419 print "</table></div>";
420} else {
421 dol_print_error($db);
422}
423
424print '<br>';
425
426// Last modified services
427$sql = "SELECT c.ref, c.fk_soc as socid,";
428$sql .= " cd.rowid as cid, cd.statut, cd.label, cd.fk_product, cd.description as note, cd.fk_contrat, cd.date_fin_validite,";
429$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,";
430$sql .= " p.rowid as pid, p.ref as pref, p.label as plabel, p.fk_product_type as ptype, p.entity as pentity";
431$sql .= " FROM (".MAIN_DB_PREFIX."contrat as c";
432$sql .= ", ".MAIN_DB_PREFIX."societe as s";
433if (!$user->hasRight('societe', 'client', 'voir')) {
434 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
435}
436$sql .= ", ".MAIN_DB_PREFIX."contratdet as cd";
437$sql .= ") LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid";
438$sql .= " WHERE c.entity IN (".getEntity('contract', 0).")";
439$sql .= " AND cd.fk_contrat = c.rowid";
440$sql .= " AND c.fk_soc = s.rowid";
441if (!$user->hasRight('societe', 'client', 'voir')) {
442 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
443}
444if ($socid) {
445 $sql .= " AND s.rowid = ".((int) $socid);
446}
447$sql .= " ORDER BY cd.tms DESC";
448
449$resql = $db->query($sql);
450if ($resql) {
451 $num = $db->num_rows($resql);
452 $i = 0;
453
454 print '<div class="div-table-responsive-no-min">';
455 print '<table class="noborder centpercent">';
456
457 print '<tr class="liste_titre"><th colspan="4">'.$langs->trans("LastModifiedServices", $max).'</th>';
458 print "</tr>\n";
459
460 while ($i < min($num, $max)) {
461 $obj = $db->fetch_object($resql);
462
463 print '<tr class="oddeven">';
464 print '<td class="nowraponall">';
465
466 $staticcontrat->ref = ($obj->ref ? $obj->ref : $obj->fk_contrat);
467 $staticcontrat->id = $obj->fk_contrat;
468
469 $staticcompany->id = $obj->socid;
470 $staticcompany->name = $obj->name;
471 $staticcompany->name_alias = $obj->name_alias;
472 $staticcompany->photo = 1;
473 $staticcompany->code_client = $obj->code_client;
474 $staticcompany->code_fournisseur = $obj->code_fournisseur;
475 $staticcompany->code_compta = $obj->code_compta_client;
476 $staticcompany->code_compta_client = $obj->code_compta_client;
477 $staticcompany->code_compta_fournisseur = $obj->code_compta_fournisseur;
478 $staticcompany->client = $obj->client;
479 $staticcompany->fournisseur = $obj->fournisseur;
480
481 print $staticcontrat->getNomUrl(1, 16);
482
483 //if (1 == 1) print img_warning($langs->trans("Late"));
484 print '</td>';
485 print '<td>';
486 if ($obj->fk_product > 0) {
487 $productstatic->id = $obj->fk_product;
488 $productstatic->type = $obj->ptype;
489 $productstatic->ref = $obj->pref;
490 $productstatic->entity = $obj->pentity;
491 print $productstatic->getNomUrl(1, '', 20);
492 } else {
493 print '<a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$obj->fk_contrat.'">'.img_object($langs->trans("ShowService"), "service");
494 if ($obj->label) {
495 print ' '.dol_trunc($obj->label, 20).'</a>';
496 } else {
497 print '</a> '.dol_trunc($obj->note, 20);
498 }
499 }
500 print '</td>';
501 print '<td class="tdoverflowmax125">';
502 print $staticcompany->getNomUrl(1, '', 20);
503 print '</td>';
504 print '<td class="nowrap right"><a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$obj->fk_contrat.'&ligne='.$obj->cid.'">';
505 $dateend = $db->jdate($obj->date_fin_validite);
506 print $staticcontratligne->LibStatut($obj->statut, 3, ($dateend && $dateend < $now) ? 1 : 0);
507 print '</a></td>';
508 print "</tr>\n";
509 $i++;
510 }
511 $db->free($resql);
512
513 print "</table></div>";
514} else {
515 dol_print_error($db);
516}
517
518print '<br>';
519
520// Not activated services
521$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,";
522$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,";
523$sql .= " p.rowid as pid, p.ref as pref, p.label as plabel, p.fk_product_type as ptype, p.entity as pentity";
524$sql .= " FROM (".MAIN_DB_PREFIX."contrat as c";
525$sql .= ", ".MAIN_DB_PREFIX."societe as s";
526if (!$user->hasRight('societe', 'client', 'voir')) {
527 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
528}
529$sql .= ", ".MAIN_DB_PREFIX."contratdet as cd";
530$sql .= " ) LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid";
531$sql .= " WHERE c.entity IN (".getEntity('contract', 0).")";
532$sql .= " AND c.statut = 1";
533$sql .= " AND cd.statut = 0";
534$sql .= " AND cd.fk_contrat = c.rowid";
535$sql .= " AND c.fk_soc = s.rowid";
536if (!$user->hasRight('societe', 'client', 'voir')) {
537 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
538}
539if ($socid) {
540 $sql .= " AND s.rowid = ".((int) $socid);
541}
542$sql .= " ORDER BY cd.tms DESC";
543
544$resql = $db->query($sql);
545if ($resql) {
546 $num = $db->num_rows($resql);
547 $i = 0;
548
549 print '<div class="div-table-responsive-no-min">';
550 print '<table class="noborder centpercent">';
551
552 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>';
553 print "</tr>\n";
554
555 while ($i < $num) {
556 $obj = $db->fetch_object($resql);
557
558 $staticcompany->id = $obj->thirdpartyid;
559 $staticcompany->name = $obj->name;
560 $staticcompany->name_alias = $obj->name_alias;
561 $staticcompany->photo = 1;
562 $staticcompany->code_client = $obj->code_client;
563 $staticcompany->code_fournisseur = $obj->code_fournisseur;
564 $staticcompany->code_compta = $obj->code_compta_client;
565 $staticcompany->code_compta_client = $obj->code_compta_client;
566 $staticcompany->code_compta_fournisseur = $obj->code_compta_fournisseur;
567 $staticcompany->client = $obj->client;
568 $staticcompany->fournisseur = $obj->fournisseur;
569
570 $staticcontrat->ref = ($obj->ref ? $obj->ref : $obj->fk_contrat);
571 $staticcontrat->id = $obj->fk_contrat;
572
573 $productstatic->id = $obj->fk_product;
574 $productstatic->type = $obj->ptype;
575 $productstatic->ref = $obj->pref;
576 $productstatic->entity = $obj->pentity;
577
578 print '<tr class="oddeven">';
579
580 print '<td class="nowraponall">';
581 print $staticcontrat->getNomUrl(1, 16);
582 print '</td>';
583 print '<td class="nowrap">';
584 if ($obj->fk_product > 0) {
585 print $productstatic->getNomUrl(1, '', 20);
586 } else {
587 print '<a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$obj->fk_contrat.'">'.img_object($langs->trans("ShowService"), "service");
588 if ($obj->label) {
589 print ' '.dol_trunc($obj->label, 20).'</a>';
590 } else {
591 print '</a> '.dol_trunc($obj->note, 20);
592 }
593 }
594 print '</td>';
595 print '<td class="tdoverflowmax125">';
596 print $staticcompany->getNomUrl(1, '', 20);
597 print '</td>';
598 print '<td width="16" class="right"><a href="line.php?id='.$obj->fk_contrat.'&ligne='.$obj->cid.'">';
599 print $staticcontratligne->LibStatut($obj->statut, 3);
600 print '</a></td>';
601 print "</tr>\n";
602 $i++;
603 }
604
605 $db->free($resql);
606
607 print "</table></div>";
608} else {
609 dol_print_error($db);
610}
611
612print '<br>';
613
614// Expired services
615$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,";
616$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,";
617$sql .= " p.rowid as pid, p.ref as pref, p.label as plabel, p.fk_product_type as ptype, p.entity as pentity";
618$sql .= " FROM (".MAIN_DB_PREFIX."contrat as c";
619$sql .= ", ".MAIN_DB_PREFIX."societe as s";
620if (!$user->hasRight('societe', 'client', 'voir')) {
621 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
622}
623$sql .= ", ".MAIN_DB_PREFIX."contratdet as cd";
624$sql .= " ) LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid";
625$sql .= " WHERE c.entity IN (".getEntity('contract', 0).")";
626$sql .= " AND c.statut = 1";
627$sql .= " AND cd.statut = 4";
628$sql .= " AND cd.date_fin_validite < '".$db->idate($now)."'";
629$sql .= " AND cd.fk_contrat = c.rowid";
630$sql .= " AND c.fk_soc = s.rowid";
631if (!$user->hasRight('societe', 'client', 'voir')) {
632 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
633}
634if ($socid) {
635 $sql .= " AND s.rowid = ".((int) $socid);
636}
637$sql .= " ORDER BY cd.tms DESC";
638
639$resql = $db->query($sql);
640if ($resql) {
641 $num = $db->num_rows($resql);
642 $i = 0;
643
644 print '<div class="div-table-responsive-no-min">';
645 print '<table class="noborder centpercent">';
646
647 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>';
648 print "</tr>\n";
649
650 while ($i < $num) {
651 $obj = $db->fetch_object($resql);
652
653 $staticcompany->id = $obj->thirdpartyid;
654 $staticcompany->name = $obj->name;
655 $staticcompany->name_alias = $obj->name_alias;
656 $staticcompany->photo = 1;
657 $staticcompany->code_client = $obj->code_client;
658 $staticcompany->code_fournisseur = $obj->code_fournisseur;
659 $staticcompany->code_compta = $obj->code_compta_client;
660 $staticcompany->code_compta_client = $obj->code_compta_client;
661 $staticcompany->code_compta_fournisseur = $obj->code_compta_fournisseur;
662 $staticcompany->client = $obj->client;
663 $staticcompany->fournisseur = $obj->fournisseur;
664
665 $staticcontrat->ref = ($obj->ref ? $obj->ref : $obj->fk_contrat);
666 $staticcontrat->id = $obj->fk_contrat;
667
668 $productstatic->id = $obj->fk_product;
669 $productstatic->type = $obj->ptype;
670 $productstatic->ref = $obj->pref;
671 $productstatic->entity = $obj->pentity;
672
673 print '<tr class="oddeven">';
674
675 print '<td class="nowraponall">';
676 print $staticcontrat->getNomUrl(1, 16);
677 print '</td>';
678 print '<td class="nowrap">';
679 if ($obj->fk_product > 0) {
680 print $productstatic->getNomUrl(1, '', 20);
681 } else {
682 print '<a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$obj->fk_contrat.'">'.img_object($langs->trans("ShowService"), "service");
683 if ($obj->label) {
684 print ' '.dol_trunc($obj->label, 20).'</a>';
685 } else {
686 print '</a> '.dol_trunc($obj->note, 20);
687 }
688 }
689 print '</td>';
690 print '<td class="tdoverflowmax125">';
691 print $staticcompany->getNomUrl(1, '', 20);
692 print '</td>';
693 print '<td width="16" class="right"><a href="line.php?id='.$obj->fk_contrat.'&ligne='.$obj->cid.'">';
694 print $staticcontratligne->LibStatut($obj->statut, 3, 1);
695 print '</a></td>';
696 print "</tr>\n";
697 $i++;
698 }
699 $db->free($resql);
700
701 print "</table></div>";
702} else {
703 dol_print_error($db);
704}
705
706
707print '</div></div>';
708
709$parameters = array('user' => $user);
710$reshook = $hookmanager->executeHooks('dashboardContracts', $parameters, $object); // Note that $action and $object may have been modified by hook
711
712llxFooter();
713
714$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:48
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 build graphs.
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_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.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
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...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
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.