# `Sp_saveReturn_sLos` (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_sLos`'`._

## Narrative

**Business context:** 物流管理 → 10.物流单据 → 物流单单据 — when a 物流单 (`logisticsordermaster`) is saved, back-writes the dispatched freight quantity onto whichever upstream document the load originated from: 送货单 (`saldelivergoodsslave`), 销售退货申请 (`salrejectgoodsapplyslave`), 工序发外 (`opsoutsideprocessslave`), or 采购订单 (`purpurchaseorderslave`). This keeps the source row's "已物流" balance in sync.

**What it does:** Parses `sGuid` into `p_t_sId`, materialises the matching `sSrcSlaveId` set into `p_sSrcSlaveId_tmp`, sums freight quantities/amounts (with `iTag=1` zeroing the in-flight batch so pre-save reflects prior state) into `t_data_temp`, then updates `saldelivergoodsslave`, `salrejectgoodsapplyslave`, `opsoutsideprocessslave`, and `purpurchaseorderslave` rows whose `sId` matches `sSrcSlaveId`.

**Invocation:** Called by `Sp_beforeSave_sLos` (`iTag=1`) and `Sp_afterSave_sLos` (`iTag=2`). The beforeSave wrapper is bound on `gdsmodule.sSaveProNameBefore` for 物流单单据 (`101251240115016270322291050`) under 物流管理 → 10.物流单据 — fired by `BusinessBaseServiceImpl` save hooks. `Sp_Invalid_backwriting` / `Sp_delete_backwriting` re-route to `Sp_beforeSave_sLos` for the same form id on cancel/delete. No xly-src callers.
