# `Sp_saveReturn_sGYKK` (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_sGYKK`'`._

## Narrative

**Business context:** 供应商扣款 (form sId `1691254111217013970488160`) — when a 供应商扣款单 (`purpurchaseinstorededmaster`/`purpurchaseinstorededslave`) is saved the deducted material amount must be written back to the upstream 质量事故报告 (`mftqualityaccidentmaster`) so the QA accident keeps a running 已扣款 figure.

**What it does:** Splits `sGuid` into temp `p_t_sId`, gathers `purpurchaseinstorededslave.sSrcSlaveId` into `p_sSrcSlaveId_tmp`, sums `-dMaterialsMoney` (with current batch zeroed on `iTag=1`) into `t_data_temp`, then `Update mftqualityaccidentmaster.dBackDeductionMaterialsMoney`. On `iTag=2` it also guards against any positive `dMaterialsPrice` row and aborts with `sReturn='扣款单单价请填写负数!'` (deduction prices must be negative).

**Invocation:** Called by `Sp_beforeSave_sGYKK` (`iTag=1`) and `Sp_afterSave_sGYKK` (`iTag=2`). Those wrappers are not currently bound on `gdsmodule.sSaveProName`/`sSaveProNameBefore` in this DB — they are reached only through the dispatcher chain `Sp_delete_backwriting` / `Sp_Invalid_backwriting`, which route `sFormGuid='1691254111217013970488160'` (供应商扣款) to `Sp_beforeSave_sGYKK` on delete / cancel-then-resubmit. The save-side hook for 供应商扣款 may live in a tenant-specific form row absent from this DB. No xly-src callers; flag if 供应商扣款 save isn't back-writing — the form-master sSaveProName may need to be set to `Sp_afterSave_sGYKK`.
