# `Sp_beforeSave_sCmt` (procedure)

> 采购到货、材料检验保存前反写数量


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

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `sGuid` | `varchar(2000)` |
| 2 | IN | `sBrId` | `varchar(100)` |
| 3 | IN | `sSuId` | `varchar(100)` |
| 4 | OUT | `sCode` | `int` |
| 5 | OUT | `sReturn` | `varchar(4000)` |

## Body

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

## Narrative

**Business context:** 质量管理单据 / 材料检验单据 (also 库存检验, 材料检验(mobile单据)) — before-save dispatcher for the material-inspection (来料/库存检验) family. Wraps `sGuid` and delegates to `Sp_saveReturn_sCmt` to backwrite arrival-/inspection-related counters before the master save commits. Comment header: `采购到货、材料检验保存前反写数量`.

**What it does:** Normalises `sGuid` to a quoted-CSV form, then `CALL Sp_saveReturn_sCmt(sGuid, sBrId, sSuId, 1, @sCode, @sReturn)`.

**Invocation:** Hooked as `gdsmodule.sSaveProNameBefore` on 3 modules — `材料检验单据` (sId `15827054010002527067474512475000`), `库存检验` (`101251240115016105078918480`), `材料检验(mobile单据)` (`12012615914116374731613080`). Also called by dispatcher procs `Sp_Invalid_backwriting` and `Sp_delete_backwriting` to replay the writeback on invalidate/delete.
