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