dolibarr 21.0.0-alpha
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 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
29include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
30
31
36{
37 public $boxcode = "lastpropals";
38 public $boximg = "object_propal";
39 public $boxlabel = "BoxLastProposals";
40 public $depends = array("propal"); // conf->propal->enabled
41
48 public function __construct($db, $param)
49 {
50 global $user;
51
52 $this->db = $db;
53
54 $this->hidden = !($user->hasRight('propal', 'read'));
55
56 $this->urltoaddentry = DOL_URL_ROOT.'/comm/propal/card.php?action=create';
57 $this->msgNoRecords = 'NoRecordedProposals';
58 }
59
66 public function loadBox($max = 5)
67 {
68 global $user, $langs, $conf;
69
70 $this->max = $max;
71
72 include_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
73 include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
74 $propalstatic = new Propal($this->db);
75 $societestatic = new Societe($this->db);
76
77 $text = $langs->trans("BoxTitleLast".(getDolGlobalString('MAIN_LASTBOX_ON_OBJECT_DATE') ? "" : "Modified")."Propals", $max);
78 $this->info_box_head = array(
79 'text' => $text.'<a class="paddingleft" href="'.DOL_URL_ROOT.'/comm/propal/list.php?sortfield=p.tms&sortorder=DESC"><span class="badge">...</span></a>'
80 );
81
82 if ($user->hasRight('propal', 'lire')) {
83 $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias";
84 $sql .= ", s.code_client, s.code_compta, s.client";
85 $sql .= ", s.logo, s.email, s.entity";
86 $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";
87 $sql .= " FROM ".MAIN_DB_PREFIX."propal as p, ".MAIN_DB_PREFIX."societe as s";
88 if (!$user->hasRight('societe', 'client', 'voir')) {
89 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
90 }
91 $sql .= " WHERE p.fk_soc = s.rowid";
92 $sql .= " AND p.entity IN (".getEntity('propal').")";
93 if (!$user->hasRight('societe', 'client', 'voir')) {
94 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
95 }
96 if ($user->socid) {
97 $sql .= " AND s.rowid = ".((int) $user->socid);
98 }
99 if (getDolGlobalString('MAIN_LASTBOX_ON_OBJECT_DATE')) {
100 $sql .= " ORDER BY p.datep DESC, p.ref DESC ";
101 } else {
102 $sql .= " ORDER BY p.tms DESC, p.ref DESC ";
103 }
104 $sql .= $this->db->plimit($max, 0);
105
106 $result = $this->db->query($sql);
107 if ($result) {
108 $num = $this->db->num_rows($result);
109 $now = dol_now();
110
111 $line = 0;
112
113 while ($line < $num) {
114 $objp = $this->db->fetch_object($result);
115 $date = $this->db->jdate($objp->dp);
116 $datec = $this->db->jdate($objp->datec);
117 $datem = $this->db->jdate($objp->tms);
118 $dateterm = $this->db->jdate($objp->fin_validite);
119 $dateclose = $this->db->jdate($objp->date_cloture);
120
121 $propalstatic->id = $objp->rowid;
122 $propalstatic->ref = $objp->ref;
123 $propalstatic->total_ht = $objp->total_ht;
124 $propalstatic->total_tva = $objp->total_tva;
125 $propalstatic->total_ttc = $objp->total_ttc;
126 $propalstatic->statut = $objp->status;
127 $propalstatic->status = $objp->status;
128 $propalstatic->date = $date;
129
130 $societestatic->id = $objp->socid;
131 $societestatic->name = $objp->name;
132 //$societestatic->name_alias = $objp->name_alias;
133 $societestatic->code_client = $objp->code_client;
134 $societestatic->code_compta = $objp->code_compta;
135 $societestatic->code_compta_client = $objp->code_compta;
136 $societestatic->client = $objp->client;
137 $societestatic->logo = $objp->logo;
138 $societestatic->email = $objp->email;
139 $societestatic->entity = $objp->entity;
140
141 $late = '';
142 if ($objp->status == 1 && $dateterm < ($now - $conf->propal->cloture->warning_delay)) {
143 $late = img_warning($langs->trans("Late"));
144 }
145
146 $this->info_box_contents[$line][] = array(
147 'td' => 'class="nowraponall"',
148 'text' => $propalstatic->getNomUrl(1),
149 'text2' => $late,
150 'asis' => 1,
151 );
152
153 $this->info_box_contents[$line][] = array(
154 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
155 'text' => $societestatic->getNomUrl(1),
156 'asis' => 1,
157 );
158
159 $this->info_box_contents[$line][] = array(
160 'td' => 'class="nowraponall right amount"',
161 'text' => price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency),
162 );
163
164 $this->info_box_contents[$line][] = array(
165 'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'"',
166 'text' => dol_print_date($datem, 'day', 'tzuserrel'),
167 );
168
169 $this->info_box_contents[$line][] = array(
170 'td' => 'class="right" width="18"',
171 'text' => $propalstatic->LibStatut($objp->status, 3),
172 );
173
174 $line++;
175 }
176
177
178 $this->db->free($result);
179 } else {
180 $this->info_box_contents[0][0] = array(
181 'td' => '',
182 'maxlength' => 500,
183 'text' => ($this->db->error().' sql='.$sql),
184 );
185 }
186 } else {
187 $this->info_box_contents[0][0] = array(
188 'td' => 'class="nohover left"',
189 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
190 );
191 }
192 }
193
194
195
204 public function showBox($head = null, $contents = null, $nooutput = 0)
205 {
206 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
207 }
208}
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.
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_now($mode='auto')
Return date for now.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
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...