New: Statistics support filtering on user.

This commit is contained in:
Laurent Destailleur 2011-06-13 13:42:51 +00:00
parent 455edddd5b
commit f46492befe
8 changed files with 65 additions and 42 deletions

View File

@ -35,27 +35,32 @@ include_once DOL_DOCUMENT_ROOT . "/comm/propal/class/propal.class.php";
*/ */
class PropaleStats extends Stats class PropaleStats extends Stats
{ {
var $db ; var $db;
var $socid; var $socid;
var $where; var $userid;
var $table_element; var $table_element;
var $field; var $from;
var $field;
var $where;
/** /**
* Constructor * Constructor
* *
* @param $DB Database handler * @param $DB Database handler
* @param $socid Id third party * @param $socid Id third party
* @param $userid Id user for filter
* @return PropaleStats * @return PropaleStats
*/ */
function PropaleStats($DB, $socid=0) function PropaleStats($DB, $socid=0, $userid=0)
{ {
global $user, $conf; global $user, $conf;
$this->db = $DB; $this->db = $DB;
$this->socid = $socid;
$this->userid = $userid;
$object=new Propal($this->db); $object=new Propal($this->db);
@ -64,7 +69,6 @@ class PropaleStats extends Stats
$this->field='total'; $this->field='total';
$this->socid = $socid;
$this->where.= " fk_statut > 0"; $this->where.= " fk_statut > 0";
$this->where.= " AND p.fk_soc = s.rowid AND s.entity = ".$conf->entity; $this->where.= " AND p.fk_soc = s.rowid AND s.entity = ".$conf->entity;
if (!$user->rights->societe->client->voir && !$user->societe_id) $this->where .= " AND p.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id; if (!$user->rights->societe->client->voir && !$user->societe_id) $this->where .= " AND p.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
@ -72,6 +76,7 @@ class PropaleStats extends Stats
{ {
$this->where .= " AND p.fk_soc = ".$this->socid; $this->where .= " AND p.fk_soc = ".$this->socid;
} }
if ($this->userid > 0) $this->where.=' AND fk_user_author = '.$this->userid;
} }

View File

@ -60,7 +60,7 @@ $dir=$conf->propale->dir_temp;
create_exdir($dir); create_exdir($dir);
$stats = new PropaleStats($db, $socid); $stats = new PropaleStats($db, $socid, $userid);
// Build graphic number of object // Build graphic number of object
$data = $stats->getNbByMonthWithPrevYear($endyear,$startyear); $data = $stats->getNbByMonthWithPrevYear($endyear,$startyear);

View File

@ -38,27 +38,31 @@ class CommandeStats extends Stats
var $db ; var $db ;
var $socid; var $socid;
var $where; var $userid;
var $table_element; var $table_element;
var $from;
var $field; var $field;
var $where;
/** /**
* Constructor * Constructor
* *
* @param $DB Database handler * @param $DB Database handler
* @param $socid Id third party * @param $socid Id third party for filter
* @param $mode Option * @param $mode Option
* @param $userid Id user for filter
* @return CommandeStats * @return CommandeStats
*/ */
function CommandeStats($DB, $socid=0, $mode) function CommandeStats($DB, $socid=0, $mode, $userid=0)
{ {
global $user, $conf; global $user, $conf;
$this->db = $DB; $this->db = $DB;
$this->socid = $socid; $this->socid = $socid;
$this->userid = $userid;
if ($mode == 'customer') if ($mode == 'customer')
{ {
@ -83,7 +87,7 @@ class CommandeStats extends Stats
{ {
$this->where .= " AND c.fk_soc = ".$this->socid; $this->where .= " AND c.fk_soc = ".$this->socid;
} }
if ($this->userid > 0) $this->where.=' AND c.fk_user_author = '.$this->userid;
} }
/** /**

View File

@ -50,6 +50,7 @@ $year = strftime("%Y", time());
$startyear=$year-2; $startyear=$year-2;
$endyear=$year; $endyear=$year;
$langs->load("orders");
/* /*
@ -73,7 +74,7 @@ print_fiche_titre($title, $mesg);
create_exdir($dir); create_exdir($dir);
$stats = new CommandeStats($db, $socid, $mode); $stats = new CommandeStats($db, $socid, $mode, $userid);
// Build graphic number of object // Build graphic number of object
$data = $stats->getNbByMonthWithPrevYear($endyear,$startyear); $data = $stats->getNbByMonthWithPrevYear($endyear,$startyear);

View File

@ -33,38 +33,43 @@ include_once DOL_DOCUMENT_ROOT . "/compta/deplacement/class/deplacement.class.ph
*/ */
class DeplacementStats extends Stats class DeplacementStats extends Stats
{ {
var $db ; var $db;
var $socid; var $socid;
var $where; var $userid;
var $table_element; var $table_element;
var $field; var $from;
var $field;
var $where;
/** /**
* Constructor * Constructor
* *
* @param $DB Database handler * @param $DB Database handler
* @param $socid Id third party * @param $socid Id third party
* @param $userid Id user for filter
* @return DeplacementStats * @return DeplacementStats
*/ */
function DeplacementStats($DB, $socid=0) function DeplacementStats($DB, $socid=0, $userid=0)
{ {
global $conf; global $conf;
$this->db = $DB; $this->db = $DB;
$this->socid = $socid;
$this->userid = $userid;
$object=new Deplacement($this->db); $object=new Deplacement($this->db);
$this->from = MAIN_DB_PREFIX.$object->table_element; $this->from = MAIN_DB_PREFIX.$object->table_element;
$this->field='km'; $this->field='km';
$this->socid = $socid;
$this->where = " fk_statut > 0"; $this->where = " fk_statut > 0";
$this->where.= " AND entity = ".$conf->entity; $this->where.= " AND entity = ".$conf->entity;
if ($this->socid) if ($this->socid)
{ {
$this->where.=" AND fk_soc = ".$this->socid; $this->where.=" AND fk_soc = ".$this->socid;
} }
if ($this->userid > 0) $this->where.=' AND fk_user_author = '.$this->userid;
} }

View File

@ -63,7 +63,7 @@ print_fiche_titre($title, $mesg);
create_exdir($dir); create_exdir($dir);
$stats = new DeplacementStats($db, $socid); $stats = new DeplacementStats($db, $socid, $userid);
// Build graphic number of object // Build graphic number of object

View File

@ -35,27 +35,34 @@ include_once DOL_DOCUMENT_ROOT . "/lib/date.lib.php";
*/ */
class FactureStats extends Stats class FactureStats extends Stats
{ {
var $db ; var $db;
var $socid; var $socid;
var $where; var $userid;
var $table_element;
var $from;
var $field;
var $where;
var $table_element;
var $field;
/** /**
* Constructor * Constructor
* *
* @param $DB Database handler * @param $DB Database handler
* @param $socid Id third party * @param $socid Id third party
* @param $mode Option * @param $mode Option
* @param $userid Id user for filter
* @return FactureStats * @return FactureStats
*/ */
function FactureStats($DB, $socid=0, $mode) function FactureStats($DB, $socid=0, $mode, $userid=0)
{ {
global $conf; global $conf;
$this->db = $DB; $this->db = $DB;
$this->socid = $socid;
$this->userid = $userid;
if ($mode == 'customer') if ($mode == 'customer')
{ {
$object=new Facture($this->db); $object=new Facture($this->db);
@ -69,7 +76,6 @@ class FactureStats extends Stats
$this->field='total_ht'; $this->field='total_ht';
} }
$this->socid = $socid;
$this->where = " fk_statut > 0"; $this->where = " fk_statut > 0";
$this->where.= " AND entity = ".$conf->entity; $this->where.= " AND entity = ".$conf->entity;
if ($mode == 'customer') $this->where.=" AND (fk_statut != 3 OR close_code != 'replaced')"; // Exclude replaced invoices as they are duplicated (we count closed invoices for other reasons) if ($mode == 'customer') $this->where.=" AND (fk_statut != 3 OR close_code != 'replaced')"; // Exclude replaced invoices as they are duplicated (we count closed invoices for other reasons)
@ -77,7 +83,7 @@ class FactureStats extends Stats
{ {
$this->where.=" AND fk_soc = ".$this->socid; $this->where.=" AND fk_soc = ".$this->socid;
} }
if ($this->userid > 0) $this->where.=' AND fk_user_author = '.$this->userid;
} }

View File

@ -31,11 +31,13 @@ require_once(DOL_DOCUMENT_ROOT."/compta/facture/class/facturestats.class.php");
$WIDTH=500; $WIDTH=500;
$HEIGHT=200; $HEIGHT=200;
// Securite acces client $userid=GETPOST('userid');
$socid=GETPOST('socid');
// Security check
if ($user->societe_id > 0) if ($user->societe_id > 0)
{ {
$action = ''; $action = '';
$socid = $user->societe_id; $socid = $user->societe_id;
} }
$year = strftime("%Y", time()); $year = strftime("%Y", time());
@ -67,7 +69,7 @@ print_fiche_titre($title, $mesg);
create_exdir($dir); create_exdir($dir);
$stats = new FactureStats($db, $socid, $mode); $stats = new FactureStats($db, $socid, $mode, $userid);
// Build graphic number of object // Build graphic number of object