Add supplier orders statistics report

This commit is contained in:
Laurent Destailleur 2008-09-08 19:04:19 +00:00
parent 9fc942ccec
commit 1249eac510
9 changed files with 72 additions and 28 deletions

View File

@ -25,6 +25,7 @@
*/
include_once DOL_DOCUMENT_ROOT . "/stats.class.php";
include_once DOL_DOCUMENT_ROOT . "/commande/commande.class.php";
include_once DOL_DOCUMENT_ROOT . "/fourn/fournisseur.commande.class.php";
/**
@ -47,20 +48,32 @@ class CommandeStats extends Stats
*
* @param $DB Database handler
* @param $socid Id third party
* @param $mode Option
* @return PropaleStats
*/
function CommandeStats($DB, $socid=0)
function CommandeStats($DB, $socid=0, $mode)
{
global $user;
$this->db = $DB;
$object=new Commande($this->db);
$this->table_element=$object->table_element;
$this->field='total_ht';
$this->socid = $socid;
$this->where.= " c.fk_statut > 0";
if ($mode == 'customer')
{
$object=new Commande($this->db);
$this->table_element=$object->table_element;
$this->field='total_ht';
$this->where.= " c.fk_statut > 0";
}
if ($mode == 'supplier')
{
$object=new CommandeFournisseur($this->db);
$this->table_element=$object->table_element;
$this->field='total_ht';
$this->where.= " c.fk_statut >= 3 AND c.date_commande IS NOT NULL";
}
if (!$user->rights->societe->client->voir && !$this->socid) $this->where .= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
if($this->socid)
{
@ -153,7 +166,7 @@ class CommandeStats extends Stats
{
global $user;
$sql = "SELECT date_format(c.date_commande,'%Y') as year, count(*) as nb, sum(".$this->field.") as total, avg(".$this->field.") as avg";
$sql = "SELECT date_format(c.date_commande,'%Y') as year, count(*) as nb, sum(c.".$this->field.") as total, avg(".$this->field.") as avg";
if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", sc.fk_soc, sc.fk_user";
$sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element." as c";
if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";

View File

@ -45,19 +45,31 @@ $year = strftime("%Y", time());
$startyear=$year-2;
$endyear=$year;
$mode='customer';
if (isset($_GET["mode"])) $mode=$_GET["mode"];
/*
* View
*/
llxHeader();
print_fiche_titre($langs->trans("OrdersStatistics"), $mesg);
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;
}
$dir=$conf->commande->dir_temp;
print_fiche_titre($title, $mesg);
create_exdir($dir);
$stats = new CommandeStats($db, $socid);
$stats = new CommandeStats($db, $socid, $mode);
// Build graphic number of object
$data = $stats->getNbByMonthWithPrevYear($endyear,$startyear);
@ -68,12 +80,14 @@ $data = $stats->getNbByMonthWithPrevYear($endyear,$startyear);
if (!$user->rights->societe->client->voir || $user->societe_id)
{
$filenamenb = $dir.'/ordersnbinyear-'.$user->id.'-'.$year.'.png';
$fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersnbinyear-'.$user->id.'-'.$year.'.png';
if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersnbinyear-'.$user->id.'-'.$year.'.png';
if ($mode == 'supplier') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersnbinyear-'.$user->id.'-'.$year.'.png';
}
else
{
$filenamenb = $dir.'/ordersnbinyear-'.$year.'.png';
$fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersnbinyear-'.$year.'.png';
if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersnbinyear-'.$year.'.png';
if ($mode == 'supplier') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersnbinyear-'.$year.'.png';
}
$px = new DolGraph();
@ -110,12 +124,14 @@ $data = $stats->getAmountByMonthWithPrevYear($endyear,$startyear);
if (!$user->rights->societe->client->voir || $user->societe_id)
{
$filenameamount = $dir.'/ordersamountinyear-'.$user->id.'-'.$year.'.png';
$fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersamountinyear-'.$user->id.'-'.$year.'.png';
if ($mode == 'customer') $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersamountinyear-'.$user->id.'-'.$year.'.png';
if ($mode == 'supplier') $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersamountinyear-'.$user->id.'-'.$year.'.png';
}
else
{
$filenameamount = $dir.'/ordersamountinyear-'.$year.'.png';
$fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersamountinyear-'.$year.'.png';
if ($mode == 'customer') $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersamountinyear-'.$year.'.png';
if ($mode == 'supplier') $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersamountinyear-'.$year.'.png';
}
$px = new DolGraph();
@ -123,7 +139,6 @@ $mesg = $px->isGraphKo();
if (! $mesg)
{
$px->SetData($data);
$px->SetPrecisionY(0);
$i=$startyear;
while ($i <= $endyear)
{
@ -163,8 +178,7 @@ $oldyear=0;
foreach ($data as $val)
{
$year = $val['year'];
print $avg;
while ($oldyear > $year+1)
while ($year && $oldyear > $year+1)
{ // If we have empty year
$oldyear--;
print '<tr height="24">';
@ -175,7 +189,7 @@ foreach ($data as $val)
print '</tr>';
}
print '<tr height="24">';
print '<td align="center"><a href="month.php?year='.$year.'">'.$year.'</a></td>';
print '<td align="center"><a href="month.php?year='.$year.'&amp;mode='.$mode.'">'.$year.'</a></td>';
print '<td align="right">'.$val['nb'].'</td>';
print '<td align="right">'.price(price2num($val['total'],'MT'),1).'</td>';
print '<td align="right">'.price(price2num($val['avg'],'MT'),1).'</td>';

View File

@ -77,12 +77,14 @@ $data = $stats->getNbByMonth($year);
if (!$user->rights->societe->client->voir || $user->societe_id)
{
$filename = $dir.'/ordersnb-'.$user->id.'-'.$year.'.png';
$fileurl = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersnb-'.$user->id.'-'.$year.'.png';
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
{
$filename = $dir.'/ordersnb-'.$year.'.png';
$fileurl = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersnb-'.$year.'.png';
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';
}
$px = new DolGraph();
@ -107,12 +109,14 @@ $data = $stats->getAmountByMonth($year);
if (!$user->rights->societe->client->voir || $user->societe_id)
{
$filename_amount = $dir.'/ordersamount-'.$user->id.'-'.$year.'.png';
$fileurl_amount = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersamount-'.$user->id.'-'.$year.'.png';
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
{
$filename_amount = $dir.'/ordersamount-'.$year.'.png';
$fileurl_amount = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersamount-'.$year.'.png';
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';
}
$px = new DolGraph();
@ -142,12 +146,14 @@ for ($i = 1 ; $i < 13 ; $i++)
if (!$user->rights->societe->client->voir || $user->societe_id)
{
$filename_avg = $dir.'/ordersaverage-'.$user->id.'-'.$year.'.png';
$fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$user->id.'-'.$year.'.png';
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
{
$filename_avg = $dir.'/ordersaverage-'.$year.'.png';
$fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$year.'.png';
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();

View File

@ -118,7 +118,6 @@ $mesg = $px->isGraphKo();
if (! $mesg)
{
$px->SetData($data);
$px->SetPrecisionY(0);
$i=$startyear;
while ($i <= $endyear)
{
@ -160,8 +159,7 @@ $oldyear=0;
foreach ($data as $val)
{
$year = $val['year'];
print $avg;
while ($oldyear > $year+1)
while ($year && $oldyear > $year+1)
{ // If we have empty year
$oldyear--;
print '<tr height="24">';

View File

@ -334,6 +334,7 @@ class MenuLeft {
$newmenu->add(DOL_URL_ROOT."/fourn/commande/index.php?leftmenu=orders_suppliers",$langs->trans("SuppliersOrders"), 0, $user->rights->fournisseur->commande->lire);
if ($leftmenu=="orders_suppliers") $newmenu->add_submenu(DOL_URL_ROOT."/societe.php?leftmenu=orders_suppliers", $langs->trans("NewOrder"), 1, $user->rights->fournisseur->commande->creer);
if ($leftmenu=="orders_suppliers") $newmenu->add_submenu(DOL_URL_ROOT."/fourn/commande/liste.php?leftmenu=orders_suppliers", $langs->trans("List"), 1, $user->rights->fournisseur->commande->lire);
if ($leftmenu=="orders_suppliers") $newmenu->add_submenu(DOL_URL_ROOT."/commande/stats/index.php?leftmenu=orders_suppliers&amp;mode=supplier", $langs->trans("Statistics"), 1 ,$user->rights->fournisseur->commande->lire);
}
// Contrat

View File

@ -316,6 +316,7 @@ class MenuLeft {
$newmenu->add(DOL_URL_ROOT."/fourn/commande/index.php?leftmenu=orders_suppliers",$langs->trans("SuppliersOrders"), 0, $user->rights->fournisseur->commande->lire);
if ($leftmenu=="orders_suppliers") $newmenu->add_submenu(DOL_URL_ROOT."/societe.php?leftmenu=orders_suppliers", $langs->trans("NewOrder"), 1, $user->rights->fournisseur->commande->creer);
if ($leftmenu=="orders_suppliers") $newmenu->add_submenu(DOL_URL_ROOT."/fourn/commande/liste.php?leftmenu=orders_suppliers", $langs->trans("List"), 1, $user->rights->fournisseur->commande->lire);
if ($leftmenu=="orders_suppliers") $newmenu->add_submenu(DOL_URL_ROOT."/commande/stats/index.php?leftmenu=orders_suppliers&amp;mode=supplier", $langs->trans("Statistics"), 1 ,$user->rights->fournisseur->commande->lire);
}
// Contrat

View File

@ -68,6 +68,7 @@ LastClosedOrders=Last %s closed orders
AllOrders=All orders
NbOfOrders=Number of orders
OrdersStatistics=Orders' statistics
OrdersStatisticsSuppliers=Supplier orders' statistics
NumberOfOrdersByMonth=Number of orders by month
AmountOfOrdersByMonthHT=amount of orders by month (net of tax)
ListOfOrders=List of orders

View File

@ -68,6 +68,7 @@ LastClosedOrders=Les %s derni
AllOrders=Toutes les commandes
NbOfOrders=Nombre de commandes
OrdersStatistics=Statistiques des commandes
OrdersStatisticsSuppliers=Statistiques des commandes fournisseurs
NumberOfOrdersByMonth=Nombre de commandes par mois
AmountOfOrdersByMonthHT=Montant total de commandes par mois (HT)
ListOfOrders=Liste des commandes

View File

@ -156,7 +156,16 @@ if ($modulepart)
}
$original_file=$conf->commande->dir_temp.'/'.$original_file;
}
elseif ($modulepart == 'orderstatssupplier')
{
$user->getrights('fournisseur');
if ($user->rights->fournisseur->commande->lire)
{
$accessallowed=1;
}
$original_file=$conf->fournisseur->commande->dir_temp.'/'.$original_file;
}
// Wrapping pour les images des stats factures
elseif ($modulepart == 'billstats')
{