66 global $conf, $user, $langs;
69 $dir = $conf->user->dir_temp;
71 $refreshaction =
'refresh_'.$this->boxcode;
73 include_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
74 include_once DOL_DOCUMENT_ROOT.
'/comm/propal/class/propal.class.php';
75 include_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
77 $param_year =
'DOLUSERCOOKIE_box_'.$this->boxcode.
'_year';
78 $param_showinvoicenb =
'DOLUSERCOOKIE_box_'.$this->boxcode.
'_showinvoicenb';
79 $param_showpropalnb =
'DOLUSERCOOKIE_box_'.$this->boxcode.
'_showpropalnb';
80 $param_showordernb =
'DOLUSERCOOKIE_box_'.$this->boxcode.
'_showordernb';
81 $autosetarray = preg_split(
"/[,;:]+/",
GETPOST(
'DOL_AUTOSET_COOKIE'));
82 if (in_array(
'DOLUSERCOOKIE_box_'.$this->boxcode, $autosetarray)) {
84 $showinvoicenb =
GETPOST($param_showinvoicenb,
'alpha');
85 $showpropalnb =
GETPOST($param_showpropalnb,
'alpha');
86 $showordernb =
GETPOST($param_showordernb,
'alpha');
88 $tmparray = (!empty($_COOKIE[
'DOLUSERCOOKIE_box_'.$this->boxcode]) ? json_decode($_COOKIE[
'DOLUSERCOOKIE_box_'.$this->boxcode],
true) : array());
89 $year = (!empty($tmparray[
'year']) ? $tmparray[
'year'] :
'');
90 $showinvoicenb = (!empty($tmparray[
'showinvoicenb']) ? $tmparray[
'showinvoicenb'] :
'');
91 $showpropalnb = (!empty($tmparray[
'showpropalnb']) ? $tmparray[
'showpropalnb'] :
'');
92 $showordernb = (!empty($tmparray[
'showordernb']) ? $tmparray[
'showordernb'] :
'');
94 if (empty($showinvoicenb) && empty($showpropalnb) && empty($showordernb)) {
99 if (!isModEnabled(
'invoice') || !$user->hasRight(
'facture',
'lire')) {
102 if (isModEnabled(
'propal') || !$user->hasRight(
'propal',
'lire')) {
105 if (!isModEnabled(
'order') || !$user->hasRight(
'commande',
'lire')) {
111 $year = $nowarray[
'year'];
115 if ($showinvoicenb) {
125 $text = $langs->trans(
"BoxProductDistribution", $max).
' - '.$langs->trans(
"Year").
': '.$year;
126 $this->info_box_head = array(
131 'subtext'=>$langs->trans(
"Filter"),
132 'subpicto'=>
'filter.png',
133 'subclass'=>
'linkobject boxfilter',
138 $socid = empty($user->socid) ? 0 : $user->socid;
141 $WIDTH = ($nbofgraph >= 2 || !empty($conf->dol_optimize_smallscreen)) ?
'300' :
'320';
144 if (isModEnabled(
"propal") && $user->hasRight(
'propal',
'lire')) {
147 $langs->load(
"propal");
148 include_once DOL_DOCUMENT_ROOT.
'/comm/propal/class/propalestats.class.php';
152 $stats_proposal =
new PropaleStats($this->db, $socid, ($userid > 0 ? $userid : 0));
153 $data2 = $stats_proposal->getAllByProductEntry($year, (
GETPOST(
'action',
'aZ09') == $refreshaction ? -1 : (3600 * 24)), $max);
157 $data2 = array(array(0=>$langs->trans(
"None"), 1=>1));
160 $filenamenb = $dir.
"/prodserforpropal-".$year.
".png";
161 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=proposalstats&file=prodserforpropal-'.$year.
'.png';
164 $mesg = $px2->isGraphKo();
170 foreach ($data2 as $key => $val) {
171 $data2[$key][0] =
dol_trunc($data2[$key][0], 32);
172 $legend[] = $data2[$key][0];
176 $px2->SetData($data2);
180 $px2->SetDataColor(array(array(220, 220, 220)));
182 $px2->SetLegend($legend);
183 $px2->setShowLegend(2);
184 if (!empty($conf->dol_optimize_smallscreen)) {
187 $px2->setShowPointValue($showpointvalue);
188 $px2->setShowPercent(0);
189 $px2->SetMaxValue($px2->GetCeilMaxValue());
190 $px2->SetWidth($WIDTH);
191 $px2->SetHeight($HEIGHT);
194 $px2->SetHorizTickIncrement(1);
195 $px2->SetCssPrefix(
"cssboxes");
197 $px2->SetType(array(
'pie'));
198 $px2->SetTitle($langs->trans(
"ForObject", $langs->transnoentitiesnoconv(
"Proposals")));
199 $px2->combine = 0.05;
201 $px2->draw($filenamenb, $fileurlnb);
206 if (isModEnabled(
'order') && $user->hasRight(
'commande',
'lire')) {
209 $langs->load(
"orders");
210 include_once DOL_DOCUMENT_ROOT.
'/commande/class/commandestats.class.php';
215 $stats_order =
new CommandeStats($this->db, $socid, $mode, ($userid > 0 ? $userid : 0));
216 $data3 = $stats_order->getAllByProductEntry($year, (
GETPOST(
'action',
'aZ09') == $refreshaction ? -1 : (3600 * 24)), $max);
220 $data3 = array(array(0=>$langs->trans(
"None"), 1=>1));
223 $filenamenb = $dir.
"/prodserfororder-".$year.
".png";
224 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=prodserfororder-'.$year.
'.png';
227 $mesg = $px3->isGraphKo();
233 foreach ($data3 as $key => $val) {
234 $data3[$key][0] =
dol_trunc($data3[$key][0], 32);
235 $legend[] = $data3[$key][0];
239 $px3->SetData($data3);
243 $px3->SetDataColor(array(array(220, 220, 220)));
245 $px3->SetLegend($legend);
246 $px3->setShowLegend(2);
247 if (!empty($conf->dol_optimize_smallscreen)) {
250 $px3->setShowPointValue($showpointvalue);
251 $px3->setShowPercent(0);
252 $px3->SetMaxValue($px3->GetCeilMaxValue());
253 $px3->SetWidth($WIDTH);
254 $px3->SetHeight($HEIGHT);
257 $px3->SetHorizTickIncrement(1);
258 $px3->SetCssPrefix(
"cssboxes");
260 $px3->SetType(array(
'pie'));
261 $px3->SetTitle($langs->trans(
"ForObject", $langs->transnoentitiesnoconv(
"Orders")));
262 $px3->combine = 0.05;
264 $px3->draw($filenamenb, $fileurlnb);
270 if (isModEnabled(
'invoice') && $user->hasRight(
'facture',
'lire')) {
272 if ($showinvoicenb) {
273 $langs->load(
"bills");
274 include_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facturestats.class.php';
279 $stats_invoice =
new FactureStats($this->db, $socid, $mode, ($userid > 0 ? $userid : 0));
280 $data1 = $stats_invoice->getAllByProductEntry($year, (
GETPOST(
'action',
'aZ09') == $refreshaction ? -1 : (3600 * 24)), $max);
285 $data1 = array(array(0=>$langs->trans(
"None"), 1=>1));
287 $filenamenb = $dir.
"/prodserforinvoice-".$year.
".png";
288 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=productstats&file=prodserforinvoice-'.$year.
'.png';
291 $mesg = $px1->isGraphKo();
297 foreach ($data1 as $key => $val) {
298 $data1[$key][0] =
dol_trunc($data1[$key][0], 32);
299 $legend[] = $data1[$key][0];
303 $px1->SetData($data1);
307 $px1->SetDataColor(array(array(220, 220, 220)));
309 $px1->SetLegend($legend);
310 $px1->setShowLegend(2);
311 if (!empty($conf->dol_optimize_smallscreen)) {
314 $px1->setShowPointValue($showpointvalue);
315 $px1->setShowPercent(0);
316 $px1->SetMaxValue($px1->GetCeilMaxValue());
317 $px1->SetWidth($WIDTH);
318 $px1->SetHeight($HEIGHT);
321 $px1->SetHorizTickIncrement(1);
322 $px1->SetCssPrefix(
"cssboxes");
324 $px1->SetType(array(
'pie'));
325 $px1->SetTitle($langs->trans(
"ForObject", $langs->transnoentitiesnoconv(
"Invoices")));
326 $px1->combine = 0.05;
328 $px1->draw($filenamenb, $fileurlnb);
333 if (empty($nbofgraph)) {
334 $langs->load(
"errors");
335 $mesg = $langs->trans(
"ReadPermissionNotAllowed");
337 if (empty($conf->use_javascript_ajax)) {
338 $langs->load(
"errors");
339 $mesg = $langs->trans(
"WarningFeatureDisabledWithDisplayOptimizedForBlindNoJs");
344 $stringtoshow .=
'<script nonce="'.getNonce().
'" type="text/javascript">
345 jQuery(document).ready(function() {
346 jQuery("#idsubimg'.$this->boxcode.
'").click(function() {
347 jQuery("#idfilter'.$this->boxcode.
'").toggle();
351 $stringtoshow .=
'<div class="center hideobject" id="idfilter'.$this->boxcode.
'">';
352 $stringtoshow .=
'<form class="flat formboxfilter" method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
353 $stringtoshow .=
'<input type="hidden" name="token" value="'.newToken().
'">';
354 $stringtoshow .=
'<input type="hidden" name="action" value="'.$refreshaction.
'">';
355 $stringtoshow .=
'<input type="hidden" name="page_y" value="">';
356 $stringtoshow .=
'<input type="hidden" name="DOL_AUTOSET_COOKIE" value="DOLUSERCOOKIE_box_'.$this->boxcode.
':year,showinvoicenb,showpropalnb,showordernb">';
357 if (isModEnabled(
"propal") || $user->hasRight(
'propal',
'lire')) {
358 $stringtoshow .=
'<input type="checkbox" name="'.$param_showpropalnb.
'"'.($showpropalnb ?
' checked' :
'').
'> '.$langs->trans(
"ForProposals");
359 $stringtoshow .=
' ';
361 if (isModEnabled(
'order') || $user->hasRight(
'commande',
'lire')) {
362 $stringtoshow .=
'<input type="checkbox" name="'.$param_showordernb.
'"'.($showordernb ?
' checked' :
'').
'> '.$langs->trans(
"ForCustomersOrders");
364 if (isModEnabled(
'invoice') || $user->hasRight(
'facture',
'lire')) {
365 $stringtoshow .=
'<input type="checkbox" name="'.$param_showinvoicenb.
'"'.($showinvoicenb ?
' checked' :
'').
'> '.$langs->trans(
"ForCustomersInvoices");
366 $stringtoshow .=
' ';
368 $stringtoshow .=
'<br>';
369 $stringtoshow .= $langs->trans(
"Year").
' <input class="flat" size="4" type="text" name="'.$param_year.
'" value="'.$year.
'">';
370 $stringtoshow .=
'<input type="image" class="reposition inline-block valigntextbottom" alt="'.$langs->trans(
"Refresh").
'" src="'.
img_picto(
'',
'refresh.png',
'',
'', 1).
'">';
371 $stringtoshow .=
'</form>';
372 $stringtoshow .=
'</div>';
374 if ($nbofgraph == 1) {
376 $stringtoshow .= $px2->show();
377 } elseif ($showordernb) {
378 $stringtoshow .= $px3->show();
380 $stringtoshow .= $px1->show();
383 if ($nbofgraph == 2) {
384 $stringtoshow .=
'<div class="fichecenter"><div class="containercenter"><div class="fichehalfleft">';
385 if (isModEnabled(
'propal') && $showpropalnb) {
386 $stringtoshow .= $px2->show();
387 } elseif (isModEnabled(
'order') && $showordernb) {
388 $stringtoshow .= $px3->show();
390 $stringtoshow .=
'</div><div class="fichehalfright">';
391 if (isModEnabled(
'invoice') && $showinvoicenb) {
392 $stringtoshow .= $px1->show();
393 } elseif (isModEnabled(
'order') && $showordernb) {
394 $stringtoshow .= $px3->show();
396 $stringtoshow .=
'</div></div></div>';
398 if ($nbofgraph == 3) {
399 $stringtoshow .=
'<div class="fichecenter"><div class="containercenter"><div class="fichehalfleft">';
400 $stringtoshow .= $px2->show();
401 $stringtoshow .=
'</div><div class="fichehalfright">';
402 $stringtoshow .= $px3->show();
403 $stringtoshow .=
'</div></div></div>';
404 $stringtoshow .=
'<div class="fichecenter"><div class="containercenter">';
405 $stringtoshow .= $px1->show();
406 $stringtoshow .=
'</div></div>';
408 $this->info_box_contents[0][0] = array(
409 'tr' =>
'class="oddeven nohover"',
410 'td' =>
'class="nohover center"',
411 'textnoformat'=>$stringtoshow,
414 $this->info_box_contents[0][0] = array(
415 'td' =>
'class="nohover left"',
417 'text' =>
'<span class="opacitymedium">'.$mesg.
'</span>'