dolibarr  16.0.5
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 
27 include_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 
43  public $db;
44 
45  public $param;
46 
47  public $info_box_head = array();
48  public $info_box_contents = array();
49 
50 
57  public function __construct($db, $param)
58  {
59  global $user;
60 
61  $this->db = $db;
62 
63  $this->hidden = !(!empty($user->rights->service->lire) && !empty($user->rights->contrat->lire));
64  }
65 
72  public function loadBox($max = 5)
73  {
74  global $user, $langs, $conf;
75 
76  $this->max = $max;
77 
78  include_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
79 
80  $form = new Form($this->db);
81 
82  $this->info_box_head = array('text' => $langs->trans("BoxLastProductsInContract", $max));
83 
84  if ($user->rights->service->lire && $user->rights->contrat->lire) {
85  $contractstatic = new Contrat($this->db);
86  $contractlinestatic = new ContratLigne($this->db);
87  $thirdpartytmp = new Societe($this->db);
88  $productstatic = new Product($this->db);
89 
90  $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,";
91  $sql .= " c.rowid, c.ref, c.statut as contract_status, c.ref_customer, c.ref_supplier,";
92  $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,";
93  $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";
94  $sql .= " FROM (".MAIN_DB_PREFIX."societe as s";
95  $sql .= " INNER JOIN ".MAIN_DB_PREFIX."contrat as c ON s.rowid = c.fk_soc";
96  $sql .= " INNER JOIN ".MAIN_DB_PREFIX."contratdet as cd ON c.rowid = cd.fk_contrat";
97  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid";
98  if (empty($user->rights->societe->client->voir) && !$user->socid) {
99  $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
100  }
101  $sql .= ")";
102  $sql .= " WHERE c.entity = ".$conf->entity;
103  if ($user->socid) {
104  $sql .= " AND s.rowid = ".((int) $user->socid);
105  }
106  $sql .= $this->db->order("c.tms", "DESC");
107  $sql .= $this->db->plimit($max, 0);
108 
109  $result = $this->db->query($sql);
110  if ($result) {
111  $num = $this->db->num_rows($result);
112  $now = dol_now();
113 
114  $i = 0;
115 
116  while ($i < $num) {
117  $late = '';
118 
119  $objp = $this->db->fetch_object($result);
120  $datem = $this->db->jdate($objp->datem);
121 
122  $contractlinestatic->id = $objp->cdid;
123  $contractlinestatic->fk_contrat = $objp->rowid;
124  $contractlinestatic->label = $objp->label;
125  $contractlinestatic->description = $objp->description;
126  $contractlinestatic->type = $objp->type;
127  $contractlinestatic->product_id = $objp->product_id;
128  $contractlinestatic->product_ref = $objp->product_ref;
129  $contractlinestatic->product_type = $objp->product_type;
130  $contractlinestatic->statut = $objp->contractline_status;
131 
132  $contractstatic->id = $objp->rowid;
133  $contractstatic->ref = $objp->ref;
134  $contractstatic->ref_customer = $objp->ref_customer;
135  $contractstatic->ref_supplier = $objp->ref_supplier;
136  $contractstatic->statut = $objp->contract_status;
137 
138  $thirdpartytmp->name = $objp->name;
139  $thirdpartytmp->id = $objp->socid;
140  $thirdpartytmp->email = $objp->email;
141  $thirdpartytmp->client = $objp->client;
142  $thirdpartytmp->fournisseur = $objp->fournisseur;
143  $thirdpartytmp->code_client = $objp->code_client;
144  $thirdpartytmp->code_fournisseur = $objp->code_fournisseur;
145  $thirdpartytmp->code_compta = $objp->code_compta;
146  $thirdpartytmp->code_compta_fournisseur = $objp->code_compta_fournisseur;
147 
148  $dateline = $this->db->jdate($objp->date_line);
149  if ($contractstatic->statut == Contrat::STATUS_VALIDATED && $objp->contractline_status == ContratLigne::STATUS_OPEN && !empty($dateline) && ($dateline + $conf->contrat->services->expires->warning_delay) < $now) {
150  $late = img_warning($langs->trans("Late"));
151  }
152 
153  // Label
154  if ($objp->product_id > 0) {
155  $productstatic->id = $objp->product_id;
156  $productstatic->type = $objp->product_type;
157  $productstatic->ref = $objp->product_ref;
158  $productstatic->entity = $objp->product_entity;
159  $productstatic->label = $objp->product_label;
160  $productstatic->status = $objp->tosell;
161  $productstatic->status_buy = $objp->tobuy;
162 
163  $text = $productstatic->getNomUrl(1, '', 20);
164  if ($objp->product_label) {
165  $text .= ' - ';
166  //$productstatic->ref=$objp->label;
167  //$text .= $productstatic->getNomUrl(0,'',16);
168  $text .= $objp->product_label;
169  }
170  $description = $objp->description;
171 
172  // Add description in form
173  if (!empty($conf->global->PRODUIT_DESC_IN_FORM)) {
174  //$text .= (! empty($objp->description) && $objp->description!=$objp->product_label)?'<br>'.dol_htmlentitiesbr($objp->description):'';
175  $description = ''; // Already added into main visible desc
176  }
177 
178  $s = $form->textwithtooltip($text, $description, 3, '', '', '', 0, (!empty($objp->fk_parent_line) ?img_picto('', 'rightarrow') : ''));
179  } else {
180  $s = img_object($langs->trans("ShowProductOrService"), ($objp->product_type ? 'service' : 'product')).' '.dol_htmlentitiesbr($objp->description);
181  }
182 
183 
184  $this->info_box_contents[$i][] = array(
185  'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
186  'text' => $s,
187  'asis' => 1
188  );
189 
190  $this->info_box_contents[$i][] = array(
191  'td' => 'class="nowraponall"',
192  'text' => $contractstatic->getNomUrl(1),
193  'asis' => 1
194  );
195 
196  $this->info_box_contents[$i][] = array(
197  'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
198  'text' => $thirdpartytmp->getNomUrl(1),
199  'asis' => 1
200  );
201 
202  $this->info_box_contents[$i][] = array(
203  'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'"',
204  'text' => dol_print_date($datem, 'day', 'tzuserrel'),
205  'text2'=> $late,
206  );
207 
208  $this->info_box_contents[$i][] = array(
209  'td' => 'class="right" width="18"',
210  'text' => $contractlinestatic->getLibStatut(3)
211  );
212 
213  $i++;
214  }
215  if ($num == 0) {
216  $this->info_box_contents[$i][0] = array(
217  'td' => 'class="center opacitymedium"',
218  'text'=>$langs->trans("NoContractedProducts")
219  );
220  }
221 
222  $this->db->free($result);
223  } else {
224  $this->info_box_contents[0][0] = array(
225  'td' => '',
226  'maxlength' => 500,
227  'text' => ($this->db->error().' sql='.$sql),
228  );
229  }
230  } else {
231  $this->info_box_contents[0][0] = array(
232  'td' => 'class="nohover opacitymedium left"',
233  'text' => $langs->trans("ReadPermissionNotAllowed")
234  );
235  }
236  }
237 
246  public function showBox($head = null, $contents = null, $nooutput = 0)
247  {
248  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
249  }
250 }
Societe
Class to manage third parties objects (customers, suppliers, prospects...)
Definition: societe.class.php:48
db
$conf db
API class for accounts.
Definition: inc.php:41
dol_escape_htmltag
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
Definition: functions.lib.php:1468
box_services_contracts\__construct
__construct($db, $param)
Constructor.
Definition: box_services_contracts.php:57
img_warning
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
Definition: functions.lib.php:4521
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2514
box_services_contracts\showBox
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
Definition: box_services_contracts.php:246
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
box_services_contracts\loadBox
loadBox($max=5)
Load data into info_box_contents array to show array later.
Definition: box_services_contracts.php:72
box_services_contracts
Class to manage the box to show last contracted products/services lines.
Definition: box_services_contracts.php:33
Contrat
Class to manage contracts.
Definition: contrat.class.php:43
Product
Class to manage products or services.
Definition: product.class.php:46
ContratLigne
Class to manage lines of contracts.
Definition: contrat.class.php:2607
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
img_object
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
Definition: functions.lib.php:4211
dol_htmlentitiesbr
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...
Definition: functions.lib.php:6991
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2845
ModeleBoxes
Class ModeleBoxes.
Definition: modules_boxes.php:34