Clean code

This commit is contained in:
Laurent Destailleur 2026-04-14 15:20:21 +02:00
parent 8c94e4b471
commit 46cab2ae70
14 changed files with 70 additions and 72 deletions

View file

@ -106,7 +106,7 @@ class AdherentStats extends Stats
public function getNbByMonth($year, $format = 0)
{
$sql = "SELECT date_format(p.dateadh,'%m') as dm, count(*)";
$sql .= " FROM ".$this->from;
$sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1);
$sql .= " WHERE ".dolSqlDateFilter('p.dateadh', 0, 0, (int) $year, 1);
$sql .= " AND ".$this->where;
$sql .= " GROUP BY dm";
@ -123,7 +123,7 @@ class AdherentStats extends Stats
public function getNbByYear()
{
$sql = "SELECT date_format(p.dateadh,'%Y') as dm, count(*)";
$sql .= " FROM ".$this->from;
$sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1);
$sql .= " WHERE ".$this->where;
$sql .= " GROUP BY dm";
$sql .= $this->db->order('dm', 'DESC');
@ -141,7 +141,7 @@ class AdherentStats extends Stats
public function getAmountByMonth($year, $format = 0)
{
$sql = "SELECT date_format(p.dateadh,'%m') as dm, sum(p.".$this->field.")";
$sql .= " FROM ".$this->from;
$sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1);
$sql .= " WHERE ".dolSqlDateFilter('p.dateadh', 0, 0, (int) $year, 1);
$sql .= " AND ".$this->where;
$sql .= " GROUP BY dm";
@ -159,7 +159,7 @@ class AdherentStats extends Stats
public function getAverageByMonth($year)
{
$sql = "SELECT date_format(p.dateadh,'%m') as dm, avg(p.".$this->field.")";
$sql .= " FROM ".$this->from;
$sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1);
$sql .= " WHERE ".dolSqlDateFilter('p.dateadh', 0, 0, (int) $year, 1);
$sql .= " AND ".$this->where;
$sql .= " GROUP BY dm";
@ -177,7 +177,7 @@ class AdherentStats extends Stats
public function getAllByYear()
{
$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;
$sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1);
$sql .= " WHERE ".$this->where;
$sql .= " GROUP BY year";
$sql .= $this->db->order('year', 'DESC');

View file

@ -149,7 +149,7 @@ class PropaleStats extends Stats
global $user;
$sql = "SELECT date_format(".$this->field_date.",'%m') as dm, COUNT(*) as nb";
$sql .= " FROM ".$this->from;
$sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1);
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON p.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
}
@ -173,7 +173,7 @@ class PropaleStats extends Stats
global $user;
$sql = "SELECT date_format(".$this->field_date.",'%Y') as dm, COUNT(*) as nb, SUM(c.".$this->field.")";
$sql .= " FROM ".$this->from;
$sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1);
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON p.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
}
@ -197,7 +197,7 @@ class PropaleStats extends Stats
global $user;
$sql = "SELECT date_format(".$this->field_date.",'%m') as dm, SUM(p.".$this->field.")";
$sql .= " FROM ".$this->from;
$sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1);
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON p.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
}
@ -222,7 +222,7 @@ class PropaleStats extends Stats
global $user;
$sql = "SELECT date_format(".$this->field_date.",'%m') as dm, AVG(p.".$this->field.")";
$sql .= " FROM ".$this->from;
$sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1);
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON p.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
}
@ -245,7 +245,7 @@ class PropaleStats extends Stats
global $user;
$sql = "SELECT date_format(".$this->field_date.",'%Y') as year, COUNT(*) as nb, SUM(".$this->field.") as total, AVG(".$this->field.") as avg";
$sql .= " FROM ".$this->from;
$sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1);
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON p.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
}
@ -270,8 +270,8 @@ class PropaleStats extends Stats
global $user;
$sql = "SELECT product.ref, COUNT(product.ref) as nb, SUM(tl.".$this->field_line.") as total, AVG(tl.".$this->field_line.") as avg";
$sql .= " FROM ".$this->from;
$sql .= " INNER JOIN ".$this->from_line." ON p.rowid = tl.fk_propal";
$sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1);
$sql .= " INNER JOIN ".$this->db->sanitize($this->from_line, 0, 0, 1)." ON p.rowid = tl.fk_propal";
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."product as product ON tl.fk_product = product.rowid";
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON p.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);

