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
63 public function loadBox($max = 5)
64 {
65 global $user, $langs, $conf;
66
67 $this->max = $max;
68
69 include_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
70 include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
71 $propalstatic = new Propal($this->db);
72 $societestatic = new Societe($this->db);
73
74 $text = $langs->trans("BoxTitleLast".(getDolGlobalString('MAIN_LASTBOX_ON_OBJECT_DATE') ? "" : "Modified")."Propals", $max);
75 $this->info_box_head = array(
76 'text' => $text.'<a class="paddingleft" href="'.DOL_URL_ROOT.'/comm/propal/list.php?sortfield=p.tms&sortorder=DESC"><span class="badge">...</span></a>'
77 );
78
79 if ($user->hasRight('propal', 'lire')) {
80 $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias";
81 $sql .= ", s.code_client, s.code_compta, s.client";
82 $sql .= ", s.logo, s.email, s.entity";
83 $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";
84 $sql .= " FROM ".MAIN_DB_PREFIX."propal as p, ".MAIN_DB_PREFIX."societe as s";
85 if (!$user->hasRight('societe', 'client', 'voir')) {
86 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
87 }
88 $sql .= " WHERE p.fk_soc = s.rowid";
89 $sql .= " AND p.entity IN (".getEntity('propal').")";
90 if (!$user->hasRight('societe', 'client', 'voir')) {
91 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
92 }
93 if ($user->socid) {
94 $sql .= " AND s.rowid = ".((int) $user->socid);
95 }
96 if (getDolGlobalString('MAIN_LASTBOX_ON_OBJECT_DATE')) {
97 $sql .= " ORDER BY p.datep DESC, p.ref DESC ";
98 } else {
99 $sql .= " ORDER BY p.tms DESC, p.ref DESC ";
100 }
101 $sql .= $this->db->plimit($max, 0);
102
103 $result = $this->db->query($sql);
104 if ($result) {
105 $num = $this->db->num_rows($result);
106 $now = dol_now();
107
108 $line = 0;
109
110 while ($line < $num) {
111 $objp = $this->db->fetch_object($result);
112 $date = $this->db->jdate($objp->dp);
113 $datec = $this->db->jdate($objp->datec);
114 $datem = $this->db->jdate($objp->tms);
115 $dateterm = $this->db->jdate($objp->fin_validite);
116 $dateclose = $this->db->jdate($objp->date_cloture);
117
118 $propalstatic->id = $objp->rowid;
119 $propalstatic->ref = $objp->ref;
120 $propalstatic->total_ht = $objp->total_ht;
121 $propalstatic->total_tva = $objp->total_tva;
122 $propalstatic->total_ttc = $objp->total_ttc;
123 $propalstatic->statut = $objp->status;
124 $propalstatic->status = $objp->status;
125 $propalstatic->date = $date;
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->code_compta_client = $objp->code_compta;
133 $societestatic->client = $objp->client;
134 $societestatic->logo = $objp->logo;
135 $societestatic->email = $objp->email;
136 $societestatic->entity = $objp->entity;
137
138 $late = '';
139 if ($objp->status == 1 && $dateterm < ($now - $conf->propal->cloture->warning_delay)) {
140 $late = img_warning($langs->trans("Late"));
141 }
142
143 $this->info_box_contents[$line][] = array(
144 'td' => 'class="nowraponall"',
145 'text' => $propalstatic->getNomUrl(1),
146 'text2' => $late,
147 'asis' => 1,
148 );
149
150 $this->info_box_contents[$line][] = array(
151 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
152 'text' => $societestatic->getNomUrl(1),
153 'asis' => 1,
154 );
155
156 $this->info_box_contents[$line][] = array(
157 'td' => 'class="nowraponall right amount"',
158 'text' => price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency),
159 );
160
161 $this->info_box_contents[$line][] = array(
162 'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'"',
163 'text' => dol_print_date($datem, 'day', 'tzuserrel'),
164 );
165
166 $this->info_box_contents[$line][] = array(
167 'td' => 'class="right" width="18"',
168 'text' => $propalstatic->LibStatut($objp->status, 3),
169 );
170
171 $line++;
172 }
173
174 if ($num == 0) {
175 $this->info_box_contents[$line][0] = array(
176 'td' => 'class="center"',
177 'text' => $langs->trans("NoRecordedProposals"),
178 );
179 }
180
181 $this->db->free($result);
182 } else {
183 $this->info_box_contents[0][0] = array(
184 'td' => '',
185 'maxlength' => 500,
186 'text' => ($this->db->error().' sql='.$sql),
187 );
188 }
189 } else {
190 $this->info_box_contents[0][0] = array(
191 'td' => 'class="nohover left"',
192 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
193 );
194 }
195 }
196
205 public function showBox($head = null, $contents = null, $nooutput = 0)
206 {
207 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
208 }
209}
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...