# `Sp_beforeSave_sDgd` (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_sDgd`'`._

## Narrative

**Business context:** 销售送货流程 / 送货单单据 (also 扫码送货(单据), 材料送货单) — before-save dispatcher for the delivery-note family. Wraps `sGuid` and delegates to `Sp_saveReturn_sDgd` to backwrite delivery quantities onto the upstream sales-order / dispatch documents before the master save commits. Comment header: `送货单保存前反写数量`.

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

**Invocation:** Hooked as `gdsmodule.sSaveProNameBefore` on 3 modules — `送货单单据` (sId `11811781131121915179924491520`), `扫码送货(单据)` (`101251240115015959853077870`), `材料送货单` (`101251240115016140459724020`). Also called by dispatcher procs `Sp_Invalid_backwriting` and `Sp_delete_backwriting` to replay the writeback on invalidate/delete.
