# `Sp_saveReturn_sWod` (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_sWod`'`._

## Narrative

**Business context:** 生产管理 → 生产工单 / 轮转工单 — quantity back-write helper for the 生产工单 (`mftworkordermaster` / `MftWorkOrderSlave`) save flow. When a work-order is created or saved this proc rolls the work-order qty back onto the upstream 销售订单 slave so the order shows how much has been issued into production.

**What it does:** Parses `sGuid` into ids, joins `MftWorkOrderSlave` to find the source `sSrcSlaveId` for each affected work-order line, aggregates per source through `p_MftworkOrderSlave_tmp` / `p_MftworkOrderSlave_tmp1` (qty / money / loss / proofing / plate / knife / freight / remainder buckets), then UPDATEs the totals onto the upstream order slave. `iTag` flips the include/exclude of the current save batch.

**Invocation:** Called from `Sp_beforeSave_sWod(iTag=1)` and `Sp_afterSave_sWod(iTag=2)`. `Sp_beforeSave_sWod` is bound as `sSaveProNameBefore` on `101251240115015840916341460` (轮转工单), `101251240115016002469445380` (生产工单) and `101251240115016098136660960` (2/3 新增生产补单). xly-src install: `script/标版/30100101/Sp_afterSave_sWod.sql`.
