24 include_once DOL_DOCUMENT_ROOT.
'/core/boxes/modules_boxes.php';
25 include_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
32 public $boxcode =
"productdistribution";
33 public $boximg =
"object_product";
34 public $boxlabel =
"BoxProductDistribution";
35 public $depends = array(
"product|service",
"facture|propal|commande");
44 public $info_box_head = array();
45 public $info_box_contents = array();
47 public $widgettype =
'graph';
63 (
isModEnabled(
'facture') && !empty($user->rights->facture->lire))
64 || (
isModEnabled(
'commande') && !empty($user->rights->commande->lire))
65 || (
isModEnabled(
'propal') && !empty($user->rights->propal->lire))
77 global $conf, $user, $langs;
80 $dir = $conf->user->dir_temp;
82 $refreshaction =
'refresh_'.$this->boxcode;
84 include_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
85 include_once DOL_DOCUMENT_ROOT.
'/comm/propal/class/propal.class.php';
86 include_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
88 $param_year =
'DOLUSERCOOKIE_box_'.$this->boxcode.
'_year';
89 $param_showinvoicenb =
'DOLUSERCOOKIE_box_'.$this->boxcode.
'_showinvoicenb';
90 $param_showpropalnb =
'DOLUSERCOOKIE_box_'.$this->boxcode.
'_showpropalnb';
91 $param_showordernb =
'DOLUSERCOOKIE_box_'.$this->boxcode.
'_showordernb';
92 $autosetarray = preg_split(
"/[,;:]+/",
GETPOST(
'DOL_AUTOSET_COOKIE'));
93 if (in_array(
'DOLUSERCOOKIE_box_'.$this->boxcode, $autosetarray)) {
94 $year =
GETPOST($param_year,
'int');
95 $showinvoicenb =
GETPOST($param_showinvoicenb,
'alpha');
96 $showpropalnb =
GETPOST($param_showpropalnb,
'alpha');
97 $showordernb =
GETPOST($param_showordernb,
'alpha');
99 $tmparray = (!empty($_COOKIE[
'DOLUSERCOOKIE_box_'.$this->boxcode]) ? json_decode($_COOKIE[
'DOLUSERCOOKIE_box_'.$this->boxcode],
true) : array());
100 $year = (!empty($tmparray[
'year']) ? $tmparray[
'year'] :
'');
101 $showinvoicenb = (!empty($tmparray[
'showinvoicenb']) ? $tmparray[
'showinvoicenb'] :
'');
102 $showpropalnb = (!empty($tmparray[
'showpropalnb']) ? $tmparray[
'showpropalnb'] :
'');
103 $showordernb = (!empty($tmparray[
'showordernb']) ? $tmparray[
'showordernb'] :
'');
105 if (empty($showinvoicenb) && empty($showpropalnb) && empty($showordernb)) {
110 if (!
isModEnabled(
'facture') || empty($user->rights->facture->lire)) {
113 if (
isModEnabled(
'propal') || empty($user->rights->propal->lire)) {
116 if (!
isModEnabled(
'commande') || empty($user->rights->commande->lire)) {
122 $year = $nowarray[
'year'];
126 if ($showinvoicenb) {
136 $text = $langs->trans(
"BoxProductDistribution", $max).
' - '.$langs->trans(
"Year").
': '.$year;
137 $this->info_box_head = array(
142 'subtext'=>$langs->trans(
"Filter"),
143 'subpicto'=>
'filter.png',
144 'subclass'=>
'linkobject boxfilter',
149 $socid = empty($user->socid) ? 0 : $user->socid;
152 $WIDTH = ($nbofgraph >= 2 || !empty($conf->dol_optimize_smallscreen)) ?
'300' :
'320';
155 if (
isModEnabled(
"propal") && !empty($user->rights->propal->lire)) {
158 $langs->load(
"propal");
159 include_once DOL_DOCUMENT_ROOT.
'/comm/propal/class/propalestats.class.php';
163 $stats_proposal =
new PropaleStats($this->
db, $socid, ($userid > 0 ? $userid : 0));
164 $data2 = $stats_proposal->getAllByProductEntry($year, (
GETPOST(
'action',
'aZ09') == $refreshaction ?-1 : (3600 * 24)), 5);
168 $data2 = array(array(0=>$langs->trans(
"None"), 1=>1));
171 $filenamenb = $dir.
"/prodserforpropal-".$year.
".png";
172 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=proposalstats&file=prodserforpropal-'.$year.
'.png';
175 $mesg = $px2->isGraphKo();
181 foreach ($data2 as $key => $val) {
182 $data2[$key][0] =
dol_trunc($data2[$key][0], 32);
183 $legend[] = $data2[$key][0];
187 $px2->SetData($data2);
191 $px2->SetDataColor(array(array(220, 220, 220)));
193 $px2->SetLegend($legend);
194 $px2->setShowLegend(2);
195 if (!empty($conf->dol_optimize_smallscreen)) {
198 $px2->setShowPointValue($showpointvalue);
199 $px2->setShowPercent(0);
200 $px2->SetMaxValue($px2->GetCeilMaxValue());
201 $px2->SetWidth($WIDTH);
202 $px2->SetHeight($HEIGHT);
205 $px2->SetHorizTickIncrement(1);
206 $px2->SetCssPrefix(
"cssboxes");
208 $px2->SetType(array(
'pie'));
209 $px2->SetTitle($langs->trans(
"ForObject", $langs->transnoentitiesnoconv(
"Proposals")));
210 $px2->combine = 0.05;
212 $px2->draw($filenamenb, $fileurlnb);
217 if (
isModEnabled(
'commande') && !empty($user->rights->commande->lire)) {
220 $langs->load(
"orders");
221 include_once DOL_DOCUMENT_ROOT.
'/commande/class/commandestats.class.php';
226 $stats_order =
new CommandeStats($this->
db, $socid, $mode, ($userid > 0 ? $userid : 0));
227 $data3 = $stats_order->getAllByProductEntry($year, (
GETPOST(
'action',
'aZ09') == $refreshaction ?-1 : (3600 * 24)), 5);
231 $data3 = array(array(0=>$langs->trans(
"None"), 1=>1));
234 $filenamenb = $dir.
"/prodserfororder-".$year.
".png";
235 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=prodserfororder-'.$year.
'.png';
238 $mesg = $px3->isGraphKo();
244 foreach ($data3 as $key => $val) {
245 $data3[$key][0] =
dol_trunc($data3[$key][0], 32);
246 $legend[] = $data3[$key][0];
250 $px3->SetData($data3);
254 $px3->SetDataColor(array(array(220, 220, 220)));
256 $px3->SetLegend($legend);
257 $px3->setShowLegend(2);
258 if (!empty($conf->dol_optimize_smallscreen)) {
261 $px3->setShowPointValue($showpointvalue);
262 $px3->setShowPercent(0);
263 $px3->SetMaxValue($px3->GetCeilMaxValue());
264 $px3->SetWidth($WIDTH);
265 $px3->SetHeight($HEIGHT);
268 $px3->SetHorizTickIncrement(1);
269 $px3->SetCssPrefix(
"cssboxes");
271 $px3->SetType(array(
'pie'));
272 $px3->SetTitle($langs->trans(
"ForObject", $langs->transnoentitiesnoconv(
"Orders")));
273 $px3->combine = 0.05;
275 $px3->draw($filenamenb, $fileurlnb);
281 if (
isModEnabled(
'facture') && !empty($user->rights->facture->lire)) {
283 if ($showinvoicenb) {
284 $langs->load(
"bills");
285 include_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facturestats.class.php';
290 $stats_invoice =
new FactureStats($this->
db, $socid, $mode, ($userid > 0 ? $userid : 0));
291 $data1 = $stats_invoice->getAllByProductEntry($year, (
GETPOST(
'action',
'aZ09') == $refreshaction ?-1 : (3600 * 24)), 5);
296 $data1 = array(array(0=>$langs->trans(
"None"), 1=>1));
298 $filenamenb = $dir.
"/prodserforinvoice-".$year.
".png";
299 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=productstats&file=prodserforinvoice-'.$year.
'.png';
302 $mesg = $px1->isGraphKo();
308 foreach ($data1 as $key => $val) {
309 $data1[$key][0] =
dol_trunc($data1[$key][0], 32);
310 $legend[] = $data1[$key][0];
314 $px1->SetData($data1);
318 $px1->SetDataColor(array(array(220, 220, 220)));
320 $px1->SetLegend($legend);
321 $px1->setShowLegend(2);
322 if (!empty($conf->dol_optimize_smallscreen)) {
325 $px1->setShowPointValue($showpointvalue);
326 $px1->setShowPercent(0);
327 $px1->SetMaxValue($px1->GetCeilMaxValue());
328 $px1->SetWidth($WIDTH);
329 $px1->SetHeight($HEIGHT);
332 $px1->SetHorizTickIncrement(1);
333 $px1->SetCssPrefix(
"cssboxes");
335 $px1->SetType(array(
'pie'));
336 $px1->SetTitle($langs->trans(
"ForObject", $langs->transnoentitiesnoconv(
"Invoices")));
337 $px1->combine = 0.05;
339 $px1->draw($filenamenb, $fileurlnb);
344 if (empty($nbofgraph)) {
345 $langs->load(
"errors");
346 $mesg = $langs->trans(
"ReadPermissionNotAllowed");
348 if (empty($conf->use_javascript_ajax)) {
349 $langs->load(
"errors");
350 $mesg = $langs->trans(
"WarningFeatureDisabledWithDisplayOptimizedForBlindNoJs");
355 $stringtoshow .=
'<script type="text/javascript">
356 jQuery(document).ready(function() {
357 jQuery("#idsubimg'.$this->boxcode.
'").click(function() {
358 jQuery("#idfilter'.$this->boxcode.
'").toggle();
362 $stringtoshow .=
'<div class="center hideobject" id="idfilter'.$this->boxcode.
'">';
363 $stringtoshow .=
'<form class="flat formboxfilter" method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
364 $stringtoshow .=
'<input type="hidden" name="token" value="'.newToken().
'">';
365 $stringtoshow .=
'<input type="hidden" name="action" value="'.$refreshaction.
'">';
366 $stringtoshow .=
'<input type="hidden" name="page_y" value="">';
367 $stringtoshow .=
'<input type="hidden" name="DOL_AUTOSET_COOKIE" value="DOLUSERCOOKIE_box_'.$this->boxcode.
':year,showinvoicenb,showpropalnb,showordernb">';
368 if (
isModEnabled(
"propal") || !empty($user->rights->propal->lire)) {
369 $stringtoshow .=
'<input type="checkbox" name="'.$param_showpropalnb.
'"'.($showpropalnb ?
' checked' :
'').
'> '.$langs->trans(
"ForProposals");
370 $stringtoshow .=
' ';
372 if (
isModEnabled(
'commande') || !empty($user->rights->commande->lire)) {
373 $stringtoshow .=
'<input type="checkbox" name="'.$param_showordernb.
'"'.($showordernb ?
' checked' :
'').
'> '.$langs->trans(
"ForCustomersOrders");
375 if (
isModEnabled(
'facture') || !empty($user->rights->facture->lire)) {
376 $stringtoshow .=
'<input type="checkbox" name="'.$param_showinvoicenb.
'"'.($showinvoicenb ?
' checked' :
'').
'> '.$langs->trans(
"ForCustomersInvoices");
377 $stringtoshow .=
' ';
379 $stringtoshow .=
'<br>';
380 $stringtoshow .= $langs->trans(
"Year").
' <input class="flat" size="4" type="text" name="'.$param_year.
'" value="'.$year.
'">';
381 $stringtoshow .=
'<input type="image" class="reposition inline-block valigntextbottom" alt="'.$langs->trans(
"Refresh").
'" src="'.
img_picto(
'',
'refresh.png',
'',
'', 1).
'">';
382 $stringtoshow .=
'</form>';
383 $stringtoshow .=
'</div>';
385 if ($nbofgraph == 1) {
387 $stringtoshow .= $px2->show();
388 } elseif ($showordernb) {
389 $stringtoshow .= $px3->show();
391 $stringtoshow .= $px1->show();
394 if ($nbofgraph == 2) {
395 $stringtoshow .=
'<div class="fichecenter"><div class="containercenter"><div class="fichehalfleft">';
397 $stringtoshow .= $px2->show();
398 } elseif ($showordernb) {
399 $stringtoshow .= $px3->show();
401 $stringtoshow .=
'</div><div class="fichehalfright">';
402 if ($showinvoicenb) {
403 $stringtoshow .= $px1->show();
404 } elseif ($showordernb) {
405 $stringtoshow .= $px3->show();
407 $stringtoshow .=
'</div></div></div>';
409 if ($nbofgraph == 3) {
410 $stringtoshow .=
'<div class="fichecenter"><div class="containercenter"><div class="fichehalfleft">';
411 $stringtoshow .= $px2->show();
412 $stringtoshow .=
'</div><div class="fichehalfright">';
413 $stringtoshow .= $px3->show();
414 $stringtoshow .=
'</div></div></div>';
415 $stringtoshow .=
'<div class="fichecenter"><div class="containercenter">';
416 $stringtoshow .= $px1->show();
417 $stringtoshow .=
'</div></div>';
419 $this->info_box_contents[0][0] = array(
420 'tr' =>
'class="oddeven nohover"',
421 'td' =>
'class="nohover center"',
422 'textnoformat'=>$stringtoshow,
425 $this->info_box_contents[0][0] = array(
426 'td' =>
'class="nohover opacitymedium left"',
441 public function showBox($head =
null, $contents =
null, $nooutput = 0)
443 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
Class to manage order statistics (customer and supplier)
Class to manage stats for invoices (customer and supplier)
Class to manage proposals statistics.
Class to manage the box to show last invoices.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
loadBox($max=5)
Load data into info_box_contents array to show array later.
__construct($db, $param)
Constructor.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_now($mode='auto')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
isModEnabled($module)
Is Dolibarr module enabled.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
$conf db
API class for accounts.