# `Sp_Check_sMcd` (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_sMcd`'`._

## Narrative

**Business context:** 物料管理 → 仓储管理 → 材料盘点单据 (sMcd = material-count, on `mitmaterialscheckmaster/slave`) — post-save profit/loss calculator. After a 盘点 saves, computes per-line 盘盈/盘亏 quantity, auxiliary qty, unit price, and money fields from the count entry and the historical material price.

**What it does:** For each `MitMaterialsCheckSlave` under `sParentId=sGuid` (tenant-scoped), sets `dProfitLossQty = dMaterialsQty - dOriginalQty`, `dProfitLossAuxiliaryQty = dAuxiliaryQty - dOriginalAuxiliaryQty`, then calls `Fun_Cashier_GetMaterialsPrice_new(sMaterialsId, '', sBrId, sSuId)` to populate `dProfitLossPrice` and `dMaterialsPrice`, and writes `dProfitLossMoney = ROUND(price * (dMaterialsQty - dOriginalQty), 2)`. Note: `sMaterialsId` is unqualified — it resolves to whichever sMaterialsId is in scope (likely a bug; intended as `M.sMaterialsId`).

**Invocation:** Status: appears unbound at module level. The 材料盘点单据 module (`192116810113315228128521360`) has `sSaveProName=''` and only `sProcName=Sp_Calc_sMcd`. No other routine references `Sp_Check_sMcd`; no `xly-src` hit (no install script). Likely wired by a customer override or invoked from `Sp_Calc_sMcd` — verify with the maintainer. Flag: the unqualified `sMaterialsId` reference is a probable bug.
