# `Sp_history_purpurchaseordermaster_data` (procedure)

> 获取采购订单历史记录


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

## Parameters

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

## Body

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

## Narrative

**Business context:** KPI流程操作菜单 → 物料采购流程 → 采购订单 → 历史采购价格 (form sId `16906148030002174531746365163300`, sChinese `历史采购价格`) — given the current purchase-order master id, returns the per-row materials price-history for each `purpurchaseorderslave` (sMaterialsId + sMaterialsStyle) so the buyer can compare prior supply/price/qty/memo before approving.

**What it does:** Builds two temp tables: `p_sRowDataSearch_tmp` from the current `purpurchaseordermaster`/`purpurchaseorderslave` join (gives the materials in scope) and `p_history_data` accumulator. Walks the scope via cursor; for each (sMaterialsId, sMaterialsStyle) pair INSERTs prior bills from historical `purpurchaseordermaster`/`purpurchaseorderslave` (supply name, price, qty, money, memo, supply id) into the accumulator. Returns the accumulated rowset.

**Invocation:** Form-master `sSqlStr` binding on form `16906148030002174531746365163300` (历史采购价格). The non-`_data` sibling `Sp_history_purpurchaseordermaster` is the older JSON-input variant (takes `sRowData LONGTEXT` of `[{sWorkOrderMaterialIds, sMaterialsId, sMaterialsStyle}, ...]`) and has no live form binding.
