dolibarr  13.0.2
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-2019 Frederic France <frederic.france@netlogic.fr>
6  * Copyright (C) 2020 Pierre Ardoin <mapiolca@me.com>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <https://www.gnu.org/licenses/>.
20  */
21 
28 include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
29 
30 
35 {
36  public $boxcode = "lastpropals";
37  public $boximg = "object_propal";
38  public $boxlabel = "BoxLastProposals";
39  public $depends = array("propal"); // conf->propal->enabled
40 
44  public $db;
45 
46  public $param;
47 
48  public $info_box_head = array();
49  public $info_box_contents = array();
50 
51 
58  public function __construct($db, $param)
59  {
60  global $user;
61 
62  $this->db = $db;
63 
64  $this->hidden = !($user->rights->propale->lire);
65  }
66 
73  public function loadBox($max = 5)
74  {
75  global $user, $langs, $conf;
76 
77  $this->max = $max;
78 
79  include_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
80  include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
81  $propalstatic = new Propal($this->db);
82  $societestatic = new Societe($this->db);
83 
84  $this->info_box_head = array('text' => $langs->trans("BoxTitleLast".($conf->global->MAIN_LASTBOX_ON_OBJECT_DATE ? "" : "Modified")."Propals", $max));
85 
86  if ($user->rights->propale->lire)
87  {
88  $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias";
89  $sql .= ", s.code_client, s.code_compta, s.client";
90  $sql .= ", s.logo, s.email, s.entity";
91  $sql .= ", p.rowid, p.ref, p.fk_statut as status, 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";
92  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
93  $sql .= ", ".MAIN_DB_PREFIX."propal as p";
94  if (!$user->rights->societe->client->voir && !$user->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
95  $sql .= " WHERE p.fk_soc = s.rowid";
96  $sql .= " AND p.entity IN (".getEntity('propal').")";
97  if (!$user->rights->societe->client->voir && !$user->socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
98  if ($user->socid) $sql .= " AND s.rowid = ".$user->socid;
99  if ($conf->global->MAIN_LASTBOX_ON_OBJECT_DATE) $sql .= " ORDER BY p.datep DESC, p.ref DESC ";
100  else $sql .= " ORDER BY p.tms DESC, p.ref DESC ";
101  $sql .= $this->db->plimit($max, 0);
102 
103  $result = $this->db->query($sql);
104  if ($result)
105  {
106  $num = $this->db->num_rows($result);
107  $now = dol_now();
108 
109  $line = 0;
110 
111  while ($line < $num) {
112  $objp = $this->db->fetch_object($result);
113  $date = $this->db->jdate($objp->dp);
114  $datec = $this->db->jdate($objp->datec);
115  $datem = $this->db->jdate($objp->tms);
116  $dateterm = $this->db->jdate($objp->fin_validite);
117  $dateclose = $this->db->jdate($objp->date_cloture);
118 
119  $propalstatic->id = $objp->rowid;
120  $propalstatic->ref = $objp->ref;
121  $propalstatic->total_ht = $objp->total_ht;
122  $propalstatic->total_tva = $objp->total_tva;
123  $propalstatic->total_ttc = $objp->total_ttc;
124  $propalstatic->statut = $objp->status;
125  $propalstatic->status = $objp->status;
126 
127  $societestatic->id = $objp->socid;
128  $societestatic->name = $objp->name;
129  //$societestatic->name_alias = $objp->name_alias;
130  $societestatic->code_client = $objp->code_client;
131  $societestatic->code_compta = $objp->code_compta;
132  $societestatic->client = $objp->client;
133  $societestatic->logo = $objp->logo;
134  $societestatic->email = $objp->email;
135  $societestatic->entity = $objp->entity;
136 
137  $late = '';
138  if ($objp->status == 1 && $dateterm < ($now - $conf->propal->cloture->warning_delay)) {
139  $late = img_warning($langs->trans("Late"));
140  }
141 
142  $this->info_box_contents[$line][] = array(
143  'td' => 'class="nowraponall"',
144  'text' => $propalstatic->getNomUrl(1),
145  'text2'=> $late,
146  'asis' => 1,
147  );
148 
149  $this->info_box_contents[$line][] = array(
150  'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
151  'text' => $societestatic->getNomUrl(1),
152  'asis' => 1,
153  );
154 
155  $this->info_box_contents[$line][] = array(
156  'td' => 'class="right nowraponall"',
157  'text' => price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency),
158  );
159 
160  $this->info_box_contents[$line][] = array(
161  'td' => 'class="right"',
162  'text' => dol_print_date($date, 'day'),
163  );
164 
165  $this->info_box_contents[$line][] = array(
166  'td' => 'class="right" width="18"',
167  'text' => $propalstatic->LibStatut($objp->status, 3),
168  );
169 
170  $line++;
171  }
172 
173  if ($num == 0)
174  $this->info_box_contents[$line][0] = array(
175  'td' => 'class="center"',
176  'text'=>$langs->trans("NoRecordedProposals"),
177  );
178 
179  $this->db->free($result);
180  } else {
181  $this->info_box_contents[0][0] = array(
182  'td' => '',
183  'maxlength'=>500,
184  'text' => ($this->db->error().' sql='.$sql),
185  );
186  }
187  } else {
188  $this->info_box_contents[0][0] = array(
189  'td' => 'class="nohover opacitymedium left"',
190  'text' => $langs->trans("ReadPermissionNotAllowed")
191  );
192  }
193  }
194 
203  public function showBox($head = null, $contents = null, $nooutput = 0)
204  {
205  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
206  }
207 }
dol_now($mode= 'auto')
Return date for now.
Class to manage the box to show last proposals.
Class ModeleBoxes.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
$conf db
API class for accounts.
Definition: inc.php:54
img_warning($titlealt= 'default', $moreatt= '', $morecss= 'pictowarning')
Show warning logo.
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...
Class to manage third parties objects (customers, suppliers, prospects...)
dol_print_date($time, $format= '', $tzoutput= 'auto', $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.