# `Sp_financialClosing_BtnEventProductStock_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_BtnEventProductStock_New`'`._

## Narrative

**Business context:** 系统设置 → 系统参数 → 财务结账 — `COMMENT '产品存货核算前检查'`. Month-end finished-goods (产品) inventory carry-over: deletes the period's prior product-stock rows, recomputes opening/closing balances by SKU + warehouse + workshop using `Sp_System_ProductCost_OutPrice`, and re-populates `accproductstore` (general 产品月结) plus `accyfcyproductstore` (已发出产品 in-transit).

**What it does:** Parses period sId from `$.params[0].value[0]`, validates parameters (`paramsErro` / `selectedRowKeysNo` guards), then `DELETE FROM accproductstore WHERE sCostPeriod=p_sPeriod` and rebuilds via several INSERT/UPDATE passes: ingest finished-goods entries (`pitproductinstoremaster`/`saldelivergoodsmaster`/adjustments) over the period window, compute cost-prices via `Sp_System_ProductCost_OutPrice`, summarise per `sProductId, sMaterialsStyle, sWarehouseId, sWorkCenterId`, and insert the resulting rows into `accproductstore` and `accyfcyproductstore` for the chosen `sCostPeriod`. ~50K-char body — full DML list includes multiple UPDATE accproductstore back-fill passes for `dCostPrice/dCostMoney`. See body summary for the exact DML.

**Invocation:** Dispatched dynamically by `GenericProcedureCallServiceImpl.doGenericProcedureCall()` from the 财务结帐 form's 产品月结 / 产品存货核算 toolbar button. The `_New` suffix marks the current generation that replaced an earlier variant. xly-src ships `script/标版/30100101/cost/Sp_financialClosing_BtnEventProductStock_New.sql`.
