425
Planning
Budgets
Twelve months per account for one cost center. Saving runs one batch of MERGE statements.
How this works - feature 425 A 12-month budget per account and cost center.
Concepts
- One row per year / account / cost center / month, protected by a UNIQUE constraint.
- Saving the grid runs one batch of MERGE statements: update, insert or delete each cell.
- 'Fill from actual' copies last year's figures (or this year's) +/- a percentage.
Read the code
service/BudgetService#savedomain/BudgetLine
SQL behind this page
MERGE budget_line AS t
USING (SELECT :year AS fiscal_year, :account AS account_id, :cc AS cost_center_id, :month AS period_month, :amount AS amount) AS s
ON t.fiscal_year = s.fiscal_year AND t.account_id = s.account_id
AND t.cost_center_id = s.cost_center_id AND t.period_month = s.period_month
WHEN MATCHED AND s.amount = 0 THEN DELETE
WHEN MATCHED THEN UPDATE SET amount = s.amount
WHEN NOT MATCHED AND s.amount <> 0 THEN
INSERT (fiscal_year, account_id, cost_center_id, period_month, amount)
VALUES (s.fiscal_year, s.account_id, s.cost_center_id, s.period_month, s.amount);