# `Sp_beforeSave_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_beforeSave_sYzfy`'`._

## Narrative

**Business context:** 预支费用 (Advance-expense reimbursement) — pre-save budget validator for the advance-cost document. Header comment: `预支费用保存之前数据校验`. Looks up the master row's create-date year/month and department, then refreshes each `advanceCostCheckslave` line's `dLimit` / `dBudgetYearAmount` against the matching `departmentalbudgetmaster` / `…slave` row for that year / department.

**What it does:** Reads `NetMoney` and `NetPrice` decimal-places from `SysSystemSettings`. Pulls `tCreateDate`/`sMasterDepartId` from `advanceCostCheckMaster` for `sGuid`. Zeroes the slave's `dLimit` and `dBudgetYearAmount`. Builds a cumulative-budget CTE over `departmentalBudgetslave` (Jan + Feb + …) joined to `departmentalbudgetmaster` filtered by `bCheck=1`, `sDepartId`, `sYear`, `sBrandsId`, `sSubsidiaryId`. Two passes — one `Select` (likely a debug remnant — the result is not captured), one `Update advanceCostCheckslave` that writes the month-cumulative budget remaining (`dBudgetYearAmount = monthBudget − dSumUseMoney`) into each line keyed by `sExpenseDetailId`. Also issues `call Sp_afterSave_sDgn(…)` near the top — purpose unclear given this is the 预支费用 routine and `_sDgn` is the delivery-notify writeback.

**Invocation:** Status: appears orphaned. No caller in any channel — no `gdsmodule` hook, no form-master reference, no entry in the backwriting dispatchers, no xly-src hit. The 9-arg signature (extra `sTableName`, `sFormGuid`, `sLoginId`, `iFlag`) does not match any framework save-hook contract, so it cannot be wired through standard `sSaveProNameBefore`. Candidate for maintainer audit.

Flag: stray `call Sp_afterSave_sDgn(…)` inside a 预支费用 budget-check routine looks like a paste error from a delivery-notify template.
