62 global $conf, $user, $langs;
66 $refreshaction =
'refresh_'.$this->boxcode;
68 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
75 $text = $langs->trans(
"BoxSuppliersOrdersPerMonth", $max);
76 $this->info_box_head = array(
81 'subtext'=>$langs->trans(
"Filter"),
82 'subpicto'=>
'filter.png',
83 'subclass'=>
'linkobject boxfilter',
91 $socid = $user->socid;
93 if (!$user->hasRight(
'societe',
'client',
'voir')) {
94 $prefix .=
'private-'.$user->id.
'-';
97 if ($user->hasRight(
'fournisseur',
'commande',
'lire')) {
98 $langs->load(
"orders");
100 $param_year =
'DOLUSERCOOKIE_box_'.$this->boxcode.
'_year';
101 $param_shownb =
'DOLUSERCOOKIE_box_'.$this->boxcode.
'_shownb';
102 $param_showtot =
'DOLUSERCOOKIE_box_'.$this->boxcode.
'_showtot';
104 include_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
105 include_once DOL_DOCUMENT_ROOT.
'/commande/class/commandestats.class.php';
106 $autosetarray = preg_split(
"/[,;:]+/",
GETPOST(
'DOL_AUTOSET_COOKIE'));
107 if (in_array(
'DOLUSERCOOKIE_box_'.$this->boxcode, $autosetarray)) {
109 $shownb =
GETPOST($param_shownb,
'alpha');
110 $showtot =
GETPOST($param_showtot,
'alpha');
112 $tmparray = (!empty($_COOKIE[
'DOLUSERCOOKIE_box_'.$this->boxcode]) ? json_decode($_COOKIE[
'DOLUSERCOOKIE_box_'.$this->boxcode],
true) : array());
113 $endyear = (!empty($tmparray[
'year']) ? $tmparray[
'year'] :
'');
114 $shownb = (!empty($tmparray[
'shownb']) ? $tmparray[
'shownb'] :
'');
115 $showtot = (!empty($tmparray[
'showtot']) ? $tmparray[
'showtot'] :
'');
117 if (empty($shownb) && empty($showtot)) {
122 if (empty($endyear)) {
123 $endyear = $nowarray[
'year'];
125 $startyear = $endyear -
getDolGlobalInt(
'MAIN_NB_OF_YEAR_IN_WIDGET_GRAPH', 3) + 1;
128 $WIDTH = (($shownb && $showtot) || !empty($conf->dol_optimize_smallscreen)) ?
'256' :
'320';
135 $data1 = $stats->getNbByMonthWithPrevYear($endyear, $startyear, (
GETPOST(
'action',
'aZ09') == $refreshaction ? -1 : (3600 * 24)), ($WIDTH < 300 ? 2 : 0), $startmonth);
137 $filenamenb = $dir.
"/".$prefix.
"orderssuppliernbinyear-".$endyear.
".png";
139 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersnbinyear-'.$endyear.
'.png';
140 if ($mode ==
'supplier') {
141 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=orderssuppliernbinyear-'.$endyear.
'.png';
145 $mesg = $px1->isGraphKo();
147 $px1->SetData($data1);
151 while ($i <= $endyear) {
152 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);
176 $data2 = $stats->getAmountByMonthWithPrevYear($endyear, $startyear, (
GETPOST(
'action',
'aZ09') == $refreshaction ? -1 : (3600 * 24)), ($WIDTH < 300 ? 2 : 0), $startmonth);
178 $filenamenb = $dir.
"/".$prefix.
"orderssupplieramountinyear-".$endyear.
".png";
180 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersamountinyear-'.$endyear.
'.png';
181 if ($mode ==
'supplier') {
182 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=orderssupplieramountinyear-'.$endyear.
'.png';
186 $mesg = $px2->isGraphKo();
188 $px2->SetData($data2);
192 while ($i <= $endyear) {
193 if ($startmonth != 1) {
194 $legend[] = sprintf(
"%d/%d", $i - 2001, $i - 2000);
200 $px2->SetLegend($legend);
201 $px2->SetMaxValue($px2->GetCeilMaxValue());
202 $px2->SetWidth($WIDTH);
203 $px2->SetHeight($HEIGHT);
204 $px2->SetYLabel($langs->trans(
"AmountOfOrdersHT"));
206 $px2->SetHorizTickIncrement(1);
207 $px2->SetCssPrefix(
"cssboxes");
208 $px2->mode =
'depth';
209 $px2->SetTitle($langs->trans(
"AmountOfOrdersByMonthHT"));
211 $px2->draw($filenamenb, $fileurlnb);
215 if (empty($conf->use_javascript_ajax)) {
216 $langs->load(
"errors");
217 $mesg = $langs->trans(
"WarningFeatureDisabledWithDisplayOptimizedForBlindNoJs");
222 $stringtoshow .=
'<script nonce="'.getNonce().
'" type="text/javascript">
223 jQuery(document).ready(function() {
224 jQuery("#idsubimg'.$this->boxcode.
'").click(function() {
225 jQuery("#idfilter'.$this->boxcode.
'").toggle();
229 $stringtoshow .=
'<div class="center hideobject" id="idfilter'.$this->boxcode.
'">';
230 $stringtoshow .=
'<form class="flat formboxfilter" method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
231 $stringtoshow .=
'<input type="hidden" name="token" value="'.newToken().
'">';
232 $stringtoshow .=
'<input type="hidden" name="action" value="'.$refreshaction.
'">';
233 $stringtoshow .=
'<input type="hidden" name="page_y" value="">';
234 $stringtoshow .=
'<input type="hidden" name="DOL_AUTOSET_COOKIE" value="DOLUSERCOOKIE_box_'.$this->boxcode.
':year,shownb,showtot">';
235 $stringtoshow .=
'<input type="checkbox" name="'.$param_shownb.
'"'.($shownb ?
' checked' :
'').
'> '.$langs->trans(
"NumberOfOrdersByMonth");
236 $stringtoshow .=
' ';
237 $stringtoshow .=
'<input type="checkbox" name="'.$param_showtot.
'"'.($showtot ?
' checked' :
'').
'> '.$langs->trans(
"AmountOfOrdersByMonthHT");
238 $stringtoshow .=
'<br>';
239 $stringtoshow .= $langs->trans(
"Year").
' <input class="flat" size="4" type="text" name="'.$param_year.
'" value="'.$endyear.
'">';
240 $stringtoshow .=
'<input type="image" class="reposition inline-block valigntextbottom" alt="'.$langs->trans(
"Refresh").
'" src="'.
img_picto($langs->trans(
"Refresh"),
'refresh.png',
'',
'', 1).
'">';
241 $stringtoshow .=
'</form>';
242 $stringtoshow .=
'</div>';
243 if ($shownb && $showtot) {
244 $stringtoshow .=
'<div class="fichecenter">';
245 $stringtoshow .=
'<div class="fichehalfleft">';
248 $stringtoshow .= $px1->show();
250 if ($shownb && $showtot) {
251 $stringtoshow .=
'</div>';
252 $stringtoshow .=
'<div class="fichehalfright">';
255 $stringtoshow .= $px2->show();
257 if ($shownb && $showtot) {
258 $stringtoshow .=
'</div>';
259 $stringtoshow .=
'</div>';
261 $this->info_box_contents[0][0] = array(
262 'tr'=>
'class="oddeven nohover"',
263 'td' =>
'class="nohover center"',
264 'textnoformat'=>$stringtoshow,
267 $this->info_box_contents[0][0] = array(
268 'tr'=>
'class="oddeven nohover"',
269 'td' =>
'class="nohover left"',
275 $this->info_box_contents[0][0] = array(
276 'td' =>
'class="nohover left"',
277 'text' =>
'<span class="opacitymedium">'.$langs->trans(
"ReadPermissionNotAllowed").
'</span>'