dolibarr  9.0.0
index.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2013 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2015 Alexandre Spangaro <aspangaro.dolibarr@gmail.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 <http://www.gnu.org/licenses/>.
19  */
20 
27 require '../../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/don/class/donstats.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
31 
34 
35 $userid=GETPOST('userid','int');
36 $socid=GETPOST('socid','int');
37 // Security check
38 if ($user->societe_id > 0)
39 {
40  $action = '';
41  $socid = $user->societe_id;
42 }
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 // Load translation files required by the page
51 $langs->loadLangs(array("companies","other","sendings"));
52 
53 
54 /*
55  * View
56  */
57 
58 $form=new Form($db);
59 
60 llxHeader();
61 
62 print load_fiche_titre($langs->trans("StatisticsOfSendings"), $mesg);
63 
64 
65 dol_mkdir($dir);
66 
67 $stats = new DonationStats($db, $socid, $mode, ($userid>0?$userid:0));
68 
69 // Build graphic number of object
70 $data = $stats->getNbByMonthWithPrevYear($endyear,$startyear);
71 //var_dump($data);exit;
72 // $data = array(array('Lib',val1,val2,val3),...)
73 
74 
75 if (!$user->rights->societe->client->voir || $user->societe_id)
76 {
77  $filenamenb = $dir.'/shipmentsnbinyear-'.$user->id.'-'.$year.'.png';
78  if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=shipmentstats&file=shipmentsnbinyear-'.$user->id.'-'.$year.'.png';
79  if ($mode == 'supplier') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=shipmentstatssupplier&file=shipmentsnbinyear-'.$user->id.'-'.$year.'.png';
80 }
81 else
82 {
83  $filenamenb = $dir.'/shipmentsnbinyear-'.$year.'.png';
84  if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=shipmentstats&file=shipmentsnbinyear-'.$year.'.png';
85  if ($mode == 'supplier') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=shipmentstatssupplier&file=shipmentsnbinyear-'.$year.'.png';
86 }
87 
88 $px1 = new DolGraph();
89 $mesg = $px1->isGraphKo();
90 if (! $mesg)
91 {
92  $px1->SetData($data);
93  $px1->SetPrecisionY(0);
94  $i=$startyear;$legend=array();
95  while ($i <= $endyear)
96  {
97  $legend[]=$i;
98  $i++;
99  }
100  $px1->SetLegend($legend);
101  $px1->SetMaxValue($px1->GetCeilMaxValue());
102  $px1->SetMinValue(min(0,$px1->GetFloorMinValue()));
103  $px1->SetWidth($WIDTH);
104  $px1->SetHeight($HEIGHT);
105  $px1->SetYLabel($langs->trans("NbOfSendings"));
106  $px1->SetShading(3);
107  $px1->SetHorizTickIncrement(1);
108  $px1->SetPrecisionY(0);
109  $px1->mode='depth';
110  $px1->SetTitle($langs->trans("NumberOfShipmentsByMonth"));
111 
112  $px1->draw($filenamenb,$fileurlnb);
113 }
114 
115 // Build graphic amount of object
116 /*
117 $data = $stats->getAmountByMonthWithPrevYear($endyear,$startyear);
118 //var_dump($data);
119 // $data = array(array('Lib',val1,val2,val3),...)
120 
121 if (!$user->rights->societe->client->voir || $user->societe_id)
122 {
123  $filenameamount = $dir.'/shipmentsamountinyear-'.$user->id.'-'.$year.'.png';
124  if ($mode == 'customer') $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=shipmentstats&file=shipmentsamountinyear-'.$user->id.'-'.$year.'.png';
125  if ($mode == 'supplier') $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=shipmentstatssupplier&file=shipmentsamountinyear-'.$user->id.'-'.$year.'.png';
126 }
127 else
128 {
129  $filenameamount = $dir.'/shipmentsamountinyear-'.$year.'.png';
130  if ($mode == 'customer') $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=shipmentstats&file=shipmentsamountinyear-'.$year.'.png';
131  if ($mode == 'supplier') $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=shipmentstatssupplier&file=shipmentsamountinyear-'.$year.'.png';
132 }
133 
134 $px2 = new DolGraph();
135 $mesg = $px2->isGraphKo();
136 if (! $mesg)
137 {
138  $px2->SetData($data);
139  $i=$startyear;$legend=array();
140  while ($i <= $endyear)
141  {
142  $legend[]=$i;
143  $i++;
144  }
145  $px2->SetLegend($legend);
146  $px2->SetMaxValue($px2->GetCeilMaxValue());
147  $px2->SetMinValue(min(0,$px2->GetFloorMinValue()));
148  $px2->SetWidth($WIDTH);
149  $px2->SetHeight($HEIGHT);
150  $px2->SetYLabel($langs->trans("AmountOfShipments"));
151  $px2->SetShading(3);
152  $px2->SetHorizTickIncrement(1);
153  $px2->SetPrecisionY(0);
154  $px2->mode='depth';
155  $px2->SetTitle($langs->trans("AmountOfShipmentsByMonthHT"));
156 
157  $px2->draw($filenameamount,$fileurlamount);
158 }
159 */
160 
161 /*
162 $data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
163 
164 if (!$user->rights->societe->client->voir || $user->societe_id)
165 {
166  $filename_avg = $dir.'/shipmentsaverage-'.$user->id.'-'.$year.'.png';
167  if ($mode == 'customer') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=shipmentstats&file=shipmentsaverage-'.$user->id.'-'.$year.'.png';
168  if ($mode == 'supplier') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=shipmentstatssupplier&file=shipmentsaverage-'.$user->id.'-'.$year.'.png';
169 }
170 else
171 {
172  $filename_avg = $dir.'/shipmentsaverage-'.$year.'.png';
173  if ($mode == 'customer') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=shipmentstats&file=shipmentsaverage-'.$year.'.png';
174  if ($mode == 'supplier') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=shipmentstatssupplier&file=shipmentsaverage-'.$year.'.png';
175 }
176 
177 $px3 = new DolGraph();
178 $mesg = $px3->isGraphKo();
179 if (! $mesg)
180 {
181  $px3->SetData($data);
182  $i=$startyear;$legend=array();
183  while ($i <= $endyear)
184  {
185  $legend[]=$i;
186  $i++;
187  }
188  $px3->SetLegend($legend);
189  $px3->SetYLabel($langs->trans("AmountAverage"));
190  $px3->SetMaxValue($px3->GetCeilMaxValue());
191  $px3->SetMinValue($px3->GetFloorMinValue());
192  $px3->SetWidth($WIDTH);
193  $px3->SetHeight($HEIGHT);
194  $px3->SetShading(3);
195  $px3->SetHorizTickIncrement(1);
196  $px3->SetPrecisionY(0);
197  $px3->mode='depth';
198  $px3->SetTitle($langs->trans("AmountAverage"));
199 
200  $px3->draw($filename_avg,$fileurl_avg);
201 }
202 */
203 
204 
205 // Show array
206 $data = $stats->getAllByYear();
207 $arrayyears=array();
208 foreach($data as $val) {
209  if (! empty($val['year'])) {
210  $arrayyears[$val['year']]=$val['year'];
211  }
212 }
213 if (! count($arrayyears)) $arrayyears[$nowyear]=$nowyear;
214 
215 $h=0;
216 $head = array();
217 $head[$h][0] = DOL_URL_ROOT . '/don/stats/index.php?mode='.$mode;
218 $head[$h][1] = $langs->trans("ByMonthYear");
219 $head[$h][2] = 'byyear';
220 $h++;
221 
222 $type='donation_stats';
223 
224 complete_head_from_modules($conf,$langs,null,$head,$h,$type);
225 
226 dol_fiche_head($head, 'byyear', $langs->trans("Statistics"), -1);
227 
228 
229 print '<div class="fichecenter"><div class="fichethirdleft">';
230 
231 
232 //if (empty($socid))
233 //{
234  // Show filter box
235  print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
236  print '<input type="hidden" name="mode" value="'.$mode.'">';
237  print '<table class="border" width="100%">';
238  print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
239  // Company
240  print '<tr><td align="left">'.$langs->trans("ThirdParty").'</td><td align="left">';
241  if ($mode == 'customer') $filter='s.client in (1,2,3)';
242  if ($mode == 'supplier') $filter='s.fournisseur = 1';
243  print $form->select_company($socid,'socid',$filter,1,0,0,array(),0,'','style="width: 95%"');
244  print '</td></tr>';
245  // User
246  print '<tr><td align="left">'.$langs->trans("CreatedBy").'</td><td align="left">';
247  print $form->select_dolusers($userid, 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth300');
248  print '</td></tr>';
249  // Year
250  print '<tr><td align="left">'.$langs->trans("Year").'</td><td align="left">';
251  if (! in_array($year,$arrayyears)) $arrayyears[$year]=$year;
252  if (! in_array($nowyear,$arrayyears)) $arrayyears[$nowyear]=$nowyear;
253  arsort($arrayyears);
254  print $form->selectarray('year',$arrayyears,$year,0);
255  print '</td></tr>';
256  print '<tr><td align="center" colspan="2"><input type="submit" name="submit" class="button" value="'.$langs->trans("Refresh").'"></td></tr>';
257  print '</table>';
258  print '</form>';
259  print '<br><br>';
260 //}
261 
262 print '<div class="div-table-responsive-no-min">';
263 print '<table class="border" width="100%">';
264 print '<tr height="24">';
265 print '<td align="center">'.$langs->trans("Year").'</td>';
266 print '<td align="center">'.$langs->trans("NbOfSendings").'</td>';
267 /*print '<td align="center">'.$langs->trans("AmountTotal").'</td>';
268 print '<td align="center">'.$langs->trans("AmountAverage").'</td>';*/
269 print '</tr>';
270 
271 $oldyear=0;
272 foreach ($data as $val)
273 {
274  $year = $val['year'];
275  while (! empty($year) && $oldyear > $year+1)
276  { // If we have empty year
277  $oldyear--;
278  print '<tr height="24">';
279  print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$oldyear.'&amp;mode='.$mode.'">'.$oldyear.'</a></td>';
280 
281  print '<td align="right">0</td>';
282  /*print '<td align="right">0</td>';
283  print '<td align="right">0</td>';*/
284  print '</tr>';
285  }
286 
287  print '<tr height="24">';
288  print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'&amp;mode='.$mode.'">'.$year.'</a></td>';
289  print '<td align="right">'.$val['nb'].'</td>';
290  /*print '<td align="right">'.price(price2num($val['total'],'MT'),1).'</td>';
291  print '<td align="right">'.price(price2num($val['avg'],'MT'),1).'</td>';*/
292  print '</tr>';
293  $oldyear=$year;
294 }
295 
296 print '</table>';
297 print '</div>';
298 
299 
300 print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
301 
302 
303 // Show graphs
304 print '<table class="border" width="100%"><tr class="pair nohover"><td align="center">';
305 if ($mesg) { print $mesg; }
306 else {
307  print $px1->show();
308  print "<br>\n";
309  /*print $px2->show();
310  print "<br>\n";
311  print $px3->show();*/
312 }
313 print '</td></tr></table>';
314 
315 
316 print '</div></div></div>';
317 print '<div style="clear:both"></div>';
318 
319 dol_fiche_end();
320 
321 
322 
323 // TODO USe code similar to commande/stats/index.php instead of this one.
324 /*
325 print '<table class="border" width="100%">';
326 print '<tr><td align="center">'.$langs->trans("Year").'</td>';
327 print '<td width="40%" align="center">'.$langs->trans("NbOfSendings").'</td></tr>';
328 
329 $sql = "SELECT count(*) as nb, date_format(date_expedition,'%Y') as dm";
330 $sql.= " FROM ".MAIN_DB_PREFIX."expedition";
331 $sql.= " WHERE fk_statut > 0";
332 $sql.= " AND entity = ".$conf->entity;
333 $sql.= " GROUP BY dm DESC";
334 
335 $resql=$db->query($sql);
336 if ($resql)
337 {
338  $num = $db->num_rows($resql);
339  $i = 0;
340  while ($i < $num)
341  {
342  $row = $db->fetch_row($resql);
343  $nbproduct = $row[0];
344  $year = $row[1];
345  print "<tr>";
346  print '<td align="center"><a href="month.php?year='.$year.'">'.$year.'</a></td><td align="center">'.$nbproduct.'</td></tr>';
347  $i++;
348  }
349 }
350 $db->free($resql);
351 
352 print '</table>';
353 */
354 
355 print '<br>';
356 print '<i>'.$langs->trans("StatsOnShipmentsOnlyValidated").'</i>';
357 
358 llxFooter();
359 
360 $db->close();
llxFooter()
Footer empty.
Definition: index.php:44
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add')
Complete or removed entries into a head array (used to build tabs).
Class to manage generation of HTML components Only common components must be here.
llxHeader()
Header empty.
Definition: index.php:36
static getDefaultGraphSizeForStats($direction, $defaultsize='')
getDefaultGraphSizeForStats
dol_fiche_end($notab=0)
Show tab footer of a card.
dol_now($mode='gmt')
Return date for now.
Class to build graphs.
dol_mkdir($dir, $dataroot='', $newmask=null)
Creation of a directory (this can create recursive subdir)
Class to manage donations statistics.
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='')
Show tab header of a card.