View file

@ -162,7 +162,7 @@ class CommandeStats extends Stats
global $user;
$sql = "SELECT date_format(c.date_commande,'%m') as dm, COUNT(*) as nb";
$sql .= " FROM ".$this->from;
$sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1);
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
}
@ -187,7 +187,7 @@ class CommandeStats extends Stats
global $user;
$sql = "SELECT date_format(c.date_commande,'%Y') as dm, COUNT(*) as nb, SUM(c.".$this->field.")";
$sql .= " FROM ".$this->from;
$sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1);
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
}
@ -211,7 +211,7 @@ class CommandeStats extends Stats
global $user;
$sql = "SELECT date_format(c.date_commande,'%m') as dm, SUM(c.".$this->field.")";
$sql .= " FROM ".$this->from;
$sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1);
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
}
@ -236,7 +236,7 @@ class CommandeStats extends Stats
global $user;
$sql = "SELECT date_format(c.date_commande,'%m') as dm, AVG(c.".$this->field.")";
$sql .= " FROM ".$this->from;
$sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1);
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
}
@ -259,7 +259,7 @@ class CommandeStats extends Stats
global $user;
$sql = "SELECT date_format(c.date_commande,'%Y') as year, COUNT(*) as nb, SUM(c.".$this->field.") as total, AVG(".$this->field.") as avg";
$sql .= " FROM ".$this->from;
$sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1);
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
}
@ -283,8 +283,8 @@ class CommandeStats extends Stats
global $user;
$sql = "SELECT product.ref, COUNT(product.ref) as nb, SUM(tl.".$this->field_line.") as total, AVG(tl.".$this->field_line.") as avg";
$sql .= " FROM ".$this->from;
$sql .= " INNER JOIN ".$this->from_line." ON c.rowid = tl.fk_commande";
$sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1);
$sql .= " INNER JOIN ".$this->db->sanitize($this->from_line, 0, 0, 1)." ON c.rowid = tl.fk_commande";
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."product as product ON tl.fk_product = product.rowid";
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);

View file

@ -99,7 +99,7 @@ class DeplacementStats extends Stats
public function getNbByYear()
{
$sql = "SELECT YEAR(dated) as dm, count(*)";
$sql .= " FROM ".$this->from;
$sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1);
$sql .= " GROUP BY dm DESC";
$sql .= " WHERE ".$this->where;
@ -117,7 +117,7 @@ class DeplacementStats extends Stats
public function getNbByMonth($year, $format = 0)
{
$sql = "SELECT MONTH(dated) as dm, count(*)";
$sql .= " FROM ".$this->from;
$sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1);
$sql .= " WHERE YEAR(dated) = ".((int) $year);
$sql .= " AND ".$this->where;
$sql .= " GROUP BY dm";
@ -139,7 +139,7 @@ class DeplacementStats extends Stats
public function getAmountByMonth($year, $format = 0)
{
$sql = "SELECT date_format(dated,'%m') as dm, sum(".$this->field.")";
$sql .= " FROM ".$this->from;
$sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1);
$sql .= " WHERE date_format(dated,'%Y') = '".$this->db->escape((string) $year)."'";
$sql .= " AND ".$this->where;
$sql .= " GROUP BY dm";
@ -159,7 +159,7 @@ class DeplacementStats extends Stats
public function getAverageByMonth($year)
{
$sql = "SELECT date_format(dated,'%m') as dm, avg(".$this->field.")";
$sql .= " FROM ".$this->from;
$sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1);
$sql .= " WHERE date_format(dated,'%Y') = '".$this->db->escape((string) $year)."'";
$sql .= " AND ".$this->where;
$sql .= " GROUP BY dm";
@ -176,7 +176,7 @@ class DeplacementStats extends Stats
public function getAllByYear()
{
$sql = "SELECT date_format(dated,'%Y') as year, count(*) as nb, sum(".$this->field.") as total, avg(".$this->field.") as avg";
$sql .= " FROM ".$this->from;
$sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1);
$sql .= " WHERE ".$this->where;
$sql .= " GROUP BY year";
$sql .= $this->db->order('year', 'DESC');

View file

