dolibarr 25.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-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';
37require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
38require_once DOL_DOCUMENT_ROOT.'/salaries/class/salary.class.php';
39require_once DOL_DOCUMENT_ROOT.'/salaries/class/salariesstats.class.php';
40
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$object = new Salary($db);
70
71$permissiontoread = $user->hasRight('salaries', 'read');
72$permissiontoadd = $user->hasRight('salaries', 'write');
73$permissiontodelete = $user->hasRight('salaries', 'delete');
74
75/*
76 * Actions
77 */
78
79// None
80
81
82/*
83 * View
84 */
85
86$form = new Form($db);
87
88
89llxHeader();
90
91$title = $langs->trans("Salaries");
92$dir = $conf->salaries->dir_temp;
93
94
95$url = DOL_URL_ROOT.'/salaries/card.php?action=create';
96if (!empty($socid)) {
97 $url .= '&socid='.$socid;
98}
99
100$param = '';
101$sortfield = '';
102$sortorder = '';
103$massactionbutton = '';
104$num = -1;
105$nbtotalofrecords = $langs->trans("Statistics");
106$limit = 0;
107
108$newcardbutton = '';
109$newcardbutton .= dolGetButtonTitle($langs->trans('ViewList'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/salaries/list.php?mode=common'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', 1, array('morecss' => 'reposition'));
110$newcardbutton .= dolGetButtonTitle($langs->trans('ViewKanban'), '', 'fa fa-th-list imgforviewmode', DOL_URL_ROOT.'/salaries/list.php?mode=kanban'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', 1, array('morecss' => 'reposition'));
111$newcardbutton .= dolGetButtonTitle($langs->trans('Statistics'), '', 'fa fa-chart-bar imgforviewmode', DOL_URL_ROOT.'/salaries/stats/index.php?'.preg_replace('/(&|\?)*(mode|groupby)=[^&]+/', '', $param), '', 2, array('morecss' => 'reposition'));
112$newcardbutton .= dolGetButtonTitleSeparator();
113$newcardbutton .= dolGetButtonTitle($langs->trans('NewSalary'), '', 'fa fa-plus-circle', $url, '', $permissiontoadd);
114
115print_barre_liste($title, 0, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, $object->picto, 0, $newcardbutton, '', $limit, 0, 0, 1);
116
117dol_mkdir($dir);
118
119$useridtofilter = $userid; // Filter from parameters
120
121if (!$user->hasRight('salaries', 'readchild') && empty($useridtofilter)) {
122 $useridtofilter = $user->id;
123}
124if (!$user->hasRight('salaries', 'readall') && empty($useridtofilter)) {
125 $useridtofilter = $user->getAllChildIds(1);
126}
127
128$stats = new SalariesStats($db, $socid, $useridtofilter);
129
130
131// Build graphic number of object
132// $data = array(array('Lib',val1,val2,val3),...)
133//print "$endyear, $startyear";
134$data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
135//var_dump($data);
136
137$filenamenb = $dir."/salariesnbinyear-".$year.".png";
138$fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=salariesstats&amp;file=salariesnbinyear-'.$year.'.png';
139
140$px1 = new DolGraph();
141$mesg = $px1->isGraphKo();
142if (!$mesg) {
143 $px1->SetData($data);
144 $i = $startyear;
145 $legend = array();
146 while ($i <= $endyear) {
147 $legend[] = $i;
148 $i++;
149 }
150 $px1->SetLegend($legend);
151 $px1->SetMaxValue($px1->GetCeilMaxValue());
152 $px1->SetWidth($WIDTH);
153 $px1->SetHeight($HEIGHT);
154 $px1->SetYLabel($langs->trans("Number"));
155 $px1->SetShading(3);
156 $px1->SetHorizTickIncrement(1);
157 $px1->mode = 'depth';
158 $px1->SetTitle($langs->trans("NumberByMonth"));
159
160 $px1->draw($filenamenb, $fileurlnb);
161}
162
163// Build graphic amount of object
164$data = $stats->getAmountByMonthWithPrevYear($endyear, $startyear);
165//var_dump($data);
166// $data = array(array('Lib',val1,val2,val3),...)
167
168$filenameamount = $dir."/salariesamountinyear-".$year.".png";
169$fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=salariesstats&amp;file=salariesamountinyear-'.$year.'.png';
170
171$px2 = new DolGraph();
172$mesg = $px2->isGraphKo();
173if (!$mesg) {
174 $px2->SetData($data);
175 $i = $startyear;
176 $legend = array();
177 while ($i <= $endyear) {
178 $legend[] = $i;
179 $i++;
180 }
181 $px2->SetLegend($legend);
182 $px2->SetMaxValue($px2->GetCeilMaxValue());
183 $px2->SetMinValue(min(0, $px2->GetFloorMinValue()));
184 $px2->SetWidth($WIDTH);
185 $px2->SetHeight($HEIGHT);
186 $px2->SetYLabel($langs->trans("Amount"));
187 $px2->SetShading(3);
188 $px2->SetHorizTickIncrement(1);
189 $px2->mode = 'depth';
190 $px2->SetTitle($langs->trans("AmountTotal"));
191
192 $px2->draw($filenameamount, $fileurlamount);
193}
194
195
196$data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
197
198$filename_avg = $dir."/salariesaverageinyear-".$year.".png";
199$fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=salariesstats&file=salariesaverageinyear-'.$year.'.png';
200
201$px3 = new DolGraph();
202$mesg = $px3->isGraphKo();
203if (!$mesg) {
204 $px3->SetData($data);
205 $i = $startyear;
206 $legend = array();
207 while ($i <= $endyear) {
208 $legend[] = $i;
209 $i++;
210 }
211 $px3->SetLegend($legend);
212 $px3->SetYLabel($langs->trans("AmountAverage"));
213 $px3->SetMaxValue($px3->GetCeilMaxValue());
214 $px3->SetMinValue((int) $px3->GetFloorMinValue());
215 $px3->SetWidth($WIDTH);
216 $px3->SetHeight($HEIGHT);
217 $px3->SetShading(3);
218 $px3->SetHorizTickIncrement(1);
219 $px3->mode = 'depth';
220 $px3->SetTitle($langs->trans("AmountAverage"));
221
222 $px3->draw($filename_avg, $fileurl_avg);
223}
224
225
226// Show array
227$data = $stats->getAllByYear();
228$arrayyears = array();
229foreach ($data as $val) {
230 $arrayyears[$val['year']] = $val['year'];
231}
232if (!count($arrayyears)) {
233 $arrayyears[$nowyear] = $nowyear;
234}
235
236
237$h = 0;
238$head = array();
239$head[$h][0] = DOL_URL_ROOT.'/salaries/stats/index.php';
240$head[$h][1] = $langs->trans("ByMonthYear");
241$head[$h][2] = 'byyear';
242$h++;
243
244complete_head_from_modules($conf, $langs, null, $head, $h, 'salaries_stats');
245
246print dol_get_fiche_head($head, 'byyear', '', -1);
247
248
249print '<div class="fichecenter"><div class="fichethirdleft">';
250
251
252// Show filter box
253print '<form name="stats" method="POST" action="'.dolBuildUrl($_SERVER["PHP_SELF"]).'">';
254print '<input type="hidden" name="token" value="'.newToken().'">';
255print '<table class="noborder centpercent">';
256print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
257
258// User
259print '<tr><td>'.$langs->trans("Employee").'</td><td>';
260if (!$user->hasRight('salaries', 'readchild') && empty($useridtofilter)) {
261 print img_picto('', 'user', 'class="pictofixedwidth"');
262 print $form->select_dolusers(($userid ? $userid : -1), 'userid', 1, null, 0, !$user->hasRight('salaries', 'readall') ? 'hierarchyme' : '', '', '0', 0, 0, '', 0, '', 'widthcentpercentminusx maxwidth300');
263} else {
264 print $user->getNomUrl(1);
265}
266print '</td></tr>';
267
268// Year
269print '<tr><td>'.$langs->trans("Year").'</td><td>';
270if (!in_array($year, $arrayyears)) {
271 $arrayyears[$year] = $year;
272}
273arsort($arrayyears);
274print img_picto('', 'calendar', 'class="pictofixedwidth"');
275print $form->selectarray('year', $arrayyears, $year, 0, 0, 0, '', 0, 0, 0, '', 'width75');
276print '</td></tr>';
277print '<tr><td align="center" colspan="2"><input type="submit" name="submit" class="button small" value="'.$langs->trans("Refresh").'"></td></tr>';
278print '</table>';
279print '</form>';
280print '<br><br>';
281print '<div class="div-table-responsive-no-min">';
282print '<table class="noborder centpercent">';
283print '<tr class="liste_titre" height="24">';
284print '<td class="center">'.$langs->trans("Year").'</td>';
285print '<td class="right">'.$langs->trans("Number").'</td>';
286print '<td class="right">'.$langs->trans("AmountTotal").'</td>';
287print '<td class="right">'.$langs->trans("AmountAverage").'</td>';
288print '</tr>';
289
290$oldyear = 0;
291foreach ($data as $val) {
292 $year = $val['year'];
293 while ($year && $oldyear > (int) $year + 1) {
294 // If we have empty year
295 $oldyear--;
296
297 print '<tr class="oddeven" height="24">';
298 print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$oldyear.'">'.$oldyear.'</a></td>';
299 print '<td class="right">0</td>';
300 print '<td class="right"><span class="amount">0</span></td>';
301 print '<td class="right"><span class="amount">0</span></td>';
302 print '</tr>';
303 }
304
305 print '<tr class="oddeven" height="24">';
306 print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'">'.$year.'</a></td>';
307 print '<td class="right">'.$val['nb'].'</td>';
308 print '<td class="right"><span class="amount">'.price(price2num($val['total'], 'MT'), 1).'</span></td>';
309 print '<td class="right"><span class="amount">'.price(price2num($val['avg'], 'MT'), 1).'</span></td>';
310 print '</tr>';
311 $oldyear = $year;
312}
313
314print '</table>';
315print '</div>';
316
317
318print '</div><div class="fichetwothirdright">';
319
320
321// Show graphs
322print '<table class="border centpercent"><tr class="pair nohover"><td align="center">';
323if ($mesg) {
324 print $mesg;
325} else {
326 print $px1->show();
327 print "<br>\n";
328 print $px2->show();
329 print "<br>\n";
330 print $px3->show();
331}
332print '</td></tr></table>';
333
334
335print '</div></div>';
336print '<div class="clearboth"></div>';
337
338
339print dol_get_fiche_end();
340
341// End of page
342llxFooter();
343$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
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.
Class to manage salary payments.
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.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
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)
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 '.
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dolGetButtonTitleSeparator($moreClass="")
Add space between dolGetButtonTitle.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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).
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.