# `Sp_check_productstoreLimitNew` (procedure)

> 校验材料库存是否够用


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

## Parameters

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

## Body

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

## Narrative

**Business context:** 库存控制公共校验 — pre-save inventory-availability gate for any out-going material/product document. Runs `Sp_Sis_GetProductInventoryFormGuid` to classify the calling `sFormGuid` as inbound vs outbound, exempts inbound, and rejects an outbound save when the projected on-hand `dProductQty` would go negative or fall below `dMinProductQty` for any line.

**What it does:** Resolves the form's direction (`p_iAdd=1` in / `2` out via INSTR against `@sInSql`/`@sOutSql`), flips direction on an unaudit (`iFlag=0`). Looks up the latest frozen period from `sysaccountperiod` and aborts if `tCreateDate` falls before the closed cutoff. Builds a temporary `sp_pitproductstorebarcode` of the document's lines and joins live stock from `mitmaterialsstoremaster`/`pitproductstoremaster` (depending on `sTbName`) to compute residual qty, populates `p_sMaterialsNames` with any line that breaks the limit, and returns `sCode=-1, sReturn='<物料> 库存不足'` to abort the save.

**Invocation:** Status: no direct caller found. No `gdsmodule.sSaveProNameBefore` / `sProcName` binding, no other proc references the name, no `xly-src` hit. The naming and the `sTbName` parameter suggest it is the next-gen replacement for an older `Sp_check_productstoreLimit` (see siblings) and is reserved for a future generic pre-save dispatch — candidate for maintainer audit.
