# `SP_Inventory_ProductCalcQty` (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 | `sLocationGuid` | `varchar(100)` |
| 8 | IN | `sWarehouseLocationGuid` | `varchar(100)` |
| 9 | IN | `sBrId` | `varchar(100)` |
| 10 | IN | `sSuId` | `varchar(100)` |

## Body

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

## Narrative

**Business context:** 成品库存 → 库存查询 — incremental finished-product stock recompute keyed to a single product / 自定义项 / warehouse / location key. Called as a step inside the audit/un-audit flow for finished-goods receipt and dispatch documents (送货单, 领料单, 转仓单, 调拨单, 收货单, 退货单 …); refreshes the `pitproductstore` ledger so downstream finished-product stock and out-of-store reports stay in sync per audit click.

**What it does:** Coerces NULL inputs to `''`. Inside a labelled `top:` block, runs three remediation updates against `pitproductstore`: back-fills `sOrderId/sOrderSlaveId/sOrderNo` from sales-order forms, fills missing `dProductPrice/dProductMoney` from `salsalesorderslave` and from the initial-balance row (`sFormId='101251240115015991142363800'`). Then `CALL SP_Inventory_ProductInOutWareHouse(...)` to rebuild the warehouse in/out flow, and `LEAVE top` — the trailing `Sp_Sis_GetProductInventoryFormGuid` / period-aware path below the leave is dead-stop scaffolding kept for compatibility.

**Invocation:** Chained from the standard sales / inventory `Sp_Calc_s*` audit procedures — found in the bodies of `Sp_Calc_sDgd`, `Sp_Calc_sDgdCL`, `Sp_Calc_sDgd_1226`, `Sp_Calc_sDgd_20250612`, `Sp_Calc_sDYDgd`, `Sp_Calc_sOpi1`, `Sp_Calc_sPaj`, `Sp_Calc_sPsa`, `Sp_Calc_sPst`/`_copy1`, `Sp_Calc_sPtr`, `Sp_Calc_sRgd`/`sRgd1`/`sRgd_new`, and `SP_Inventory_Product_Inout_new`, plus the named wrapper `call_SP_Inventory_ProductCalcQty`. Not bound directly to a form or `gdsmodule` hook. xly-src ships `script/标版/30100101/SP_Inventory_ProductCalcQty.sql`.
