62 global $conf, $user, $langs;
66 $refreshaction =
'refresh_'.$this->boxcode;
68 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
75 $text = $langs->trans(
"BoxSuppliersInvoicesPerMonth", $max);
76 $this->info_box_head = array(
81 'subtext'=>$langs->trans(
"Filter"),
82 'subpicto'=>
'filter.png',
83 'subclass'=>
'linkobject boxfilter',
91 $socid = $user->socid;
93 if (!$user->hasRight(
'societe',
'client',
'voir')) {
94 $prefix .=
'private-'.$user->id.
'-';
97 if ($user->hasRight(
'fournisseur',
'facture',
'lire')) {
98 $param_year =
'DOLUSERCOOKIE_box_'.$this->boxcode.
'_year';
99 $param_shownb =
'DOLUSERCOOKIE_box_'.$this->boxcode.
'_shownb';
100 $param_showtot =
'DOLUSERCOOKIE_box_'.$this->boxcode.
'_showtot';
102 include_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
103 include_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facturestats.class.php';
104 $autosetarray = preg_split(
"/[,;:]+/",
GETPOST(
'DOL_AUTOSET_COOKIE'));
105 if (in_array(
'DOLUSERCOOKIE_box_'.$this->boxcode, $autosetarray)) {
107 $shownb =
GETPOST($param_shownb,
'alpha');
108 $showtot =
GETPOST($param_showtot,
'alpha');
110 $tmparray = (!empty($_COOKIE[
'DOLUSERCOOKIE_box_'.$this->boxcode]) ? json_decode($_COOKIE[
'DOLUSERCOOKIE_box_'.$this->boxcode],
true) : array());
111 $endyear = (!empty($tmparray[
'year']) ? $tmparray[
'year'] :
'');
112 $shownb = (!empty($tmparray[
'shownb']) ? $tmparray[
'shownb'] :
'');
113 $showtot = (!empty($tmparray[
'showtot']) ? $tmparray[
'showtot'] :
'');
115 if (empty($shownb) && empty($showtot)) {
120 if (empty($endyear)) {
121 $endyear = $nowarray[
'year'];
123 $startyear = $endyear -
getDolGlobalInt(
'MAIN_NB_OF_YEAR_IN_WIDGET_GRAPH', 3) + 1;
126 $WIDTH = (($shownb && $showtot) || !empty($conf->dol_optimize_smallscreen)) ?
'256' :
'320';
133 $data1 = $stats->getNbByMonthWithPrevYear($endyear, $startyear, (
GETPOST(
'action',
'aZ09') == $refreshaction ? -1 : (3600 * 24)), ($WIDTH < 300 ? 2 : 0), $startmonth);
135 $filenamenb = $dir.
"/".$prefix.
"invoicessuppliernbinyear-".$endyear.
".png";
137 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=billstatssupplier&file=invoicessuppliernbinyear-'.$endyear.
'.png';
140 $mesg = $px1->isGraphKo();
142 $langs->load(
"bills");
144 $px1->SetData($data1);
148 while ($i <= $endyear) {
149 if ($startmonth != 1) {
150 $legend[] = sprintf(
"%d/%d", $i - 2001, $i - 2000);
156 $px1->SetLegend($legend);
157 $px1->SetMaxValue($px1->GetCeilMaxValue());
158 $px1->SetWidth($WIDTH);
159 $px1->SetHeight($HEIGHT);
160 $px1->SetYLabel($langs->trans(
"NumberOfBills"));
162 $px1->SetHorizTickIncrement(1);
163 $px1->SetCssPrefix(
"cssboxes");
164 $px1->mode =
'depth';
165 $px1->SetTitle($langs->trans(
"NumberOfBillsByMonth"));
167 $px1->draw($filenamenb, $fileurlnb);
173 $data2 = $stats->getAmountByMonthWithPrevYear($endyear, $startyear, (
GETPOST(
'action',
'aZ09') == $refreshaction ? -1 : (3600 * 24)), ($WIDTH < 300 ? 2 : 0), $startmonth);
175 $filenamenb = $dir.
"/".$prefix.
"invoicessupplieramountinyear-".$endyear.
".png";
177 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=billstatssupplier&file=invoicessupplieramountinyear-'.$endyear.
'.png';
180 $mesg = $px2->isGraphKo();
182 $langs->load(
"bills");
184 $px2->SetData($data2);
188 while ($i <= $endyear) {
189 if ($startmonth != 1) {
190 $legend[] = sprintf(
"%d/%d", $i - 2001, $i - 2000);
196 $px2->SetLegend($legend);
197 $px2->SetMaxValue($px2->GetCeilMaxValue());
198 $px2->SetWidth($WIDTH);
199 $px2->SetHeight($HEIGHT);
200 $px2->SetYLabel($langs->trans(
"AmountOfBillsHT"));
202 $px2->SetHorizTickIncrement(1);
203 $px2->SetCssPrefix(
"cssboxes");
204 $px2->mode =
'depth';
205 $px2->SetTitle($langs->trans(
"AmountOfBillsByMonthHT"));
207 $px2->draw($filenamenb, $fileurlnb);
211 if (empty($conf->use_javascript_ajax)) {
212 $langs->load(
"errors");
213 $mesg = $langs->trans(
"WarningFeatureDisabledWithDisplayOptimizedForBlindNoJs");
218 $stringtoshow .=
'<script nonce="'.getNonce().
'" type="text/javascript">
219 jQuery(document).ready(function() {
220 jQuery("#idsubimg'.$this->boxcode.
'").click(function() {
221 jQuery("#idfilter'.$this->boxcode.
'").toggle();
225 $stringtoshow .=
'<div class="center hideobject" id="idfilter'.$this->boxcode.
'">';
226 $stringtoshow .=
'<form class="flat formboxfilter" method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
227 $stringtoshow .=
'<input type="hidden" name="token" value="'.newToken().
'">';
228 $stringtoshow .=
'<input type="hidden" name="action" value="'.$refreshaction.
'">';
229 $stringtoshow .=
'<input type="hidden" name="page_y" value="">';
230 $stringtoshow .=
'<input type="hidden" name="DOL_AUTOSET_COOKIE" value="DOLUSERCOOKIE_box_'.$this->boxcode.
':year,shownb,showtot">';
231 $stringtoshow .=
'<input type="checkbox" name="'.$param_shownb.
'"'.($shownb ?
' checked' :
'').
'> '.$langs->trans(
"NumberOfBillsByMonth");
232 $stringtoshow .=
' ';
233 $stringtoshow .=
'<input type="checkbox" name="'.$param_showtot.
'"'.($showtot ?
' checked' :
'').
'> '.$langs->trans(
"AmountOfBillsByMonthHT");
234 $stringtoshow .=
'<br>';
235 $stringtoshow .= $langs->trans(
"Year").
' <input class="flat" size="4" type="text" name="'.$param_year.
'" value="'.$endyear.
'">';
236 $stringtoshow .=
'<input type="image" class="reposition inline-block valigntextbottom" alt="'.$langs->trans(
"Refresh").
'" src="'.
img_picto($langs->trans(
"Refresh"),
'refresh.png',
'',
'', 1).
'">';
237 $stringtoshow .=
'</form>';
238 $stringtoshow .=
'</div>';
239 if ($shownb && $showtot) {
240 $stringtoshow .=
'<div class="fichecenter">';
241 $stringtoshow .=
'<div class="fichehalfleft">';
244 $stringtoshow .= $px1->show();
246 if ($shownb && $showtot) {
247 $stringtoshow .=
'</div>';
248 $stringtoshow .=
'<div class="fichehalfright">';
251 $stringtoshow .= $px2->show();
253 if ($shownb && $showtot) {
254 $stringtoshow .=
'</div>';
255 $stringtoshow .=
'</div>';
257 $this->info_box_contents[0][0] = array(
'tr'=>
'class="oddeven nohover"',
'td' =>
'class="nohover center"',
'textnoformat'=>$stringtoshow);
259 $this->info_box_contents[0][0] = array(
'tr'=>
'class="oddeven nohover"',
'td' =>
'class="nohover left"',
'maxlength'=>500,
'text' => $mesg);
262 $this->info_box_contents[0][0] = array(
263 'td' =>
'class="nohover left"',
264 'text' =>
'<span class="opacitymedium">'.$langs->trans(
"ReadPermissionNotAllowed").
'</span>'