dolibarr  19.0.0-dev
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-2021 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->hasRight('propal', 'read'));
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".(!empty($conf->global->MAIN_LASTBOX_ON_OBJECT_DATE) ? "" : "Modified")."Propals", $max));
85 
86  if ($user->hasRight('propal', 'lire')) {
87  $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias";
88  $sql .= ", s.code_client, s.code_compta, s.client";
89  $sql .= ", s.logo, s.email, s.entity";
90  $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.total_tva, p.total_ttc, p.tms";
91  $sql .= " FROM ".MAIN_DB_PREFIX."propal as p, ".MAIN_DB_PREFIX."societe as s";
92  if (empty($user->rights->societe->client->voir) && !$user->socid) {
93  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
94  }
95  $sql .= " WHERE p.fk_soc = s.rowid";
96  $sql .= " AND p.entity IN (".getEntity('propal').")";
97  if (empty($user->rights->societe->client->voir) && !$user->socid) {
98  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
99  }
100  if ($user->socid) {
101  $sql .= " AND s.rowid = ".((int) $user->socid);
102  }
103  if (!empty($conf->global->MAIN_LASTBOX_ON_OBJECT_DATE)) {
104  $sql .= " ORDER BY p.datep DESC, p.ref DESC ";
105  } else {
106  $sql .= " ORDER BY p.tms DESC, p.ref DESC ";
107  }
108  $sql .= $this->db->plimit($max, 0);
109 
110  $result = $this->db->query($sql);
111  if ($result) {
112  $num = $this->db->num_rows($result);
113  $now = dol_now();
114 
115  $line = 0;
116 
117  while ($line < $num) {
118  $objp = $this->db->fetch_object($result);
119  $date = $this->db->jdate($objp->dp);
120  $datec = $this->db->jdate($objp->datec);
121  $datem = $this->db->jdate($objp->tms);
122  $dateterm = $this->db->jdate($objp->fin_validite);
123  $dateclose = $this->db->jdate($objp->date_cloture);
124 
125  $propalstatic->id = $objp->rowid;
126  $propalstatic->ref = $objp->ref;
127  $propalstatic->total_ht = $objp->total_ht;
128  $propalstatic->total_tva = $objp->total_tva;
129  $propalstatic->total_ttc = $objp->total_ttc;
130  $propalstatic->statut = $objp->status;
131  $propalstatic->status = $objp->status;
132  $propalstatic->date = $date;
133 
134  $societestatic->id = $objp->socid;
135  $societestatic->name = $objp->name;
136  //$societestatic->name_alias = $objp->name_alias;
137  $societestatic->code_client = $objp->code_client;
138  $societestatic->code_compta = $objp->code_compta;
139  $societestatic->client = $objp->client;
140  $societestatic->logo = $objp->logo;
141  $societestatic->email = $objp->email;
142  $societestatic->entity = $objp->entity;
143 
144  $late = '';
145  if ($objp->status == 1 && $dateterm < ($now - $conf->propal->cloture->warning_delay)) {
146  $late = img_warning($langs->trans("Late"));
147  }
148 
149  $this->info_box_contents[$line][] = array(
150  'td' => 'class="nowraponall"',
151  'text' => $propalstatic->getNomUrl(1),
152  'text2'=> $late,
153  'asis' => 1,
154  );
155 
156  $this->info_box_contents[$line][] = array(
157  'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
158  'text' => $societestatic->getNomUrl(1),
159  'asis' => 1,
160  );
161 
162  $this->info_box_contents[$line][] = array(
163  'td' => 'class="nowraponall right amount"',
164  'text' => price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency),
165  );
166 
167  $this->info_box_contents[$line][] = array(
168  'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'"',
169  'text' => dol_print_date($datem, 'day', 'tzuserrel'),
170  );
171 
172  $this->info_box_contents[$line][] = array(
173  'td' => 'class="right" width="18"',
174  'text' => $propalstatic->LibStatut($objp->status, 3),
175  );
176 
177  $line++;
178  }
179 
180  if ($num == 0) {
181  $this->info_box_contents[$line][0] = array(
182  'td' => 'class="center"',
183  'text'=>$langs->trans("NoRecordedProposals"),
184  );
185  }
186 
187  $this->db->free($result);
188  } else {
189  $this->info_box_contents[0][0] = array(
190  'td' => '',
191  'maxlength'=>500,
192  'text' => ($this->db->error().' sql='.$sql),
193  );
194  }
195  } else {
196  $this->info_box_contents[0][0] = array(
197  'td' => 'class="nohover opacitymedium left"',
198  'text' => $langs->trans("ReadPermissionNotAllowed")
199  );
200  }
201  }
202 
211  public function showBox($head = null, $contents = null, $nooutput = 0)
212  {
213  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
214  }
215 }
Class ModeleBoxes.
Class to manage proposals.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage the box to show last proposals.
loadBox($max=5)
Load data into info_box_contents array to show array later.
__construct($db, $param)
Constructor.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:746
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.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...