Merge pull request #13943 from atm-maxime/fix_pgsql_if

Fix SQL IF for PGSQL
This commit is contained in:
Laurent Destailleur 2020-05-23 13:41:18 +02:00 committed by GitHub
commit afacfa702d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -136,9 +136,9 @@ if ($id > 0 || ! empty($ref))
$sql.= " f.datef, f.paye, f.fk_statut as statut, f.type,";
if (!$user->rights->societe->client->voir && !$socid) $sql.= " sc.fk_soc, sc.fk_user,";
$sql.= " sum(d.total_ht) as selling_price,"; // may be negative or positive
$sql.= " IF(f.type = 2, -1, 1) * sum(d.qty) as qty,"; // not always positive in case of Credit note
$sql.= " IF(f.type = 2, -1, 1) * sum(d.qty * d.buy_price_ht) as buying_price,"; // not always positive in case of Credit note
$sql.= " IF(f.type = 2, -1, 1) * sum(abs(d.total_ht) - (d.buy_price_ht * d.qty)) as marge" ; // not always positive in case of Credit note
$sql.= " ".$db->ifsql('f.type = 2', -1, 1)." * sum(d.qty) as qty,"; // not always positive in case of Credit note
$sql.= " ".$db->ifsql('f.type = 2', -1, 1)." * sum(d.qty * d.buy_price_ht) as buying_price,"; // not always positive in case of Credit note
$sql.= " ".$db->ifsql('f.type = 2', -1, 1)." * sum(abs(d.total_ht) - (d.buy_price_ht * d.qty)) as marge" ; // not always positive in case of Credit note
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
$sql.= ", ".MAIN_DB_PREFIX."facture as f";
$sql.= ", ".MAIN_DB_PREFIX."facturedet as d";