diff --git a/htdocs/product.class.php b/htdocs/product.class.php index a1c9682b361..2a9ca0ebee8 100644 --- a/htdocs/product.class.php +++ b/htdocs/product.class.php @@ -286,11 +286,15 @@ class Product * * */ - Function count_propale() + Function count_propale($socid=0) { $sql = "SELECT pd.fk_propal"; - $sql .= " FROM ".MAIN_DB_PREFIX."propaldet as pd, ".MAIN_DB_PREFIX."product as p"; - $sql .= " WHERE p.rowid = pd.fk_product AND p.rowid = ".$this->id; + $sql .= " FROM ".MAIN_DB_PREFIX."propaldet as pd, ".MAIN_DB_PREFIX."product as p, ".MAIN_DB_PREFIX."propal as pr"; + $sql .= " WHERE pr.rowid = pd.fk_propal AND p.rowid = pd.fk_product AND p.rowid = ".$this->id; + if ($socid > 0) + { + $sql .= " AND pr.fk_soc = $socid"; + } $sql .= " GROUP BY pd.fk_propal"; $result = $this->db->query($sql) ; @@ -308,11 +312,15 @@ class Product * * */ - Function count_propale_client() + Function count_propale_client($socid=0) { $sql = "SELECT pr.fk_soc"; $sql .= " FROM ".MAIN_DB_PREFIX."propaldet as pd, ".MAIN_DB_PREFIX."product as p, ".MAIN_DB_PREFIX."propal as pr"; $sql .= " WHERE p.rowid = pd.fk_product AND pd.fk_propal = pr.rowid AND p.rowid = ".$this->id; + if ($socid > 0) + { + $sql .= " AND pr.fk_soc = $socid"; + } $sql .= " GROUP BY pr.fk_soc"; $result = $this->db->query($sql) ; @@ -330,11 +338,16 @@ class Product * * */ - Function count_facture() + Function count_facture($socid=0) { $sql = "SELECT pd.fk_facture"; $sql .= " FROM ".MAIN_DB_PREFIX."facturedet as pd, ".MAIN_DB_PREFIX."product as p"; - $sql .= " WHERE p.rowid = pd.fk_product AND p.rowid = ".$this->id; + $sql .= ", ".MAIN_DB_PREFIX."facture as f"; + $sql .= " WHERE f.rowid = pd.fk_facture AND p.rowid = pd.fk_product AND p.rowid = ".$this->id; + if ($socid > 0) + { + $sql .= " AND f.fk_soc = $socid"; + } $sql .= " GROUP BY pd.fk_facture"; $result = $this->db->query($sql) ; @@ -403,11 +416,15 @@ class Product * * */ - Function get_nb_vente() + Function get_nb_vente($socid=0) { $sql = "SELECT sum(d.qty), date_format(f.datef, '%Y%m') "; $sql .= " FROM ".MAIN_DB_PREFIX."facturedet as d, ".MAIN_DB_PREFIX."facture as f"; - $sql .= " WHERE f.rowid = d.fk_facture and f.paye = 1 and d.fk_product =".$this->id; + $sql .= " WHERE f.rowid = d.fk_facture and d.fk_product =".$this->id; + if ($socid > 0) + { + $sql .= " AND f.fk_soc = $socid"; + } $sql .= " GROUP BY date_format(f.datef,'%Y%m') DESC ;"; return $this->_get_stats($sql); @@ -416,11 +433,15 @@ class Product *Renvoie le nombre de facture dans lesquelles figure le produit * */ - Function get_num_vente() + Function get_num_vente($socid=0) { $sql = "SELECT count(*), date_format(f.datef, '%Y%m') "; $sql .= " FROM ".MAIN_DB_PREFIX."facturedet as d, ".MAIN_DB_PREFIX."facture as f"; - $sql .= " WHERE f.rowid = d.fk_facture and f.paye = 1 and d.fk_product =".$this->id; + $sql .= " WHERE f.rowid = d.fk_facture AND d.fk_product =".$this->id; + if ($socid > 0) + { + $sql .= " AND f.fk_soc = $socid"; + } $sql .= " GROUP BY date_format(f.datef,'%Y%m') DESC ;"; return $this->_get_stats($sql); @@ -429,11 +450,15 @@ class Product *Renvoie le nombre de proaple dans lesquelles figure le produit * */ - Function get_num_propal() - { + Function get_num_propal($socid=0) + { $sql = "SELECT count(*), date_format(p.datep, '%Y%m') "; $sql .= " FROM ".MAIN_DB_PREFIX."propaldet as d, ".MAIN_DB_PREFIX."propal as p"; $sql .= " WHERE p.rowid = d.fk_propal and d.fk_product =".$this->id; + if ($socid > 0) + { + $sql .= " AND p.fk_soc = $socid"; + } $sql .= " GROUP BY date_format(p.datep,'%Y%m') DESC ;"; return $this->_get_stats($sql); diff --git a/htdocs/product/stats/facture.php b/htdocs/product/stats/facture.php index 3a98ee07050..e60c4d9861c 100644 --- a/htdocs/product/stats/facture.php +++ b/htdocs/product/stats/facture.php @@ -51,9 +51,9 @@ if ($_GET["id"]) print 'Statistiques'; print "Libellé$product->libelle"; print ''; - print "Propositions commerciales : ".$product->count_propale(); - print "
Proposé à ".$product->count_propale_client()." clients"; - print "
Factures : ".$product->count_facture(); + print "Propositions commerciales : ".$product->count_propale($socid); + print "
Proposé à ".$product->count_propale_client($socid)." clients"; + print "
Factures : ".$product->count_facture($socid); print ''; print 'Prix de vente'.price($product->price).''; print ""; diff --git a/htdocs/product/stats/fiche.php b/htdocs/product/stats/fiche.php index 8ecb6ae7ce3..ca0841d04ce 100644 --- a/htdocs/product/stats/fiche.php +++ b/htdocs/product/stats/fiche.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2001-2004 Rodolphe Quiedeville * Copyright (c) 2004 Laurent Destailleur * * This program is free software; you can redistribute it and/or modify @@ -23,6 +23,17 @@ require("./pre.inc.php"); require("../../propal.class.php"); +if ($user->societe_id > 0) +{ + $action = ''; + $socid = $user->societe_id; +} +else +{ + $socid = 0; +} + + llxHeader(); $mesg = ''; @@ -48,31 +59,29 @@ if ($_GET["id"]) $mesg = "Impossible de créer $dir !"; } } - - $filenbpropal = $dir . "/propal12mois.png"; + $img_propal_name = "propal12mois.png"; + $filenbpropal = $dir . "/" . $img_propal_name; $filenbvente = $dir . "/vente12mois.png"; $filenbpiece = $dir . "/vendu12mois.png"; - if (! file_exists($filenbvente) or $_GET["action"] == 'recalcul') - { + + $px = new BarGraph(); + $mesg = $px->isGraphKo(); + if (! $mesg) + { + $graph_data = $product->get_num_vente($socid); + $px->draw($filenbvente, $graph_data); + $px = new BarGraph(); - $mesg = $px->isGraphKo(); - if (! $mesg) - { - $graph_data = $product->get_num_vente(); - $px->draw($filenbvente, $graph_data); + $graph_data = $product->get_nb_vente($socid); + $px->draw($filenbpiece, $graph_data); + + $px = new BarGraph(); + $graph_data = $product->get_num_propal($socid); + $px->draw($filenbpropal, $graph_data); - $px = new BarGraph(); - $graph_data = $product->get_nb_vente(); - $px->draw($filenbpiece, $graph_data); - - $px = new BarGraph(); - $graph_data = $product->get_num_propal(); - $px->draw($filenbpropal, $graph_data); - - $mesg = "Graphiques générés"; - } - } + $mesg = "Graphiques générés"; + } // Zone recherche print ''; @@ -100,9 +109,9 @@ if ($_GET["id"]) print ''; print ""; print ''; print ''; print "
Statistiques
Libellé$product->libelle'; - print 'Propositions commerciales : '.$product->count_propale(); - print "
Proposé à ".$product->count_propale_client()." clients"; - print '
Factures : '.$product->count_facture(); + print 'Propositions commerciales : '.$product->count_propale($socid); + print "
Proposé à ".$product->count_propale_client($socid)." clients"; + print '
Factures : '.$product->count_facture($socid); print '
Prix actuel'.price($product->price).'
"; @@ -142,7 +151,7 @@ if ($_GET["id"]) print '-'; print ''; - print 'Propales sur les 12 derniers mois'; + print 'Propales sur les 12 derniers mois'; print 'TODO AUTRE GRAPHIQUE'; diff --git a/htdocs/product/stats/propal.php b/htdocs/product/stats/propal.php index 6c5dd59ef35..0354377482b 100644 --- a/htdocs/product/stats/propal.php +++ b/htdocs/product/stats/propal.php @@ -22,6 +22,12 @@ require("./pre.inc.php"); +if ($user->societe_id > 0) +{ + $action = ''; + $socid = $user->societe_id; +} + llxHeader(); $mesg = ''; @@ -45,9 +51,9 @@ if ($_GET["id"]) print 'Statistiques'; print "Libellé$product->libelle"; print ''; - print "Propositions commerciales : ".$product->count_propale(); - print "
Proposé à ".$product->count_propale_client()." clients"; - print "
Factures : ".$product->count_facture(); + print "Propositions commerciales : ".$product->count_propale($socid); + print "
Proposé à ".$product->count_propale_client($socid)." clients"; + print "
Factures : ".$product->count_facture($socid); print ''; print 'Prix de vente'.price($product->price).''; print ""; @@ -73,7 +79,13 @@ if ($_GET["id"]) $sql = "SELECT distinct(p.rowid), s.nom,s.idp, p.ref,".$db->pdate("p.datep")." as df,p.rowid as facid"; $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."propal as p, ".MAIN_DB_PREFIX."propaldet as d WHERE p.fk_soc = s.idp"; $sql .= " AND d.fk_propal = p.rowid AND d.fk_product =".$product->id; - $sql .= " ORDER BY $sortfield $sortorder "; + + if ($socid) + { + $sql .= " AND p.fk_soc = $socid"; + } + + $sql .= " ORDER BY $sortfield $sortorder "; $sql .= $db->plimit( $limit ,$offset); $result = $db->query($sql);