# `Sp_Check_sOpp` (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_sOpp`'`._

## Narrative

**Business context:** KPI流程操作菜单 → 发外加工流程 → 整单发外 — post-save validator on `opsoutsideprocessmaster`/`opsoutsideprocessslave`. Recomputes per-line money/tax/qty fields against the chosen tax rate and the material's 正算/反算 formula so the slave totals stay coherent after price/quantity edits.

**What it does:** Reads `NetMoney`/`NetPrice` precision from `SysSystemSettings`. Inside the `top:` block, opens a cursor over `opsoutsideprocessslave` joined to `elematerials` (for `bInverse`, `sReComputeId`, `sComputeId`, `sMaterialsName`) and `sistax` (for `dRate`). For each row recomputes `dMaterialsMoney`/`dMaterialsNoTaxMoney`/`dMaterialsTaxMoney`/`dAuxiliaryQty` via the material's compute formula (forward or inverse), updates the slave with the rounded values, then aggregates the slave totals into the master.

**Invocation:** Bound to `gdsmodule.sSaveProName` (post-save) on `整单发外` (`192116810113315234963208090`, under KPI流程操作菜单 → 发外加工流程). Dispatched by `BusinessBaseServiceImpl.checkUpdate(..., "sSaveProName")` after the save batch commits. xly-src ships `script/标版/30100101/Sp_Check_sOpp.sql` as the install body.
