# `Sp_Inventory_MaterialsInventory_Outdated` (procedure)

> 材料库龄分析详情表


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

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `iType` | `int` |
| 2 | IN | `sBrId` | `varchar(100)` |
| 3 | IN | `sSuId` | `varchar(100)` |
| 4 | IN | `bFilter` | `varchar(5000)` |
| 5 | IN | `sUnTaskFormId` | `varchar(100)` |
| 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_MaterialsInventory_Outdated`'`._

## Narrative

**Business context:** 材料库存 → 材料库存查询 → 库存呆滞料分析表 (material slow-moving / dead-stock analysis — "材料库龄分析详情表" per the page header). Buckets materials by how long the stock has been sitting in the warehouse (库龄 / inventory age), highlighting items that have not turned over within the threshold so purchasing/production can decide on consumption or write-down.

**What it does:** Builds working tables `p_elematerialsstock_table`, `sp_mitmaterialsstore`, `sp_mitmaterialsstore_iRowNum`, `sp_mitmaterialsstore_sy` from `elematerialsstock` + `mitmaterialsstore`, ranks per-material lots by row number to identify the oldest residual quantities, computes their age vs. the reference date, then paginates the aging report. Form-config constants come from `Sp_Sis_GetMertialsInventoryFormGuid`.

**Invocation:** Bound as the data source of form 库存呆滞料分析表 (sId `101801153119616611588427900`) under 材料库存 → 材料库存查询 → 库存呆滞料分析表 — loaded when the user opens the report. No other DB or `xly-src` callers.
