# `Sp_sYzfy_JN` (procedure)

> 费用预支填报计算


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

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `sDropTableSql` | `longtext` |
| 2 | IN | `sCreateTableSql` | `longtext` |
| 3 | IN | `insertSql` | `longtext` |
| 4 | IN | `selectSql` | `longtext` |
| 5 | IN | `sFormGuid` | `varchar(100)` |
| 6 | IN | `sLoginId` | `varchar(100)` |
| 7 | IN | `sBrId` | `varchar(100)` |
| 8 | IN | `sSuId` | `varchar(100)` |

## Body

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

## Narrative

**Business context:** 费用管理 → 费用预支 (advance-expense reimbursement filing). Header comment: "费用预支填报计算". Customer-specific (the `_JN` suffix marks a 客户=JN tenant variant). Drives the in-form preview calculation of an 费用预支单 row's monthly budget remaining: takes the staged temp tables the front-end uploads, executes them, then pivots the department's `departmentalbudgetmaster`/`departmentalbudgetslave` monthly budget against current 已用金额 to populate `dLimit`/`dBudgetYearAmount` on each 费用预支 slave row.

**What it does:** Parameters are four longtext SQL bundles + form/login/brand context. Splits each `sDropTableSql`, `sCreateTableSql`, `insertSql` on `;` and runs every fragment via `PREPARE`/`EXECUTE`/`DEALLOCATE` to drop, create, and seed the per-session temp tables (the form's calc temp `advanceCostCheckMaster_calc_tmp` / `advanceCostCheckslave_calc_tmp` and similar `purpurchaseorderslave_calc_tmp` shapes). After the dynamic-SQL phase reads `sMasterDepartId` + create-year/month from `advanceCostCheckMaster_calc_tmp`, resets `dLimit=0,dBudgetYearAmount=0` on the slave, then joins to `departmentalbudgetslave`/`departmentalbudgetmaster` (filtered by `sDepartId`, `sYear`, `bCheck=1`) and updates `dLimit` to the cumulative monthly budget (Jan + Feb + … + selected month) minus `dSumUseMoney`.

**Invocation:** Status: appears orphaned in this baseline. No `gdsmodule` binding, no form-master, no other-proc, no xly-src match. The `_JN` suffix and the "JN" tenant convention identify this as a customer-override — likely installed under the JN tenant's customer folder (e.g. `script/客户/JN/`) which this baseline doesn't ship. Production dispatch is via `GenericProcedureCallServiceImpl.doGenericProcedureCall()` from the 费用预支填报 form's 计算 toolbar button when the tenant is JN. Candidate for maintainer audit at the JN deployment.
