dolibarr/htdocs/commande/stats/month.php

196 lines
6.4 KiB
PHP
Raw Normal View History

<?php
2003-11-09 18:32:09 +01:00
/* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
2008-09-08 15:32:37 +02:00
* Copyright (c) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net>
2003-11-09 18:32:09 +01:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/**
2008-09-08 15:32:37 +02:00
* \file htdocs/commande/stats/month.php
* \ingroup commande
* \brief Page des stats commandes par mois
* \version $Id$
*/
2003-11-09 18:32:09 +01:00
require("./pre.inc.php");
require_once(DOL_DOCUMENT_ROOT."/commande/commande.class.php");
require_once(DOL_DOCUMENT_ROOT."/commande/stats/commandestats.class.php");
require_once(DOL_DOCUMENT_ROOT."/core/dolgraph.class.php");
2003-11-09 18:32:09 +01:00
2008-09-08 15:32:37 +02:00
$GRAPHWIDTH=500;
$GRAPHHEIGHT=200;
// Check security access
if ($user->societe_id > 0)
{
$action = '';
$socid = $user->societe_id;
}
$year = isset($_GET["year"])?$_GET["year"]:date("Y",time());
2008-09-08 15:32:37 +02:00
$mode='customer';
if (isset($_GET["mode"])) $mode=$_GET["mode"];
2003-11-09 18:32:09 +01:00
2003-11-09 18:32:09 +01:00
/*
2008-09-08 15:32:37 +02:00
* View
2003-11-09 18:32:09 +01:00
*/
2008-09-08 15:32:37 +02:00
llxHeader();
2003-11-09 18:32:09 +01:00
2008-09-08 15:32:37 +02:00
if ($mode == 'customer')
{
$title=$langs->trans("OrdersStatistics");
$dir=$conf->commande->dir_temp;
}
if ($mode == 'supplier')
{
$title=$langs->trans("OrdersStatisticsSuppliers");
$dir=$conf->fournisseur->commande->dir_temp;
}
$mesg = '<a href="month.php?year='.($year - 1).'&amp;mode='.$mode.'">'.img_previous().'</a> ';
$mesg.= $langs->trans("Year")." $year";
$mesg.= ' <a href="month.php?year='.($year + 1).'&amp;mode='.$mode.'">'.img_next().'</a>';
print_fiche_titre($title, $mesg);
create_exdir($dir);
2003-11-09 18:32:09 +01:00
2008-09-08 15:32:37 +02:00
$stats = new CommandeStats($db, $socid, $mode);
2008-09-08 15:32:37 +02:00
$data = $stats->getNbByMonth($year);
2008-03-01 02:26:41 +01:00
if (!$user->rights->societe->client->voir || $user->societe_id)
{
2008-09-08 15:32:37 +02:00
$filename = $dir.'/ordersnb-'.$user->id.'-'.$year.'.png';
2008-09-08 21:04:19 +02:00
if ($mode == 'customer') $fileurl = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersnb-'.$user->id.'-'.$year.'.png';
if ($mode == 'supplier') $fileurl = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersnb-'.$user->id.'-'.$year.'.png';
}
else
{
2008-09-08 15:32:37 +02:00
$filename = $dir.'/ordersnb-'.$year.'.png';
2008-09-08 21:04:19 +02:00
if ($mode == 'customer') $fileurl = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersnb-'.$year.'.png';
if ($mode == 'supplier') $fileurl = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersnb-'.$year.'.png';
}
2003-11-09 18:32:09 +01:00
$px = new DolGraph();
$mesg = $px->isGraphKo();
if (! $mesg)
{
$px->SetData($data);
$px->SetMaxValue($px->GetCeilMaxValue());
2008-09-08 15:32:37 +02:00
$px->SetMinValue($px->GetFloorMinValue());
$px->SetWidth($GRAPHWIDTH);
$px->SetHeight($GRAPHHEIGHT);
$px->SetYLabel($langs->trans("NbOfOrders"));
2007-12-21 04:34:32 +01:00
$px->SetShading(3);
$px->SetHorizTickIncrement(1);
$px->SetPrecisionY(0);
$px->draw($filename);
}
2003-11-16 17:47:50 +01:00
2003-11-09 18:32:09 +01:00
2008-09-08 15:32:37 +02:00
$data = $stats->getAmountByMonth($year);
2003-11-09 18:32:09 +01:00
2008-03-01 02:26:41 +01:00
if (!$user->rights->societe->client->voir || $user->societe_id)
{
2008-09-08 15:32:37 +02:00
$filename_amount = $dir.'/ordersamount-'.$user->id.'-'.$year.'.png';
2008-09-08 21:04:19 +02:00
if ($mode == 'customer') $fileurl_amount = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersamount-'.$user->id.'-'.$year.'.png';
if ($mode == 'supplier') $fileurl_amount = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersamount-'.$user->id.'-'.$year.'.png';
}
else
{
2008-09-08 15:32:37 +02:00
$filename_amount = $dir.'/ordersamount-'.$year.'.png';
2008-09-08 21:04:19 +02:00
if ($mode == 'customer') $fileurl_amount = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersamount-'.$year.'.png';
if ($mode == 'supplier') $fileurl_amount = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersamount-'.$year.'.png';
}
2003-11-09 18:32:09 +01:00
$px = new DolGraph();
$mesg = $px->isGraphKo();
if (! $mesg)
{
$px->SetData($data);
$px->SetYLabel($langs->trans("AmountTotal"));
2008-09-08 15:32:37 +02:00
$px->SetMaxValue($px->GetCeilMaxValue());
$px->SetMinValue($px->GetFloorMinValue());
$px->SetWidth($GRAPHWIDTH);
$px->SetHeight($GRAPHHEIGHT);
$px->SetShading(3);
$px->SetHorizTickIncrement(1);
$px->SetPrecisionY(0);
$px->draw($filename_amount);
}
$res = $stats->getAverageByMonth($year);
2003-11-09 18:32:09 +01:00
$data = array();
for ($i = 1 ; $i < 13 ; $i++)
{
$data[$i-1] = array(ucfirst(substr(strftime("%b",dolibarr_mktime(12,12,12,$i,1,$year)),0,3)), $res[$i]);
2003-11-09 18:32:09 +01:00
}
2008-03-01 02:26:41 +01:00
if (!$user->rights->societe->client->voir || $user->societe_id)
{
2008-09-08 15:32:37 +02:00
$filename_avg = $dir.'/ordersaverage-'.$user->id.'-'.$year.'.png';
2008-09-08 21:04:19 +02:00
if ($mode == 'customer') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$user->id.'-'.$year.'.png';
if ($mode == 'supplier') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$user->id.'-'.$year.'.png';
}
else
{
2008-09-08 15:32:37 +02:00
$filename_avg = $dir.'/ordersaverage-'.$year.'.png';
2008-09-08 21:04:19 +02:00
if ($mode == 'customer') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$year.'.png';
if ($mode == 'supplier') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$year.'.png';
}
$px = new DolGraph();
$mesg = $px->isGraphKo();
if (! $mesg)
{
$px->SetData($data);
$px->SetYLabel($langs->trans("AmountAverage"));
2008-09-08 15:32:37 +02:00
$px->SetMaxValue($px->GetCeilMaxValue());
$px->SetMinValue($px->GetFloorMinValue());
$px->SetWidth($GRAPHWIDTH);
$px->SetHeight($GRAPHHEIGHT);
$px->SetShading(3);
$px->SetHorizTickIncrement(1);
$px->SetPrecisionY(0);
$px->draw($filename_avg);
}
2003-11-09 18:32:09 +01:00
print '<table class="border" width="100%">';
print '<tr><td align="center">'.$langs->trans("NumberOfOrdersByMonth").'</td>';
2003-11-09 18:32:09 +01:00
print '<td align="center">';
if ($mesg) { print $mesg; }
else { print '<img src="'.$fileurl.'">'; }
2003-11-09 18:32:09 +01:00
print '</td></tr>';
print '<tr><td align="center">'.$langs->trans("AmountTotal").'</td>';
2003-11-09 18:32:09 +01:00
print '<td align="center">';
if ($mesg) { print $mesg; }
else { print '<img src="'.$fileurl_amount.'">'; }
2003-11-09 18:32:09 +01:00
print '</td></tr>';
print '<tr><td align="center">'.$langs->trans("AmountAverage").'</td>';
2003-11-09 18:32:09 +01:00
print '<td align="center">';
if ($mesg) { print $mesg; }
else { print '<img src="'.$fileurl_avg.'">'; }
2003-11-09 18:32:09 +01:00
print '</td></tr></table>';
$db->close();
llxFooter('$Date$ - $Revision$');
2003-11-09 18:32:09 +01:00
?>