dolibarr 21.0.0-beta
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 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
27include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
28
29
34{
35 public $boxcode = "lastcontracts";
36 public $boximg = "object_contract";
37 public $boxlabel = "BoxLastContracts";
38 public $depends = array("contrat"); // conf->contrat->enabled
39
46 public function __construct($db, $param)
47 {
48 global $user;
49
50 $this->db = $db;
51
52 $this->hidden = !($user->hasRight('contrat', 'lire'));
53 $this->urltoaddentry = DOL_URL_ROOT.'/contrat/card.php?action=create';
54 $this->msgNoRecords = 'NoRecordedContracts';
55 }
56
63 public function loadBox($max = 5)
64 {
65 global $user, $langs, $conf;
66
67 $this->max = $max;
68
69 include_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
70
71 $this->info_box_head = array(
72 '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>'
73 );
74
75 if ($user->hasRight('contrat', 'lire')) {
76 $contractstatic = new Contrat($this->db);
77 $thirdpartytmp = new Societe($this->db);
78
79 $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,";
80 $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,";
81 $sql .= " c.ref_customer, c.ref_supplier";
82 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."contrat as c";
83 if (!$user->hasRight('societe', 'client', 'voir')) {
84 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
85 }
86 $sql .= " WHERE c.fk_soc = s.rowid";
87 $sql .= " AND c.entity = ".$conf->entity;
88 if (!$user->hasRight('societe', 'client', 'voir')) {
89 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
90 }
91 if ($user->socid) {
92 $sql .= " AND s.rowid = ".((int) $user->socid);
93 }
94 if (getDolGlobalString('MAIN_LASTBOX_ON_OBJECT_DATE')) {
95 $sql .= " ORDER BY c.date_contrat DESC, c.ref DESC ";
96 } else {
97 $sql .= " ORDER BY c.tms DESC, c.ref DESC ";
98 }
99 $sql .= $this->db->plimit($max, 0);
100
101 $resql = $this->db->query($sql);
102 if ($resql) {
103 $num = $this->db->num_rows($resql);
104 $now = dol_now();
105
106 $line = 0;
107
108 $langs->load("contracts");
109
110 while ($line < $num) {
111 $objp = $this->db->fetch_object($resql);
112
113 $datec = $this->db->jdate($objp->datec);
114 $datem = $this->db->jdate($objp->date_modification);
115 $dateterm = $this->db->jdate($objp->fin_validite);
116 $dateclose = $this->db->jdate($objp->date_cloture);
117 $late = '';
118
119 $contractstatic->statut = $objp->fk_statut;
120 $contractstatic->id = $objp->rowid;
121 $contractstatic->ref = $objp->ref;
122 $contractstatic->ref_customer = $objp->ref_customer;
123 $contractstatic->ref_supplier = $objp->ref_supplier;
124 $result = $contractstatic->fetch_lines();
125
126 $thirdpartytmp->name = $objp->name;
127 $thirdpartytmp->id = $objp->socid;
128 $thirdpartytmp->email = $objp->email;
129 $thirdpartytmp->client = $objp->client;
130 $thirdpartytmp->fournisseur = $objp->fournisseur;
131 $thirdpartytmp->code_client = $objp->code_client;
132 $thirdpartytmp->code_fournisseur = $objp->code_fournisseur;
133 $thirdpartytmp->code_compta = $objp->code_compta;
134 $thirdpartytmp->code_compta_client = $objp->code_compta;
135 $thirdpartytmp->code_compta_fournisseur = $objp->code_compta_fournisseur;
136
137 // fin_validite is no more on contract but on services
138 // if ($objp->fk_statut == 1 && $dateterm < ($now - $conf->contrat->cloture->warning_delay)) { $late = img_warning($langs->trans("Late")); }
139
140 $this->info_box_contents[$line][] = array(
141 'td' => 'class="nowraponall"',
142 'text' => $contractstatic->getNomUrl(1),
143 'text2' => $late,
144 'asis' => 1
145 );
146
147 $this->info_box_contents[$line][] = array(
148 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
149 'text' => $thirdpartytmp->getNomUrl(1),
150 'asis' => 1
151 );
152
153 $this->info_box_contents[$line][] = array(
154 'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'"',
155 'text' => dol_print_date($datem, 'day', 'tzuserrel'),
156 );
157
158 $this->info_box_contents[$line][] = array(
159 'td' => 'class="nowraponall right"',
160 'text' => $contractstatic->getLibStatut(7),
161 'asis' => 1,
162 );
163
164 $line++;
165 }
166
167 // if ($num == 0) {
168 // $this->info_box_contents[$line][0] = array(
169 // 'td' => 'class="center"',
170 // 'text' => '<span class="opacitymedium">'.$langs->trans("NoRecordedContracts").'</span>'
171 // );
172 // }
173
174 $this->db->free($resql);
175 } else {
176 $this->info_box_contents[0][0] = array(
177 'td' => '',
178 'maxlength' => 500,
179 'text' => ($this->db->error().' sql='.$sql),
180 );
181 }
182 } else {
183 $this->info_box_contents[0][0] = array(
184 'td' => 'class="nohover left"',
185 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
186 );
187 }
188 }
189
190
191
200 public function showBox($head = null, $contents = null, $nooutput = 0)
201 {
202 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
203 }
204}
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 a 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...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79