dolibarr 19.0.3
box_contracts.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2010 Regis Houssin <regis.houssin@inodbox.com>
3 * Copyright (C) 2015 Frederic France <frederic.france@free.fr>
4 * Copyright (C) 2016-2017 Laurent Destailleur <eldy@users.sourceforge.net>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
26include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
27
28
33{
34 public $boxcode = "lastcontracts";
35 public $boximg = "object_contract";
36 public $boxlabel = "BoxLastContracts";
37 public $depends = array("contrat"); // conf->contrat->enabled
38
42 public $db;
43
44 public $param;
45
46 public $info_box_head = array();
47 public $info_box_contents = array();
48
49
56 public function __construct($db, $param)
57 {
58 global $user;
59
60 $this->db = $db;
61
62 $this->hidden = !($user->hasRight('contrat', 'lire'));
63 }
64
71 public function loadBox($max = 5)
72 {
73 global $user, $langs, $conf;
74
75 $this->max = $max;
76
77 include_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
78
79 $this->info_box_head = array('text' => $langs->trans("BoxTitleLastContracts", $max));
80
81 if ($user->hasRight('contrat', 'lire')) {
82 $contractstatic = new Contrat($this->db);
83 $thirdpartytmp = new Societe($this->db);
84
85 $sql = "SELECT 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 .= " c.rowid, c.ref, c.statut as fk_statut, c.date_contrat, c.datec, c.tms as date_modification, c.fin_validite, c.date_cloture,";
87 $sql .= " c.ref_customer, c.ref_supplier";
88 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."contrat as c";
89 if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) {
90 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
91 }
92 $sql .= " WHERE c.fk_soc = s.rowid";
93 $sql .= " AND c.entity = ".$conf->entity;
94 if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) {
95 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
96 }
97 if ($user->socid) {
98 $sql .= " AND s.rowid = ".((int) $user->socid);
99 }
100 if (getDolGlobalString('MAIN_LASTBOX_ON_OBJECT_DATE')) {
101 $sql .= " ORDER BY c.date_contrat DESC, c.ref DESC ";
102 } else {
103 $sql .= " ORDER BY c.tms DESC, c.ref DESC ";
104 }
105 $sql .= $this->db->plimit($max, 0);
106
107 $resql = $this->db->query($sql);
108 if ($resql) {
109 $num = $this->db->num_rows($resql);
110 $now = dol_now();
111
112 $line = 0;
113
114 $langs->load("contracts");
115
116 while ($line < $num) {
117 $objp = $this->db->fetch_object($resql);
118
119 $datec = $this->db->jdate($objp->datec);
120 $datem = $this->db->jdate($objp->date_modification);
121 $dateterm = $this->db->jdate($objp->fin_validite);
122 $dateclose = $this->db->jdate($objp->date_cloture);
123 $late = '';
124
125 $contractstatic->statut = $objp->fk_statut;
126 $contractstatic->id = $objp->rowid;
127 $contractstatic->ref = $objp->ref;
128 $contractstatic->ref_customer = $objp->ref_customer;
129 $contractstatic->ref_supplier = $objp->ref_supplier;
130 $result = $contractstatic->fetch_lines();
131
132 $thirdpartytmp->name = $objp->name;
133 $thirdpartytmp->id = $objp->socid;
134 $thirdpartytmp->email = $objp->email;
135 $thirdpartytmp->client = $objp->client;
136 $thirdpartytmp->fournisseur = $objp->fournisseur;
137 $thirdpartytmp->code_client = $objp->code_client;
138 $thirdpartytmp->code_fournisseur = $objp->code_fournisseur;
139 $thirdpartytmp->code_compta = $objp->code_compta;
140 $thirdpartytmp->code_compta_fournisseur = $objp->code_compta_fournisseur;
141
142 // fin_validite is no more on contract but on services
143 // if ($objp->fk_statut == 1 && $dateterm < ($now - $conf->contrat->cloture->warning_delay)) { $late = img_warning($langs->trans("Late")); }
144
145 $this->info_box_contents[$line][] = array(
146 'td' => 'class="nowraponall"',
147 'text' => $contractstatic->getNomUrl(1),
148 'text2'=> $late,
149 'asis'=>1
150 );
151
152 $this->info_box_contents[$line][] = array(
153 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
154 'text' => $thirdpartytmp->getNomUrl(1),
155 'asis'=>1
156 );
157
158 $this->info_box_contents[$line][] = array(
159 'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'"',
160 'text' => dol_print_date($datem, 'day', 'tzuserrel'),
161 );
162
163 $this->info_box_contents[$line][] = array(
164 'td' => 'class="nowraponall right"',
165 'text' => $contractstatic->getLibStatut(7),
166 'asis'=>1,
167 );
168
169 $line++;
170 }
171
172 if ($num == 0) {
173 $this->info_box_contents[$line][0] = array(
174 'td' => 'class="center"',
175 'text'=> '<span class="opacitymedium">'.$langs->trans("NoRecordedContracts").'</span>'
176 );
177 }
178
179 $this->db->free($resql);
180 } else {
181 $this->info_box_contents[0][0] = array(
182 'td' => '',
183 'maxlength'=>500,
184 'text' => ($this->db->error().' sql='.$sql),
185 );
186 }
187 } else {
188 $this->info_box_contents[0][0] = array(
189 'td' => 'class="nohover left"',
190 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
191 );
192 }
193 }
194
203 public function showBox($head = null, $contents = null, $nooutput = 0)
204 {
205 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
206 }
207}
Class to manage contracts.
Class ModeleBoxes.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage the box to show last contracts.
__construct($db, $param)
Constructor.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
loadBox($max=5)
Load data for box to show them later.
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.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
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...