diff --git a/htdocs/donations/class/donationstats.class.php b/htdocs/donations/class/donationstats.class.php index 74fd4d3d6f1..b26617d651b 100644 --- a/htdocs/donations/class/donationstats.class.php +++ b/htdocs/donations/class/donationstats.class.php @@ -63,19 +63,14 @@ class DonationStats extends Stats $this->cachefilesuffix = $mode; $object=new Don($this->db); - $this->from = MAIN_DB_PREFIX.$object->table_element." as c"; + $this->from = MAIN_DB_PREFIX.$object->table_element." as d"; //$this->from.= ", ".MAIN_DB_PREFIX."societe as s"; //$this->field='weight'; // Warning, unit of weight is NOT USED AND MUST BE - $this->where.= " c.fk_statut > 0"; // Not draft and not cancelled + $this->where.= " d.fk_statut > 0"; // Not draft and not cancelled //$this->where.= " AND c.fk_soc = s.rowid AND c.entity = ".$conf->entity; - $this->where.= " AND c.entity = ".$conf->entity; - 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) - { - $this->where.=" AND c.fk_soc = ".$this->socid; - } - if ($this->userid > 0) $this->where.=' AND c.fk_user_author = '.$this->userid; + $this->where.= " AND d.entity = ".$conf->entity; + if ($this->userid > 0) $this->where.=' WHERE c.fk_user_author = '.$this->userid; } /** @@ -88,10 +83,9 @@ class DonationStats extends Stats { global $user; - $sql = "SELECT date_format(c.date_valid,'%m') as dm, COUNT(*) as nb"; + $sql = "SELECT date_format(d.datedon,'%m') as dm, COUNT(*) as nb"; $sql.= " FROM ".$this->from; - if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; - $sql.= " WHERE c.date_valid BETWEEN '".$this->db->idate(dol_get_first_day($year))."' AND '".$this->db->idate(dol_get_last_day($year))."'"; + $sql.= " WHERE d.datedon BETWEEN '".$this->db->idate(dol_get_first_day($year))."' AND '".$this->db->idate(dol_get_last_day($year))."'"; $sql.= " AND ".$this->where; $sql.= " GROUP BY dm"; $sql.= $this->db->order('dm','DESC'); @@ -110,9 +104,8 @@ class DonationStats extends Stats { global $user; - $sql = "SELECT date_format(c.date_valid,'%Y') as dm, COUNT(*) as nb, SUM(c.".$this->field.")"; + $sql = "SELECT date_format(d.datedon,'%Y') as dm, COUNT(*) as nb, SUM(d.".$this->field.")"; $sql.= " FROM ".$this->from; - if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE ".$this->where; $sql.= " GROUP BY dm"; $sql.= $this->db->order('dm','DESC'); @@ -129,9 +122,8 @@ class DonationStats extends Stats { global $user; - $sql = "SELECT date_format(c.date_valid,'%Y') as year, COUNT(*) as nb, SUM(c.".$this->field.") as total, AVG(".$this->field.") as avg"; + $sql = "SELECT date_format(d.datedon,'%Y') as year, COUNT(*) as nb, SUM(d.".$this->field.") as total, AVG(".$this->field.") as avg"; $sql.= " FROM ".$this->from; - if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE ".$this->where; $sql.= " GROUP BY year"; $sql.= $this->db->order('year','DESC'); diff --git a/htdocs/donations/stats/index.php b/htdocs/donations/stats/index.php index f6fc43ce90a..0a58751b8ed 100644 --- a/htdocs/donations/stats/index.php +++ b/htdocs/donations/stats/index.php @@ -213,12 +213,12 @@ if (! count($arrayyears)) $arrayyears[$nowyear]=$nowyear; $h=0; $head = array(); -$head[$h][0] = DOL_URL_ROOT . '/commande/stats/index.php?mode='.$mode; +$head[$h][0] = DOL_URL_ROOT . '/donations/stats/index.php?mode='.$mode; $head[$h][1] = $langs->trans("ByMonthYear"); $head[$h][2] = 'byyear'; $h++; -$type='shipment_stats'; +$type='donation_stats'; complete_head_from_modules($conf,$langs,null,$head,$h,$type);