dolibarr 20.0.0
box_services_contracts.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2005-2017 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2011 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2017 Nicolas Zabouri <info@inovea-conseil.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 = "lastproductsincontract";
36 public $boximg = "object_product";
37 public $boxlabel = "BoxLastProductsInContract";
38 public $depends = array("service", "contrat");
39
46 public function __construct($db, $param)
47 {
48 global $user;
49
50 $this->db = $db;
51
52 $this->hidden = !($user->hasRight('service', 'lire') && $user->hasRight('contrat', 'lire'));
53 }
54
61 public function loadBox($max = 5)
62 {
63 global $user, $langs, $conf;
64
65 $this->max = $max;
66
67 include_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
68
69 $form = new Form($this->db);
70
71 $this->info_box_head = array(
72 'text' => $langs->trans("BoxLastProductsInContract", $max).'<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('service', 'lire') && $user->hasRight('contrat', 'lire')) {
76 $contractstatic = new Contrat($this->db);
77 $contractlinestatic = new ContratLigne($this->db);
78 $thirdpartytmp = new Societe($this->db);
79 $productstatic = new Product($this->db);
80
81 $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,";
82 $sql .= " c.rowid, c.ref, c.statut as contract_status, c.ref_customer, c.ref_supplier,";
83 $sql .= " cd.rowid as cdid, cd.label, cd.description, cd.tms as datem, cd.statut as contractline_status, cd.product_type as type, cd.date_fin_validite as date_line,";
84 $sql .= " p.rowid as product_id, p.ref as product_ref, p.label as product_label, p.fk_product_type as product_type, p.entity as product_entity, p.tobuy, p.tosell";
85 $sql .= " FROM (".MAIN_DB_PREFIX."societe as s";
86 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."contrat as c ON s.rowid = c.fk_soc";
87 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."contratdet as cd ON c.rowid = cd.fk_contrat";
88 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid";
89 if (!$user->hasRight('societe', 'client', 'voir')) {
90 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
91 }
92 $sql .= ")";
93 $sql .= " WHERE c.entity = ".$conf->entity;
94 if ($user->socid) {
95 $sql .= " AND s.rowid = ".((int) $user->socid);
96 }
97 $sql .= $this->db->order("c.tms", "DESC");
98 $sql .= $this->db->plimit($max, 0);
99
100 $result = $this->db->query($sql);
101 if ($result) {
102 $num = $this->db->num_rows($result);
103 $now = dol_now();
104
105 $i = 0;
106
107 while ($i < $num) {
108 $late = '';
109
110 $objp = $this->db->fetch_object($result);
111 $datem = $this->db->jdate($objp->datem);
112
113 $contractlinestatic->id = $objp->cdid;
114 $contractlinestatic->fk_contrat = $objp->rowid;
115 $contractlinestatic->label = $objp->label;
116 $contractlinestatic->description = $objp->description;
117 $contractlinestatic->type = $objp->type;
118 $contractlinestatic->fk_product = $objp->product_id;
119 $contractlinestatic->product_ref = $objp->product_ref;
120 $contractlinestatic->product_type = $objp->product_type;
121 $contractlinestatic->statut = $objp->contractline_status;
122
123 $contractstatic->id = $objp->rowid;
124 $contractstatic->ref = $objp->ref;
125 $contractstatic->ref_customer = $objp->ref_customer;
126 $contractstatic->ref_supplier = $objp->ref_supplier;
127 $contractstatic->statut = $objp->contract_status;
128 $contractstatic->status = $objp->contract_status;
129
130 $thirdpartytmp->name = $objp->name;
131 $thirdpartytmp->id = $objp->socid;
132 $thirdpartytmp->email = $objp->email;
133 $thirdpartytmp->client = $objp->client;
134 $thirdpartytmp->fournisseur = $objp->fournisseur;
135 $thirdpartytmp->code_client = $objp->code_client;
136 $thirdpartytmp->code_fournisseur = $objp->code_fournisseur;
137 $thirdpartytmp->code_compta = $objp->code_compta;
138 $thirdpartytmp->code_compta_client = $objp->code_compta;
139 $thirdpartytmp->code_compta_fournisseur = $objp->code_compta_fournisseur;
140
141 $dateline = $this->db->jdate($objp->date_line);
142 if ($contractstatic->status == Contrat::STATUS_VALIDATED && $objp->contractline_status == ContratLigne::STATUS_OPEN && !empty($dateline) && ($dateline + $conf->contrat->services->expires->warning_delay) < $now) {
143 $late = img_warning($langs->trans("Late"));
144 }
145
146 // Label
147 if ($objp->product_id > 0) {
148 $productstatic->id = $objp->product_id;
149 $productstatic->type = $objp->product_type;
150 $productstatic->ref = $objp->product_ref;
151 $productstatic->entity = $objp->product_entity;
152 $productstatic->label = $objp->product_label;
153 $productstatic->status = $objp->tosell;
154 $productstatic->status_buy = $objp->tobuy;
155
156 $text = $productstatic->getNomUrl(1, '', 20);
157 if ($objp->product_label) {
158 $text .= ' - ';
159 //$productstatic->ref=$objp->label;
160 //$text .= $productstatic->getNomUrl(0,'',16);
161 $text .= $objp->product_label;
162 }
163 $description = $objp->description;
164
165 $s = $form->textwithtooltip($text, $description, 3, '', '', '', 0, '');
166 } else {
167 $s = img_object($langs->trans("ShowProductOrService"), ($objp->product_type ? 'service' : 'product')).' '.dol_htmlentitiesbr($objp->description);
168 }
169
170
171 $this->info_box_contents[$i][] = array(
172 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
173 'text' => $s,
174 'asis' => 1
175 );
176
177 $this->info_box_contents[$i][] = array(
178 'td' => 'class="nowraponall"',
179 'text' => $contractstatic->getNomUrl(1),
180 'asis' => 1
181 );
182
183 $this->info_box_contents[$i][] = array(
184 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
185 'text' => $thirdpartytmp->getNomUrl(1),
186 'asis' => 1
187 );
188
189 $this->info_box_contents[$i][] = array(
190 'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'"',
191 'text' => dol_print_date($datem, 'day', 'tzuserrel'),
192 'text2'=> $late,
193 );
194
195 $this->info_box_contents[$i][] = array(
196 'td' => 'class="right" width="18"',
197 'text' => $contractlinestatic->getLibStatut(3)
198 );
199
200 $i++;
201 }
202 if ($num == 0) {
203 $this->info_box_contents[$i][0] = array(
204 'td' => 'class="center"',
205 'text'=> '<span class="opacitymedium">'.$langs->trans("NoContractedProducts").'</span>'
206 );
207 }
208
209 $this->db->free($result);
210 } else {
211 $this->info_box_contents[0][0] = array(
212 'td' => '',
213 'maxlength' => 500,
214 'text' => ($this->db->error().' sql='.$sql),
215 );
216 }
217 } else {
218 $this->info_box_contents[0][0] = array(
219 'td' => 'class="nohover left"',
220 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
221 );
222 }
223 }
224
233 public function showBox($head = null, $contents = null, $nooutput = 0)
234 {
235 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
236 }
237}
Class to manage contracts.
Class to manage lines of contracts.
Class to manage generation of HTML components Only common components must be here.
Class ModeleBoxes.
Class to manage products or services.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage the box to show last contracted products/services lines.
loadBox($max=5)
Load data into info_box_contents array to show array later.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
__construct($db, $param)
Constructor.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
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_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
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...