# `SP_Inventory_ProductInOutWareHouse` (procedure)

> 出入库流水账


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

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `sCustomerGuid` | `varchar(100)` |
| 2 | IN | `sProductGuid` | `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 | `iUpdate` | `int` |
| 9 | IN | `iUpdateAll` | `int` |
| 10 | IN | `sLocationGuid` | `varchar(100)` |
| 11 | IN | `sWarehouseLocationGuid` | `varchar(100)` |
| 12 | IN | `sBrId` | `varchar(100)` |
| 13 | IN | `sSuId` | `varchar(100)` |
| 14 | IN | `bFilter` | `varchar(5000)` |
| 15 | IN | `pageNum` | `int` |
| 16 | IN | `pageSize` | `int` |
| 17 | OUT | `totalCount` | `int` |
| 18 | IN | `countCloumn` | `varchar(5000)` |
| 19 | OUT | `countMapJson` | `longtext` |
| 20 | IN | `sFilterOrderBy` | `varchar(5000)` |
| 21 | IN | `sGroupby_select_sql` | `varchar(5000)` |
| 22 | 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_ProductInOutWareHouse`'`._

## Narrative

**Business context:** 成品库存 → 库存查询 → 成品库存台账 — finished-product warehouse in/out 流水账 (movement ledger) per product / 自定义项 / warehouse / location across a date window. The `iUpdate=1` mode writes back into `pitproductstore` so `SP_Inventory_ProductCalcQty` and the standard audit chain rely on this proc to refresh the ledger after every audit click.

**What it does:** Builds a temp table `InOutWarehouse` seeded with the opening balance (`pitproductstore` rows before `tStartDate` summed into `p_dProductMoneyOne`), inserts in-window receipts and dispatches with running average cost (`dProductPrice = SUM(money)/SUM(qty)`), joins `eleproduct` for `sProductNo` / display columns, then pages / counts through `Sp_Outstanding_Query`. When called from `SP_Inventory_ProductCalcQty` it runs in update mode (`iUpdate=1`) to back-write the recomputed cost/qty into `pitproductstore`.

**Invocation:** Bound as the data source of form-master `19211681015115285157572790` (成品库存台账 — 库存查询). Also chained inside `Sp_Calc_sPst`/`_copy1`, `Sp_Calc_sPtr`, and `SP_Inventory_ProductCalcQty` for the audit-time stock refresh. xly-src ships `script/标版/30100101/SP_Inventory_ProductInOutWareHouse.sql` and `script/标版/optimize/SP_Inventory_ProductInOutWareHouse.sql`; `script/客户/千彩/SP_Inventory_ProductInOutWareHouse.sql` and `script/客户/无锡中江/SP_Inventory_ProductInOutWareHouseXGJE.sql` are customer overrides.
