# `Sp_System_BatchPriceMoney` (procedure)

> @author:       qmj
		     @date:         20210707 封存
			 @describe:     价格批量更新，按外币计算，目前仅使用销售订单


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

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `sFormGuid` | `varchar(100)` |
| 2 | IN | `sSrcGuid` | `varchar(100)` |
| 3 | IN | `dPrice` | `decimal(18,6)` |
| 4 | IN | `dMoney` | `decimal(18,6)` |
| 5 | IN | `dQty` | `decimal(18,6)` |
| 6 | IN | `oldQty` | `decimal(18,6)` |
| 7 | IN | `tDeliverDate` | `datetime` |
| 8 | IN | `sLoginId` | `varchar(100)` |
| 9 | IN | `sBrId` | `varchar(100)` |
| 10 | IN | `sSuId` | `varchar(100)` |
| 11 | IN | `sChangePriceMemo` | `longtext` |
| 12 | OUT | `sCode` | `int` |
| 13 | OUT | `sReturn` | `varchar(4000)` |

## Body

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

## Narrative

**Business context:** 销售管理 → 销售订单 / 改价（外币） — foreign-currency batch price-update twin of `Sp_System_BatchNPriceMoney`. Same trigger (改价 button on a sales-order slave) and same propagation (订单→工单→送货通知/送货单), but the price input `dPrice` is interpreted as 外币价 (`dForeignPrice`) and the proc back-computes local-currency `dProductPrice` / `dProductMoney` from `dCurrencyRate`. Header `封存` (qmj, 2021-07-07): "价格批量更新，按外币计算，目前仅使用销售订单".

**What it does:** Reads `NetMoney`/`NetPrice` decimals and `CbxDeliverGoods`/`CbxDeliverGoodsNotify` flags from `SysSystemSettings`. Resolves the parent `SalSalesOrderMaster` for slave id `sSrcGuid`, looks up its `dCurrencyRate` and the order's `tCreateDate`, and gates on `sysaccountperiod.bFrozen` — aborts with `sNoCanCheckByAccountPeriod` when frozen. Calls `Sp_System_AutoMaterialsPriceSingle` for any materials touched by the change (refreshing weighted-average prices). Updates `SalSalesOrderSlave` with new `dForeignPrice` / derived `dProductPrice` / `dProductMoney` / tax fields, then cascades the same money set to `MftWorkOrderSlave` (joined with `sistax`) and pending 送货通知/送货单 rows. `sChangePriceMemo` is stored on the slave for the audit trail.

**Invocation:** Dispatched dynamically by `GenericProcedureCallServiceImpl.doGenericProcedureCall()` from the 销售订单 改价(外币) button. Java `BusinessBaseServiceImpl.updatePriceBatch` matches the name and, after successful run, pushes the new `dProductMoney` to RocketMQ (`rocketMQService.pushERPOrderAmount`) keyed by `sWebOrderId` so any cloud-order partner sees the new amount. Install: `script/标版/30100101/Sp_System_BatchPriceMoney.sql`, customer override `script/客户/千彩/Sp_System_BatchPriceMoney.sql`.
