# `Sp_saveReturn_sSod` (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_sSod`'`._

## Narrative

**Business context:** 销售管理 → 销售订单 — quantity back-write helper for the 销售订单 (`salsalesordermaster` / `salsalesorderslave`) save flow. When an order is saved or invalidated this proc rolls the ordered qty/money back onto the upstream 报价单 slave (`quoquotationslave`) so the quotation shows its current confirmed-order qty / remaining qty.

**What it does:** Parses `sGuid` into temp ids, collects `sSrcSlaveId` from `salsalesorderslave` for the affected orders, aggregates per source (`dProductQty`, `dProductMoney`, etc.) with `iTag` driving include/exclude of the current save-set, then `UPDATE quoquotationslave` with the new totals.

**Invocation:** Called from `Sp_beforeSave_sSod(iTag=1)` and `Sp_afterSave_sSod(iTag=2)`. `Sp_beforeSave_sSod` is bound on multiple sales-order modules — e.g. `101251240115015878710737470` (1/3 新增轮转销售订单) and `101251240115016086186007360` (1/3 新增销售订单) — via `sSaveProNameBefore`; the afterSave variant is dispatched on the same save event and on invalidate/delete via `Sp_Invalid_backwriting` / `Sp_delete_backwriting`.
