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";
139 $data1 = $stats->getNbByMonthWithPrevYear($endyear, $startyear, (
GETPOST(
'action',
'aZ09') == $refreshaction ? -1 : (3600 * 24)), ($WIDTH < 300 ? 2 : 0), $startmonth);
141 $filenamenb = $dir.
"/".$prefix.
"invoicesnbinyear-".$endyear.
".png";
143 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=billstats&file=invoicesnbinyear-'.$endyear.
'.png';
146 $mesg = $px1->isGraphKo();
148 $langs->load(
"bills");
150 $px1->SetData($data1);
154 while ($i <= $endyear) {
155 if ($startmonth != 1) {
156 $legend[] = sprintf(
"%d/%d", $i - 2001, $i - 2000);
163 $px1->SetLegend($legend);
164 $px1->SetMaxValue($px1->GetCeilMaxValue());
165 $px1->SetWidth($WIDTH);
166 $px1->SetHeight($HEIGHT);
167 $px1->SetYLabel($langs->trans(
"NumberOfBills"));
169 $px1->SetHorizTickIncrement(1);
170 $px1->SetCssPrefix(
"cssboxes");
171 $px1->mode =
'depth';
172 $px1->SetTitle($langs->trans(
"NumberOfBillsByMonth"));
174 $px1->draw($filenamenb, $fileurlnb);
180 $data2 = $stats->getAmountByMonthWithPrevYear($endyear, $startyear, (
GETPOST(
'action',
'aZ09') == $refreshaction ? -1 : (3600 * 24)), ($WIDTH < 300 ? 2 : 0), $startmonth);
182 $filenamenb = $dir.
"/".$prefix.
"invoicesamountinyear-".$endyear.
".png";
184 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=billstats&file=invoicesamountinyear-'.$endyear.
'.png';
187 $mesg = $px2->isGraphKo();
189 $langs->load(
"bills");
191 $px2->SetData($data2);
195 while ($i <= $endyear) {
196 if ($startmonth != 1) {
197 $legend[] = sprintf(
"%d/%d", $i - 2001, $i - 2000);
203 $px2->SetLegend($legend);
204 $px2->SetMaxValue($px2->GetCeilMaxValue());
205 $px2->SetWidth($WIDTH);
206 $px2->SetHeight($HEIGHT);
207 $px2->SetYLabel($langs->trans(
"AmountOfBillsHT"));
209 $px2->SetHorizTickIncrement(1);
210 $px2->SetCssPrefix(
"cssboxes");
211 $px2->mode =
'depth';
212 $px2->SetTitle($langs->trans(
"AmountOfBillsByMonthHT"));
214 $px2->draw($filenamenb, $fileurlnb);
218 if (empty(
$conf->use_javascript_ajax)) {
219 $langs->load(
"errors");
220 $mesg = $langs->trans(
"WarningFeatureDisabledWithDisplayOptimizedForBlindNoJs");
225 $stringtoshow .=
'<script nonce="'.getNonce().
'" type="text/javascript">
226 jQuery(document).ready(function() {
227 jQuery("#idsubimg'.$this->boxcode.
'").click(function() {
228 jQuery("#idfilter'.$this->boxcode.
'").toggle();
232 $stringtoshow .=
'<div class="center hideobject" id="idfilter'.$this->boxcode.
'">';
233 $stringtoshow .=
'<form class="flat formboxfilter" method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
234 $stringtoshow .=
'<input type="hidden" name="token" value="'.newToken().
'">';
235 $stringtoshow .=
'<input type="hidden" name="action" value="'.$refreshaction.
'">';
236 $stringtoshow .=
'<input type="hidden" name="page_y" value="">';
237 $stringtoshow .=
'<input type="hidden" name="DOL_AUTOSET_COOKIE" value="DOLUSER_box_'.$this->boxcode.
':year,shownb,showtot">';
238 $stringtoshow .=
'<input type="checkbox" id="'.$param_shownb.
'" name="'.$param_shownb.
'"'.($shownb ?
' checked' :
'').
'><label for="'.$param_shownb.
'"> '.$langs->trans(
"NumberOfBillsByMonth").
'</label>';
239 $stringtoshow .=
' ';
240 $stringtoshow .=
'<input type="checkbox" id="'.$param_showtot.
'" name="'.$param_showtot.
'"'.($showtot ?
' checked' :
'').
'><label for="'.$param_showtot.
'"> '.$langs->trans(
"AmountOfBillsByMonthHT").
'</label>';
241 $stringtoshow .=
'<br>';
242 $stringtoshow .= $langs->trans(
"Year").
' <input class="flat" size="4" type="text" name="'.$param_year.
'" value="'.$endyear.
'">';
243 $stringtoshow .=
'<input type="image" class="reposition inline-block valigntextbottom" alt="'.$langs->trans(
"Refresh").
'" src="'.
img_picto($langs->trans(
"Refresh"),
'refresh.png',
'', 0, 1).
'">';
244 $stringtoshow .=
'</form>';
245 $stringtoshow .=
'</div>';
246 if ($shownb && $showtot) {
247 $stringtoshow .=
'<div class="fichecenter">';
248 $stringtoshow .=
'<div class="fichehalfleft">';
251 $stringtoshow .= $px1->show();
253 if ($shownb && $showtot) {
254 $stringtoshow .=
'</div>';
255 $stringtoshow .=
'<div class="fichehalfright">';
258 $stringtoshow .= $px2->show();
260 if ($shownb && $showtot) {
261 $stringtoshow .=
'</div>';
262 $stringtoshow .=
'</div>';
264 $this->info_box_contents[0][0] = array(
'tr' =>
'class="oddeven nohover"',
'td' =>
'class="nohover center"',
'textnoformat' => $stringtoshow);
266 $this->info_box_contents[0][0] = array(
'tr' =>
'class="oddeven nohover"',
'td' =>
'class="nohover left"',
'maxlength' => 500,
'text' => $mesg);
269 $this->info_box_contents[0][0] = array(
270 'td' =>
'class="nohover left"',
271 'text' =>
'<span class="opacitymedium">'.$langs->trans(
"ReadPermissionNotAllowed").
'</span>'