70 global $conf, $user, $langs;
74 $refreshaction =
'refresh_'.$this->boxcode;
76 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
78 $startmonth = $conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1;
83 $text = $langs->trans(
"BoxSuppliersInvoicesPerMonth", $max);
84 $this->info_box_head = array(
89 'subtext'=>$langs->trans(
"Filter"),
90 'subpicto'=>
'filter.png',
91 'subclass'=>
'linkobject boxfilter',
99 $socid = $user->socid;
101 if (!$user->hasRight(
'societe',
'client',
'voir') || $socid) {
102 $prefix .=
'private-'.$user->id.
'-';
105 if ($user->hasRight(
'fournisseur',
'facture',
'lire')) {
106 $param_year =
'DOLUSERCOOKIE_box_'.$this->boxcode.
'_year';
107 $param_shownb =
'DOLUSERCOOKIE_box_'.$this->boxcode.
'_shownb';
108 $param_showtot =
'DOLUSERCOOKIE_box_'.$this->boxcode.
'_showtot';
110 include_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
111 include_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facturestats.class.php';
112 $autosetarray = preg_split(
"/[,;:]+/",
GETPOST(
'DOL_AUTOSET_COOKIE'));
113 if (in_array(
'DOLUSERCOOKIE_box_'.$this->boxcode, $autosetarray)) {
114 $endyear =
GETPOST($param_year,
'int');
115 $shownb =
GETPOST($param_shownb,
'alpha');
116 $showtot =
GETPOST($param_showtot,
'alpha');
118 $tmparray = (!empty($_COOKIE[
'DOLUSERCOOKIE_box_'.$this->boxcode]) ? json_decode($_COOKIE[
'DOLUSERCOOKIE_box_'.$this->boxcode],
true) : array());
119 $endyear = (!empty($tmparray[
'year']) ? $tmparray[
'year'] :
'');
120 $shownb = (!empty($tmparray[
'shownb']) ? $tmparray[
'shownb'] :
'');
121 $showtot = (!empty($tmparray[
'showtot']) ? $tmparray[
'showtot'] :
'');
123 if (empty($shownb) && empty($showtot)) {
128 if (empty($endyear)) {
129 $endyear = $nowarray[
'year'];
131 $startyear = $endyear - (!
getDolGlobalString(
'MAIN_NB_OF_YEAR_IN_WIDGET_GRAPH') ? 2 : ($conf->global->MAIN_NB_OF_YEAR_IN_WIDGET_GRAPH - 1));
134 $WIDTH = (($shownb && $showtot) || !empty($conf->dol_optimize_smallscreen)) ?
'256' :
'320';
141 $data1 = $stats->getNbByMonthWithPrevYear($endyear, $startyear, (
GETPOST(
'action',
'aZ09') == $refreshaction ? -1 : (3600 * 24)), ($WIDTH < 300 ? 2 : 0), $startmonth);
143 $filenamenb = $dir.
"/".$prefix.
"invoicessuppliernbinyear-".$endyear.
".png";
145 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=billstatssupplier&file=invoicessuppliernbinyear-'.$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);
164 $px1->SetLegend($legend);
165 $px1->SetMaxValue($px1->GetCeilMaxValue());
166 $px1->SetWidth($WIDTH);
167 $px1->SetHeight($HEIGHT);
168 $px1->SetYLabel($langs->trans(
"NumberOfBills"));
170 $px1->SetHorizTickIncrement(1);
171 $px1->SetCssPrefix(
"cssboxes");
172 $px1->mode =
'depth';
173 $px1->SetTitle($langs->trans(
"NumberOfBillsByMonth"));
175 $px1->draw($filenamenb, $fileurlnb);
181 $data2 = $stats->getAmountByMonthWithPrevYear($endyear, $startyear, (
GETPOST(
'action',
'aZ09') == $refreshaction ? -1 : (3600 * 24)), ($WIDTH < 300 ? 2 : 0), $startmonth);
183 $filenamenb = $dir.
"/".$prefix.
"invoicessupplieramountinyear-".$endyear.
".png";
185 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=billstatssupplier&file=invoicessupplieramountinyear-'.$endyear.
'.png';
188 $mesg = $px2->isGraphKo();
190 $langs->load(
"bills");
192 $px2->SetData($data2);
196 while ($i <= $endyear) {
197 if ($startmonth != 1) {
198 $legend[] = sprintf(
"%d/%d", $i - 2001, $i - 2000);
204 $px2->SetLegend($legend);
205 $px2->SetMaxValue($px2->GetCeilMaxValue());
206 $px2->SetWidth($WIDTH);
207 $px2->SetHeight($HEIGHT);
208 $px2->SetYLabel($langs->trans(
"AmountOfBillsHT"));
210 $px2->SetHorizTickIncrement(1);
211 $px2->SetCssPrefix(
"cssboxes");
212 $px2->mode =
'depth';
213 $px2->SetTitle($langs->trans(
"AmountOfBillsByMonthHT"));
215 $px2->draw($filenamenb, $fileurlnb);
219 if (empty($conf->use_javascript_ajax)) {
220 $langs->load(
"errors");
221 $mesg = $langs->trans(
"WarningFeatureDisabledWithDisplayOptimizedForBlindNoJs");
226 $stringtoshow .=
'<script nonce="'.getNonce().
'" type="text/javascript">
227 jQuery(document).ready(function() {
228 jQuery("#idsubimg'.$this->boxcode.
'").click(function() {
229 jQuery("#idfilter'.$this->boxcode.
'").toggle();
233 $stringtoshow .=
'<div class="center hideobject" id="idfilter'.$this->boxcode.
'">';
234 $stringtoshow .=
'<form class="flat formboxfilter" method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
235 $stringtoshow .=
'<input type="hidden" name="token" value="'.newToken().
'">';
236 $stringtoshow .=
'<input type="hidden" name="action" value="'.$refreshaction.
'">';
237 $stringtoshow .=
'<input type="hidden" name="page_y" value="">';
238 $stringtoshow .=
'<input type="hidden" name="DOL_AUTOSET_COOKIE" value="DOLUSERCOOKIE_box_'.$this->boxcode.
':year,shownb,showtot">';
239 $stringtoshow .=
'<input type="checkbox" name="'.$param_shownb.
'"'.($shownb ?
' checked' :
'').
'> '.$langs->trans(
"NumberOfBillsByMonth");
240 $stringtoshow .=
' ';
241 $stringtoshow .=
'<input type="checkbox" name="'.$param_showtot.
'"'.($showtot ?
' checked' :
'').
'> '.$langs->trans(
"AmountOfBillsByMonthHT");
242 $stringtoshow .=
'<br>';
243 $stringtoshow .= $langs->trans(
"Year").
' <input class="flat" size="4" type="text" name="'.$param_year.
'" value="'.$endyear.
'">';
244 $stringtoshow .=
'<input type="image" class="reposition inline-block valigntextbottom" alt="'.$langs->trans(
"Refresh").
'" src="'.
img_picto($langs->trans(
"Refresh"),
'refresh.png',
'',
'', 1).
'">';
245 $stringtoshow .=
'</form>';
246 $stringtoshow .=
'</div>';
247 if ($shownb && $showtot) {
248 $stringtoshow .=
'<div class="fichecenter">';
249 $stringtoshow .=
'<div class="fichehalfleft">';
252 $stringtoshow .= $px1->show();
254 if ($shownb && $showtot) {
255 $stringtoshow .=
'</div>';
256 $stringtoshow .=
'<div class="fichehalfright">';
259 $stringtoshow .= $px2->show();
261 if ($shownb && $showtot) {
262 $stringtoshow .=
'</div>';
263 $stringtoshow .=
'</div>';
265 $this->info_box_contents[0][0] = array(
'tr'=>
'class="oddeven nohover"',
'td' =>
'class="nohover center"',
'textnoformat'=>$stringtoshow);
267 $this->info_box_contents[0][0] = array(
'tr'=>
'class="oddeven nohover"',
'td' =>
'class="nohover left"',
'maxlength'=>500,
'text' => $mesg);
270 $this->info_box_contents[0][0] = array(
271 'td' =>
'class="nohover left"',
272 'text' =>
'<span class="opacitymedium">'.$langs->trans(
"ReadPermissionNotAllowed").
'</span>'