# `Sp_BillOfApply` (procedure)


- **Type:** PROCEDURE
- **Deterministic:** NO
- **SQL data access:** CONTAINS SQL

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `sBrId` | `varchar(100)` |
| 2 | IN | `sSuId` | `varchar(100)` |
| 3 | IN | `sLoginId` | `varchar(100)` |
| 4 | IN | `bFilter` | `text` |
| 5 | IN | `pageNum` | `int` |
| 6 | IN | `pageSize` | `int` |
| 7 | IN | `sUnTaskFormId` | `varchar(100)` |
| 8 | OUT | `totalCount` | `int` |
| 9 | IN | `countCloumn` | `varchar(5000)` |
| 10 | OUT | `countMapJson` | `longtext` |
| 11 | IN | `sFilterOrderBy` | `varchar(5000)` |
| 12 | IN | `sGroupby_select_sql` | `varchar(5000)` |
| 13 | IN | `sGroupby_group_sql` | `varchar(5000)` |

## Body

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

## Narrative

**Business context:** 生产执行 / 现场物料管理 / 根据工单领料申请 — list-page datasource that builds the "by-work-order materials-application" picker. Used on the form `101251240115016056038424570` (sParentId → 现场物料管理) to let line-side staff pick the work order whose unfulfilled material demand they want to apply for.

**What it does:** Standard paged-list shape (`sBrId, sSuId, sLoginId, bFilter, pageNum, pageSize, sUnTaskFormId, totalCount OUT, countCloumn, countMapJson OUT, sFilterOrderBy, sGroupby_select_sql, sGroupby_group_sql`). Constructs a dynamic SQL into `P_Tmp_List` by joining `eleproduct` (product), `EleMaterials` / `elematerialsstock` (material + on-hand), `elecustomer`, `siswarehouse`, and `MftWorkOrderControl` (work-order control), then resolves auxiliary-unit conversions (`p_dAuxiliaryQtySum`, `p_dProductionApplyAuxiliaryQty`) from `SysSystemSettings`, and applies the filter/orderBy/groupBy before pagination.

**Invocation:** Wired to form `101251240115016056038424570` under module 现场物料管理 (`16351574590001409130024039409000`) → 生产执行 (`19211681019715708716954960`). Resolved via the standard list-paging dispatch (`gdsconfigformmaster.sSqlStr` embeds the `CALL Sp_BillOfApply(...)` invocation).
