# `Sp_saveReturn_sPrj` (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_sPrj`'`._

## Narrative

**Business context:** 采购管理 → 采购退货 — back-write helper for 采购退货 (`PurPurchaseRejectMaster`). When a purchase-return is saved or cancelled, it re-aggregates the returned qty back to the source 采购订单 line and the receipt (`PurPurchaseInStoreSlave`) that the return points at, so the order's "已退" and the receipt's "已退" stay consistent.

**What it does:** Splits `sGuid` into `p_t_sId`, fills `p_data_tmp` with `sSrcSlaveId/sPurchaseOrderSlaveId` aggregates from `PurPurchaseRejectSlave`, then updates `purpurchaseorderslave` and `PurPurchaseInStoreSlave`. `iTag=1` (before/delete) excludes the current 采购退货; `iTag=2` (after) includes it.

**Invocation:** Wrapped by `Sp_afterSave_sPrj` (iTag=2) and `Sp_beforeSave_sPrj` (iTag=1). 采购退货 forms bind through the standard `Sp_Check_*`/`Sp_beforeSave_*` slots on `gdsmodule`; `Sp_afterSave_sPrj` is reached via `Sp_Invalid_backwriting` on cancel/un-cancel. Routine COMMENT says "保存前反写报价数量" — wording predates a refactor; current body adjusts qty, not 报价.
