# `Sp_saveReturn_sOpn` (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_sOpn`'`._

## Narrative

**Business context:** 发外加工流程 — 发外到货通知 (outsource arrival-notice) back-write. When a 发外到货 notice is saved, it back-writes the arrival qty onto the upstream 工序发外 slave (`opsoutsideprocessslave`) so the source line's "已到货" balance stays current ahead of the actual 工序发外入库.

**What it does:** Splits `sGuid` into `p_t_sId`, gathers each line's `sSrcSlaveId` into `p_sSrcSlaveId_tmp`, sums the arrival qty (with `iTag=1` zeroing the in-flight batch) into `t_data_temp`, then `Update opsoutsideprocessslave` rows whose `sId = sSrcSlaveId` with the accumulated arrival qty.

**Invocation:** Called by `Sp_beforeSave_sOpn` (`iTag=1`) and `Sp_afterSave_sOpn` (`iTag=2`). Also called by the `_sOpn1` wrapper pair (`Sp_beforeSave_sOpn1`/`Sp_afterSave_sOpn1`), which route the same way — so the duplicated procedure `Sp_saveReturn_sOpn1` is effectively dead (its callers go through `Sp_saveReturn_sOpn` instead). `Sp_Invalid_backwriting` / `Sp_delete_backwriting` re-route to `Sp_beforeSave_sOpn` for form ids `101801153119616635492000790`, `101801153119616635492273100`, and `1691254111217206694187850` on cancel/delete. The save-side `gdsmodule` binding for 发外到货 was not present in this DB snapshot — likely a tenant-specific form row. No xly-src callers.
