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