# `Sp_Calc_sSmb` (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_sSmb`'`._

## Narrative

**Business context:** 生产管理 → 装配工单 / 配墨工单 (assembly work-order / ink-mixing work-order — `sgdsemigoodsmatchbillmaster`) audit / un-audit. Auditing the 装配工单 expands the BOM into production-plan rows, reserves material stock and back-writes the parent 销售订单 with planned qty.

**What it does:** Validates `sGuid`/`bInvalid`, then on `iFlag=1` sets `bCheck=1` on `sgdsemigoodsmatchbillmaster` and its slave/materials/process rows; iterates a `Materials_cursor` and `INSERT INTO mftproductionplan` (one plan row per material) calling `Sp_Manufacture_InsertMftPlan` and `Sp_MaterialsStoreVirtual` for each; updates `EleMaterialsStock` (deduct) and `MitMaterialsStoreVirtual` (delete-reseed); writes back `UPDATE SalSalesOrderSlave` (mark assembled qty); replaces `mftworkorderparam` rows via `Sp_System_ReplaceField`. `iFlag=0` reverses by `DELETE FROM mftproductionplan` and restoring stock.

**Invocation:** Bound to `gdsmodule.sProcName` on:
- `装配工单` (sId `101251240115015922165750500`) — 制造管理
- `配墨工单` (sId `101251240115016045673367650`)

Dispatched by `BusinessBaseServiceImpl.getPrcName(sFormGuid, …)` on the 审核/反审核 button. xly-src ships an `script/标版/optimize/Sp_Calc_sSmb.sql` perf patch — verify which is deployed.
