# `Sp_share_salsalesinvoices_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_salsalesinvoices_One`'`._

## Narrative

**Business context:** 销售管理 → 销售发票 — per-row 发票分摊 (`COMMENT '发票分摊'`): allocates the invoice's total money across its slave-line items (`salsalesinvoiceslave`) so each line carries its share of rounding, freight, discount, etc. Twin of `Sp_share_sPay_One` / `Sp_share_sRcts_One` for the AR side.

**What it does:** Takes the four dynamic-SQL strings (`sDropTableSql`, `sCreateTableSql`, `insertSql`, `selectSql`) handed in by the Java side, executes them to materialise `salsalesinvoicemaster_calc_tmp` and `salsalesinvoiceslave_calc_tmp` temp tables seeded from the form's current data, runs the share/round arithmetic, then UPDATEs the temp tables and SELECTs them back so the front-end refreshes the master and slave grids with the new per-row amounts.

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