# `Sp_MaterialAgingAnalysis` (procedure)

> 材料库龄分析表


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

## Parameters

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

## Body

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

## Narrative

**Business context:** 材料库存 — paged 材料库龄分析表 (material aging analysis). Buckets every on-hand material row by how long it has sat in stock, grouped against a fixed allow-list of inventory `sFormId`s (raw-material, finished-stock, virtual-store, etc.) so the user can see what is "stuck" in the warehouse.

**What it does:** Builds the temp `P_Tmp_sFromId` with a hard-coded list of inventory `sFormId` values (`'192116810113315220315711060'`, `'192116810113315226622476570'`, `'101251168116315839165634020'`, ...). Populates `P_Tmp_Materials_List` from `elematerialsstock` / `mitmaterialsstore` / `PitMaterialsStore` filtered by those forms, rolls up into `P_Tmp_Materials_List_Group` (per material × style with aging buckets), and finally `P_Tmp_Materials_List_return` is the output staging picked up by the report grid through the standard `bFilter / sFilterOrderBy / sGroupby_*` paging contract.

**Invocation:** No form-master binding, no gdsmodule hook, no other-routine reference, no Java caller — install script ships at `script/标版/30100101/Sp_MaterialAgingAnalysis.sql` plus a performance patch at `script/标版/optimize/Sp_MaterialAgingAnalysis.sql`. Status: appears orphaned in this database. Likely the production data-source for an aging-analysis report that has not been wired to a form-master in the current `xlyweberp_saas_ai` instance; candidate for maintainer audit / form-master verification.
