# `Sp_beforeSave_sOiv` (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_sOiv`'`._

## Narrative

**Business context:** KPI流程操作菜单 / 发外加工流程 / 发外发票 — before-save delegator for the outsourcing invoice. Forwards to `Sp_saveReturn_sOiv` to backwrite invoiced quote-quantities onto the upstream `工序发外` / `发外对账` documents before the master save commits. Comment header: `发外发票保存前反写报价数量`.

**What it does:** If `sGuid` is non-empty, `CALL Sp_saveReturn_sOiv(sGuid, sBrId, sSuId, 1, @sCode, @sReturn)`. Unlike most siblings, the `sGuid` quoting normalisation is omitted here — `Sp_saveReturn_sOiv` is expected to handle quoting itself.

**Invocation:** Hooked as `gdsmodule.sSaveProNameBefore` on module `发外发票` (sId `101251168116315832142387420`). Neither dispatcher (`Sp_Invalid_backwriting`, `Sp_delete_backwriting`) calls this name, and no xly-src install script ships it — install path differs from the rest of the family.
