# `Sp_saveReturn_sWXKK` (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_sWXKK`'`._

## Narrative

**Business context:** 外协管理 → 外协入库扣款 — quantity back-write helper for the 外协扣款 (outsourcing-deduction, `opsoutsideinstorededmaster` / Slave) doc. The deduction records the qty/money clawed back from a vendor for a quality accident; this helper rolls those numbers onto the originating `mftqualityaccidentmaster` (quality-incident) record so the incident shows how much has been recovered.

**What it does:** Parses `sGuid`, finds the source ids on `opsoutsideinstorededslave`, aggregates the deducted qty/money per source (`dProductQty`, `dProductMoney`, ...) with `iTag` toggling whether the current save-set is included, then `UPDATE mftqualityaccidentmaster` setting the recovered totals.

**Invocation:** Called from `Sp_beforeSave_sWXKK(iTag=1)` and `Sp_afterSave_sWXKK(iTag=2)`. Those wrappers are dispatched on save of the 外协扣款 form by the standard `Sp_beforeSave_<code>` / `Sp_afterSave_<code>` naming convention in `BusinessBaseServiceImpl` (no gdsmodule row binds `Sp_beforeSave_sWXKK` directly) and re-fire on invalidate/delete via `Sp_Invalid_backwriting` / `Sp_delete_backwriting`.
