63 global $conf, $user, $langs;
67 $refreshaction =
'refresh_'.$this->boxcode;
69 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
76 $text = $langs->trans(
"BoxSuppliersOrdersPerMonth", $max);
77 $this->info_box_head = array(
82 'subtext' => $langs->trans(
"Filter"),
83 'subpicto' =>
'filter.png',
84 'subclass' =>
'linkobject boxfilter',
92 $socid = $user->socid;
94 if (!$user->hasRight(
'societe',
'client',
'voir')) {
95 $prefix .=
'private-'.$user->id.
'-';
98 if ($user->hasRight(
'fournisseur',
'commande',
'lire')) {
99 $langs->load(
"orders");
101 $param_year =
'DOLUSER_box_'.$this->boxcode.
'_year';
102 $param_shownb =
'DOLUSER_box_'.$this->boxcode.
'_shownb';
103 $param_showtot =
'DOLUSER_box_'.$this->boxcode.
'_showtot';
105 include_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
106 include_once DOL_DOCUMENT_ROOT.
'/commande/class/commandestats.class.php';
107 $autosetarray = preg_split(
"/[,;:]+/",
GETPOST(
'DOL_AUTOSET_COOKIE'));
108 if (in_array(
'DOLUSER_box_'.$this->boxcode, $autosetarray)) {
110 $shownb =
GETPOST($param_shownb,
'alpha');
111 $showtot =
GETPOST($param_showtot,
'alpha');
113 $tmparray = (!empty($_COOKIE[
'DOLUSER_box_'.$this->boxcode]) ? json_decode($_COOKIE[
'DOLUSER_box_'.$this->boxcode],
true) : array());
114 $endyear = (!empty($tmparray[
'year']) ? $tmparray[
'year'] :
'');
115 $shownb = (!empty($tmparray[
'shownb']) ? $tmparray[
'shownb'] :
'');
116 $showtot = (!empty($tmparray[
'showtot']) ? $tmparray[
'showtot'] :
'');
118 if (empty($shownb) && empty($showtot)) {
123 if (empty($endyear)) {
124 $endyear = $nowarray[
'year'];
126 $startyear = $endyear -
getDolGlobalInt(
'MAIN_NB_OF_YEAR_IN_WIDGET_GRAPH', 3) + 1;
129 $WIDTH = (($shownb && $showtot) || !empty($conf->dol_optimize_smallscreen)) ?
'256' :
'320';
136 $data1 = $stats->getNbByMonthWithPrevYear($endyear, $startyear, (
GETPOST(
'action',
'aZ09') == $refreshaction ? -1 : (3600 * 24)), ($WIDTH < 300 ? 2 : 0), $startmonth);
138 $filenamenb = $dir.
"/".$prefix.
"orderssuppliernbinyear-".$endyear.
".png";
140 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersnbinyear-'.$endyear.
'.png';
141 if ($mode ==
'supplier') {
142 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=orderssuppliernbinyear-'.$endyear.
'.png';
146 $mesg = $px1->isGraphKo();
148 $px1->SetData($data1);
152 while ($i <= $endyear) {
153 if ($startmonth != 1) {
154 $legend[] = sprintf(
"%d/%d", $i - 2001, $i - 2000);
160 $px1->SetLegend($legend);
161 $px1->SetMaxValue($px1->GetCeilMaxValue());
162 $px1->SetWidth($WIDTH);
163 $px1->SetHeight($HEIGHT);
164 $px1->SetYLabel($langs->trans(
"NumberOfOrders"));
166 $px1->SetHorizTickIncrement(1);
167 $px1->SetCssPrefix(
"cssboxes");
168 $px1->mode =
'depth';
169 $px1->SetTitle($langs->trans(
"NumberOfOrdersByMonth"));
171 $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.
"orderssupplieramountinyear-".$endyear.
".png";
181 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersamountinyear-'.$endyear.
'.png';
182 if ($mode ==
'supplier') {
183 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=orderssupplieramountinyear-'.$endyear.
'.png';
187 $mesg = $px2->isGraphKo();
189 $px2->SetData($data2);
193 while ($i <= $endyear) {
194 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)) {
217 $langs->load(
"errors");
218 $mesg = $langs->trans(
"WarningFeatureDisabledWithDisplayOptimizedForBlindNoJs");
223 $stringtoshow .=
'<script nonce="'.getNonce().
'" type="text/javascript">
224 jQuery(document).ready(function() {
225 jQuery("#idsubimg'.$this->boxcode.
'").click(function() {
226 jQuery("#idfilter'.$this->boxcode.
'").toggle();
230 $stringtoshow .=
'<div class="center hideobject" id="idfilter'.$this->boxcode.
'">';
231 $stringtoshow .=
'<form class="flat formboxfilter" method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
232 $stringtoshow .=
'<input type="hidden" name="token" value="'.newToken().
'">';
233 $stringtoshow .=
'<input type="hidden" name="action" value="'.$refreshaction.
'">';
234 $stringtoshow .=
'<input type="hidden" name="page_y" value="">';
235 $stringtoshow .=
'<input type="hidden" name="DOL_AUTOSET_COOKIE" value="DOLUSER_box_'.$this->boxcode.
':year,shownb,showtot">';
236 $stringtoshow .=
'<input type="checkbox" id="'.$param_shownb.
'" name="'.$param_shownb.
'"'.($shownb ?
' checked' :
'').
'><label for="'.$param_shownb.
'"> '.$langs->trans(
"NumberOfOrdersByMonth").
'</label>';
237 $stringtoshow .=
' ';
238 $stringtoshow .=
'<input type="checkbox" id="'.$param_showtot.
'" name="'.$param_showtot.
'"'.($showtot ?
' checked' :
'').
'><label for="'.$param_showtot.
'"> '.$langs->trans(
"AmountOfOrdersByMonthHT").
'</label>';
239 $stringtoshow .=
'<br>';
240 $stringtoshow .= $langs->trans(
"Year").
' <input class="flat" size="4" type="text" name="'.$param_year.
'" value="'.$endyear.
'">';
241 $stringtoshow .=
'<input type="image" class="reposition inline-block valigntextbottom" alt="'.$langs->trans(
"Refresh").
'" src="'.
img_picto($langs->trans(
"Refresh"),
'refresh.png',
'', 0, 1).
'">';
242 $stringtoshow .=
'</form>';
243 $stringtoshow .=
'</div>';
244 if ($shownb && $showtot) {
245 $stringtoshow .=
'<div class="fichecenter">';
246 $stringtoshow .=
'<div class="fichehalfleft">';
249 $stringtoshow .= $px1->show();
251 if ($shownb && $showtot) {
252 $stringtoshow .=
'</div>';
253 $stringtoshow .=
'<div class="fichehalfright">';
256 $stringtoshow .= $px2->show();
258 if ($shownb && $showtot) {
259 $stringtoshow .=
'</div>';
260 $stringtoshow .=
'</div>';
262 $this->info_box_contents[0][0] = array(
263 'tr' =>
'class="oddeven nohover"',
264 'td' =>
'class="nohover center"',
265 'textnoformat' => $stringtoshow,
268 $this->info_box_contents[0][0] = array(
269 'tr' =>
'class="oddeven nohover"',
270 'td' =>
'class="nohover left"',
276 $this->info_box_contents[0][0] = array(
277 'td' =>
'class="nohover left"',
278 'text' =>
'<span class="opacitymedium">'.$langs->trans(
"ReadPermissionNotAllowed").
'</span>'