dolibarr  9.0.0
box_propales.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2007 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2015 Frederic France <frederic.france@free.fr>
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="lastpropals";
36  var $boximg="object_propal";
37  var $boxlabel="BoxLastProposals";
38  var $depends = array("propal"); // conf->propal->enabled
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->propale->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.'/comm/propal/class/propal.class.php';
79  include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
80  $propalstatic=new Propal($db);
81  $societestatic = new Societe($db);
82 
83  $this->info_box_head = array('text' => $langs->trans("BoxTitleLast".($conf->global->MAIN_LASTBOX_ON_OBJECT_DATE?"":"Modified")."Propals",$max));
84 
85  if ($user->rights->propale->lire)
86  {
87  $sql = "SELECT s.nom as name, s.rowid as socid, s.code_client, s.logo,";
88  $sql.= " p.rowid, p.ref, p.fk_statut, p.datep as dp, p.datec, p.fin_validite, p.date_cloture, p.total_ht, p.tva as total_tva, p.total as total_ttc, p.tms";
89  $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
90  $sql.= ", ".MAIN_DB_PREFIX."propal as p";
91  if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
92  $sql.= " WHERE p.fk_soc = s.rowid";
93  $sql.= " AND p.entity = ".$conf->entity;
94  if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
95  if($user->societe_id) $sql.= " AND s.rowid = ".$user->societe_id;
96  if ($conf->global->MAIN_LASTBOX_ON_OBJECT_DATE) $sql.= " ORDER BY p.datep DESC, p.ref DESC ";
97  else $sql.= " ORDER BY p.tms DESC, p.ref DESC ";
98  $sql.= $db->plimit($max, 0);
99 
100  $result = $db->query($sql);
101  if ($result)
102  {
103  $num = $db->num_rows($result);
104  $now=dol_now();
105 
106  $line = 0;
107 
108  while ($line < $num) {
109  $objp = $db->fetch_object($result);
110  $date=$db->jdate($objp->dp);
111  $datec=$db->jdate($objp->datec);
112  $datem=$db->jdate($objp->tms);
113  $dateterm=$db->jdate($objp->fin_validite);
114  $dateclose=$db->jdate($objp->date_cloture);
115  $propalstatic->id = $objp->rowid;
116  $propalstatic->ref = $objp->ref;
117  $propalstatic->total_ht = $objp->total_ht;
118  $propalstatic->total_tva = $objp->total_tva;
119  $propalstatic->total_ttc = $objp->total_ttc;
120  $societestatic->id = $objp->socid;
121  $societestatic->name = $objp->name;
122  $societestatic->code_client = $objp->code_client;
123  $societestatic->logo = $objp->logo;
124 
125  $late = '';
126  if ($objp->fk_statut == 1 && $dateterm < ($now - $conf->propal->cloture->warning_delay)) {
127  $late = img_warning($langs->trans("Late"));
128  }
129 
130  $this->info_box_contents[$line][] = array(
131  'td' => '',
132  'text' => $propalstatic->getNomUrl(1),
133  'text2'=> $late,
134  'asis' => 1,
135  );
136 
137  $this->info_box_contents[$line][] = array(
138  'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
139  'text' => $societestatic->getNomUrl(1),
140  'asis' => 1,
141  );
142 
143  $this->info_box_contents[$line][] = array(
144  'td' => 'class="right nowraponall"',
145  'text' => price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency),
146  );
147 
148  $this->info_box_contents[$line][] = array(
149  'td' => 'class="right"',
150  'text' => dol_print_date($date,'day'),
151  );
152 
153  $this->info_box_contents[$line][] = array(
154  'td' => 'align="right" width="18"',
155  'text' => $propalstatic->LibStatut($objp->fk_statut,3),
156  );
157 
158  $line++;
159  }
160 
161  if ($num==0)
162  $this->info_box_contents[$line][0] = array(
163  'td' => 'align="center"',
164  'text'=>$langs->trans("NoRecordedProposals"),
165  );
166 
167  $db->free($result);
168  } else {
169  $this->info_box_contents[0][0] = array(
170  'td' => '',
171  'maxlength'=>500,
172  'text' => ($db->error().' sql='.$sql),
173  );
174  }
175  } else {
176  $this->info_box_contents[0][0] = array(
177  'td' => 'align="left" class="nohover opacitymedium"',
178  'text' => $langs->trans("ReadPermissionNotAllowed")
179  );
180  }
181  }
182 
191  function showBox($head = null, $contents = null, $nooutput=0)
192  {
193  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
194  }
195 }
196 
img_warning($titlealt='default', $moreatt='')
Show warning logo.
Class to manage the box to show last proposals.
Class ModeleBoxes.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
Class to manage third parties objects (customers, suppliers, prospects...)
dol_now($mode='gmt')
Return date for now.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages...
dol_print_date($time, $format='', $tzoutput='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
loadBox($max=5)
Load data into info_box_contents array to show array later.
__construct($db, $param)
Constructor.
Class to manage proposals.