# `Sp_unifiedPlanning_BtnCalculation_workorder` (procedure)

> @author:钱豹
	按工艺路线，更改机台的开始时间，推算交期


- **Type:** PROCEDURE
- **Deterministic:** NO
- **SQL data access:** CONTAINS SQL

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `p_sWorkOrderId` | `varchar(100)` |
| 2 | IN | `sBrId` | `varchar(100)` |
| 3 | IN | `sSuId` | `varchar(100)` |
| 4 | OUT | `sReturn` | `varchar(1000)` |
| 5 | OUT | `sCode` | `int` |

## Body

_Body is not pre-cached. To inspect: `mysql --defaults-file=~/.my.cnf -e 'SHOW CREATE PROCEDURE `Sp_unifiedPlanning_BtnCalculation_workorder`'`._

## Narrative

**Business context:** 生产管理 → 生产排程 → 统一规划 — work-order routing-walk during 主生产计划 → 确认计划. Author 钱豹's header: "按工艺路线，更改机台的开始时间，推算交期" — for the given work-order, propagate start times along the routing and back-derive each downstream process's 交期.

**What it does:** Builds a temp `MftProductionPlanSlave_Tmp_div` keyed by `(sWorkOrderId, sWorkOrderProcessId, sMachineId)`. For each row in routing order it computes successor `tStartDate` from predecessor `tEndDate` + hand-off lag, calls `Sp_unifiedPlanning_BtnCalculation_workorder_calc` per work-order to actually rewrite `mftproductionplanslave`, and propagates the latest end-date back to the work-order's 交期 estimate.

**Invocation:** Called by `Sp_unifiedPlanning_BtnCalculation` at line 731 of its body (`CALL Sp_unifiedPlanning_BtnCalculation_workorder(p_sWorkOrderGuid, sBrId, sSuId, sReturn, sCode)`) and by `Sp_productionMainPlan_BtnEventBlock` (block-and-reschedule path). No form-master or Java direct binding. xly-src ships `script/标版/30100101/schedule/Sp_unifiedPlanning_BtnCalculation_workorder.sql`.
