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