# `Sp_Calc_sBac` (procedure) > 预算调整审批 - **Type:** PROCEDURE - **Deterministic:** NO - **SQL data access:** CONTAINS SQL ## Parameters | # | Mode | Name | Type | |---|---|---|---| | 1 | IN | `iFlag` | `int` | | 2 | IN | `iTmpCheck` | `int` | | 3 | IN | `sFormGuid` | `varchar(100)` | | 4 | IN | `sGuid` | `varchar(100)` | | 5 | IN | `sLoginId` | `varchar(100)` | | 6 | OUT | `sReturn` | `varchar(4000)` | | 7 | IN | `sBrId` | `varchar(100)` | | 8 | IN | `sSuId` | `varchar(100)` | | 9 | OUT | `sCode` | `int` | ## Body _Body is not pre-cached. To inspect: `mysql --defaults-file=~/.my.cnf -e 'SHOW CREATE PROCEDURE `Sp_Calc_sBac`'`._ ## Narrative **Business context:** 预算管理 / 预算调整审批 — budget-adjustment check / uncheck on `budgetAdjustmentCheckMaster`. On approval, posts each slave-row adjustment amount (`dMaterialsMoney`) into the right monthly column of the target department-budget row (`departmentalBudgetslave.dBudget`) plus the yearly `dSumBudget`. **What it does:** Validates `sGuid`. Reads `tCreateDate` (for year/month derivation), `sMasterDepartId`, and `bInvalid` from `budgetAdjustmentCheckMaster`; refuses if invalid. With `iFlag=1`: refuses if already checked. Resolves the bill's year/month via `DATE_FORMAT(tCreateDate, '%Y'/'%m')`. Then, on each of the twelve `ELSEIF p_sMonth='01'..='12'` branches, runs `UPDATE departmentalBudgetslave B JOIN budgetadjustmentcheckslave A ON A.sAfterExpenseDetailId=B.sExpenseDetailId JOIN departmentalbudgetmaster C ON B.sParentId=C.sId SET B.dBudget = B.dBudget + A.dMaterialsMoney WHERE A.sParentId=sGuid AND C.sDepartId=p_sMasterDepartId AND C.sYear=p_sYear AND C.bCheck=1`. Finally bumps `dSumBudget` and `budgetmaster` totals for adjustment types 1 or 2; reverses on uncheck (not shown in fragment). **Invocation:** Status: appears orphaned in this DB instance. No `gdsmodule.sProcName/sCalcProName`, form-master, routine, or xly-src caller. Likely bound from a customer-specific budget-management module override (the budget tables suggest a customised 部门预算 module). Standard `Sp_Calc_*` check-hook signature. Flag: per-month dispatch is a 12-way ELSEIF chain — fragile if the bill's `tCreateDate` month differs from the budget month the adjustment is *for*; the proc uses the create-date month rather than a dedicated `iAdjustmentMonth` column.