# `Sp_beforeSave_sSiv` (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_sSiv`'`._

## Narrative

**Business context:** 销售发票单据 / 销售送货流程 — before-save dispatcher for the sales-invoice document. Wraps `sGuid` and delegates to `Sp_saveReturn_sSiv` to backwrite invoiced quantity / money onto the upstream sales-order and delivery-note lines before the invoice master save commits. Header comment: `销售发票保存前反写`.

**What it does:** Normalises `sGuid` to a quoted-CSV form, declares an unused `sDeliverSrc` local, then `CALL Sp_saveReturn_sSiv(sGuid, sBrId, sSuId, 1, @sCode, @sReturn)`.

**Invocation:** Hooked as `gdsmodule.sSaveProNameBefore` on module `销售发票单据` (sId `15780358080007074056281633539000`, parent `销售送货流程`). Also dispatched by `Sp_Invalid_backwriting` and `Sp_delete_backwriting` when `sFormGuid = '15780358080007074056281633539000'`, so the writeback is replayed on cancel-invalidate and on delete.
