# `Sp_saveReturn_sOdt` (procedure)

> 发外检验(mobile单据)反写


- **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_sOdt`'`._

## Narrative

**Business context:** 质量管理 → 质量管理单据 → 发外检验单据 (and 移动端管理 → 现场 → 功能操作 → 发外检验(mobile单据)) — when 发外检验 (outsourcing-incoming inspection) records are saved, back-writes the inspected/pass/fail figures onto the upstream 工序发外 slave (`opsoutsideprocessslave`).

**What it does:** Splits `sGuid` into `p_t_sId`, collects each inspection row's `sSrcSlaveId` into `p_sSrcSlaveId_tmp`, sums the inspection figures (with `iTag=1` zeroing the in-flight batch) into `t_data_temp`, then updates `opsoutsideprocessslave` rows whose `sId = sSrcSlaveId` with the accumulated inspected qty/values.

**Invocation:** Called by `Sp_beforeSave_sOdt` (`iTag=1`) and `Sp_afterSave_sOdt` (`iTag=2`). The beforeSave wrapper is bound on `gdsmodule.sSaveProNameBefore` for 发外检验单据 (`15827076660008241075501010830000`) under 质量管理 → 质量管理单据 and for 发外检验(mobile单据) (`12012615914116374731690490`) under 移动端管理 → 现场 → 功能操作 — fired by `BusinessBaseServiceImpl` save hooks. `Sp_Invalid_backwriting` / `Sp_delete_backwriting` re-route to `Sp_beforeSave_sOdt` for the desktop form id on cancel/delete. No xly-src callers.
