dolibarr  7.0.0-beta
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@capnetworks.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 
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->propale->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.'/comm/propal/class/propal.class.php';
75  include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
76  $propalstatic=new Propal($db);
77  $societestatic = new Societe($db);
78 
79  $this->info_box_head = array('text' => $langs->trans("BoxTitleLast".($conf->global->MAIN_LASTBOX_ON_OBJECT_DATE?"":"Modified")."Propals",$max));
80 
81  if ($user->rights->propale->lire)
82  {
83  $sql = "SELECT s.nom as name, s.rowid as socid, s.code_client, s.logo,";
84  $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";
85  $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
86  $sql.= ", ".MAIN_DB_PREFIX."propal as p";
87  if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
88  $sql.= " WHERE p.fk_soc = s.rowid";
89  $sql.= " AND p.entity = ".$conf->entity;
90  if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
91  if($user->societe_id) $sql.= " AND s.rowid = ".$user->societe_id;
92  if ($conf->global->MAIN_LASTBOX_ON_OBJECT_DATE) $sql.= " ORDER BY p.datep DESC, p.ref DESC ";
93  else $sql.= " ORDER BY p.tms DESC, p.ref DESC ";
94  $sql.= $db->plimit($max, 0);
95 
96  $result = $db->query($sql);
97  if ($result)
98  {
99  $num = $db->num_rows($result);
100  $now=dol_now();
101 
102  $line = 0;
103 
104  while ($line < $num) {
105  $objp = $db->fetch_object($result);
106  $date=$db->jdate($objp->dp);
107  $datec=$db->jdate($objp->datec);
108  $datem=$db->jdate($objp->tms);
109  $dateterm=$db->jdate($objp->fin_validite);
110  $dateclose=$db->jdate($objp->date_cloture);
111  $propalstatic->id = $objp->rowid;
112  $propalstatic->ref = $objp->ref;
113  $propalstatic->total_ht = $objp->total_ht;
114  $propalstatic->total_tva = $objp->total_tva;
115  $propalstatic->total_ttc = $objp->total_ttc;
116  $societestatic->id = $objp->socid;
117  $societestatic->name = $objp->name;
118  $societestatic->code_client = $objp->code_client;
119  $societestatic->logo = $objp->logo;
120 
121  $late = '';
122  if ($objp->fk_statut == 1 && $dateterm < ($now - $conf->propal->cloture->warning_delay)) {
123  $late = img_warning($langs->trans("Late"));
124  }
125 
126  $this->info_box_contents[$line][] = array(
127  'td' => '',
128  'text' => $propalstatic->getNomUrl(1),
129  'text2'=> $late,
130  'asis' => 1,
131  );
132 
133  $this->info_box_contents[$line][] = array(
134  'td' => 'class="tdoverflowmax100"',
135  'text' => $societestatic->getNomUrl(1),
136  'asis' => 1,
137  );
138 
139  $this->info_box_contents[$line][] = array(
140  'td' => 'class="right"',
141  'text' => price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency),
142  );
143 
144  $this->info_box_contents[$line][] = array(
145  'td' => 'class="right"',
146  'text' => dol_print_date($date,'day'),
147  );
148 
149  $this->info_box_contents[$line][] = array(
150  'td' => 'align="right" width="18"',
151  'text' => $propalstatic->LibStatut($objp->fk_statut,3),
152  );
153 
154  $line++;
155  }
156 
157  if ($num==0)
158  $this->info_box_contents[$line][0] = array(
159  'td' => 'align="center"',
160  'text'=>$langs->trans("NoRecordedProposals"),
161  );
162 
163  $db->free($result);
164  } else {
165  $this->info_box_contents[0][0] = array(
166  'td' => '',
167  'maxlength'=>500,
168  'text' => ($db->error().' sql='.$sql),
169  );
170  }
171  } else {
172  $this->info_box_contents[0][0] = array(
173  'td' => 'align="left" class="nohover opacitymedium"',
174  'text' => $langs->trans("ReadPermissionNotAllowed")
175  );
176  }
177  }
178 
187  function showBox($head = null, $contents = null, $nooutput=0)
188  {
189  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
190  }
191 
192 }
193 
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...)
img_warning($titlealt= 'default', $moreatt= '')
Show warning logo.
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.