# `Sp_Check_sYzfy` (procedure)

> 预支费用保存之前数据校验


- **Type:** PROCEDURE
- **Deterministic:** NO
- **SQL data access:** CONTAINS SQL

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `sTableName` | `varchar(100)` |
| 2 | IN | `sGuid` | `varchar(100)` |
| 3 | IN | `sFormGuid` | `varchar(100)` |
| 4 | IN | `sLoginId` | `varchar(100)` |
| 5 | IN | `sBrId` | `varchar(100)` |
| 6 | IN | `sSuId` | `varchar(100)` |
| 7 | IN | `iFlag` | `int` |
| 8 | OUT | `sCode` | `int` |
| 9 | OUT | `sReturn` | `varchar(4000)` |

## Body

_Body is not pre-cached. To inspect: `mysql --defaults-file=~/.my.cnf -e 'SHOW CREATE PROCEDURE `Sp_Check_sYzfy`'`._

## Narrative

**Business context:** 预支费用 (advance-cost claim) post-save validator on `advanceCostCheckMaster`/`advanceCostCheckslave`. Recomputes the remaining budget (`dLimit`) and the full-year budget (`dBudgetYearAmount`) for each claim line by joining `departmentalBudgetslave` of the approved `departmentalbudgetmaster` for the claim's dept + year, then computing the cumulative monthly budget through the current month minus `dSumUseMoney`.

**What it does:** Reads `NetMoney`/`NetPrice`, resolves `sYear`/`sMonth`/`sMasterDepartId` from `advanceCostCheckMaster`. Zeroes `dLimit` and `dBudgetYearAmount` on all slave rows. Re-updates them by joining `departmentalBudgetslave` (filtered by the dept's approved budget master, matching `sExpenseDetailId`) — sets `dLimit` to the running `dJanuaryBudget+...+d<Month>Budget - dSumUseMoney` matching the master's month (via a 12-branch CASE), and `dBudgetYearAmount` to the corresponding cumulative. Acts as a refresh-only hook — no abort branch on overspend is wired in the snapshot, so the proc never actually rejects a claim.

**Invocation:** Status: appears orphaned. No `gdsmodule.sSaveProName`/`sSaveProNameBefore` hook in the current DB snapshot, no form-master binding, no other-routine caller, no xly-src reference. The 预算 (budget) module family is staged but not wired into the live UI — the only 预算 module in `gdsmodule` is `年度费用预算KPI设定(暂不开放)` (marked "not yet open"). Candidate for maintainer audit on whether 预支费用 was meant to ship alongside `Sp_Check_sYstb` and `Sp_Check_sYstz`.
