dolibarr 21.0.0-beta
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 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
28include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
29
30
35{
36 public $boxcode = "lastproductsincontract";
37 public $boximg = "object_product";
38 public $boxlabel = "BoxLastProductsInContract";
39 public $depends = array("service", "contrat");
40
47 public function __construct($db, $param)
48 {
49 global $user;
50
51 $this->db = $db;
52
53 $this->hidden = !($user->hasRight('service', 'lire') && $user->hasRight('contrat', 'lire'));
54
55 $this->urltoaddentry = DOL_URL_ROOT.'/contrat/card.php?action=create';
56 $this->msgNoRecords = 'NoContractedProducts';
57 }
58
65 public function loadBox($max = 5)
66 {
67 global $user, $langs, $conf;
68
69 $this->max = $max;
70
71 include_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
72
73 $form = new Form($this->db);
74
75 $this->info_box_head = array(
76 '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>'
77 );
78
79 if ($user->hasRight('service', 'lire') && $user->hasRight('contrat', 'lire')) {
80 $contractstatic = new Contrat($this->db);
81 $contractlinestatic = new ContratLigne($this->db);
82 $thirdpartytmp = new Societe($this->db);
83 $productstatic = new Product($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 contract_status, c.ref_customer, c.ref_supplier,";
87 $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,";
88 $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";
89 $sql .= " FROM (".MAIN_DB_PREFIX."societe as s";
90 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."contrat as c ON s.rowid = c.fk_soc";
91 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."contratdet as cd ON c.rowid = cd.fk_contrat";
92 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid";
93 if (!$user->hasRight('societe', 'client', 'voir')) {
94 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
95 }
96 $sql .= ")";
97 $sql .= " WHERE c.entity = ".$conf->entity;
98 if ($user->socid) {
99 $sql .= " AND s.rowid = ".((int) $user->socid);
100 }
101 $sql .= $this->db->order("c.tms", "DESC");
102 $sql .= $this->db->plimit($max, 0);
103
104 $result = $this->db->query($sql);
105 if ($result) {
106 $num = $this->db->num_rows($result);
107 $now = dol_now();
108
109 $i = 0;
110
111 while ($i < $num) {
112 $late = '';
113
114 $objp = $this->db->fetch_object($result);
115 $datem = $this->db->jdate($objp->datem);
116
117 $contractlinestatic->id = $objp->cdid;
118 $contractlinestatic->fk_contrat = $objp->rowid;
119 $contractlinestatic->label = $objp->label;
120 $contractlinestatic->description = $objp->description;
121 $contractlinestatic->type = $objp->type;
122 $contractlinestatic->fk_product = $objp->product_id;
123 $contractlinestatic->product_ref = $objp->product_ref;
124 $contractlinestatic->product_type = $objp->product_type;
125 $contractlinestatic->statut = $objp->contractline_status;
126
127 $contractstatic->id = $objp->rowid;
128 $contractstatic->ref = $objp->ref;
129 $contractstatic->ref_customer = $objp->ref_customer;
130 $contractstatic->ref_supplier = $objp->ref_supplier;
131 $contractstatic->statut = $objp->contract_status;
132 $contractstatic->status = $objp->contract_status;
133
134 $thirdpartytmp->name = $objp->name;
135 $thirdpartytmp->id = $objp->socid;
136 $thirdpartytmp->email = $objp->email;
137 $thirdpartytmp->client = $objp->client;
138 $thirdpartytmp->fournisseur = $objp->fournisseur;
139 $thirdpartytmp->code_client = $objp->code_client;
140 $thirdpartytmp->code_fournisseur = $objp->code_fournisseur;
141 $thirdpartytmp->code_compta = $objp->code_compta;
142 $thirdpartytmp->code_compta_client = $objp->code_compta;
143 $thirdpartytmp->code_compta_fournisseur = $objp->code_compta_fournisseur;
144
145 $dateline = $this->db->jdate($objp->date_line);
146 if ($contractstatic->status == Contrat::STATUS_VALIDATED && $objp->contractline_status == ContratLigne::STATUS_OPEN && !empty($dateline) && ($dateline + $conf->contrat->services->expires->warning_delay) < $now) {
147 $late = img_warning($langs->trans("Late"));
148 }
149
150 // Label
151 if ($objp->product_id > 0) {
152 $productstatic->id = $objp->product_id;
153 $productstatic->type = $objp->product_type;
154 $productstatic->ref = $objp->product_ref;
155 $productstatic->entity = $objp->product_entity;
156 $productstatic->label = $objp->product_label;
157 $productstatic->status = $objp->tosell;
158 $productstatic->status_buy = $objp->tobuy;
159
160 $text = $productstatic->getNomUrl(1, '', 20);
161 if ($objp->product_label) {
162 $text .= ' - ';
163 //$productstatic->ref=$objp->label;
164 //$text .= $productstatic->getNomUrl(0,'',16);
165 $text .= $objp->product_label;
166 }
167 $description = $objp->description;
168
169 $s = $form->textwithtooltip($text, $description, 3, '', '', '', 0, '');
170 } else {
171 $s = img_object($langs->trans("ShowProductOrService"), ($objp->product_type ? 'service' : 'product')).' '.dol_htmlentitiesbr($objp->description);
172 }
173
174
175 $this->info_box_contents[$i][] = array(
176 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
177 'text' => $s,
178 'asis' => 1
179 );
180
181 $this->info_box_contents[$i][] = array(
182 'td' => 'class="nowraponall"',
183 'text' => $contractstatic->getNomUrl(1),
184 'asis' => 1
185 );
186
187 $this->info_box_contents[$i][] = array(
188 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
189 'text' => $thirdpartytmp->getNomUrl(1),
190 'asis' => 1
191 );
192
193 $this->info_box_contents[$i][] = array(
194 'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'"',
195 'text' => dol_print_date($datem, 'day', 'tzuserrel'),
196 'text2' => $late,
197 );
198
199 $this->info_box_contents[$i][] = array(
200 'td' => 'class="right" width="18"',
201 'text' => $contractlinestatic->getLibStatut(3)
202 );
203
204 $i++;
205 }
206
207 $this->db->free($result);
208 } else {
209 $this->info_box_contents[0][0] = array(
210 'td' => '',
211 'maxlength' => 500,
212 'text' => ($this->db->error().' sql='.$sql),
213 );
214 }
215 } else {
216 $this->info_box_contents[0][0] = array(
217 'td' => 'class="nohover left"',
218 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
219 );
220 }
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 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...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79