# `Sp_financialClosing_BtnEventCalcCost_New` (procedure)

> 成本核算前检查


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

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `sProInParam` | `varchar(10000)` |
| 2 | IN | `sMakePerson` | `varchar(100)` |
| 3 | IN | `sBrId` | `varchar(100)` |
| 4 | IN | `sSuId` | `varchar(100)` |
| 5 | OUT | `sReturn` | `varchar(1000)` |
| 6 | OUT | `sCode` | `int` |

## Body

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

## Narrative

**Business context:** 系统设置 → 系统参数 → 财务结账 — newer "calculate cost" button on the 财务结账 panel. Pre-flight check + cost calculation for a selected 会计期 before the period can be frozen: walks the eight cost categories (1 直接材料, 2 本期作业汇总, 3 外发发票, 4 本期作业明细, 5 发外期初, 6 在制品期初, 7 本期暂估发外入库, 8 上期工单) flagged in its header comment.

**What it does:** Validates `sProInParam` carries a valid `sysaccountperiod.sId`, looks up `p_tStart`/`p_tEnd` and prior-period bounds, reads system settings (研发费用系数 `16596091900003285479512869866500` and a data-flag `16596092080006754786975820680000`). Then orchestrates the cost-accumulation pipeline: rebuilds 直接材料 / 作业汇总 / 外发发票 / 在制品 entries into `acc*` cost tables for the period, summed into `p_dSumMoney`. On any check failure returns `sCode=-1` with a localized `sReturn` message; on success leaves the period ready for `Sp_financialClosing_BtnEventCheckout` to freeze.

**Invocation:** Dispatched by `GenericProcedureCallServiceImpl.doGenericProcedureCall()` when the user clicks the 成本核算 button on the 财务结账 form — the front-end button config supplies `sProName='Sp_financialClosing_BtnEventCalcCost_New'` plus the selected period id(s) as `sProInParam`. Install script: `script/标版/30100101/cost/Sp_financialClosing_BtnEventCalcCost_New.sql`.
