dolibarr 21.0.0-alpha
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 * Copyright (C) 2020 Maxime DEMAREST <maxime@indelog.fr>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
29// Load Dolibarr environment
30require '../../../main.inc.php';
31require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propalestats.class.php';
32require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
33require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
34require_once DOL_DOCUMENT_ROOT.'/core/class/html.formpropal.class.php';
35require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
36require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
37
40
41$mode = GETPOSTISSET("mode") ? GETPOST("mode", 'aZ09') : 'customer';
42
43$hookmanager->initHooks(array('propalstats', 'globalcard'));
44
45$object_status = GETPOST('object_status', 'intcomma');
46$typent_id = GETPOSTINT('typent_id');
47$categ_id = GETPOSTINT('categ_id');
48
49$userid = GETPOSTINT('userid');
50$socid = GETPOSTINT('socid');
51// Security check
52if ($user->socid > 0) {
53 $action = '';
54 $socid = $user->socid;
55}
56
57$parameters = array();
58$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
59if ($reshook < 0) {
60 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
61}
62
63$nowyear = dol_print_date(dol_now('gmt'), "%Y", 'gmt');
64$year = GETPOST('year') > 0 ? GETPOSTINT('year') : $nowyear;
65$startyear = $year - (!getDolGlobalString('MAIN_STATS_GRAPHS_SHOW_N_YEARS') ? 2 : max(1, min(10, getDolGlobalString('MAIN_STATS_GRAPHS_SHOW_N_YEARS'))));
66$endyear = $year;
67
68// Load translation files required by the page
69$langs->loadLangs(array('orders', 'companies', 'other', 'suppliers', 'supplier_proposal'));
70
71if ($mode == 'customer' && !$user->hasRight('propal', 'lire')) {
73}
74if ($mode == 'supplier' && !$user->hasRight('supplier_proposal', 'lire')) {
76}
77
78
79/*
80 * View
81 */
82
83$form = new Form($db);
84$formpropal = new FormPropal($db);
85$formcompany = new FormCompany($db);
86$formother = new FormOther($db);
87
88$langs->loadLangs(array('propal', 'other', 'companies'));
89
90if ($mode == 'customer') {
91 $picto = 'propal';
92 $title = $langs->trans("ProposalsStatistics");
93 $dir = $conf->propal->dir_temp;
94 $cat_type = Categorie::TYPE_CUSTOMER;
95 $cat_label = $langs->trans("Category").' '.lcfirst($langs->trans("Customer"));
96}
97if ($mode == 'supplier') {
98 $picto = 'supplier_proposal';
99 $title = $langs->trans("ProposalsStatisticsSuppliers");
100 $dir = $conf->supplier_proposal->dir_temp;
101 $cat_type = Categorie::TYPE_SUPPLIER;
102 $cat_label = $langs->trans("Category").' '.lcfirst($langs->trans("Supplier"));
103}
104
105llxHeader('', $title);
106
107print load_fiche_titre($title, '', $picto);
108
109
110dol_mkdir($dir);
111
112
113$stats = new PropaleStats($db, $socid, ($userid > 0 ? $userid : 0), $mode, ($typent_id > 0 ? $typent_id : 0), ($categ_id > 0 ? $categ_id : 0));
114if ($object_status != '' && $object_status >= 0) {
115 $stats->where .= ' AND p.fk_statut IN ('.$db->sanitize($object_status).')';
116}
117
118// Build graphic number of object
119$data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
120// $data = array(array('Lib',val1,val2,val3),...)
121
122
123if (!$user->hasRight('societe', 'client', 'voir')) {
124 $filenamenb = $dir.'/proposalsnbinyear-'.$user->id.'-'.$year.'.png';
125 $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=proposalsnbinyear-'.$user->id.'-'.$year.'.png';
126} else {
127 $filenamenb = $dir.'/proposalsnbinyear-'.$year.'.png';
128 $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=proposalsnbinyear-'.$year.'.png';
129}
130
131$px1 = new DolGraph();
132$mesg = $px1->isGraphKo();
133if (!$mesg) {
134 $px1->SetData($data);
135 $i = $startyear;
136 $legend = array();
137 while ($i <= $endyear) {
138 $legend[] = $i;
139 $i++;
140 }
141 $px1->SetLegend($legend);
142 $px1->SetMaxValue($px1->GetCeilMaxValue());
143 $px1->SetMinValue(min(0, $px1->GetFloorMinValue()));
144 $px1->SetWidth($WIDTH);
145 $px1->SetHeight($HEIGHT);
146 $px1->SetYLabel($langs->trans("NbOfProposals"));
147 $px1->SetShading(3);
148 $px1->SetHorizTickIncrement(1);
149 $px1->mode = 'depth';
150 $px1->SetTitle($langs->trans("NumberOfProposalsByMonth"));
151
152 $px1->draw($filenamenb, $fileurlnb);
153}
154
155// Build graphic amount of object
156$data = $stats->getAmountByMonthWithPrevYear($endyear, $startyear, 0);
157// $data = array(array('Lib',val1,val2,val3),...)
158
159if (!$user->hasRight('societe', 'client', 'voir')) {
160 $filenameamount = $dir.'/proposalsamountinyear-'.$user->id.'-'.$year.'.png';
161 $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=proposalsamountinyear-'.$user->id.'-'.$year.'.png';
162} else {
163 $filenameamount = $dir.'/proposalsamountinyear-'.$year.'.png';
164 $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=proposalsamountinyear-'.$year.'.png';
165}
166
167$px2 = new DolGraph();
168$mesg = $px2->isGraphKo();
169if (!$mesg) {
170 $px2->SetData($data);
171 $i = $startyear;
172 $legend = array();
173 while ($i <= $endyear) {
174 $legend[] = $i;
175 $i++;
176 }
177 $px2->SetLegend($legend);
178 $px2->SetMaxValue($px2->GetCeilMaxValue());
179 $px2->SetMinValue(min(0, $px2->GetFloorMinValue()));
180 $px2->SetWidth($WIDTH);
181 $px2->SetHeight($HEIGHT);
182 $px2->SetYLabel($langs->trans("AmountOfProposals"));
183 $px2->SetShading(3);
184 $px2->SetHorizTickIncrement(1);
185 $px2->mode = 'depth';
186 $px2->SetTitle($langs->trans("AmountOfProposalsByMonthHT"));
187
188 $px2->draw($filenameamount, $fileurlamount);
189}
190
191$data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
192
193$fileurl_avg = '';
194if (!$user->hasRight('societe', 'client', 'voir')) {
195 $filename_avg = $dir.'/ordersaverage-'.$user->id.'-'.$year.'.png';
196 if ($mode == 'customer') {
197 $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$user->id.'-'.$year.'.png';
198 }
199 if ($mode == 'supplier') {
200 $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$user->id.'-'.$year.'.png';
201 }
202} else {
203 $filename_avg = $dir.'/ordersaverage-'.$year.'.png';
204 if ($mode == 'customer') {
205 $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$year.'.png';
206 }
207 if ($mode == 'supplier') {
208 $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$year.'.png';
209 }
210}
211
212$px3 = new DolGraph();
213$mesg = $px3->isGraphKo();
214if (!$mesg) {
215 $px3->SetData($data);
216 $i = $startyear;
217 $legend = array();
218 while ($i <= $endyear) {
219 $legend[] = $i;
220 $i++;
221 }
222 $px3->SetLegend($legend);
223 $px3->SetYLabel($langs->trans("AmountAverage"));
224 $px3->SetMaxValue($px3->GetCeilMaxValue());
225 $px3->SetMinValue($px3->GetFloorMinValue());
226 $px3->SetWidth($WIDTH);
227 $px3->SetHeight($HEIGHT);
228 $px3->SetShading(3);
229 $px3->SetHorizTickIncrement(1);
230 $px3->mode = 'depth';
231 $px3->SetTitle($langs->trans("AmountAverage"));
232
233 $px3->draw($filename_avg, $fileurl_avg);
234}
235
236
237// Show array
238$data = $stats->getAllByYear();
239$arrayyears = array();
240foreach ($data as $val) {
241 if (!empty($val['year'])) {
242 $arrayyears[$val['year']] = $val['year'];
243 }
244}
245if (!count($arrayyears)) {
246 $arrayyears[$nowyear] = $nowyear;
247}
248
249
250$h = 0;
251$head = array();
252$head[$h][0] = DOL_URL_ROOT.'/comm/propal/stats/index.php';
253$head[$h][1] = $langs->trans("ByMonthYear");
254$head[$h][2] = 'byyear';
255$h++;
256
257complete_head_from_modules($conf, $langs, null, $head, $h, 'propal_stats');
258
259print dol_get_fiche_head($head, 'byyear', '', -1);
260
261
262print '<div class="fichecenter"><div class="fichethirdleft">';
263
264
265// Show filter box
266print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
267print '<input type="hidden" name="token" value="'.newToken().'">';
268print '<input type="hidden" name="mode" value="'.$mode.'">';
269
270print '<table class="noborder centpercent">';
271print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
272// Company
273print '<tr><td class="left">'.$langs->trans("ThirdParty").'</td><td class="left">';
274print img_picto('', 'company', 'class="pictofixedwidth"');
275$filter = '(s.client:IN:1,2,3)';
276print $form->select_company($socid, 'socid', $filter, 1, 0, 0, array(), 0, 'widthcentpercentminusx maxwidth300', '');
277print '</td></tr>';
278// ThirdParty Type
279print '<tr><td>'.$langs->trans("ThirdPartyType").'</td><td>';
280$sortparam_typent = (!getDolGlobalString('SOCIETE_SORT_ON_TYPEENT') ? 'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT); // NONE means we keep sort of original array, so we sort on position. ASC, means next function will sort on label.
281print $form->selectarray("typent_id", $formcompany->typent_array(0), $typent_id, 1, 0, 0, '', 0, 0, 0, $sortparam_typent, '', 1);
282if ($user->admin) {
283 print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
284}
285print '</td></tr>';
286// Category
287print '<tr><td>'.$cat_label.'</td><td>';
288print img_picto('', 'category', 'class="pictofixedwidth"');
289print $formother->select_categories($cat_type, $categ_id, 'categ_id', 0, 1, 'widthcentpercentminusx maxwidth300');
290print '</td></tr>';
291// User
292print '<tr><td>'.$langs->trans("CreatedBy").'</td><td>';
293print img_picto('', 'user', 'class="pictofixedwidth"');
294print $form->select_dolusers($userid, 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'widthcentpercentminusx maxwidth300');
295print '</td></tr>';
296// Status
297print '<tr><td>'.$langs->trans("Status").'</td><td>';
298$formpropal->selectProposalStatus(($object_status != '' ? $object_status : -1), 0, 0, 1, $mode, 'object_status');
299print '</td></tr>';
300// Year
301print '<tr><td>'.$langs->trans("Year").'</td><td>';
302if (!in_array($year, $arrayyears)) {
303 $arrayyears[$year] = $year;
304}
305if (!in_array($nowyear, $arrayyears)) {
306 $arrayyears[$nowyear] = $nowyear;
307}
308arsort($arrayyears);
309print $form->selectarray('year', $arrayyears, $year, 0, 0, 0, '', 0, 0, 0, '', 'width75');
310print '</td></tr>';
311print '<tr><td align="center" colspan="2"><input type="submit" name="submit" class="button small" value="'.$langs->trans("Refresh").'"></td></tr>';
312print '</table>';
313print '</form>';
314print '<br><br>';
315
316print '<div class="div-table-responsive-no-min">';
317print '<table class="noborder centpercent">';
318print '<tr class="liste_titre" height="24">';
319print '<td class="center">'.$langs->trans("Year").'</td>';
320print '<td class="right">'.$langs->trans("NbOfProposals").'</td>';
321print '<td class="right">%</td>';
322print '<td class="right">'.$langs->trans("AmountTotal").'</td>';
323print '<td class="right">%</td>';
324print '<td class="right">'.$langs->trans("AmountAverage").'</td>';
325print '<td class="right">%</td>';
326print '</tr>';
327
328$oldyear = 0;
329foreach ($data as $val) {
330 $year = $val['year'];
331 while (!empty($year) && $oldyear > $year + 1) { // If we have empty year
332 $oldyear--;
333
334 print '<tr class="oddeven" height="24">';
335 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>';
336 print '<td class="right">0</td>';
337 print '<td class="right"></td>';
338 print '<td class="right">0</td>';
339 print '<td class="right"></td>';
340 print '<td class="right">0</td>';
341 print '<td class="right"></td>';
342 print '</tr>';
343 }
344 print '<tr class="oddeven" height="24">';
345 print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$year.($socid > 0 ? '&socid='.$socid : '').($userid > 0 ? '&userid='.$userid : '').'">'.$year.'</a></td>';
346 print '<td class="right">'.$val['nb'].'</td>';
347 print '<td class="right opacitylow" style="'.((!isset($val['nb_diff']) || $val['nb_diff'] >= 0) ? 'color: green;' : 'color: red;').'">'.(isset($val['nb_diff']) ? round($val['nb_diff']) : "0").'%</td>';
348 print '<td class="right">'.price(price2num($val['total'], 'MT'), 1).'</td>';
349 print '<td class="right opacitylow" style="'.((!isset($val['total_diff']) || $val['total_diff'] >= 0) ? 'color: green;' : 'color: red;').'">'.(isset($val['total_diff']) ? round($val['total_diff']) : "0").'%</td>';
350 print '<td class="right">'.price(price2num($val['avg'], 'MT'), 1).'</td>';
351 print '<td class="right opacitylow" style="'.((!isset($val['avg_diff']) || $val['avg_diff'] >= 0) ? 'color: green;' : 'color: red;').'">'.(isset($val['avg_diff']) ? round($val['avg_diff']) : "0").'%</td>';
352 print '</tr>';
353 $oldyear = $year;
354}
355
356print '</table>';
357print '</div>';
358
359print '</div><div class="fichetwothirdright">';
360
361
362// Show graphs
363print '<table class="border centpercent"><tr class="pair nohover"><td align="center">';
364if ($mesg) {
365 print $mesg;
366} else {
367 print $px1->show();
368 print "<br>\n";
369 print $px2->show();
370 print "<br>\n";
371 print $px3->show();
372}
373print '</td></tr></table>';
374
375
376print '</div></div>';
377print '<div class="clearboth"></div>';
378
379
380print dol_get_fiche_end();
381
382// End of page
383llxFooter();
384$db->close();
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:70
Class to build graphs.
static getDefaultGraphSizeForStats($direction, $defaultsize='')
getDefaultGraphSizeForStats
Class to build HTML component for third parties management Only common components are here.
Class to manage generation of HTML components Only common components must be here.
Class permettant la generation de composants html autre Only common components are here.
Class to manage generation of HTML components for proposal management.
Class to manage proposals statistics.
llxFooter()
Footer empty.
Definition document.php:107
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_now($mode='auto')
Return date for now.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add', $filterorigmodule='')
Complete or removed entries into a head array (used to build tabs).
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.