# `Sp_Apply_Flow_Purpurchaseapplynew` (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_Purpurchaseapplynew`'`._

## Narrative

**Business context:** 采购申请单(新) — replacement workflow-apply data builder for the 采购申请 approval flow on `purpurchaseapplymaster`, superseding `Sp_Apply_Flow_Purpurchaseapply`. Adds dept-based tier resolution, 烟包 routing, and four additional senior tiers (副董/总鉴/董事长).

**What it does:** Reads `purpurchaseapplymaster` for `sGuid`. Resolves apply-employee's `sDepartId` and parent `sParentDeptId` from `sisdepart`. First two tiers (`p_OneFlow`/`p_TwoFlow`) come from `sisdepart.sEmployeeId` for the apply-dept and its parent (dept-leader hierarchy). Five position-based tiers: `iPosition` 2=营销副总, 1=总经理, 37=销售经理, 34=国同事业副总, 38=副董执行董事, 11=财务总鉴, 39=董事长. Reads `iApplySort` (1=烟包, 2=否) for routing. `p_dTotalMoney = ROUND(SUM(dMaterialsQty*dGuidePrice),3)` joining `elematerials`; material memo includes 指导价. Payload also exposes display string for `iType` (客服申请/常备物料/车间辅料申请/设备零配件需求/补料申请).

**Invocation:** Dispatched dynamically by Java `CheckExamineFlowDataServiceImpl.doSendCheckFolwData()` via `doProByNameFlow(..., sApplyProName, ...)` from `gdsmoduleflow.sApplyProName` (empty in this DB). The live binding for the current 采购申请 form.

Flag: declares `p_iType` and `iType` is referenced inside the JSON build but the local `p_iType` is read into a local that isn't re-passed to JSON_OBJECT — the JSON `"iType",iType` field refers to the master column directly, so the local read is dead. `p_FiveFlow`...`p_ElevenFlow` are dynamically populated but some tiers (`p_FiveFlow`=销售经理 iPosition=37, `p_SixFlow`=34, `p_NineFlow`=38, `p_TenFlow`=11, `p_ElevenFlow`=39) may have empty results in this tenant.
