23 include_once DOL_DOCUMENT_ROOT.
'/core/boxes/modules_boxes.php';
31 public $boxcode =
"orderspermonth";
32 public $boximg =
"object_order";
33 public $boxlabel =
"BoxCustomersOrdersPerMonth";
34 public $depends = array(
"commande");
41 public $info_box_head = array();
42 public $info_box_contents = array();
57 $this->hidden = !($user->rights->commande->lire);
68 global $conf, $user, $langs;
72 $refreshaction =
'refresh_'.$this->boxcode;
77 $startmonth = $conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1;
78 if (empty($conf->global->GRAPH_USE_FISCAL_YEAR)) $startmonth = 1;
80 $text = $langs->trans(
"BoxCustomersOrdersPerMonth", $max);
81 $this->info_box_head = array(
86 'subtext'=>$langs->trans(
"Filter"),
87 'subpicto'=>
'filter.png',
88 'subclass'=>
'linkobject boxfilter',
95 if ($user->socid) $socid = $user->socid;
96 if (!$user->rights->societe->client->voir || $socid) $prefix .=
'private-'.$user->id.
'-';
98 if ($user->rights->commande->lire)
100 $langs->load(
"orders");
102 $param_year =
'DOLUSERCOOKIE_box_'.$this->boxcode.
'_year';
103 $param_shownb =
'DOLUSERCOOKIE_box_'.$this->boxcode.
'_shownb';
104 $param_showtot =
'DOLUSERCOOKIE_box_'.$this->boxcode.
'_showtot';
106 include_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
107 include_once DOL_DOCUMENT_ROOT.
'/commande/class/commandestats.class.php';
108 $autosetarray = preg_split(
"/[,;:]+/",
GETPOST(
'DOL_AUTOSET_COOKIE'));
109 if (in_array(
'DOLUSERCOOKIE_box_'.$this->boxcode, $autosetarray))
111 $endyear =
GETPOST($param_year,
'int');
112 $shownb =
GETPOST($param_shownb,
'alpha');
113 $showtot =
GETPOST($param_showtot,
'alpha');
115 $tmparray = json_decode($_COOKIE[
'DOLUSERCOOKIE_box_'.$this->boxcode],
true);
116 $endyear = $tmparray[
'year'];
117 $shownb = $tmparray[
'shownb'];
118 $showtot = $tmparray[
'showtot'];
120 if (empty($shownb) && empty($showtot)) { $shownb = 1; $showtot = 1; }
122 if (empty($endyear)) $endyear = $nowarray[
'year'];
123 $startyear = $endyear - (empty($conf->global->MAIN_NB_OF_YEAR_IN_WIDGET_GRAPH) ? 1 : $conf->global->MAIN_NB_OF_YEAR_IN_WIDGET_GRAPH);
126 $WIDTH = (($shownb && $showtot) || !empty($conf->dol_optimize_smallscreen)) ?
'256' :
'320';
134 $data1 = $stats->getNbByMonthWithPrevYear($endyear, $startyear, (
GETPOST(
'action',
'aZ09') == $refreshaction ?-1 : (3600 * 24)), ($WIDTH < 300 ? 2 : 0), $startmonth);
136 $filenamenb = $dir.
"/".$prefix.
"ordersnbinyear-".$endyear.
".png";
138 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersnbinyear-'.$endyear.
'.png';
139 if ($mode ==
'supplier') $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersnbinyear-'.$endyear.
'.png';
142 $mesg = $px1->isGraphKo();
145 $px1->SetData($data1);
149 while ($i <= $endyear)
151 if ($startmonth != 1)
153 $legend[] = sprintf(
"%d/%d", $i - 2001, $i - 2000);
159 $px1->SetLegend($legend);
160 $px1->SetMaxValue($px1->GetCeilMaxValue());
161 $px1->SetWidth($WIDTH);
162 $px1->SetHeight($HEIGHT);
163 $px1->SetYLabel($langs->trans(
"NumberOfOrders"));
165 $px1->SetHorizTickIncrement(1);
166 $px1->SetCssPrefix(
"cssboxes");
167 $px1->mode =
'depth';
168 $px1->SetTitle($langs->trans(
"NumberOfOrdersByMonth"));
170 $px1->draw($filenamenb, $fileurlnb);
177 $data2 = $stats->getAmountByMonthWithPrevYear($endyear, $startyear, (
GETPOST(
'action',
'aZ09') == $refreshaction ?-1 : (3600 * 24)), ($WIDTH < 300 ? 2 : 0), $startmonth);
179 $filenamenb = $dir.
"/".$prefix.
"ordersamountinyear-".$endyear.
".png";
181 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersamountinyear-'.$endyear.
'.png';
182 if ($mode ==
'supplier') $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersamountinyear-'.$endyear.
'.png';
185 $mesg = $px2->isGraphKo();
188 $px2->SetData($data2);
190 $i = $startyear; $legend = array();
191 while ($i <= $endyear)
193 if ($startmonth != 1)
195 $legend[] = sprintf(
"%d/%d", $i - 2001, $i - 2000);
201 $px2->SetLegend($legend);
202 $px2->SetMaxValue($px2->GetCeilMaxValue());
203 $px2->SetWidth($WIDTH);
204 $px2->SetHeight($HEIGHT);
205 $px2->SetYLabel($langs->trans(
"AmountOfOrdersHT"));
207 $px2->SetHorizTickIncrement(1);
208 $px2->SetCssPrefix(
"cssboxes");
209 $px2->mode =
'depth';
210 $px2->SetTitle($langs->trans(
"AmountOfOrdersByMonthHT"));
212 $px2->draw($filenamenb, $fileurlnb);
216 if (empty($conf->use_javascript_ajax))
218 $langs->load(
"errors");
219 $mesg = $langs->trans(
"WarningFeatureDisabledWithDisplayOptimizedForBlindNoJs");
225 $stringtoshow .=
'<script type="text/javascript" language="javascript">
226 jQuery(document).ready(function() {
227 jQuery("#idsubimg'.$this->boxcode.
'").click(function() {
228 jQuery("#idfilter'.$this->boxcode.
'").toggle();
232 $stringtoshow .=
'<div class="center hideobject" id="idfilter'.$this->boxcode.
'">';
233 $stringtoshow .=
'<form class="flat formboxfilter" method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
234 $stringtoshow .=
'<input type="hidden" name="token" value="'.newToken().
'">';
235 $stringtoshow .=
'<input type="hidden" name="action" value="'.$refreshaction.
'">';
236 $stringtoshow .=
'<input type="hidden" name="page_y" value="">';
237 $stringtoshow .=
'<input type="hidden" name="DOL_AUTOSET_COOKIE" value="DOLUSERCOOKIE_box_'.$this->boxcode.
':year,shownb,showtot">';
238 $stringtoshow .=
'<input type="checkbox" name="'.$param_shownb.
'"'.($shownb ?
' checked' :
'').
'> '.$langs->trans(
"NumberOfOrdersByMonth");
239 $stringtoshow .=
' ';
240 $stringtoshow .=
'<input type="checkbox" name="'.$param_showtot.
'"'.($showtot ?
' checked' :
'').
'> '.$langs->trans(
"AmountOfOrdersByMonthHT");
241 $stringtoshow .=
'<br>';
242 $stringtoshow .= $langs->trans(
"Year").
' <input class="flat" size="4" type="text" name="'.$param_year.
'" value="'.$endyear.
'">';
243 $stringtoshow .=
'<input type="image" class="reposition inline-block valigntextbottom" alt="'.$langs->trans(
"Refresh").
'" src="'.
img_picto($langs->trans(
"Refresh"),
'refresh.png',
'',
'', 1).
'">';
244 $stringtoshow .=
'</form>';
245 $stringtoshow .=
'</div>';
246 if ($shownb && $showtot)
248 $stringtoshow .=
'<div class="fichecenter">';
249 $stringtoshow .=
'<div class="fichehalfleft">';
251 if ($shownb) $stringtoshow .= $px1->show();
252 if ($shownb && $showtot)
254 $stringtoshow .=
'</div>';
255 $stringtoshow .=
'<div class="fichehalfright">';
257 if ($showtot) $stringtoshow .= $px2->show();
258 if ($shownb && $showtot)
260 $stringtoshow .=
'</div>';
261 $stringtoshow .=
'</div>';
263 $this->info_box_contents[0][0] = array(
264 'tr'=>
'class="oddeven nohover"',
265 'td' =>
'class="nohover center"',
266 'textnoformat'=>$stringtoshow,
269 $this->info_box_contents[0][0] = array(
270 'tr'=>
'class="oddeven nohover"',
271 'td' =>
'class="nohover left"',
277 $this->info_box_contents[0][0] = array(
278 'td' =>
'class="nohover opacitymedium left"',
279 'text' => $langs->trans(
"ReadPermissionNotAllowed")
292 public function showBox($head = null, $contents = null, $nooutput = 0)
294 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
loadBox($max=5)
Load data into info_box_contents array to show array later.
dol_now($mode= 'auto')
Return date for now.
__construct($db, $param)
Constructor.
Class to manage the box to show last orders.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
$conf db
API class for accounts.
dol_strlen($string, $stringencoding= 'UTF-8')
Make a strlen call.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_getdate($timestamp, $fast=false, $forcetimezone= '')
Return an array with locale date info.
Class to manage order statistics (customer and supplier)