# `Sp_Check_sPsra` (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_sPsra`'`._

## Narrative

**Business context:** Inferred from the name and routine comment: 销售管理 → 销售退货 → 销售退货申请 — would-be post-save validator on `salrejectgoodsapplymaster`/`salrejectgoodsapplyslave`. Guards 退货走账/无实物退货 mutual exclusion, recomputes line money against tax rate, and ensures the requested return qty does not exceed the actual 出库 qty in the originating delivery note.

**What it does:** Sets `sCode=1`, `iFlag=0`, clears `sReturn`. Aborts with `sChooseThzz` ("勾选了退货走账，不能勾选无实物退货") when any slave row has both `bNoObject=1` and the master's `bNotAccident=1`. Then `UPDATE salrejectgoodsapplyslave INNER JOIN sistax` recomputes `dProductMoney`, `dProductForeignMoney`, `dProductNoTaxPrice`/`Money`, `dProductTaxMoney`, `dNProductPrice`/`Money` per the joined tax rate. Opens a cursor over the slave rows and, for each `sSrcNo`+`sProductId`+`sDefineNo`, sums the matching `saldelivergoodsslavechildren.dProductQty` (joined via `saldelivergoodsmaster.sBillNo`) and aborts with a concatenated `sChooseThzz`/`sOutStoreQtyLessReturn` ("在出库单中的出库数量少于退货申请数量；请重新选择批次,出库单号") when the requested qty exceeds the delivered qty.

**Invocation:** Status: appears orphaned. No `gdsmodule` row binds this proc on `sSaveProName`/`sSaveProNameBefore`. No `Sp_Calc_sPsra` exists either. No other routine references it, no `xly-src` hit (no install script). The body is substantive and clearly intended for a 销售退货申请 form, but the dispatch wire is missing — candidate for maintainer audit.
