# `Fun_Get_Change_WorkOrderStatus` (procedure)

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


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

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `sWorkOrderGuid` | `varchar(50)` |
| 2 | IN | `sSrcModifyType` | `varchar(255)` |
| 3 | IN | `sLoginId` | `varchar(255)` |
| 4 | IN | `sBrId` | `varchar(50)` |
| 5 | IN | `sSuId` | `varchar(50)` |

## Body

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

## Narrative

**Business context:** 生产管理 / 工单完工状态 — recomputes whether a work order is finished (`bBillComplete`) by comparing requested vs reported/in-store quantities. Branches on whether the work order is `bBillOutside` (整单发外) or in-house: outside path compares 成品入库数量 to `opsoutsideprocessslave` totals, in-house path compares 入库数量 plus per-process 产量上报 / 发外回库 完工 status.

**What it does:** Builds a temp table `workorderTmp` from `viw_mftworkorder`, joins it to source detail tables, then issues an `UPDATE MftWorkOrderMaster` setting `bBillComplete`, `tBillCompleteDate = SYSDATE()` when newly complete, and appends the trigger context (`sLoginId`/`sSrcModifyType`) to `sCompletePerson` as an audit trail. The in-house branch additionally builds a second temp table `p_MftWorkOrderProcess` to classify each process row's `iStatus` (1=未做 / 2=进行中 / 5=完工) by `dProductionReportQty` vs `dDispatchQty` and 发外完工; a work-order is considered complete only when **all** processes reach `iStatus=5`.

**Invocation:** Status: appears orphaned. No form-master, gdsmodule hook, routine caller, or xly-src reference. The "Fun_" name + `declare result bit(1) ... # return result` commented-out tail suggest this began as a function and was converted to a procedure; the live work-order completion recompute likely lives in the `Sp_Calc_sWod*` / `Sp_WorkOrder_*Complete` family instead. Candidate for maintainer audit — confirm whether this is intended to be wired into bill-event triggers (产量上报 / 成品入库 / 发外回库 save hooks).
