# `Sp_Apply_Flow_ReturnWork` (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_ReturnWork`'`._

## Narrative

**Business context:** 返工单 (流程启动前调用-返工单) — workflow-apply data builder for the rework approval flow on `mftproductionplanbillslave` (production-plan rework lines). Builds a three-tier roster and quality-sample routing flag.

**What it does:** Resolves tiers from `eleemployee.iPosition`: 18 OR 28=品质部 (品管/品质两个分组合并), `iPosition1=21`=生产计划经理 (note `iPosition1`, a secondary-role column), 11=财务经理. Joins `mftproductionplanbillslave` with the originating `salsalesorderslave` (`A.sOrderSlaveId=B.sId`) and emits `sBillNo`, `sWorkOrderNo`, `sCustomerName`, `sProductName`, `dProcessQty`, plus `dProductNoTaxMoney = A.dLossMoney if set else ROUND(A.dProcessQty * B.dProductNoTaxPrice, 2)`. `iOut=1` when `bQualitySample=1` (quality-sample branch).

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