# `Sp_Inventory_ProductInOutStoreMoney` (procedure)

> @author:杨恒林
							@date:20210521 封存
							@describe: 计算库存产品商品价值并存入月结表 主要思路如下：
							从本月月末之前最近一次订单取价格，如果取不到 从 产品客户表中取 ，再取不到 从产品表中取，再取不到,从最近取对帐
							bUpdate = 1 时，表示月末结帐时调用，0：在库存商品价值表界面 调用


- **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)` |
| 21 | OUT | `sCode` | `int` |
| 22 | OUT | `sReturn` | `varchar(255)` |

## Body

_Body is not pre-cached. To inspect: `mysql --defaults-file=~/.my.cnf -e 'SHOW CREATE PROCEDURE `Sp_Inventory_ProductInOutStoreMoney`'`._

## Narrative

**Business context:** 库存商品价值 — month-end finished-product value posting (sealed). Per the proc header (`@author:杨恒林 @date:20210521 封存`): "computes inventory product value and writes it into the month-end ledger". Price source falls back through (1) most recent order before month-end, (2) `eleproductcustomer`, (3) `eleproduct`, then (4) most recent reconciliation. `bUpdate=1` is the month-end-close call site; `bUpdate=0` is the 库存商品价值 screen.

**What it does:** Resolves a price per product/customer/warehouse via the four-step fallback chain (delegating to `Sp_System_CalcProductPrice`), multiplies it against current on-hand from `pitproductstore` / `eleproductstock`, and either returns the rowset (read-only mode) or writes the month-end posting back to the value ledger. Final rowset paginates through `Sp_Outstanding_Query`; the `sCode`/`sReturn` OUT params carry the standard error-channel on failure.

**Invocation:** Status: appears orphaned — header explicitly marks the routine 封存 (sealed) on 20210521. No form-master binding, no `gdsmodule` hook, no other DB caller in the live schema. Only present in xly-src as `script/标版/optimize/Sp_Inventory_ProductInOutStoreMoney.sql` and `script/标版/30100101/cost/Sp_Inventory_ProductInOutStoreMoney.sql`. The live 库存产品价值 form binds to `Sp_Inventory_ProductInOutStore`, not this sealed variant.
