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';
134 $stats->where =
"f.fk_statut > 0";
138 $data1 = $stats->getNbByMonthWithPrevYear($endyear, $startyear, (
GETPOST(
'action',
'aZ09') == $refreshaction ? -1 : (3600 * 24)), ($WIDTH < 300 ? 2 : 0), $startmonth);
140 $filenamenb = $dir.
"/".$prefix.
"invoicesnbinyear-".$endyear.
".png";
142 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=billstats&file=invoicesnbinyear-'.$endyear.
'.png';
145 $mesg = $px1->isGraphKo();
147 $langs->load(
"bills");
149 $px1->SetData($data1);
153 while ($i <= $endyear) {
154 if ($startmonth != 1) {
155 $legend[] = sprintf(
"%d/%d", $i - 2001, $i - 2000);
162 $px1->SetLegend($legend);
163 $px1->SetMaxValue($px1->GetCeilMaxValue());
164 $px1->SetWidth($WIDTH);
165 $px1->SetHeight($HEIGHT);
166 $px1->SetYLabel($langs->trans(
"NumberOfBills"));
168 $px1->SetHorizTickIncrement(1);
169 $px1->SetCssPrefix(
"cssboxes");
170 $px1->mode =
'depth';
171 $px1->SetTitle($langs->trans(
"NumberOfBillsByMonth"));
173 $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';
186 $mesg = $px2->isGraphKo();
188 $langs->load(
"bills");
190 $px2->SetData($data2);
194 while ($i <= $endyear) {
195 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)) {
218 $langs->load(
"errors");
219 $mesg = $langs->trans(
"WarningFeatureDisabledWithDisplayOptimizedForBlindNoJs");
224 $stringtoshow .=
'<script nonce="'.getNonce().
'" type="text/javascript">
225 jQuery(document).ready(function() {
226 jQuery("#idsubimg'.$this->boxcode.
'").click(function() {
227 jQuery("#idfilter'.$this->boxcode.
'").toggle();
231 $stringtoshow .=
'<div class="center hideobject" id="idfilter'.$this->boxcode.
'">';
232 $stringtoshow .=
'<form class="flat formboxfilter" method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
233 $stringtoshow .=
'<input type="hidden" name="token" value="'.newToken().
'">';
234 $stringtoshow .=
'<input type="hidden" name="action" value="'.$refreshaction.
'">';
235 $stringtoshow .=
'<input type="hidden" name="page_y" value="">';
236 $stringtoshow .=
'<input type="hidden" name="DOL_AUTOSET_COOKIE" value="DOLUSERCOOKIE_box_'.$this->boxcode.
':year,shownb,showtot">';
237 $stringtoshow .=
'<input type="checkbox" name="'.$param_shownb.
'"'.($shownb ?
' checked' :
'').
'> '.$langs->trans(
"NumberOfBillsByMonth");
238 $stringtoshow .=
' ';
239 $stringtoshow .=
'<input type="checkbox" name="'.$param_showtot.
'"'.($showtot ?
' checked' :
'').
'> '.$langs->trans(
"AmountOfBillsByMonthHT");
240 $stringtoshow .=
'<br>';
241 $stringtoshow .= $langs->trans(
"Year").
' <input class="flat" size="4" type="text" name="'.$param_year.
'" value="'.$endyear.
'">';
242 $stringtoshow .=
'<input type="image" class="reposition inline-block valigntextbottom" alt="'.$langs->trans(
"Refresh").
'" src="'.
img_picto($langs->trans(
"Refresh"),
'refresh.png',
'',
'', 1).
'">';
243 $stringtoshow .=
'</form>';
244 $stringtoshow .=
'</div>';
245 if ($shownb && $showtot) {
246 $stringtoshow .=
'<div class="fichecenter">';
247 $stringtoshow .=
'<div class="fichehalfleft">';
250 $stringtoshow .= $px1->show();
252 if ($shownb && $showtot) {
253 $stringtoshow .=
'</div>';
254 $stringtoshow .=
'<div class="fichehalfright">';
257 $stringtoshow .= $px2->show();
259 if ($shownb && $showtot) {
260 $stringtoshow .=
'</div>';
261 $stringtoshow .=
'</div>';
263 $this->info_box_contents[0][0] = array(
'tr'=>
'class="oddeven nohover"',
'td' =>
'class="nohover center"',
'textnoformat'=>$stringtoshow);
265 $this->info_box_contents[0][0] = array(
'tr'=>
'class="oddeven nohover"',
'td' =>
'class="nohover left"',
'maxlength'=>500,
'text' => $mesg);
268 $this->info_box_contents[0][0] = array(
269 'td' =>
'class="nohover left"',
270 'text' =>
'<span class="opacitymedium">'.$langs->trans(
"ReadPermissionNotAllowed").
'</span>'