# `Sp_Calc_sWod` (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_sWod`'`._

## Narrative

**Business context:** 生产管理 → 生产单据 / 订单生产流程 — work-order audit (审核 / 反审核). The umbrella `Sp_Calc_s*` handler for every flavour of 工单 (production work-order) in xly: 生产工单, 印刷工单系列 (轮转 / 丝印 / 柔印 / 数码 / 膜类 / 书刊 / 通用 / 套装 / 材料加工), prepress 打样工单, 制版/印刷工作单, plus their 补单 (supplemental) variants. Auditing the work-order locks specs and emits its production plan; un-auditing reverses.

**What it does:** ~168 KB body. Branches on `iFlag`. On audit: validates `sGuid`, refuses on `bInvalid=1` or already `bCheck=1`; copies/locks technology, materials and process versions; allocates a new `MftProductMaster`/`MftProductSlave`/`MftProductControl` row when the work-order changes product (`sChangeProductGuid`), `Insert into mftproductionplan` to seed the production-plan row, `Insert into eleproductcustomer` to register customer-product binding, `Insert into EleMaterialsStock` reservation, `UPDATE EleKnifeMould` to reserve knife-mould assets, may `CALL SP_Sis_GetMaxNo` for the plan no. Optionally invokes `Sp_System_CheckFlow` (custom approval). Finally `CALL Sp_Bill_Used` for usage registration. On un-audit symmetric clean-up.

**Invocation:** Bound to `gdsmodule.sProcName` on **22+** work-order modules: 生产工单, 轮转工单, 合版工单, 丝印工单 + 补单, 柔印工单, 数码工单, 膜类工单 + 补单, 书刊工单 + 补单, 通用工单 + 补单, 套装工单, 材料加工单, 实验工单, 打样工单 (各类), 白样 / 蓝纸 / 制版 / 测试 / 印刷工作单, 2/3 新增生产补单 + 新增轮转补单, 包装补单(new), 生产工单(兼容停用), 生产补单(兼容停用). For 生产工单 / 轮转工单 / 2-3 新增生产补单 also drives the `sSaveProName=Sp_Check_sWod`, `sSaveProNameBefore=Sp_beforeSave_sWod`, `sDeleteProName=Sp_afterSave_sWod` hooks. Dispatched by Java `BusinessBaseServiceImpl.getPrcName(sFormGuid, ...)`. Also called by sibling procs `Sp_Calc_sBgd`, `Sp_Calc_sRct`, `Sp_Calc_sRcts`, `Sp_Calc_sRct_copy1` (cascading audit of related bills). xly-src ships install + optimize scripts at `script/标版/30100101/Sp_Calc_sWod.sql` and `script/标版/optimize/Sp_Calc_sWod.sql`, plus customer overrides under `script/客户/` (金宣发, 千彩, 上海亚峰 — verify which is deployed).
