64 global
$conf, $user, $langs;
68 $refreshaction =
'refresh_'.$this->boxcode;
78 $text = $langs->trans(
"BoxCustomersInvoicesPerMonth", $max);
79 $this->info_box_head = array(
84 'subtext' => $langs->trans(
"Filter"),
85 'subpicto' =>
'filter.png',
86 'subclass' =>
'linkobject boxfilter',
94 $socid = $user->socid;
96 if (!$user->hasRight(
'societe',
'client',
'voir')) {
97 $prefix .=
'private-'.$user->id.
'-';
100 if ($user->hasRight(
'facture',
'lire')) {
103 $param_year =
'DOLUSER_box_'.$this->boxcode.
'_year';
104 $param_shownb =
'DOLUSER_box_'.$this->boxcode.
'_shownb';
105 $param_showtot =
'DOLUSER_box_'.$this->boxcode.
'_showtot';
107 include_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
108 include_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facturestats.class.php';
109 $autosetarray = preg_split(
"/[,;:]+/",
GETPOST(
'DOL_AUTOSET_COOKIE'));
110 if (in_array(
'DOLUSER_box_'.$this->boxcode, $autosetarray)) {
112 $shownb =
GETPOST($param_shownb,
'alpha');
113 $showtot =
GETPOST($param_showtot,
'alpha');
115 $tmparray = (!empty($_COOKIE[
'DOLUSER_box_'.$this->boxcode]) ? json_decode($_COOKIE[
'DOLUSER_box_'.$this->boxcode],
true) : array());
116 $endyear = (!empty($tmparray[
'year']) ? $tmparray[
'year'] :
'');
117 $shownb = (!empty($tmparray[
'shownb']) ? $tmparray[
'shownb'] :
'');
118 $showtot = (!empty($tmparray[
'showtot']) ? $tmparray[
'showtot'] :
'');
120 if (empty($shownb) && empty($showtot)) {
125 if (empty($endyear)) {
126 $endyear = $nowarray[
'year'];
128 $startyear = $endyear -
getDolGlobalInt(
'MAIN_NB_OF_YEAR_IN_WIDGET_GRAPH', 3) + 1;
131 $WIDTH = (($shownb && $showtot) || !empty(
$conf->dol_optimize_smallscreen)) ?
'256' :
'320';
135 $stats->where =
"f.fk_statut > 0";
141 $data1 = $stats->getNbByMonthWithPrevYear($endyear, $startyear, (
GETPOST(
'action',
'aZ09') == $refreshaction ? -1 : (3600 * 24)), ($WIDTH < 300 ? 2 : 0), $startmonth);
143 $filenamenb = $dir.
"/".$prefix.
"invoicesnbinyear-".$endyear.
".png";
145 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=billstats&file=invoicesnbinyear-'.$endyear.
'.png';
148 $mesg = $px1->isGraphKo();
150 $langs->load(
"bills");
152 $px1->SetData($data1);
156 while ($i <= $endyear) {
157 if ($startmonth != 1) {
158 $legend[] = sprintf(
"%d/%d", $i - 2001, $i - 2000);
165 $px1->SetLegend($legend);
166 $px1->SetMaxValue($px1->GetCeilMaxValue());
167 $px1->SetWidth($WIDTH);
168 $px1->SetHeight($HEIGHT);
169 $px1->SetYLabel($langs->trans(
"NumberOfBills"));
171 $px1->SetHorizTickIncrement(1);
172 $px1->SetCssPrefix(
"cssboxes");
173 $px1->mode =
'depth';
174 $px1->SetTitle($langs->trans(
"NumberOfBillsByMonth"));
176 $px1->draw($filenamenb, $fileurlnb);
182 $data2 = $stats->getAmountByMonthWithPrevYear($endyear, $startyear, (
GETPOST(
'action',
'aZ09') == $refreshaction ? -1 : (3600 * 24)), ($WIDTH < 300 ? 2 : 0), $startmonth);
184 $filenamenb = $dir.
"/".$prefix.
"invoicesamountinyear-".$endyear.
".png";
186 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=billstats&file=invoicesamountinyear-'.$endyear.
'.png';
189 $mesg = $px2->isGraphKo();
191 $langs->load(
"bills");
193 $px2->SetData($data2);
197 while ($i <= $endyear) {
198 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)) {
221 $langs->load(
"errors");
222 $mesg = $langs->trans(
"WarningFeatureDisabledWithDisplayOptimizedForBlindNoJs");
227 $stringtoshow .=
'<script nonce="'.getNonce().
'" type="text/javascript">
228 jQuery(document).ready(function() {
229 jQuery("#idsubimg'.$this->boxcode.
'").click(function() {
230 jQuery("#idfilter'.$this->boxcode.
'").toggle();
234 $stringtoshow .=
'<div class="center hideobject" id="idfilter'.$this->boxcode.
'">';
235 $stringtoshow .=
'<form class="flat formboxfilter" method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
236 $stringtoshow .=
'<input type="hidden" name="token" value="'.newToken().
'">';
237 $stringtoshow .=
'<input type="hidden" name="action" value="'.$refreshaction.
'">';
238 $stringtoshow .=
'<input type="hidden" name="page_y" value="">';
239 $stringtoshow .=
'<input type="hidden" name="DOL_AUTOSET_COOKIE" value="DOLUSER_box_'.$this->boxcode.
':year,shownb,showtot">';
240 $stringtoshow .=
'<input type="checkbox" id="'.$param_shownb.
'" name="'.$param_shownb.
'"'.($shownb ?
' checked' :
'').
'><label for="'.$param_shownb.
'"> '.$langs->trans(
"NumberOfBillsByMonth").
'</label>';
241 $stringtoshow .=
' ';
242 $stringtoshow .=
'<input type="checkbox" id="'.$param_showtot.
'" name="'.$param_showtot.
'"'.($showtot ?
' checked' :
'').
'><label for="'.$param_showtot.
'"> '.$langs->trans(
"AmountOfBillsByMonthHT").
'</label>';
243 $stringtoshow .=
'<br>';
244 $stringtoshow .= $langs->trans(
"Year").
' <input class="flat" size="4" type="text" name="'.$param_year.
'" value="'.$endyear.
'">';
245 $stringtoshow .=
'<input type="image" class="reposition inline-block valigntextbottom" alt="'.$langs->trans(
"Refresh").
'" src="'.
img_picto($langs->trans(
"Refresh"),
'refresh.png',
'', 0, 1).
'">';
246 $stringtoshow .=
'</form>';
247 $stringtoshow .=
'</div>';
248 if ($shownb && $showtot) {
249 $stringtoshow .=
'<div class="fichecenter">';
250 $stringtoshow .=
'<div class="fichehalfleft">';
252 if ($shownb && $px1 !==
null) {
253 $stringtoshow .= $px1->show();
255 if ($shownb && $showtot) {
256 $stringtoshow .=
'</div>';
257 $stringtoshow .=
'<div class="fichehalfright">';
259 if ($showtot && $px2 !==
null) {
260 $stringtoshow .= $px2->show();
262 if ($shownb && $showtot) {
263 $stringtoshow .=
'</div>';
264 $stringtoshow .=
'</div>';
266 $this->info_box_contents[0][0] = array(
'tr' =>
'class="oddeven nohover"',
'td' =>
'class="nohover center"',
'textnoformat' => $stringtoshow);
268 $this->info_box_contents[0][0] = array(
'tr' =>
'class="oddeven nohover"',
'td' =>
'class="nohover left"',
'maxlength' => 500,
'text' => $mesg);
271 $this->info_box_contents[0][0] = array(
272 'td' =>
'class="nohover left"',
273 'text' =>
'<span class="opacitymedium">'.$langs->trans(
"ReadPermissionNotAllowed").
'</span>'