# `Sp_saveReturn_sDgn` (procedure)

> 送货通知单反写


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

## Parameters

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

## Body

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

## Narrative

**Business context:** 销售管理 → 销售送货流程 → 送货通知单单据 (and 销售单据 → 材料送货通知单单据) — back-writes the notified quantity onto the upstream 销售订单 (`salsalesorderslave` / `salsalesorderchild`) and 生产工单 (`mftworkorderslave`) when a 送货通知单 is saved. Keeps the "已通知/未通知" balance on the order rows correct ahead of the actual 送货单.

**What it does:** Splits `sGuid` into `p_t_sId`, materialises every `saldelivernotifyslave.sSrcSlaveId` for the affected masters into `p_sSrcSlaveId_tmp`, sums `dProductQty / dMaterialsQty / dGiveQty …` into `t_data_temp` (with `iTag=1` zeroing the in-flight batch so pre-save sees the prior state) and then updates `salsalesorderslave.dNotifyQty / dMaterialsNotifyQty / dPresentNotifyQty`, `salsalesorderchild`, and `mftworkorderslave` for any rows whose `sSrcSlaveId` matches.

**Invocation:** Called by `Sp_beforeSave_sDgn` (`iTag=1`) and `Sp_afterSave_sDgn` (`iTag=2`). Those wrappers are bound on `gdsmodule.sSaveProNameBefore` for 送货通知单单据 (`15833158840002862255575040533000`) under 销售管理 → 销售送货流程 and for 材料送货通知单单据 (`101251240115016140461755160`) under 销售管理 → 销售单据 — dispatched by `BusinessBaseServiceImpl` save flow. `Sp_Invalid_backwriting` / `Sp_delete_backwriting` re-route to the same wrappers for those form ids on cancel/delete. No xly-src callers.
