# `Sp_Apply_Flow_PurpurchaseOrder` (procedure)

> 流程启动前调用-采购订单


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

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `sFormGuid` | `varchar(100)` |
| 2 | IN | `sGuid` | `varchar(100)` |
| 3 | IN | `sSrcNo` | `varchar(100)` |
| 4 | IN | `sLoginId` | `varchar(100)` |
| 5 | OUT | `sTableParams` | `longtext` |
| 6 | OUT | `sSrcReportData` | `longtext` |
| 7 | OUT | `sTableParamsValue` | `longtext` |
| 8 | OUT | `sReturn` | `varchar(4000)` |
| 9 | IN | `sBrId` | `varchar(100)` |
| 10 | IN | `sSuId` | `varchar(100)` |
| 11 | OUT | `sCode` | `int` |

## Body

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

## Narrative

**Business context:** 采购订单 — live workflow-apply data builder for the 采购订单 approval flow on `purpurchaseordermaster`, superseding the minimal `Sp_Apply_Flow_PurOrder`. Builds seven-tier roster, two price-variance flags, and a 烟包 indicator.

**What it does:** Reads `purpurchaseordermaster` for `sGuid` joined to `elesupply`. **Two variance branches:** `p_iType=1` when any line has `dMaterialsPrice>dGuidePrice` AND its `sismaterialsclassify.bPrice=1` (guidance-priced category); `p_iType1=1` when the sum of over-guidance line money `p_dOutMoney>30000`. Also reads `p_iOut1` = count of order lines whose material classify has `bPrice=1` (indicates the order can be guidance-checked at all). Resolves seven tiers from `eleemployee.iPosition`: 6=物控经理, 5=供应链部长, 1=总经理, 34=国同事业副总, 38=副董执行董事, 39=董事长, 11=财务总鉴. Reads master `iCigPack`. Concatenates per-line `物料➜规格➜数量+单位➜单价` summary using `dOldMaterialsPrice`. Final payload includes `iSource`, `dTotalMoney`, all seven tier fields plus the two variance flags.

**Invocation:** Dispatched dynamically by Java `CheckExamineFlowDataServiceImpl.doSendCheckFolwData()` via `doProByNameFlow(..., sApplyProName, ...)` from `gdsmoduleflow.sApplyProName` (empty in this DB).

Flag: `p_iOut1` query lacks WHERE `A.sParentId=sGuId` — counts guidance-priced lines across **all** purchase orders globally, not just this order. `p_dOutMoney>30000` threshold (30k CNY) is hardcoded; comment header mentions "超过2万的总经理审核" — comment says 20k, code says 30k.
