diff --git a/htdocs/comm/propal/stats/propalestats.class.php b/htdocs/comm/propal/stats/propalestats.class.php index dcfcf2ee41f..1091213abd4 100644 --- a/htdocs/comm/propal/stats/propalestats.class.php +++ b/htdocs/comm/propal/stats/propalestats.class.php @@ -20,7 +20,9 @@ * */ -class PropaleStats +include_once DOL_DOCUMENT_ROOT . "/stats.class.php"; + +class PropaleStats extends Stats { var $db ; @@ -29,84 +31,29 @@ class PropaleStats $this->db = $DB; } - Function getNbByMonthWithPrevYear($year) - { - $data1 = $this->getNbByMonth($year - 1); - $data2 = $this->getNbByMonth($year); - $data = array(); - - for ($i = 0 ; $i < 12 ; $i++) - { - $data[$i] = array($data1[$i][0], - $data1[$i][1], - $data2[$i][1]); - } - return $data; - } /** * Renvoie le nombre de proposition par mois pour une année donnée * */ Function getNbByMonth($year) { - $result = array(); $sql = "SELECT date_format(datep,'%m') as dm, count(*) FROM llx_propal"; $sql .= " WHERE date_format(datep,'%Y') = $year AND fk_statut > 0"; $sql .= " GROUP BY dm DESC"; - - if ($this->db->query($sql)) - { - $num = $this->db->num_rows(); - $i = 0; - while ($i < $num) - { - $row = $this->db->fetch_row($i); - $j = $row[0] * 1; - $result[$j] = $row[1]; - $i++; - } - $this->db->free(); - } - for ($i = 1 ; $i < 13 ; $i++) - { - $res[$i] = $result[$i] + 0; - } - - $data = array(); - - for ($i = 1 ; $i < 13 ; $i++) - { - $data[$i-1] = array(strftime("%b",mktime(12,12,12,$i,1,$year)), $res[$i]); - } - - return $data; + return $this->_getNbByMonth($year, $sql); } - /** * Renvoie le nombre de propale par année * */ Function getNbByYear() { - $result = array(); $sql = "SELECT date_format(datep,'%Y') as dm, count(*) FROM llx_propal GROUP BY dm DESC WHERE fk_statut > 0"; - if ($this->db->query($sql)) - { - $num = $this->db->num_rows(); - $i = 0; - while ($i < $num) - { - $row = $this->db->fetch_row($i); - $result[$i] = $row; - $i++; - } - $this->db->free(); - } - return $result; + return $this->_getNbByYear($sql); } /** * Renvoie le nombre de propale par mois pour une année donnée @@ -114,31 +61,11 @@ class PropaleStats */ Function getAmountByMonth($year) { - $result = array(); $sql = "SELECT date_format(datep,'%m') as dm, sum(price) FROM llx_propal"; $sql .= " WHERE date_format(datep,'%Y') = $year AND fk_statut > 0"; $sql .= " GROUP BY dm DESC"; - if ($this->db->query($sql)) - { - $num = $this->db->num_rows(); - $i = 0; - while ($i < $num) - { - $row = $this->db->fetch_row($i); - $j = $row[0] * 1; - $result[$j] = $row[1]; - $i++; - } - $this->db->free(); - } - - for ($i = 1 ; $i < 13 ; $i++) - { - $res[$i] = $result[$i] + 0; - } - - return $res; + return $this->_getAmountByMonth($year, $sql); } /** * @@ -146,31 +73,11 @@ class PropaleStats */ Function getAverageByMonth($year) { - $result = array(); $sql = "SELECT date_format(datep,'%m') as dm, avg(price) FROM llx_propal"; $sql .= " WHERE date_format(datep,'%Y') = $year AND fk_statut > 0"; $sql .= " GROUP BY dm DESC"; - if ($this->db->query($sql)) - { - $num = $this->db->num_rows(); - $i = 0; - while ($i < $num) - { - $row = $this->db->fetch_row($i); - $j = $row[0] * 1; - $result[$j] = $row[1]; - $i++; - } - $this->db->free(); - } - - for ($i = 1 ; $i < 13 ; $i++) - { - $res[$i] = $result[$i] + 0; - } - - return $res; + return $this->_getAverageByMonth($year, $sql); } }