From 7380f5901b398618b2b5f92c9d6f69f60daae9d6 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Tue, 16 Nov 2021 17:41:38 +0100 Subject: [PATCH 1/4] ZENDSI: fix margin calc with credit note --- htdocs/accountancy/customer/index.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/htdocs/accountancy/customer/index.php b/htdocs/accountancy/customer/index.php index 7dc88a6939a..8f23ee5c532 100644 --- a/htdocs/accountancy/customer/index.php +++ b/htdocs/accountancy/customer/index.php @@ -511,7 +511,7 @@ if ($conf->global->MAIN_FEATURES_LEVEL > 0) { // This part of code looks strange print "
\n"; print '
'; print ''; - print ''; + print ''; for ($i = 1; $i <= 12; $i++) { $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START ? $conf->global->SOCIETE_FISCAL_MONTH_START : 1) - 1; if ($j > 12) { @@ -529,7 +529,14 @@ if ($conf->global->MAIN_FEATURES_LEVEL > 0) { // This part of code looks strange } $sql .= " SUM(".$db->ifsql('MONTH(f.datef)='.$j, '(fd.total_ht-(fd.qty * fd.buy_price_ht))', '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((fd.total_ht-(fd.qty * fd.buy_price_ht))) as total"; + $sql .= ' SUM(CASE WHEN + MONTH(f.datef)='.$j.' + THEN (CASE WHEN fd.total_ht < 0 + THEN (-1 * (abs(fd.total_ht) - (fd.buy_price_ht * fd.qty * (fd.situation_percent / 100)))) + ELSE (fd.total_ht - (fd.buy_price_ht * fd.qty * (fd.situation_percent / 100))) + END) + ELSE 0 END) AS month'.str_pad($j, 2, '0', STR_PAD_LEFT); $sql .= " FROM ".MAIN_DB_PREFIX."facturedet as fd"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture as f ON f.rowid = fd.fk_facture"; $sql .= " WHERE f.datef >= '".$db->idate($search_date_start)."'"; From 8bb7f9c8fb34c399e8cf678c13c5adb68164d60b Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Tue, 16 Nov 2021 17:44:18 +0100 Subject: [PATCH 2/4] ZENDSI: fix margin calc with credit note --- htdocs/accountancy/customer/index.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/htdocs/accountancy/customer/index.php b/htdocs/accountancy/customer/index.php index 8f23ee5c532..87fe74e2c77 100644 --- a/htdocs/accountancy/customer/index.php +++ b/htdocs/accountancy/customer/index.php @@ -520,23 +520,22 @@ if ($conf->global->MAIN_FEATURES_LEVEL > 0) { // This part of code looks strange print ''; } print ''; - $sql = "SELECT '".$db->escape($langs->trans("Vide"))."' AS marge,"; for ($i = 1; $i <= 12; $i++) { $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START ? $conf->global->SOCIETE_FISCAL_MONTH_START : 1) - 1; if ($j > 12) { $j -= 12; } - $sql .= " SUM(".$db->ifsql('MONTH(f.datef)='.$j, '(fd.total_ht-(fd.qty * fd.buy_price_ht))', '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(CASE WHEN + $sql .= ' SUM(CASE WHEN MONTH(f.datef)='.$j.' THEN (CASE WHEN fd.total_ht < 0 THEN (-1 * (abs(fd.total_ht) - (fd.buy_price_ht * fd.qty * (fd.situation_percent / 100)))) ELSE (fd.total_ht - (fd.buy_price_ht * fd.qty * (fd.situation_percent / 100))) END) - ELSE 0 END) AS month'.str_pad($j, 2, '0', STR_PAD_LEFT); + ELSE 0 END) AS month'.str_pad($j, 2, '0', STR_PAD_LEFT).','; + } + $sql .= " SUM((fd.total_ht-(fd.qty * fd.buy_price_ht))) 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"; $sql .= " WHERE f.datef >= '".$db->idate($search_date_start)."'"; From e4803dda882c3165d2386ff4dcadad4595b7dc64 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Tue, 16 Nov 2021 17:46:12 +0100 Subject: [PATCH 3/4] ZENDSI: fix margin calc with credit note --- htdocs/accountancy/customer/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/accountancy/customer/index.php b/htdocs/accountancy/customer/index.php index 87fe74e2c77..54262c32dbd 100644 --- a/htdocs/accountancy/customer/index.php +++ b/htdocs/accountancy/customer/index.php @@ -511,7 +511,7 @@ if ($conf->global->MAIN_FEATURES_LEVEL > 0) { // This part of code looks strange print "
\n"; print '
'; print '
'.$langs->trans("TotalMarge").'
'.$langs->trans("TotalMarge").'SSSSS'.$langs->trans('MonthShort'.str_pad($j, 2, '0', STR_PAD_LEFT)).''.$langs->trans("Total").'
'; - print ''; + print ''; for ($i = 1; $i <= 12; $i++) { $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START ? $conf->global->SOCIETE_FISCAL_MONTH_START : 1) - 1; if ($j > 12) { From 0e8e8a79dc5911e41524660d9d752febf55a035d Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Thu, 18 Nov 2021 21:12:43 +0100 Subject: [PATCH 4/4] review code --- htdocs/accountancy/customer/index.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/htdocs/accountancy/customer/index.php b/htdocs/accountancy/customer/index.php index 54262c32dbd..a88524ec5d4 100644 --- a/htdocs/accountancy/customer/index.php +++ b/htdocs/accountancy/customer/index.php @@ -526,13 +526,14 @@ if ($conf->global->MAIN_FEATURES_LEVEL > 0) { // This part of code looks strange if ($j > 12) { $j -= 12; } - $sql .= ' SUM(CASE WHEN - MONTH(f.datef)='.$j.' - THEN (CASE WHEN fd.total_ht < 0 - THEN (-1 * (abs(fd.total_ht) - (fd.buy_price_ht * fd.qty * (fd.situation_percent / 100)))) - ELSE (fd.total_ht - (fd.buy_price_ht * fd.qty * (fd.situation_percent / 100))) - END) - ELSE 0 END) 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"; @@ -552,7 +553,6 @@ if ($conf->global->MAIN_FEATURES_LEVEL > 0) { // This part of code looks strange } else { $sql .= " AND f.type IN (".Facture::TYPE_STANDARD.", ".Facture::TYPE_REPLACEMENT.", ".Facture::TYPE_CREDIT_NOTE.", ".Facture::TYPE_DEPOSIT.", ".Facture::TYPE_SITUATION.")"; } - dol_syslog('htdocs/accountancy/customer/index.php'); $resql = $db->query($sql); if ($resql) {
'.$langs->trans("TotalMarge").'SSSSS
'.$langs->trans("TotalMarge").'