From db6d345e54a7727e89fdf9bf6f7b6ad15327429f Mon Sep 17 00:00:00 2001 From: lmarcouiller Date: Tue, 30 Aug 2022 11:31:20 +0200 Subject: [PATCH] Fix #21810 : Broken statistics in project module --- htdocs/projet/class/projectstats.class.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/htdocs/projet/class/projectstats.class.php b/htdocs/projet/class/projectstats.class.php index 9b2314deacc..f1295c10424 100644 --- a/htdocs/projet/class/projectstats.class.php +++ b/htdocs/projet/class/projectstats.class.php @@ -528,4 +528,22 @@ class ProjectStats extends Stats // var_dump($res);print '
'; return $res; } + + /** + * Return average of entity by month + * @param int $year year number + * @return int value + */ + protected function getAverageByMonth($year) + { + $sql = "SELECT date_format(datef,'%m') as dm, AVG(f.".$this->field.")"; + $sql .= " FROM ".$this->from; + $sql .= $this->join; + $sql .= " WHERE f.datef 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'); + + return $this->_getAverageByMonth($year, $sql); + } }