# `Sp_Calc_sBgd` (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(5000)` |
| 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_sBgd`'`._

## Narrative

**Business context:** 生产管理 → 生产单据 → 工艺变更单 — process-change-order check / uncheck on `mftprocesschangemaster`. Approves a 工艺变更 (manufacturing-process change) and back-writes the change into the affected work-orders' BOM, process, slave, and control rows, then refreshes standardized data via the `Sp_WorkOrder_CalcData*Std` helpers.

**What it does:** Validates `sGuid` and re-checks. With `iFlag=1`: refuses if already checked; loads `sWorkOrderId`, `sWorkOrderNo`, `bPlanFrozen`, `bPlanMaterialCheck`, `bCheckWork`, `iChangeType` from the master, then `UPDATE`s `mftworkordermaster`, `mftworkorderslave`, `mftworkorderprocess`, `mftworkordermaterials`, `mftworkordercontrol` to apply the change. Calls `Sp_Calc_sWod`, `Sp_WorkOrder_CalcDataStd`, `Sp_WorkOrder_CalcDataBookStd`, `Sp_WorkOrder_CalcDataSetStd`, `Sp_WorkOrder_CalcDataPackStd` to recompute derived totals, then sets `mftprocesschangemaster.bCheck=1`. With `iFlag=0`: symmetric uncheck.

**Invocation:** Bound to `gdsmodule.sProcName` on:
- `工艺变更单` (sId `101251240115016062111323530`) — 生产管理 → 生产单据
- `功能模块界面设置单据` (sId `16411004790004762980820285096000`) — 开发平台 (developer-platform overlay; not normally seen by end users)

xly-src has a `客户/千彩/Sp_Calc_sBgd.sql` customer-specific override of this proc — verify which one is currently deployed.
