# `Sp_afterSave_sOpkg` (procedure)

> 发外发票后反写数量


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

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `sGuid` | `varchar(2000)` |
| 2 | IN | `sBrId` | `varchar(100)` |
| 3 | IN | `sSuId` | `varchar(100)` |
| 4 | OUT | `sCode` | `int` |
| 5 | OUT | `sReturn` | `varchar(4000)` |

## Body

_Body is not pre-cached. To inspect: `mysql --defaults-file=~/.my.cnf -e 'SHOW CREATE PROCEDURE `Sp_afterSave_sOpkg`'`._

## Narrative

**Business context:** 发外对账 → 发外加工流程 → KPI流程操作菜单 — header says 发外发票后反写数量 (the header is mis-copied from the `sOiv` invoice variant; the actual business is outsource-reconciliation, not invoice). Thin save-phase wrapper in the `Sp_afterSave_s<Code>` family that delegates the qty back-write to `Sp_saveReturn_sOpkg`.

**What it does:** Wraps `sGuid` in double-quotes if not already quoted and, when `sGuid` is non-empty, calls `Sp_saveReturn_sOpkg(sGuid, sBrId, sSuId, 2, @sCode, @sReturn)`. Does not propagate the inner `@sCode`/`@sReturn` to its own OUT params.

**Invocation:** Reached on three paths. (1) The 发外对账 gdsmodule row binds this proc directly into `sDeleteProName` — the only live member of the family that occupies its own `gdsmodule` slot rather than relying solely on the `Sp_Check_s<Code>` save chain. (2) `Sp_Check_sOpkg` (bound via `gdsmodule.sSaveProName` on the same 发外对账 row) calls this proc at the tail of a successful save. (3) `Sp_Invalid_backwriting` dispatches to this proc on 作废/取消作废 of form `192116810113315235850403280` (发外对账), itself triggered by Java `CheckmodelServiceImpl` via `Sp_Invalidation`.
