dolibarr 20.0.0
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
43 public function __construct($db, $param)
44 {
45 global $user;
46
47 $this->db = $db;
48
49 $this->hidden = !($user->hasRight('contrat', 'lire'));
50 }
51
58 public function loadBox($max = 5)
59 {
60 global $user, $langs, $conf;
61
62 $this->max = $max;
63
64 include_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
65
66 $now = dol_now();
67
68 $this->info_box_head = array('text' => $langs->trans("BoxLastExpiredServices", $max));
69
70 if ($user->hasRight('contrat', 'lire')) {
71 // Select contracts with at least one expired service
72 $sql = "SELECT ";
73 $sql .= " c.rowid, c.ref, c.statut as fk_statut, c.date_contrat, c.ref_customer, c.ref_supplier,";
74 $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,";
75 $sql .= " MIN(cd.date_fin_validite) as date_line, COUNT(cd.rowid) as nb_services";
76 $sql .= " FROM ".MAIN_DB_PREFIX."contrat as c, ".MAIN_DB_PREFIX."societe s, ".MAIN_DB_PREFIX."contratdet as cd";
77 if (!$user->hasRight('societe', 'client', 'voir')) {
78 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
79 }
80 $sql .= " WHERE cd.statut = 4 AND cd.date_fin_validite <= '".$this->db->idate($now)."'";
81 $sql .= " AND c.entity = ".$conf->entity;
82 $sql .= " AND c.fk_soc=s.rowid AND cd.fk_contrat=c.rowid AND c.statut > 0";
83 if ($user->socid) {
84 $sql .= ' AND c.fk_soc = '.((int) $user->socid);
85 }
86 if (!$user->hasRight('societe', 'client', 'voir')) {
87 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
88 }
89 $sql .= " GROUP BY c.rowid, c.ref, c.statut, c.date_contrat, c.ref_customer, c.ref_supplier, s.nom, s.rowid";
90 $sql .= ", s.email, s.client, s.fournisseur, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur";
91 $sql .= " ORDER BY date_line ASC";
92 $sql .= $this->db->plimit($max, 0);
93
94 $resql = $this->db->query($sql);
95 if ($resql) {
96 $num = $this->db->num_rows($resql);
97
98 $i = 0;
99
100 $thirdpartytmp = new Societe($this->db);
101 $contract = new Contrat($this->db);
102
103 while ($i < $num) {
104 $late = '';
105
106 $objp = $this->db->fetch_object($resql);
107
108 $thirdpartytmp->name = $objp->name;
109 $thirdpartytmp->id = $objp->socid;
110 $thirdpartytmp->email = $objp->email;
111 $thirdpartytmp->client = $objp->client;
112 $thirdpartytmp->fournisseur = $objp->fournisseur;
113 $thirdpartytmp->code_client = $objp->code_client;
114 $thirdpartytmp->code_fournisseur = $objp->code_fournisseur;
115 $thirdpartytmp->code_compta = $objp->code_compta;
116 $thirdpartytmp->code_compta_fournisseur = $objp->code_compta_fournisseur;
117
118 $contract->id = $objp->rowid;
119 $contract->ref = $objp->ref;
120 $contract->statut = $objp->fk_statut;
121 $contract->ref_customer = $objp->ref_customer;
122 $contract->ref_supplier = $objp->ref_supplier;
123
124 $dateline = $this->db->jdate($objp->date_line);
125 if (($dateline + $conf->contrat->services->expires->warning_delay) < $now) {
126 $late = img_warning($langs->trans("Late"));
127 }
128
129 $this->info_box_contents[$i][] = array(
130 'td' => 'class="nowraponall"',
131 'text' => $contract->getNomUrl(1),
132 'asis' => 1
133 );
134
135 $this->info_box_contents[$i][] = array(
136 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone left"',
137 'text' => $thirdpartytmp->getNomUrl(1, 'customer'),
138 'asis' => 1
139 );
140
141 $this->info_box_contents[$i][] = array(
142 'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateEndPlanned").': '.dol_print_date($dateline, 'dayhour', 'tzuserrel')).'"',
143 'text' => dol_print_date($dateline, 'day', 'tzuserrel'),
144 'text2'=> $late,
145 );
146
147 $this->info_box_contents[$i][] = array(
148 'td' => 'class="right"',
149 'text' => $objp->nb_services,
150 );
151
152
153 $i++;
154 }
155
156 if ($num == 0) {
157 $langs->load("contracts");
158 $this->info_box_contents[$i][] = array(
159 'td' => 'class="nohover center"',
160 'text' => '<span class="opacitymedium">'.$langs->trans("NoExpiredServices").'</span>'
161 );
162 }
163
164 $this->db->free($resql);
165 } else {
166 $this->info_box_contents[0][] = array(
167 'td' => '',
168 'maxlength'=>500,
169 'text' => ($this->db->error().' sql='.$sql),
170 );
171 }
172 } else {
173 $this->info_box_contents[0][0] = array(
174 'td' => 'class="nohover left"',
175 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
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 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_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...