# `Sp_System_SaveReport` (procedure)

> 本期间已结账不允许保存


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

## Parameters

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

## Body

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

## Narrative

**Business context:** 系统 → 业务单据保存校验 (header comment: "本期间已结账不允许保存"). A POST-save guard: when a user saves any bill whose `tCreateDate` falls in a 会计期间 that has been frozen (`sysaccountperiod.bFrozen=1`), the save is rejected. Acts as the default 期间已结账 check; modules with finer rules layer their own checks on top.

**What it does:** Reads `SysSystemSettings('CkxfirstInspection')` (unused after read — looks like a partial port). Pulls the master `sTbName` for the given `sFormGuid` from `gdsconfigformmaster sparentid=sFormGuid` (the first slave entry, `ORDER BY iincrement LIMIT 1`). Builds dynamic SQL `SELECT count(A.sPeriodID) FROM sysaccountperiod a WHERE bFrozen=1 AND sPeriodID = (SELECT date_format(tCreateDate,'%Y%m') FROM <tbname> WHERE sId='<sGuid>')` via PREPARE/EXECUTE. If the count is 1 (i.e. the bill's create-month is closed) sets `sCode=-1, sReturn='本月已结账，不允许保存本月内单据！'` and `LEAVE top`.

**Invocation:** Status: appears orphaned. No `gdsmodule.sSaveProName`/`sSaveProNameBefore` binding (despite the name pattern suggesting `Sp_System_SaveReport` would be the universal pre-save hook), no form-master, no other-proc, no xly-src caller. Either dispatched via a string-keyed lookup invisible to grep, or — more likely — never wired in. The variable name typo `p_TableName` initialised once with the *first* slave's table, not the master table, suggests this proc was prototyped but not deployed. Candidate for maintainer audit.
