# `SP_Inventory_InOutWarehouse` (procedure)


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

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `sMaterialsGuid` | `varchar(100)` |
| 2 | IN | `sMaterialsStyleS` | `varchar(100)` |
| 3 | IN | `sDefineNoS` | `varchar(100)` |
| 4 | IN | `sDefineNoS2` | `varchar(100)` |
| 5 | IN | `sWareHouseGuid` | `varchar(100)` |
| 6 | IN | `tStartDate` | `datetime` |
| 7 | IN | `tEndDate` | `datetime` |
| 8 | IN | `bUpdate` | `int` |
| 9 | IN | `bFlag` | `int` |
| 10 | IN | `sLocationGuid` | `varchar(100)` |
| 11 | IN | `sWarehouseLocationGuid` | `varchar(100)` |
| 12 | IN | `bUpdateAll` | `int` |
| 13 | IN | `sLoginId` | `varchar(100)` |
| 14 | IN | `sBrId` | `varchar(100)` |
| 15 | IN | `sSuId` | `varchar(100)` |
| 16 | IN | `bFilter` | `varchar(5000)` |
| 17 | IN | `pageNum` | `int` |
| 18 | IN | `pageSize` | `int` |
| 19 | OUT | `totalCount` | `int` |
| 20 | IN | `countCloumn` | `varchar(5000)` |
| 21 | OUT | `countMapJson` | `longtext` |
| 22 | IN | `sFilterOrderBy` | `varchar(5000)` |
| 23 | IN | `sGroupby_select_sql` | `varchar(5000)` |
| 24 | IN | `sGroupby_group_sql` | `varchar(5000)` |
| 25 | OUT | `sCode` | `int` |
| 26 | OUT | `sReturn` | `varchar(5000)` |

## Body

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

## Narrative

**Business context:** 材料库存 → 材料库存查询 → 材料库存台账 — material in/out warehouse ledger (出入库台账). Per-material, per-warehouse opening stock + every receipt/issue/cut/adjustment + running balance over a date window. The auditor's go-to view to reconcile `MitMaterialsStore` movements against `EleMaterialsStock` and the `MitMaterialsCheck` stock-count workflow.

**What it does:** Resolves the account period from `sysaccountperiod` and `SysSystemSettings`, builds the working `InOutWarehouse` set from `MitMaterialsStore` movements + `Viw_MitMaterialsCheck` (盘点) + `MitMaterialsCutMaster/Slave` (paper-reel cut slips). Defaults dates, calls `Sp_Sis_GetMertialsInventoryFormGuid` + `Sp_Sis_GetConst` for form-config constants, optionally normalises material-style fields via `Sp_System_ReplaceField`, then paginates the rowset via `Sp_Outstanding_Query`.

**Invocation:** Bound as the data source of form 材料库存台账 (sId `19211681019715754498436890`) under 材料库存 → 材料库存查询 → 材料库存台账, loaded when the user opens the report (the form-binding dispatcher reads the proc name from `gdsconfigformmaster.sSqlStr`). Also called from `Sp_System_AutoMaterialsPriceSingle` and `Sp_System_AutoMaterialsPriceSingle_new` / `_Old` (automatic per-material costing) to fetch period movement totals when reconstructing weighted-average prices. xly-src ships install script `script/标版/30100101/SP_Inventory_InOutWarehouse.sql`.
