dolibarr  13.0.2
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@open-dsi.fr>
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 <https://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 
33 $HEIGHT = DolGraph::getDefaultGraphSizeForStats('height');
34 
35 $userid = GETPOST('userid', 'int');
36 $socid = GETPOST('socid', 'int');
37 // Security check
38 if ($user->socid > 0)
39 {
40  $action = '';
41  $socid = $user->socid;
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, '', ($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->socid)
76 {
77  $filenamenb = $dir.'/shipmentsnbinyear-'.$user->id.'-'.$year.'.png';
78 } else {
79  $filenamenb = $dir.'/shipmentsnbinyear-'.$year.'.png';
80 }
81 
82 $px1 = new DolGraph();
83 $mesg = $px1->isGraphKo();
84 if (!$mesg)
85 {
86  $px1->SetData($data);
87  $i = $startyear; $legend = array();
88  while ($i <= $endyear)
89  {
90  $legend[] = $i;
91  $i++;
92  }
93  $px1->SetLegend($legend);
94  $px1->SetMaxValue($px1->GetCeilMaxValue());
95  $px1->SetMinValue(min(0, $px1->GetFloorMinValue()));
96  $px1->SetWidth($WIDTH);
97  $px1->SetHeight($HEIGHT);
98  $px1->SetYLabel($langs->trans("NbOfSendings"));
99  $px1->SetShading(3);
100  $px1->SetHorizTickIncrement(1);
101  $px1->mode = 'depth';
102  $px1->SetTitle($langs->trans("NumberOfShipmentsByMonth"));
103 
104  $px1->draw($filenamenb, $fileurlnb);
105 }
106 
107 // Build graphic amount of object
108 /*
109 $data = $stats->getAmountByMonthWithPrevYear($endyear,$startyear);
110 //var_dump($data);
111 // $data = array(array('Lib',val1,val2,val3),...)
112 
113 if (!$user->rights->societe->client->voir || $user->socid)
114 {
115  $filenameamount = $dir.'/shipmentsamountinyear-'.$user->id.'-'.$year.'.png';
116 }
117 else
118 {
119  $filenameamount = $dir.'/shipmentsamountinyear-'.$year.'.png';
120 }
121 
122 $px2 = new DolGraph();
123 $mesg = $px2->isGraphKo();
124 if (! $mesg)
125 {
126  $px2->SetData($data);
127  $i=$startyear;$legend=array();
128  while ($i <= $endyear)
129  {
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("AmountOfShipments"));
139  $px2->SetShading(3);
140  $px2->SetHorizTickIncrement(1);
141  $px2->mode='depth';
142  $px2->SetTitle($langs->trans("AmountOfShipmentsByMonthHT"));
143 
144  $px2->draw($filenameamount,$fileurlamount);
145 }
146 */
147 
148 /*
149 $data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
150 
151 if (!$user->rights->societe->client->voir || $user->socid)
152 {
153  $filename_avg = $dir.'/shipmentsaverage-'.$user->id.'-'.$year.'.png';
154 }
155 else
156 {
157  $filename_avg = $dir.'/shipmentsaverage-'.$year.'.png';
158 }
159 
160 $px3 = new DolGraph();
161 $mesg = $px3->isGraphKo();
162 if (! $mesg)
163 {
164  $px3->SetData($data);
165  $i=$startyear;$legend=array();
166  while ($i <= $endyear)
167  {
168  $legend[]=$i;
169  $i++;
170  }
171  $px3->SetLegend($legend);
172  $px3->SetYLabel($langs->trans("AmountAverage"));
173  $px3->SetMaxValue($px3->GetCeilMaxValue());
174  $px3->SetMinValue($px3->GetFloorMinValue());
175  $px3->SetWidth($WIDTH);
176  $px3->SetHeight($HEIGHT);
177  $px3->SetShading(3);
178  $px3->SetHorizTickIncrement(1);
179  $px3->mode='depth';
180  $px3->SetTitle($langs->trans("AmountAverage"));
181 
182  $px3->draw($filename_avg,$fileurl_avg);
183 }
184 */
185 
186 
187 // Show array
188 $data = $stats->getAllByYear();
189 $arrayyears = array();
190 foreach ($data as $val) {
191  if (!empty($val['year'])) {
192  $arrayyears[$val['year']] = $val['year'];
193  }
194 }
195 if (!count($arrayyears)) $arrayyears[$nowyear] = $nowyear;
196 
197 $h = 0;
198 $head = array();
199 $head[$h][0] = DOL_URL_ROOT.'/don/stats/index.php';
200 $head[$h][1] = $langs->trans("ByMonthYear");
201 $head[$h][2] = 'byyear';
202 $h++;
203 
204 $type = 'donation_stats';
205 
206 complete_head_from_modules($conf, $langs, null, $head, $h, $type);
207 
208 print dol_get_fiche_head($head, 'byyear', $langs->trans("Statistics"), -1);
209 
210 
211 print '<div class="fichecenter"><div class="fichethirdleft">';
212 
213 
214 //if (empty($socid))
215 //{
216  // Show filter box
217  print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
218  print '<input type="hidden" name="token" value="'.newToken().'">';
219 
220  print '<table class="border centpercent">';
221  print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
222  // Company
223  print '<tr><td class="left">'.$langs->trans("ThirdParty").'</td><td class="left">';
224  print $form->select_company($socid, 'socid', '', 1, 0, 0, array(), 0, '', 'style="width: 95%"');
225  print '</td></tr>';
226  // User
227  print '<tr><td class="left">'.$langs->trans("CreatedBy").'</td><td class="left">';
228  print $form->select_dolusers($userid, 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth300');
229  print '</td></tr>';
230  // Year
231  print '<tr><td class="left">'.$langs->trans("Year").'</td><td class="left">';
232  if (!in_array($year, $arrayyears)) $arrayyears[$year] = $year;
233  if (!in_array($nowyear, $arrayyears)) $arrayyears[$nowyear] = $nowyear;
234  arsort($arrayyears);
235  print $form->selectarray('year', $arrayyears, $year, 0);
236  print '</td></tr>';
237  print '<tr><td class="center" colspan="2"><input type="submit" name="submit" class="button" value="'.$langs->trans("Refresh").'"></td></tr>';
238  print '</table>';
239  print '</form>';
240  print '<br><br>';
241 //}
242 
243 print '<div class="div-table-responsive-no-min">';
244 print '<table class="border centpercent">';
245 print '<tr height="24">';
246 print '<td class="center">'.$langs->trans("Year").'</td>';
247 print '<td class="center">'.$langs->trans("NbOfSendings").'</td>';
248 /*print '<td class="center">'.$langs->trans("AmountTotal").'</td>';
249 print '<td class="center">'.$langs->trans("AmountAverage").'</td>';*/
250 print '</tr>';
251 
252 $oldyear = 0;
253 foreach ($data as $val)
254 {
255  $year = $val['year'];
256  while (!empty($year) && $oldyear > $year + 1)
257  { // If we have empty year
258  $oldyear--;
259  print '<tr height="24">';
260  print '<td class="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$oldyear.'">'.$oldyear.'</a></td>';
261 
262  print '<td class="right">0</td>';
263  /*print '<td class="right">0</td>';
264  print '<td class="right">0</td>';*/
265  print '</tr>';
266  }
267 
268  print '<tr height="24">';
269  print '<td class="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'">'.$year.'</a></td>';
270  print '<td class="right">'.$val['nb'].'</td>';
271  /*print '<td class="right">'.price(price2num($val['total'],'MT'),1).'</td>';
272  print '<td class="right">'.price(price2num($val['avg'],'MT'),1).'</td>';*/
273  print '</tr>';
274  $oldyear = $year;
275 }
276 
277 print '</table>';
278 print '</div>';
279 
280 
281 print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
282 
283 
284 // Show graphs
285 print '<table class="border centpercent"><tr class="pair nohover"><td class="center">';
286 if ($mesg) { print $mesg; } else {
287  print $px1->show();
288  print "<br>\n";
289  /*print $px2->show();
290  print "<br>\n";
291  print $px3->show();*/
292 }
293 print '</td></tr></table>';
294 
295 
296 print '</div></div></div>';
297 print '<div style="clear:both"></div>';
298 
299 print dol_get_fiche_end();
300 
301 
302 
303 // TODO USe code similar to commande/stats/index.php instead of this one.
304 /*
305 print '<table class="border centpercent">';
306 print '<tr><td class="center">'.$langs->trans("Year").'</td>';
307 print '<td width="40%" class="center">'.$langs->trans("NbOfSendings").'</td></tr>';
308 
309 $sql = "SELECT count(*) as nb, date_format(date_expedition,'%Y') as dm";
310 $sql.= " FROM ".MAIN_DB_PREFIX."expedition";
311 $sql.= " WHERE fk_statut > 0";
312 $sql.= " AND entity = ".$conf->entity;
313 $sql.= " GROUP BY dm DESC";
314 
315 $resql=$db->query($sql);
316 if ($resql)
317 {
318  $num = $db->num_rows($resql);
319  $i = 0;
320  while ($i < $num)
321  {
322  $row = $db->fetch_row($resql);
323  $nbproduct = $row[0];
324  $year = $row[1];
325  print "<tr>";
326  print '<td class="center"><a href="month.php?year='.$year.'">'.$year.'</a></td><td class="center">'.$nbproduct.'</td></tr>';
327  $i++;
328  }
329 }
330 $db->free($resql);
331 
332 print '</table>';
333 */
334 
335 print '<br>';
336 print '<i>'.$langs->trans("StatsOnShipmentsOnlyValidated").'</i>';
337 
338 llxFooter();
339 
340 $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.
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.
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.
Class to manage donations statistics.
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)