23 include_once DOL_DOCUMENT_ROOT.
'/core/boxes/modules_boxes.php';
31 public $boxcode =
"invoicessupplierpermonth";
32 public $boximg =
"object_bill";
33 public $boxlabel =
"BoxSuppliersInvoicesPerMonth";
34 public $depends = array(
"fournisseur");
41 public $info_box_head = array();
42 public $info_box_contents = array();
57 $this->hidden = !($user->rights->fournisseur->facture->lire);
68 global $conf, $user, $langs;
72 $refreshaction =
'refresh_'.$this->boxcode;
74 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
76 $startmonth = $conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1;
77 if (empty($conf->global->GRAPH_USE_FISCAL_YEAR)) $startmonth = 1;
79 $text = $langs->trans(
"BoxSuppliersInvoicesPerMonth", $max);
80 $this->info_box_head = array(
85 'subtext'=>$langs->trans(
"Filter"),
86 'subpicto'=>
'filter.png',
87 'subclass'=>
'linkobject boxfilter',
94 if ($user->socid) $socid = $user->socid;
95 if (!$user->rights->societe->client->voir || $socid) $prefix .=
'private-'.$user->id.
'-';
97 if ($user->rights->fournisseur->facture->lire)
99 $param_year =
'DOLUSERCOOKIE_box_'.$this->boxcode.
'_year';
100 $param_shownb =
'DOLUSERCOOKIE_box_'.$this->boxcode.
'_shownb';
101 $param_showtot =
'DOLUSERCOOKIE_box_'.$this->boxcode.
'_showtot';
103 include_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
104 include_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facturestats.class.php';
105 $autosetarray = preg_split(
"/[,;:]+/",
GETPOST(
'DOL_AUTOSET_COOKIE'));
106 if (in_array(
'DOLUSERCOOKIE_box_'.$this->boxcode, $autosetarray))
108 $endyear =
GETPOST($param_year,
'int');
109 $shownb =
GETPOST($param_shownb,
'alpha');
110 $showtot =
GETPOST($param_showtot,
'alpha');
112 $tmparray = json_decode($_COOKIE[
'DOLUSERCOOKIE_box_'.$this->boxcode],
true);
113 $endyear = $tmparray[
'year'];
114 $shownb = $tmparray[
'shownb'];
115 $showtot = $tmparray[
'showtot'];
117 if (empty($shownb) && empty($showtot)) { $shownb = 1; $showtot = 1; }
119 if (empty($endyear)) $endyear = $nowarray[
'year'];
120 $startyear = $endyear - (empty($conf->global->MAIN_NB_OF_YEAR_IN_WIDGET_GRAPH) ? 1 : $conf->global->MAIN_NB_OF_YEAR_IN_WIDGET_GRAPH);
123 $WIDTH = (($shownb && $showtot) || !empty($conf->dol_optimize_smallscreen)) ?
'256' :
'320';
131 $data1 = $stats->getNbByMonthWithPrevYear($endyear, $startyear, (
GETPOST(
'action',
'aZ09') == $refreshaction ?-1 : (3600 * 24)), ($WIDTH < 300 ? 2 : 0), $startmonth);
133 $filenamenb = $dir.
"/".$prefix.
"invoicessuppliernbinyear-".$year.
".png";
135 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=billstats&file=invoicesnbinyear-'.$year.
'.png';
136 if ($mode ==
'supplier') $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=billstatssupplier&file=invoicessuppliernbinyear-'.$year.
'.png';
139 $mesg = $px1->isGraphKo();
142 $langs->load(
"bills");
144 $px1->SetData($data1);
148 while ($i <= $endyear)
150 if ($startmonth != 1)
152 $legend[] = sprintf(
"%d/%d", $i - 2001, $i - 2000);
158 $px1->SetLegend($legend);
159 $px1->SetMaxValue($px1->GetCeilMaxValue());
160 $px1->SetWidth($WIDTH);
161 $px1->SetHeight($HEIGHT);
162 $px1->SetYLabel($langs->trans(
"NumberOfBills"));
164 $px1->SetHorizTickIncrement(1);
165 $px1->SetCssPrefix(
"cssboxes");
166 $px1->mode =
'depth';
167 $px1->SetTitle($langs->trans(
"NumberOfBillsByMonth"));
169 $px1->draw($filenamenb, $fileurlnb);
176 $data2 = $stats->getAmountByMonthWithPrevYear($endyear, $startyear, (
GETPOST(
'action',
'aZ09') == $refreshaction ?-1 : (3600 * 24)), ($WIDTH < 300 ? 2 : 0), $startmonth);
178 $filenamenb = $dir.
"/".$prefix.
"invoicessupplieramountinyear-".$year.
".png";
180 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=billstats&file=invoicesamountinyear-'.$year.
'.png';
181 if ($mode ==
'supplier') $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=billstatssupplier&file=invoicessupplieramountinyear-'.$year.
'.png';
184 $mesg = $px2->isGraphKo();
187 $langs->load(
"bills");
189 $px2->SetData($data2);
191 $i = $startyear; $legend = array();
192 while ($i <= $endyear)
194 if ($startmonth != 1)
196 $legend[] = sprintf(
"%d/%d", $i - 2001, $i - 2000);
202 $px2->SetLegend($legend);
203 $px2->SetMaxValue($px2->GetCeilMaxValue());
204 $px2->SetWidth($WIDTH);
205 $px2->SetHeight($HEIGHT);
206 $px2->SetYLabel($langs->trans(
"AmountOfBillsHT"));
208 $px2->SetHorizTickIncrement(1);
209 $px2->SetCssPrefix(
"cssboxes");
210 $px2->mode =
'depth';
211 $px2->SetTitle($langs->trans(
"AmountOfBillsByMonthHT"));
213 $px2->draw($filenamenb, $fileurlnb);
217 if (empty($conf->use_javascript_ajax))
219 $langs->load(
"errors");
220 $mesg = $langs->trans(
"WarningFeatureDisabledWithDisplayOptimizedForBlindNoJs");
226 $stringtoshow .=
'<script type="text/javascript" language="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="DOLUSERCOOKIE_box_'.$this->boxcode.
':year,shownb,showtot">';
239 $stringtoshow .=
'<input type="checkbox" name="'.$param_shownb.
'"'.($shownb ?
' checked' :
'').
'> '.$langs->trans(
"NumberOfBillsByMonth");
240 $stringtoshow .=
' ';
241 $stringtoshow .=
'<input type="checkbox" name="'.$param_showtot.
'"'.($showtot ?
' checked' :
'').
'> '.$langs->trans(
"AmountOfBillsByMonthHT");
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',
'',
'', 1).
'">';
245 $stringtoshow .=
'</form>';
246 $stringtoshow .=
'</div>';
247 if ($shownb && $showtot)
249 $stringtoshow .=
'<div class="fichecenter">';
250 $stringtoshow .=
'<div class="fichehalfleft">';
252 if ($shownb) $stringtoshow .= $px1->show();
253 if ($shownb && $showtot)
255 $stringtoshow .=
'</div>';
256 $stringtoshow .=
'<div class="fichehalfright">';
258 if ($showtot) $stringtoshow .= $px2->show();
259 if ($shownb && $showtot)
261 $stringtoshow .=
'</div>';
262 $stringtoshow .=
'</div>';
264 $this->info_box_contents[0][0] = array(
'tr'=>
'class="oddeven nohover"',
'td' =>
'class="nohover center"',
'textnoformat'=>$stringtoshow);
266 $this->info_box_contents[0][0] = array(
267 'tr'=>
'class="oddeven nohover"',
268 'td' =>
'class="nohover left"',
274 $this->info_box_contents[0][0] = array(
275 'td' =>
'class="nohover opacitymedium left"',
276 'text' => $langs->trans(
"ReadPermissionNotAllowed")
289 public function showBox($head = null, $contents = null, $nooutput = 0)
291 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to manage the box to show last invoices.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
dol_now($mode= 'auto')
Return date for now.
$conf db
API class for accounts.
loadBox($max=5)
Load data into info_box_contents array to show array later.
dol_strlen($string, $stringencoding= 'UTF-8')
Make a strlen call.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_getdate($timestamp, $fast=false, $forcetimezone= '')
Return an array with locale date info.
__construct($db, $param)
Constructor.
Class to manage stats for invoices (customer and supplier)