# `Sp_Calc_sMat` (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_sMat`'`._

## Narrative

**Business context:** 基础设置 → 纸张与辅料 → 物料信息 — material-master audit on `elematerials` (COMMENT `'物料审核'`). Approves a 物料 (material master record — paper/ink/PS-plate/glue/etc.) so it becomes usable in downstream sales-orders, work-orders, and stock movements. Curiously, the audit also flips the row's `sFormId` from one form-id to another — a form-migration side-effect.

**What it does:** Validates `sGuid`. With `iFlag=1`: refuses already-`bCheck=1`; opens a 工作流 cursor over `SalSalesOrderSlave` rows joined to `salsalesordermaster`/`eleproduct` and calls `Sp_System_CheckFlow` per slave when `CkxDefineCheck=1` to drive an approval workflow over the **sales-order tables** (unusual for a material-master audit — flag for maintainer audit); then `Update elematerials` to set `bCheck=1, sStatus=1, sCheckPerson, tCheckDate, sFormId='192116811311115106418895950'` only when the current `sFormId='101251240115016270291152360'`. With `iFlag<>1`: symmetric uncheck on `elematerials` without the `sFormId` rewrite.

**Invocation:** Status: appears orphaned. No live `gdsmodule.sProcName` binding (the matching 物料信息 sId `192116811311115106418895950` has no proc bound — the form-id rewrite suggests it was previously bound under the other id and migrated), no `sSaveProName` hook, no other-routine CALLs, no xly-src reference — candidate for maintainer audit.

Flag: the embedded `Sp_System_CheckFlow` loop scans `SalSalesOrderSlave` rather than any `elematerials` slave — a copy-paste from the 销售订单 audit template that is almost certainly wrong for a material-master approval.
