# `Sp_Check_sScr` (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_sScr`'`._

## Narrative

**Business context:** Inferred from the name and routine comment: 物流管理 → 10.物流单据 → 派车单 — would-be post-save validator on `salsendcarmaster`/`salsendcarslave`. Caps each dispatch line's quantity against the originating 送货单 line, so a single 派车单 cannot over-allocate against the source delivery.

**What it does:** Sets `sCode=1`, `iFlag=0`, clears `sReturn`. Reads `NetMoney`/`NetPrice` precisions (unused — template scaffolding). When `sFormGuid` is set, opens a cursor over `salsendcarslave` rows for `sParentId=sGuid`. For each row with a non-empty `sSrcSlaveId`, joins to `saldelivergoodsslave` (source 送货单 line) and the summed `dProductQty` from `salsendcarslave` (non-invalid masters only) and `eleproduct`, computing `(Q.dProductQty - SUM(S.dProductQty))`. When the result is negative, concatenates either `sProductInPcd` ("产品名称在当前派车单中") or `sProductInPcdNo` ("产品名称在派车单中,单号") with `sScrDeliveryQtyUpProduct` ("送货数已超过产品数量") into `sReturn`. Sets `sCode=-1` and exits if `sReturn` is non-empty, otherwise calls `Sp_afterSave_sScr`.

**Invocation:** Status: appears orphaned. The module `派车单单据` (`15839936170002427227633635401000`, 物流管理 → 10.物流单据) binds `Sp_Calc_sScr` on `sProcName`, but `Sp_Check_sScr` itself is not wired as `sSaveProName`/`sSaveProNameBefore` on that module or any other. No other routine references it. xly-src ships `script/标版/30100101/Sp_Check_sScr.sql` as the install body — the script is in the codebase but the hook is unbound — candidate for maintainer audit.
