28 include_once DOL_DOCUMENT_ROOT.
'/core/class/stats.class.php';
29 include_once DOL_DOCUMENT_ROOT.
'/comm/propal/class/propal.class.php';
30 include_once DOL_DOCUMENT_ROOT.
'/supplier_proposal/class/supplier_proposal.class.php';
31 include_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
42 public $table_element;
63 public function __construct($db, $socid = 0, $userid = 0, $mode =
'customer', $typentid = 0, $categid = 0)
68 $this->socid = ($socid > 0 ? $socid : 0);
69 $this->userid = $userid;
72 if ($mode ==
'customer')
76 $this->from = MAIN_DB_PREFIX.$object->table_element.
" as p";
77 $this->from_line = MAIN_DB_PREFIX.$object->table_element_line.
" as tl";
78 $this->field_date =
'p.datep';
79 $this->field =
'total_ht';
80 $this->field_line =
'total_ht';
84 if ($mode ==
'supplier')
88 $this->from = MAIN_DB_PREFIX.$object->table_element.
" as p";
89 $this->from_line = MAIN_DB_PREFIX.$object->table_element_line.
" as tl";
90 $this->field_date =
'p.date_valid';
91 $this->field =
'total_ht';
92 $this->field_line =
'total_ht';
97 $this->where .= ($this->where ?
' AND ' :
'').
"p.entity IN (".
getEntity(
'propal').
")";
98 if (!$user->rights->societe->client->voir && !$this->socid) $this->where .=
" AND p.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id;
101 $this->where .=
" AND p.fk_soc = ".$this->socid;
103 if ($this->userid > 0) $this->where .=
' AND fk_user_author = '.$this->userid;
107 $this->join .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'societe as s ON s.rowid = p.fk_soc';
108 $this->where .=
' AND s.fk_typent = '.$typentid;
113 $this->join .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'categorie_societe as cs ON cs.fk_soc = p.fk_soc';
114 $this->join .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'categorie as c ON c.rowid = cs.fk_categorie';
115 $this->where .=
' AND c.rowid = '.$categid;
131 $sql =
"SELECT date_format(".$this->field_date.
",'%m') as dm, COUNT(*) as nb";
132 $sql .=
" FROM ".$this->from;
133 if (!$user->rights->societe->client->voir && !$user->socid) $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
136 $sql .=
" AND ".$this->where;
137 $sql .=
" GROUP BY dm";
138 $sql .= $this->
db->order(
'dm',
'DESC');
154 $sql =
"SELECT date_format(".$this->field_date.
",'%Y') as dm, COUNT(*) as nb, SUM(c.".$this->field.
")";
155 $sql .=
" FROM ".$this->from;
156 if (!$user->rights->societe->client->voir && !$this->socid) $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
158 $sql .=
" WHERE ".$this->where;
159 $sql .=
" GROUP BY dm";
160 $sql .= $this->
db->order(
'dm',
'DESC');
176 $sql =
"SELECT date_format(".$this->field_date.
",'%m') as dm, SUM(p.".$this->field.
")";
177 $sql .=
" FROM ".$this->from;
178 if (!$user->rights->societe->client->voir && !$this->socid) $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
181 $sql .=
" AND ".$this->where;
182 $sql .=
" GROUP BY dm";
183 $sql .= $this->
db->order(
'dm',
'DESC');
199 $sql =
"SELECT date_format(".$this->field_date.
",'%m') as dm, AVG(p.".$this->field.
")";
200 $sql .=
" FROM ".$this->from;
201 if (!$user->rights->societe->client->voir && !$this->socid) $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
204 $sql .=
" AND ".$this->where;
205 $sql .=
" GROUP BY dm";
206 $sql .= $this->
db->order(
'dm',
'DESC');
220 $sql =
"SELECT date_format(".$this->field_date.
",'%Y') as year, COUNT(*) as nb, SUM(".$this->field.
") as total, AVG(".$this->field.
") as avg";
221 $sql .=
" FROM ".$this->from;
222 if (!$user->rights->societe->client->voir && !$this->socid) $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
224 $sql .=
" WHERE ".$this->where;
225 $sql .=
" GROUP BY year";
226 $sql .= $this->
db->order(
'year',
'DESC');
244 $sql =
"SELECT product.ref, COUNT(product.ref) as nb, SUM(tl.".$this->field_line.
") as total, AVG(tl.".$this->field_line.
") as avg";
245 $sql .=
" FROM ".$this->from.
", ".$this->from_line.
", ".MAIN_DB_PREFIX.
"product as product";
246 if (!$user->rights->societe->client->voir && !$user->socid) $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
248 $sql .=
" WHERE ".$this->where;
249 $sql .=
" AND p.rowid = tl.fk_propal AND tl.fk_product = product.rowid";
251 $sql .=
" GROUP BY product.ref";
252 $sql .= $this->
db->order(
'nb',
'DESC');
Parent class of statistics class.
getAllByProduct($year, $limit=10)
Return nb, amount of predefined product for year.
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 documents par mois pour une annee donnee Return number of documents per month fo...
$conf db
API class for accounts.
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.
__construct($db, $socid=0, $userid=0, $mode= 'customer', $typentid=0, $categid=0)
Constructor.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
_getAllByYear($sql)
Return nb of elements, total amount and avg amount each 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)
Return the amount per month for a given year.
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 Return the amount average par month for a giv...
Class to manage proposals statistics.
Class to manage proposals.