dolibarr 21.0.0-alpha
box_services_expired.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2011 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
25include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
26
27
32{
33 public $boxcode = "expiredservices"; // id of box
34 public $boximg = "object_contract";
35 public $boxlabel = "BoxOldestExpiredServices";
36 public $depends = array("contrat"); // conf->propal->enabled
37
44 public function __construct($db, $param)
45 {
46 global $user;
47
48 $this->db = $db;
49
50 $this->hidden = !($user->hasRight('contrat', 'lire'));
51
52 $this->urltoaddentry = DOL_URL_ROOT.'/contrat/card.php?action=create';
53 $this->msgNoRecords = 'NoExpiredServices';
54 }
55
62 public function loadBox($max = 5)
63 {
64 global $user, $langs, $conf;
65
66 $this->max = $max;
67
68 include_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
69
70 $now = dol_now();
71
72 $this->info_box_head = array('text' => $langs->trans("BoxLastExpiredServices", $max));
73
74 if ($user->hasRight('contrat', 'lire')) {
75 // Select contracts with at least one expired service
76 $sql = "SELECT ";
77 $sql .= " c.rowid, c.ref, c.statut as fk_statut, c.date_contrat, c.ref_customer, c.ref_supplier,";
78 $sql .= " s.nom as name, s.rowid as socid, s.email, s.client, s.fournisseur, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur,";
79 $sql .= " MIN(cd.date_fin_validite) as date_line, COUNT(cd.rowid) as nb_services";
80 $sql .= " FROM ".MAIN_DB_PREFIX."contrat as c, ".MAIN_DB_PREFIX."societe s, ".MAIN_DB_PREFIX."contratdet as cd";
81 if (!$user->hasRight('societe', 'client', 'voir')) {
82 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
83 }
84 $sql .= " WHERE cd.statut = 4 AND cd.date_fin_validite <= '".$this->db->idate($now)."'";
85 $sql .= " AND c.entity = ".$conf->entity;
86 $sql .= " AND c.fk_soc=s.rowid AND cd.fk_contrat=c.rowid AND c.statut > 0";
87 if ($user->socid) {
88 $sql .= ' AND c.fk_soc = '.((int) $user->socid);
89 }
90 if (!$user->hasRight('societe', 'client', 'voir')) {
91 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
92 }
93 $sql .= " GROUP BY c.rowid, c.ref, c.statut, c.date_contrat, c.ref_customer, c.ref_supplier, s.nom, s.rowid";
94 $sql .= ", s.email, s.client, s.fournisseur, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur";
95 $sql .= " ORDER BY date_line ASC";
96 $sql .= $this->db->plimit($max, 0);
97
98 $resql = $this->db->query($sql);
99 if ($resql) {
100 $num = $this->db->num_rows($resql);
101
102 $i = 0;
103
104 $thirdpartytmp = new Societe($this->db);
105 $contract = new Contrat($this->db);
106
107 while ($i < $num) {
108 $late = '';
109
110 $objp = $this->db->fetch_object($resql);
111
112 $thirdpartytmp->name = $objp->name;
113 $thirdpartytmp->id = $objp->socid;
114 $thirdpartytmp->email = $objp->email;
115 $thirdpartytmp->client = $objp->client;
116 $thirdpartytmp->fournisseur = $objp->fournisseur;
117 $thirdpartytmp->code_client = $objp->code_client;
118 $thirdpartytmp->code_fournisseur = $objp->code_fournisseur;
119 $thirdpartytmp->code_compta = $objp->code_compta;
120 $thirdpartytmp->code_compta_client = $objp->code_compta;
121 $thirdpartytmp->code_compta_fournisseur = $objp->code_compta_fournisseur;
122
123 $contract->id = $objp->rowid;
124 $contract->ref = $objp->ref;
125 $contract->statut = $objp->fk_statut;
126 $contract->ref_customer = $objp->ref_customer;
127 $contract->ref_supplier = $objp->ref_supplier;
128
129 $dateline = $this->db->jdate($objp->date_line);
130 if (($dateline + $conf->contrat->services->expires->warning_delay) < $now) {
131 $late = img_warning($langs->trans("Late"));
132 }
133
134 $this->info_box_contents[$i][] = array(
135 'td' => 'class="nowraponall"',
136 'text' => $contract->getNomUrl(1),
137 'asis' => 1
138 );
139
140 $this->info_box_contents[$i][] = array(
141 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone left"',
142 'text' => $thirdpartytmp->getNomUrl(1, 'customer'),
143 'asis' => 1
144 );
145
146 $this->info_box_contents[$i][] = array(
147 'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateEndPlanned").': '.dol_print_date($dateline, 'dayhour', 'tzuserrel')).'"',
148 'text' => dol_print_date($dateline, 'day', 'tzuserrel'),
149 'text2' => $late,
150 );
151
152 $this->info_box_contents[$i][] = array(
153 'td' => 'class="right"',
154 'text' => $objp->nb_services,
155 );
156
157
158 $i++;
159 }
160
161
162 $this->db->free($resql);
163 } else {
164 $this->info_box_contents[0][] = array(
165 'td' => '',
166 'maxlength' => 500,
167 'text' => ($this->db->error().' sql='.$sql),
168 );
169 }
170 } else {
171 $this->info_box_contents[0][0] = array(
172 'td' => 'class="nohover left"',
173 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
174 );
175 }
176 }
177
178
179
188 public function showBox($head = null, $contents = null, $nooutput = 0)
189 {
190 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
191 }
192}
Class ModeleBoxes.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage the box to show expired services.
loadBox($max=5)
Load data for box to show them later.
__construct($db, $param)
Constructor.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
dol_now($mode='auto')
Return date for now.
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).
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...