# `Sp_Inventory_ProductWarning` (procedure)


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

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `iType` | `int` |
| 2 | IN | `tEndDate` | `datetime` |
| 3 | IN | `sBrId` | `varchar(100)` |
| 4 | IN | `sSuId` | `varchar(100)` |
| 5 | IN | `bFilter` | `varchar(5000)` |
| 6 | IN | `pageNum` | `int` |
| 7 | IN | `pageSize` | `int` |
| 8 | OUT | `totalCount` | `int` |
| 9 | IN | `countCloumn` | `varchar(5000)` |
| 10 | OUT | `countMapJson` | `longtext` |
| 11 | IN | `sFilterOrderBy` | `varchar(5000)` |
| 12 | IN | `sGroupby_select_sql` | `varchar(5000)` |
| 13 | IN | `sGroupby_group_sql` | `varchar(5000)` |

## Body

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

## Narrative

**Business context:** 成品库存 → 预警报表 → 成品库存不足预警表 / 成品库存超量预警表 — finished-product stock-out and over-stock warning report. `iType` switches between the two views: low-stock (qty below `dMinStock`) and over-stock (qty above `dMaxStock`).

**What it does:** Defaults `tEndDate` to NOW (+ 1 day) and zero-clears NULLs. Builds temp table `p_TMP_ProductWarning` shaped like `eleproductstock` extended with `dMinStock` / `dMaxStock` / `iProductioning` / display columns. Populates from `eleproductstock` joined to `eleproduct` for the min/max thresholds, computes in-production qty (`iProductioning`) from work-order tables, and selects the rowset filtered by `iType` (0 = 库存不足, 1 = 库存超量). Paginates / counts through `Sp_Outstanding_Query`.

**Invocation:** Bound as the data source of two form-masters under 成品库存 → 预警报表: `19211681015115285244387250` (成品库存不足预警表) and `19211681015115285246087340` (成品库存超量预警表) — the same proc backs both with `iType` differentiating. Function `Fun_getInitColumnByProName` references it for column metadata. xly-src ships `script/标版/30100101/Sp_Inventory_ProductWarning.sql` and `script/标版/optimize/Sp_Inventory_ProductWarning.sql`.
