# `Sp_System_ProductCost_OutPrice` (procedure)

> @author:杨恒林
							
			
		@date:20221126 封存
							
			
		@describe: 计算出库成本


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

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `p_sPeriod` | `varchar(100)` |
| 2 | IN | `sBrId` | `varchar(100)` |
| 3 | IN | `sSuId` | `varchar(100)` |
| 4 | OUT | `sReturn` | `varchar(4000)` |
| 5 | OUT | `sCode` | `int` |

## Body

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

## Narrative

**Business context:** 成本核算 / 出库成本计算 — per the procedure `COMMENT` (杨恒林, 2022-11-26): "计算出库成本". Computes the per-period 成品出库价 (finished-product issue cost) so that 送货单 / 退货单 lines get a costed-out value driven by the 库存商品价值 ledger, not just the most recent purchase price. Runs as the final pricing pass during 月末结帐 for the 成品库存 side.

**What it does:** Reads `sysaccountperiod.tStartDate/tEndDate` for `p_sPeriod`, extends `tEndDate` by one day, calls `Sp_Sis_GetProductInventoryFormGuid` to fetch the `@sInSql/@sOutSql` form-id filters, drops and rebuilds the `Sp_EleProductStock` temp table (one row per product / warehouse / location: prior qty+money+price, in qty+money+price, out qty+money+price, end qty+price+money, plus `dNowOutAdjustStoreMoney`), then loops to compute weighted out-prices and push them back into `saldelivergoodsslave`, `salrejectgoodsslave`, `eleproductstock(month)`, and `eleproductstockmonthcost`. Tail-call coordinates with `Sp_System_ProductCost`.

**Invocation:** Called from `Sp_financialClosing_BtnEventProductStock_New` — the 月末结帐 → 库存成本 button on the financial closing module. No direct UI or gdsmodule binding; reached transitively as the finishing step of the product-stock cost flow. Install script `script/标版/30100101/cost/Sp_System_ProductCost_OutPrice.sql`.
