# `Sp_saveReturn_sScr` (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_sScr`'`._

## Narrative

**Business context:** 储运管理 → 派车单 — back-write helper for 派车单 (`salsendcarmaster`). When a dispatch doc is saved or cancelled, it re-aggregates the loaded qty back onto the source 送货单 line (`saldelivergoodsslave.dSendCarQty`) so the warehouse-dispatch grid shows the latest "已派车" total.

**What it does:** Splits `sGuid` into `p_t_sId`, joins `salsendcarslave` to `salsendcarmaster` (`bInvalid=0`) and aggregates `dProductQty` per `sSrcSlaveId` into `p_MftworkOrderSlave_tmp`, then `UPDATE saldelivergoodsslave A JOIN p_MftworkOrderSlave_tmp B SET A.dSendCarQty = IFNULL(B.dProductQty,0)`. `iTag=1` (before/delete) subtracts current doc via `IF(INSTR(sGuid,M.sId)>0,0,…)`; `iTag=2` (after) includes it.

**Invocation:** Wrapped by `Sp_afterSave_sScr` (iTag=2) and `Sp_beforeSave_sScr` (iTag=1). 派车单单据 (`sId 15839936170002427227633635401000`) binds `Sp_Check_sScr`/`Sp_beforeSave_sScr` on `gdsmodule`; `Sp_afterSave_sScr` is dispatched by `Sp_Invalid_backwriting` on cancel/un-cancel. Install script: `xly-src/script/标版/30100101/Sp_afterSave_sScr.sql`.
