Sp_MaterialsStoreVirtual.md 1.65 KB

Sp_MaterialsStoreVirtual (procedure)

实际库存

  • Type: PROCEDURE
  • Deterministic: NO
  • SQL data access: CONTAINS SQL

Parameters

# Mode Name Type
1 IN sGuid varchar(4000)
2 IN sBrId varchar(100)
3 IN sSuId varchar(100)

Body

Body is not pre-cached. To inspect: mysql --defaults-file=~/.my.cnf -e 'SHOW CREATE PROCEDURESpMaterialsStoreVirtual'._

Narrative

Business context: 仓库管理 → 虚拟库存 — single-工单 rebuild of MitMaterialsStoreVirtual, the "实际库存 + 已下单/已计划" projection used by MRP and领料 checks. Called whenever a 工单 (mftworkordermaster) is audited or its consumption changes so the virtual stock view stays in sync.

What it does: Materialises the comma-delimited sGuid list into temp table p_t_sId, looks up the work-order's sMaterialsUnit and 卷筒纸 (CkxReelPaper) switch from SysSystemSettings, deletes the existing MitMaterialsStoreVirtual rows for those bill ids, then re-inserts virtual-store rows by joining mftworkorder*, elematerials, and store views — emitting one row per (材料, 单据) carrying the projected on-hand qty after accounting for unfinished consumption. Branch/subsidiary scoped throughout.

Invocation: Chained from a wide set of lifecycle hooks: Sp_Calc_sMaterialsBgd, Sp_Calc_sPmd, Sp_Calc_sSmb, Sp_Calc_sWod, Sp_Bill_Force_Complete, and Sp_System_UpdateWorkCl; also driven in bulk by Sp_MaterialsStoreVirtual_refresh. xly-src ships script/标版/30100101/Sp_MaterialsStoreVirtual.sql (install). No direct UI binding — purely side-effect.