# `Sp_Check_sMpa` (procedure)

> 领料申请单据保存之前数据校验


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

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `sTableName` | `varchar(100)` |
| 2 | IN | `sGuid` | `varchar(100)` |
| 3 | IN | `sFormGuid` | `varchar(100)` |
| 4 | IN | `sLoginId` | `varchar(100)` |
| 5 | IN | `sBrId` | `varchar(100)` |
| 6 | IN | `sSuId` | `varchar(100)` |
| 7 | IN | `iFlag` | `int` |
| 8 | OUT | `sCode` | `int` |
| 9 | OUT | `sReturn` | `varchar(4000)` |

## Body

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

## Narrative

**Business context:** 生产执行 → MES单据 → 领料申请单据 / 补料申请单据 / 补版申请单据 — post-save validator on `mitproductionapplymaster`. Same proc serves all three申请 variants (领料/补料/补版) because they share the same master/slave tables.

**What it does:** Reads `NetMoney`/`NetPrice` precision from `SysSystemSettings`, then runs three gating checks: (1) every requested material must have `sWorkCenterId` matching `elematerialsworkcenter` for the requesting department, else aborts with `sMaterialNeedWorkCenter`; (2) materials currently mid-工艺变更 (open `mftprocesschangemaster` of sType=1 with changed `sMaterialsId`/`sMaterialsStyle`) are blocked with `sMaterialInChange`; (3) once both pass, dedupes slave rows by `(sMaterialsId, sMaterialsStyle, sParentId)` and branches on `sFormGuid` to apply form-specific rules per the embedded comment block.

**Invocation:** Bound to `gdsmodule.sSaveProName` (post-save) on `补料申请单据` (`12012615914116395420093200`), `补版申请单据` (`12012615914116395420566910`) and `领料申请单据` (`101251240115016056026128440`), all under 生产执行 → MES单据. Dispatched by `BusinessBaseServiceImpl.checkUpdate(..., "sSaveProName")` after the save batch commits. xly-src ships `script/标版/30100101/Sp_Check_sMpa.sql` as the install body.
