# `Sp_calc_productstoreLimit` (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 | `sCustomerGuid` | `varchar(100)` |
| 4 | IN | `tCreateDate` | `datetime` |
| 5 | IN | `sBrId` | `varchar(100)` |
| 6 | IN | `sSuId` | `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_calc_productstoreLimit`'`._

## Narrative

**Business context:** 库存管理 — finished-product-inventory month-end-limit helper, the 成品 (product) counterpart of `Sp_calc_materialsstoreLimit`. Per the proc comment: "审核包含自身，消审不包含自身 消审要在删除库存明细前调用，审核再插入库存明细后调用".

**What it does:** Validates required params (`sGuid`, `sFormGuid`, `tCreateDate`, brand/subsidiary, `iFlag`) — note `sCustomerGuid` is *not* required. Loads the latest frozen `sysaccountperiod.tEndDate`, decides current-vs-closed-period bracket, and drives the per-product inventory recalc based on `iFlag` (1=check, 0=uncheck). Tracks bill numbers for messaging and gates inserts against the closed period.

**Invocation:** Called from the `Sp_Calc_s*` finished-product bill-check procs that mutate product inventory: `Sp_Calc_sDgd`, `Sp_Calc_sDgdCL`, `Sp_Calc_sOpi`, `Sp_Calc_sPaj`, `Sp_Calc_sPck`, `Sp_Calc_sPit`, `Sp_Calc_sPsa`, `Sp_Calc_sPst`, `Sp_Calc_sPtr`, `Sp_Calc_sRgd`, etc. — each calls this proc during its check/uncheck path. xly-src refs are in customer SQL bundles under `script/标版/`.
