diff --git a/htdocs/accountancy/customer/index.php b/htdocs/accountancy/customer/index.php index 06e788bab51..b7ec854fd7c 100644 --- a/htdocs/accountancy/customer/index.php +++ b/htdocs/accountancy/customer/index.php @@ -638,13 +638,15 @@ if ($conf->global->MAIN_FEATURES_LEVEL > 0) { // This part of code looks strange if ($j > 12) { $j -= 12; } - $sql .= ' SUM('.$db->ifsql('MONTH(f.datef)='.$j, - ' ('.$db->ifsql('fd.total_ht < 0', - ' (-1 * (abs(fd.total_ht) - (fd.buy_price_ht * fd.qty * (fd.situation_percent / 100))))', - ' (fd.total_ht - (fd.buy_price_ht * fd.qty * (fd.situation_percent / 100)))').')', - 0).') AS month'.str_pad($j, 2, '0', STR_PAD_LEFT).','; + $sql .= " SUM(".$db->ifsql("MONTH(f.datef)=".$j, + " (".$db->ifsql("fd.total_ht < 0", + " (-1 * (abs(fd.total_ht) - (fd.buy_price_ht * fd.qty * (fd.situation_percent / 100))))", + " (fd.total_ht - (fd.buy_price_ht * fd.qty * (fd.situation_percent / 100)))").")", + 0).") AS month".str_pad($j, 2, '0', STR_PAD_LEFT).","; } - $sql .= " SUM((fd.total_ht-(fd.qty * fd.buy_price_ht))) as total"; + $sql .= " SUM(".$db->ifsql("fd.total_ht < 0", + " (-1 * (abs(fd.total_ht) - (fd.buy_price_ht * fd.qty * (fd.situation_percent / 100))))", + " (fd.total_ht - (fd.buy_price_ht * fd.qty * (fd.situation_percent / 100)))").") as total"; $sql .= " FROM ".MAIN_DB_PREFIX."facturedet as fd"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture as f ON f.rowid = fd.fk_facture";