29 require
'../../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
31 require_once DOL_DOCUMENT_ROOT.
'/commande/class/commandestats.class.php';
32 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
33 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formorder.class.php';
34 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
35 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
36 require_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
42 if ($mode ==
'customer' && !$user->rights->commande->lire)
accessforbidden();
43 if ($mode ==
'supplier' && !$user->rights->fournisseur->commande->lire)
accessforbidden();
45 $object_status =
GETPOST(
'object_status',
'intcomma');
46 $typent_id =
GETPOST(
'typent_id',
'int');
47 $categ_id =
GETPOST(
'categ_id',
'categ_id');
49 $userid =
GETPOST(
'userid',
'int');
50 $socid =
GETPOST(
'socid',
'int');
55 $socid = $user->socid;
58 $nowyear = strftime(
"%Y",
dol_now());
61 $startyear = $year - 1;
65 $langs->loadLangs(array(
'orders',
'companies',
'other',
'suppliers'));
72 $form =
new Form($db);
78 $title = $langs->trans(
"OrdersStatistics");
79 $dir = $conf->commande->dir_temp;
81 if ($mode ==
'supplier')
83 $picto =
'supplier_order';
84 $title = $langs->trans(
"OrdersStatisticsSuppliers");
85 $dir = $conf->fournisseur->commande->dir_temp;
94 $stats =
new CommandeStats($db, $socid, $mode, ($userid > 0 ? $userid : 0), ($typent_id > 0 ? $typent_id : 0), ($categ_id > 0 ? $categ_id : 0));
95 if ($mode ==
'customer')
97 if ($object_status !=
'' && $object_status >= -1) $stats->where .=
' AND c.fk_statut IN ('.$db->sanitize($db->escape($object_status)).
')';
99 if ($mode ==
'supplier')
101 if ($object_status !=
'' && $object_status >= 0) $stats->where .=
' AND c.fk_statut IN ('.$db->sanitize($db->escape($object_status)).
')';
106 $data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
112 if (!$user->rights->societe->client->voir || $user->socid)
114 $filenamenb = $dir.
'/ordersnbinyear-'.$user->id.
'-'.$year.
'.png';
115 if ($mode ==
'customer') $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersnbinyear-'.$user->id.
'-'.$year.
'.png';
116 if ($mode ==
'supplier') $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersnbinyear-'.$user->id.
'-'.$year.
'.png';
118 $filenamenb = $dir.
'/ordersnbinyear-'.$year.
'.png';
119 if ($mode ==
'customer') $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersnbinyear-'.$year.
'.png';
120 if ($mode ==
'supplier') $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersnbinyear-'.$year.
'.png';
124 $mesg = $px1->isGraphKo();
127 $px1->SetData($data);
128 $i = $startyear; $legend = array();
129 while ($i <= $endyear)
134 $px1->SetLegend($legend);
135 $px1->SetMaxValue($px1->GetCeilMaxValue());
136 $px1->SetMinValue(min(0, $px1->GetFloorMinValue()));
137 $px1->SetWidth($WIDTH);
138 $px1->SetHeight($HEIGHT);
139 $px1->SetYLabel($langs->trans(
"NbOfOrder"));
141 $px1->SetHorizTickIncrement(1);
142 $px1->mode =
'depth';
143 $px1->SetTitle($langs->trans(
"NumberOfOrdersByMonth"));
145 $px1->draw($filenamenb, $fileurlnb);
149 $data = $stats->getAmountByMonthWithPrevYear($endyear, $startyear);
153 if (!$user->rights->societe->client->voir || $user->socid)
155 $filenameamount = $dir.
'/ordersamountinyear-'.$user->id.
'-'.$year.
'.png';
156 if ($mode ==
'customer') $fileurlamount = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersamountinyear-'.$user->id.
'-'.$year.
'.png';
157 if ($mode ==
'supplier') $fileurlamount = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersamountinyear-'.$user->id.
'-'.$year.
'.png';
159 $filenameamount = $dir.
'/ordersamountinyear-'.$year.
'.png';
160 if ($mode ==
'customer') $fileurlamount = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersamountinyear-'.$year.
'.png';
161 if ($mode ==
'supplier') $fileurlamount = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersamountinyear-'.$year.
'.png';
165 $mesg = $px2->isGraphKo();
168 $px2->SetData($data);
169 $i = $startyear; $legend = array();
170 while ($i <= $endyear)
175 $px2->SetLegend($legend);
176 $px2->SetMaxValue($px2->GetCeilMaxValue());
177 $px2->SetMinValue(min(0, $px2->GetFloorMinValue()));
178 $px2->SetWidth($WIDTH);
179 $px2->SetHeight($HEIGHT);
180 $px2->SetYLabel($langs->trans(
"AmountOfOrders"));
182 $px2->SetHorizTickIncrement(1);
183 $px2->mode =
'depth';
184 $px2->SetTitle($langs->trans(
"AmountOfOrdersByMonthHT"));
186 $px2->draw($filenameamount, $fileurlamount);
190 $data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
192 if (!$user->rights->societe->client->voir || $user->socid)
194 $filename_avg = $dir.
'/ordersaverage-'.$user->id.
'-'.$year.
'.png';
195 if ($mode ==
'customer') $fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$user->id.
'-'.$year.
'.png';
196 if ($mode ==
'supplier') $fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$user->id.
'-'.$year.
'.png';
198 $filename_avg = $dir.
'/ordersaverage-'.$year.
'.png';
199 if ($mode ==
'customer') $fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$year.
'.png';
200 if ($mode ==
'supplier') $fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$year.
'.png';
204 $mesg = $px3->isGraphKo();
207 $px3->SetData($data);
208 $i = $startyear; $legend = array();
209 while ($i <= $endyear)
214 $px3->SetLegend($legend);
215 $px3->SetYLabel($langs->trans(
"AmountAverage"));
216 $px3->SetMaxValue($px3->GetCeilMaxValue());
217 $px3->SetMinValue($px3->GetFloorMinValue());
218 $px3->SetWidth($WIDTH);
219 $px3->SetHeight($HEIGHT);
221 $px3->SetHorizTickIncrement(1);
222 $px3->mode =
'depth';
223 $px3->SetTitle($langs->trans(
"AmountAverage"));
225 $px3->draw($filename_avg, $fileurl_avg);
231 $data = $stats->getAllByYear();
232 $arrayyears = array();
233 foreach ($data as $val) {
234 if (!empty($val[
'year'])) {
235 $arrayyears[$val[
'year']] = $val[
'year'];
238 if (!count($arrayyears)) $arrayyears[$nowyear] = $nowyear;
242 $head[$h][0] = DOL_URL_ROOT.
'/commande/stats/index.php?mode='.$mode;
243 $head[$h][1] = $langs->trans(
"ByMonthYear");
244 $head[$h][2] =
'byyear';
247 if ($mode ==
'customer') $type =
'order_stats';
248 if ($mode ==
'supplier') $type =
'supplier_order_stats';
255 print '<div class="fichecenter"><div class="fichethirdleft">';
259 print
'<form name="stats" method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
260 print
'<input type="hidden" name="token" value="'.newToken().
'">';
261 print
'<input type="hidden" name="mode" value="'.$mode.
'">';
263 print
'<table class="noborder centpercent">';
264 print
'<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans(
"Filter").
'</td></tr>';
266 print
'<tr><td class="left">'.$langs->trans(
"ThirdParty").
'</td><td class="left">';
267 if ($mode ==
'customer') $filter =
's.client IN (1,2,3)';
268 if ($mode ==
'supplier') $filter =
's.fournisseur = 1';
269 print $form->select_company($socid,
'socid', $filter, 1, 0, 0, array(), 0,
'',
'style="width: 95%"');
272 print
'<tr><td>'.$langs->trans(
"ThirdPartyType").
'</td><td>';
273 $sortparam_typent = (empty($conf->global->SOCIETE_SORT_ON_TYPEENT) ?
'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT);
274 print $form->selectarray(
"typent_id", $formcompany->typent_array(0), $typent_id, 0, 0, 0,
'', 0, 0, 0, $sortparam_typent);
275 if ($user->admin) print
' '.info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
278 if ($mode ==
'customer')
280 $cat_type = Categorie::TYPE_CUSTOMER;
281 $cat_label = $langs->trans(
"Category").
' '.lcfirst($langs->trans(
"Customer"));
283 if ($mode ==
'supplier')
285 $cat_type = Categorie::TYPE_SUPPLIER;
286 $cat_label = $langs->trans(
"Category").
' '.lcfirst($langs->trans(
"Supplier"));
288 print
'<tr><td>'.$cat_label.
'</td><td>';
289 print $formother->select_categories($cat_type, $categ_id,
'categ_id',
true);
292 print
'<tr><td class="left">'.$langs->trans(
"CreatedBy").
'</td><td class="left">';
293 print $form->select_dolusers($userid,
'userid', 1,
'', 0,
'',
'', 0, 0, 0,
'', 0,
'',
'maxwidth300');
295 print
'<tr><td class="left">'.$langs->trans(
"Status").
'</td><td class="left">';
296 if ($mode ==
'customer')
305 print $form->selectarray(
'object_status', $liststatus,
GETPOST(
'object_status',
'intcomma'), -4);
307 if ($mode ==
'supplier')
309 $formorder->selectSupplierOrderStatus((strstr($object_status,
',') ? -1 : $object_status), 0,
'object_status');
313 print
'<tr><td class="left">'.$langs->trans(
"Year").
'</td><td class="left">';
314 if (!in_array($year, $arrayyears)) $arrayyears[$year] = $year;
315 if (!in_array($nowyear, $arrayyears)) $arrayyears[$nowyear] = $nowyear;
317 print $form->selectarray(
'year', $arrayyears, $year, 0);
319 print
'<tr><td align="center" colspan="2"><input type="submit" name="submit" class="button" value="'.$langs->trans(
"Refresh").
'"></td></tr>';
325 print
'<div class="div-table-responsive-no-min">';
326 print
'<table class="noborder centpercent">';
327 print
'<tr class="liste_titre" height="24">';
328 print
'<td class="center">'.$langs->trans(
"Year").
'</td>';
329 print
'<td class="right">'.$langs->trans(
"NbOfOrders").
'</td>';
330 print
'<td class="right">%</td>';
331 print
'<td class="right">'.$langs->trans(
"AmountTotal").
'</td>';
332 print
'<td class="right">%</td>';
333 print
'<td class="right">'.$langs->trans(
"AmountAverage").
'</td>';
334 print
'<td class="right">%</td>';
338 foreach ($data as $val)
340 $year = $val[
'year'];
341 while (!empty($year) && $oldyear > $year + 1)
345 print
'<tr class="oddeven" height="24">';
346 print
'<td align="center"><a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$oldyear.
'&mode='.$mode.($socid > 0 ?
'&socid='.$socid :
'').($userid > 0 ?
'&userid='.$userid :
'').
'">'.$oldyear.
'</a></td>';
347 print
'<td class="right">0</td>';
348 print
'<td class="right"></td>';
349 print
'<td class="right">0</td>';
350 print
'<td class="right"></td>';
351 print
'<td class="right">0</td>';
352 print
'<td class="right"></td>';
357 print
'<tr class="oddeven" height="24">';
358 print
'<td align="center"><a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$year.
'&mode='.$mode.($socid > 0 ?
'&socid='.$socid :
'').($userid > 0 ?
'&userid='.$userid :
'').
'">'.$year.
'</a></td>';
359 print
'<td class="right">'.$val[
'nb'].
'</td>';
360 print
'<td class="right" style="'.(($val[
'nb_diff'] >= 0) ?
'color: green;' :
'color: red;').
'">'.round($val[
'nb_diff']).
'</td>';
361 print
'<td class="right">'.price(
price2num($val[
'total'],
'MT'), 1).
'</td>';
362 print
'<td class="right" style="'.(($val[
'total_diff'] >= 0) ?
'color: green;' :
'color: red;').
'">'.round($val[
'total_diff']).
'</td>';
363 print
'<td class="right">'.price(
price2num($val[
'avg'],
'MT'), 1).
'</td>';
364 print
'<td class="right" style="'.(($val[
'avg_diff'] >= 0) ?
'color: green;' :
'color: red;').
'">'.round($val[
'avg_diff']).
'</td>';
373 print
'</div><div class="fichetwothirdright"><div class="ficheaddleft">';
377 print
'<table class="border centpercent"><tr class="pair nohover"><td align="center">';
378 if ($mesg) { print $mesg; }
else {
385 print
'</td></tr></table>';
388 print
'</div></div></div>';
389 print
'<div style="clear:both"></div>';
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
const STATUS_CLOSED
Closed (Sent, billed or not)
dol_now($mode= 'auto')
Return date for now.
const STATUS_SHIPMENTONPROCESS
Shipment on process.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is '...
const STATUS_DRAFT
Draft status.
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
const STATUS_VALIDATED
Validated status.
Class to manage order statistics (customer and supplier)
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.
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).
dol_mkdir($dir, $dataroot= '', $newmask=null)
Creation of a directory (this can create recursive subdir)
const STATUS_CANCELED
Canceled status.