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