@ -152,7 +152,7 @@ class FactureStats extends Stats
global $user;
$sql = "SELECT date_format(f.datef,'%m') as dm, COUNT(*) as nb";
$sql .= " FROM ".$this->from;
$sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1);
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON f.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
}
@ -178,7 +178,7 @@ class FactureStats extends Stats
global $user;
$sql = "SELECT date_format(f.datef,'%Y') as dm, COUNT(*), SUM(c.".$this->field.")";
$sql .= " FROM ".$this->from;
$sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1);
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON f.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
}
@ -203,7 +203,7 @@ class FactureStats extends Stats
global $user;
$sql = "SELECT date_format(datef,'%m') as dm, SUM(f.".$this->field.")";
$sql .= " FROM ".$this->from;
$sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1);
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON f.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
}
@ -229,7 +229,7 @@ class FactureStats extends Stats
global $user;
$sql = "SELECT date_format(datef,'%m') as dm, AVG(f.".$this->field.")";
$sql .= " FROM ".$this->from;
$sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1);
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON f.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
}
@ -252,7 +252,7 @@ class FactureStats extends Stats
global $user;
$sql = "SELECT date_format(datef,'%Y') as year, COUNT(*) as nb, SUM(f.".$this->field.") as total, AVG(f.".$this->field.") as avg";
$sql .= " FROM ".$this->from;
$sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1);
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON f.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
}
@ -276,8 +276,8 @@ class FactureStats extends Stats
global $user;
$sql = "SELECT product.ref, COUNT(product.ref) as nb, SUM(tl.".$this->field_line.") as total, AVG(tl.".$this->field_line.") as avg";
$sql .= " FROM ".$this->from;
$sql .= " INNER JOIN ".$this->from_line." ON f.rowid = tl.fk_facture";
$sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1);
$sql .= " INNER JOIN ".$this->db->sanitize($this->from_line, 0, 0, 1)." ON f.rowid = tl.fk_facture";
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."product as product ON tl.fk_product = product.rowid";
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON f.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
@ -305,7 +305,7 @@ class FactureStats extends Stats
$endYear = (int) date('Y');
$startYear = $endYear - $numberYears;
$sql = "SELECT date_format(datef,'%Y') as dm, SUM(f.".$this->field.")";
$sql .= " FROM ".$this->from;
$sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1);
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON f.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
}

View file

@ -126,7 +126,7 @@ class DonationStats extends Stats
public function getNbByMonth($year, $format = 0)
{
$sql = "SELECT date_format(d.datedon,'%m') as dm, COUNT(*) as nb";
$sql .= " FROM ".$this->from;
$sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1);
$sql .= $this->join;
$sql .= " WHERE d.datedon BETWEEN '".$this->db->idate(dol_get_first_day($year))."' AND '".$this->db->idate(dol_get_last_day($year))."'";
$sql .= " AND ".$this->where;
@ -144,7 +144,7 @@ class DonationStats extends Stats
public function getNbByYear()
{
$sql = "SELECT date_format(d.datedon,'%Y') as dm, COUNT(*) as nb, SUM(d.".$this->db->sanitize($this->field).")";
$sql .= " FROM ".$this->from;
$sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1);
$sql .= $this->join;
$sql .= " WHERE ".$this->where;
$sql .= " GROUP BY dm";
@ -163,7 +163,7 @@ class DonationStats extends Stats
public function getAmountByMonth($year, $format = 0)
{
$sql = "SELECT date_format(d.datedon,'%m') as dm, sum(d.".$this->db->sanitize($this->field).")";
$sql .= " FROM ".$this->from;
$sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1);
$sql .= $this->join;
$sql .= " WHERE ".dolSqlDateFilter('d.datedon', 0, 0, (int) $year, 1);
$sql .= " AND ".$this->where;
@ -182,7 +182,7 @@ class DonationStats extends Stats
public function getAverageByMonth($year)
{
$sql = "SELECT date_format(d.datedon,'%m') as dm, avg(d.".$this->db->sanitize($this->field).")";
$sql .= " FROM ".$this->from;
$sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1);
$sql .= $this->join;
$sql .= " WHERE ".dolSqlDateFilter('d.datedon', 0, 0, (int) $year, 1);
$sql .= " AND ".$this->where;
@ -200,7 +200,7 @@ class DonationStats extends Stats
public function getAllByYear()
{
$sql = "SELECT date_format(d.datedon,'%Y') as year, COUNT(*) as nb, SUM(d.".$this->db->sanitize($this->field).") as total, AVG(".$this->field.") as avg";
$sql .= " FROM ".$this->from;
$sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1);
$sql .= $this->join;
$sql .= " WHERE ".$this->where;
$sql .= " GROUP BY year";

