# `Sp_Calc_sOpkg` (procedure) - **Type:** PROCEDURE - **Deterministic:** NO - **SQL data access:** CONTAINS SQL ## Parameters | # | Mode | Name | Type | |---|---|---|---| | 1 | IN | `iFlag` | `int` | | 2 | IN | `iTmpCheck` | `int` | | 3 | IN | `sFormGuid` | `varchar(100)` | | 4 | IN | `sGuid` | `varchar(100)` | | 5 | IN | `sLoginId` | `varchar(100)` | | 6 | OUT | `sReturn` | `varchar(4000)` | | 7 | IN | `sBrId` | `varchar(100)` | | 8 | IN | `sSuId` | `varchar(100)` | | 9 | OUT | `sCode` | `int` | ## Body _Body is not pre-cached. To inspect: `mysql --defaults-file=~/.my.cnf -e 'SHOW CREATE PROCEDURE `Sp_Calc_sOpkg`'`._ ## Narrative **Business context:** KPI流程操作菜单 → 发外加工流程 → 发外对账 — outsource-processing reconciliation audit on `opsoutsidecheckingmaster`. After 发外入库 / 发外确认 lines accumulate, the 发外对账 doc consolidates them for AP settlement with the vendor; this proc audits the consolidation, posts a 财务调整 row when adjustments are recorded, and (when configured) writes the operator's KPI. **What it does:** Validates `sGuid`/`bInvalid`, guards the `bCheck` toggle, then `Update`s `opsoutsidecheckingmaster` + `opsoutsidecheckingslave` to flip `bCheck/sStatus/sCheckPerson/tCheckDate`. Touches `cahfinancialadjustslave` to reflect adjustment amounts back to financial-adjustment slave rows, reads `gdsmodule` + `SysSystemSettings` to decide on `INSERT INTO kpidetail`, and `CALL`s `Sp_System_CheckFlow` / `Sp_Bill_Used` on the standard approval/consumption hooks. `iFlag=0` reverses the flags. **Invocation:** Bound to `gdsmodule.sProcName` on `发外对账` (sId `192116810113315235850403280`) under 发外加工流程. Dispatched by `BusinessBaseServiceImpl.getPrcName(sFormGuid, …)`. Multiple deployment variants ship under `xly-src/script/标版/`: `30100101/Sp_Calc_sOpkg.sql` (current), `optimize/Sp_Calc_sOpkg.sql` (perf patch), `20250616/Sp_Calc_sOpkg(old).sql` (legacy), and `upgrade/20220104审核去除结账校验/Sp_Calc_sOpkg.sql` (removed accounting-period guard) — verify which is live.