# `Sp_unifiedPlanning_BtnCalculation_workorder_calc` (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_calc`'`._

## Narrative

**Business context:** 生产管理 → 生产排程 → 统一规划 — inner per-work-order calc kernel of the routing-walk. Author 钱豹's header repeats the parent's intent: "按工艺路线，更改机台的开始时间，推算交期". Where `Sp_unifiedPlanning_BtnCalculation_workorder` orchestrates one work-order, this kernel writes the concrete `mftproductionplanslave` time updates and calls the per-machine helpers.

**What it does:** For each process in the work-order's routing, computes `tStartDate = max(predecessor tEndDate, machine availability)` and `tEndDate = tStartDate + dCapacityHour`, then `UPDATE mftproductionplanslave` for the matched slave. Calls `Sp_BtnCalculation_Machine_time_byMachineType` at the start (mode 1) and end (mode 2) to refresh machine-type windows, and `Sp_unifiedPlanning_BtnCalculation_Machine` per machine to fan out time recompute.

**Invocation:** Called by `Sp_unifiedPlanning_BtnCalculation_workorder` once per work-order during the routing walk. No form-master or Java caller. xly-src ships `script/标版/30100101/schedule/tl/Sp_unifiedPlanning_BtnCalculation_workorder_calc.sql`.
