# `Sp_Apply_Flow_SalSaleOrder` (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_SalSaleOrder`'`._

## Narrative

**Business context:** 销售订单 (流程启动前调用-销售订单) — large workflow-apply data builder for the sales-order approval flow on `salsalesordermaster`. Builds a fourteen-tier roster plus 会签 group, 营销一/二部 classification, and seven boolean routing flags (白名单, 特批, 框架协议, 备货, 费用, 烟包, 客户类型).

**What it does:** Resolves tiers from `eleemployee.iPosition`: 4=客服经理, 10=法务, 3=营销部长, 11=财务, 12=总经办, 2=营销副总, 1=总经理, 23=销售管理专员, 27=应收会计, 37=销售经理, 34=营销负责人(同时分配给 ElevenFlow 和 TwelveFlow), 38=副董执行董事, 39=董事长. `p_MoreFlow` (会签) = all `iPosition=3`. Counts `salsalesorderslave` lines whose product belongs to classify subtree `'16624527080007919539418229414000'` (烟包产品 root): `p_iOut2=1` if any. Sets `p_iOut=1` when any line is `sBillType='备货'`, `p_iOut1=1` when `sBillType='费用'`. Climbs applicant dept via `sisdepart.sParentId` to set `p_saledept` (=1 营销一部 `1734417170...`, =2 营销二部 `2023112009...`). Reads master `bApproved` (特批), customer `bWhile` (白名单), and counts active `elecustomeraccord` (`bCheck=1 AND tBufferDate>NOW()`) for `p_iAccord` (框架协议). Computes `p_dTotalMoney = SUM(dProductMoney)`. Emits per-line memo CONCAT-ing `生产类型➜毛利率➜产品分类➜产品名称➜数量➜金额` filtered to non-split lines (`IFNULL(sFatherSlaveId,'')=''`).

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

Flag: `p_ElevenFlow` and `p_TwelveFlow` both populate from `iPosition=34` (duplicate value — only one of营销负责人 ElevenFlow/TwelveFlow should differ; this slot is dev scaffolding); `p_MoreFlow` = same `iPosition=3` as `p_ThreeFlow` (会签 and 营销部长 are identical, so 会签 isn't multi-party); hardcodes 烟包 classify root + tenant dept GUIDs (营销一/二部).
