# `Sp_Check_sSmi` (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_sSmi`'`._

## Narrative

**Business context:** 半成品入库 (semi-goods inbound) post-save validator on `sgdsemigoodsinstoremaster`/`sgdsemigoodsinstoreslave`. Two-part enforcement: (1) 红冲 (red-strike reversal) entries must net to zero against the source bill, and (2) the inbound qty per `sSrcSlaveId` cannot exceed the upstream 半成品入库申请 (`sgdsemigoodsinstoreapplyslave.dProcessQty`).

**What it does:** Sets defaults. Reads `sMinusSrcId` from the master; if set, sums all linked reversal-slave `dProcessQty` against the original — non-zero net triggers `sCcprkHaveRedData` ("已存在红冲数据，不允许重复提交"). Opens a cursor over slave rows; for each `sSrcSlaveId` joins `sgdsemigoodsinstoreapplyslave` and accumulates over-quantity with bill numbers, emits localized `sSmiProductNameInBcp[Order]` + `sSmiQtyUpApply` ("数量已超过申请数量") on overage. Aborts with `sCode=-1` if `sReturn` non-empty, otherwise chains `Sp_afterSave_sSmi`.

**Invocation:** Status: appears orphaned. No `gdsmodule.sSaveProName`/`sSaveProNameBefore` hook, no `gdsconfigformmaster` binding, no other-routine caller in the live DB. The matching `Sp_beforeSave_sSmi`, `Sp_afterSave_sSmi`, `Sp_Calc_sSmi` siblings are all present (full family registered) and xly-src ships `script/标版/30100101/Sp_Check_sSmi.sql` as the install body — likely a 半成品入库 module wired only in deployments where the semi-goods workflow is enabled. Candidate for maintainer audit.
