# `Sp_beforeSave_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_beforeSave_sOpkg`'`._

## Narrative

**Business context:** KPI流程操作菜单 / 发外加工流程 / 发外对账 — before-save delegator for the outsourcing reconciliation document. Wraps `sGuid` and forwards to `Sp_saveReturn_sOpkg` to backwrite reconciled quantities onto the upstream `工序发外` / `工序发外确认` documents before the master save commits. Comment header: `发外发票前反写数量` (the comment mentions invoice but the hook is reconciliation).

**What it does:** Normalises `sGuid` to a quoted-CSV form, then `CALL Sp_saveReturn_sOpkg(sGuid, sBrId, sSuId, 1, @sCode, @sReturn)`.

**Invocation:** Hooked as `gdsmodule.sSaveProNameBefore` on module `发外对账` (sId `192116810113315235850403280`). Also called by dispatcher procs `Sp_Invalid_backwriting` and `Sp_delete_backwriting` to replay the writeback on invalidate/delete. Install script: `xly-src/script/标版/30100101/Sp_beforeSave_sOpkg.sql`.
