dolibarr  18.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
27 require '../../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
29 require_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 
35 $HEIGHT = DolGraph::getDefaultGraphSizeForStats('height');
36 
37 $userid = GETPOST('userid', 'int');
38 if ($userid < 0) {
39  $userid = 0;
40 }
41 $socid = GETPOST('socid', 'int');
42 if ($socid < 0) {
43  $socid = 0;
44 }
45 $id = GETPOST('id', 'int');
46 
47 // Security check
48 $socid = GETPOST("socid", "int");
49 if ($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 - (empty($conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS) ? 2 : max(1, min(10, $conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS)));
57 $endyear = $year;
58 
59 
60 /*
61  * View
62  */
63 
64 $form = new Form($db);
65 
66 
67 llxHeader();
68 
69 $title = $langs->trans("SalariesStatistics");
70 $dir = $conf->salaries->dir_temp;
71 
72 print load_fiche_titre($title, '', 'salary');
73 
74 dol_mkdir($dir);
75 
76 $useridtofilter = $userid; // Filter from parameters
77 
78 if (empty($user->rights->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();
96 if (!$mesg) {
97  $px1->SetData($data);
98  $i = $startyear; $legend = array();
99  while ($i <= $endyear) {
100  $legend[] = $i;
101  $i++;
102  }
103  $px1->SetLegend($legend);
104  $px1->SetMaxValue($px1->GetCeilMaxValue());
105  $px1->SetWidth($WIDTH);
106  $px1->SetHeight($HEIGHT);
107  $px1->SetYLabel($langs->trans("Number"));
108  $px1->SetShading(3);
109  $px1->SetHorizTickIncrement(1);
110  $px1->mode = 'depth';
111  $px1->SetTitle($langs->trans("NumberByMonth"));
112 
113  $px1->draw($filenamenb, $fileurlnb);
114 }
115 
116 // Build graphic amount of object
117 $data = $stats->getAmountByMonthWithPrevYear($endyear, $startyear);
118 //var_dump($data);
119 // $data = array(array('Lib',val1,val2,val3),...)
120 
121 $filenameamount = $dir."/salariesamountinyear-".$year.".png";
122 $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=salariesstats&amp;file=salariesamountinyear-'.$year.'.png';
123 
124 $px2 = new DolGraph();
125 $mesg = $px2->isGraphKo();
126 if (!$mesg) {
127  $px2->SetData($data);
128  $i = $startyear; $legend = array();
129  while ($i <= $endyear) {
130  $legend[] = $i;
131  $i++;
132  }
133  $px2->SetLegend($legend);
134  $px2->SetMaxValue($px2->GetCeilMaxValue());
135  $px2->SetMinValue(min(0, $px2->GetFloorMinValue()));
136  $px2->SetWidth($WIDTH);
137  $px2->SetHeight($HEIGHT);
138  $px2->SetYLabel($langs->trans("Amount"));
139  $px2->SetShading(3);
140  $px2->SetHorizTickIncrement(1);
141  $px2->mode = 'depth';
142  $px2->SetTitle($langs->trans("AmountTotal"));
143 
144  $px2->draw($filenameamount, $fileurlamount);
145 }
146 
147 
148 $data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
149 
150 $filename_avg = $dir."/salariesaverageinyear-".$year.".png";
151 $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=salariesstats&file=salariesaverageinyear-'.$year.'.png';
152 
153 $px3 = new DolGraph();
154 $mesg = $px3->isGraphKo();
155 if (!$mesg) {
156  $px3->SetData($data);
157  $i = $startyear; $legend = array();
158  while ($i <= $endyear) {
159  $legend[] = $i;
160  $i++;
161  }
162  $px3->SetLegend($legend);
163  $px3->SetYLabel($langs->trans("AmountAverage"));
164  $px3->SetMaxValue($px3->GetCeilMaxValue());
165  $px3->SetMinValue($px3->GetFloorMinValue());
166  $px3->SetWidth($WIDTH);
167  $px3->SetHeight($HEIGHT);
168  $px3->SetShading(3);
169  $px3->SetHorizTickIncrement(1);
170  $px3->mode = 'depth';
171  $px3->SetTitle($langs->trans("AmountAverage"));
172 
173  $px3->draw($filename_avg, $fileurl_avg);
174 }
175 
176 
177 // Show array
178 $data = $stats->getAllByYear();
179 $arrayyears = array();
180 foreach ($data as $val) {
181  $arrayyears[$val['year']] = $val['year'];
182 }
183 if (!count($arrayyears)) {
184  $arrayyears[$nowyear] = $nowyear;
185 }
186 
187 
188 $h = 0;
189 $head = array();
190 $head[$h][0] = DOL_URL_ROOT.'/salaries/stats/index.php';
191 $head[$h][1] = $langs->trans("ByMonthYear");
192 $head[$h][2] = 'byyear';
193 $h++;
194 
195 complete_head_from_modules($conf, $langs, null, $head, $h, 'salaries_stats');
196 
197 print dol_get_fiche_head($head, 'byyear', $langs->trans("Statistics"), -1);
198 
199 
200 print '<div class="fichecenter"><div class="fichethirdleft">';
201 
202 
203 // Show filter box
204 print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
205 print '<input type="hidden" name="token" value="'.newToken().'">';
206 
207 print '<table class="noborder centpercent">';
208 print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
209 // User
210 print '<tr><td>'.$langs->trans("Employee").'</td><td>';
211 print img_picto('', 'user', 'class="pictofixedwidth"');
212 print $form->select_dolusers(($userid ? $userid : -1), 'userid', 1, '', 0, empty($user->rights->salaries->readall) ? 'hierarchyme' : '', '', 0, 0, 0, '', 0, '', 'widthcentpercentminusx maxwidth300');
213 print '</td></tr>';
214 // Year
215 print '<tr><td>'.$langs->trans("Year").'</td><td>';
216 if (!in_array($year, $arrayyears)) {
217  $arrayyears[$year] = $year;
218 }
219 arsort($arrayyears);
220 print $form->selectarray('year', $arrayyears, $year, 0, 0, 0, '', 0, 0, 0, '', 'width75');
221 print '</td></tr>';
222 print '<tr><td align="center" colspan="2"><input type="submit" name="submit" class="button small" value="'.$langs->trans("Refresh").'"></td></tr>';
223 print '</table>';
224 print '</form>';
225 print '<br><br>';
226 
227 print '<div class="div-table-responsive-no-min">';
228 print '<table class="noborder centpercent">';
229 print '<tr class="liste_titre" height="24">';
230 print '<td class="center">'.$langs->trans("Year").'</td>';
231 print '<td class="right">'.$langs->trans("Number").'</td>';
232 print '<td class="right">'.$langs->trans("AmountTotal").'</td>';
233 print '<td class="right">'.$langs->trans("AmountAverage").'</td>';
234 print '</tr>';
235 
236 $oldyear = 0;
237 foreach ($data as $val) {
238  $year = $val['year'];
239  while ($year && $oldyear > $year + 1) {
240  // If we have empty year
241  $oldyear--;
242 
243  print '<tr class="oddeven" height="24">';
244  print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$oldyear.'">'.$oldyear.'</a></td>';
245  print '<td class="right">0</td>';
246  print '<td class="right"><span class="amount">0</span></td>';
247  print '<td class="right"><span class="amount">0</span></td>';
248  print '</tr>';
249  }
250 
251  print '<tr class="oddeven" height="24">';
252  print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'">'.$year.'</a></td>';
253  print '<td class="right">'.$val['nb'].'</td>';
254  print '<td class="right"><span class="amount">'.price(price2num($val['total'], 'MT'), 1).'</span></td>';
255  print '<td class="right"><span class="amount">'.price(price2num($val['avg'], 'MT'), 1).'</span></td>';
256  print '</tr>';
257  $oldyear = $year;
258 }
259 
260 print '</table>';
261 print '</div>';
262 
263 
264 print '</div><div class="fichetwothirdright">';
265 
266 
267 // Show graphs
268 print '<table class="border centpercent"><tr class="pair nohover"><td align="center">';
269 if ($mesg) {
270  print $mesg;
271 } else {
272  print $px1->show();
273  print "<br>\n";
274  print $px2->show();
275  print "<br>\n";
276  print $px3->show();
277 }
278 print '</td></tr></table>';
279 
280 
281 print '</div></div>';
282 print '<div class="clearboth"></div>';
283 
284 
285 print dol_get_fiche_end();
286 
287 // End of page
288 llxFooter();
289 $db->close();
Class to build graphs.
static getDefaultGraphSizeForStats($direction, $defaultsize='')
getDefaultGraphSizeForStats
Class to manage generation of HTML components Only common components must be here.
Classe permettant la gestion des stats des salaires.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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).
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
llxFooter()
Footer empty.
Definition: index.php:71
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
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.