# `Sp_Calc_sOpi` (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_sOpi`'`._ ## Narrative **Business context:** KPI流程操作菜单 → 发外加工流程 → 整单发外入库 — outsource-processing finished-goods receipt audit on `OpsOutsideInStoreMaster`. After material is sent out (整单发外) and the vendor returns it as a finished sub-assembly or rework, this proc audits the inbound receipt; on approval it posts the received qty against the originating `mftworkorderslave` line and (when configured) writes the operator's KPI. **What it does:** Validates `sGuid`, refuses when `bInvalid=1` or when the master is already at the target `bCheck` state. On `iFlag=1` it sets `bCheck=1, sStatus=1, sCheckPerson, tCheckDate=NOW()` on `OpsOutsideInStoreMaster` and its `opsoutsideinstoreslave` rows, joins back to `mftworkorderslave` to accumulate received quantity, optionally `INSERT`s a `kpidetail` row when `gdsmodule.bKpi` is on, and `CALL`s `Sp_System_CheckFlow` / `Sp_Bill_Used` for workflow + consumption. `iFlag=0` reverses the flags. **Invocation:** Bound to `gdsmodule.sProcName` on `整单发外入库` (sId `192116810113315235917608210`) under 发外加工流程. Dispatched by `BusinessBaseServiceImpl.getPrcName(sFormGuid, …)` on the 审核/反审核 button — the standard `Sp_Calc_s` slot. Install scripts ship at `script/标版/30100101/Sp_Calc_sOpi.sql` with a paired `Sp_Check_sOpi.sql` pre-flight guard.