dolibarr  13.0.2
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  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <https://www.gnu.org/licenses/>.
17  */
18 
25 require '../../main.inc.php';
26 require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
27 require_once DOL_DOCUMENT_ROOT.'/salaries/class/salariesstats.class.php';
28 
29 // Load translation files required by the page
30 $langs->loadLangs(array("salaries", "companies"));
31 
33 $HEIGHT = DolGraph::getDefaultGraphSizeForStats('height');
34 
35 $userid = GETPOST('userid', 'int'); if ($userid < 0) $userid = 0;
36 $socid = GETPOST('socid', 'int'); if ($socid < 0) $socid = 0;
37 $id = GETPOST('id', 'int');
38 
39 // Security check
40 $socid = GETPOST("socid", "int");
41 if ($user->socid) $socid = $user->socid;
42 $result = restrictedArea($user, 'salaries', '', '', '');
43 
44 $nowyear = strftime("%Y", dol_now());
45 $year = GETPOST('year') > 0 ?GETPOST('year') : $nowyear;
46 //$startyear=$year-2;
47 $startyear = $year - 1;
48 $endyear = $year;
49 
50 
51 /*
52  * View
53  */
54 
55 $form = new Form($db);
56 
57 
58 llxHeader();
59 
60 $title = $langs->trans("SalariesStatistics");
61 $dir = $conf->salaries->dir_temp;
62 
63 print load_fiche_titre($title, '', 'object_payment');
64 
65 dol_mkdir($dir);
66 
67 $useridtofilter = $userid; // Filter from parameters
68 
69 $stats = new SalariesStats($db, $socid, $useridtofilter);
70 
71 
72 // Build graphic number of object
73 // $data = array(array('Lib',val1,val2,val3),...)
74 //print "$endyear, $startyear";
75 $data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
76 //var_dump($data);
77 
78 $filenamenb = $dir."/salariesnbinyear-".$year.".png";
79 $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=salariesstats&amp;file=salariesnbinyear-'.$year.'.png';
80 
81 $px1 = new DolGraph();
82 $mesg = $px1->isGraphKo();
83 if (!$mesg)
84 {
85  $px1->SetData($data);
86  $i = $startyear; $legend = array();
87  while ($i <= $endyear)
88  {
89  $legend[] = $i;
90  $i++;
91  }
92  $px1->SetLegend($legend);
93  $px1->SetMaxValue($px1->GetCeilMaxValue());
94  $px1->SetWidth($WIDTH);
95  $px1->SetHeight($HEIGHT);
96  $px1->SetYLabel($langs->trans("Number"));
97  $px1->SetShading(3);
98  $px1->SetHorizTickIncrement(1);
99  $px1->mode = 'depth';
100  $px1->SetTitle($langs->trans("NumberByMonth"));
101 
102  $px1->draw($filenamenb, $fileurlnb);
103 }
104 
105 // Build graphic amount of object
106 $data = $stats->getAmountByMonthWithPrevYear($endyear, $startyear);
107 //var_dump($data);
108 // $data = array(array('Lib',val1,val2,val3),...)
109 
110 $filenameamount = $dir."/salariesamountinyear-".$year.".png";
111 $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=salariesstats&amp;file=salariesamountinyear-'.$year.'.png';
112 
113 $px2 = new DolGraph();
114 $mesg = $px2->isGraphKo();
115 if (!$mesg)
116 {
117  $px2->SetData($data);
118  $i = $startyear; $legend = array();
119  while ($i <= $endyear)
120  {
121  $legend[] = $i;
122  $i++;
123  }
124  $px2->SetLegend($legend);
125  $px2->SetMaxValue($px2->GetCeilMaxValue());
126  $px2->SetMinValue(min(0, $px2->GetFloorMinValue()));
127  $px2->SetWidth($WIDTH);
128  $px2->SetHeight($HEIGHT);
129  $px2->SetYLabel($langs->trans("Amount"));
130  $px2->SetShading(3);
131  $px2->SetHorizTickIncrement(1);
132  $px2->mode = 'depth';
133  $px2->SetTitle($langs->trans("AmountTotal"));
134 
135  $px2->draw($filenameamount, $fileurlamount);
136 }
137 
138 
139 $data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
140 
141 $filename_avg = $dir."/salariesaverageinyear-".$year.".png";
142 $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=salariesstats&file=salariesaverageinyear-'.$year.'.png';
143 
144 $px3 = new DolGraph();
145 $mesg = $px3->isGraphKo();
146 if (!$mesg)
147 {
148  $px3->SetData($data);
149  $i = $startyear; $legend = array();
150  while ($i <= $endyear)
151  {
152  $legend[] = $i;
153  $i++;
154  }
155  $px3->SetLegend($legend);
156  $px3->SetYLabel($langs->trans("AmountAverage"));
157  $px3->SetMaxValue($px3->GetCeilMaxValue());
158  $px3->SetMinValue($px3->GetFloorMinValue());
159  $px3->SetWidth($WIDTH);
160  $px3->SetHeight($HEIGHT);
161  $px3->SetShading(3);
162  $px3->SetHorizTickIncrement(1);
163  $px3->mode = 'depth';
164  $px3->SetTitle($langs->trans("AmountAverage"));
165 
166  $px3->draw($filename_avg, $fileurl_avg);
167 }
168 
169 
170 // Show array
171 $data = $stats->getAllByYear();
172 $arrayyears = array();
173 foreach ($data as $val) {
174  $arrayyears[$val['year']] = $val['year'];
175 }
176 if (!count($arrayyears)) $arrayyears[$nowyear] = $nowyear;
177 
178 
179 $h = 0;
180 $head = array();
181 $head[$h][0] = DOL_URL_ROOT.'/salaries/stats/index.php';
182 $head[$h][1] = $langs->trans("ByMonthYear");
183 $head[$h][2] = 'byyear';
184 $h++;
185 
186 complete_head_from_modules($conf, $langs, null, $head, $h, 'salaries_stats');
187 
188 print dol_get_fiche_head($head, 'byyear', $langs->trans("Statistics"), -1);
189 
190 
191 print '<div class="fichecenter"><div class="fichethirdleft">';
192 
193 
194 // Show filter box
195 print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
196 print '<input type="hidden" name="token" value="'.newToken().'">';
197 
198 print '<table class="noborder centpercent">';
199 print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
200 // User
201 print '<tr><td>'.$langs->trans("User").'</td><td>';
202 print $form->select_dolusers($userid, 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth300');
203 print '</td></tr>';
204 // Year
205 print '<tr><td>'.$langs->trans("Year").'</td><td>';
206 if (!in_array($year, $arrayyears)) $arrayyears[$year] = $year;
207 arsort($arrayyears);
208 print $form->selectarray('year', $arrayyears, $year, 0);
209 print '</td></tr>';
210 print '<tr><td align="center" colspan="2"><input type="submit" name="submit" class="button" value="'.$langs->trans("Refresh").'"></td></tr>';
211 print '</table>';
212 print '</form>';
213 print '<br><br>';
214 
215 print '<div class="div-table-responsive-no-min">';
216 print '<table class="noborder centpercent">';
217 print '<tr class="liste_titre" height="24">';
218 print '<td class="center">'.$langs->trans("Year").'</td>';
219 print '<td class="right">'.$langs->trans("Number").'</td>';
220 print '<td class="right">'.$langs->trans("AmountTotal").'</td>';
221 print '<td class="right">'.$langs->trans("AmountAverage").'</td>';
222 print '</tr>';
223 
224 $oldyear = 0;
225 foreach ($data as $val)
226 {
227  $year = $val['year'];
228  while ($year && $oldyear > $year + 1)
229  {
230  // If we have empty year
231  $oldyear--;
232 
233  print '<tr class="oddeven" height="24">';
234  print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$oldyear.'">'.$oldyear.'</a></td>';
235  print '<td class="right">0</td>';
236  print '<td class="right">0</td>';
237  print '<td class="right">0</td>';
238  print '</tr>';
239  }
240 
241  print '<tr class="oddeven" height="24">';
242  print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'">'.$year.'</a></td>';
243  print '<td class="right">'.$val['nb'].'</td>';
244  print '<td class="right">'.price(price2num($val['total'], 'MT'), 1).'</td>';
245  print '<td class="right">'.price(price2num($val['avg'], 'MT'), 1).'</td>';
246  print '</tr>';
247  $oldyear = $year;
248 }
249 
250 print '</table>';
251 print '</div>';
252 
253 
254 print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
255 
256 
257 // Show graphs
258 print '<table class="border centpercent"><tr class="pair nohover"><td align="center">';
259 if ($mesg) { print $mesg; } else {
260  print $px1->show();
261  print "<br>\n";
262  print $px2->show();
263  print "<br>\n";
264  print $px3->show();
265 }
266 print '</td></tr></table>';
267 
268 
269 print '</div></div></div>';
270 print '<div style="clear:both"></div>';
271 
272 
273 print dol_get_fiche_end();
274 
275 // End of page
276 llxFooter();
277 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_now($mode= 'auto')
Return date for now.
Classe permettant la gestion des stats des salaires.
llxHeader()
Empty header.
Definition: wrapper.php:45
Class to manage generation of HTML components Only common components must be here.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is &#39;...
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
Definition: index.php:89
Class to build graphs.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
static getDefaultGraphSizeForStats($direction, $defaultsize= '')
getDefaultGraphSizeForStats
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode= 'add')
Complete or removed entries into a head array (used to build tabs).
llxFooter()
Empty footer.
Definition: wrapper.php:59
dol_mkdir($dir, $dataroot= '', $newmask=null)
Creation of a directory (this can create recursive subdir)