# `Sp_saveReturn_sPst` (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_sPst`'`._

## Narrative

**Business context:** 生产管理 → 成品入库 — back-write helper for 成品入库 (`PitProductInStoreMaster`). When a finished-goods receipt is saved or cancelled, it re-aggregates the inwarded qty back onto the source 工单 line, the originating 销售订单 (`salsalesorderslave`), the 销售退货 line being replenished, and any matching 成品检验 master that gated it.

**What it does:** Splits `sGuid` into `p_t_sId`, fills `p_sOrderSlaveId_tmp`, `p_sReturnSlaveId_tmp`, `p_sWorkOrderSlaveId_tmp` plus `t_data_temp` aggregates, then updates `MftWorkOrderSlave`, `salsalesorderslave`, `qlyproducttestmaster` setting `dInStoreQty/dCheckQty`. Page metadata mis-labels it as "供货资格申请" — body and COMMENT (`成品入库保存后反写数量`) both target 成品入库. `iTag=1` excludes current doc; `iTag=2` includes it.

**Invocation:** Wrapped by `Sp_afterSave_sPst` (iTag=2) and `Sp_beforeSave_sPst` (iTag=1). 成品入库 binds `Sp_Check_sPst`/`Sp_beforeSave_sPst` on `gdsmodule`; `Sp_afterSave_sPst` is dispatched by `Sp_Invalid_backwriting` on cancel/un-cancel. Install script: `xly-src/script/标版/30100101/Sp_afterSave_sPst.sql`.
