70 global $conf, $user, $langs;
74 $refreshaction =
'refresh_'.$this->boxcode;
79 $startmonth = $conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1;
80 if (empty($conf->global->GRAPH_USE_FISCAL_YEAR)) {
84 $text = $langs->trans(
"BoxCustomersOrdersPerMonth", $max);
85 $this->info_box_head = array(
90 'subtext'=>$langs->trans(
"Filter"),
91 'subpicto'=>
'filter.png',
92 'subclass'=>
'linkobject boxfilter',
100 $socid = $user->socid;
102 if (empty($user->rights->societe->client->voir) || $socid) {
103 $prefix .=
'private-'.$user->id.
'-';
106 if ($user->hasRight(
'commande',
'lire')) {
107 $langs->load(
"orders");
109 $param_year =
'DOLUSERCOOKIE_box_'.$this->boxcode.
'_year';
110 $param_shownb =
'DOLUSERCOOKIE_box_'.$this->boxcode.
'_shownb';
111 $param_showtot =
'DOLUSERCOOKIE_box_'.$this->boxcode.
'_showtot';
113 include_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
114 include_once DOL_DOCUMENT_ROOT.
'/commande/class/commandestats.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');
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'] :
'');
126 if (empty($shownb) && empty($showtot)) {
131 if (empty($endyear)) {
132 $endyear = $nowarray[
'year'];
134 $startyear = $endyear - (empty($conf->global->MAIN_NB_OF_YEAR_IN_WIDGET_GRAPH) ? 2 : ($conf->global->MAIN_NB_OF_YEAR_IN_WIDGET_GRAPH - 1));
137 $WIDTH = (($shownb && $showtot) || !empty($conf->dol_optimize_smallscreen)) ?
'256' :
'320';
144 $data1 = $stats->getNbByMonthWithPrevYear($endyear, $startyear, (
GETPOST(
'action',
'aZ09') == $refreshaction ?-1 : (3600 * 24)), ($WIDTH < 300 ? 2 : 0), $startmonth);
146 $filenamenb = $dir.
"/".$prefix.
"ordersnbinyear-".$endyear.
".png";
148 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersnbinyear-'.$endyear.
'.png';
149 if ($mode ==
'supplier') {
150 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersnbinyear-'.$endyear.
'.png';
154 $mesg = $px1->isGraphKo();
156 $px1->SetData($data1);
160 while ($i <= $endyear) {
161 if ($startmonth != 1) {
162 $legend[] = sprintf(
"%d/%d", $i - 2001, $i - 2000);
168 $px1->SetLegend($legend);
169 $px1->SetMaxValue($px1->GetCeilMaxValue());
170 $px1->SetWidth($WIDTH);
171 $px1->SetHeight($HEIGHT);
172 $px1->SetYLabel($langs->trans(
"NumberOfOrders"));
174 $px1->SetHorizTickIncrement(1);
175 $px1->SetCssPrefix(
"cssboxes");
176 $px1->mode =
'depth';
177 $px1->SetTitle($langs->trans(
"NumberOfOrdersByMonth"));
179 $px1->draw($filenamenb, $fileurlnb);
185 $data2 = $stats->getAmountByMonthWithPrevYear($endyear, $startyear, (
GETPOST(
'action',
'aZ09') == $refreshaction ?-1 : (3600 * 24)), ($WIDTH < 300 ? 2 : 0), $startmonth);
187 $filenamenb = $dir.
"/".$prefix.
"ordersamountinyear-".$endyear.
".png";
189 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersamountinyear-'.$endyear.
'.png';
190 if ($mode ==
'supplier') {
191 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersamountinyear-'.$endyear.
'.png';
195 $mesg = $px2->isGraphKo();
197 $px2->SetData($data2);
201 while ($i <= $endyear) {
202 if ($startmonth != 1) {
203 $legend[] = sprintf(
"%d/%d", $i - 2001, $i - 2000);
209 $px2->SetLegend($legend);
210 $px2->SetMaxValue($px2->GetCeilMaxValue());
211 $px2->SetWidth($WIDTH);
212 $px2->SetHeight($HEIGHT);
213 $px2->SetYLabel($langs->trans(
"AmountOfOrdersHT"));
215 $px2->SetHorizTickIncrement(1);
216 $px2->SetCssPrefix(
"cssboxes");
217 $px2->mode =
'depth';
218 $px2->SetTitle($langs->trans(
"AmountOfOrdersByMonthHT"));
220 $px2->draw($filenamenb, $fileurlnb);
224 if (empty($conf->use_javascript_ajax)) {
225 $langs->load(
"errors");
226 $mesg = $langs->trans(
"WarningFeatureDisabledWithDisplayOptimizedForBlindNoJs");
231 $stringtoshow .=
'<script nonce="'.getNonce().
'" type="text/javascript">
232 jQuery(document).ready(function() {
233 jQuery("#idsubimg'.$this->boxcode.
'").click(function() {
234 jQuery("#idfilter'.$this->boxcode.
'").toggle();
238 $stringtoshow .=
'<div class="center hideobject" id="idfilter'.$this->boxcode.
'">';
239 $stringtoshow .=
'<form class="flat formboxfilter" method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
240 $stringtoshow .=
'<input type="hidden" name="token" value="'.newToken().
'">';
241 $stringtoshow .=
'<input type="hidden" name="action" value="'.$refreshaction.
'">';
242 $stringtoshow .=
'<input type="hidden" name="page_y" value="">';
243 $stringtoshow .=
'<input type="hidden" name="DOL_AUTOSET_COOKIE" value="DOLUSERCOOKIE_box_'.$this->boxcode.
':year,shownb,showtot">';
244 $stringtoshow .=
'<input type="checkbox" name="'.$param_shownb.
'"'.($shownb ?
' checked' :
'').
'> '.$langs->trans(
"NumberOfOrdersByMonth");
245 $stringtoshow .=
' ';
246 $stringtoshow .=
'<input type="checkbox" name="'.$param_showtot.
'"'.($showtot ?
' checked' :
'').
'> '.$langs->trans(
"AmountOfOrdersByMonthHT");
247 $stringtoshow .=
'<br>';
248 $stringtoshow .= $langs->trans(
"Year").
' <input class="flat" size="4" type="text" name="'.$param_year.
'" value="'.$endyear.
'">';
249 $stringtoshow .=
'<input type="image" class="reposition inline-block valigntextbottom" alt="'.$langs->trans(
"Refresh").
'" src="'.
img_picto($langs->trans(
"Refresh"),
'refresh.png',
'',
'', 1).
'">';
250 $stringtoshow .=
'</form>';
251 $stringtoshow .=
'</div>';
252 if ($shownb && $showtot) {
253 $stringtoshow .=
'<div class="fichecenter">';
254 $stringtoshow .=
'<div class="fichehalfleft">';
257 $stringtoshow .= $px1->show();
259 if ($shownb && $showtot) {
260 $stringtoshow .=
'</div>';
261 $stringtoshow .=
'<div class="fichehalfright">';
264 $stringtoshow .= $px2->show();
266 if ($shownb && $showtot) {
267 $stringtoshow .=
'</div>';
268 $stringtoshow .=
'</div>';
270 $this->info_box_contents[0][0] = array(
271 'tr'=>
'class="oddeven nohover"',
272 'td' =>
'class="nohover center"',
273 'textnoformat'=>$stringtoshow,
276 $this->info_box_contents[0][0] = array(
277 'tr'=>
'class="oddeven nohover"',
278 'td' =>
'class="nohover left"',
284 $this->info_box_contents[0][0] = array(
285 'td' =>
'class="nohover opacitymedium left"',
286 'text' => $langs->trans(
"ReadPermissionNotAllowed")