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

## Narrative

**Business context:** Post-save validator nominally for 采购到货单据 (per procedure summary), targeting `purpurchasearrivemaster`/`purpurchasearriveslave`. Gates on 反算 materials needing 到货数量 entry, then recomputes per-line money/tax/qty fields against the chosen tax rate and the material's 正算/反算 formula.

**What it does:** Counts `purpurchasearriveslave` rows joined to `elematerials` where `iHandIn=1` AND `bInverse=0`; on hit, aborts with sCode=-8 and `sMaterialNotFsgsDh` (物料不是反算公式物料，请输入到货数量进行计算) concatenated with the offending material names. Reads `NetMoney`/`NetPrice` precision from `SysSystemSettings`, then opens a cursor over `purpurchasearriveslave` joined to `elematerials`/`sistax` and recomputes `dMaterialsMoney`/`dMaterialsNoTaxMoney`/`dMaterialsTaxMoney`/`dAuxiliaryQty` per row using the chosen 正算/反算 formula and tax rate.

**Invocation:** Status: appears orphaned. No `gdsmodule.sSaveProName`/`sSaveProNameBefore`/`sProcName`/`sDeleteProName` row references it; no form-master `sSqlStr` ref; no other DB routine calls it; xly-src grep finds only `script/标版/30100101/Sp_Check_sPca.sql` (the install body). The 采购到货 module appears to dispatch its post-save logic through a different `sSaveProName` (or the `sPca1` variant below) — candidate for maintainer audit.
