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',
96 $socid = $user->socid;
98 if (!$user->hasRight(
'societe',
'client',
'voir')) {
99 $prefix .=
'private-'.$user->id.
'-';
102 if ($user->hasRight(
'commande',
'lire')) {
103 $langs->load(
"orders");
105 $param_year =
'DOLUSER_box_'.$this->boxcode.
'_year';
106 $param_shownb =
'DOLUSER_box_'.$this->boxcode.
'_shownb';
107 $param_showtot =
'DOLUSER_box_'.$this->boxcode.
'_showtot';
109 include_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
110 include_once DOL_DOCUMENT_ROOT.
'/commande/class/commandestats.class.php';
111 $autosetarray = preg_split(
"/[,;:]+/",
GETPOST(
'DOL_AUTOSET_COOKIE'));
112 if (in_array(
'DOLUSER_box_'.$this->boxcode, $autosetarray)) {
114 $shownb =
GETPOST($param_shownb,
'alpha');
115 $showtot =
GETPOST($param_showtot,
'alpha');
117 $tmparray = (!empty($_COOKIE[
'DOLUSER_box_'.$this->boxcode]) ? json_decode($_COOKIE[
'DOLUSER_box_'.$this->boxcode],
true) : array());
118 $endyear = (!empty($tmparray[
'year']) ? $tmparray[
'year'] :
'');
119 $shownb = (!empty($tmparray[
'shownb']) ? $tmparray[
'shownb'] :
'');
120 $showtot = (!empty($tmparray[
'showtot']) ? $tmparray[
'showtot'] :
'');
122 if (empty($shownb) && empty($showtot)) {
127 if (empty($endyear)) {
128 $endyear = $nowarray[
'year'];
130 $startyear = $endyear -
getDolGlobalInt(
'MAIN_NB_OF_YEAR_IN_WIDGET_GRAPH', 3) + 1;
133 $WIDTH = (($shownb && $showtot) || !empty(
$conf->dol_optimize_smallscreen)) ?
'256' :
'320';
140 $data1 = $stats->getNbByMonthWithPrevYear($endyear, $startyear, (
GETPOST(
'action',
'aZ09') == $refreshaction ? -1 : (3600 * 24)), ($WIDTH < 300 ? 2 : 0), $startmonth);
142 $filenamenb = $dir.
"/".$prefix.
"ordersnbinyear-".$endyear.
".png";
144 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersnbinyear-'.$endyear.
'.png';
145 if ($mode ==
'supplier') {
146 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersnbinyear-'.$endyear.
'.png';
150 $mesg = $px1->isGraphKo();
152 $px1->SetData($data1);
156 while ($i <= $endyear) {
157 if ($startmonth != 1) {
158 $legend[] = sprintf(
"%d/%d", $i - 2001, $i - 2000);
164 $px1->SetLegend($legend);
165 $px1->SetMaxValue($px1->GetCeilMaxValue());
166 $px1->SetWidth($WIDTH);
167 $px1->SetHeight($HEIGHT);
168 $px1->SetYLabel($langs->trans(
"NumberOfOrders"));
170 $px1->SetHorizTickIncrement(1);
171 $px1->SetCssPrefix(
"cssboxes");
172 $px1->mode =
'depth';
173 $px1->SetTitle($langs->trans(
"NumberOfOrdersByMonth"));
175 $px1->draw($filenamenb, $fileurlnb);
181 $data2 = $stats->getAmountByMonthWithPrevYear($endyear, $startyear, (
GETPOST(
'action',
'aZ09') == $refreshaction ? -1 : (3600 * 24)), ($WIDTH < 300 ? 2 : 0), $startmonth);
183 $filenamenb = $dir.
"/".$prefix.
"ordersamountinyear-".$endyear.
".png";
185 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersamountinyear-'.$endyear.
'.png';
186 if ($mode ==
'supplier') {
187 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersamountinyear-'.$endyear.
'.png';
191 $mesg = $px2->isGraphKo();
193 $px2->SetData($data2);
197 while ($i <= $endyear) {
198 if ($startmonth != 1) {
199 $legend[] = sprintf(
"%d/%d", $i - 2001, $i - 2000);
205 $px2->SetLegend($legend);
206 $px2->SetMaxValue($px2->GetCeilMaxValue());
207 $px2->SetWidth($WIDTH);
208 $px2->SetHeight($HEIGHT);
209 $px2->SetYLabel($langs->trans(
"AmountOfOrdersHT"));
211 $px2->SetHorizTickIncrement(1);
212 $px2->SetCssPrefix(
"cssboxes");
213 $px2->mode =
'depth';
214 $px2->SetTitle($langs->trans(
"AmountOfOrdersByMonthHT"));
216 $px2->draw($filenamenb, $fileurlnb);
220 if (empty(
$conf->use_javascript_ajax)) {
221 $langs->load(
"errors");
222 $mesg = $langs->trans(
"WarningFeatureDisabledWithDisplayOptimizedForBlindNoJs");
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();
234 $stringtoshow .=
'<div class="center hideobject" id="idfilter'.$this->boxcode.
'">';
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="DOLUSER_box_'.$this->boxcode.
':year,shownb,showtot">';
240 $stringtoshow .=
'<input type="checkbox" id="'.$param_shownb.
'" name="'.$param_shownb.
'"'.($shownb ?
' checked' :
'').
'><label for="'.$param_shownb.
'"> '.$langs->trans(
"NumberOfOrdersByMonth").
'</label>';
241 $stringtoshow .=
' ';
242 $stringtoshow .=
'<input type="checkbox" id="'.$param_showtot.
'" name="'.$param_showtot.
'"'.($showtot ?
' checked' :
'').
'><label for="'.$param_showtot.
'"> '.$langs->trans(
"AmountOfOrdersByMonthHT").
'</label>';
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',
'', 0, 1).
'">';
246 $stringtoshow .=
'</form>';
247 $stringtoshow .=
'</div>';
248 if ($shownb && $showtot) {
249 $stringtoshow .=
'<div class="fichecenter">';
250 $stringtoshow .=
'<div class="fichehalfleft">';
252 if ($shownb && $px1 !==
null) {
253 $stringtoshow .= $px1->show();
255 if ($shownb && $showtot) {
256 $stringtoshow .=
'</div>';
257 $stringtoshow .=
'<div class="fichehalfright">';
259 if ($showtot && $px2 !==
null) {
260 $stringtoshow .= $px2->show();
262 if ($shownb && $showtot) {
263 $stringtoshow .=
'</div>';
264 $stringtoshow .=
'</div>';
266 $this->info_box_contents[0][0] = array(
267 'tr' =>
'class="oddeven nohover"',
268 'td' =>
'class="nohover center"',
269 'textnoformat' => $stringtoshow,
272 $this->info_box_contents[0][0] = array(
273 'tr' =>
'class="oddeven nohover"',
274 'td' =>
'class="nohover left"',
280 $this->info_box_contents[0][0] = array(
281 'td' =>
'class="nohover left"',
282 'text' =>
'<span class="opacitymedium">'.$langs->trans(
"ReadPermissionNotAllowed").
'</span>'