View file

@ -119,7 +119,7 @@ class ExpeditionStats extends Stats
global $user;
$sql = "SELECT date_format(c.date_valid,'%m') as dm, COUNT(*) as nb";
$sql .= " FROM ".$this->from;
$sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1);
if (!$user->hasRight('societe', 'client', 'voir')) {
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
}
@ -143,7 +143,7 @@ class ExpeditionStats extends Stats
global $user;
$sql = "SELECT date_format(c.date_valid,'%Y') as dm, COUNT(*) as nb, SUM(c.".$this->field.")";
$sql .= " FROM ".$this->from;
$sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1);
if (!$user->hasRight('societe', 'client', 'voir')) {
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
}
@ -166,7 +166,7 @@ class ExpeditionStats extends Stats
global $user;
$sql = "SELECT date_format(c.date_valid,'%m') as dm, SUM(c.".$this->field.")";
$sql .= " FROM ".$this->from;
$sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1);
if (!$user->hasRight('societe', 'client', 'voir')) {
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
}
@ -190,7 +190,7 @@ class ExpeditionStats extends Stats
global $user;
$sql = "SELECT date_format(c.date_valid,'%m') as dm, AVG(c.".$this->field.")";
$sql .= " FROM ".$this->from;
$sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1);
if (!$user->hasRight('societe', 'client', 'voir')) {
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
}
@ -212,7 +212,7 @@ class ExpeditionStats extends Stats
global $user;
$sql = "SELECT date_format(c.date_valid,'%Y') as year, COUNT(*) as nb, SUM(c.".$this->field.") as total, AVG(".$this->field.") as avg";
$sql .= " FROM ".$this->from;
$sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1);
if (!$user->hasRight('societe', 'client', 'voir')) {
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
}

View file

@ -119,7 +119,7 @@ class ExpenseReportStats extends Stats
public function getNbByYear()
{
$sql = "SELECT YEAR(".$this->db->ifsql("e.".$this->datetouse." IS NULL", "e.date_create", "e.".$this->datetouse).") as dm, count(*)";
$sql .= " FROM ".$this->from;
$sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1);
$sql .= " GROUP BY dm DESC";
$sql .= " WHERE ".$this->where;
@ -137,7 +137,7 @@ class ExpenseReportStats extends Stats
public function getNbByMonth($year, $format = 0)
{
$sql = "SELECT MONTH(".$this->db->ifsql("e.".$this->datetouse." IS NULL", "e.date_create", "e.".$this->datetouse).") as dm, count(*)";
$sql .= " FROM ".$this->from;
$sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1);
$sql .= " WHERE YEAR(e.".$this->datetouse.") = ".((int) $year);
$sql .= " AND ".$this->where;
$sql .= " GROUP BY dm";
@ -159,7 +159,7 @@ class ExpenseReportStats extends Stats
public function getAmountByMonth($year, $format = 0)
{
$sql = "SELECT date_format(".$this->db->ifsql("e.".$this->datetouse." IS NULL", "e.date_create", "e.".$this->datetouse).",'%m') as dm, sum(".$this->field.")";
$sql .= " FROM ".$this->from;
$sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1);
$sql .= " WHERE date_format(".$this->db->ifsql("e.".$this->datetouse." IS NULL", "e.date_create", "e.".$this->datetouse).",'%Y') = '".$this->db->escape((string) $year)."'";
$sql .= " AND ".$this->where;
$sql .= " GROUP BY dm";
@ -179,7 +179,7 @@ class ExpenseReportStats extends Stats
public function getAverageByMonth($year)
{
$sql = "SELECT date_format(".$this->db->ifsql("e.".$this->datetouse." IS NULL", "e.date_create", "e.".$this->datetouse).",'%m') as dm, avg(".$this->field.")";
$sql .= " FROM ".$this->from;
$sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1);
$sql .= " WHERE date_format(".$this->db->ifsql("e.".$this->datetouse." IS NULL", "e.date_create", "e.".$this->datetouse).",'%Y') = '".$this->db->escape((string) $year)."'";
$sql .= " AND ".$this->where;
$sql .= " GROUP BY dm";
@ -196,7 +196,7 @@ class ExpenseReportStats extends Stats
public function getAllByYear()
{
$sql = "SELECT date_format(".$this->db->ifsql("e.".$this->datetouse." IS NULL", "e.date_create", "e.".$this->datetouse).",'%Y') as year, count(*) as nb, sum(".$this->field.") as total, avg(".$this->field.") as avg";
$sql .= " FROM ".$this->from;
$sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1);
$sql .= " WHERE ".$this->where;
$sql .= " GROUP BY year";
$sql .= $this->db->order('year', 'DESC');

