# `Sp_saveReturn_sLok` (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_sLok`'`._

## Narrative

**Business context:** 物流管理 → 10.物流单据 → 物流对账单单据 — back-writes 物流对账 (`logisticsorderdetails`) figures and supplier balances when a 物流对账单 is saved, so the 物流单 and 应付/外协厂 accounts stay tied to the reconciliation totals.

**What it does:** Splits `sGuid` into `p_t_sId`, collects both `sSrcId` (master) and `sSrcSlaveId` into `p_sSrcId_tmp` / `p_sSrcSlaveId_tmp`, sums logistic amounts into `t_data_temp` with `iTag=1` zeroing the current batch, then updates `logisticsorderdetails` (the source 物流单 detail rows), `OpsOutsideInStoreSlave` / `opsoutsideinstorededslave` (when the 物流单 originated from 发外入库), and `CahSupplyInit` (supplier opening-balance / running account).

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