dolibarr  16.0.5
index.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2018 Alexandre Spangaro <aspangaro@open-dsi.fr>
3  * Copyright (C) 2018 Fidesio <contact@fidesio.com>
4  * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
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 
26 require '../../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
28 require_once DOL_DOCUMENT_ROOT.'/salaries/class/salariesstats.class.php';
29 
30 // Load translation files required by the page
31 $langs->loadLangs(array("salaries", "companies", "bills"));
32 
34 $HEIGHT = DolGraph::getDefaultGraphSizeForStats('height');
35 
36 $userid = GETPOST('userid', 'int');
37 if ($userid < 0) {
38  $userid = 0;
39 }
40 $socid = GETPOST('socid', 'int');
41 if ($socid < 0) {
42  $socid = 0;
43 }
44 $id = GETPOST('id', 'int');
45 
46 // Security check
47 $socid = GETPOST("socid", "int");
48 if ($user->socid) {
49  $socid = $user->socid;
50 }
51 $result = restrictedArea($user, 'salaries', '', '', '');
52 
53 $nowyear = strftime("%Y", dol_now());
54 $year = GETPOST('year') > 0 ?GETPOST('year') : $nowyear;
55 $startyear = $year - (empty($conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS) ? 2 : max(1, min(10, $conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS)));
56 $endyear = $year;
57 
58 
59 /*
60  * View
61  */
62 
63 $form = new Form($db);
64 
65 
66 llxHeader();
67 
68 $title = $langs->trans("SalariesStatistics");
69 $dir = $conf->salaries->dir_temp;
70 
71 print load_fiche_titre($title, '', 'salary');
72 
73 dol_mkdir($dir);
74 
75 $useridtofilter = $userid; // Filter from parameters
76 
77 if (empty($user->rights->salaries->readall) && empty($useridtofilter)) {
78  $useridtofilter = $user->getAllChildIds(1);
79 }
80 
81 $stats = new SalariesStats($db, $socid, $useridtofilter);
82 
83 
84 // Build graphic number of object
85 // $data = array(array('Lib',val1,val2,val3),...)
86 //print "$endyear, $startyear";
87 $data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
88 //var_dump($data);
89 
90 $filenamenb = $dir."/salariesnbinyear-".$year.".png";
91 $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=salariesstats&amp;file=salariesnbinyear-'.$year.'.png';
92 
93 $px1 = new DolGraph();
94 $mesg = $px1->isGraphKo();
95 if (!$mesg) {
96  $px1->SetData($data);
97  $i = $startyear; $legend = array();
98  while ($i <= $endyear) {
99  $legend[] = $i;
100  $i++;
101  }
102  $px1->SetLegend($legend);
103  $px1->SetMaxValue($px1->GetCeilMaxValue());
104  $px1->SetWidth($WIDTH);
105  $px1->SetHeight($HEIGHT);
106  $px1->SetYLabel($langs->trans("Number"));
107  $px1->SetShading(3);
108  $px1->SetHorizTickIncrement(1);
109  $px1->mode = 'depth';
110  $px1->SetTitle($langs->trans("NumberByMonth"));
111 
112  $px1->draw($filenamenb, $fileurlnb);
113 }
114 
115 // Build graphic amount of object
116 $data = $stats->getAmountByMonthWithPrevYear($endyear, $startyear);
117 //var_dump($data);
118 // $data = array(array('Lib',val1,val2,val3),...)
119 
120 $filenameamount = $dir."/salariesamountinyear-".$year.".png";
121 $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=salariesstats&amp;file=salariesamountinyear-'.$year.'.png';
122 
123 $px2 = new DolGraph();
124 $mesg = $px2->isGraphKo();
125 if (!$mesg) {
126  $px2->SetData($data);
127  $i = $startyear; $legend = array();
128  while ($i <= $endyear) {
129  $legend[] = $i;
130  $i++;
131  }
132  $px2->SetLegend($legend);
133  $px2->SetMaxValue($px2->GetCeilMaxValue());
134  $px2->SetMinValue(min(0, $px2->GetFloorMinValue()));
135  $px2->SetWidth($WIDTH);
136  $px2->SetHeight($HEIGHT);
137  $px2->SetYLabel($langs->trans("Amount"));
138  $px2->SetShading(3);
139  $px2->SetHorizTickIncrement(1);
140  $px2->mode = 'depth';
141  $px2->SetTitle($langs->trans("AmountTotal"));
142 
143  $px2->draw($filenameamount, $fileurlamount);
144 }
145 
146 
147 $data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
148 
149 $filename_avg = $dir."/salariesaverageinyear-".$year.".png";
150 $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=salariesstats&file=salariesaverageinyear-'.$year.'.png';
151 
152 $px3 = new DolGraph();
153 $mesg = $px3->isGraphKo();
154 if (!$mesg) {
155  $px3->SetData($data);
156  $i = $startyear; $legend = array();
157  while ($i <= $endyear) {
158  $legend[] = $i;
159  $i++;
160  }
161  $px3->SetLegend($legend);
162  $px3->SetYLabel($langs->trans("AmountAverage"));
163  $px3->SetMaxValue($px3->GetCeilMaxValue());
164  $px3->SetMinValue($px3->GetFloorMinValue());
165  $px3->SetWidth($WIDTH);
166  $px3->SetHeight($HEIGHT);
167  $px3->SetShading(3);
168  $px3->SetHorizTickIncrement(1);
169  $px3->mode = 'depth';
170  $px3->SetTitle($langs->trans("AmountAverage"));
171 
172  $px3->draw($filename_avg, $fileurl_avg);
173 }
174 
175 
176 // Show array
177 $data = $stats->getAllByYear();
178 $arrayyears = array();
179 foreach ($data as $val) {
180  $arrayyears[$val['year']] = $val['year'];
181 }
182 if (!count($arrayyears)) {
183  $arrayyears[$nowyear] = $nowyear;
184 }
185 
186 
187 $h = 0;
188 $head = array();
189 $head[$h][0] = DOL_URL_ROOT.'/salaries/stats/index.php';
190 $head[$h][1] = $langs->trans("ByMonthYear");
191 $head[$h][2] = 'byyear';
192 $h++;
193 
194 complete_head_from_modules($conf, $langs, null, $head, $h, 'salaries_stats');
195 
196 print dol_get_fiche_head($head, 'byyear', $langs->trans("Statistics"), -1);
197 
198 
199 print '<div class="fichecenter"><div class="fichethirdleft">';
200 
201 
202 // Show filter box
203 print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
204 print '<input type="hidden" name="token" value="'.newToken().'">';
205 
206 print '<table class="noborder centpercent">';
207 print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
208 // User
209 print '<tr><td>'.$langs->trans("Employee").'</td><td>';
210 print img_picto('', 'user', 'class="pictofixedwidth"');
211 print $form->select_dolusers(($userid ? $userid : -1), 'userid', 1, '', 0, empty($user->rights->salaries->readall) ? 'hierarchyme' : '', '', 0, 0, 0, '', 0, '', 'widthcentpercentminusx maxwidth300');
212 print '</td></tr>';
213 // Year
214 print '<tr><td>'.$langs->trans("Year").'</td><td>';
215 if (!in_array($year, $arrayyears)) {
216  $arrayyears[$year] = $year;
217 }
218 arsort($arrayyears);
219 print $form->selectarray('year', $arrayyears, $year, 0, 0, 0, '', 0, 0, 0, '', 'width75');
220 print '</td></tr>';
221 print '<tr><td align="center" colspan="2"><input type="submit" name="submit" class="button small" value="'.$langs->trans("Refresh").'"></td></tr>';
222 print '</table>';
223 print '</form>';
224 print '<br><br>';
225 
226 print '<div class="div-table-responsive-no-min">';
227 print '<table class="noborder centpercent">';
228 print '<tr class="liste_titre" height="24">';
229 print '<td class="center">'.$langs->trans("Year").'</td>';
230 print '<td class="right">'.$langs->trans("Number").'</td>';
231 print '<td class="right">'.$langs->trans("AmountTotal").'</td>';
232 print '<td class="right">'.$langs->trans("AmountAverage").'</td>';
233 print '</tr>';
234 
235 $oldyear = 0;
236 foreach ($data as $val) {
237  $year = $val['year'];
238  while ($year && $oldyear > $year + 1) {
239  // If we have empty year
240  $oldyear--;
241 
242  print '<tr class="oddeven" height="24">';
243  print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$oldyear.'">'.$oldyear.'</a></td>';
244  print '<td class="right">0</td>';
245  print '<td class="right"><span class="amount">0</span></td>';
246  print '<td class="right"><span class="amount">0</span></td>';
247  print '</tr>';
248  }
249 
250  print '<tr class="oddeven" height="24">';
251  print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'">'.$year.'</a></td>';
252  print '<td class="right">'.$val['nb'].'</td>';
253  print '<td class="right"><span class="amount">'.price(price2num($val['total'], 'MT'), 1).'</span></td>';
254  print '<td class="right"><span class="amount">'.price(price2num($val['avg'], 'MT'), 1).'</span></td>';
255  print '</tr>';
256  $oldyear = $year;
257 }
258 
259 print '</table>';
260 print '</div>';
261 
262 
263 print '</div><div class="fichetwothirdright">';
264 
265 
266 // Show graphs
267 print '<table class="border centpercent"><tr class="pair nohover"><td align="center">';
268 if ($mesg) {
269  print $mesg;
270 } else {
271  print $px1->show();
272  print "<br>\n";
273  print $px2->show();
274  print "<br>\n";
275  print $px3->show();
276 }
277 print '</td></tr></table>';
278 
279 
280 print '</div></div>';
281 print '<div style="clear:both"></div>';
282 
283 
284 print dol_get_fiche_end();
285 
286 // End of page
287 llxFooter();
288 $db->close();
DolGraph\getDefaultGraphSizeForStats
static getDefaultGraphSizeForStats($direction, $defaultsize='')
getDefaultGraphSizeForStats
Definition: dolgraph.class.php:1539
restrictedArea
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
Definition: security.lib.php:234
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
DolGraph
Class to build graphs.
Definition: dolgraph.class.php:40
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
complete_head_from_modules
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add')
Complete or removed entries into a head array (used to build tabs).
Definition: functions.lib.php:9038
price2num
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
Definition: functions.lib.php:5661
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
llxFooter
llxFooter()
Footer empty.
Definition: index.php:71
SalariesStats
Classe permettant la gestion des stats des salaires.
Definition: salariesstats.class.php:31
llxHeader
if(!defined('NOTOKENRENEWAL')) if(!defined('NOLOGIN')) if(!defined('NOCSRFCHECK')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) if(!defined('NOIPCHECK')) if(!defined('NOBROWSERNOTIF')) llxHeader()
Header empty.
Definition: index.php:63
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2845
dol_mkdir
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
Definition: functions.lib.php:6603