Skip to content

Commit

Permalink
Merge pull request #23941 from ATM-Consulting/FIX_propalestats_SQL_un…
Browse files Browse the repository at this point in the history
…known_column_fk_soc

FIX: SQL error "unknown column p.fk_soc"
  • Loading branch information
eldy authored Mar 3, 2023
2 parents eaaee09 + b29ebef commit 89810f9
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions htdocs/comm/propal/class/propalestats.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,13 +248,14 @@ public function getAllByProduct($year, $limit = 10)
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";
$sql .= " FROM ".$this->from;
$sql .= " INNER JOIN ".$this->from_line." ON p.rowid = tl.fk_propal";
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."product as product ON tl.fk_product = product.rowid";
if (empty($user->rights->societe->client->voir) && !$user->socid) {
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON p.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
}
$sql .= $this->join;
$sql .= " WHERE ".$this->where;
$sql .= " AND p.rowid = tl.fk_propal AND tl.fk_product = product.rowid";
$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))."'";
$sql .= " GROUP BY product.ref";
$sql .= $this->db->order('nb', 'DESC');
Expand Down

0 comments on commit 89810f9

Please sign in to comment.