# `Sp_Inventory_MaterialsWarning` (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 | `sLoginId` | `varchar(100)` |
| 6 | IN | `bFilter` | `varchar(5000)` |
| 7 | IN | `pageNum` | `int` |
| 8 | IN | `pageSize` | `int` |
| 9 | OUT | `totalCount` | `int` |
| 10 | IN | `countCloumn` | `varchar(5000)` |
| 11 | OUT | `countMapJson` | `longtext` |
| 12 | IN | `sFilterOrderBy` | `varchar(5000)` |
| 13 | IN | `sGroupby_select_sql` | `varchar(5000)` |
| 14 | 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_MaterialsWarning`'`._

## Narrative

**Business context:** 材料库存 → 分析报表 — material stock-level alert driver. Powers both the over-stock alarm (材料库存超量预警表) and the under-stock alarm (材料库存不足预警表) by listing materials whose current stock breaches the upper or lower threshold from `elematerialssafe`.

**What it does:** Builds working table `p_TMP_MaterialsWarning` (and secondary `p_TMP_MaterialsWarning_2` / `p_TMP_MaterialsWarning_` for per-material/per-style breakdowns) by joining `elematerials` to `elematerialssafe` (the per-material 安全库存 thresholds) and netting against `elematerialsstock` + `mitmaterialsstorevirtual` (locked stock). Joined to `siswarehouse` for per-warehouse splits. Form switches between over- and under-stock predicates based on `bFilter`. Final rowset paginated via `Sp_Outstanding_Query`.

**Invocation:** Bound as the data source of both 材料库存超量预警表 (sId `19211681015115282648096630`) and 材料库存不足预警表 (sId `19211681015115282651657340`) under 材料库存 → 分析报表 via `gdsconfigformmaster.sSqlStr`. Also referenced by `Fun_getInitColumnByProName` (returned-column metadata). xly-src ships both `script/标版/30100101/Sp_Inventory_MaterialsWarning.sql` (install) and `script/标版/optimize/Sp_Inventory_MaterialsWarning.sql` (performance patch) — verify which is deployed.
