# `Sp_Check_sRgd` (procedure) > 材料销售退货单据保存之前数据校验 - **Type:** PROCEDURE - **Deterministic:** NO - **SQL data access:** CONTAINS SQL ## Parameters | # | Mode | Name | Type | |---|---|---|---| | 1 | IN | `sTableName` | `varchar(100)` | | 2 | IN | `sGuid` | `varchar(100)` | | 3 | IN | `sFormGuid` | `varchar(100)` | | 4 | IN | `sLoginId` | `varchar(100)` | | 5 | IN | `sBrId` | `varchar(100)` | | 6 | IN | `sSuId` | `varchar(100)` | | 7 | IN | `iFlag` | `int` | | 8 | OUT | `sCode` | `int` | | 9 | OUT | `sReturn` | `varchar(4000)` | ## Body _Body is not pre-cached. To inspect: `mysql --defaults-file=~/.my.cnf -e 'SHOW CREATE PROCEDURE `Sp_Check_sRgd`'`._ ## Narrative **Business context:** 销售管理 → 销售送货流程 → 新增销售退货 — post-save validator on `salrejectgoodsmaster`/`salrejectgoodsslave` (`sRgd` = sales-reject-goods despite the comment calling out 材料销售退货). Two business rules: deny duplicate 红冲 submissions for the same source bill, and forbid mixing different `sSlaveType` (退货类型) within one return note. Also bridges to `Sp_Check_dOraQtyTs` for over-quantity guard. **What it does:** Sets `sCode=1`, `iFlag=0`, clears `sReturn`. Reads `pitproductrejectmaster.sMinusSrcId` (red-charge source). If set, joins original slave rows with summed reverse-charge `dProductQty` per `sMinusSrcSlaveId` (only against non-invalid masters) and aborts with `sCcprkHaveRedData` ("已存在红冲数据,不允许重复提交") when any imbalance survives. Then `SELECT COUNT(DISTINCT sSlaveType) FROM salrejectgoodsslave WHERE sParentId=sGuid` — if >1, aborts with `sReturnOrderCantDiffrentType` ("不同退货类型的退货申请单不能做在同一个退货单上"). Opens a cursor over `viw_salrejectgoods` (the large block of further per-slave 余数库 reconciliation and auto-inserting split rows is fully commented out). Calls `Sp_Check_dOraQtyTs('salrejectgoodsslave', 'dProductQty', ...)` for the family-shared over-qty check, then `Sp_afterSave_sRgd`. **Invocation:** Bound to `gdsmodule.sSaveProName` on `2/4 新增销售退货` (`11811781131121915179924871530`) — 销售管理 → 销售送货流程 (KPI流程操作菜单). Dispatched by `BusinessBaseServiceImpl.checkUpdate(..., "sSaveProName")` after the save batch commits. Pre-save peer is `Sp_beforeSave_sRgd`. xly-src ships `script/标版/30100101/Sp_Check_sRgd.sql` as the install body.