# `Sp_QlyProduct_BtnCalculate` (procedure)


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

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `sProInParam` | `varchar(10000)` |
| 2 | IN | `sMakePerson` | `varchar(100)` |
| 3 | IN | `sBrId` | `varchar(100)` |
| 4 | IN | `sSuId` | `varchar(100)` |
| 5 | OUT | `sReturn` | `varchar(1000)` |
| 6 | OUT | `sCode` | `int` |

## Body

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

## Narrative

**Business context:** 质量管理 / 成品检验 — toolbar-button variant of `Sp_QlyProductJudge`: takes the selected grid row(s) via `sProInParam` JSON (rather than a single `sGuid`), then runs the standard "fill sample thresholds + roll up pass/fail" sequence on `QlyProductTestSlave` / `qlyproducttestmaster`.

**What it does:** Validates `sProInParam` is valid JSON and has params (returns localised `paramsErro` / `chooseData` errors via `Fun_Sis_GetConst` otherwise). Extracts the first row's `sId` and `sSlaveId` from `$.params[0].value[0]`. `UPDATE QlyProductTestSlave A INNER JOIN EleTestStandardItem B INNER JOIN qlyproducttestmaster C SET A.dSampleQty=B.iSample, A.iAcQty=B.iAccept, A.iReQty=B.iReject WHERE A.sParentId=p_sId AND C.dProductQty BETWEEN B.iQuantityFrom AND B.iQuantityTo`. Then rolls master `iTestResult = (COUNT slave sActValue='不合格' > 0 ? 1 : 0)` and `dSampleQty = MAX(slave.dSampleQty)`.

**Invocation:** Status: appears orphaned. No caller found in any channel (form-master, gdsmodule hooks, other routines, xly-src grep across all extensions). The `sProInParam`-shaped signature is the standard `GenericProcedureCallServiceImpl.doGenericProcedureCall()` button-handler contract, so this is intended for a 自动判断 toolbar button on the 成品检验 grid — currently with no DB-level binding found; candidate for maintainer audit. Sibling: `Sp_QlyProductJudge` (single-row, `sSaveProNameBefore`-shaped signature).

Bug note: leaves a stray `SELECT p_sId, p_sSlaveId;` in the body, which is returned to the caller as a result set — likely debug residue.
