dolibarr 21.0.0-alpha
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 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
27// Load Dolibarr environment
28require '../../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
30require_once DOL_DOCUMENT_ROOT.'/salaries/class/salariesstats.class.php';
31
32// Load translation files required by the page
33$langs->loadLangs(array("salaries", "companies", "bills"));
34
37
38$userid = GETPOSTINT('userid');
39if ($userid < 0) {
40 $userid = 0;
41}
42$socid = GETPOSTINT('socid');
43if ($socid < 0) {
44 $socid = 0;
45}
46$id = GETPOSTINT('id');
47
48// Security check
49$socid = GETPOSTINT("socid");
50if ($user->socid) {
51 $socid = $user->socid;
52}
53$result = restrictedArea($user, 'salaries', '', '', '');
54
55$nowyear = (int) dol_print_date(dol_now('gmt'), "%Y", 'gmt');
56$year = GETPOSTINT('year') > 0 ? GETPOSTINT('year') : $nowyear;
57$startyear = $year - (!getDolGlobalString('MAIN_STATS_GRAPHS_SHOW_N_YEARS') ? 2 : max(1, min(10, getDolGlobalString('MAIN_STATS_GRAPHS_SHOW_N_YEARS'))));
58$endyear = $year;
59
60
61/*
62 * View
63 */
64
65$form = new Form($db);
66
67
68llxHeader();
69
70$title = $langs->trans("SalariesStatistics");
71$dir = $conf->salaries->dir_temp;
72
73print load_fiche_titre($title, '', 'salary');
74
75dol_mkdir($dir);
76
77$useridtofilter = $userid; // Filter from parameters
78
79if (!$user->hasRight('salaries', 'readall') && empty($useridtofilter)) {
80 $useridtofilter = $user->getAllChildIds(1);
81}
82
83$stats = new SalariesStats($db, $socid, $useridtofilter);
84
85
86// Build graphic number of object
87// $data = array(array('Lib',val1,val2,val3),...)
88//print "$endyear, $startyear";
89$data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
90//var_dump($data);
91
92$filenamenb = $dir."/salariesnbinyear-".$year.".png";
93$fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=salariesstats&amp;file=salariesnbinyear-'.$year.'.png';
94
95$px1 = new DolGraph();
96$mesg = $px1->isGraphKo();
97if (!$mesg) {
98 $px1->SetData($data);
99 $i = $startyear;
100 $legend = array();
101 while ($i <= $endyear) {
102 $legend[] = $i;
103 $i++;
104 }
105 $px1->SetLegend($legend);
106 $px1->SetMaxValue($px1->GetCeilMaxValue());
107 $px1->SetWidth($WIDTH);
108 $px1->SetHeight($HEIGHT);
109 $px1->SetYLabel($langs->trans("Number"));
110 $px1->SetShading(3);
111 $px1->SetHorizTickIncrement(1);
112 $px1->mode = 'depth';
113 $px1->SetTitle($langs->trans("NumberByMonth"));
114
115 $px1->draw($filenamenb, $fileurlnb);
116}
117
118// Build graphic amount of object
119$data = $stats->getAmountByMonthWithPrevYear($endyear, $startyear);
120//var_dump($data);
121// $data = array(array('Lib',val1,val2,val3),...)
122
123$filenameamount = $dir."/salariesamountinyear-".$year.".png";
124$fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=salariesstats&amp;file=salariesamountinyear-'.$year.'.png';
125
126$px2 = new DolGraph();
127$mesg = $px2->isGraphKo();
128if (!$mesg) {
129 $px2->SetData($data);
130 $i = $startyear;
131 $legend = array();
132 while ($i <= $endyear) {
133 $legend[] = $i;
134 $i++;
135 }
136 $px2->SetLegend($legend);
137 $px2->SetMaxValue($px2->GetCeilMaxValue());
138 $px2->SetMinValue(min(0, $px2->GetFloorMinValue()));
139 $px2->SetWidth($WIDTH);
140 $px2->SetHeight($HEIGHT);
141 $px2->SetYLabel($langs->trans("Amount"));
142 $px2->SetShading(3);
143 $px2->SetHorizTickIncrement(1);
144 $px2->mode = 'depth';
145 $px2->SetTitle($langs->trans("AmountTotal"));
146
147 $px2->draw($filenameamount, $fileurlamount);
148}
149
150
151$data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
152
153$filename_avg = $dir."/salariesaverageinyear-".$year.".png";
154$fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=salariesstats&file=salariesaverageinyear-'.$year.'.png';
155
156$px3 = new DolGraph();
157$mesg = $px3->isGraphKo();
158if (!$mesg) {
159 $px3->SetData($data);
160 $i = $startyear;
161 $legend = array();
162 while ($i <= $endyear) {
163 $legend[] = $i;
164 $i++;
165 }
166 $px3->SetLegend($legend);
167 $px3->SetYLabel($langs->trans("AmountAverage"));
168 $px3->SetMaxValue($px3->GetCeilMaxValue());
169 $px3->SetMinValue($px3->GetFloorMinValue());
170 $px3->SetWidth($WIDTH);
171 $px3->SetHeight($HEIGHT);
172 $px3->SetShading(3);
173 $px3->SetHorizTickIncrement(1);
174 $px3->mode = 'depth';
175 $px3->SetTitle($langs->trans("AmountAverage"));
176
177 $px3->draw($filename_avg, $fileurl_avg);
178}
179
180
181// Show array
182$data = $stats->getAllByYear();
183$arrayyears = array();
184foreach ($data as $val) {
185 $arrayyears[$val['year']] = $val['year'];
186}
187if (!count($arrayyears)) {
188 $arrayyears[$nowyear] = $nowyear;
189}
190
191
192$h = 0;
193$head = array();
194$head[$h][0] = DOL_URL_ROOT.'/salaries/stats/index.php';
195$head[$h][1] = $langs->trans("ByMonthYear");
196$head[$h][2] = 'byyear';
197$h++;
198
199complete_head_from_modules($conf, $langs, null, $head, $h, 'salaries_stats');
200
201print dol_get_fiche_head($head, 'byyear', '', -1);
202
203
204print '<div class="fichecenter"><div class="fichethirdleft">';
205
206
207// Show filter box
208print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
209print '<input type="hidden" name="token" value="'.newToken().'">';
210
211print '<table class="noborder centpercent">';
212print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
213// User
214print '<tr><td>'.$langs->trans("Employee").'</td><td>';
215print img_picto('', 'user', 'class="pictofixedwidth"');
216print $form->select_dolusers(($userid ? $userid : -1), 'userid', 1, '', 0, !$user->hasRight('salaries', 'readall') ? 'hierarchyme' : '', '', 0, 0, 0, '', 0, '', 'widthcentpercentminusx maxwidth300');
217print '</td></tr>';
218// Year
219print '<tr><td>'.$langs->trans("Year").'</td><td>';
220if (!in_array($year, $arrayyears)) {
221 $arrayyears[$year] = $year;
222}
223arsort($arrayyears);
224print $form->selectarray('year', $arrayyears, $year, 0, 0, 0, '', 0, 0, 0, '', 'width75');
225print '</td></tr>';
226print '<tr><td align="center" colspan="2"><input type="submit" name="submit" class="button small" value="'.$langs->trans("Refresh").'"></td></tr>';
227print '</table>';
228print '</form>';
229print '<br><br>';
230
231print '<div class="div-table-responsive-no-min">';
232print '<table class="noborder centpercent">';
233print '<tr class="liste_titre" height="24">';
234print '<td class="center">'.$langs->trans("Year").'</td>';
235print '<td class="right">'.$langs->trans("Number").'</td>';
236print '<td class="right">'.$langs->trans("AmountTotal").'</td>';
237print '<td class="right">'.$langs->trans("AmountAverage").'</td>';
238print '</tr>';
239
240$oldyear = 0;
241foreach ($data as $val) {
242 $year = $val['year'];
243 while ($year && $oldyear > (int) $year + 1) {
244 // If we have empty year
245 $oldyear--;
246
247 print '<tr class="oddeven" height="24">';
248 print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$oldyear.'">'.$oldyear.'</a></td>';
249 print '<td class="right">0</td>';
250 print '<td class="right"><span class="amount">0</span></td>';
251 print '<td class="right"><span class="amount">0</span></td>';
252 print '</tr>';
253 }
254
255 print '<tr class="oddeven" height="24">';
256 print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'">'.$year.'</a></td>';
257 print '<td class="right">'.$val['nb'].'</td>';
258 print '<td class="right"><span class="amount">'.price(price2num($val['total'], 'MT'), 1).'</span></td>';
259 print '<td class="right"><span class="amount">'.price(price2num($val['avg'], 'MT'), 1).'</span></td>';
260 print '</tr>';
261 $oldyear = $year;
262}
263
264print '</table>';
265print '</div>';
266
267
268print '</div><div class="fichetwothirdright">';
269
270
271// Show graphs
272print '<table class="border centpercent"><tr class="pair nohover"><td align="center">';
273if ($mesg) {
274 print $mesg;
275} else {
276 print $px1->show();
277 print "<br>\n";
278 print $px2->show();
279 print "<br>\n";
280 print $px3->show();
281}
282print '</td></tr></table>';
283
284
285print '</div></div>';
286print '<div class="clearboth"></div>';
287
288
289print dol_get_fiche_end();
290
291// End of page
292llxFooter();
293$db->close();
$id
Definition account.php:39
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:70
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.
llxFooter()
Footer empty.
Definition document.php:107
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).
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 a 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.