# `Sp_WorkOrder_CalcDataPackLastStd` (procedure)


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

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `sGuid` | `varchar(100)` |
| 2 | IN | `bChangeRate` | `int` |
| 3 | IN | `sLoginId` | `varchar(100)` |
| 4 | IN | `sBrId` | `varchar(100)` |
| 5 | IN | `sSuId` | `varchar(100)` |
| 6 | IN | `p_sFormId` | `varchar(100)` |
| 7 | IN | `p_sCorrugateWidth` | `varchar(100)` |
| 8 | IN | `p_sCorrugateLength` | `varchar(100)` |
| 9 | IN | `p_dMinusLength` | `varchar(100)` |
| 10 | IN | `p_dMinusWidth` | `varchar(100)` |
| 11 | IN | `p_sModelsType` | `varchar(100)` |
| 12 | IN | `p_sSlaveGuid` | `varchar(100)` |
| 13 | IN | `p_sCustomerId` | `varchar(100)` |
| 14 | IN | `p_sProductId` | `varchar(100)` |
| 15 | IN | `p_tDeliverDate` | `datetime` |
| 16 | OUT | `sCode` | `int` |
| 17 | OUT | `sReturn` | `varchar(5000)` |

## Body

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

## Narrative

**Business context:** 包装工单 → 计算 → 收尾阶段 — final/aggregation phase of the 包装 (packaging) work-order cost calc. Sibling of `Sp_WorkOrder_CalcDataBsLastStd`; the "Last" stage in the Java orchestrator's `Product → PartsStd → LastStd` pipeline. Runs after every parts/process row is computed, collapsing per-part figures into master totals.

**What it does:** Operates on `mftworkordermaster_Tmp`/`mftworkorderslave_Tmp`/`mftworkordercontrol_tmp`/`mftworkordermaterials_tmp`/`mftworkorderprocess_tmp` plus per-call working tables `p_calc_MftWorkOrderControl_first_cal`, `_first_process`, `_laster_cal`, `_next`, `_order`, `_orderNew`, `_process_laster` to walk the control-row graph from innermost children outward. Finalises `mftworkorderslavemoney_tmp` (per-slave money), per-control loss qty, capacity hours, materials qty, and process money. Heavily customised — every shipped customer has an override script (千彩/金宣发/高旺/上海亚峰…) layered on top of the base 标版 install.

**Invocation:** Called by `WorkOrderCalcDataPackServiceImpl.doCalcDataPackStd()` as the `Sp_WorkOrder_CalcLastStd` slot when running in 包装 mode (it points `Sp_WorkOrder_CalcLastStd = Sp_WorkOrder_CalcDataPackLastStd`). Runs after `Sp_WorkOrder_CalcDataPackProductStd` (before) and per-control `Sp_WorkOrder_CalcDataPackPartsStd` loops. Install scripts: `script/标版/30100101/Sp_WorkOrder_CalcDataPackLastStd.sql` plus customer overrides in `script/客户/*/`.
