dolibarr  9.0.0
index.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2012 Marcos García <marcosgdf@gmail.com>
6  * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
28 require '../../../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propalestats.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formpropal.class.php';
32 
35 
36 $mode=GETPOST("mode")?GETPOST("mode"):'customer';
37 if ($mode == 'customer' && ! $user->rights->propale->lire) accessforbidden();
38 if ($mode == 'supplier' && ! $user->rights->supplier_proposal->lire) accessforbidden();
39 
40 $object_status=GETPOST('object_status');
41 
42 $userid=GETPOST('userid','int');
43 $socid=GETPOST('socid','int');
44 // Security check
45 if ($user->societe_id > 0)
46 {
47  $action = '';
48  $socid = $user->societe_id;
49 }
50 
51 $nowyear=strftime("%Y", dol_now());
52 $year = GETPOST('year')>0?GETPOST('year'):$nowyear;
53 //$startyear=$year-2;
54 $startyear=$year-1;
55 $endyear=$year;
56 
57 // Load translation files required by the page
58 $langs->loadLangs(array('orders', 'companies', 'other', 'suppliers', 'supplier_proposal'));
59 
60 
61 /*
62  * View
63  */
64 
65 $form=new Form($db);
66 $formpropal=new FormPropal($db);
67 
68 $langs->loadLangs(array('propal', 'other', 'companies'));
69 
70 if ($mode == 'customer')
71 {
72  $title=$langs->trans("ProposalsStatistics");
73  $dir=$conf->propale->dir_temp;
74 }
75 if ($mode == 'supplier')
76 {
77  $title=$langs->trans("ProposalsStatisticsSuppliers").' ('.$langs->trans("SentToSuppliers").")";
78  $dir=$conf->supplier_proposal->dir_temp;
79 }
80 
81 llxHeader('', $title);
82 
83 print load_fiche_titre($title,'','title_commercial.png');
84 
85 
86 dol_mkdir($dir);
87 
88 
89 $stats = new PropaleStats($db, $socid, ($userid>0?$userid:0), $mode);
90 if ($object_status != '' && $object_status >= 0) $stats->where .= ' AND p.fk_statut IN ('.$db->escape($object_status).')';
91 
92 // Build graphic number of object
93 $data = $stats->getNbByMonthWithPrevYear($endyear,$startyear);
94 // $data = array(array('Lib',val1,val2,val3),...)
95 
96 
97 if (!$user->rights->societe->client->voir || $user->societe_id)
98 {
99  $filenamenb = $dir.'/proposalsnbinyear-'.$user->id.'-'.$year.'.png';
100  $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=proposalsnbinyear-'.$user->id.'-'.$year.'.png';
101 }
102 else
103 {
104  $filenamenb = $dir.'/proposalsnbinyear-'.$year.'.png';
105  $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=proposalsnbinyear-'.$year.'.png';
106 }
107 
108 $px1 = new DolGraph();
109 $mesg = $px1->isGraphKo();
110 if (! $mesg)
111 {
112  $px1->SetData($data);
113  $px1->SetPrecisionY(0);
114  $i=$startyear;$legend=array();
115  while ($i <= $endyear)
116  {
117  $legend[]=$i;
118  $i++;
119  }
120  $px1->SetLegend($legend);
121  $px1->SetMaxValue($px1->GetCeilMaxValue());
122  $px1->SetMinValue(min(0,$px1->GetFloorMinValue()));
123  $px1->SetWidth($WIDTH);
124  $px1->SetHeight($HEIGHT);
125  $px1->SetYLabel($langs->trans("NbOfProposals"));
126  $px1->SetShading(3);
127  $px1->SetHorizTickIncrement(1);
128  $px1->SetPrecisionY(0);
129  $px1->mode='depth';
130  $px1->SetTitle($langs->trans("NumberOfProposalsByMonth"));
131 
132  $px1->draw($filenamenb,$fileurlnb);
133 }
134 
135 // Build graphic amount of object
136 $data = $stats->getAmountByMonthWithPrevYear($endyear,$startyear,0);
137 // $data = array(array('Lib',val1,val2,val3),...)
138 
139 if (!$user->rights->societe->client->voir || $user->societe_id)
140 {
141  $filenameamount = $dir.'/proposalsamountinyear-'.$user->id.'-'.$year.'.png';
142  $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=proposalsamountinyear-'.$user->id.'-'.$year.'.png';
143 }
144 else
145 {
146  $filenameamount = $dir.'/proposalsamountinyear-'.$year.'.png';
147  $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=proposalsamountinyear-'.$year.'.png';
148 }
149 
150 $px2 = new DolGraph();
151 $mesg = $px2->isGraphKo();
152 if (! $mesg)
153 {
154  $px2->SetData($data);
155  $px2->SetPrecisionY(0);
156  $i=$startyear;$legend=array();
157  while ($i <= $endyear)
158  {
159  $legend[]=$i;
160  $i++;
161  }
162  $px2->SetLegend($legend);
163  $px2->SetMaxValue($px2->GetCeilMaxValue());
164  $px2->SetMinValue(min(0,$px2->GetFloorMinValue()));
165  $px2->SetWidth($WIDTH);
166  $px2->SetHeight($HEIGHT);
167  $px2->SetYLabel($langs->trans("AmountOfProposals"));
168  $px2->SetShading(3);
169  $px2->SetHorizTickIncrement(1);
170  $px2->SetPrecisionY(0);
171  $px2->mode='depth';
172  $px2->SetTitle($langs->trans("AmountOfProposalsByMonthHT"));
173 
174  $px2->draw($filenameamount,$fileurlamount);
175 }
176 
177 $data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
178 
179 $fileurl_avg='';
180 if (!$user->rights->societe->client->voir || $user->societe_id)
181 {
182  $filename_avg = $dir.'/ordersaverage-'.$user->id.'-'.$year.'.png';
183  if ($mode == 'customer') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$user->id.'-'.$year.'.png';
184  if ($mode == 'supplier') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$user->id.'-'.$year.'.png';
185 }
186 else
187 {
188  $filename_avg = $dir.'/ordersaverage-'.$year.'.png';
189  if ($mode == 'customer') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$year.'.png';
190  if ($mode == 'supplier') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$year.'.png';
191 }
192 
193 $px3 = new DolGraph();
194 $mesg = $px3->isGraphKo();
195 if (! $mesg)
196 {
197  $px3->SetData($data);
198  $i=$startyear;$legend=array();
199  while ($i <= $endyear)
200  {
201  $legend[]=$i;
202  $i++;
203  }
204  $px3->SetLegend($legend);
205  $px3->SetYLabel($langs->trans("AmountAverage"));
206  $px3->SetMaxValue($px3->GetCeilMaxValue());
207  $px3->SetMinValue($px3->GetFloorMinValue());
208  $px3->SetWidth($WIDTH);
209  $px3->SetHeight($HEIGHT);
210  $px3->SetShading(3);
211  $px3->SetHorizTickIncrement(1);
212  $px3->SetPrecisionY(0);
213  $px3->mode='depth';
214  $px3->SetTitle($langs->trans("AmountAverage"));
215 
216  $px3->draw($filename_avg,$fileurl_avg);
217 }
218 
219 
220 // Show array
221 $data = $stats->getAllByYear();
222 $arrayyears=array();
223 foreach($data as $val) {
224  if (! empty($val['year'])) {
225  $arrayyears[$val['year']]=$val['year'];
226  }
227 }
228 if (! count($arrayyears)) $arrayyears[$nowyear]=$nowyear;
229 
230 
231 $h=0;
232 $head = array();
233 $head[$h][0] = DOL_URL_ROOT . '/comm/propal/stats/index.php';
234 $head[$h][1] = $langs->trans("ByMonthYear");
235 $head[$h][2] = 'byyear';
236 $h++;
237 
238 complete_head_from_modules($conf,$langs,null,$head,$h,'propal_stats');
239 
240 dol_fiche_head($head, 'byyear', $langs->trans("Statistics"), -1);
241 
242 
243 print '<div class="fichecenter"><div class="fichethirdleft">';
244 
245 
246 //if (empty($socid))
247 //{
248  // Show filter box
249  print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
250  print '<input type="hidden" name="mode" value="'.$mode.'">';
251  print '<table class="noborder" width="100%">';
252  print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
253  // Company
254  print '<tr><td align="left">'.$langs->trans("ThirdParty").'</td><td align="left">';
255  $filter='s.client in (1,2,3)';
256  print $form->select_company($socid,'socid',$filter,1,0,0,array(),0,'','style="width: 95%"');
257  print '</td></tr>';
258  // User
259  print '<tr><td align="left">'.$langs->trans("CreatedBy").'</td><td align="left">';
260  print $form->select_dolusers($userid, 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth300');
261  print '</td></tr>';
262  // Status
263  print '<tr><td align="left">'.$langs->trans("Status").'</td><td align="left">';
264  $formpropal->selectProposalStatus(($object_status!=''?$object_status:-1),0,0,1,$mode,'object_status');
265  print '</td></tr>';
266  // Year
267  print '<tr><td align="left">'.$langs->trans("Year").'</td><td align="left">';
268  if (! in_array($year,$arrayyears)) $arrayyears[$year]=$year;
269  if (! in_array($nowyear,$arrayyears)) $arrayyears[$nowyear]=$nowyear;
270  arsort($arrayyears);
271  print $form->selectarray('year',$arrayyears,$year,0);
272  print '</td></tr>';
273  print '<tr><td align="center" colspan="2"><input type="submit" name="submit" class="button" value="'.$langs->trans("Refresh").'"></td></tr>';
274  print '</table>';
275  print '</form>';
276  print '<br><br>';
277 //}
278 
279 print '<div class="div-table-responsive-no-min">';
280 print '<table class="noborder" width="100%">';
281 print '<tr class="liste_titre" height="24">';
282 print '<td align="center">'.$langs->trans("Year").'</td>';
283 print '<td align="right">'.$langs->trans("NbOfProposals").'</td>';
284 print '<td align="right">%</td>';
285 print '<td align="right">'.$langs->trans("AmountTotal").'</td>';
286 print '<td align="right">%</td>';
287 print '<td align="right">'.$langs->trans("AmountAverage").'</td>';
288 print '<td align="right">%</td>';
289 print '</tr>';
290 
291 $oldyear=0;
292 foreach ($data as $val)
293 {
294  $year = $val['year'];
295  while (! empty($year) && $oldyear > $year+1)
296  { // If we have empty year
297  $oldyear--;
298 
299  print '<tr class="oddeven" height="24">';
300  print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$oldyear.'&amp;mode='.$mode.($socid>0?'&socid='.$socid:'').($userid>0?'&userid='.$userid:'').'">'.$oldyear.'</a></td>';
301  print '<td align="right">0</td>';
302  print '<td align="right"></td>';
303  print '<td align="right">0</td>';
304  print '<td align="right"></td>';
305  print '<td align="right">0</td>';
306  print '<td align="right"></td>';
307  print '</tr>';
308  }
309  print '<tr class="oddeven" height="24">';
310  print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$year.($socid>0?'&socid='.$socid:'').($userid>0?'&userid='.$userid:'').'">'.$year.'</a></td>';
311  print '<td align="right">'.$val['nb'].'</td>';
312  print '<td align="right" style="'.(($val['nb_diff'] >= 0) ? 'color: green;':'color: red;').'">'.round($val['nb_diff']).'</td>';
313  print '<td align="right">'.price(price2num($val['total'],'MT'),1).'</td>';
314  print '<td align="right" style="'.(($val['total_diff'] >= 0) ? 'color: green;':'color: red;').'">'.round($val['total_diff']).'</td>';
315  print '<td align="right">'.price(price2num($val['avg'],'MT'),1).'</td>';
316  print '<td align="right" style="'.(($val['avg_diff'] >= 0) ? 'color: green;':'color: red;').'">'.round($val['avg_diff']).'</td>';
317  print '</tr>';
318  $oldyear=$year;
319 }
320 
321 print '</table>';
322 print '</div>';
323 
324 print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
325 
326 
327 // Show graphs
328 print '<table class="border" width="100%"><tr class="pair nohover"><td align="center">';
329 if ($mesg) { print $mesg; }
330 else {
331  print $px1->show();
332  print "<br>\n";
333  print $px2->show();
334  print "<br>\n";
335  print $px3->show();
336 }
337 print '</td></tr></table>';
338 
339 
340 print '</div></div></div>';
341 print '<div style="clear:both"></div>';
342 
343 
344 dol_fiche_end();
345 
346 // End of page
347 llxFooter();
348 $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 for proposal management.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
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)
price2num($amount, $rounding='', $alreadysqlnb=0)
Function that return a number with universal decimal format (decimal separator is &#39;...
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='')
Show tab header of a card.
Class to manage proposals statistics.