# `Sp_Calc_sRetunWork` (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_sRetunWork`'`._

## Narrative

**Business context:** 返工单审核 — audit / un-audit of a 返工单 (rework / re-work order) on `mftproductionplanbillslave`. Used when a finished or partly-finished piece fails QC and a rework cycle is scheduled into the production plan. The audit flips the planbill-slave's `bCheck`/`sStatus`/`sCheckPerson`/`tCheckDate` so downstream MES can pick the rework as an actionable plan row.

**What it does:** Validates `sGuid`, refuses when the source row is being edited (`SysLocking` lock check) or `bInvalid=1`. On `iFlag=1` guards on already-checked, then `UPDATE mftproductionplanbillslave` to set `bCheck=1`, `sStatus=1`, stamp `sCheckPerson`/`tCheckDate`. `iFlag=0` reverses. Body declares hooks for source-order / materials / supplier-pay processing that are kept but not exercised in the active branch — likely vestiges of a richer prior version.

**Invocation:** No `gdsmodule.sProcName='Sp_Calc_sRetunWork'` binding in this snapshot, no other proc/func references it, no metadata `gdsconfigformmaster` hits. xly-src ships `script/标版/30100101/Sp_Calc_sRetunWork.sql` (install script). **Status: appears orphaned in the standard dispatcher path.** Either dispatched via a 返工单 module installed in a customer overlay not in this snapshot, or invoked from a manual maintenance script — candidate for maintainer audit.

Naming note: `sRetunWork` is missing the "r" in 返工 → should likely be `sReturnWork`. Casing/spelling outlier kept for backwards-compat with any deployed binding that uses the misspelling.
