# `Sp_BtnEventProductSure_New` (procedure)


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

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `sProInParam` | `longtext` |
| 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_BtnEventProductSure_New`'`._

## Narrative

**Business context:** 成本核算 / 订单成本汇总 — toolbar handler that batch-toggles 确认 on `accordercostanalysis` rows for a costing period and then rebuilds the period's `accworkcenter` cost-aggregates from confirmed work-orders, production reports, and machine roster. Drives the downstream 工作中心成本 view used by costing reports.

**What it does:** Reads `$.params[0].value[0].sCostPeriod` plus the `sId` array, builds `Sp_ids_Table`, then flips `accordercostanalysis.bConfirm` for matching rows and updates `sConfirmMonth` based on the new flag value. Nulls out the period's `accworkcenter` aggregate columns (`dPower, iPeople, iMachine, dProcessQty, dMonthHour, ...`), then rebuilds them from joined sources: machine count from `elemachine GROUP BY sCostCenterId`; people, average power, total-hour salary from `sisworkcenter`; period production hours, process qty, area, color/plate quantity from joined `accordercostanalysis × elemachine × sisworkcenter` (and from `viw_mftproductionreport` in the commented variants). Re-issues the same DELETE+INSERT against `accordercostanalysis` per `iBillType` 1/3/4/5/6 (rebuild grain by bill type — work order, in-store, etc.).

**Invocation:** Dispatched dynamically by `GenericProcedureCallServiceImpl.doGenericProcedureCall()` (POST `/procedureCall/doGenericProcedureCall`) — 订单成本汇总 / 成本核算 grid's 确认 toolbar button names this proc as its action. Siblings in the cost-confirm family: `Sp_BtnEventDepartSure_New`, `Sp_BtnEventworkcenterSure_New`, `Sp_BtnEventMaterialsSure_New`, `Sp_BtnEventProductInStoreSure_New`, `Sp_BtnEventProductionmaterialSure_New`.

Flag: large procedure with multiple alternative blocks commented out — verify which DELETE/INSERT/Update branches are intended live before relying on the output. Several rebuild variants reference `viw_mftproductionreport` only in commented form.
