diff --git a/htdocs/adherents/class/adherentstats.class.php b/htdocs/adherents/class/adherentstats.class.php index 9aa2fe2e8ad..72db71d07bd 100644 --- a/htdocs/adherents/class/adherentstats.class.php +++ b/htdocs/adherents/class/adherentstats.class.php @@ -55,7 +55,7 @@ class AdherentStats extends Stats */ public function __construct($db, $socid = 0, $userid = 0) { - global $user, $conf; + global $conf; $this->db = $db; $this->socid = $socid; @@ -87,8 +87,6 @@ class AdherentStats extends Stats */ public function getNbByMonth($year, $format = 0) { - global $user; - $sql = "SELECT date_format(p.dateadh,'%m') as dm, count(*)"; $sql .= " FROM ".$this->from; //if (empty($user->rights->societe->client->voir) && !$user->socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; @@ -107,8 +105,6 @@ class AdherentStats extends Stats */ public function getNbByYear() { - global $user; - $sql = "SELECT date_format(p.dateadh,'%Y') as dm, count(*)"; $sql .= " FROM ".$this->from; //if (empty($user->rights->societe->client->voir) && !$user->socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; @@ -128,8 +124,6 @@ class AdherentStats extends Stats */ public function getAmountByMonth($year, $format = 0) { - global $user; - $sql = "SELECT date_format(p.dateadh,'%m') as dm, sum(p.".$this->field.")"; $sql .= " FROM ".$this->from; //if (empty($user->rights->societe->client->voir) && !$user->socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; @@ -149,8 +143,6 @@ class AdherentStats extends Stats */ public function getAverageByMonth($year) { - global $user; - $sql = "SELECT date_format(p.dateadh,'%m') as dm, avg(p.".$this->field.")"; $sql .= " FROM ".$this->from; //if (empty($user->rights->societe->client->voir) && !$this->socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; @@ -170,8 +162,6 @@ class AdherentStats extends Stats */ public function getAllByYear() { - global $user; - $sql = "SELECT date_format(p.dateadh,'%Y') as year, count(*) as nb, sum(".$this->field.") as total, avg(".$this->field.") as avg"; $sql .= " FROM ".$this->from; //if (empty($user->rights->societe->client->voir) && !$this->socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; diff --git a/htdocs/don/class/donstats.class.php b/htdocs/don/class/donstats.class.php index 07eb6d6588e..bd52f10dbc4 100644 --- a/htdocs/don/class/donstats.class.php +++ b/htdocs/don/class/donstats.class.php @@ -68,10 +68,11 @@ class DonationStats extends Stats */ public function __construct($db, $socid, $mode, $userid = 0) { - global $user, $conf; + global $conf; $this->db = $db; + $this->field = 'amount'; $this->socid = ($socid > 0 ? $socid : 0); $this->userid = $userid; $this->cachefilesuffix = $mode; @@ -98,8 +99,6 @@ class DonationStats extends Stats */ public function getNbByMonth($year, $format = 0) { - global $user; - $sql = "SELECT date_format(d.datedon,'%m') as dm, COUNT(*) as nb"; $sql .= " FROM ".$this->from; $sql .= " WHERE d.datedon BETWEEN '".$this->db->idate(dol_get_first_day($year))."' AND '".$this->db->idate(dol_get_last_day($year))."'"; @@ -119,8 +118,6 @@ class DonationStats extends Stats */ public function getNbByYear() { - global $user; - $sql = "SELECT date_format(d.datedon,'%Y') as dm, COUNT(*) as nb, SUM(d.".$this->field.")"; $sql .= " FROM ".$this->from; $sql .= " WHERE ".$this->where; @@ -130,6 +127,45 @@ class DonationStats extends Stats return $this->_getNbByYear($sql); } + /** + * Return the number of subscriptions by month for a given year + * + * @param int $year Year + * @param int $format 0=Label of abscissa is a translated text, 1=Label of abscissa is month number, 2=Label of abscissa is first letter of month + * @return array Array of amount each month + */ + public function getAmountByMonth($year, $format = 0) + { + $sql = "SELECT date_format(d.datedon,'%m') as dm, sum(d.".$this->field.")"; + $sql .= " FROM ".$this->from; + //if (empty($user->rights->societe->client->voir) && !$user->socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql .= " WHERE ".dolSqlDateFilter('d.datedon', 0, 0, (int) $year, 1); + $sql .= " AND ".$this->where; + $sql .= " GROUP BY dm"; + $sql .= $this->db->order('dm', 'DESC'); + + return $this->_getAmountByMonth($year, $sql, $format); + } + + /** + * Return average amount each month + * + * @param int $year Year + * @return array Array of average each month + */ + public function getAverageByMonth($year) + { + $sql = "SELECT date_format(d.datedon,'%m') as dm, avg(d.".$this->field.")"; + $sql .= " FROM ".$this->from; + //if (empty($user->rights->societe->client->voir) && !$this->socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql .= " WHERE ".dolSqlDateFilter('d.datedon', 0, 0, (int) $year, 1); + $sql .= " AND ".$this->where; + $sql .= " GROUP BY dm"; + $sql .= $this->db->order('dm', 'DESC'); + + return $this->_getAverageByMonth($year, $sql); + } + /** * Return nb, total and average * @@ -137,8 +173,6 @@ class DonationStats extends Stats */ public function getAllByYear() { - global $user; - $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; $sql .= " WHERE ".$this->where; diff --git a/htdocs/don/stats/index.php b/htdocs/don/stats/index.php index e9c2b82ae22..866cd25eef1 100644 --- a/htdocs/don/stats/index.php +++ b/htdocs/don/stats/index.php @@ -58,7 +58,7 @@ $form = new Form($db); llxHeader(); -print load_fiche_titre($langs->trans("StatisticsOfSendings"), $mesg); +print load_fiche_titre($langs->trans("StatisticsOfDonations"), $mesg); dol_mkdir($dir); @@ -72,9 +72,9 @@ $data = $stats->getNbByMonthWithPrevYear($endyear, $startyear); if (empty($user->rights->societe->client->voir) || $user->socid) { - $filenamenb = $dir.'/shipmentsnbinyear-'.$user->id.'-'.$year.'.png'; + $filenamenb = $dir.'/donationnbinyear-'.$user->id.'-'.$year.'.png'; } else { - $filenamenb = $dir.'/shipmentsnbinyear-'.$year.'.png'; + $filenamenb = $dir.'/donationnbinyear-'.$year.'.png'; } $px1 = new DolGraph(); @@ -91,11 +91,11 @@ if (!$mesg) { $px1->SetMinValue(min(0, $px1->GetFloorMinValue())); $px1->SetWidth($WIDTH); $px1->SetHeight($HEIGHT); - $px1->SetYLabel($langs->trans("NbOfSendings")); + $px1->SetYLabel($langs->trans("NbOfDonations")); $px1->SetShading(3); $px1->SetHorizTickIncrement(1); $px1->mode = 'depth'; - $px1->SetTitle($langs->trans("NumberOfShipmentsByMonth")); + $px1->SetTitle($langs->trans("NumberOfDonationsByMonth")); $px1->draw($filenamenb, $fileurlnb); } @@ -245,7 +245,7 @@ print '
'; print ''; print ''; print ''; -print ''; +print ''; /*print ''; print '';*/ print ''; @@ -334,7 +334,7 @@ print '
'.$langs->trans("Year").''.$langs->trans("NbOfSendings").''.$langs->trans("NbOfDonations").''.$langs->trans("AmountTotal").''.$langs->trans("AmountAverage").'
'; */ print '
'; -print ''.$langs->trans("StatsOnShipmentsOnlyValidated").''; +print ''.$langs->trans("StatsOnDonationsOnlyValidated").''; llxFooter();