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 as code_compta_client, 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_client;
293 $staticcompany->code_compta_client = $obj->code_compta_client;
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, 0);
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 as code_compta_client, 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_client;
380 $staticcompany->code_compta_client = $obj->code_compta_client;
381 $staticcompany->code_compta_fournisseur = $obj->code_compta_fournisseur;
382 $staticcompany->client = $obj->client;
383 $staticcompany->fournisseur = $obj->fournisseur;
384
385 print '<tr class="oddeven">';
386 print '<td class="nowraponall">';
387 print $staticcontrat->getNomUrl(1, 16);
388 if ($obj->nb_late) {
389 print img_warning($langs->trans("Late"));
390 }
391 print '</td>';
392
393 print '<td class="tdoverflowmax150">';
394 print $staticcompany->getNomUrl(1, '', 20);
395 print '</td>';
396 print '<td class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'">';
397 print dol_print_date($datem, 'dayhour');
398 print '</td>';
399 //print '<td class="left">'.$staticcontrat->LibStatut($obj->statut,2).'</td>';
400 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>';
401 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>';
402 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>';
403 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>';
404 print "</tr>\n";
405 $i++;
406 }
407 $db->free($result);
408
409 print "</table></div>";
410} else {
411 dol_print_error($db);
412}
413
414print '<br>';
415
416// Last modified services
417$sql = "SELECT c.ref, c.fk_soc as socid,";
418$sql .= " cd.rowid as cid, cd.statut, cd.label, cd.fk_product, cd.description as note, cd.fk_contrat, cd.date_fin_validite,";
419$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,";
420$sql .= " p.rowid as pid, p.ref as pref, p.label as plabel, p.fk_product_type as ptype, p.entity as pentity";
421$sql .= " FROM (".MAIN_DB_PREFIX."contrat as c";
422$sql .= ", ".MAIN_DB_PREFIX."societe as s";
423if (!$user->hasRight('societe', 'client', 'voir')) {
424 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
425}
426$sql .= ", ".MAIN_DB_PREFIX."contratdet as cd";
427$sql .= ") LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid";
428$sql .= " WHERE c.entity IN (".getEntity('contract', 0).")";
429$sql .= " AND cd.fk_contrat = c.rowid";
430$sql .= " AND c.fk_soc = s.rowid";
431if (!$user->hasRight('societe', 'client', 'voir')) {
432 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
433}
434if ($socid) {
435 $sql .= " AND s.rowid = ".((int) $socid);
436}
437$sql .= " ORDER BY cd.tms DESC";
438
439$resql = $db->query($sql);
440if ($resql) {
441 $num = $db->num_rows($resql);
442 $i = 0;
443
444 print '<div class="div-table-responsive-no-min">';
445 print '<table class="noborder centpercent">';
446
447 print '<tr class="liste_titre"><th colspan="4">'.$langs->trans("LastModifiedServices", $max).'</th>';
448 print "</tr>\n";
449
450 while ($i < min($num, $max)) {
451 $obj = $db->fetch_object($resql);
452
453 print '<tr class="oddeven">';
454 print '<td class="nowraponall">';
455
456 $staticcontrat->ref = ($obj->ref ? $obj->ref : $obj->fk_contrat);
457 $staticcontrat->id = $obj->fk_contrat;
458
459 $staticcompany->id = $obj->socid;
460 $staticcompany->name = $obj->name;
461 $staticcompany->name_alias = $obj->name_alias;
462 $staticcompany->photo = 1;
463 $staticcompany->code_client = $obj->code_client;
464 $staticcompany->code_fournisseur = $obj->code_fournisseur;
465 $staticcompany->code_compta = $obj->code_compta_client;
466 $staticcompany->code_compta_client = $obj->code_compta_client;
467 $staticcompany->code_compta_fournisseur = $obj->code_compta_fournisseur;
468 $staticcompany->client = $obj->client;
469 $staticcompany->fournisseur = $obj->fournisseur;
470
471 print $staticcontrat->getNomUrl(1, 16);
472
473 //if (1 == 1) print img_warning($langs->trans("Late"));
474 print '</td>';
475 print '<td>';
476 if ($obj->fk_product > 0) {
477 $productstatic->id = $obj->fk_product;
478 $productstatic->type = $obj->ptype;
479 $productstatic->ref = $obj->pref;
480 $productstatic->entity = $obj->pentity;
481 print $productstatic->getNomUrl(1, '', 20);
482 } else {
483 print '<a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$obj->fk_contrat.'">'.img_object($langs->trans("ShowService"), "service");
484 if ($obj->label) {
485 print ' '.dol_trunc($obj->label, 20).'</a>';
486 } else {
487 print '</a> '.dol_trunc($obj->note, 20);
488 }
489 }
490 print '</td>';
491 print '<td class="tdoverflowmax125">';
492 print $staticcompany->getNomUrl(1, '', 20);
493 print '</td>';
494 print '<td class="nowrap right"><a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$obj->fk_contrat.'&ligne='.$obj->cid.'">';
495 $dateend = $db->jdate($obj->date_fin_validite);
496 print $staticcontratligne->LibStatut($obj->statut, 3, ($dateend && $dateend < $now) ? 1 : 0);
497 print '</a></td>';
498 print "</tr>\n";
499 $i++;
500 }
501 $db->free($resql);
502
503 print "</table></div>";
504} else {
505 dol_print_error($db);
506}
507
508print '<br>';
509
510// Not activated services
511$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,";
512$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,";
513$sql .= " p.rowid as pid, p.ref as pref, p.label as plabel, p.fk_product_type as ptype, p.entity as pentity";
514$sql .= " FROM (".MAIN_DB_PREFIX."contrat as c";
515$sql .= ", ".MAIN_DB_PREFIX."societe as s";
516if (!$user->hasRight('societe', 'client', 'voir')) {
517 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
518}
519$sql .= ", ".MAIN_DB_PREFIX."contratdet as cd";
520$sql .= " ) LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid";
521$sql .= " WHERE c.entity IN (".getEntity('contract', 0).")";
522$sql .= " AND c.statut = 1";
523$sql .= " AND cd.statut = 0";
524$sql .= " AND cd.fk_contrat = c.rowid";
525$sql .= " AND c.fk_soc = s.rowid";
526if (!$user->hasRight('societe', 'client', 'voir')) {
527 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
528}
529if ($socid) {
530 $sql .= " AND s.rowid = ".((int) $socid);
531}
532$sql .= " ORDER BY cd.tms DESC";
533
534$resql = $db->query($sql);
535if ($resql) {
536 $num = $db->num_rows($resql);
537 $i = 0;
538
539 print '<div class="div-table-responsive-no-min">';
540 print '<table class="noborder centpercent">';
541
542 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>';
543 print "</tr>\n";
544
545 while ($i < $num) {
546 $obj = $db->fetch_object($resql);
547
548 $staticcompany->id = $obj->thirdpartyid;
549 $staticcompany->name = $obj->name;
550 $staticcompany->name_alias = $obj->name_alias;
551 $staticcompany->photo = 1;
552 $staticcompany->code_client = $obj->code_client;
553 $staticcompany->code_fournisseur = $obj->code_fournisseur;
554 $staticcompany->code_compta = $obj->code_compta_client;
555 $staticcompany->code_compta_client = $obj->code_compta_client;
556 $staticcompany->code_compta_fournisseur = $obj->code_compta_fournisseur;
557 $staticcompany->client = $obj->client;
558 $staticcompany->fournisseur = $obj->fournisseur;
559
560 $staticcontrat->ref = ($obj->ref ? $obj->ref : $obj->fk_contrat);
561 $staticcontrat->id = $obj->fk_contrat;
562
563 $productstatic->id = $obj->fk_product;
564 $productstatic->type = $obj->ptype;
565 $productstatic->ref = $obj->pref;
566 $productstatic->entity = $obj->pentity;
567
568 print '<tr class="oddeven">';
569
570 print '<td class="nowraponall">';
571 print $staticcontrat->getNomUrl(1, 16);
572 print '</td>';
573 print '<td class="nowrap">';
574 if ($obj->fk_product > 0) {
575 print $productstatic->getNomUrl(1, '', 20);
576 } else {
577 print '<a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$obj->fk_contrat.'">'.img_object($langs->trans("ShowService"), "service");
578 if ($obj->label) {
579 print ' '.dol_trunc($obj->label, 20).'</a>';
580 } else {
581 print '</a> '.dol_trunc($obj->note, 20);
582 }
583 }
584 print '</td>';
585 print '<td class="tdoverflowmax125">';
586 print $staticcompany->getNomUrl(1, '', 20);
587 print '</td>';
588 print '<td width="16" class="right"><a href="line.php?id='.$obj->fk_contrat.'&ligne='.$obj->cid.'">';
589 print $staticcontratligne->LibStatut($obj->statut, 3);
590 print '</a></td>';
591 print "</tr>\n";
592 $i++;
593 }
594
595 $db->free($resql);
596
597 print "</table></div>";
598} else {
599 dol_print_error($db);
600}
601
602print '<br>';
603
604// Expired services
605$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,";
606$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,";
607$sql .= " p.rowid as pid, p.ref as pref, p.label as plabel, p.fk_product_type as ptype, p.entity as pentity";
608$sql .= " FROM (".MAIN_DB_PREFIX."contrat as c";
609$sql .= ", ".MAIN_DB_PREFIX."societe as s";
610if (!$user->hasRight('societe', 'client', 'voir')) {
611 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
612}
613$sql .= ", ".MAIN_DB_PREFIX."contratdet as cd";
614$sql .= " ) LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid";
615$sql .= " WHERE c.entity IN (".getEntity('contract', 0).")";
616$sql .= " AND c.statut = 1";
617$sql .= " AND cd.statut = 4";
618$sql .= " AND cd.date_fin_validite < '".$db->idate($now)."'";
619$sql .= " AND cd.fk_contrat = c.rowid";
620$sql .= " AND c.fk_soc = s.rowid";
621if (!$user->hasRight('societe', 'client', 'voir')) {
622 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
623}
624if ($socid) {
625 $sql .= " AND s.rowid = ".((int) $socid);
626}
627$sql .= " ORDER BY cd.tms DESC";
628
629$resql = $db->query($sql);
630if ($resql) {
631 $num = $db->num_rows($resql);
632 $i = 0;
633
634 print '<div class="div-table-responsive-no-min">';
635 print '<table class="noborder centpercent">';
636
637 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>';
638 print "</tr>\n";
639
640 while ($i < $num) {
641 $obj = $db->fetch_object($resql);
642
643 $staticcompany->id = $obj->thirdpartyid;
644 $staticcompany->name = $obj->name;
645 $staticcompany->name_alias = $obj->name_alias;
646 $staticcompany->photo = 1;
647 $staticcompany->code_client = $obj->code_client;
648 $staticcompany->code_fournisseur = $obj->code_fournisseur;
649 $staticcompany->code_compta = $obj->code_compta_client;
650 $staticcompany->code_compta_client = $obj->code_compta_client;
651 $staticcompany->code_compta_fournisseur = $obj->code_compta_fournisseur;
652 $staticcompany->client = $obj->client;
653 $staticcompany->fournisseur = $obj->fournisseur;
654
655 $staticcontrat->ref = ($obj->ref ? $obj->ref : $obj->fk_contrat);
656 $staticcontrat->id = $obj->fk_contrat;
657
658 $productstatic->id = $obj->fk_product;
659 $productstatic->type = $obj->ptype;
660 $productstatic->ref = $obj->pref;
661 $productstatic->entity = $obj->pentity;
662
663 print '<tr class="oddeven">';
664
665 print '<td class="nowraponall">';
666 print $staticcontrat->getNomUrl(1, 16);
667 print '</td>';
668 print '<td class="nowrap">';
669 if ($obj->fk_product > 0) {
670 print $productstatic->getNomUrl(1, '', 20);
671 } else {
672 print '<a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$obj->fk_contrat.'">'.img_object($langs->trans("ShowService"), "service");
673 if ($obj->label) {
674 print ' '.dol_trunc($obj->label, 20).'</a>';
675 } else {
676 print '</a> '.dol_trunc($obj->note, 20);
677 }
678 }
679 print '</td>';
680 print '<td class="tdoverflowmax125">';
681 print $staticcompany->getNomUrl(1, '', 20);
682 print '</td>';
683 print '<td width="16" class="right"><a href="line.php?id='.$obj->fk_contrat.'&ligne='.$obj->cid.'">';
684 print $staticcontratligne->LibStatut($obj->statut, 3, 1);
685 print '</a></td>';
686 print "</tr>\n";
687 $i++;
688 }
689 $db->free($resql);
690
691 print "</table></div>";
692} else {
693 dol_print_error($db);
694}
695
696
697print '</div></div>';
698
699$parameters = array('user' => $user);
700$reshook = $hookmanager->executeHooks('dashboardContracts', $parameters, $object); // Note that $action and $object may have been modified by hook
701
702llxFooter();
703
704$db->close();
$id
Definition account.php:39
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 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.