70 global $conf, $user, $langs;
74 $refreshaction =
'refresh_'.$this->boxcode;
79 $startmonth = $conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1;
84 $text = $langs->trans(
"BoxCustomersInvoicesPerMonth", $max);
85 $this->info_box_head = array(
90 'subtext'=>$langs->trans(
"Filter"),
91 'subpicto'=>
'filter.png',
92 'subclass'=>
'linkobject boxfilter',
100 $socid = $user->socid;
102 if (!$user->hasRight(
'societe',
'client',
'voir') || $socid) {
103 $prefix .=
'private-'.$user->id.
'-';
106 if ($user->hasRight(
'facture',
'lire')) {
109 $param_year =
'DOLUSERCOOKIE_box_'.$this->boxcode.
'_year';
110 $param_shownb =
'DOLUSERCOOKIE_box_'.$this->boxcode.
'_shownb';
111 $param_showtot =
'DOLUSERCOOKIE_box_'.$this->boxcode.
'_showtot';
113 include_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
114 include_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facturestats.class.php';
115 $autosetarray = preg_split(
"/[,;:]+/",
GETPOST(
'DOL_AUTOSET_COOKIE'));
116 if (in_array(
'DOLUSERCOOKIE_box_'.$this->boxcode, $autosetarray)) {
117 $endyear =
GETPOST($param_year,
'int');
118 $shownb =
GETPOST($param_shownb,
'alpha');
119 $showtot =
GETPOST($param_showtot,
'alpha');
121 $tmparray = (!empty($_COOKIE[
'DOLUSERCOOKIE_box_'.$this->boxcode]) ? json_decode($_COOKIE[
'DOLUSERCOOKIE_box_'.$this->boxcode],
true) : array());
122 $endyear = (!empty($tmparray[
'year']) ? $tmparray[
'year'] :
'');
123 $shownb = (!empty($tmparray[
'shownb']) ? $tmparray[
'shownb'] :
'');
124 $showtot = (!empty($tmparray[
'showtot']) ? $tmparray[
'showtot'] :
'');
126 if (empty($shownb) && empty($showtot)) {
131 if (empty($endyear)) {
132 $endyear = $nowarray[
'year'];
134 $startyear = $endyear - (
getDolGlobalString(
'MAIN_NB_OF_YEAR_IN_WIDGET_GRAPH') ? ($conf->global->MAIN_NB_OF_YEAR_IN_WIDGET_GRAPH - 1) : 2);
137 $WIDTH = (($shownb && $showtot) || !empty($conf->dol_optimize_smallscreen)) ?
'256' :
'320';
144 $data1 = $stats->getNbByMonthWithPrevYear($endyear, $startyear, (
GETPOST(
'action',
'aZ09') == $refreshaction ? -1 : (3600 * 24)), ($WIDTH < 300 ? 2 : 0), $startmonth);
146 $filenamenb = $dir.
"/".$prefix.
"invoicesnbinyear-".$endyear.
".png";
148 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=billstats&file=invoicesnbinyear-'.$endyear.
'.png';
151 $mesg = $px1->isGraphKo();
153 $langs->load(
"bills");
155 $px1->SetData($data1);
159 while ($i <= $endyear) {
160 if ($startmonth != 1) {
161 $legend[] = sprintf(
"%d/%d", $i - 2001, $i - 2000);
168 $px1->SetLegend($legend);
169 $px1->SetMaxValue($px1->GetCeilMaxValue());
170 $px1->SetWidth($WIDTH);
171 $px1->SetHeight($HEIGHT);
172 $px1->SetYLabel($langs->trans(
"NumberOfBills"));
174 $px1->SetHorizTickIncrement(1);
175 $px1->SetCssPrefix(
"cssboxes");
176 $px1->mode =
'depth';
177 $px1->SetTitle($langs->trans(
"NumberOfBillsByMonth"));
179 $px1->draw($filenamenb, $fileurlnb);
185 $data2 = $stats->getAmountByMonthWithPrevYear($endyear, $startyear, (
GETPOST(
'action',
'aZ09') == $refreshaction ? -1 : (3600 * 24)), ($WIDTH < 300 ? 2 : 0), $startmonth);
187 $filenamenb = $dir.
"/".$prefix.
"invoicesamountinyear-".$endyear.
".png";
189 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=billstats&file=invoicesamountinyear-'.$endyear.
'.png';
192 $mesg = $px2->isGraphKo();
194 $langs->load(
"bills");
196 $px2->SetData($data2);
200 while ($i <= $endyear) {
201 if ($startmonth != 1) {
202 $legend[] = sprintf(
"%d/%d", $i - 2001, $i - 2000);
208 $px2->SetLegend($legend);
209 $px2->SetMaxValue($px2->GetCeilMaxValue());
210 $px2->SetWidth($WIDTH);
211 $px2->SetHeight($HEIGHT);
212 $px2->SetYLabel($langs->trans(
"AmountOfBillsHT"));
214 $px2->SetHorizTickIncrement(1);
215 $px2->SetCssPrefix(
"cssboxes");
216 $px2->mode =
'depth';
217 $px2->SetTitle($langs->trans(
"AmountOfBillsByMonthHT"));
219 $px2->draw($filenamenb, $fileurlnb);
223 if (empty($conf->use_javascript_ajax)) {
224 $langs->load(
"errors");
225 $mesg = $langs->trans(
"WarningFeatureDisabledWithDisplayOptimizedForBlindNoJs");
230 $stringtoshow .=
'<script nonce="'.getNonce().
'" type="text/javascript">
231 jQuery(document).ready(function() {
232 jQuery("#idsubimg'.$this->boxcode.
'").click(function() {
233 jQuery("#idfilter'.$this->boxcode.
'").toggle();
237 $stringtoshow .=
'<div class="center hideobject" id="idfilter'.$this->boxcode.
'">';
238 $stringtoshow .=
'<form class="flat formboxfilter" method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
239 $stringtoshow .=
'<input type="hidden" name="token" value="'.newToken().
'">';
240 $stringtoshow .=
'<input type="hidden" name="action" value="'.$refreshaction.
'">';
241 $stringtoshow .=
'<input type="hidden" name="page_y" value="">';
242 $stringtoshow .=
'<input type="hidden" name="DOL_AUTOSET_COOKIE" value="DOLUSERCOOKIE_box_'.$this->boxcode.
':year,shownb,showtot">';
243 $stringtoshow .=
'<input type="checkbox" name="'.$param_shownb.
'"'.($shownb ?
' checked' :
'').
'> '.$langs->trans(
"NumberOfBillsByMonth");
244 $stringtoshow .=
' ';
245 $stringtoshow .=
'<input type="checkbox" name="'.$param_showtot.
'"'.($showtot ?
' checked' :
'').
'> '.$langs->trans(
"AmountOfBillsByMonthHT");
246 $stringtoshow .=
'<br>';
247 $stringtoshow .= $langs->trans(
"Year").
' <input class="flat" size="4" type="text" name="'.$param_year.
'" value="'.$endyear.
'">';
248 $stringtoshow .=
'<input type="image" class="reposition inline-block valigntextbottom" alt="'.$langs->trans(
"Refresh").
'" src="'.
img_picto($langs->trans(
"Refresh"),
'refresh.png',
'',
'', 1).
'">';
249 $stringtoshow .=
'</form>';
250 $stringtoshow .=
'</div>';
251 if ($shownb && $showtot) {
252 $stringtoshow .=
'<div class="fichecenter">';
253 $stringtoshow .=
'<div class="fichehalfleft">';
256 $stringtoshow .= $px1->show();
258 if ($shownb && $showtot) {
259 $stringtoshow .=
'</div>';
260 $stringtoshow .=
'<div class="fichehalfright">';
263 $stringtoshow .= $px2->show();
265 if ($shownb && $showtot) {
266 $stringtoshow .=
'</div>';
267 $stringtoshow .=
'</div>';
269 $this->info_box_contents[0][0] = array(
'tr'=>
'class="oddeven nohover"',
'td' =>
'class="nohover center"',
'textnoformat'=>$stringtoshow);
271 $this->info_box_contents[0][0] = array(
'tr'=>
'class="oddeven nohover"',
'td' =>
'class="nohover left"',
'maxlength'=>500,
'text' => $mesg);
274 $this->info_box_contents[0][0] = array(
275 'td' =>
'class="nohover left"',
276 'text' =>
'<span class="opacitymedium">'.$langs->trans(
"ReadPermissionNotAllowed").
'</span>'