# `Sp_Inventory_InOutStoreCost` (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_InOutStoreCost`'`._

## Narrative

**Business context:** 财务管理 → 分析报表 → 材料存货核算 (cost view) — cost-side cut of the 材料存货核算 report. Same temp-table shape as `Sp_Inventory_InOutStore` but stripped down to the columns and joins needed for the financial cost reconciliation (no language switching, no inventory-form lookup) — produces opening / movement / closing **amounts** rather than full audit-trail detail.

**What it does:** Defaults `tStartDate` to NOW-1 month and `tEndDate` to NOW. Builds `p_TmpInOutStore` and `p_Tmp_LastInitStore` temp tables and populates them from the 入库 / 出库 transaction tables filtered by `sMaterialsGuid` / `sParentGuid` / `sWarehouseGuid` / `sLocationGuid` / `sWarehouseLocationGuid`. Updates the rollups with cost calculations. Finally `CALL Sp_Outstanding_Query` to apply `bFilter` / `sFilterOrderBy` / paging / `countCloumn` summing and return the report rowset and `countMapJson`.

**Invocation:** Bound to the cost-side data source of the 材料存货核算 report (same module 财务管理 → 分析报表 → 材料存货核算). Dispatched by the form-binding service when the user opens the cost view of the report. Install scripts: `script/标版/optimize/Sp_Inventory_InOutStoreCost.sql` and `script/标版/30100101/cost/Sp_Inventory_InOutStoreCost.sql` — verify which is deployed.
