From b50d2a9a930d6e19eee3809567020f4fedd1337b Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Mon, 13 Apr 2026 16:05:41 +0200 Subject: [PATCH] feat(falukant): refine tax calculation logic to handle political office exemptions - Updated the tax calculation in FalukantService to ensure no exemptions are applied for political offices, streamlining the cumulative tax query. - Enhanced the SQL query to accurately compute cumulative tax while excluding exempted ancestor levels based on office, improving overall accuracy in tax assessments. --- backend/services/falukantService.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/backend/services/falukantService.js b/backend/services/falukantService.js index 2751f6c..11d13b1 100644 --- a/backend/services/falukantService.js +++ b/backend/services/falukantService.js @@ -355,7 +355,12 @@ async function calcRegionalSellPrice(product, knowledgeFactor, regionId, worthPe // If chancellor, exempt all region types -> tax = 0 if (hasChancellor) return 0; - // Now compute cumulative tax but exclude regions whose regionType.labelTr is in exemptTypes + // No exemptions from political offices -> use normal cumulative tax query. + if (exemptTypes.size === 0) { + return await getCumulativeTaxPercent(regionId); + } + + // Compute cumulative tax excluding ancestor levels that are exempted by office. const rows = await sequelize.query( `WITH RECURSIVE ancestors AS ( SELECT r.id, r.parent_id, r.tax_percent, rt.label_tr as region_type @@ -368,7 +373,11 @@ async function calcRegionalSellPrice(product, knowledgeFactor, regionId, worthPe JOIN falukant_type.region_type rt2 ON rt2.id = reg.region_type_id JOIN ancestors a ON reg.id = a.parent_id ) - SELECT COALESCE(SUM(CASE WHEN :exempt_types::text[] && ARRAY[region_type] THEN 0 ELSE tax_percent END),0) AS total FROM ancestors;`, + SELECT COALESCE( + SUM(CASE WHEN region_type IN (:exempt_types) THEN 0 ELSE tax_percent END), + 0 + ) AS total + FROM ancestors;`, { replacements: { id: regionId, exempt_types: Array.from(exemptTypes) }, type: sequelize.QueryTypes.SELECT