# `Sp_afterSave_sPpr` (procedure)

> 产量上报保存后反写数量


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

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `sGuid` | `varchar(2000)` |
| 2 | IN | `sBrId` | `varchar(100)` |
| 3 | IN | `sSuId` | `varchar(100)` |
| 4 | IN | `iFlag` | `int` |
| 5 | OUT | `sCode` | `int` |
| 6 | OUT | `sReturn` | `varchar(4000)` |

## Body

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

## Narrative

**Business context:** 产量上报 → 订单生产流程 → KPI流程操作菜单 — header says 产量上报保存后反写数量. Save-phase wrapper in the `Sp_afterSave_s<Code>` family for 产量上报 (production-quantity-report) bills. Unlike most siblings this one carries real body logic on top of the standard `Sp_saveReturn_sPpr` delegation: an 超报校验 (over-report validation) guard plus several housekeeping updates on `mftproductionreportslave` / `mftproductionreportemployee`.

**What it does:** Sets `iFlag` default 0 and `sReturn` empty; when `iFlag=0` builds a temporary table `p_Root_MftProductionReportSlave` joining `MftProductionReportSlave` → `mftproductionplanslave` and compares `SUM(dProcessQty)` of all report rows against the plan's `dProcessQty`; if any process is over-reported it emits the `sOverReport` i18n message and `LEAVE top` with `sCode=-7`. Then deletes empty-employee rows from `mftproductionreportemployee`; recomputes `dOtherHour`/`dAllHour`/`dSumEmpNum`/`dEmpHour` on `mftproductionreportslave`; reads the `CbxProductionReport` setting from `SysSystemSettings`; finally calls `Sp_saveReturn_sPpr(sGuid, sBrId, sSuId, 2, @sCode, @sReturn)`.

**Invocation:** Status: appears dormant. Both known call sites are commented out — `Sp_Check_sPpr` (the proc bound via `gdsmodule.sSaveProName` on 产量上报) has its `call Sp_afterSave_sPpr(...)` block commented, and the `Sp_Invalid_backwriting` dispatch branch for `sFormGuid='19211681019715476042694840'` (产量上报) is also commented. No live caller found in any channel — candidate for maintainer audit.

Caveats: uses `sGuId` (capital `I`) in several queries while the parameter is `sGuid` — relies on MySQL identifier case-insensitivity, but the inconsistency is worth flagging.
