dolibarr 21.0.0-alpha
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
45 public function __construct($db, $param)
46 {
47 global $user;
48
49 $this->db = $db;
50
51 $this->hidden = !($user->hasRight('contrat', 'lire'));
52 }
53
60 public function loadBox($max = 5)
61 {
62 global $user, $langs, $conf;
63
64 $this->max = $max;
65
66 include_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
67
68 $this->info_box_head = array(
69 'text' => '<span class="valignmiddle">'.$langs->trans("BoxTitleLastContracts", $max).'</span><a class="paddingleft valignmiddle" href="'.DOL_URL_ROOT.'/contrat/list.php?sortfield=c.tms&sortorder=DESC"><span class="badge">...</span></a>'
70 );
71
72 if ($user->hasRight('contrat', 'lire')) {
73 $contractstatic = new Contrat($this->db);
74 $thirdpartytmp = new Societe($this->db);
75
76 $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,";
77 $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,";
78 $sql .= " c.ref_customer, c.ref_supplier";
79 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."contrat as c";
80 if (!$user->hasRight('societe', 'client', 'voir')) {
81 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
82 }
83 $sql .= " WHERE c.fk_soc = s.rowid";
84 $sql .= " AND c.entity = ".$conf->entity;
85 if (!$user->hasRight('societe', 'client', 'voir')) {
86 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
87 }
88 if ($user->socid) {
89 $sql .= " AND s.rowid = ".((int) $user->socid);
90 }
91 if (getDolGlobalString('MAIN_LASTBOX_ON_OBJECT_DATE')) {
92 $sql .= " ORDER BY c.date_contrat DESC, c.ref DESC ";
93 } else {
94 $sql .= " ORDER BY c.tms DESC, c.ref DESC ";
95 }
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 $now = dol_now();
102
103 $line = 0;
104
105 $langs->load("contracts");
106
107 while ($line < $num) {
108 $objp = $this->db->fetch_object($resql);
109
110 $datec = $this->db->jdate($objp->datec);
111 $datem = $this->db->jdate($objp->date_modification);
112 $dateterm = $this->db->jdate($objp->fin_validite);
113 $dateclose = $this->db->jdate($objp->date_cloture);
114 $late = '';
115
116 $contractstatic->statut = $objp->fk_statut;
117 $contractstatic->id = $objp->rowid;
118 $contractstatic->ref = $objp->ref;
119 $contractstatic->ref_customer = $objp->ref_customer;
120 $contractstatic->ref_supplier = $objp->ref_supplier;
121 $result = $contractstatic->fetch_lines();
122
123 $thirdpartytmp->name = $objp->name;
124 $thirdpartytmp->id = $objp->socid;
125 $thirdpartytmp->email = $objp->email;
126 $thirdpartytmp->client = $objp->client;
127 $thirdpartytmp->fournisseur = $objp->fournisseur;
128 $thirdpartytmp->code_client = $objp->code_client;
129 $thirdpartytmp->code_fournisseur = $objp->code_fournisseur;
130 $thirdpartytmp->code_compta = $objp->code_compta;
131 $thirdpartytmp->code_compta_fournisseur = $objp->code_compta_fournisseur;
132
133 // fin_validite is no more on contract but on services
134 // if ($objp->fk_statut == 1 && $dateterm < ($now - $conf->contrat->cloture->warning_delay)) { $late = img_warning($langs->trans("Late")); }
135
136 $this->info_box_contents[$line][] = array(
137 'td' => 'class="nowraponall"',
138 'text' => $contractstatic->getNomUrl(1),
139 'text2'=> $late,
140 'asis'=>1
141 );
142
143 $this->info_box_contents[$line][] = array(
144 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
145 'text' => $thirdpartytmp->getNomUrl(1),
146 'asis'=>1
147 );
148
149 $this->info_box_contents[$line][] = array(
150 'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'"',
151 'text' => dol_print_date($datem, 'day', 'tzuserrel'),
152 );
153
154 $this->info_box_contents[$line][] = array(
155 'td' => 'class="nowraponall right"',
156 'text' => $contractstatic->getLibStatut(7),
157 'asis'=>1,
158 );
159
160 $line++;
161 }
162
163 if ($num == 0) {
164 $this->info_box_contents[$line][0] = array(
165 'td' => 'class="center"',
166 'text'=> '<span class="opacitymedium">'.$langs->trans("NoRecordedContracts").'</span>'
167 );
168 }
169
170 $this->db->free($resql);
171 } else {
172 $this->info_box_contents[0][0] = array(
173 'td' => '',
174 'maxlength'=>500,
175 'text' => ($this->db->error().' sql='.$sql),
176 );
177 }
178 } else {
179 $this->info_box_contents[0][0] = array(
180 'td' => 'class="nohover left"',
181 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
182 );
183 }
184 }
185
194 public function showBox($head = null, $contents = null, $nooutput = 0)
195 {
196 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
197 }
198}
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_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).
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...