# `Sp_saveReturn_sPdt` (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_sPdt`'`._

## Narrative

**Business context:** 品质管理 → 成品外购检验 — back-write helper for the 成品外购检验单据 (`qlyproducttestmaster/slave`). Re-syncs inspected/accepted quantities back to every upstream document the inspected line came from when the inspection is saved, cancelled, or deleted.

**What it does:** Splits `sGuid` into `p_t_sId`, builds `t_data_temp/t_data_temp2` with `sSrcSlaveId` aggregates from the inspection slaves, then updates the source-line tables — `mftproductionplanbillslave`, `MftWorkOrderSlave`, `opsoutsideprocessslave`, `saldelivernotifyslave`, `SgdSemigoodsMatchBillMaster` — adjusting their inspected/accepted column. `iTag=1` excludes the current `sGuid` (before-save / delete); `iTag=2` includes it (after-save / uncancel).

**Invocation:** Wrapped by `Sp_afterSave_sPdt` (after-save / uncancel, `iTag=2`) and `Sp_beforeSave_sPdt` (before-save / delete, `iTag=1`). Those wrappers are routed by `Sp_Invalid_backwriting` / `Sp_delete_backwriting` for the 成品外购检验 form. Install script: `xly-src/script/标版/30100101/Sp_afterSave_sPdt.sql`.
