# `Sp_Sis_GetMertialsInventoryFormGuid` (function)


- **Type:** FUNCTION
- **Returns:** `varchar(1)`
- **Deterministic:** NO
- **SQL data access:** CONTAINS SQL

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `sFormId` | `varchar(1000)` |

## Body

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

## Narrative

**Business context:** Inventory-direction classifier for materials transactions — given a `sFormId` (the form/document type that triggered the move), returns `'0'` for in-store movements (入库类: 采购入库, 退货入库, 委外回收入库, 客来料入库, etc.), `'1'` for out-store movements (出库类: 领料, 退料, 委外发料, 销售出库, etc.). The hardcoded sId lists embed the standard xly inventory form-types — each placeholder slot tagged `后续增加` reserves room for client-defined custom forms. Used by the materials in/out store calculation chain to pick the right qty-direction sign.

**What it does:** keeps two long string lists (`sInSql` and `sOutSql`) of form-guid literals; runs `LOCATE(sFormId, ...)` against each; returns `'0'` if the form is in the in-store list, `'1'` if in the out-store list, `NULL` otherwise. Despite the `Sp_` prefix this is a **function** (returns `varchar(1)`); the sibling `Sp_Sis_GetMertialsInventoryFormGuid` *procedure* exists separately with the same name.

**Invocation:** referenced by 20+ materials-stock routines including `Sp_calc_materialsstoreLimit`, `Sp_check_MaterialsStockLimitNew`, the entire `Sp_Inventory_InOutStore*`/`SP_Inventory_InOutWarehouse*` family, `Sp_Inventory_MaterialsInOutStoreDoing`, `Sp_Inventory_MaterialsInventory_Outdated`, `SP_Inventory_ProductInOutWarehouseCost/Money`, `Sp_MaterialAgingAnalysis_detail`, `Sp_System_AutoMaterialsPriceSingle`, `Sp_System_CalcMaterialsPrice*`. Also referenced in `script/标版/upgrade/.../Sp_Calc_sPis.sql`. Misnamed: the `Sp_` prefix and the catalog filename both suggest a procedure, but this is a function — the actual procedure version is a separate routine. Caveat: hard-coded sId lists must be updated by hand when new form types are added; clients deploying with extra inventory forms need the function rewritten.
