# `Sp_Manufacture_sWodPurchareMaterials` (procedure)

> 工单到采购计划


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

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `sId_s` | `varchar(4000)` |
| 2 | IN | `sStyle_s` | `varchar(4000)` |
| 3 | IN | `sWorkId_s` | `varchar(4000)` |
| 4 | IN | `sLoginId` | `varchar(100)` |
| 5 | IN | `sWorkOrderNo_s` | `varchar(255)` |
| 6 | IN | `sCustomerName_s` | `varchar(255)` |
| 7 | IN | `sProductName_s` | `varchar(255)` |
| 8 | IN | `iPurchase_s` | `int` |
| 9 | IN | `bViewAll_s` | `int` |
| 10 | IN | `bSlaveAll_s` | `int` |
| 11 | OUT | `sCode` | `int` |
| 12 | OUT | `sReturn` | `varchar(5000)` |
| 13 | IN | `sBrId` | `varchar(255)` |
| 14 | IN | `sSuId` | `varchar(255)` |
| 15 | IN | `bFilter` | `varchar(5000)` |
| 16 | IN | `sUnTaskFormId` | `varchar(100)` |
| 17 | IN | `pageNum` | `int` |
| 18 | IN | `pageSize` | `int` |
| 19 | OUT | `totalCount` | `int` |
| 20 | IN | `countCloumn` | `varchar(5000)` |
| 21 | OUT | `countMapJson` | `longtext` |
| 22 | IN | `sFilterOrderBy` | `varchar(5000)` |
| 23 | IN | `sGroupby_select_sql` | `varchar(5000)` |
| 24 | IN | `sGroupby_group_sql` | `varchar(5000)` |

## Body

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

## Narrative

**Business context:** 物料采购流程 → 1/4 物料需求计划->采购订单 — paged report that turns work-order material rollups into a purchase-plan grid (header: 工单到采购计划). For the selected 工单 rows, sums required material against on-hand and reservation virtual stock, splits the residual into purchase-suggestion lines per supplier, and returns the gridded result with the standard `Sp_Outstanding_Query` paging contract.

**What it does:** Builds working tables: `Tmp` (work-order material breakdown joined from `MftWorkOrderMaterials`, `purpurchaseordermaster` for already-on-order, `elematerialsstock` for warehouse, `MitMaterialsStoreVirtual` for the reservation pool), `p_work` for the per-work-order pivot, `p_sSupplyId_table` for supplier shortlists, and `sWodMaterialsStoreList` as the output staging — populated by `INSERT INTO ... / UPDATE ...` against each helper, then the final SELECT through `Sp_Outstanding_Query` for filter/page/total/groupby splicing.

**Invocation:** Bound as the data-source of two form-masters under 物料采购流程 → 1/4 物料需求计划->采购订单 (`gdsmodule.sId 19211681019715620563907770`): 物料需求计划 (`gfm.sId 19211681019715620563909010`) and 物料需求计划详情 (`gfm.sId 19211681019715622273398481`) via `gdsconfigformmaster.sSqlStr`. Also referenced by `Fun_getInitColumnByProName` for grid-init metadata. Ships at `script/标版/30100101/Sp_Manufacture_sWodPurchareMaterials.sql` (production) and `script/客户/千彩/Sp_Manufacture_sWodPurchareMaterials.sql` (千彩 customer override).
