63 global $conf, $user, $langs;
67 $refreshaction =
'refresh_'.$this->boxcode;
77 $text = $langs->trans(
"BoxCustomersOrdersPerMonth", $max);
78 $this->info_box_head = array(
83 'subtext' => $langs->trans(
"Filter"),
84 'subpicto' =>
'filter.png',
85 'subclass' =>
'linkobject boxfilter',
93 $socid = $user->socid;
95 if (!$user->hasRight(
'societe',
'client',
'voir')) {
96 $prefix .=
'private-'.$user->id.
'-';
99 if ($user->hasRight(
'commande',
'lire')) {
100 $langs->load(
"orders");
102 $param_year =
'DOLUSER_box_'.$this->boxcode.
'_year';
103 $param_shownb =
'DOLUSER_box_'.$this->boxcode.
'_shownb';
104 $param_showtot =
'DOLUSER_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(
'DOLUSER_box_'.$this->boxcode, $autosetarray)) {
111 $shownb =
GETPOST($param_shownb,
'alpha');
112 $showtot =
GETPOST($param_showtot,
'alpha');
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'] :
'');
119 if (empty($shownb) && empty($showtot)) {
124 if (empty($endyear)) {
125 $endyear = $nowarray[
'year'];
127 $startyear = $endyear -
getDolGlobalInt(
'MAIN_NB_OF_YEAR_IN_WIDGET_GRAPH', 3) + 1;
130 $WIDTH = (($shownb && $showtot) || !empty($conf->dol_optimize_smallscreen)) ?
'256' :
'320';
137 $data1 = $stats->getNbByMonthWithPrevYear($endyear, $startyear, (
GETPOST(
'action',
'aZ09') == $refreshaction ? -1 : (3600 * 24)), ($WIDTH < 300 ? 2 : 0), $startmonth);
139 $filenamenb = $dir.
"/".$prefix.
"ordersnbinyear-".$endyear.
".png";
141 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersnbinyear-'.$endyear.
'.png';
142 if ($mode ==
'supplier') {
143 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersnbinyear-'.$endyear.
'.png';
147 $mesg = $px1->isGraphKo();
149 $px1->SetData($data1);
153 while ($i <= $endyear) {
154 if ($startmonth != 1) {
155 $legend[] = sprintf(
"%d/%d", $i - 2001, $i - 2000);
161 $px1->SetLegend($legend);
162 $px1->SetMaxValue($px1->GetCeilMaxValue());
163 $px1->SetWidth($WIDTH);
164 $px1->SetHeight($HEIGHT);
165 $px1->SetYLabel($langs->trans(
"NumberOfOrders"));
167 $px1->SetHorizTickIncrement(1);
168 $px1->SetCssPrefix(
"cssboxes");
169 $px1->mode =
'depth';
170 $px1->SetTitle($langs->trans(
"NumberOfOrdersByMonth"));
172 $px1->draw($filenamenb, $fileurlnb);
178 $data2 = $stats->getAmountByMonthWithPrevYear($endyear, $startyear, (
GETPOST(
'action',
'aZ09') == $refreshaction ? -1 : (3600 * 24)), ($WIDTH < 300 ? 2 : 0), $startmonth);
180 $filenamenb = $dir.
"/".$prefix.
"ordersamountinyear-".$endyear.
".png";
182 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersamountinyear-'.$endyear.
'.png';
183 if ($mode ==
'supplier') {
184 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersamountinyear-'.$endyear.
'.png';
188 $mesg = $px2->isGraphKo();
190 $px2->SetData($data2);
194 while ($i <= $endyear) {
195 if ($startmonth != 1) {
196 $legend[] = sprintf(
"%d/%d", $i - 2001, $i - 2000);
202 $px2->SetLegend($legend);
203 $px2->SetMaxValue($px2->GetCeilMaxValue());
204 $px2->SetWidth($WIDTH);
205 $px2->SetHeight($HEIGHT);
206 $px2->SetYLabel($langs->trans(
"AmountOfOrdersHT"));
208 $px2->SetHorizTickIncrement(1);
209 $px2->SetCssPrefix(
"cssboxes");
210 $px2->mode =
'depth';
211 $px2->SetTitle($langs->trans(
"AmountOfOrdersByMonthHT"));
213 $px2->draw($filenamenb, $fileurlnb);
217 if (empty($conf->use_javascript_ajax)) {
218 $langs->load(
"errors");
219 $mesg = $langs->trans(
"WarningFeatureDisabledWithDisplayOptimizedForBlindNoJs");
224 $stringtoshow .=
'<script nonce="'.getNonce().
'" type="text/javascript">
225 jQuery(document).ready(function() {
226 jQuery("#idsubimg'.$this->boxcode.
'").click(function() {
227 jQuery("#idfilter'.$this->boxcode.
'").toggle();
231 $stringtoshow .=
'<div class="center hideobject" id="idfilter'.$this->boxcode.
'">';
232 $stringtoshow .=
'<form class="flat formboxfilter" method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
233 $stringtoshow .=
'<input type="hidden" name="token" value="'.newToken().
'">';
234 $stringtoshow .=
'<input type="hidden" name="action" value="'.$refreshaction.
'">';
235 $stringtoshow .=
'<input type="hidden" name="page_y" value="">';
236 $stringtoshow .=
'<input type="hidden" name="DOL_AUTOSET_COOKIE" value="DOLUSER_box_'.$this->boxcode.
':year,shownb,showtot">';
237 $stringtoshow .=
'<input type="checkbox" id="'.$param_shownb.
'" name="'.$param_shownb.
'"'.($shownb ?
' checked' :
'').
'><label for="'.$param_shownb.
'"> '.$langs->trans(
"NumberOfOrdersByMonth").
'</label>';
238 $stringtoshow .=
' ';
239 $stringtoshow .=
'<input type="checkbox" id="'.$param_showtot.
'" name="'.$param_showtot.
'"'.($showtot ?
' checked' :
'').
'><label for="'.$param_showtot.
'"> '.$langs->trans(
"AmountOfOrdersByMonthHT").
'</label>';
240 $stringtoshow .=
'<br>';
241 $stringtoshow .= $langs->trans(
"Year").
' <input class="flat" size="4" type="text" name="'.$param_year.
'" value="'.$endyear.
'">';
242 $stringtoshow .=
'<input type="image" class="reposition inline-block valigntextbottom" alt="'.$langs->trans(
"Refresh").
'" src="'.
img_picto($langs->trans(
"Refresh"),
'refresh.png',
'', 0, 1).
'">';
243 $stringtoshow .=
'</form>';
244 $stringtoshow .=
'</div>';
245 if ($shownb && $showtot) {
246 $stringtoshow .=
'<div class="fichecenter">';
247 $stringtoshow .=
'<div class="fichehalfleft">';
250 $stringtoshow .= $px1->show();
252 if ($shownb && $showtot) {
253 $stringtoshow .=
'</div>';
254 $stringtoshow .=
'<div class="fichehalfright">';
257 $stringtoshow .= $px2->show();
259 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 left"',
279 'text' =>
'<span class="opacitymedium">'.$langs->trans(
"ReadPermissionNotAllowed").
'</span>'