# `Sp_Calc_sPct` (procedure)

> 发外检验


- **Type:** PROCEDURE
- **Deterministic:** NO
- **SQL data access:** CONTAINS SQL

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `iFlag` | `int` |
| 2 | IN | `iTmpCheck` | `int` |
| 3 | IN | `sFormGuid` | `varchar(100)` |
| 4 | IN | `sGuid` | `varchar(100)` |
| 5 | IN | `sLoginId` | `varchar(100)` |
| 6 | OUT | `sReturn` | `varchar(4000)` |
| 7 | IN | `sBrId` | `varchar(100)` |
| 8 | IN | `sSuId` | `varchar(100)` |
| 9 | OUT | `sCode` | `int` |

## Body

_Body is not pre-cached. To inspect: `mysql --defaults-file=~/.my.cnf -e 'SHOW CREATE PROCEDURE `Sp_Calc_sPct`'`._

## Narrative

**Business context:** Two-bind audit for the 工序检验 (in-process / process inspection) doc on `QlyProcessTestMaster`. Serves both the desktop 质量管理 → 质量管理单据 → 工序检验单据 and the mobile 移动端管理 → 现场 → 功能操作 → 工序检验(单据). On approval it freezes the inspection result and (when configured) writes the inspector's KPI row so the operator gets credit for the inspection event.

**What it does:** Validates `sGuid`, refuses re-audit when `bCheck=1`, then `Update QlyProcessTestMaster` to set `bCheck=1, sStatus=1, sCheckPerson, tCheckDate=NOW()`; joins back to `QlyProcessTestMaster` aliases for related-record consistency, reads `gdsmodule` + `SysSystemSettings` to decide whether to `INSERT INTO kpidetail`, and `CALL`s the standard workflow/consumption hooks (`Sp_System_CheckFlow`, `Sp_Bill_Used`). `iFlag=0` reverses the flags.

**Invocation:** Bound to `gdsmodule.sProcName` on:
- `工序检验单据` (sId `15818303350003257780407017498600`) — 质量管理 → 质量管理单据
- `工序检验(单据)` (sId `101251240115016197764940500`) — 移动端管理 → 现场 → 功能操作

Dispatched by `BusinessBaseServiceImpl.getPrcName(sFormGuid, …)`. Install scripts ship at `script/标版/30100101/Sp_Calc_sPct.sql` and `script/标版/optimize/Sp_Calc_sPct.sql`. Variants `Sp_Calc_sPct1` (首检/印刷大检), `Sp_Calc_sPct2` (巡检), `Sp_Calc_sPct3` (OEE 机长首检) cover different QC modes against the same table.
