From 6e31609b14ec77cb98757bb3831c469bc3d5276c 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); + } }