feat(falukant): refine tax calculation logic to handle political office exemptions
All checks were successful
Deploy to production / deploy (push) Successful in 2m41s

- 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.
This commit is contained in:
Torsten Schulz (local)
2026-04-13 16:05:41 +02:00
parent f92b62e55b
commit b50d2a9a93

View File

@@ -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