63 global $conf, $user, $langs;
67 $refreshaction =
'refresh_'.$this->boxcode;
77 $text = $langs->trans(
"BoxCustomersInvoicesPerMonth", $max);
78 $this->info_box_head = array(
83 'subtext'=>$langs->trans(
"Filter"),
84 'subpicto'=>
'filter.png',
85 'subclass'=>
'linkobject boxfilter',
93 $socid = $user->socid;
95 if (!$user->hasRight(
'societe',
'client',
'voir')) {
96 $prefix .=
'private-'.$user->id.
'-';
99 if ($user->hasRight(
'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 $shownb =
GETPOST($param_shownb,
'alpha');
112 $showtot =
GETPOST($param_showtot,
'alpha');
114 $tmparray = (!empty($_COOKIE[
'DOLUSERCOOKIE_box_'.$this->boxcode]) ? json_decode($_COOKIE[
'DOLUSERCOOKIE_box_'.$this->boxcode],
true) : array());
115 $endyear = (!empty($tmparray[
'year']) ? $tmparray[
'year'] :
'');
116 $shownb = (!empty($tmparray[
'shownb']) ? $tmparray[
'shownb'] :
'');
117 $showtot = (!empty($tmparray[
'showtot']) ? $tmparray[
'showtot'] :
'');
119 if (empty($shownb) && empty($showtot)) {
124 if (empty($endyear)) {
125 $endyear = $nowarray[
'year'];
127 $startyear = $endyear -
getDolGlobalInt(
'MAIN_NB_OF_YEAR_IN_WIDGET_GRAPH', 3) + 1;
130 $WIDTH = (($shownb && $showtot) || !empty($conf->dol_optimize_smallscreen)) ?
'256' :
'320';
137 $data1 = $stats->getNbByMonthWithPrevYear($endyear, $startyear, (
GETPOST(
'action',
'aZ09') == $refreshaction ? -1 : (3600 * 24)), ($WIDTH < 300 ? 2 : 0), $startmonth);
139 $filenamenb = $dir.
"/".$prefix.
"invoicesnbinyear-".$endyear.
".png";
141 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=billstats&file=invoicesnbinyear-'.$endyear.
'.png';
144 $mesg = $px1->isGraphKo();
146 $langs->load(
"bills");
148 $px1->SetData($data1);
152 while ($i <= $endyear) {
153 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);
178 $data2 = $stats->getAmountByMonthWithPrevYear($endyear, $startyear, (
GETPOST(
'action',
'aZ09') == $refreshaction ? -1 : (3600 * 24)), ($WIDTH < 300 ? 2 : 0), $startmonth);
180 $filenamenb = $dir.
"/".$prefix.
"invoicesamountinyear-".$endyear.
".png";
182 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=billstats&file=invoicesamountinyear-'.$endyear.
'.png';
185 $mesg = $px2->isGraphKo();
187 $langs->load(
"bills");
189 $px2->SetData($data2);
193 while ($i <= $endyear) {
194 if ($startmonth != 1) {
195 $legend[] = sprintf(
"%d/%d", $i - 2001, $i - 2000);
201 $px2->SetLegend($legend);
202 $px2->SetMaxValue($px2->GetCeilMaxValue());
203 $px2->SetWidth($WIDTH);
204 $px2->SetHeight($HEIGHT);
205 $px2->SetYLabel($langs->trans(
"AmountOfBillsHT"));
207 $px2->SetHorizTickIncrement(1);
208 $px2->SetCssPrefix(
"cssboxes");
209 $px2->mode =
'depth';
210 $px2->SetTitle($langs->trans(
"AmountOfBillsByMonthHT"));
212 $px2->draw($filenamenb, $fileurlnb);
216 if (empty($conf->use_javascript_ajax)) {
217 $langs->load(
"errors");
218 $mesg = $langs->trans(
"WarningFeatureDisabledWithDisplayOptimizedForBlindNoJs");
223 $stringtoshow .=
'<script nonce="'.getNonce().
'" type="text/javascript">
224 jQuery(document).ready(function() {
225 jQuery("#idsubimg'.$this->boxcode.
'").click(function() {
226 jQuery("#idfilter'.$this->boxcode.
'").toggle();
230 $stringtoshow .=
'<div class="center hideobject" id="idfilter'.$this->boxcode.
'">';
231 $stringtoshow .=
'<form class="flat formboxfilter" method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
232 $stringtoshow .=
'<input type="hidden" name="token" value="'.newToken().
'">';
233 $stringtoshow .=
'<input type="hidden" name="action" value="'.$refreshaction.
'">';
234 $stringtoshow .=
'<input type="hidden" name="page_y" value="">';
235 $stringtoshow .=
'<input type="hidden" name="DOL_AUTOSET_COOKIE" value="DOLUSERCOOKIE_box_'.$this->boxcode.
':year,shownb,showtot">';
236 $stringtoshow .=
'<input type="checkbox" name="'.$param_shownb.
'"'.($shownb ?
' checked' :
'').
'> '.$langs->trans(
"NumberOfBillsByMonth");
237 $stringtoshow .=
' ';
238 $stringtoshow .=
'<input type="checkbox" name="'.$param_showtot.
'"'.($showtot ?
' checked' :
'').
'> '.$langs->trans(
"AmountOfBillsByMonthHT");
239 $stringtoshow .=
'<br>';
240 $stringtoshow .= $langs->trans(
"Year").
' <input class="flat" size="4" type="text" name="'.$param_year.
'" value="'.$endyear.
'">';
241 $stringtoshow .=
'<input type="image" class="reposition inline-block valigntextbottom" alt="'.$langs->trans(
"Refresh").
'" src="'.
img_picto($langs->trans(
"Refresh"),
'refresh.png',
'',
'', 1).
'">';
242 $stringtoshow .=
'</form>';
243 $stringtoshow .=
'</div>';
244 if ($shownb && $showtot) {
245 $stringtoshow .=
'<div class="fichecenter">';
246 $stringtoshow .=
'<div class="fichehalfleft">';
249 $stringtoshow .= $px1->show();
251 if ($shownb && $showtot) {
252 $stringtoshow .=
'</div>';
253 $stringtoshow .=
'<div class="fichehalfright">';
256 $stringtoshow .= $px2->show();
258 if ($shownb && $showtot) {
259 $stringtoshow .=
'</div>';
260 $stringtoshow .=
'</div>';
262 $this->info_box_contents[0][0] = array(
'tr'=>
'class="oddeven nohover"',
'td' =>
'class="nohover center"',
'textnoformat'=>$stringtoshow);
264 $this->info_box_contents[0][0] = array(
'tr'=>
'class="oddeven nohover"',
'td' =>
'class="nohover left"',
'maxlength'=>500,
'text' => $mesg);
267 $this->info_box_contents[0][0] = array(
268 'td' =>
'class="nohover left"',
269 'text' =>
'<span class="opacitymedium">'.$langs->trans(
"ReadPermissionNotAllowed").
'</span>'