# `Sp_share_sPay_One` (procedure)

> 付款单(汇总)分摊


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

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `sDropTableSql` | `longtext` |
| 2 | IN | `sCreateTableSql` | `longtext` |
| 3 | IN | `insertSql` | `longtext` |
| 4 | IN | `selectSql` | `longtext` |
| 5 | IN | `sFormGuid` | `varchar(100)` |
| 6 | IN | `sLoginId` | `varchar(100)` |
| 7 | IN | `sBrId` | `varchar(100)` |
| 8 | IN | `sSuId` | `varchar(100)` |
| 9 | OUT | `sCode` | `int` |
| 10 | OUT | `sReturn` | `longtext` |

## Body

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

## Narrative

**Business context:** 财务管理 → 付款单 — per-row 付款单分摊 (`COMMENT '付款单(汇总)分摊'`). Allocates a single payment header (`cahpaymentmaster`) across its detail slave lines (`cahpaymentslave`) so each line carries its share of total / foreign / rounding / balance money. Twin of `Sp_share_sRcts_One` on the AR side and the simpler counterpart of `Sp_share_sPay` which also rolls into `cahpaymentsumslave` for the summary variant.

**What it does:** Executes the four dynamic-SQL strings handed in by the Java side (`sDropTableSql`, `sCreateTableSql`, `insertSql`, `selectSql`) to materialise `cahpaymentmaster_calc_tmp` and `cahpaymentslave_calc_tmp` temp tables seeded from the form's current data, then performs the share/round arithmetic on totals (`dTotalForeignMoneySum`, `dCurrencyRate`, `dRoundingForeignMoneySum`, `dBalanceMoneySum`, `dBalanceForeignMoneySum`) and UPDATEs the temps. Finally SELECTs the temps so the front-end refreshes the slave grid with the new per-row amounts.

**Invocation:** Dispatched dynamically by `CalcProcedureServiceImpl.calc()` (POST `/calcprocedure/calc`) — the 分摊 button on the 付款单 form has `sProName='Sp_share_sPay_One'` configured; Java builds the four temp-table SQLs from the form's current row data and forwards the call. No DB caller; no xly-src install script for this proc — DB-only.
