# `Sp_Calc_sMit` (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(4000)` | | 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_sMit`'`._ ## Narrative **Business context:** 系统设置 → 期初设置 → 材料期初 (单据 + 列表) — material opening-balance audit / un-audit on `MitMaterialsInitMaster`/`MitMaterialsInitSlave`. The 材料期初 is run once per warehouse at system go-live to seed `MitMaterialsStore` with the starting on-hand quantities and `EleMaterialsStock` with the rolled-up snapshot; auditing the period freezes those seed rows. **What it does:** Validates `sGuid`, branches on `iFlag`. On `iFlag=1` flips `MitMaterialsInitMaster.bCheck=1` plus slave rows, then for each slave row inserts the opening qty into `MitMaterialsStore` and `INSERT INTO EleMaterialsStock` to rebuild the per-material on-hand snapshot. On `iFlag=0` reverses by `delete from mitmaterialsstore`/`Delete FROM EleMaterialsStock` to drop the seed and recomputing the snapshot without the opening balance. **Invocation:** Bound to `gdsmodule.sProcName` on two sibling modules under 系统设置 → 期初设置: `材料期初单据` (sId `101251240115015946054872880`) and `材料期初` list view (sId `101251240115015946178618470`). Dispatched by Java `BusinessBaseServiceImpl.getPrcName(sFormGuid, …)` on the 审核/反审核 button. xly-src ships `script/标版/30100101/Sp_Calc_sMit.sql` and `script/标版/optimize/Sp_Calc_sMit.sql`.