# `Sp_System_ProductionCost_new` (procedure)

> 期初按比例分摊


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

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `sProInParam` | `varchar(10000)` |
| 2 | IN | `iSecond` | `int` |
| 3 | IN | `sMakePerson` | `varchar(100)` |
| 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_ProductionCost_new`'`._

## Narrative

**Business context:** 成本核算 / 生产成本（期初按比例分摊版） — newer variant of `Sp_System_ProductionCost`. Per the procedure `COMMENT` (`期初按比例分摊`): the change versus the base is how the 期初成本 is allocated — instead of grabbing the nearest prior 月结 row verbatim, the `_new` build spreads the prior-period 在制品 cost proportionally across this period's work-orders by 工时 / 数量 ratios. Same target ledger (`accordercostanalysis`), same call topology, different apportionment.

**What it does:** Validates `sProInParam` JSON of period ids; per period, reads `sPeriodId/bCost`, refuses when the period is already 已核算 (`bCost=1`). Drives the standard 生产成本 pipeline: `CALL Sp_System_MaterialsCost` first to lock material prices, then walks the per-work-order cursor, INSERTs into `TmpCostWorkOrder*` / `p_accordercostanalysis*` temp tables, applies the *proportional* 期初 allocation (`Sp_WorkCostCarryforward`), and writes back `accordercostanalysis` / `accproductstore`. Tail-`CALL`s `Sp_System_ProductionCost` for shared finishing logic.

**Invocation:** Status: appears orphaned at the procedure level — no other proc, gdsmodule binding, or form-master ref calls `Sp_System_ProductionCost_new` directly, and no xly-src script ships it (the only `Sp_System_ProductionCost*` install scripts cover the base name and `…AllSure/AllReSure`). Almost certainly a manual-trigger alternative wired up by a 生产成本 button via `GenericProcedureCallServiceImpl.doGenericProcedureCall()` for customers needing the prorated 期初 model. Candidate for maintainer audit — confirm whether any production tenant still routes to this variant.
