# `Sp_CheckExceedReport` (procedure)

> 判断工单是否完工并修改


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

## Parameters

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

## Body

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

## Narrative

**Business context:** 生产报工 (production report) per-process over-quantity gate, called from `Sp_Calc_sPpr`. For each reported process whose `eleProcess.sReportType` is `2` (按实际投入数) it enforces that you cannot report more on a downstream process than what was reported on the prior process; `sReportType` of `3` (按计划投入数) and `4` (按正数) carry their own caps that this proc evaluates the same way. The setting `CkxProductionReport` in `SysSystemSettings` (`productionplan` or `workorder`) decides whether the prior-process anchor is the production plan slave or the work-order process slave.

**What it does:** Opens a cursor over `viw_mftproductionreport` rows for the current bill (`sId=sGuid`) joined to `eleProcess` filtered to `sReportType <> '1'`. For each row, calls `Sp_SortReportProcess` to refresh `mftworkorderprocess.iGroupOrder`, then looks up the current process's `iGroupOrder` (from `mftproductionplanslave` or `mftworkorderprocess` depending on the system setting), the minimum `iGroupOrder` on the work order, and the prior process's `dProductionReportQty`/`sProcessName`. Compares the cumulative `dReportQty` against the prior anchor; when over, sets `sCode` to a negative status, builds `sReturn` with `<sPriorProcessName>已报工<X>, 本工序累计已超出` style messages, and exits via the cursor's NOT FOUND handler.

**Invocation:** Called by `Sp_Calc_sPpr` (生产报工审核, the `Sp_Calc_s<Code>` audit dispatcher for 生产报工) during the audit-time validation pass. Not bound to any UI module directly.