View file

@ -112,7 +112,7 @@ class FichinterStats extends Stats
global $user;
$sql = "SELECT date_format(c.date_valid,'%m') as dm, COUNT(*) as nb";
$sql .= " FROM ".$this->from;
$sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1);
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
}
@ -136,7 +136,7 @@ class FichinterStats extends Stats
global $user;
$sql = "SELECT date_format(c.date_valid,'%Y') as dm, COUNT(*) as nb, 0";
$sql .= " FROM ".$this->from;
$sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1);
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
}
@ -159,7 +159,7 @@ class FichinterStats extends Stats
global $user;
$sql = "SELECT date_format(c.date_valid,'%m') as dm, 0";
$sql .= " FROM ".$this->from;
$sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1);
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
}
@ -183,7 +183,7 @@ class FichinterStats extends Stats
global $user;
$sql = "SELECT date_format(c.date_valid,'%m') as dm, 0";
$sql .= " FROM ".$this->from;
$sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1);
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
}
@ -205,7 +205,7 @@ class FichinterStats extends Stats
global $user;
$sql = "SELECT date_format(c.date_valid,'%Y') as year, COUNT(*) as nb, 0 as total, 0 as avg";
$sql .= " FROM ".$this->from;
$sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1);
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
}
@ -225,10 +225,8 @@ class FichinterStats extends Stats
*/
public function getAllByProduct($year, $limit = 0)
{
global $user;
$sql = "SELECT product.ref, COUNT(product.ref) as nb, 0 as total, 0 as avg";
$sql .= " FROM ".$this->from.", ".$this->from_line.", ".MAIN_DB_PREFIX."product as product";
$sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1).", ".$this->db->sanitize($this->from_line, 0, 0, 1).", ".MAIN_DB_PREFIX."product as product";
//if (empty($user->rights->societe->client->voir) && !$user->socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql .= " WHERE ".$this->where;
$sql .= " AND c.rowid = tl.fk_fichinter AND tl.fk_product = product.rowid";

View file

@ -562,7 +562,7 @@ class ProjectStats extends Stats
protected function getAverageByMonth($year)
{
$sql = "SELECT date_format(datef,'%m') as dm, AVG(f.".$this->field.")";
$sql .= " FROM ".$this->from;
$sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1);
$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";

View file

@ -221,7 +221,7 @@ class TaskStats extends Stats
protected function getAverageByMonth($year)
{
$sql = "SELECT date_format(datef,'%m') as dm, AVG(f.".$this->field.")";
$sql .= " FROM ".$this->from;
$sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1);
$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";

View file

@ -112,7 +112,7 @@ class ReceptionStats extends Stats
global $user;
$sql = "SELECT date_format(c.date_valid,'%m') as dm, COUNT(*) as nb";
$sql .= " FROM ".$this->from;
$sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1);
if (!$user->hasRight('societe', 'client', 'voir')) {
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
}
@ -136,7 +136,7 @@ class ReceptionStats extends Stats
global $user;
$sql = "SELECT date_format(c.date_valid,'%Y') as dm, COUNT(*) as nb, SUM(c.".$this->field.")";
$sql .= " FROM ".$this->from;
$sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1);
if (!$user->hasRight('societe', 'client', 'voir')) {
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
}
@ -159,7 +159,7 @@ class ReceptionStats extends Stats
global $user;
$sql = "SELECT date_format(c.date_valid,'%m') as dm, SUM(c.".$this->field.")";
$sql .= " FROM ".$this->from;
$sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1);
if (!$user->hasRight('societe', 'client', 'voir')) {
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
}
@ -183,7 +183,7 @@ class ReceptionStats extends Stats
global $user;
$sql = "SELECT date_format(c.date_valid,'%m') as dm, AVG(c.".$this->field.")";
$sql .= " FROM ".$this->from;
$sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1);
if (!$user->hasRight('societe', 'client', 'voir')) {
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
}
@ -205,7 +205,7 @@ class ReceptionStats extends Stats
global $user;
$sql = "SELECT date_format(c.date_valid,'%Y') as year, COUNT(*) as nb, SUM(c.".$this->field.") as total, AVG(".$this->field.") as avg";
$sql .= " FROM ".$this->from;
$sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1);
if (!$user->hasRight('societe', 'client', 'voir')) {
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
}

