mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2026-02-07 16:41:48 +01:00
Work on graphical box with product distribution
This commit is contained in:
@@ -66,16 +66,18 @@ class CommandeStats extends Stats
|
||||
{
|
||||
$object=new Commande($this->db);
|
||||
$this->from = MAIN_DB_PREFIX.$object->table_element." as c";
|
||||
//$this->from.= ", ".MAIN_DB_PREFIX."societe as s";
|
||||
$this->from_line = MAIN_DB_PREFIX.$object->table_element_line." as tl";
|
||||
$this->field='total_ht';
|
||||
$this->field_line='total_ht';
|
||||
$this->where.= " c.fk_statut > 0"; // Not draft and not cancelled
|
||||
}
|
||||
if ($mode == 'supplier')
|
||||
{
|
||||
$object=new CommandeFournisseur($this->db);
|
||||
$this->from = MAIN_DB_PREFIX.$object->table_element." as c";
|
||||
//$this->from.= ", ".MAIN_DB_PREFIX."societe as s";
|
||||
$this->from_line = MAIN_DB_PREFIX.$object->table_element_line." as tl";
|
||||
$this->field='total_ht';
|
||||
$this->field_line='total_ht';
|
||||
$this->where.= " c.fk_statut > 2"; // Only approved & ordered
|
||||
}
|
||||
//$this->where.= " AND c.fk_soc = s.rowid AND c.entity = ".$conf->entity;
|
||||
@@ -191,6 +193,29 @@ class CommandeStats extends Stats
|
||||
|
||||
return $this->_getAllByYear($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return nb, amount of predefined product for year
|
||||
*
|
||||
* @param int $year Year to scan
|
||||
* @return array Array of values
|
||||
*/
|
||||
function getAllByProduct($year)
|
||||
{
|
||||
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.", ".$this->from_line.", ".MAIN_DB_PREFIX."product as product";
|
||||
//if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
$sql.= " WHERE ".$this->where;
|
||||
$sql.= " AND c.rowid = tl.fk_commande AND tl.fk_product = product.rowid";
|
||||
$sql.= " GROUP BY product.ref";
|
||||
$sql.= $this->db->order('nb','DESC');
|
||||
$sql.= $this->db->plimit(20);
|
||||
|
||||
return $this->_getAllByProduct($sql);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user