23 include_once DOL_DOCUMENT_ROOT.
'/core/boxes/modules_boxes.php';
31 public $boxcode =
"invoicespermonth";
32 public $boximg =
"object_bill";
33 public $boxlabel =
"BoxCustomersInvoicesPerMonth";
34 public $depends = array(
"facture");
41 public $info_box_head = array();
42 public $info_box_contents = array();
57 $this->hidden = !($user->rights->facture->lire);
68 global $conf, $user, $langs;
72 $refreshaction =
'refresh_'.$this->boxcode;
77 $startmonth = $conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1;
78 if (empty($conf->global->GRAPH_USE_FISCAL_YEAR)) $startmonth = 1;
80 $text = $langs->trans(
"BoxCustomersInvoicesPerMonth", $max);
81 $this->info_box_head = array(
86 'subtext'=>$langs->trans(
"Filter"),
87 'subpicto'=>
'filter.png',
88 'subclass'=>
'linkobject boxfilter',
95 if ($user->socid) $socid = $user->socid;
96 if (!$user->rights->societe->client->voir || $socid) $prefix .=
'private-'.$user->id.
'-';
98 if ($user->rights->facture->lire)
102 $param_year =
'DOLUSERCOOKIE_box_'.$this->boxcode.
'_year';
103 $param_shownb =
'DOLUSERCOOKIE_box_'.$this->boxcode.
'_shownb';
104 $param_showtot =
'DOLUSERCOOKIE_box_'.$this->boxcode.
'_showtot';
106 include_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
107 include_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facturestats.class.php';
108 $autosetarray = preg_split(
"/[,;:]+/",
GETPOST(
'DOL_AUTOSET_COOKIE'));
109 if (in_array(
'DOLUSERCOOKIE_box_'.$this->boxcode, $autosetarray))
111 $endyear =
GETPOST($param_year,
'int');
112 $shownb =
GETPOST($param_shownb,
'alpha');
113 $showtot =
GETPOST($param_showtot,
'alpha');
115 $tmparray = json_decode($_COOKIE[
'DOLUSERCOOKIE_box_'.$this->boxcode],
true);
116 $endyear = $tmparray[
'year'];
117 $shownb = $tmparray[
'shownb'];
118 $showtot = $tmparray[
'showtot'];
120 if (empty($shownb) && empty($showtot)) { $shownb = 1; $showtot = 1; }
122 if (empty($endyear)) $endyear = $nowarray[
'year'];
123 $startyear = $endyear - (empty($conf->global->MAIN_NB_OF_YEAR_IN_WIDGET_GRAPH) ? 1 : $conf->global->MAIN_NB_OF_YEAR_IN_WIDGET_GRAPH);
126 $WIDTH = (($shownb && $showtot) || !empty($conf->dol_optimize_smallscreen)) ?
'256' :
'320';
134 $data1 = $stats->getNbByMonthWithPrevYear($endyear, $startyear, (
GETPOST(
'action',
'aZ09') == $refreshaction ?-1 : (3600 * 24)), ($WIDTH < 300 ? 2 : 0), $startmonth);
136 $filenamenb = $dir.
"/".$prefix.
"invoicesnbinyear-".$endyear.
".png";
138 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=billstats&file=invoicesnbinyear-'.$endyear.
'.png';
139 if ($mode ==
'supplier') $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=billstatssupplier&file=invoicessuppliernbinyear-'.$endyear.
'.png';
142 $mesg = $px1->isGraphKo();
145 $langs->load(
"bills");
147 $px1->SetData($data1);
149 $i = $startyear; $legend = array();
150 while ($i <= $endyear)
152 if ($startmonth != 1)
154 $legend[] = sprintf(
"%d/%d", $i - 2001, $i - 2000);
161 $px1->SetLegend($legend);
162 $px1->SetMaxValue($px1->GetCeilMaxValue());
163 $px1->SetWidth($WIDTH);
164 $px1->SetHeight($HEIGHT);
165 $px1->SetYLabel($langs->trans(
"NumberOfBills"));
167 $px1->SetHorizTickIncrement(1);
168 $px1->SetCssPrefix(
"cssboxes");
169 $px1->mode =
'depth';
170 $px1->SetTitle($langs->trans(
"NumberOfBillsByMonth"));
172 $px1->draw($filenamenb, $fileurlnb);
179 $data2 = $stats->getAmountByMonthWithPrevYear($endyear, $startyear, (
GETPOST(
'action',
'aZ09') == $refreshaction ?-1 : (3600 * 24)), ($WIDTH < 300 ? 2 : 0), $startmonth);
181 $filenamenb = $dir.
"/".$prefix.
"invoicesamountinyear-".$endyear.
".png";
183 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=billstats&file=invoicesamountinyear-'.$endyear.
'.png';
184 if ($mode ==
'supplier') $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=billstatssupplier&file=invoicessupplieramountinyear-'.$endyear.
'.png';
187 $mesg = $px2->isGraphKo();
190 $langs->load(
"bills");
192 $px2->SetData($data2);
194 $i = $startyear; $legend = array();
195 while ($i <= $endyear)
197 if ($startmonth != 1)
199 $legend[] = sprintf(
"%d/%d", $i - 2001, $i - 2000);
205 $px2->SetLegend($legend);
206 $px2->SetMaxValue($px2->GetCeilMaxValue());
207 $px2->SetWidth($WIDTH);
208 $px2->SetHeight($HEIGHT);
209 $px2->SetYLabel($langs->trans(
"AmountOfBillsHT"));
211 $px2->SetHorizTickIncrement(1);
212 $px2->SetCssPrefix(
"cssboxes");
213 $px2->mode =
'depth';
214 $px2->SetTitle($langs->trans(
"AmountOfBillsByMonthHT"));
216 $px2->draw($filenamenb, $fileurlnb);
220 if (empty($conf->use_javascript_ajax))
222 $langs->load(
"errors");
223 $mesg = $langs->trans(
"WarningFeatureDisabledWithDisplayOptimizedForBlindNoJs");
229 $stringtoshow .=
'<script type="text/javascript" language="javascript">
230 jQuery(document).ready(function() {
231 jQuery("#idsubimg'.$this->boxcode.
'").click(function() {
232 jQuery("#idfilter'.$this->boxcode.
'").toggle();
236 $stringtoshow .=
'<div class="center hideobject" id="idfilter'.$this->boxcode.
'">';
237 $stringtoshow .=
'<form class="flat formboxfilter" method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
238 $stringtoshow .=
'<input type="hidden" name="token" value="'.newToken().
'">';
239 $stringtoshow .=
'<input type="hidden" name="action" value="'.$refreshaction.
'">';
240 $stringtoshow .=
'<input type="hidden" name="page_y" value="">';
241 $stringtoshow .=
'<input type="hidden" name="DOL_AUTOSET_COOKIE" value="DOLUSERCOOKIE_box_'.$this->boxcode.
':year,shownb,showtot">';
242 $stringtoshow .=
'<input type="checkbox" name="'.$param_shownb.
'"'.($shownb ?
' checked' :
'').
'> '.$langs->trans(
"NumberOfBillsByMonth");
243 $stringtoshow .=
' ';
244 $stringtoshow .=
'<input type="checkbox" name="'.$param_showtot.
'"'.($showtot ?
' checked' :
'').
'> '.$langs->trans(
"AmountOfBillsByMonthHT");
245 $stringtoshow .=
'<br>';
246 $stringtoshow .= $langs->trans(
"Year").
' <input class="flat" size="4" type="text" name="'.$param_year.
'" value="'.$endyear.
'">';
247 $stringtoshow .=
'<input class="reposition inline-block valigntextbottom" type="image" alt="'.$langs->trans(
"Refresh").
'" src="'.
img_picto($langs->trans(
"Refresh"),
'refresh.png',
'',
'', 1).
'">';
248 $stringtoshow .=
'</form>';
249 $stringtoshow .=
'</div>';
250 if ($shownb && $showtot)
252 $stringtoshow .=
'<div class="fichecenter">';
253 $stringtoshow .=
'<div class="fichehalfleft">';
255 if ($shownb) $stringtoshow .= $px1->show();
256 if ($shownb && $showtot)
258 $stringtoshow .=
'</div>';
259 $stringtoshow .=
'<div class="fichehalfright">';
261 if ($showtot) $stringtoshow .= $px2->show();
262 if ($shownb && $showtot)
264 $stringtoshow .=
'</div>';
265 $stringtoshow .=
'</div>';
267 $this->info_box_contents[0][0] = array(
'tr'=>
'class="oddeven nohover"',
'td' =>
'class="nohover center"',
'textnoformat'=>$stringtoshow);
269 $this->info_box_contents[0][0] = array(
'tr'=>
'class="oddeven nohover"',
'td' =>
'class="nohover left"',
'maxlength'=>500,
'text' => $mesg);
272 $this->info_box_contents[0][0] = array(
273 'td' =>
'class="nohover left"',
274 'text' =>
'<span class="opacitymedium">'.$langs->trans(
"ReadPermissionNotAllowed").
'</span>'
287 public function showBox($head = null, $contents = null, $nooutput = 0)
289 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.
loadBox($max=5)
Load data into info_box_contents array to show array later.
dol_now($mode= 'auto')
Return date for now.
Class to manage the box to show last invoices.
$conf db
API class for accounts.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
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)