dolibarr 19.0.3
box_services_expired.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2011 Laurent Destailleur <eldy@users.sourceforge.net>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
24include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
25
26
31{
32 public $boxcode = "expiredservices"; // id of box
33 public $boximg = "object_contract";
34 public $boxlabel = "BoxOldestExpiredServices";
35 public $depends = array("contrat"); // conf->propal->enabled
36
40 public $db;
41
42 public $param;
43
44 public $info_box_head = array();
45 public $info_box_contents = array();
46
47
54 public function __construct($db, $param)
55 {
56 global $user;
57
58 $this->db = $db;
59
60 $this->hidden = !($user->hasRight('contrat', 'lire'));
61 }
62
69 public function loadBox($max = 5)
70 {
71 global $user, $langs, $conf;
72
73 $this->max = $max;
74
75 include_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
76
77 $now = dol_now();
78
79 $this->info_box_head = array('text' => $langs->trans("BoxLastExpiredServices", $max));
80
81 if ($user->hasRight('contrat', 'lire')) {
82 // Select contracts with at least one expired service
83 $sql = "SELECT ";
84 $sql .= " c.rowid, c.ref, c.statut as fk_statut, c.date_contrat, c.ref_customer, c.ref_supplier,";
85 $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,";
86 $sql .= " MIN(cd.date_fin_validite) as date_line, COUNT(cd.rowid) as nb_services";
87 $sql .= " FROM ".MAIN_DB_PREFIX."contrat as c, ".MAIN_DB_PREFIX."societe s, ".MAIN_DB_PREFIX."contratdet as cd";
88 if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) {
89 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
90 }
91 $sql .= " WHERE cd.statut = 4 AND cd.date_fin_validite <= '".$this->db->idate($now)."'";
92 $sql .= " AND c.entity = ".$conf->entity;
93 $sql .= " AND c.fk_soc=s.rowid AND cd.fk_contrat=c.rowid AND c.statut > 0";
94 if ($user->socid) {
95 $sql .= ' AND c.fk_soc = '.((int) $user->socid);
96 }
97 if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) {
98 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
99 }
100 $sql .= " GROUP BY c.rowid, c.ref, c.statut, c.date_contrat, c.ref_customer, c.ref_supplier, s.nom, s.rowid";
101 $sql .= ", s.email, s.client, s.fournisseur, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur";
102 $sql .= " ORDER BY date_line ASC";
103 $sql .= $this->db->plimit($max, 0);
104
105 $resql = $this->db->query($sql);
106 if ($resql) {
107 $num = $this->db->num_rows($resql);
108
109 $i = 0;
110
111 $thirdpartytmp = new Societe($this->db);
112 $contract = new Contrat($this->db);
113
114 while ($i < $num) {
115 $late = '';
116
117 $objp = $this->db->fetch_object($resql);
118
119 $thirdpartytmp->name = $objp->name;
120 $thirdpartytmp->id = $objp->socid;
121 $thirdpartytmp->email = $objp->email;
122 $thirdpartytmp->client = $objp->client;
123 $thirdpartytmp->fournisseur = $objp->fournisseur;
124 $thirdpartytmp->code_client = $objp->code_client;
125 $thirdpartytmp->code_fournisseur = $objp->code_fournisseur;
126 $thirdpartytmp->code_compta = $objp->code_compta;
127 $thirdpartytmp->code_compta_fournisseur = $objp->code_compta_fournisseur;
128
129 $contract->id = $objp->rowid;
130 $contract->ref = $objp->ref;
131 $contract->statut = $objp->fk_statut;
132 $contract->ref_customer = $objp->ref_customer;
133 $contract->ref_supplier = $objp->ref_supplier;
134
135 $dateline = $this->db->jdate($objp->date_line);
136 if (($dateline + $conf->contrat->services->expires->warning_delay) < $now) {
137 $late = img_warning($langs->trans("Late"));
138 }
139
140 $this->info_box_contents[$i][] = array(
141 'td' => 'class="nowraponall"',
142 'text' => $contract->getNomUrl(1),
143 'asis' => 1
144 );
145
146 $this->info_box_contents[$i][] = array(
147 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone left"',
148 'text' => $thirdpartytmp->getNomUrl(1, 'customer'),
149 'asis' => 1
150 );
151
152 $this->info_box_contents[$i][] = array(
153 'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateEndPlanned").': '.dol_print_date($dateline, 'dayhour', 'tzuserrel')).'"',
154 'text' => dol_print_date($dateline, 'day', 'tzuserrel'),
155 'text2'=> $late,
156 );
157
158 $this->info_box_contents[$i][] = array(
159 'td' => 'class="right"',
160 'text' => $objp->nb_services,
161 );
162
163
164 $i++;
165 }
166
167 if ($num == 0) {
168 $langs->load("contracts");
169 $this->info_box_contents[$i][] = array(
170 'td' => 'class="nohover center"',
171 'text' => '<span class="opacitymedium">'.$langs->trans("NoExpiredServices").'</span>'
172 );
173 }
174
175 $this->db->free($resql);
176 } else {
177 $this->info_box_contents[0][] = array(
178 'td' => '',
179 'maxlength'=>500,
180 'text' => ($this->db->error().' sql='.$sql),
181 );
182 }
183 } else {
184 $this->info_box_contents[0][0] = array(
185 'td' => 'class="nohover left"',
186 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
187 );
188 }
189 }
190
199 public function showBox($head = null, $contents = null, $nooutput = 0)
200 {
201 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
202 }
203}
Class to manage contracts.
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_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
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...