# `SP_Inventory_SemgoodsInOutWareHouse` (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 | `sPartsNameGuid` | `varchar(100)` |
| 4 | IN | `dSinglePQtyGuid` | `decimal(18,6)` |
| 5 | IN | `sProcessIdGuid` | `varchar(100)` |
| 6 | IN | `sVerGuid` | `varchar(100)` |
| 7 | IN | `sDefineNoS` | `varchar(100)` |
| 8 | IN | `sDefineNoS2` | `varchar(100)` |
| 9 | IN | `sWareHouseGuid` | `varchar(100)` |
| 10 | IN | `tStartDate` | `datetime` |
| 11 | IN | `tEndDate` | `datetime` |
| 12 | IN | `iUpdate` | `int` |
| 13 | IN | `iUpdateAll` | `int` |
| 14 | IN | `sLocationGuid` | `varchar(100)` |
| 15 | IN | `sWarehouseLocationGuid` | `varchar(100)` |
| 16 | IN | `sBrId` | `varchar(100)` |
| 17 | IN | `sSuId` | `varchar(100)` |
| 18 | IN | `bFilter` | `varchar(5000)` |
| 19 | IN | `pageNum` | `int` |
| 20 | IN | `pageSize` | `int` |
| 21 | OUT | `totalCount` | `int` |
| 22 | IN | `countCloumn` | `varchar(5000)` |
| 23 | OUT | `countMapJson` | `longtext` |
| 24 | IN | `sFilterOrderBy` | `varchar(5000)` |
| 25 | IN | `sGroupby_select_sql` | `varchar(5000)` |
| 26 | 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_SemgoodsInOutWareHouse`'`._

## Narrative

**Business context:** 半成品出入库流水账 — semi-finished-goods (半成品 / Semgoods) counterpart of `SP_Inventory_ProductInOutWareHouse`. Warehouse in/out 流水账 over a date window for the semi-goods ledger keyed by product / 半成品零件 (`sPartsNameGuid`) / 工序 (`sProcessIdGuid`) / 版本 (`sVerGuid`) / 自定义项 / warehouse / location; used by the semi-goods audit chain to refresh the ledger after each audit click.

**What it does:** Builds a temp ledger seeded with semi-goods opening balance before `tStartDate`, inserts in-window receipts and dispatches with running average cost, joins to `elesemgoods` / `elewarehouse` for display, then either returns the paginated rowset via `Sp_Outstanding_Query` or — when called in update mode (`iUpdate=1`) from a semi-goods audit proc — back-writes the recomputed qty/cost into the semi-goods stock table.

**Invocation:** Chained from the semi-goods audit procedures `Sp_Calc_sSmi` (半成品入库) and `Sp_Calc_sSmo` (半成品出库). Not bound directly to a form-master in the live `gdsconfigformmaster`. xly-src ships `script/标版/30100101/SP_Inventory_SemgoodsInOutWareHouse.sql` and `script/标版/optimize/SP_Inventory_SemgoodsInOutWareHouse.sql`.
