# `Sp_BtnEventworkcenterSure_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_BtnEventworkcenterSure_New`'`._

## Narrative

**Business context:** 成本核算 / 工作中心 — toolbar handler that toggles 工作中心核算确认 (`accworkcenter.bConfirm`) for the selected costing-period rows, then re-aggregates `accdepart` totals from confirmed work-centers under each department. Period gate: rejects if `sysaccountperiod.bCost=1`.

**What it does:** Parses `$.params[*].value[*]` with `sId, sCostPeriod`. Per row: reads `sysaccountperiod.bCost` — if `1`, returns `sCode=-1, sBtnDepartFinished` ("该会计期间已核算完成,不能进行此操作"). Otherwise flips `accworkcenter.bConfirm` and stamps `sConfirmMonth=p_sPeriodId` for matching `(sId, sBrId, sSuId)`. After the loop: resets every `accdepart` row's `dPower/dDepreciation/dMonthHour/iPeople/iMachine/dArea/dAveragePower/dAllHourSalary` to 0, then re-aggregates them from `accworkcenter` `SUM(...) GROUP BY sDepartId, sCostPeriod` where `bConfirm=1`, joining on `A.sSrcId=B.sDepartId AND A.sCostPeriod=B.sCostPeriod` (the secondary update also brings in `dColorQty, dProcessQty, dSumPlateQty, dMonthArea`).

**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_BtnEventMaterialsSure_New`, `Sp_BtnEventProductInStoreSure_New`, `Sp_BtnEventProductionmaterialSure_New`, `Sp_BtnEventProductSure_New`.

Flag: the post-loop `accdepart` reset has no `WHERE sCostPeriod=p_sPeriodId` — it zeros every period's `accdepart` row globally before re-aggregating from the temp join. Other periods lose their precomputed `accdepart` values until those periods are confirmed again. Maintainer audit recommended.