View file

@ -87,7 +87,7 @@ class SalariesStats extends Stats
public function getNbByYear()
{
$sql = "SELECT YEAR(dateep) as dm, count(*)";
$sql .= " FROM ".$this->from;
$sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1);
$sql .= " WHERE ".$this->where;
$sql .= " GROUP BY dm DESC";
@ -105,7 +105,7 @@ class SalariesStats extends Stats
public function getNbByMonth($year, $format = 0)
{
$sql = "SELECT MONTH(dateep) as dm, count(*)";
$sql .= " FROM ".$this->from;
$sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1);
$sql .= " WHERE YEAR(dateep) = ".((int) $year);
$sql .= " AND ".$this->where;
$sql .= " GROUP BY dm";
@ -127,7 +127,7 @@ class SalariesStats extends Stats
public function getAmountByMonth($year, $format = 0)
{
$sql = "SELECT date_format(dateep,'%m') as dm, sum(".$this->field.")";
$sql .= " FROM ".$this->from;
$sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1);
$sql .= " WHERE date_format(dateep,'%Y') = '".((int) $year)."'";
$sql .= " AND ".$this->where;
$sql .= " GROUP BY dm";
@ -147,7 +147,7 @@ class SalariesStats extends Stats
public function getAverageByMonth($year)
{
$sql = "SELECT date_format(dateep,'%m') as dm, avg(".$this->field.")";
$sql .= " FROM ".$this->from;
$sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1);
$sql .= " WHERE date_format(dateep,'%Y') = '".((int) $year)."'";
$sql .= " AND ".$this->where;
$sql .= " GROUP BY dm";
@ -164,7 +164,7 @@ class SalariesStats extends Stats
public function getAllByYear()
{
$sql = "SELECT date_format(dateep,'%Y') as year, count(*) as nb, sum(".$this->field.") as total, avg(".$this->field.") as avg";
$sql .= " FROM ".$this->from;
$sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1);
$sql .= " WHERE ".$this->where;
$sql .= " GROUP BY year";
$sql .= $this->db->order('year', 'DESC');

View file

@ -86,7 +86,7 @@ class TicketStats extends Stats
public function getNbByYear()
{
$sql = "SELECT YEAR(datec) as dm, count(*)";
$sql .= " FROM ".$this->from;
$sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1);
$sql .= " GROUP BY dm DESC";
$sql .= " WHERE ".$this->where;
@ -103,7 +103,7 @@ class TicketStats extends Stats
public function getNbByMonth($year, $format = 0)
{
$sql = "SELECT MONTH(datec) as dm, count(*)";
$sql .= " FROM ".$this->from;
$sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1);
$sql .= " WHERE YEAR(datec) = ".((int) $year);
$sql .= " AND ".$this->where;
$sql .= " GROUP BY dm";
@ -124,7 +124,7 @@ class TicketStats extends Stats
public function getAmountByMonth($year, $format = 0)
{
$sql = "SELECT date_format(datec,'%m') as dm, sum(".$this->field.")";
$sql .= " FROM ".$this->from;
$sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1);
$sql .= " WHERE date_format(datec,'%Y') = '".$this->db->escape((string) $year)."'";
$sql .= " AND ".$this->where;
$sql .= " GROUP BY dm";
@ -144,7 +144,7 @@ class TicketStats extends Stats
public function getAverageByMonth($year)
{
$sql = "SELECT date_format(datec,'%m') as dm, avg(".$this->field.")";
$sql .= " FROM ".$this->from;
$sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1);
$sql .= " WHERE date_format(datec,'%Y') = '".$this->db->escape((string) $year)."'";
$sql .= " AND ".$this->where;
$sql .= " GROUP BY dm";
@ -161,7 +161,7 @@ class TicketStats extends Stats
public function getAllByYear()
{
$sql = "SELECT date_format(datec,'%Y') as year, count(*) as nb, sum(".$this->field.") as total, avg(".$this->field.") as avg";
$sql .= " FROM ".$this->from;
$sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1);
$sql .= " WHERE ".$this->where;
$sql .= " GROUP BY year";
$sql .= $this->db->order('year', 'DESC');