# `Sp_Quotation__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_NetPrice` | `varchar(100)` |
| 16 | IN | `p_NetMoney` | `varchar(100)` |
| 17 | OUT | `sCode` | `int` |
| 18 | OUT | `sReturn` | `varchar(5000)` |

## Body

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

## Narrative

**Business context:** 销售管理 → 报价&估计管理 → 新报价单 (gdsmodule sId `101251240115016076506222050`) — final-control / last-process stage of the packaging-product (包装) quote-cost engine. Receives the temp-table snapshot built by `Sp_Quotation_CalcDataPack` and finishes the per-工艺 quantity/rate/loss math for the terminal process where `bLastProcess=1`, then writes results back to `QuoQuotationControl_Tmp` / `QuoQuotationMaterials_Tmp` / `QuoQuotationProcess_Tmp` for return to the front-end.

**What it does:** Reads quote master/slave/control/materials/process/control-combine `*_tmp` tables. For each control row it determines `bLastProcess`/`bProductProcess`/`bSameControl`, walks the process cursor to compute `dProcessInQty`/`dProcessOutQty`/`dAdjustLossQty` against materials and prior process rates, applies the `p_sCorrugateWidth/Length`/`p_dMinusLength/Width` deductions, and consolidates by `sControlParentId`/`sFirstProcessId`. Writes `dPartsQty`, `dArrangeQty`, `dAdjustRate` back per row. The `Sp_System_ReplaceField` call (and the parallel `Sp_Sis_GetConst`) localise error messages.

**Invocation:** Called by `Sp_Quotation_CalcDataPack` (`CALL Sp_Quotation__CalcDataPackLastStd(...)`) inside the packaging-quote calculation chain. The outer entry point — `Sp_Quotation_CalcDataPack` — is invoked from `ManyQuoServiceImpl.addQuotationsheetManyThread(params, userInfo, "Sp_Quotation_CalcDataPack")` (called by `QuoquotationController` for the multi-quantity quote flow); the standard single-quantity flow reaches the same proc via `gdsmodule.sCalcProName='Sp_Quotation_CalcDataPack'`. xly-src ships customer-specific overrides for this proc at `script/客户/高旺/20211108成本计算/` and `script/客户/上海亚峰/报价单计算/` — verify which body is deployed.
