# `Sp_beforeSave_sSmia` (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_sSmia`'`._

## Narrative

**Business context:** 半成品入库申请单据 (Semi-finished-goods stock-in apply) — before-save dispatcher for the in-store-apply document. Wraps `sGuid` and delegates to `Sp_saveReturn_sSmia`, which is meant to backwrite the apply quantity onto the upstream `mftworkorderprocess` (work-order process) lines before the master save commits. Header comment: `半成品入库申请存前反写数量`.

**What it does:** Normalises `sGuid` to a quoted-CSV form, then `CALL Sp_saveReturn_sSmia(sGuid, sBrId, sSuId, 1, @sCode, @sReturn)`. The historical inline `Update mftworkorderprocess` block (joining `sgdsemigoodsinstoreapplyslave` / `…master`) remains commented-out in the body.

**Invocation:** Not bound to a module as a save-hook in this DB. Called by both backwriting dispatchers — `Sp_Invalid_backwriting` and `Sp_delete_backwriting` — when `sFormGuid = '101801153119616759337165930'` (半成品入库申请单据), to replay the writeback on cancel-invalidate and on delete.

Flag: target `Sp_saveReturn_sSmia` does not exist in this DB. Both dispatcher branches will surface a `PROCEDURE … does not exist` error at runtime — `Sp_afterSave_sSmia` / `Sp_beforeSave_sSmia` both call this missing routine.
