mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-02-20 13:46:52 +01:00
FIX stats page for donation
This commit is contained in:
parent
fc1365daed
commit
edad39a93b
|
|
@ -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";
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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 '<div class="div-table-responsive-no-min">';
|
|||
print '<table class="border centpercent">';
|
||||
print '<tr height="24">';
|
||||
print '<td class="center">'.$langs->trans("Year").'</td>';
|
||||
print '<td class="center">'.$langs->trans("NbOfSendings").'</td>';
|
||||
print '<td class="right">'.$langs->trans("NbOfDonations").'</td>';
|
||||
/*print '<td class="center">'.$langs->trans("AmountTotal").'</td>';
|
||||
print '<td class="center">'.$langs->trans("AmountAverage").'</td>';*/
|
||||
print '</tr>';
|
||||
|
|
@ -334,7 +334,7 @@ print '</table>';
|
|||
*/
|
||||
|
||||
print '<br>';
|
||||
print '<i>'.$langs->trans("StatsOnShipmentsOnlyValidated").'</i>';
|
||||
print '<i>'.$langs->trans("StatsOnDonationsOnlyValidated").'</i>';
|
||||
|
||||
llxFooter();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user