# `Sp_Inventory_ProductInOutStoreStock` (procedure)

> @author:杨恒林 
		     @date:20210521 封存 
				 @describe: 库存商品价值：查询当前库存商品的价值，产品价格来源为 Sp_System_CalcProductPrice 这个过程
				 从最近订单，产品客户表，产品表 三个地方取价格


- **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 | `tStartDate` | `datetime` |
| 8 | IN | `tEndDate` | `datetime` |
| 9 | IN | `iViewOperation` | `int` |
| 10 | IN | `sBrId` | `varchar(255)` |
| 11 | IN | `sSuId` | `varchar(255)` |
| 12 | IN | `bFilter` | `varchar(5000)` |
| 13 | IN | `pageNum` | `int` |
| 14 | IN | `pageSize` | `int` |
| 15 | OUT | `totalCount` | `int` |
| 16 | IN | `countCloumn` | `varchar(5000)` |
| 17 | OUT | `countMapJson` | `longtext` |
| 18 | IN | `sFilterOrderBy` | `varchar(5000)` |
| 19 | IN | `sGroupby_select_sql` | `varchar(5000)` |
| 20 | 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_ProductInOutStoreStock`'`._

## Narrative

**Business context:** 库存商品价值 — current finished-product inventory-value query (sealed). Per the proc header (`@author:杨恒林 @date:20210521 封存`): "library inventory value: queries current value with product price sourced via `Sp_System_CalcProductPrice` falling back from latest order → 产品客户表 → 产品表". Live 财务管理 → 分析报表 → 库存产品价值 form binding is the value-view side of the finished-product ledger family.

**What it does:** Calls `Sp_System_CalcProductPrice` per product/customer to resolve a unit price (latest sales-order → `eleproductcustomer` → `eleproduct` fallback chain), aggregates `pitproductstore` per product / 自定义项 / warehouse / location to the current closing qty, multiplies into product value, and joins `eleproduct`/`elewarehouse`/`elecustomer` for display columns. Paginates / counts through `Sp_Outstanding_Query`.

**Invocation:** Bound as the data source of form-master `101251240115016215062363140` (库存产品价值 — 财务管理 → 分析报表). Note the 封存 header indicates the proc was sealed in 2021 — the live form may instead dispatch to `Sp_Inventory_ProductInOutStore`; flag for maintainer verification of the actual runtime binding. xly-src ships `script/标版/30100101/cost/Sp_Inventory_ProductInOutStoreStock.sql` and `script/标版/optimize/Sp_Inventory_ProductInOutStoreStock.sql`; `script/客户/千彩/Sp_Inventory_ProductInOutStoreStock.sql` is the 千彩 customer override.
