# `Sp_System_CalcProductPrice_new` (procedure)

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


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

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `tStartDate` | `datetime` |
| 2 | IN | `tEndDate` | `datetime` |
| 3 | IN | `bUpdate` | `int` |
| 4 | IN | `sLoginId` | `varchar(100)` |
| 5 | IN | `sBrId` | `varchar(100)` |
| 6 | IN | `sSuId` | `varchar(100)` |
| 7 | OUT | `sReturn` | `varchar(4000)` |
| 8 | OUT | `sCode` | `int` |

## Body

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

## Narrative

**Business context:** 成本核算 / 财务月结 → 计算产品价格 — `_new` revision of `Sp_System_CalcProductPrice` (identical signature). Used by a narrower subset of close-time button-events; intent unchanged: derive per-product `dProductPrice` from the 销售订单价 → 产品客户特价 → 产品默认价 → 销售对账价 cascade and write it into the period's成品 movements.

**What it does:** Same body shape as the base proc — walks成品 movements in `[tStartDate, tEndDate]`, applies the price cascade against `tEndDate`, writes back `dProductPrice` / `dProductMoney` to in-period成品 stock and (when `bUpdate=1`) consolidates into the month-end snapshot.

**Invocation:** Called by `Sp_financialClosing_BtnEventCalcMaterialPrice` and `Sp_financialClosing_BtnEventCalcYM_New` — both 财务月结 button handlers dispatched by `GenericProcedureCallServiceImpl.doGenericProcedureCall()`. The base `Sp_System_CalcProductPrice` retains the wider caller set (audit-time `Sp_Product_BtnEventCheck`, `Sp_Cost_CheckBusinessData`, `Sp_CalcCost_BtnEventReCalcCost`), so the `_new` body is the slimmer月结-only variant. No standalone install script for this `_new` revision in xly-src — deploy from the base script and tag the patched body.
