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