# `Sp_saveReturn_sQtt` (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_sQtt`'`._

## Narrative

**Business context:** 销售管理 → 估价单 — back-write helper for 估价单 (`quoquotationmaster`). When a quote is saved or cancelled, it stamps the quote id (or clears it) onto the originating 销售机会产品 (`salsaleschanceproduct`) so the sales-opportunity record knows which 报价 is current.

**What it does:** Splits `sGuid` into `p_t_sId`, builds `p_sSrcSlaveId_tmp` from `pitproductrejectslave` joins to the quote slaves, then updates `salsaleschanceproduct.sQuotationId` — `iTag=1` (before-save / delete) clears the link (`= ''''`); `iTag=2` (after-save) sets it to the parent `quoquotationmaster.sId`. Scoped to `sBrId/sSuId`.

**Invocation:** Wrapped by `Sp_afterSave_sQtt` (iTag=2) and `Sp_beforeSave_sQtt` (iTag=1). The 估价单 form binds `Sp_Check_sQtt`/`Sp_beforeSave_sQtt` on `gdsmodule`; `Sp_afterSave_sQtt` is dispatched by `Sp_Invalid_backwriting` on cancel/un-cancel. The body's `pitproductrejectslave` join looks misplaced for a quote — keep an eye on it; it may be a copy-paste from `Sp_saveReturn_sPdt`.
