dolibarr 20.0.0
box_graph_invoices_peryear.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2013 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
24include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
25
26
31{
32 public $boxcode = "invoicesperyear";
33 public $boximg = "object_bill";
34 public $boxlabel = "BoxCustomersInvoicesPerYear";
35 public $depends = array("facture");
36
43 public function __construct($db, $param)
44 {
45 global $user;
46
47 $this->db = $db;
48
49 $this->hidden = !$user->hasRight('facture', 'lire');
50 }
51
58 public function loadBox($max = 5)
59 {
60 global $conf, $user, $langs;
61
62 $this->max = $max;
63
64 $refreshaction = 'refresh_'.$this->boxcode;
65
66 //include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
67 //$facturestatic=new Facture($this->db);
68
69 $startmonth = getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1);
70 if (!getDolGlobalString('GRAPH_USE_FISCAL_YEAR')) {
71 $startmonth = 1;
72 }
73
74 $text = $langs->trans("Turnover", $max);
75 $this->info_box_head = array(
76 'text' => $text,
77 'limit'=> dol_strlen($text),
78 'graph'=> 1,
79 'sublink'=>'',
80 'subtext'=>$langs->trans("Filter"),
81 'subpicto'=>'filter.png',
82 'subclass'=>'linkobject boxfilter',
83 'target'=>'none' // Set '' to get target="_blank"
84 );
85
86 $dir = ''; // We don't need a path because image file will not be saved into disk
87 $prefix = '';
88 $socid = 0;
89 if ($user->socid) {
90 $socid = $user->socid;
91 }
92 if (!$user->hasRight('societe', 'client', 'voir')) {
93 $prefix .= 'private-'.$user->id.'-';
94 } // If user has no permission to see all, output dir is specific to user
95
96 if ($user->hasRight('facture', 'lire')) {
97 $mesg = '';
98
99 $param_year = 'DOLUSERCOOKIE_box_'.$this->boxcode.'_year';
100 $param_showtot = 'DOLUSERCOOKIE_box_'.$this->boxcode.'_showtot';
101
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)) {
106 $endyear = GETPOSTINT($param_year);
107 $showtot = GETPOST($param_showtot, 'alpha');
108 } else {
109 $tmparray = json_decode($_COOKIE['DOLUSERCOOKIE_box_'.$this->boxcode], true);
110 $endyear = $tmparray['year'];
111 $showtot = $tmparray['showtot'];
112 }
113 if (empty($showtot)) {
114 $showtot = 1;
115 }
116 $nowarray = dol_getdate(dol_now(), true);
117 if (empty($endyear)) {
118 $endyear = $nowarray['year'];
119 }
120 $numberyears = getDolGlobalInt('MAIN_NB_OF_YEAR_IN_WIDGET_GRAPH', 5);
121 $startyear = $endyear - $numberyears;
122
123 $mode = 'customer';
124 $WIDTH = (($showtot) || !empty($conf->dol_optimize_smallscreen)) ? '256' : '320';
125 $HEIGHT = '192';
126
127 $stats = new FactureStats($this->db, $socid, $mode, 0);
128
129 // Build graphic amount of object. $data = array(array('Lib',val1,val2,val3),...)
130 $data2 = $stats->getAmountByYear($numberyears);
131
132 $filenamenb = $dir."/".$prefix."invoicesamountyears-".$endyear.".png";
133 // default value for customer mode
134 $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=billstats&file=invoicesamountyears-'.$endyear.'.png';
135 if ($mode == 'supplier') {
136 $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=billstatssupplier&file=invoicessupplieramountyears-'.$endyear.'.png';
137 }
138
139 $px2 = new DolGraph();
140 $mesg = $px2->isGraphKo();
141 if (!$mesg) {
142 $langs->load("bills");
143
144 $px2->SetData($data2);
145 unset($data2);
146 $i = $startyear;
147 /*$legend = array();
148 while ($i <= $endyear) {
149 if ($startmonth != 1) {
150 $legend[] = sprintf("%d/%d", $i - 2001, $i - 2000);
151 } else {
152 $legend[] = $i;
153 }
154 $i++;
155 }*/
156 $px2->SetLegend([$langs->trans("AmountOfBillsHT")]);
157 $px2->SetMaxValue($px2->GetCeilMaxValue());
158 $px2->SetWidth($WIDTH);
159 $px2->SetHeight($HEIGHT);
160 $px2->SetYLabel($langs->trans("AmountOfBillsHT"));
161 $px2->SetShading(3);
162 $px2->SetHorizTickIncrement(1);
163 $px2->SetCssPrefix("cssboxes");
164 $px2->mode = 'depth';
165 $px2->SetTitle($langs->trans("Turnover"));
166
167 $px2->draw($filenamenb, $fileurlnb);
168 }
169
170 if (empty($conf->use_javascript_ajax)) {
171 $langs->load("errors");
172 $mesg = $langs->trans("WarningFeatureDisabledWithDisplayOptimizedForBlindNoJs");
173 }
174
175 if (!$mesg) {
176 $stringtoshow = '';
177 $stringtoshow .= '<script nonce="'.getNonce().'" type="text/javascript" language="javascript">
178 jQuery(document).ready(function() {
179 jQuery("#idsubimg'.$this->boxcode.'").click(function() {
180 jQuery("#idfilter'.$this->boxcode.'").toggle();
181 });
182 });
183 </script>';
184 $stringtoshow .= '<div class="center hideobject" id="idfilter'.$this->boxcode.'">'; // hideobject is to start hidden
185 $stringtoshow .= '<form class="flat formboxfilter" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
186 $stringtoshow .= '<input type="hidden" name="token" value="'.newToken().'">';
187 $stringtoshow .= '<input type="hidden" name="action" value="'.$refreshaction.'">';
188 $stringtoshow .= '<input type="hidden" name="page_y" value="">';
189 $stringtoshow .= '<input type="hidden" name="DOL_AUTOSET_COOKIE" value="DOLUSERCOOKIE_box_'.$this->boxcode.':year,showtot">';
190 $stringtoshow .= $langs->trans("Year").' <input class="flat" size="4" type="text" name="'.$param_year.'" value="'.$endyear.'">';
191 $stringtoshow .= '<input class="reposition inline-block valigntextbottom" type="image" alt="'.$langs->trans("Refresh").'" src="'.img_picto($langs->trans("Refresh"), 'refresh.png', '', '', 1).'">';
192 $stringtoshow .= '</form>';
193 $stringtoshow .= '</div>';
194 $stringtoshow .= $px2->show();
195 $this->info_box_contents[0][0] = array('tr'=>'class="oddeven nohover"', 'td' => 'class="nohover center"', 'textnoformat'=>$stringtoshow);
196 } else {
197 $this->info_box_contents[0][0] = array('tr'=>'class="oddeven nohover"', 'td' => 'class="nohover left"', 'maxlength'=>500, 'text' => $mesg);
198 }
199 } else {
200 $this->info_box_contents[0][0] = array(
201 'td' => 'class="nohover left"',
202 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
203 );
204 }
205 }
206
215 public function showBox($head = null, $contents = null, $nooutput = 0)
216 {
217 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
218 }
219}
Class to build graphs.
Class to manage stats for invoices (customer and supplier)
Class ModeleBoxes.
Class to manage the box to show invoices per year graph.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
loadBox($max=5)
Load data into info_box_contents array to show array later.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.