Implement tax handling for branches by adding tax percent to regions, updating product sell costs, and enhancing UI for tax summaries in BranchView

This commit is contained in:
Torsten Schulz (local)
2025-12-09 16:16:08 +01:00
parent 25d7c70058
commit 43d86cce18
15 changed files with 477 additions and 19 deletions

View File

@@ -228,10 +228,29 @@ async function initializeFalukantStockTypes() {
}
async function initializeFalukantProducts() {
await ProductType.bulkCreate([
// compute min/max cumulative tax across regions
const taxRows = await sequelize.query(`
WITH RECURSIVE ancestors AS (
SELECT id AS start_id, id, parent_id, tax_percent FROM falukant_data.region
UNION ALL
SELECT a.start_id, r.id, r.parent_id, r.tax_percent
FROM falukant_data.region r
JOIN ancestors a ON r.id = a.parent_id
), totals AS (
SELECT start_id, COALESCE(SUM(tax_percent), 0) AS total FROM ancestors GROUP BY start_id
)
SELECT COALESCE(MIN(total),0) AS min_total, COALESCE(MAX(total),0) AS max_total FROM totals
`, { type: sequelize.QueryTypes.SELECT });
const minTax = parseFloat(taxRows?.[0]?.min_total) || 0;
const maxTax = parseFloat(taxRows?.[0]?.max_total) || 0;
const factorMin = (minTax >= 100) ? 1 : (1 / (1 - minTax / 100));
const factorMax = (maxTax >= 100) ? 1 : (1 / (1 - maxTax / 100));
const baseProducts = [
{ labelTr: 'wheat', category: 1, productionTime: 2, sellCost: 7 },
{ labelTr: 'grain', category: 1, productionTime: 2, sellCost: 7 },
{ labelTr: 'carrot', category: 1, productionTime: 1, sellCost: 46},
{ labelTr: 'carrot', category: 1, productionTime: 1, sellCost: 5},
{ labelTr: 'fish', category: 1, productionTime: 2, sellCost: 7 },
{ labelTr: 'meat', category: 1, productionTime: 2, sellCost: 7 },
{ labelTr: 'leather', category: 1, productionTime: 2, sellCost: 7 },
@@ -261,7 +280,15 @@ async function initializeFalukantProducts() {
{ labelTr: 'shield', category: 4, productionTime: 5, sellCost: 60 },
{ labelTr: 'horse', category: 5, productionTime: 5, sellCost: 60 },
{ labelTr: 'ox', category: 5, productionTime: 5, sellCost: 60 },
], {
];
const productsToInsert = baseProducts.map(p => ({
...p,
sellCostMinNeutral: Math.ceil(p.sellCost * factorMin),
sellCostMaxNeutral: Math.ceil(p.sellCost * factorMax),
}));
await ProductType.bulkCreate(productsToInsert, {
ignoreDuplicates: true,
});
}

View File

@@ -302,6 +302,7 @@ const politicalOfficeBenefitTypes = [
{ tr: 'tax_exemption' },
{ tr: 'guard_protection' },
{ tr: 'court_immunity' },
{ tr: 'set_regionl_tax' },
];
const politicalOffices = [