dolibarr 18.0.6
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 (empty($conf->global->GRAPH_USE_FISCAL_YEAR)) $startmonth = 1;
79
80 $text = $langs->trans("Turnover", $max);
81 $this->info_box_head = array(
82 'text' => $text,
83 'limit'=> dol_strlen($text),
84 'graph'=> 1,
85 'sublink'=>'',
86 'subtext'=>$langs->trans("Filter"),
87 'subpicto'=>'filter.png',
88 'subclass'=>'linkobject boxfilter',
89 'target'=>'none' // Set '' to get target="_blank"
90 );
91
92 $dir = ''; // We don't need a path because image file will not be saved into disk
93 $prefix = '';
94 $socid = 0;
95 if ($user->socid) $socid = $user->socid;
96 if (empty($user->rights->societe->client->voir) || $socid) $prefix .= 'private-'.$user->id.'-'; // If user has no permission to see all, output dir is specific to user
97
98 if ($user->hasRight('facture', 'lire')) {
99 $mesg = '';
100
101 $param_year = 'DOLUSERCOOKIE_box_'.$this->boxcode.'_year';
102 $param_showtot = 'DOLUSERCOOKIE_box_'.$this->boxcode.'_showtot';
103
104 include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
105 include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facturestats.class.php';
106 $autosetarray = preg_split("/[,;:]+/", GETPOST('DOL_AUTOSET_COOKIE'));
107 if (in_array('DOLUSERCOOKIE_box_'.$this->boxcode, $autosetarray)) {
108 $endyear = GETPOST($param_year, 'int');
109 $showtot = GETPOST($param_showtot, 'alpha');
110 } else {
111 $tmparray = json_decode($_COOKIE['DOLUSERCOOKIE_box_'.$this->boxcode], true);
112 $endyear = $tmparray['year'];
113 $showtot = $tmparray['showtot'];
114 }
115 if (empty($showtot)) { $showtot = 1; }
116 $nowarray = dol_getdate(dol_now(), true);
117 if (empty($endyear)) $endyear = $nowarray['year'];
118 $numberyears = (empty($conf->global->MAIN_NB_OF_YEAR_IN_WIDGET_GRAPH) ? 5 : $conf->global->MAIN_NB_OF_YEAR_IN_WIDGET_GRAPH);
119 $startyear = $endyear - $numberyears;
120
121 $mode = 'customer';
122 $WIDTH = (($showtot) || !empty($conf->dol_optimize_smallscreen)) ? '256' : '320';
123 $HEIGHT = '192';
124
125 $stats = new FactureStats($this->db, $socid, $mode, 0);
126
127 // Build graphic amount of object. $data = array(array('Lib',val1,val2,val3),...)
128 $data2 = $stats->getAmountByYear($numberyears);
129
130 $filenamenb = $dir."/".$prefix."invoicesamountyears-".$endyear.".png";
131 // default value for customer mode
132 $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=billstats&file=invoicesamountyears-'.$endyear.'.png';
133 if ($mode == 'supplier') {
134 $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=billstatssupplier&file=invoicessupplieramountyears-'.$endyear.'.png';
135 }
136
137 $px2 = new DolGraph();
138 $mesg = $px2->isGraphKo();
139 if (!$mesg) {
140 $langs->load("bills");
141
142 $px2->SetData($data2);
143 unset($data2);
144 $i = $startyear;
145 /*$legend = array();
146 while ($i <= $endyear) {
147 if ($startmonth != 1) {
148 $legend[] = sprintf("%d/%d", $i - 2001, $i - 2000);
149 } else {
150 $legend[] = $i;
151 }
152 $i++;
153 }*/
154 $px2->SetLegend([$langs->trans("AmountOfBillsHT")]);
155 $px2->SetMaxValue($px2->GetCeilMaxValue());
156 $px2->SetWidth($WIDTH);
157 $px2->SetHeight($HEIGHT);
158 $px2->SetYLabel($langs->trans("AmountOfBillsHT"));
159 $px2->SetShading(3);
160 $px2->SetHorizTickIncrement(1);
161 $px2->SetCssPrefix("cssboxes");
162 $px2->mode = 'depth';
163 $px2->SetTitle($langs->trans("Turnover"));
164
165 $px2->draw($filenamenb, $fileurlnb);
166 }
167
168 if (empty($conf->use_javascript_ajax)) {
169 $langs->load("errors");
170 $mesg = $langs->trans("WarningFeatureDisabledWithDisplayOptimizedForBlindNoJs");
171 }
172
173 if (!$mesg) {
174 $stringtoshow = '';
175 $stringtoshow .= '<script nonce="'.getNonce().'" type="text/javascript" language="javascript">
176 jQuery(document).ready(function() {
177 jQuery("#idsubimg'.$this->boxcode.'").click(function() {
178 jQuery("#idfilter'.$this->boxcode.'").toggle();
179 });
180 });
181 </script>';
182 $stringtoshow .= '<div class="center hideobject" id="idfilter'.$this->boxcode.'">'; // hideobject is to start hidden
183 $stringtoshow .= '<form class="flat formboxfilter" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
184 $stringtoshow .= '<input type="hidden" name="token" value="'.newToken().'">';
185 $stringtoshow .= '<input type="hidden" name="action" value="'.$refreshaction.'">';
186 $stringtoshow .= '<input type="hidden" name="page_y" value="">';
187 $stringtoshow .= '<input type="hidden" name="DOL_AUTOSET_COOKIE" value="DOLUSERCOOKIE_box_'.$this->boxcode.':year,showtot">';
188 $stringtoshow .= $langs->trans("Year").' <input class="flat" size="4" type="text" name="'.$param_year.'" value="'.$endyear.'">';
189 $stringtoshow .= '<input class="reposition inline-block valigntextbottom" type="image" alt="'.$langs->trans("Refresh").'" src="'.img_picto($langs->trans("Refresh"), 'refresh.png', '', '', 1).'">';
190 $stringtoshow .= '</form>';
191 $stringtoshow .= '</div>';
192 $stringtoshow .= $px2->show();
193 $this->info_box_contents[0][0] = array('tr'=>'class="oddeven nohover"', 'td' => 'class="nohover center"', 'textnoformat'=>$stringtoshow);
194 } else {
195 $this->info_box_contents[0][0] = array('tr'=>'class="oddeven nohover"', 'td' => 'class="nohover left"', 'maxlength'=>500, 'text' => $mesg);
196 }
197 } else {
198 $this->info_box_contents[0][0] = array(
199 'td' => 'class="nohover left"',
200 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
201 );
202 }
203 }
204
213 public function showBox($head = null, $contents = null, $nooutput = 0)
214 {
215 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
216 }
217}
Class to build graphs.
Class to manage stats for invoices (customer and supplier)
Class ModeleBoxes.
Class to manage the box to show last invoices.
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.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.