# `Sp_saveReturn_sRct` (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_sRct`'`._

## Narrative

**Business context:** 财务管理 → 收款单 — back-write helper for 收款单 (`CahReceiptMaster`). The receipt settles many sales-side documents at once; whenever it's saved or cancelled this proc fans the received amount back to the matched 销售订单/送货/对账/发票 lines, the customer opening balance, payment/refund records, the work-order master/slave (for direct-charge orders), and quality-abnormal claims.

**What it does:** Splits `sGuid` into `p_t_sId`, builds `t_data_temp`, then UPDATEs across `SalSalesOrderMaster/Slave`, `SalDeliverGoodsMaster/Slave`, `SalSalesCheckingSlave`, `SalSalesInvoiceSlave`, `MftWorkOrderMaster/Slave`, `CahCustomerInit`, `CahPaymentMaster`, `CahReceiptMaster`, `CahFinancialAdjust` — adjusting received/refund amounts. `iTag=1` (before/delete) excludes current 收款 doc; `iTag=2` (after) includes it.

**Invocation:** Wrapped by `Sp_afterSave_sRct` (iTag=2) and `Sp_beforeSave_sRct` (iTag=1) — and notably also re-used by `Sp_afterSave_sRcts`/`Sp_beforeSave_sRcts` (the 汇总 variant delegates to this same `Sp_saveReturn_sRct`). 收款单 binds `Sp_Check_sRct`/`Sp_beforeSave_sRct` on `gdsmodule`; `Sp_afterSave_sRct` is dispatched by `Sp_Invalid_backwriting`. Page front-matter mis-labels as "估价单保存前反写状态" — proc COMMENT and body target 收款单.
