# `Sp_Calc_sOiv` (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_sOiv`'`._ ## Narrative **Business context:** 发外加工流程 / 外协管理 → 外协单据 → 发外发票 — outsourced-process supplier-invoice audit / un-audit on `OpsOutsideInvoiceMaster`. When the outsourcing vendor sends an invoice for completed steps, finance audits the invoice doc to register the payable, post the operator KPI, and clear the check-rows against `OpsOutsideCheckingSlave`. **What it does:** Defaults the IN params, branches on `iFlag`. On `iFlag=1` flips `OpsOutsideInvoiceMaster.bCheck=1`, writes a KPI row to `kpidetail` for the auditing user, `Update OpsOutsideCheckingSlave` to mark the matched checking rows reconciled, `Update CahFinancialAdjust` / `Update CahSupplyInit` to seed the finance-side adjust and supplier-initial rows, then writes the payable into `CahPaymentables`. `iFlag=0` reverses by `Delete FROM CahPaymentables` plus the symmetric back-outs. **Invocation:** Bound to `gdsmodule.sProcName` on two sibling modules: `发外发票` (sId `101251168116315832142387420`) under 发外加工流程 and `发外发票(新)` (sId `1012521165114317002882431280`) under 外协管理 → 外协单据. The legacy one also has `Sp_Check_sOiv` / `Sp_beforeSave_sOiv` plus a `Sp_beforeSave_sOiv` delete hook; the (新) variant is leaner. Dispatched by Java `BusinessBaseServiceImpl.getPrcName(sFormGuid, …)` on 审核/反审核. xly-src ships an upgrade patch at `script/标版/upgrade/20220104审核去除结账校验/Sp_Calc_sOiv.sql` (removed close-of-period validation) — verify which body is deployed.