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