30 require
'../../main.inc.php';
31 require_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
32 require_once DOL_DOCUMENT_ROOT.
'/commande/class/commandestats.class.php';
33 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
34 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formorder.class.php';
35 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
36 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
37 require_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
43 if ($mode ==
'customer' && !$user->rights->commande->lire) {
46 if ($mode ==
'supplier' && empty($user->rights->fournisseur->commande->lire)) {
49 if ($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');
63 if ($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;
90 if ($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));
103 if ($mode ==
'customer') {
104 if ($object_status !=
'' && $object_status >= -1) {
105 $stats->where .=
' AND c.fk_statut IN ('.$db->sanitize($object_status).
')';
108 if ($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);
122 if (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);
168 if (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);
212 if (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();
258 foreach ($data as $val) {
259 if (!empty($val[
'year'])) {
260 $arrayyears[$val[
'year']] = $val[
'year'];
263 if (!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';
274 if ($mode ==
'customer') {
275 $type =
'order_stats';
277 if ($mode ==
'supplier') {
278 $type =
'supplier_order_stats';
286 print
'<div class="fichecenter"><div class="fichethirdleft">';
290 print
'<form name="stats" method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
291 print
'<input type="hidden" name="token" value="'.newToken().
'">';
292 print
'<input type="hidden" name="mode" value="'.$mode.
'">';
294 print
'<table class="noborder centpercent">';
295 print
'<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans(
"Filter").
'</td></tr>';
297 print
'<tr><td class="left">'.$langs->trans(
"ThirdParty").
'</td><td class="left">';
298 if ($mode ==
'customer') {
299 $filter =
's.client IN (1,2,3)';
301 if ($mode ==
'supplier') {
302 $filter =
's.fournisseur = 1';
304 print
img_picto(
'',
'company',
'class="pictofixedwidth"');
305 print
$form->select_company($socid,
'socid', $filter, 1, 0, 0, array(), 0,
'widthcentpercentminusx maxwidth300');
308 print
'<tr><td>'.$langs->trans(
"ThirdPartyType").
'</td><td>';
309 $sortparam_typent = (empty($conf->global->SOCIETE_SORT_ON_TYPEENT) ?
'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT);
310 print
$form->selectarray(
"typent_id", $formcompany->typent_array(0), $typent_id, 1, 0, 0,
'', 0, 0, 0, $sortparam_typent,
'', 1);
312 print
' '.info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
316 if ($mode ==
'customer') {
317 $cat_type = Categorie::TYPE_CUSTOMER;
318 $cat_label = $langs->trans(
"Category").
' '.lcfirst($langs->trans(
"Customer"));
320 if ($mode ==
'supplier') {
321 $cat_type = Categorie::TYPE_SUPPLIER;
322 $cat_label = $langs->trans(
"Category").
' '.lcfirst($langs->trans(
"Supplier"));
324 print
'<tr><td>'.$cat_label.
'</td><td>';
325 print
img_picto(
'',
'category',
'class="pictofixedwidth"');
326 print $formother->select_categories($cat_type, $categ_id,
'categ_id', 0, 1,
'widthcentpercentminusx maxwidth300');
329 print
'<tr><td>'.$langs->trans(
"CreatedBy").
'</td><td>';
330 print
img_picto(
'',
'user',
'class="pictofixedwidth"');
331 print
$form->select_dolusers($userid,
'userid', 1,
'', 0,
'',
'', 0, 0, 0,
'', 0,
'',
'widthcentpercentminusx maxwidth300');
333 print
'<tr><td>'.$langs->trans(
"Status").
'</td><td>';
334 if ($mode ==
'customer') {
342 print
$form->selectarray(
'object_status', $liststatus,
GETPOST(
'object_status',
'intcomma'), -4);
344 if ($mode ==
'supplier') {
345 $formorder->selectSupplierOrderStatus((strstr($object_status,
',') ? -1 : $object_status), 0,
'object_status');
349 print
'<tr><td class="left">'.$langs->trans(
"Year").
'</td><td class="left">';
350 if (!in_array($year, $arrayyears)) {
351 $arrayyears[$year] = $year;
353 if (!in_array($nowyear, $arrayyears)) {
354 $arrayyears[$nowyear] = $nowyear;
357 print
$form->selectarray(
'year', $arrayyears, $year, 0, 0, 0,
'', 0, 0, 0,
'',
'width75');
359 print
'<tr><td align="center" colspan="2"><input type="submit" class="button small" name="submit" value="'.$langs->trans(
"Refresh").
'"></td></tr>';
365 print
'<div class="div-table-responsive-no-min">';
366 print
'<table class="noborder centpercent">';
367 print
'<tr class="liste_titre" height="24">';
368 print
'<td class="center">'.$langs->trans(
"Year").
'</td>';
369 print
'<td class="right">'.$langs->trans(
"NbOfOrders").
'</td>';
370 print
'<td class="right">%</td>';
371 print
'<td class="right">'.$langs->trans(
"AmountTotal").
'</td>';
372 print
'<td class="right">%</td>';
373 print
'<td class="right">'.$langs->trans(
"AmountAverage").
'</td>';
374 print
'<td class="right">%</td>';
378 foreach ($data as $val) {
379 $year = $val[
'year'];
380 while (!empty($year) && $oldyear > $year + 1) {
383 print
'<tr class="oddeven" height="24">';
384 print
'<td align="center"><a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$oldyear.
'&mode='.$mode.($socid > 0 ?
'&socid='.$socid :
'').($userid > 0 ?
'&userid='.$userid :
'').
'">'.$oldyear.
'</a></td>';
385 print
'<td class="right">0</td>';
386 print
'<td class="right"></td>';
387 print
'<td class="right">0</td>';
388 print
'<td class="right"></td>';
389 print
'<td class="right">0</td>';
390 print
'<td class="right"></td>';
395 print
'<tr class="oddeven" height="24">';
396 print
'<td align="center"><a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$year.
'&mode='.$mode.($socid > 0 ?
'&socid='.$socid :
'').($userid > 0 ?
'&userid='.$userid :
'').
'">'.$year.
'</a></td>';
397 print
'<td class="right">'.$val[
'nb'].
'</td>';
398 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>';
399 print
'<td class="right">'.price(
price2num($val[
'total'],
'MT'), 1).
'</td>';
400 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>';
401 print
'<td class="right">'.price(
price2num($val[
'avg'],
'MT'), 1).
'</td>';
402 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>';
411 print
'</div><div class="fichetwothirdright">';
415 print
'<table class="border centpercent"><tr class="pair nohover"><td align="center">';
425 print
'</td></tr></table>';
428 print
'</div></div>';
429 print
'<div style="clear:both"></div>';
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
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
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.
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.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
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)
if(!defined('NOTOKENRENEWAL')) if(!defined('NOLOGIN')) if(!defined('NOCSRFCHECK')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) if(!defined('NOIPCHECK')) if(!defined('NOBROWSERNOTIF')) llxHeader()
Header empty.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.