# `Sp_Inventory_InOutStoreNew` (procedure)


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

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `sMaterialsGuid` | `varchar(100)` |
| 2 | IN | `sParentGuid` | `varchar(100)` |
| 3 | IN | `sWarehouseGuid` | `varchar(100)` |
| 4 | IN | `tStartDate` | `datetime` |
| 5 | IN | `tEndDate` | `datetime` |
| 6 | IN | `iViewOperation` | `int` |
| 7 | IN | `sLocationGuid` | `varchar(100)` |
| 8 | IN | `sWarehouseLocationGuid` | `varchar(100)` |
| 9 | IN | `sBrId` | `varchar(100)` |
| 10 | IN | `sSuId` | `varchar(100)` |
| 11 | IN | `bFilter` | `varchar(5000)` |
| 12 | IN | `pageNum` | `int` |
| 13 | IN | `pageSize` | `int` |
| 14 | OUT | `totalCount` | `int` |
| 15 | IN | `countCloumn` | `varchar(5000)` |
| 16 | OUT | `countMapJson` | `longtext` |
| 17 | IN | `sFilterOrderBy` | `varchar(5000)` |
| 18 | IN | `sGroupby_select_sql` | `varchar(5000)` |
| 19 | IN | `sGroupby_group_sql` | `varchar(5000)` |
| 20 | OUT | `sCode` | `int` |
| 21 | OUT | `sReturn` | `varchar(255)` |

## Body

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

## Narrative

**Business context:** 财务管理 → 分析报表 → 材料存货核算 — newer rewrite of `Sp_Inventory_InOutStore`. Adds `p_tPeriodStartDate` period-start handling so the opening balance is anchored to the 期初 baseline (`mitmaterialsinitmaster`) rather than recomputed from move history each time, and clamps `tEndDate` to NOW so future dates do not skew the report.

**What it does:** Defaults `tStartDate` to NOW-1 month, clamps `tEndDate` to MIN(tEndDate, NOW()), and reads `SysSystemSettings.CbxLanguage` for the active locale and the materials-cost-mode. Builds `p_TmpInOutStore` movement-detail, `p_Tmp_LastStore` opening-stock, `p_Tmp_LastInitStore` period-initial-baseline (sourced via `FROM mitmaterialsinitmaster`) and `TmpMitMaterialsStore` per-material rollup temp tables. Filters by `sMaterialsGuid` / `sParentGuid` / `sWarehouseGuid` / `sLocationGuid` / `sWarehouseLocationGuid`. Calls `Sp_Sis_GetConst` for localised constants and `Sp_Sis_GetMertialsInventoryFormGuid` to resolve inventory form-guids, then `CALL Sp_Outstanding_Query` for paging and column-config emission.

**Invocation:** Same module as the legacy `Sp_Inventory_InOutStore` (财务管理 → 分析报表 → 材料存货核算, gdsmodule sId `101251240115016213194819340`). Status: present in DB but no install script in xly-src and no `gdsconfigformmaster.sSqlStr` match (the form binding still points at `Sp_Inventory_InOutStore`). Appears to be a forward-staged rewrite not yet promoted to the form binding; verify before relying on it.
