dolibarr  9.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 <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 
43  public $db;
44 
45  var $param;
46 
47  var $info_box_head = array();
48  var $info_box_contents = array();
49 
50 
57  function __construct($db,$param)
58  {
59  global $user;
60 
61  $this->db=$db;
62 
63  $this->hidden=! ($user->rights->service->lire && $user->rights->contrat->lire);
64  }
65 
72  function loadBox($max=5)
73  {
74  global $user, $langs, $db, $conf;
75 
76  $this->max=$max;
77 
78  include_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
79 
80  $form = new Form($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  {
86  $contractstatic=new Contrat($db);
87  $contratlignestatic=new ContratLigne($db);
88  $thirdpartytmp = new Societe($db);
89  $productstatic = new Product($db);
90 
91  $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,";
92  $sql.= " c.rowid, c.ref, c.statut as contract_status, c.ref_customer, c.ref_supplier,";
93  $sql.= " cd.rowid as cdid, cd.label, cd.description, cd.tms as datem, cd.statut, cd.product_type as type,";
94  $sql.= " p.rowid as product_id, p.ref as product_ref, p.label as plabel, p.fk_product_type as ptype, p.entity";
95  $sql.= " FROM (".MAIN_DB_PREFIX."societe as s";
96  $sql.= " INNER JOIN ".MAIN_DB_PREFIX."contrat as c ON s.rowid = c.fk_soc";
97  $sql.= " INNER JOIN ".MAIN_DB_PREFIX."contratdet as cd ON c.rowid = cd.fk_contrat";
98  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid";
99  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;
100  $sql.= ")";
101  $sql.= " WHERE c.entity = ".$conf->entity;
102  if($user->societe_id) $sql.= " AND s.rowid = ".$user->societe_id;
103  $sql.= $db->order("c.tms","DESC");
104  $sql.= $db->plimit($max, 0);
105 
106  $result = $db->query($sql);
107  if ($result)
108  {
109  $num = $db->num_rows($result);
110  $now=dol_now();
111 
112  $i = 0;
113 
114  while ($i < $num)
115  {
116  $objp = $db->fetch_object($result);
117  $datem=$db->jdate($objp->datem);
118 
119  $contratlignestatic->id=$objp->cdid;
120  $contratlignestatic->fk_contrat=$objp->rowid;
121  $contratlignestatic->label=$objp->label;
122  $contratlignestatic->description=$objp->description;
123  $contratlignestatic->type=$objp->type;
124  $contratlignestatic->product_id=$objp->product_id;
125  $contratlignestatic->product_ref=$objp->product_ref;
126 
127  $contractstatic->statut=$objp->contract_status;
128  $contractstatic->id=$objp->rowid;
129  $contractstatic->ref=$objp->ref;
130  $contractstatic->ref_customer=$objp->ref_customer;
131  $contractstatic->ref_supplier=$objp->ref_supplier;
132 
133  $thirdpartytmp->name = $objp->name;
134  $thirdpartytmp->id = $objp->socid;
135  $thirdpartytmp->email = $objp->email;
136  $thirdpartytmp->client = $objp->client;
137  $thirdpartytmp->fournisseur = $objp->fournisseur;
138  $thirdpartytmp->code_client = $objp->code_client;
139  $thirdpartytmp->code_fournisseur = $objp->code_fournisseur;
140  $thirdpartytmp->code_compta = $objp->code_compta;
141  $thirdpartytmp->code_compta_fournisseur = $objp->code_compta_fournisseur;
142 
143  // Multilangs
144  if (! empty($conf->global->MAIN_MULTILANGS) && $objp->product_id > 0) // if option multilang is on
145  {
146  $sqld = "SELECT label";
147  $sqld.= " FROM ".MAIN_DB_PREFIX."product_lang";
148  $sqld.= " WHERE fk_product=".$objp->product_id;
149  $sqld.= " AND lang='". $langs->getDefaultLang() ."'";
150  $sqld.= " LIMIT 1";
151 
152  $resultd = $db->query($sqld);
153  if ($resultd)
154  {
155  $objtp = $db->fetch_object($resultd);
156  if ($objtp->label != '') $contratlignestatic->label = $objtp->label;
157  }
158  }
159 
160  // Label
161  if ($objp->product_id > 0)
162  {
163  $productstatic->id=$objp->product_id;
164  $productstatic->type=$objp->ptype;
165  $productstatic->ref=$objp->product_ref;
166  $productstatic->entity=$objp->pentity;
167  $productstatic->label=$objp->plabel;
168  $text = $productstatic->getNomUrl(1,'',20);
169  if ($objp->plabel)
170  {
171  $text .= ' - ';
172  //$productstatic->ref=$objp->label;
173  //$text .= $productstatic->getNomUrl(0,'',16);
174  $text .= $objp->plabel;
175  }
176  $description = $objp->description;
177 
178  // Add description in form
179  if (! empty($conf->global->PRODUIT_DESC_IN_FORM))
180  {
181  //$text .= (! empty($objp->description) && $objp->description!=$objp->plabel)?'<br>'.dol_htmlentitiesbr($objp->description):'';
182  $description = ''; // Already added into main visible desc
183  }
184 
185  $s = $form->textwithtooltip($text,$description,3,'','',$cursorline,0,(!empty($line->fk_parent_line)?img_picto('', 'rightarrow'):''));
186  }
187  else
188  {
189  $s = img_object($langs->trans("ShowProductOrService"), ($objp->product_type ? 'service' : 'product')).' '.dol_htmlentitiesbr($objp->description);
190  }
191 
192 
193  $this->info_box_contents[$i][] = array('td' => 'class="tdoverflowmax100 maxwidth100onsmartphone"',
194  'text' => $s,
195  'asis' => 1
196  );
197 
198  $this->info_box_contents[$i][] = array('td' => '',
199  'text' => $contractstatic->getNomUrl(1),
200  'asis' => 1
201  );
202 
203  $this->info_box_contents[$i][] = array('td' => 'class="tdoverflowmax100 maxwidth100onsmartphone"',
204  'text' => $thirdpartytmp->getNomUrl(1),
205  'asis' => 1
206  );
207 
208  $this->info_box_contents[$i][] = array('td' => '',
209  'text' => dol_print_date($datem,'day'));
210 
211  $this->info_box_contents[$i][] = array('td' => 'align="right" width="18"',
212  'text' => $contratlignestatic->LibStatut($objp->statut,3)
213  );
214 
215  $i++;
216  }
217  if ($num==0) $this->info_box_contents[$i][0] = array('td' => 'align="center"','text'=>$langs->trans("NoContractedProducts"));
218 
219  $db->free($result);
220  }
221  else
222  {
223  $this->info_box_contents[0][0] = array( 'td' => '',
224  'maxlength'=>500,
225  'text' => ($db->error().' sql='.$sql));
226  }
227  }
228  else {
229  $this->info_box_contents[0][0] = array(
230  'td' => 'align="left" class="nohover opacitymedium"',
231  'text' => $langs->trans("ReadPermissionNotAllowed")
232  );
233  }
234  }
235 
244  function showBox($head = null, $contents = null, $nooutput=0)
245  {
246  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
247  }
248 }
249 
__construct($db, $param)
Constructor.
Class to manage products or services.
Class to manage contracts.
Classe permettant la gestion des lignes de contrats.
Class ModeleBoxes.
Class to manage generation of HTML components Only common components must be here.
Class to manage third parties objects (customers, suppliers, prospects...)
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.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='')
Show picto whatever it&#39;s its name (generic function)
loadBox($max=5)
Load data into info_box_contents array to show array later.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)