# `Sp_Inventory_ProductInOutStore` (procedure)


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

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `sCustomerGuid` | `varchar(255)` |
| 2 | IN | `sProductGuid` | `varchar(255)` |
| 3 | IN | `sParentGuid` | `varchar(255)` |
| 4 | IN | `sWarehouseGuid` | `varchar(255)` |
| 5 | IN | `sDefineNoS` | `varchar(255)` |
| 6 | IN | `sDefineNoS2` | `varchar(255)` |
| 7 | IN | `sProductNameSear` | `varchar(255)` |
| 8 | IN | `tStartDate` | `datetime` |
| 9 | IN | `tEndDate` | `datetime` |
| 10 | IN | `iViewOperation` | `int` |
| 11 | IN | `sBrId` | `varchar(255)` |
| 12 | IN | `sSuId` | `varchar(255)` |
| 13 | IN | `bFilter` | `varchar(5000)` |
| 14 | IN | `pageNum` | `int` |
| 15 | IN | `pageSize` | `int` |
| 16 | OUT | `totalCount` | `int` |
| 17 | IN | `countCloumn` | `varchar(5000)` |
| 18 | OUT | `countMapJson` | `longtext` |
| 19 | IN | `sFilterOrderBy` | `varchar(5000)` |
| 20 | IN | `sGroupby_select_sql` | `varchar(5000)` |
| 21 | 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_ProductInOutStore`'`._

## Narrative

**Business context:** 成品库存 → 库存查询 → 成品进销存报表 / 成本管理 → 产品存货分析 → 产品存货核算 / 财务管理 → 分析报表 → 库存产品价值 — finished-product 进销存 (opening + in + out + closing) ledger across a date range. The same proc backs all three forms because they read the same `pitproductstore` movement table and only differ in column slicing.

**What it does:** Defaults NULL inputs to `''`, sets `tStartDate`/`tEndDate` to current period bounds if missing, builds a temp ledger that (a) sums opening qty/money from `pitproductstore` rows before `tStartDate`, (b) inserts in-window receipts and dispatches grouped by product / 自定义项 / warehouse / location, then (c) joins `eleproduct`, `elecustomer`, `elewarehouse`, `elewarehouseLocation` for display columns. Final rowset/pagination flow via `Sp_Outstanding_Query` (filter, page, group-by, count-column JSON). `iViewOperation` toggles per-row drill-down vs. summary mode.

**Invocation:** Bound as the data source on three form-masters: `19211681015115285230704000` (成品进销存报表 — 库存查询), `101251240115016213196171340` (产品存货核算 — 成本管理 → 产品存货分析), and `101251240115016215062363140` (库存产品价值 — 财务管理 → 分析报表). Form-binding dispatcher reads the proc name from `gdsconfigformmaster.sSqlStr`. Function `Fun_getInitColumnByProName` references it for column-config metadata. xly-src ships `script/标版/30100101/Sp_Inventory_ProductInOutStore.sql`; `script/客户/千彩/Sp_Inventory_ProductInOutStore.sql` is the 千彩 customer override.
