67 global $conf, $user, $langs;
70 $dir = $conf->user->dir_temp;
72 $refreshaction =
'refresh_'.$this->boxcode;
74 include_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
75 include_once DOL_DOCUMENT_ROOT.
'/comm/propal/class/propal.class.php';
76 include_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
78 $param_year =
'DOLUSER_box_'.$this->boxcode.
'_year';
79 $param_showinvoicenb =
'DOLUSER_box_'.$this->boxcode.
'_showinvoicenb';
80 $param_showpropalnb =
'DOLUSER_box_'.$this->boxcode.
'_showpropalnb';
81 $param_showordernb =
'DOLUSER_box_'.$this->boxcode.
'_showordernb';
82 $autosetarray = preg_split(
"/[,;:]+/",
GETPOST(
'DOL_AUTOSET_COOKIE'));
83 if (in_array(
'DOLUSER_box_'.$this->boxcode, $autosetarray)) {
85 $showinvoicenb =
GETPOST($param_showinvoicenb,
'alpha');
86 $showpropalnb =
GETPOST($param_showpropalnb,
'alpha');
87 $showordernb =
GETPOST($param_showordernb,
'alpha');
89 $tmparray = (!empty($_COOKIE[
'DOLUSER_box_'.$this->boxcode]) ? json_decode($_COOKIE[
'DOLUSER_box_'.$this->boxcode],
true) : array());
90 $year = (!empty($tmparray[
'year']) ? $tmparray[
'year'] :
'');
91 $showinvoicenb = (!empty($tmparray[
'showinvoicenb']) ? $tmparray[
'showinvoicenb'] :
'');
92 $showpropalnb = (!empty($tmparray[
'showpropalnb']) ? $tmparray[
'showpropalnb'] :
'');
93 $showordernb = (!empty($tmparray[
'showordernb']) ? $tmparray[
'showordernb'] :
'');
95 if (empty($showinvoicenb) && empty($showpropalnb) && empty($showordernb)) {
100 if (!isModEnabled(
'invoice') || !$user->hasRight(
'facture',
'lire')) {
103 if (isModEnabled(
'propal') || !$user->hasRight(
'propal',
'lire')) {
106 if (!isModEnabled(
'order') || !$user->hasRight(
'commande',
'lire')) {
112 $year = $nowarray[
'year'];
116 if ($showinvoicenb) {
126 $text = $langs->trans(
"BoxProductDistribution", $max).
' - '.$langs->trans(
"Year").
': '.$year;
127 $this->info_box_head = array(
132 'subtext' => $langs->trans(
"Filter"),
133 'subpicto' =>
'filter.png',
134 'subclass' =>
'linkobject boxfilter',
139 $socid = empty($user->socid) ? 0 : $user->socid;
142 $WIDTH = ($nbofgraph >= 2 || !empty($conf->dol_optimize_smallscreen)) ?
'300' :
'320';
145 if (isModEnabled(
"propal") && $user->hasRight(
'propal',
'lire')) {
148 $langs->load(
"propal");
149 include_once DOL_DOCUMENT_ROOT.
'/comm/propal/class/propalestats.class.php';
153 $stats_proposal =
new PropaleStats($this->db, $socid, ($userid > 0 ? $userid : 0));
154 $data2 = $stats_proposal->getAllByProductEntry($year, (
GETPOST(
'action',
'aZ09') == $refreshaction ? -1 : (3600 * 24)), $max);
158 $data2 = array(array(0 => $langs->trans(
"None"), 1 => 1));
161 $filenamenb = $dir.
"/prodserforpropal-".$year.
".png";
162 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=proposalstats&file=prodserforpropal-'.$year.
'.png';
165 $mesg = $px2->isGraphKo();
171 foreach ($data2 as $key => $val) {
172 $data2[$key][0] =
dol_trunc($data2[$key][0], 32);
173 $legend[] = $data2[$key][0];
177 $px2->SetData($data2);
181 $px2->SetDataColor(array(array(220, 220, 220)));
183 $px2->SetLegend($legend);
184 $px2->setShowLegend(2);
185 if (!empty($conf->dol_optimize_smallscreen)) {
188 $px2->setShowPointValue($showpointvalue);
189 $px2->setShowPercent(0);
190 $px2->SetMaxValue($px2->GetCeilMaxValue());
191 $px2->SetWidth($WIDTH);
192 $px2->SetHeight($HEIGHT);
195 $px2->SetHorizTickIncrement(1);
196 $px2->SetCssPrefix(
"cssboxes");
198 $px2->SetType(array(
'pie'));
199 $px2->SetTitle($langs->trans(
"ForObject", $langs->transnoentitiesnoconv(
"Proposals")));
200 $px2->combine = 0.05;
202 $px2->draw($filenamenb, $fileurlnb);
207 if (isModEnabled(
'order') && $user->hasRight(
'commande',
'lire')) {
210 $langs->load(
"orders");
211 include_once DOL_DOCUMENT_ROOT.
'/commande/class/commandestats.class.php';
216 $stats_order =
new CommandeStats($this->db, $socid, $mode, ($userid > 0 ? $userid : 0));
217 $data3 = $stats_order->getAllByProductEntry($year, (
GETPOST(
'action',
'aZ09') == $refreshaction ? -1 : (3600 * 24)), $max);
221 $data3 = array(array(0 => $langs->trans(
"None"), 1 => 1));
224 $filenamenb = $dir.
"/prodserfororder-".$year.
".png";
225 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=prodserfororder-'.$year.
'.png';
228 $mesg = $px3->isGraphKo();
234 foreach ($data3 as $key => $val) {
235 $data3[$key][0] =
dol_trunc($data3[$key][0], 32);
236 $legend[] = $data3[$key][0];
240 $px3->SetData($data3);
244 $px3->SetDataColor(array(array(220, 220, 220)));
246 $px3->SetLegend($legend);
247 $px3->setShowLegend(2);
248 if (!empty($conf->dol_optimize_smallscreen)) {
251 $px3->setShowPointValue($showpointvalue);
252 $px3->setShowPercent(0);
253 $px3->SetMaxValue($px3->GetCeilMaxValue());
254 $px3->SetWidth($WIDTH);
255 $px3->SetHeight($HEIGHT);
258 $px3->SetHorizTickIncrement(1);
259 $px3->SetCssPrefix(
"cssboxes");
261 $px3->SetType(array(
'pie'));
262 $px3->SetTitle($langs->trans(
"ForObject", $langs->transnoentitiesnoconv(
"Orders")));
263 $px3->combine = 0.05;
265 $px3->draw($filenamenb, $fileurlnb);
271 if (isModEnabled(
'invoice') && $user->hasRight(
'facture',
'lire')) {
273 if ($showinvoicenb) {
274 $langs->load(
"bills");
275 include_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facturestats.class.php';
280 $stats_invoice =
new FactureStats($this->db, $socid, $mode, ($userid > 0 ? $userid : 0));
281 $data1 = $stats_invoice->getAllByProductEntry($year, (
GETPOST(
'action',
'aZ09') == $refreshaction ? -1 : (3600 * 24)), $max);
286 $data1 = array(array(0 => $langs->trans(
"None"), 1 => 1));
288 $filenamenb = $dir.
"/prodserforinvoice-".$year.
".png";
289 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=productstats&file=prodserforinvoice-'.$year.
'.png';
292 $mesg = $px1->isGraphKo();
298 foreach ($data1 as $key => $val) {
299 $data1[$key][0] =
dol_trunc($data1[$key][0], 32);
300 $legend[] = $data1[$key][0];
304 $px1->SetData($data1);
308 $px1->SetDataColor(array(array(220, 220, 220)));
310 $px1->SetLegend($legend);
311 $px1->setShowLegend(2);
312 if (!empty($conf->dol_optimize_smallscreen)) {
315 $px1->setShowPointValue($showpointvalue);
316 $px1->setShowPercent(0);
317 $px1->SetMaxValue($px1->GetCeilMaxValue());
318 $px1->SetWidth($WIDTH);
319 $px1->SetHeight($HEIGHT);
322 $px1->SetHorizTickIncrement(1);
323 $px1->SetCssPrefix(
"cssboxes");
325 $px1->SetType(array(
'pie'));
326 $px1->SetTitle($langs->trans(
"ForObject", $langs->transnoentitiesnoconv(
"Invoices")));
327 $px1->combine = 0.05;
329 $px1->draw($filenamenb, $fileurlnb);
334 if (empty($nbofgraph)) {
335 $langs->load(
"errors");
336 $mesg = $langs->trans(
"ReadPermissionNotAllowed");
338 if (empty($conf->use_javascript_ajax)) {
339 $langs->load(
"errors");
340 $mesg = $langs->trans(
"WarningFeatureDisabledWithDisplayOptimizedForBlindNoJs");
345 $stringtoshow .=
'<script nonce="'.getNonce().
'" type="text/javascript">
346 jQuery(document).ready(function() {
347 jQuery("#idsubimg'.$this->boxcode.
'").click(function() {
348 jQuery("#idfilter'.$this->boxcode.
'").toggle();
352 $stringtoshow .=
'<div class="center hideobject" id="idfilter'.$this->boxcode.
'">';
353 $stringtoshow .=
'<form class="flat formboxfilter" method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
354 $stringtoshow .=
'<input type="hidden" name="token" value="'.newToken().
'">';
355 $stringtoshow .=
'<input type="hidden" name="action" value="'.$refreshaction.
'">';
356 $stringtoshow .=
'<input type="hidden" name="page_y" value="">';
357 $stringtoshow .=
'<input type="hidden" name="DOL_AUTOSET_COOKIE" value="DOLUSER_box_'.$this->boxcode.
':year,showinvoicenb,showpropalnb,showordernb">';
358 if (isModEnabled(
"propal") || $user->hasRight(
'propal',
'lire')) {
359 $stringtoshow .=
'<input type="checkbox" name="'.$param_showpropalnb.
'"'.($showpropalnb ?
' checked' :
'').
'> '.$langs->trans(
"ForProposals");
360 $stringtoshow .=
' ';
362 if (isModEnabled(
'order') || $user->hasRight(
'commande',
'lire')) {
363 $stringtoshow .=
'<input type="checkbox" name="'.$param_showordernb.
'"'.($showordernb ?
' checked' :
'').
'> '.$langs->trans(
"ForCustomersOrders");
365 if (isModEnabled(
'invoice') || $user->hasRight(
'facture',
'lire')) {
366 $stringtoshow .=
'<input type="checkbox" name="'.$param_showinvoicenb.
'"'.($showinvoicenb ?
' checked' :
'').
'> '.$langs->trans(
"ForCustomersInvoices");
367 $stringtoshow .=
' ';
369 $stringtoshow .=
'<br>';
370 $stringtoshow .= $langs->trans(
"Year").
' <input class="flat" size="4" type="text" name="'.$param_year.
'" value="'.$year.
'">';
371 $stringtoshow .=
'<input type="image" class="reposition inline-block valigntextbottom" alt="'.$langs->trans(
"Refresh").
'" src="'.
img_picto(
'',
'refresh.png',
'', 0, 1).
'">';
372 $stringtoshow .=
'</form>';
373 $stringtoshow .=
'</div>';
375 if ($nbofgraph == 1) {
377 $stringtoshow .= $px2->show();
378 } elseif ($showordernb) {
379 $stringtoshow .= $px3->show();
381 $stringtoshow .= $px1->show();
384 if ($nbofgraph == 2) {
385 $stringtoshow .=
'<div class="fichecenter"><div class="containercenter"><div class="fichehalfleft">';
386 if (isModEnabled(
'propal') && $showpropalnb) {
387 $stringtoshow .= $px2->show();
388 } elseif (isModEnabled(
'order') && $showordernb) {
389 $stringtoshow .= $px3->show();
391 $stringtoshow .=
'</div><div class="fichehalfright">';
392 if (isModEnabled(
'invoice') && $showinvoicenb) {
393 $stringtoshow .= $px1->show();
394 } elseif (isModEnabled(
'order') && $showordernb) {
395 $stringtoshow .= $px3->show();
397 $stringtoshow .=
'</div></div></div>';
399 if ($nbofgraph == 3) {
400 $stringtoshow .=
'<div class="fichecenter"><div class="containercenter"><div class="fichehalfleft">';
401 $stringtoshow .= $px2->show();
402 $stringtoshow .=
'</div><div class="fichehalfright">';
403 $stringtoshow .= $px3->show();
404 $stringtoshow .=
'</div></div></div>';
405 $stringtoshow .=
'<div class="fichecenter"><div class="containercenter">';
406 $stringtoshow .= $px1->show();
407 $stringtoshow .=
'</div></div>';
409 $this->info_box_contents[0][0] = array(
410 'tr' =>
'class="oddeven nohover"',
411 'td' =>
'class="nohover center"',
412 'textnoformat' => $stringtoshow,
415 $this->info_box_contents[0][0] = array(
416 'td' =>
'class="nohover left"',
418 'text' =>
'<span class="opacitymedium">'.$mesg.
'</span>'