# `Sp_saveReturn_sPca` (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_sPca`'`._

## Narrative

**Business context:** 物料采购流程 → 采购到货(送检) — when a 采购到货送检 document is saved, back-writes the arrived qty onto the upstream 采购订单 slave (`purpurchaseorderslave`) so the order's "已到货" balance moves before the inspection completes.

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

**Invocation:** Called by `Sp_beforeSave_sPca` (`iTag=1`) and `Sp_afterSave_sPca` (`iTag=2`), and also by the `_sPca1` variant pair (`Sp_beforeSave_sPca1` / `Sp_afterSave_sPca1`) — both wrappers route to this single `Sp_saveReturn_sPca`. `Sp_Invalid_backwriting` / `Sp_delete_backwriting` re-route to `Sp_beforeSave_sPca` for form `101251240115016068096930620` (采购到货) and `Sp_beforeSave_sPca1` for form `1691254111217000139251980` (the alternate variant). The save-side `gdsmodule.sSaveProNameBefore` row is not present in this DB snapshot — likely tenant-form configuration. No xly-src callers.
