# `Sp_Apply_Flow_SalInvoice` (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_SalInvoice`'`._

## Narrative

**Business context:** 销售发票 (流程启动前调用-销售发票舍入金额) — workflow-apply data builder for the sales-invoice rounding-amount approval flow on `salsalesinvoicemaster`. Header comment notes the intent: "对账改了单价总价也会变，发票也涉及到改价格...超过100元的，二级部门、一级部门，财务审核，超过2万的总经理审核". Builds a six-tier roster with applicant-dept-driven branching and 烟包 indicator.

**What it does:** Reads `sMakePerson` from master. Resolves `p_OneFlow` (二级部门) via `eleemployee.sDepartId` → `sisdepart.sEmployeeId` (the applicant's dept leader). Resolves `p_TwoFlow` (一级部门) by climbing one `sisdepart.sParentId` level. Resolves tiers from `eleemployee.iPosition`: 11=财务, 1=总经理, 34=国同事业副总, 38=副董执行董事. Counts `salsalesinvoiceslave` whose product belongs to classify subtree `'16624527080007919539418229414000'` (烟包产品 root); `p_iOut2=1` if any. Per-line memo restricted to lines with `dRoundingMoney>0 AND sRoundingReason<>'汇率差异'` and `dRoundingMoney` aggregated under the same filter (汇率差异 rounding is excluded from the threshold check).

**Invocation:** Dispatched dynamically by Java `CheckExamineFlowDataServiceImpl.doSendCheckFolwData()` via `doProByNameFlow(..., sApplyProName, ...)` from `gdsmoduleflow.sApplyProName` (empty in this DB — workflow configs tenant-provisioned per deployment).

Flag: header comment says "超过2万的总经理审核" but proc emits only the tier roster — threshold gating is left to the consumer JSON-evaluator (no `p_iOut1` analog). Hardcodes 烟包产品 classify root.
