# `Sp_System_CalcMaterialsPrice_220709` (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 | `sBrId` | `varchar(100)` |
| 5 | IN | `sSuId` | `varchar(100)` |
| 6 | OUT | `sReturn` | `varchar(4000)` |
| 7 | OUT | `sCode` | `int` |

## Body

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

## Narrative

**Business context:** 成本核算 / 财务月结 → 计算材料价格 — dated backup revision (2022-07-09 snapshot) of `Sp_System_CalcMaterialsPrice`. Preserved alongside the live body so closing-period revaluations can be reproduced or rolled back if a later edit changes the period numbers.

**What it does:** Same algorithm as `Sp_System_CalcMaterialsPrice` at the 2022-07-09 cut — period-walk over each material's prior-month closing balance plus current 采购/其它入库 to derive a 全月加权 unit price, then propagate back to in-period materials slaves with system-settings decimal rounding. The header comment retains the original `bUpdate=1` 月末结帐 / `bUpdate=0` 材料存货核算表 split.

**Invocation:** Status: appears orphaned. No `gdsmodule` hook, no form-master binding, no other-routine caller in `information_schema.ROUTINES`, no xly-src reference. Per the playbook backup-variant convention, treat as a frozen snapshot — not expected to be called from any live flow; verify before redeploying.
