dolibarr 21.0.0-beta
box_graph_propales_permonth.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2013 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
4 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
25include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
26
27
32{
33 public $boxcode = "propalpermonth";
34 public $boximg = "object_propal";
35 public $boxlabel = "BoxProposalsPerMonth";
36 public $depends = array("propal");
37
38 public $widgettype = 'graph';
39
46 public function __construct($db, $param)
47 {
48 global $user;
49
50 $this->db = $db;
51
52 $this->hidden = !$user->hasRight('propal', 'lire');
53 }
54
61 public function loadBox($max = 5)
62 {
63 global $conf, $user, $langs;
64
65 $this->max = $max;
66
67 $refreshaction = 'refresh_'.$this->boxcode;
68
69 //include_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
70 //$propalstatic=new Propal($this->db);
71
72 $startmonth = getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1);
73 if (!getDolGlobalString('GRAPH_USE_FISCAL_YEAR')) {
74 $startmonth = 1;
75 }
76
77 $langs->load("propal");
78
79 $text = $langs->trans("BoxProposalsPerMonth", $max);
80 $this->info_box_head = array(
81 'text' => $text,
82 'limit' => dol_strlen($text),
83 'graph' => 1, // Set to 1 if it's a box graph
84 'sublink' => '',
85 'subtext' => $langs->trans("Filter"),
86 'subpicto' => 'filter.png',
87 'subclass' => 'linkobject boxfilter',
88 'target' => 'none' // Set '' to get target="_blank"
89 );
90
91 $dir = ''; // We don't need a path because image file will not be saved into disk
92 $prefix = '';
93 $socid = 0;
94 if ($user->socid) {
95 $socid = $user->socid;
96 }
97 if (!$user->hasRight('societe', 'client', 'voir')) {
98 $prefix .= 'private-'.$user->id.'-'; // If user has no permission to see all, output dir is specific to user
99 }
100
101 if ($user->hasRight('propal', 'lire')) {
102 $param_year = 'DOLUSER_box_'.$this->boxcode.'_year';
103 $param_shownb = 'DOLUSER_box_'.$this->boxcode.'_shownb';
104 $param_showtot = 'DOLUSER_box_'.$this->boxcode.'_showtot';
105
106 include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
107 include_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propalestats.class.php';
108 $autosetarray = preg_split("/[,;:]+/", GETPOST('DOL_AUTOSET_COOKIE'));
109 if (in_array('DOLUSER_box_'.$this->boxcode, $autosetarray)) {
110 $endyear = GETPOSTINT($param_year);
111 $shownb = GETPOST($param_shownb, 'alpha');
112 $showtot = GETPOST($param_showtot, 'alpha');
113 } else {
114 $tmparray = (!empty($_COOKIE['DOLUSER_box_'.$this->boxcode]) ? json_decode($_COOKIE['DOLUSER_box_'.$this->boxcode], true) : array());
115 $endyear = (!empty($tmparray['year']) ? $tmparray['year'] : '');
116 $shownb = (!empty($tmparray['shownb']) ? $tmparray['shownb'] : '');
117 $showtot = (!empty($tmparray['showtot']) ? $tmparray['showtot'] : '');
118 }
119 if (empty($shownb) && empty($showtot)) {
120 $shownb = 1;
121 $showtot = 1;
122 }
123 $nowarray = dol_getdate(dol_now(), true);
124 if (empty($endyear)) {
125 $endyear = $nowarray['year'];
126 }
127 $startyear = $endyear - getDolGlobalInt('MAIN_NB_OF_YEAR_IN_WIDGET_GRAPH', 3) + 1;
128
129 $WIDTH = (($shownb && $showtot) || !empty($conf->dol_optimize_smallscreen)) ? '256' : '320';
130 $HEIGHT = '192';
131
132 $stats = new PropaleStats($this->db, $socid, 0);
133
134 // Build graphic number of object. $data = array(array('Lib',val1,val2,val3),...)
135 if ($shownb) {
136 $data1 = $stats->getNbByMonthWithPrevYear($endyear, $startyear, (GETPOST('action', 'aZ09') == $refreshaction ? -1 : (3600 * 24)), ($WIDTH < 300 ? 2 : 0), $startmonth);
137 $datatype1 = array_pad(array(), ($endyear - $startyear + 1), 'bars');
138
139 $filenamenb = $dir."/".$prefix."propalsnbinyear-".$endyear.".png";
140 $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&amp;file=propalsnbinyear-'.$endyear.'.png';
141
142 $px1 = new DolGraph();
143 $mesg = $px1->isGraphKo();
144 if (!$mesg) {
145 $px1->SetType($datatype1);
146 $px1->SetData($data1);
147 unset($data1);
148 $i = $startyear;
149 $legend = array();
150 while ($i <= $endyear) {
151 if ($startmonth != 1) {
152 $legend[] = sprintf("%d/%d", $i - 2001, $i - 2000);
153 } else {
154 $legend[] = $i;
155 }
156 $i++;
157 }
158 $px1->SetLegend($legend);
159 $px1->SetMaxValue($px1->GetCeilMaxValue());
160 $px1->SetWidth($WIDTH);
161 $px1->SetHeight($HEIGHT);
162 $px1->SetYLabel($langs->trans("NumberOfProposals"));
163 $px1->SetShading(3);
164 $px1->SetHorizTickIncrement(1);
165 $px1->SetCssPrefix("cssboxes");
166 $px1->mode = 'depth';
167 $px1->SetTitle($langs->trans("NumberOfProposalsByMonth"));
168
169 $px1->draw($filenamenb, $fileurlnb);
170 }
171 }
172
173 // Build graphic number of object. $data = array(array('Lib',val1,val2,val3),...)
174 if ($showtot) {
175 $data2 = $stats->getAmountByMonthWithPrevYear($endyear, $startyear, (GETPOST('action', 'aZ09') == $refreshaction ? -1 : (3600 * 24)), ($WIDTH < 300 ? 2 : 0), $startmonth);
176 $datatype2 = array_pad(array(), ($endyear - $startyear + 1), 'bars');
177 //$datatype2 = array('lines','bars');
178
179 $filenamenb = $dir."/".$prefix."propalsamountinyear-".$endyear.".png";
180 $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&amp;file=propalsamountinyear-'.$endyear.'.png';
181
182 $px2 = new DolGraph();
183 $mesg = $px2->isGraphKo();
184 if (!$mesg) {
185 $px2->SetType($datatype2);
186 $px2->SetData($data2);
187 unset($data2);
188 $i = $startyear;
189 $legend = array();
190 while ($i <= $endyear) {
191 if ($startmonth != 1) {
192 $legend[] = sprintf("%d/%d", $i - 2001, $i - 2000);
193 } else {
194 $legend[] = $i;
195 }
196 $i++;
197 }
198 $px2->SetLegend($legend);
199 $px2->SetMaxValue($px2->GetCeilMaxValue());
200 $px2->SetWidth($WIDTH);
201 $px2->SetHeight($HEIGHT);
202 $px2->SetYLabel($langs->trans("AmountOfProposalsHT"));
203 $px2->SetShading(3);
204 $px2->SetHorizTickIncrement(1);
205 $px2->SetCssPrefix("cssboxes");
206 $px2->mode = 'depth';
207 $px2->SetTitle($langs->trans("AmountOfProposalsByMonthHT"));
208
209 $px2->draw($filenamenb, $fileurlnb);
210 }
211 }
212
213 if (empty($conf->use_javascript_ajax)) {
214 $langs->load("errors");
215 $mesg = $langs->trans("WarningFeatureDisabledWithDisplayOptimizedForBlindNoJs");
216 }
217
218 if (!$mesg) {
219 $stringtoshow = '';
220 $stringtoshow .= '<script nonce="'.getNonce().'" type="text/javascript">
221 jQuery(document).ready(function() {
222 jQuery("#idsubimg'.$this->boxcode.'").click(function() {
223 jQuery("#idfilter'.$this->boxcode.'").toggle();
224 });
225 });
226 </script>';
227 $stringtoshow .= '<div class="center hideobject divboxfilter" id="idfilter'.$this->boxcode.'">'; // hideobject is to start hidden
228 $stringtoshow .= '<form class="flat formboxfilter" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
229 $stringtoshow .= '<input type="hidden" name="token" value="'.newToken().'">';
230 $stringtoshow .= '<input type="hidden" name="action" value="'.$refreshaction.'">';
231 $stringtoshow .= '<input type="hidden" name="page_y" value="">';
232 $stringtoshow .= '<input type="hidden" name="DOL_AUTOSET_COOKIE" value="DOLUSER_box_'.$this->boxcode.':year,shownb,showtot">';
233 $stringtoshow .= '<input type="checkbox" id="'.$param_shownb.'" name="'.$param_shownb.'"'.($shownb ? ' checked' : '').'><label for="'.$param_shownb.'"> '.$langs->trans("NumberOfProposalsByMonth").'</label>';
234 $stringtoshow .= ' &nbsp; ';
235 $stringtoshow .= '<input type="checkbox" id="'.$param_showtot.'" name="'.$param_showtot.'"'.($showtot ? ' checked' : '').'><label for="'.$param_showtot.'"> '.$langs->trans("AmountOfProposalsByMonthHT").'</label>';
236 $stringtoshow .= '<br>';
237 $stringtoshow .= $langs->trans("Year").' <input class="flat" size="4" type="text" name="'.$param_year.'" value="'.$endyear.'">';
238 $stringtoshow .= '<input type="image" class="reposition inline-block valigntextbottom" alt="'.$langs->trans("Refresh").'" src="'.img_picto($langs->trans("Refresh"), 'refresh.png', '', 0, 1).'">';
239 $stringtoshow .= '</form>';
240 $stringtoshow .= '</div>';
241 if ($shownb && $showtot) {
242 $stringtoshow .= '<div class="fichecenter">';
243 $stringtoshow .= '<div class="fichehalfleft">';
244 }
245 if ($shownb) {
246 $stringtoshow .= $px1->show();
247 }
248 if ($shownb && $showtot) {
249 $stringtoshow .= '</div>';
250 $stringtoshow .= '<div class="fichehalfright">';
251 }
252 if ($showtot) {
253 $stringtoshow .= $px2->show();
254 }
255 if ($shownb && $showtot) {
256 $stringtoshow .= '</div>';
257 $stringtoshow .= '</div>';
258 }
259 $this->info_box_contents[0][0] = array(
260 'tr' => 'class="oddeven nohover"',
261 'td' => 'class="nohover center"',
262 'textnoformat' => $stringtoshow,
263 );
264 } else {
265 $this->info_box_contents[0][0] = array(
266 'tr' => 'class="oddeven nohover"',
267 'td' => 'class="nohover left"',
268 'maxlength' => 500,
269 'text' => $mesg,
270 );
271 }
272 } else {
273 $this->info_box_contents[0][0] = array(
274 'td' => 'class="nohover left"',
275 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
276 );
277 }
278 }
279
280
281
290 public function showBox($head = null, $contents = null, $nooutput = 0)
291 {
292 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
293 }
294}
Class to build graphs.
Class ModeleBoxes.
Class to manage proposals statistics.
Class to manage the box to show proposals per month graph.
loadBox($max=5)
Load data into info_box_contents array to show array later.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79