30require
'../../main.inc.php';
31require_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
32require_once DOL_DOCUMENT_ROOT.
'/commande/class/commandestats.class.php';
33require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
34require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formorder.class.php';
35require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
36require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
37require_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
42$mode = GETPOSTISSET(
"mode") ?
GETPOST(
"mode",
'aZ09') :
'customer';
43if ($mode ==
'customer' && !$user->rights->commande->lire) {
46if ($mode ==
'supplier' && empty($user->rights->fournisseur->commande->lire)) {
49if ($mode ==
'supplier') {
50 $object_status =
GETPOST(
'object_status',
'array:int');
51 $object_status = implode(
',', $object_status);
53 $object_status =
GETPOST(
'object_status',
'intcomma');
57$typent_id =
GETPOST(
'typent_id',
'int');
58$categ_id =
GETPOST(
'categ_id',
'categ_id');
60$userid =
GETPOST(
'userid',
'int');
61$socid =
GETPOST(
'socid',
'int');
63if ($user->socid > 0) {
65 $socid = $user->socid;
70$startyear = $year - (empty($conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS) ? 2 : max(1, min(10, $conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS)));
74$langs->loadLangs(array(
'orders',
'companies',
'other',
'suppliers'));
87$title = $langs->trans(
"OrdersStatistics");
88$dir = $conf->commande->dir_temp;
90if ($mode ==
'supplier') {
91 $picto =
'supplier_order';
92 $title = $langs->trans(
"OrdersStatisticsSuppliers");
93 $dir = $conf->fournisseur->commande->dir_temp;
102$stats =
new CommandeStats($db, $socid, $mode, ($userid > 0 ? $userid : 0), ($typent_id > 0 ? $typent_id : 0), ($categ_id > 0 ? $categ_id : 0));
103if ($mode ==
'customer') {
104 if ($object_status !=
'' && $object_status >= -1) {
105 $stats->where .=
' AND c.fk_statut IN ('.$db->sanitize($object_status).
')';
108if ($mode ==
'supplier') {
109 if ($object_status !=
'' && $object_status >= 0) {
110 $stats->where .=
' AND c.fk_statut IN ('.$db->sanitize($object_status).
')';
116$data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
122if (empty($user->rights->societe->client->voir) || $user->socid) {
123 $filenamenb = $dir.
'/ordersnbinyear-'.$user->id.
'-'.$year.
'.png';
124 if ($mode ==
'customer') {
125 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersnbinyear-'.$user->id.
'-'.$year.
'.png';
127 if ($mode ==
'supplier') {
128 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersnbinyear-'.$user->id.
'-'.$year.
'.png';
131 $filenamenb = $dir.
'/ordersnbinyear-'.$year.
'.png';
132 if ($mode ==
'customer') {
133 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersnbinyear-'.$year.
'.png';
135 if ($mode ==
'supplier') {
136 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersnbinyear-'.$year.
'.png';
141$mesg = $px1->isGraphKo();
143 $px1->SetData($data);
144 $i = $startyear; $legend = array();
145 while ($i <= $endyear) {
149 $px1->SetLegend($legend);
150 $px1->SetMaxValue($px1->GetCeilMaxValue());
151 $px1->SetMinValue(min(0, $px1->GetFloorMinValue()));
152 $px1->SetWidth($WIDTH);
153 $px1->SetHeight($HEIGHT);
154 $px1->SetYLabel($langs->trans(
"NbOfOrder"));
156 $px1->SetHorizTickIncrement(1);
157 $px1->mode =
'depth';
158 $px1->SetTitle($langs->trans(
"NumberOfOrdersByMonth"));
160 $px1->draw($filenamenb, $fileurlnb);
164$data = $stats->getAmountByMonthWithPrevYear($endyear, $startyear);
168if (empty($user->rights->societe->client->voir) || $user->socid) {
169 $filenameamount = $dir.
'/ordersamountinyear-'.$user->id.
'-'.$year.
'.png';
170 if ($mode ==
'customer') {
171 $fileurlamount = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersamountinyear-'.$user->id.
'-'.$year.
'.png';
173 if ($mode ==
'supplier') {
174 $fileurlamount = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersamountinyear-'.$user->id.
'-'.$year.
'.png';
177 $filenameamount = $dir.
'/ordersamountinyear-'.$year.
'.png';
178 if ($mode ==
'customer') {
179 $fileurlamount = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersamountinyear-'.$year.
'.png';
181 if ($mode ==
'supplier') {
182 $fileurlamount = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersamountinyear-'.$year.
'.png';
187$mesg = $px2->isGraphKo();
189 $px2->SetData($data);
190 $i = $startyear; $legend = array();
191 while ($i <= $endyear) {
195 $px2->SetLegend($legend);
196 $px2->SetMaxValue($px2->GetCeilMaxValue());
197 $px2->SetMinValue(min(0, $px2->GetFloorMinValue()));
198 $px2->SetWidth($WIDTH);
199 $px2->SetHeight($HEIGHT);
200 $px2->SetYLabel($langs->trans(
"AmountOfOrders"));
202 $px2->SetHorizTickIncrement(1);
203 $px2->mode =
'depth';
204 $px2->SetTitle($langs->trans(
"AmountOfOrdersByMonthHT"));
206 $px2->draw($filenameamount, $fileurlamount);
210$data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
212if (empty($user->rights->societe->client->voir) || $user->socid) {
213 $filename_avg = $dir.
'/ordersaverage-'.$user->id.
'-'.$year.
'.png';
214 if ($mode ==
'customer') {
215 $fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$user->id.
'-'.$year.
'.png';
217 if ($mode ==
'supplier') {
218 $fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$user->id.
'-'.$year.
'.png';
221 $filename_avg = $dir.
'/ordersaverage-'.$year.
'.png';
222 if ($mode ==
'customer') {
223 $fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$year.
'.png';
225 if ($mode ==
'supplier') {
226 $fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$year.
'.png';
231$mesg = $px3->isGraphKo();
233 $px3->SetData($data);
234 $i = $startyear; $legend = array();
235 while ($i <= $endyear) {
239 $px3->SetLegend($legend);
240 $px3->SetYLabel($langs->trans(
"AmountAverage"));
241 $px3->SetMaxValue($px3->GetCeilMaxValue());
242 $px3->SetMinValue($px3->GetFloorMinValue());
243 $px3->SetWidth($WIDTH);
244 $px3->SetHeight($HEIGHT);
246 $px3->SetHorizTickIncrement(1);
247 $px3->mode =
'depth';
248 $px3->SetTitle($langs->trans(
"AmountAverage"));
250 $px3->draw($filename_avg, $fileurl_avg);
256$data = $stats->getAllByYear();
257$arrayyears = array();
258foreach ($data as $val) {
259 if (!empty($val[
'year'])) {
260 $arrayyears[$val[
'year']] = $val[
'year'];
263if (!count($arrayyears)) {
264 $arrayyears[$nowyear] = $nowyear;
269$head[$h][0] = DOL_URL_ROOT.
'/commande/stats/index.php?mode='.$mode;
270$head[$h][1] = $langs->trans(
"ByMonthYear");
271$head[$h][2] =
'byyear';
274if ($mode ==
'customer') {
275 $type =
'order_stats';
277if ($mode ==
'supplier') {
278 $type =
'supplier_order_stats';
286print
'<div class="fichecenter"><div class="fichethirdleft">';
290print
'<form name="stats" method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
291print
'<input type="hidden" name="token" value="'.newToken().
'">';
292print
'<input type="hidden" name="mode" value="'.$mode.
'">';
294print
'<table class="noborder centpercent">';
295print
'<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans(
"Filter").
'</td></tr>';
297print
'<tr><td class="left">'.$langs->trans(
"ThirdParty").
'</td><td class="left">';
299if ($mode ==
'customer') {
300 $filter =
'(s.client:IN:1,2,3)';
302if ($mode ==
'supplier') {
303 $filter =
'(s.fournisseur:=:1)';
305print
img_picto(
'',
'company',
'class="pictofixedwidth"');
306print $form->select_company($socid,
'socid', $filter, 1, 0, 0, array(), 0,
'widthcentpercentminusx maxwidth300');
309print
'<tr><td>'.$langs->trans(
"ThirdPartyType").
'</td><td>';
310$sortparam_typent = (empty($conf->global->SOCIETE_SORT_ON_TYPEENT) ?
'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT);
311print $form->selectarray(
"typent_id", $formcompany->typent_array(0), $typent_id, 1, 0, 0,
'', 0, 0, 0, $sortparam_typent,
'', 1);
313 print
' '.info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
317if ($mode ==
'customer') {
318 $cat_type = Categorie::TYPE_CUSTOMER;
319 $cat_label = $langs->trans(
"Category").
' '.lcfirst($langs->trans(
"Customer"));
321if ($mode ==
'supplier') {
322 $cat_type = Categorie::TYPE_SUPPLIER;
323 $cat_label = $langs->trans(
"Category").
' '.lcfirst($langs->trans(
"Supplier"));
325print
'<tr><td>'.$cat_label.
'</td><td>';
326print
img_picto(
'',
'category',
'class="pictofixedwidth"');
327print $formother->select_categories($cat_type, $categ_id,
'categ_id', 0, 1,
'widthcentpercentminusx maxwidth300');
330print
'<tr><td>'.$langs->trans(
"CreatedBy").
'</td><td>';
331print
img_picto(
'',
'user',
'class="pictofixedwidth"');
332print $form->select_dolusers($userid,
'userid', 1,
'', 0,
'',
'', 0, 0, 0,
'', 0,
'',
'widthcentpercentminusx maxwidth300');
334print
'<tr><td>'.$langs->trans(
"Status").
'</td><td>';
335if ($mode ==
'customer') {
343 print $form->selectarray(
'object_status', $liststatus,
GETPOST(
'object_status',
'intcomma'), -4);
345if ($mode ==
'supplier') {
346 $formorder->selectSupplierOrderStatus((strstr($object_status,
',') ? -1 : $object_status), 0,
'object_status');
350print
'<tr><td class="left">'.$langs->trans(
"Year").
'</td><td class="left">';
351if (!in_array($year, $arrayyears)) {
352 $arrayyears[$year] = $year;
354if (!in_array($nowyear, $arrayyears)) {
355 $arrayyears[$nowyear] = $nowyear;
358print $form->selectarray(
'year', $arrayyears, $year, 0, 0, 0,
'', 0, 0, 0,
'',
'width75');
360print
'<tr><td align="center" colspan="2"><input type="submit" class="button small" name="submit" value="'.$langs->trans(
"Refresh").
'"></td></tr>';
366print
'<div class="div-table-responsive-no-min">';
367print
'<table class="noborder centpercent">';
368print
'<tr class="liste_titre" height="24">';
369print
'<td class="center">'.$langs->trans(
"Year").
'</td>';
370print
'<td class="right">'.$langs->trans(
"NbOfOrders").
'</td>';
371print
'<td class="right">%</td>';
372print
'<td class="right">'.$langs->trans(
"AmountTotal").
'</td>';
373print
'<td class="right">%</td>';
374print
'<td class="right">'.$langs->trans(
"AmountAverage").
'</td>';
375print
'<td class="right">%</td>';
379foreach ($data as $val) {
380 $year = $val[
'year'];
381 while (!empty($year) && $oldyear > $year + 1) {
384 print
'<tr class="oddeven" height="24">';
385 print
'<td align="center"><a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$oldyear.
'&mode='.$mode.($socid > 0 ?
'&socid='.$socid :
'').($userid > 0 ?
'&userid='.$userid :
'').
'">'.$oldyear.
'</a></td>';
386 print
'<td class="right">0</td>';
387 print
'<td class="right"></td>';
388 print
'<td class="right">0</td>';
389 print
'<td class="right"></td>';
390 print
'<td class="right">0</td>';
391 print
'<td class="right"></td>';
396 print
'<tr class="oddeven" height="24">';
397 print
'<td align="center"><a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$year.
'&mode='.$mode.($socid > 0 ?
'&socid='.$socid :
'').($userid > 0 ?
'&userid='.$userid :
'').
'">'.$year.
'</a></td>';
398 print
'<td class="right">'.$val[
'nb'].
'</td>';
399 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>';
400 print
'<td class="right">'.price(
price2num($val[
'total'],
'MT'), 1).
'</td>';
401 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>';
402 print
'<td class="right">'.price(
price2num($val[
'avg'],
'MT'), 1).
'</td>';
403 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>';
412print
'</div><div class="fichetwothirdright">';
416print
'<table class="border centpercent"><tr class="pair nohover"><td align="center">';
426print
'</td></tr></table>';
430print
'<div class="clearboth"></div>';
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
const STATUS_SHIPMENTONPROCESS
Shipment on process.
const STATUS_CLOSED
Closed (Sent, billed or not)
const STATUS_CANCELED
Canceled status.
const STATUS_DRAFT
Draft status.
const STATUS_VALIDATED
Validated status.
Class to manage order statistics (customer and supplier)
static getDefaultGraphSizeForStats($direction, $defaultsize='')
getDefaultGraphSizeForStats
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='', $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_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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).
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.