# `fun_workmaterials_used` (function)

> 工单材料使用情况


- **Type:** FUNCTION
- **Returns:** `longtext`
- **Deterministic:** NO
- **SQL data access:** CONTAINS SQL

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `p_workordermaterialsId` | `varchar(255)` |
| 2 | IN | `sBrId` | `varchar(255)` |
| 3 | IN | `sSuId` | `varchar(255)` |

## Body

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

## Narrative

**Business context:** Work-order downstream-usage check — for a given `mftworkordermaterials.sId`, returns a human-readable string naming the first bill that consumed this work-order material (purchase order, production picking). Header gloss: "工单材料使用情况". Used to block deletes/edits when material rows have already been transacted.

**What it does:** Queries `viw_purpurchaseorderdetail` for a `sSrcSlaveId` match → returns `'采购订单使用:<sBillNo>'`. Otherwise queries `viw_mitproductionmaterials` → returns `'生产领料使用:<sBillNo>'`. Empty string if neither hit.

**Invocation:** Orphan-via-dead-chain. Only routine caller is `Sp_WorkOrder_CheckUpdateNew`, which itself has no caller (no module hook, no form-master, no xly-src reference). The sibling `fun_workprocess_used` / `fun_workproduct_used` form a parallel "is-used" check trio that all funnel into the same dead `Sp_WorkOrder_CheckUpdateNew`. Bug suspect: second IF tests `p_sUsed` instead of `p_sUsed2`, so the production-picking branch never returns — confirm before re-wiring.
