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',
95 $socid = $user->socid;
97 if (!$user->hasRight(
'societe',
'client',
'voir')) {
98 $prefix .=
'private-'.$user->id.
'-';
101 if ($user->hasRight(
'fournisseur',
'commande',
'lire')) {
102 $langs->load(
"orders");
104 $param_year =
'DOLUSER_box_'.$this->boxcode.
'_year';
105 $param_shownb =
'DOLUSER_box_'.$this->boxcode.
'_shownb';
106 $param_showtot =
'DOLUSER_box_'.$this->boxcode.
'_showtot';
108 include_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
109 include_once DOL_DOCUMENT_ROOT.
'/commande/class/commandestats.class.php';
110 $autosetarray = preg_split(
"/[,;:]+/",
GETPOST(
'DOL_AUTOSET_COOKIE'));
111 if (in_array(
'DOLUSER_box_'.$this->boxcode, $autosetarray)) {
113 $shownb =
GETPOST($param_shownb,
'alpha');
114 $showtot =
GETPOST($param_showtot,
'alpha');
116 $tmparray = (!empty($_COOKIE[
'DOLUSER_box_'.$this->boxcode]) ? json_decode($_COOKIE[
'DOLUSER_box_'.$this->boxcode],
true) : array());
117 $endyear = (!empty($tmparray[
'year']) ? $tmparray[
'year'] :
'');
118 $shownb = (!empty($tmparray[
'shownb']) ? $tmparray[
'shownb'] :
'');
119 $showtot = (!empty($tmparray[
'showtot']) ? $tmparray[
'showtot'] :
'');
121 if (empty($shownb) && empty($showtot)) {
126 if (empty($endyear)) {
127 $endyear = $nowarray[
'year'];
129 $startyear = $endyear -
getDolGlobalInt(
'MAIN_NB_OF_YEAR_IN_WIDGET_GRAPH', 3) + 1;
132 $WIDTH = (($shownb && $showtot) || !empty(
$conf->dol_optimize_smallscreen)) ?
'256' :
'320';
139 $data1 = $stats->getNbByMonthWithPrevYear($endyear, $startyear, (
GETPOST(
'action',
'aZ09') == $refreshaction ? -1 : (3600 * 24)), ($WIDTH < 300 ? 2 : 0), $startmonth);
141 $filenamenb = $dir.
"/".$prefix.
"orderssuppliernbinyear-".$endyear.
".png";
143 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersnbinyear-'.$endyear.
'.png';
144 if ($mode ==
'supplier') {
145 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=orderssuppliernbinyear-'.$endyear.
'.png';
149 $mesg = $px1->isGraphKo();
151 $px1->SetData($data1);
155 while ($i <= $endyear) {
156 if ($startmonth != 1) {
157 $legend[] = sprintf(
"%d/%d", $i - 2001, $i - 2000);
163 $px1->SetLegend($legend);
164 $px1->SetMaxValue($px1->GetCeilMaxValue());
165 $px1->SetWidth($WIDTH);
166 $px1->SetHeight($HEIGHT);
167 $px1->SetYLabel($langs->trans(
"NumberOfOrders"));
169 $px1->SetHorizTickIncrement(1);
170 $px1->SetCssPrefix(
"cssboxes");
171 $px1->mode =
'depth';
172 $px1->SetTitle($langs->trans(
"NumberOfOrdersByMonth"));
174 $px1->draw($filenamenb, $fileurlnb);
180 $data2 = $stats->getAmountByMonthWithPrevYear($endyear, $startyear, (
GETPOST(
'action',
'aZ09') == $refreshaction ? -1 : (3600 * 24)), ($WIDTH < 300 ? 2 : 0), $startmonth);
182 $filenamenb = $dir.
"/".$prefix.
"orderssupplieramountinyear-".$endyear.
".png";
184 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersamountinyear-'.$endyear.
'.png';
185 if ($mode ==
'supplier') {
186 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=orderssupplieramountinyear-'.$endyear.
'.png';
190 $mesg = $px2->isGraphKo();
192 $px2->SetData($data2);
196 while ($i <= $endyear) {
197 if ($startmonth != 1) {
198 $legend[] = sprintf(
"%d/%d", $i - 2001, $i - 2000);
204 $px2->SetLegend($legend);
205 $px2->SetMaxValue($px2->GetCeilMaxValue());
206 $px2->SetWidth($WIDTH);
207 $px2->SetHeight($HEIGHT);
208 $px2->SetYLabel($langs->trans(
"AmountOfOrdersHT"));
210 $px2->SetHorizTickIncrement(1);
211 $px2->SetCssPrefix(
"cssboxes");
212 $px2->mode =
'depth';
213 $px2->SetTitle($langs->trans(
"AmountOfOrdersByMonthHT"));
215 $px2->draw($filenamenb, $fileurlnb);
219 if (empty(
$conf->use_javascript_ajax)) {
220 $langs->load(
"errors");
221 $mesg = $langs->trans(
"WarningFeatureDisabledWithDisplayOptimizedForBlindNoJs");
226 $stringtoshow .=
'<script nonce="'.getNonce().
'" type="text/javascript">
227 jQuery(document).ready(function() {
228 jQuery("#idsubimg'.$this->boxcode.
'").click(function() {
229 jQuery("#idfilter'.$this->boxcode.
'").toggle();
233 $stringtoshow .=
'<div class="center hideobject" id="idfilter'.$this->boxcode.
'">';
234 $stringtoshow .=
'<form class="flat formboxfilter" method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
235 $stringtoshow .=
'<input type="hidden" name="token" value="'.newToken().
'">';
236 $stringtoshow .=
'<input type="hidden" name="action" value="'.$refreshaction.
'">';
237 $stringtoshow .=
'<input type="hidden" name="page_y" value="">';
238 $stringtoshow .=
'<input type="hidden" name="DOL_AUTOSET_COOKIE" value="DOLUSER_box_'.$this->boxcode.
':year,shownb,showtot">';
239 $stringtoshow .=
'<input type="checkbox" id="'.$param_shownb.
'" name="'.$param_shownb.
'"'.($shownb ?
' checked' :
'').
'><label for="'.$param_shownb.
'"> '.$langs->trans(
"NumberOfOrdersByMonth").
'</label>';
240 $stringtoshow .=
' ';
241 $stringtoshow .=
'<input type="checkbox" id="'.$param_showtot.
'" name="'.$param_showtot.
'"'.($showtot ?
' checked' :
'').
'><label for="'.$param_showtot.
'"> '.$langs->trans(
"AmountOfOrdersByMonthHT").
'</label>';
242 $stringtoshow .=
'<br>';
243 $stringtoshow .= $langs->trans(
"Year").
' <input class="flat" size="4" type="text" name="'.$param_year.
'" value="'.$endyear.
'">';
244 $stringtoshow .=
'<input type="image" class="reposition inline-block valigntextbottom" alt="'.$langs->trans(
"Refresh").
'" src="'.
img_picto($langs->trans(
"Refresh"),
'refresh.png',
'', 0, 1).
'">';
245 $stringtoshow .=
'</form>';
246 $stringtoshow .=
'</div>';
247 if ($shownb && $showtot) {
248 $stringtoshow .=
'<div class="fichecenter">';
249 $stringtoshow .=
'<div class="fichehalfleft">';
251 if ($shownb && $px1 !==
null) {
252 $stringtoshow .= $px1->show();
254 if ($shownb && $showtot) {
255 $stringtoshow .=
'</div>';
256 $stringtoshow .=
'<div class="fichehalfright">';
258 if ($showtot && $px2 !==
null) {
259 $stringtoshow .= $px2->show();
261 if ($shownb && $showtot) {
262 $stringtoshow .=
'</div>';
263 $stringtoshow .=
'</div>';
265 $this->info_box_contents[0][0] = array(
266 'tr' =>
'class="oddeven nohover"',
267 'td' =>
'class="nohover center"',
268 'textnoformat' => $stringtoshow,
271 $this->info_box_contents[0][0] = array(
272 'tr' =>
'class="oddeven nohover"',
273 'td' =>
'class="nohover left"',
279 $this->info_box_contents[0][0] = array(
280 'td' =>
'class="nohover left"',
281 'text' =>
'<span class="opacitymedium">'.$langs->trans(
"ReadPermissionNotAllowed").
'</span>'