dolibarr  7.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@capnetworks.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 <http://www.gnu.org/licenses/>.
19  */
20 
27 include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
28 
29 
34 {
35  var $boxcode="lastproductsincontract";
36  var $boximg="object_product";
37  var $boxlabel="BoxLastProductsInContract";
38  var $depends = array("service","contrat");
39 
40  var $db;
41  var $param;
42 
43  var $info_box_head = array();
44  var $info_box_contents = array();
45 
46 
53  function __construct($db,$param)
54  {
55  global $user;
56 
57  $this->db=$db;
58 
59  $this->hidden=! ($user->rights->service->lire && $user->rights->contrat->lire);
60  }
61 
68  function loadBox($max=5)
69  {
70  global $user, $langs, $db, $conf;
71 
72  $this->max=$max;
73 
74  include_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
75 
76  $form = new Form($db);
77 
78  $this->info_box_head = array('text' => $langs->trans("BoxLastProductsInContract",$max));
79 
80  if ($user->rights->service->lire && $user->rights->contrat->lire)
81  {
82  $contractstatic=new Contrat($db);
83  $contratlignestatic=new ContratLigne($db);
84  $thirdpartytmp = new Societe($db);
85  $productstatic = new Product($db);
86 
87  $sql = "SELECT s.nom as name, s.rowid as socid,";
88  $sql.= " c.rowid, c.ref, c.statut as contract_status,";
89  $sql.= " cd.rowid as cdid, cd.label, cd.description, cd.tms as datem, cd.statut, cd.product_type as type,";
90  $sql.= " p.rowid as product_id, p.ref as product_ref, p.label as plabel, p.fk_product_type as ptype, p.entity";
91  $sql.= " FROM (".MAIN_DB_PREFIX."societe as s";
92  $sql.= " INNER JOIN ".MAIN_DB_PREFIX."contrat as c ON s.rowid = c.fk_soc";
93  $sql.= " INNER JOIN ".MAIN_DB_PREFIX."contratdet as cd ON c.rowid = cd.fk_contrat";
94  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid";
95  if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
96  $sql.= ")";
97  $sql.= " WHERE c.entity = ".$conf->entity;
98  if($user->societe_id) $sql.= " AND s.rowid = ".$user->societe_id;
99  $sql.= $db->order("c.tms","DESC");
100  $sql.= $db->plimit($max, 0);
101 
102  $result = $db->query($sql);
103  if ($result)
104  {
105  $num = $db->num_rows($result);
106  $now=dol_now();
107 
108  $i = 0;
109 
110  while ($i < $num)
111  {
112  $objp = $db->fetch_object($result);
113  $datem=$db->jdate($objp->datem);
114 
115  $contratlignestatic->id=$objp->cdid;
116  $contratlignestatic->fk_contrat=$objp->rowid;
117  $contratlignestatic->label=$objp->label;
118  $contratlignestatic->description=$objp->description;
119  $contratlignestatic->type=$objp->type;
120  $contratlignestatic->product_id=$objp->product_id;
121  $contratlignestatic->product_ref=$objp->product_ref;
122 
123  $contractstatic->statut=$objp->contract_status;
124  $contractstatic->id=$objp->rowid;
125  $contractstatic->ref=$objp->ref;
126 
127  $thirdpartytmp->name = $objp->name;
128  $thirdpartytmp->id = $objp->socid;
129 
130  // Multilangs
131  if (! empty($conf->global->MAIN_MULTILANGS) && $objp->product_id > 0) // if option multilang is on
132  {
133  $sqld = "SELECT label";
134  $sqld.= " FROM ".MAIN_DB_PREFIX."product_lang";
135  $sqld.= " WHERE fk_product=".$objp->product_id;
136  $sqld.= " AND lang='". $langs->getDefaultLang() ."'";
137  $sqld.= " LIMIT 1";
138 
139  $resultd = $db->query($sqld);
140  if ($resultd)
141  {
142  $objtp = $db->fetch_object($resultd);
143  if ($objtp->label != '') $contratlignestatic->label = $objtp->label;
144  }
145  }
146 
147  // Label
148  if ($objp->product_id > 0)
149  {
150  $productstatic->id=$objp->product_id;
151  $productstatic->type=$objp->ptype;
152  $productstatic->ref=$objp->product_ref;
153  $productstatic->entity=$objp->pentity;
154  $productstatic->label=$objp->plabel;
155  $text = $productstatic->getNomUrl(1,'',20);
156  if ($objp->plabel)
157  {
158  $text .= ' - ';
159  //$productstatic->ref=$objp->label;
160  //$text .= $productstatic->getNomUrl(0,'',16);
161  $text .= $objp->plabel;
162  }
163  $description = $objp->description;
164 
165  // Add description in form
166  if (! empty($conf->global->PRODUIT_DESC_IN_FORM))
167  {
168  //$text .= (! empty($objp->description) && $objp->description!=$objp->plabel)?'<br>'.dol_htmlentitiesbr($objp->description):'';
169  $description = ''; // Already added into main visible desc
170  }
171 
172  $s = $form->textwithtooltip($text,$description,3,'','',$cursorline,0,(!empty($line->fk_parent_line)?img_picto('', 'rightarrow'):''));
173  }
174  else
175  {
176  $s = img_object($langs->trans("ShowProductOrService"), ($objp->product_type ? 'service' : 'product')).' '.dol_htmlentitiesbr($objp->description);
177  }
178 
179 
180  $this->info_box_contents[$i][] = array('td' => 'class="tdoverflowmax100 maxwidth100onsmartphone"',
181  'text' => $s,
182  'asis' => 1
183  );
184 
185  $this->info_box_contents[$i][] = array('td' => '',
186  'text' => $contractstatic->getNomUrl(1),
187  'asis' => 1
188  );
189 
190  $this->info_box_contents[$i][] = array('td' => 'class="tdoverflowmax100 maxwidth100onsmartphone"',
191  'text' => $thirdpartytmp->getNomUrl(1),
192  'asis' => 1
193  );
194 
195  $this->info_box_contents[$i][] = array('td' => '',
196  'text' => dol_print_date($datem,'day'));
197 
198  $this->info_box_contents[$i][] = array('td' => 'align="right" width="18"',
199  'text' => $contratlignestatic->LibStatut($objp->statut,3)
200  );
201 
202  $i++;
203  }
204  if ($num==0) $this->info_box_contents[$i][0] = array('td' => 'align="center"','text'=>$langs->trans("NoContractedProducts"));
205 
206  $db->free($result);
207  }
208  else
209  {
210  $this->info_box_contents[0][0] = array( 'td' => '',
211  'maxlength'=>500,
212  'text' => ($db->error().' sql='.$sql));
213  }
214  }
215  else {
216  $this->info_box_contents[0][0] = array(
217  'td' => 'align="left" class="nohover opacitymedium"',
218  'text' => $langs->trans("ReadPermissionNotAllowed")
219  );
220  }
221 
222  }
223 
232  function showBox($head = null, $contents = null, $nooutput=0)
233  {
234  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
235  }
236 
237 }
238 
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='')
Show picto whatever it's its name (generic function)
__construct($db, $param)
Constructor.
Class to manage products or services.
Class to manage contracts.
Classe permettant la gestion des lignes de contrats.
Class ModeleBoxes.
if(empty($reshook)) $form
View.
Definition: perms.php:103
Class to manage generation of HTML components Only common components must be here.
Class to manage third parties objects (customers, suppliers, prospects...)
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_now($mode='gmt')
Return date for now.
dol_print_date($time, $format='', $tzoutput='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Class to manage the box to show last contracted products/services lines.
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...
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
loadBox($max=5)
Load data into info_box_contents array to show array later.