Fix: pgsql compatibility
This commit is contained in:
parent
737eb57b33
commit
f0a15ff975
@ -88,13 +88,14 @@ class PropaleStats extends Stats
|
||||
if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
$sql.= " WHERE date_format(p.datep,'%Y') = ".$year;
|
||||
$sql.= " AND ".$this->where;
|
||||
$sql.= " GROUP BY dm DESC";
|
||||
$sql.= " GROUP BY dm";
|
||||
$sql.= $this->db->order('dm','DESC');
|
||||
|
||||
return $this->_getNbByMonth($year, $sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renvoie le nombre de propale par ann<EFBFBD>e
|
||||
* Renvoie le nombre de propale par annee
|
||||
*
|
||||
*/
|
||||
function getNbByYear()
|
||||
@ -105,12 +106,13 @@ class PropaleStats extends Stats
|
||||
$sql.= " FROM ".$this->from;
|
||||
if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
$sql.= " WHERE ".$this->where;
|
||||
$sql.= " GROUP BY dm DESC";
|
||||
$sql.= " GROUP BY dm";
|
||||
$sql.= $this->db->order('dm','DESC');
|
||||
|
||||
return $this->_getNbByYear($sql);
|
||||
}
|
||||
/**
|
||||
* Renvoie le nombre de propale par mois pour une ann<EFBFBD>e donn<EFBFBD>e
|
||||
* Renvoie le nombre de propale par mois pour une annee donnee
|
||||
*
|
||||
*/
|
||||
function getAmountByMonth($year)
|
||||
@ -122,7 +124,8 @@ class PropaleStats extends Stats
|
||||
if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
$sql.= " WHERE date_format(p.datep,'%Y') = ".$year;
|
||||
$sql.= " AND ".$this->where;
|
||||
$sql.= " GROUP BY dm DESC";
|
||||
$sql.= " GROUP BY dm";
|
||||
$sql.= $this->db->order('dm','DESC');
|
||||
|
||||
return $this->_getAmountByMonth($year, $sql);
|
||||
}
|
||||
@ -139,7 +142,8 @@ class PropaleStats extends Stats
|
||||
if (!$user->rights->societe->client->voir && !$this->socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
$sql.= " WHERE date_format(p.datep,'%Y') = ".$year;
|
||||
$sql.= " AND ".$this->where;
|
||||
$sql.= " GROUP BY dm DESC";
|
||||
$sql.= " GROUP BY dm";
|
||||
$sql.= $this->db->order('dm','DESC');
|
||||
|
||||
return $this->_getAverageByMonth($year, $sql);
|
||||
}
|
||||
@ -157,7 +161,8 @@ class PropaleStats extends Stats
|
||||
$sql.= " FROM ".$this->from;
|
||||
if (!$user->rights->societe->client->voir && !$this->socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
$sql.= " WHERE ".$this->where;
|
||||
$sql.= " GROUP BY year DESC";
|
||||
$sql.= " GROUP BY year";
|
||||
$sql.= $this->db->order('year','DESC');
|
||||
|
||||
return $this->_getAllByYear($sql);
|
||||
}
|
||||
|
||||
@ -100,13 +100,14 @@ class CommandeStats extends Stats
|
||||
if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
$sql.= " WHERE date_format(c.date_commande,'%Y') = ".$year;
|
||||
$sql.= " AND ".$this->where;
|
||||
$sql.= " GROUP BY dm DESC";
|
||||
$sql.= " GROUP BY dm";
|
||||
$sql.= $this->db->order('dm','DESC');
|
||||
|
||||
return $this->_getNbByMonth($year, $sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renvoie le nombre de commande par ann<EFBFBD>e
|
||||
* Renvoie le nombre de commande par annee
|
||||
*
|
||||
*/
|
||||
function getNbByYear()
|
||||
@ -118,13 +119,14 @@ class CommandeStats extends Stats
|
||||
$sql.= " FROM ".$this->from;
|
||||
if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
$sql.= " WHERE ".$this->where;
|
||||
$sql.= " GROUP BY dm DESC";
|
||||
$sql.= " GROUP BY dm";
|
||||
$sql.= $this->db->order('dm','DESC');
|
||||
|
||||
return $this->_getNbByYear($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renvoie le nombre de commande par mois pour une ann<EFBFBD>e donn<EFBFBD>e
|
||||
* Renvoie le nombre de commande par mois pour une annee donnee
|
||||
*
|
||||
*/
|
||||
function getAmountByMonth($year)
|
||||
@ -137,13 +139,14 @@ class CommandeStats extends Stats
|
||||
if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
$sql.= " WHERE date_format(c.date_commande,'%Y') = ".$year;
|
||||
$sql.= " AND ".$this->where;
|
||||
$sql.= " GROUP BY dm DESC";
|
||||
$sql.= " GROUP BY dm";
|
||||
$sql.= $this->db->order('dm','DESC');
|
||||
|
||||
return $this->_getAmountByMonth($year, $sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renvoie le nombre de commande par mois pour une ann<EFBFBD>e donn<EFBFBD>e
|
||||
* Renvoie le nombre de commande par mois pour une annee donnee
|
||||
*
|
||||
*/
|
||||
function getAverageByMonth($year)
|
||||
@ -156,7 +159,8 @@ class CommandeStats extends Stats
|
||||
if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
$sql.= " WHERE date_format(c.date_commande,'%Y') = ".$year;
|
||||
$sql.= " AND ".$this->where;
|
||||
$sql.= " GROUP BY dm DESC";
|
||||
$sql.= " GROUP BY dm";
|
||||
$sql.= $this->db->order('dm','DESC');
|
||||
|
||||
return $this->_getAverageByMonth($year, $sql);
|
||||
}
|
||||
@ -174,7 +178,8 @@ class CommandeStats extends Stats
|
||||
$sql.= " FROM ".$this->from;
|
||||
if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
$sql.= " WHERE ".$this->where;
|
||||
$sql.= " GROUP BY year DESC";
|
||||
$sql.= " GROUP BY year";
|
||||
$sql.= $this->db->order('year','DESC');
|
||||
|
||||
return $this->_getAllByYear($sql);
|
||||
}
|
||||
|
||||
@ -94,7 +94,8 @@ class DeplacementStats extends Stats
|
||||
$sql.= " FROM ".$this->from;
|
||||
$sql.= " WHERE YEAR(dated) = ".$year;
|
||||
$sql.= " AND ".$this->where;
|
||||
$sql.= " GROUP BY dm DESC";
|
||||
$sql.= " GROUP BY dm";
|
||||
$sql.= $this->db->order('dm','DESC');
|
||||
|
||||
$res=$this->_getNbByMonth($year, $sql);
|
||||
//var_dump($res);print '<br>';
|
||||
@ -113,7 +114,8 @@ class DeplacementStats extends Stats
|
||||
$sql.= " FROM ".$this->from;
|
||||
$sql.= " WHERE date_format(dated,'%Y') = ".$year;
|
||||
$sql.= " AND ".$this->where;
|
||||
$sql.= " GROUP BY dm DESC";
|
||||
$sql.= " GROUP BY dm";
|
||||
$sql.= $this->db->order('dm','DESC');
|
||||
|
||||
$res=$this->_getAmountByMonth($year, $sql);
|
||||
//var_dump($res);print '<br>';
|
||||
@ -131,7 +133,8 @@ class DeplacementStats extends Stats
|
||||
$sql.= " FROM ".$this->from;
|
||||
$sql.= " WHERE date_format(dated,'%Y') = ".$year;
|
||||
$sql.= " AND ".$this->where;
|
||||
$sql.= " GROUP BY dm DESC";
|
||||
$sql.= " GROUP BY dm";
|
||||
$sql.= $this->db->order('dm','DESC');
|
||||
|
||||
return $this->_getAverageByMonth($year, $sql);
|
||||
}
|
||||
@ -145,7 +148,8 @@ class DeplacementStats extends Stats
|
||||
$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.= " WHERE ".$this->where;
|
||||
$sql.= " GROUP BY year DESC";
|
||||
$sql.= " GROUP BY year";
|
||||
$sql.= $this->db->order('year','DESC');
|
||||
|
||||
return $this->_getAllByYear($sql);
|
||||
}
|
||||
|
||||
@ -91,7 +91,7 @@ class FactureStats extends Stats
|
||||
$sql.= " FROM ".$this->from;
|
||||
$sql.= " WHERE ".$this->where;
|
||||
$sql.= " GROUP BY dm";
|
||||
$sql.= " ORDER BY dm DESC";
|
||||
$sql.= $this->db->order('dm','DESC');
|
||||
|
||||
return $this->_getNbByYear($sql);
|
||||
}
|
||||
@ -109,7 +109,7 @@ class FactureStats extends Stats
|
||||
$sql.= " WHERE 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.= " ORDER BY dm DESC";
|
||||
$sql.= $this->db->order('dm','DESC');
|
||||
|
||||
$res=$this->_getNbByMonth($year, $sql);
|
||||
//var_dump($res);print '<br>';
|
||||
@ -129,7 +129,7 @@ class FactureStats extends Stats
|
||||
$sql.= " WHERE date_format(datef,'%Y') = ".$year;
|
||||
$sql.= " AND ".$this->where;
|
||||
$sql.= " GROUP BY dm";
|
||||
$sql.= " ORDER BY dm DESC";
|
||||
$sql.= $this->db->order('dm','DESC');
|
||||
|
||||
$res=$this->_getAmountByMonth($year, $sql);
|
||||
//var_dump($res);print '<br>';
|
||||
@ -148,7 +148,7 @@ class FactureStats extends Stats
|
||||
$sql.= " WHERE 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.= " ORDER BY dm DESC";
|
||||
$sql.= $this->db->order('dm','DESC');
|
||||
|
||||
return $this->_getAverageByMonth($year, $sql);
|
||||
}
|
||||
@ -163,7 +163,7 @@ class FactureStats extends Stats
|
||||
$sql.= " FROM ".$this->from;
|
||||
$sql.= " WHERE ".$this->where;
|
||||
$sql.= " GROUP BY year";
|
||||
$sql.= " ORDER BY year DESC";
|
||||
$sql.= $this->db->order('year','DESC');
|
||||
|
||||
return $this->_getAllByYear($sql);
|
||||
}
|
||||
|
||||
@ -29,6 +29,13 @@ CREATE OR REPLACE FUNCTION UNIX_TIMESTAMP(TIMESTAMP WITH TIME ZONE) RETURNS BIGI
|
||||
CREATE OR REPLACE FUNCTION date_format(timestamp without time zone, text) RETURNS text AS $$ DECLARE i int := 1; temp text := ''; c text; n text; res text; BEGIN WHILE i <= pg_catalog.length($2) LOOP c := SUBSTRING ($2 FROM i FOR 1); IF c = '%' AND i != pg_catalog.length($2) THEN n := SUBSTRING ($2 FROM (i + 1) FOR 1); SELECT INTO res CASE WHEN n = 'a' THEN pg_catalog.to_char($1, 'Dy') WHEN n = 'b' THEN pg_catalog.to_char($1, 'Mon') WHEN n = 'c' THEN pg_catalog.to_char($1, 'FMMM') WHEN n = 'D' THEN pg_catalog.to_char($1, 'FMDDth') WHEN n = 'd' THEN pg_catalog.to_char($1, 'DD') WHEN n = 'e' THEN pg_catalog.to_char($1, 'FMDD') WHEN n = 'f' THEN pg_catalog.to_char($1, 'US') WHEN n = 'H' THEN pg_catalog.to_char($1, 'HH24') WHEN n = 'h' THEN pg_catalog.to_char($1, 'HH12') WHEN n = 'I' THEN pg_catalog.to_char($1, 'HH12') WHEN n = 'i' THEN pg_catalog.to_char($1, 'MI') WHEN n = 'j' THEN pg_catalog.to_char($1, 'DDD') WHEN n = 'k' THEN pg_catalog.to_char($1, 'FMHH24') WHEN n = 'l' THEN pg_catalog.to_char($1, 'FMHH12') WHEN n = 'M' THEN pg_catalog.to_char($1, 'FMMonth') WHEN n = 'm' THEN pg_catalog.to_char($1, 'MM') WHEN n = 'p' THEN pg_catalog.to_char($1, 'AM') WHEN n = 'r' THEN pg_catalog.to_char($1, 'HH12:MI:SS AM') WHEN n = 'S' THEN pg_catalog.to_char($1, 'SS') WHEN n = 's' THEN pg_catalog.to_char($1, 'SS') WHEN n = 'T' THEN pg_catalog.to_char($1, 'HH24:MI:SS') WHEN n = 'U' THEN pg_catalog.to_char($1, '?') WHEN n = 'u' THEN pg_catalog.to_char($1, '?') WHEN n = 'V' THEN pg_catalog.to_char($1, '?') WHEN n = 'v' THEN pg_catalog.to_char($1, '?') WHEN n = 'W' THEN pg_catalog.to_char($1, 'FMDay') WHEN n = 'w' THEN EXTRACT(DOW FROM $1)::text WHEN n = 'X' THEN pg_catalog.to_char($1, '?') WHEN n = 'x' THEN pg_catalog.to_char($1, '?') WHEN n = 'Y' THEN pg_catalog.to_char($1, 'YYYY') WHEN n = 'y' THEN pg_catalog.to_char($1, 'YY') WHEN n = '%' THEN pg_catalog.to_char($1, '%') ELSE NULL END; temp := temp operator(pg_catalog.||) res; i := i + 2; ELSE temp = temp operator(pg_catalog.||) c; i := i + 1; END IF; END LOOP; RETURN temp; END $$ IMMUTABLE STRICT LANGUAGE PLPGSQL;
|
||||
|
||||
|
||||
CREATE OR REPLACE FUNCTION YEAR(TIMESTAMP without TIME ZONE) RETURNS INTEGER AS $$ SELECT EXTRACT(YEAR FROM $1)::INTEGER; $$ LANGUAGE SQL IMMUTABLE;
|
||||
|
||||
CREATE OR REPLACE FUNCTION YEAR(TIMESTAMP WITH TIME ZONE) RETURNS INTEGER AS $$ SELECT EXTRACT(YEAR FROM $1)::INTEGER; $$ LANGUAGE SQL STABLE;
|
||||
|
||||
CREATE OR REPLACE FUNCTION YEAR(DATE) RETURNS INTEGER AS $$ SELECT EXTRACT(YEAR FROM $1)::INTEGER; $$ LANGUAGE SQL IMMUTABLE;
|
||||
|
||||
|
||||
CREATE OR REPLACE FUNCTION MONTH(TIMESTAMP without TIME ZONE) RETURNS INTEGER AS $$ SELECT EXTRACT(MONTH FROM $1)::INTEGER; $$ LANGUAGE SQL IMMUTABLE;
|
||||
|
||||
CREATE OR REPLACE FUNCTION MONTH(TIMESTAMP WITH TIME ZONE) RETURNS INTEGER AS $$ SELECT EXTRACT(MONTH FROM $1)::INTEGER; $$ LANGUAGE SQL STABLE;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user