diff --git a/backend/services/falukantService.js b/backend/services/falukantService.js index 0b159b2..d564be2 100644 --- a/backend/services/falukantService.js +++ b/backend/services/falukantService.js @@ -194,6 +194,12 @@ async function calcRegionalSellPrice(product, knowledgeFactor, regionId, worthPe if (hasChancellor) return 0; // Now compute cumulative tax but exclude regions whose regionType.labelTr is in exemptTypes + // Konvertiere exemptTypes Set zu einem PostgreSQL-Array-String + const exemptTypesArray = Array.from(exemptTypes); + const exemptTypesString = exemptTypesArray.length > 0 + ? `ARRAY[${exemptTypesArray.map(t => `'${t.replace(/'/g, "''")}'`).join(',')}]` + : `ARRAY[]::text[]`; + const rows = await sequelize.query( `WITH RECURSIVE ancestors AS ( SELECT r.id, r.parent_id, r.tax_percent, rt.label_tr as region_type @@ -206,9 +212,9 @@ 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 ${exemptTypesString} && ARRAY[region_type] THEN 0 ELSE tax_percent END),0) AS total FROM ancestors;`, { - replacements: { id: regionId, exempt_types: Array.from(exemptTypes) }, + replacements: { id: regionId }, type: sequelize.QueryTypes.SELECT } );