# `Sp_Apply_Flow_PurCheck` (procedure)

> 流程启动前调用-采购对账对账修改单价
					对账改了单价总价也会变，发票也涉及到改价格。
					这个到时候需要增加审批流程，比如说超过100元的，
					二级部门、一级部门，财务审核，
					超过2万的总经理审核


- **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_PurCheck`'`._

## Narrative

**Business context:** 采购对账(单价变更) — workflow-apply data builder for the 采购对账修改单价 approval flow on `purpurchasecheckingmaster`. Builds the five-tier approver roster (二级部门→一级部门→财务→总经理 plus 事业部负责人) and the price-variance line summary.

**What it does:** Reads `purpurchasecheckingmaster` for `sGuid` joined to `elesupply`. For each `purpurchasecheckingslave` row where `dMaterialsPrice<>` the originating `purpurchaseorderslave.dMaterialsPrice` AND the source-no does not contain 'KK' (KK = 扣款 lines exempted), accumulates `p_dChangeMoney = SUM(dMaterialsMoney) − SUM(orderPrice*newPrice)` (signed variance) and concatenates `p_sMaterialsName` with 现单价/原单价 per line. Resolves二级部门 (`p_OneFlow`) and 一级部门 (`p_TwoFlow`) by walking `sisdepart.sParentId` from the 制单人's dept. Three position-based tiers: `iPosition` 11=财务, 1=总经理, 34=事业部负责人. Also reads first slave's `iCigPack` (烟包 flag).

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

Flag: `dMaterialsMoney − dMaterialsPrice*dMaterialsPrice` formula multiplies new-price by new-price (should be `dAuxiliaryQty*dMaterialsPrice` — likely a copy-paste typo in the variance calc); inspect against `purpurchaseorderslave` column meanings before relying on `dChangeMoney` for thresholding.
