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