# `Sp_Inventory_MaterialsInventoryV56` (procedure)


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

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `sMaterialsGuid` | `varchar(4000)` |
| 2 | IN | `sMaterialsClassifyGuid` | `varchar(100)` |
| 3 | IN | `sWarehouseGuid` | `varchar(100)` |
| 4 | IN | `iHasZero` | `int` |
| 5 | IN | `sMaterialsStyle` | `varchar(100)` |
| 6 | IN | `iGetQty` | `int` |
| 7 | IN | `sDefine_no` | `varchar(100)` |
| 8 | IN | `sDefine_no2` | `varchar(100)` |
| 9 | OUT | `dAuxiliaryQty` | `decimal(18,6)` |
| 10 | OUT | `dMaterialsQty` | `decimal(18,6)` |
| 11 | OUT | `dMaterialsPrice` | `decimal(18,6)` |
| 12 | IN | `iSumQty` | `int` |
| 13 | IN | `iSales` | `int` |
| 14 | IN | `iDetailStock` | `int` |
| 15 | IN | `iAdditionalMaterialInfo` | `int` |
| 16 | IN | `sLocationalGuid` | `varchar(100)` |
| 17 | IN | `sWarehouseLocationGuid` | `varchar(100)` |
| 18 | IN | `iMaterialsType` | `int` |
| 19 | IN | `sBrId` | `varchar(100)` |
| 20 | IN | `sSuId` | `varchar(100)` |
| 21 | IN | `bFilter` | `varchar(5000)` |
| 22 | IN | `pageNum` | `int` |
| 23 | IN | `pageSize` | `int` |
| 24 | OUT | `totalCount` | `int` |
| 25 | IN | `countCloumn` | `varchar(5000)` |
| 26 | OUT | `countMapJson` | `longtext` |
| 27 | IN | `sFilterOrderBy` | `varchar(5000)` |
| 28 | IN | `sGroupby_select_sql` | `varchar(5000)` |
| 29 | 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_MaterialsInventoryV56`'`._

## Narrative

**Business context:** 材料库存 → 材料库存查询 → 材料可用库存查询 — the live V56-revision available-stock query for materials. Also drives the 材料库存 widget on the 工作台 → 常用报表 dashboard and the 材料实际库存查询 form under the same module group. Answers "for each material, how much can I actually allocate right now?" by netting physical stock against locked/virtual reservations.

**What it does:** Builds `p_TmpMaterialsStoreList` and the per-material auxiliary set `p_TmpMaterialsStoreList_sMaterial` from `MitMaterialsStore` (physical lots) + `MitMaterialsStoreVirtual` (locked/reserved) + `EleMaterialsStock` (rolling totals), joined to `EleMaterials` and `siswarehouse`. Reads decimal precision from `SysSystemSettings`. Supports per-material/style/warehouse/location/classification filters, `iHasZero` (include zero-stock rows), `iSumQty`, `iSales`, `iDetailStock`, `iAdditionalMaterialInfo`, dynamic `bFilter`, then paginates via `Sp_Outstanding_Query`.

**Invocation:** Bound as the data source of three forms via `gdsconfigformmaster.sSqlStr`:
- 材料可用库存查询 (sId `192116810113315275580988560`) — 材料库存 → 材料库存查询
- 材料库存 (sId `192116810113315275746226950`) — 移动端管理 → 工作台 → 常用报表
- 材料实际库存查询 (sId `101251240115015897740323900`) — 材料库存 → 材料库存查询

Also referenced by `Fun_getInitColumnByProName` (the metadata function that maps proc name → returned column list). xly-src ships install script `script/标版/30100101/Sp_Inventory_MaterialsInventoryV56.sql` plus a customer-override at `script/客户/千彩/Sp_Inventory_MaterialsInventoryV56.sql` (tenant 千彩 carries a forked version — verify which is deployed for that customer).
