27 include_once DOL_DOCUMENT_ROOT .
'/core/class/stats.class.php';
28 include_once DOL_DOCUMENT_ROOT .
'/comm/propal/class/propal.class.php';
29 include_once DOL_DOCUMENT_ROOT .
'/supplier_proposal/class/supplier_proposal.class.php';
30 include_once DOL_DOCUMENT_ROOT .
'/core/lib/date.lib.php';
41 public $table_element;
59 function __construct($db, $socid=0, $userid=0, $mode=
'customer')
64 $this->socid = ($socid > 0 ? $socid : 0);
65 $this->userid = $userid;
67 if ($mode ==
'customer')
69 $object=
new Propal($this->db);
71 $this->from = MAIN_DB_PREFIX.$object->table_element.
" as p";
72 $this->from_line = MAIN_DB_PREFIX.$object->table_element_line.
" as tl";
73 $this->field_date=
'p.datep';
74 $this->field=
'total_ht';
75 $this->field_line=
'total_ht';
77 $this->where.=
" p.fk_statut > 0";
79 if ($mode ==
'supplier')
83 $this->from = MAIN_DB_PREFIX.$object->table_element.
" as p";
84 $this->from_line = MAIN_DB_PREFIX.$object->table_element_line.
" as tl";
85 $this->field_date=
'p.date_valid';
86 $this->field=
'total_ht';
87 $this->field_line=
'total_ht';
89 $this->where.=
" p.fk_statut > 0";
92 $this->where.=
" AND p.entity IN (".getEntity(
'propal').
")";
93 if (!$user->rights->societe->client->voir && !$this->socid) $this->where .=
" AND p.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
96 $this->where.=
" AND p.fk_soc = ".$this->socid;
98 if ($this->userid > 0) $this->where.=
' AND fk_user_author = '.$this->userid;
113 $sql =
"SELECT date_format(".$this->field_date.
",'%m') as dm, COUNT(*) as nb";
114 $sql.=
" FROM ".$this->from;
115 if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
117 $sql.=
" AND ".$this->where;
118 $sql.=
" GROUP BY dm";
119 $sql.= $this->db->order(
'dm',
'DESC');
135 $sql =
"SELECT date_format(".$this->field_date.
",'%Y') as dm, COUNT(*) as nb, SUM(c.".$this->field.
")";
136 $sql.=
" FROM ".$this->from;
137 if (!$user->rights->societe->client->voir && !$this->socid) $sql.=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
138 $sql.=
" WHERE ".$this->where;
139 $sql.=
" GROUP BY dm";
140 $sql.= $this->db->order(
'dm',
'DESC');
156 $sql =
"SELECT date_format(".$this->field_date.
",'%m') as dm, SUM(p.".$this->field.
")";
157 $sql.=
" FROM ".$this->from;
158 if (!$user->rights->societe->client->voir && !$this->socid) $sql.=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
160 $sql.=
" AND ".$this->where;
161 $sql.=
" GROUP BY dm";
162 $sql.= $this->db->order(
'dm',
'DESC');
178 $sql =
"SELECT date_format(".$this->field_date.
",'%m') as dm, AVG(p.".$this->field.
")";
179 $sql.=
" FROM ".$this->from;
180 if (!$user->rights->societe->client->voir && !$this->socid) $sql.=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
182 $sql.=
" AND ".$this->where;
183 $sql.=
" GROUP BY dm";
184 $sql.= $this->db->order(
'dm',
'DESC');
198 $sql =
"SELECT date_format(".$this->field_date.
",'%Y') as year, COUNT(*) as nb, SUM(".$this->field.
") as total, AVG(".$this->field.
") as avg";
199 $sql.=
" FROM ".$this->from;
200 if (!$user->rights->societe->client->voir && !$this->socid) $sql.=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
201 $sql.=
" WHERE ".$this->where;
202 $sql.=
" GROUP BY year";
203 $sql.= $this->db->order(
'year',
'DESC');
220 $sql =
"SELECT product.ref, COUNT(product.ref) as nb, SUM(tl.".$this->field_line.
") as total, AVG(tl.".$this->field_line.
") as avg";
221 $sql.=
" FROM ".$this->from.
", ".$this->from_line.
", ".MAIN_DB_PREFIX.
"product as product";
222 if (!$user->rights->societe->client->voir && !$user->socid) $sql.=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
223 $sql.=
" WHERE ".$this->where;
224 $sql.=
" AND p.rowid = tl.fk_propal AND tl.fk_product = product.rowid";
225 $sql.=
" AND ".$this->field_date.
" BETWEEN '".$this->db->idate(
dol_get_first_day($year,1,
false)).
"' AND '".$this->db->idate(
dol_get_last_day($year,12,
false)).
"'";
226 $sql.=
" GROUP BY product.ref";
227 $sql.= $this->db->order(
'nb',
'DESC');
Parent class of statistics class.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
_getNbByMonth($year, $sql, $format=0)
Renvoie le nombre de proposition par mois pour une annee donnee.
getAmountByMonth($year, $format)
Return the propals amount by month for a year.
getAllByYear()
Return nb, total and average.
_getAllByProduct($sql, $limit=10)
Return number or total of product refs.
_getAllByYear($sql)
Return nb of elements, total amount and avg amount each year.
__construct($db, $socid=0, $userid=0, $mode='customer')
Constructor.
getAllByProduct($year)
Return nb, amount of predefined product for year.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
getAverageByMonth($year)
Return the propals amount average by month for a year.
Class to manage price ask supplier.
_getAmountByMonth($year, $sql, $format=0)
Renvoie le nombre d'element par mois pour une annee donnee.
getNbByMonth($year, $format=0)
Return propals number by month for a year.
_getNbByYear($sql)
Return nb of elements by year.
getNbByYear()
Return propals number per year.
_getAverageByMonth($year, $sql, $format=0)
Renvoie le montant moyen par mois pour une annee donnee.
Class to manage proposals statistics.
Class to manage proposals.