# `Sp_Sales_PerformanceCommission` (procedure)


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

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `sStatistics` | `varchar(255)` |
| 2 | IN | `tStartDate` | `datetime` |
| 3 | IN | `tEndDate` | `datetime` |
| 4 | IN | `sLoginId` | `varchar(255)` |
| 5 | IN | `iSum` | `int` |
| 6 | IN | `iType` | `int` |
| 7 | IN | `sBrId` | `varchar(100)` |
| 8 | IN | `sSuId` | `varchar(255)` |
| 9 | IN | `bFilter` | `varchar(5000)` |
| 10 | IN | `pageNum` | `int` |
| 11 | IN | `pageSize` | `int` |
| 12 | OUT | `totalCount` | `int` |
| 13 | IN | `countCloumn` | `varchar(5000)` |
| 14 | OUT | `countMapJson` | `longtext` |
| 15 | IN | `sFilterOrderBy` | `varchar(5000)` |
| 16 | IN | `sGroupby_select_sql` | `varchar(5000)` |
| 17 | IN | `sGroupby_group_sql` | `varchar(5000)` |

## Body

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

## Narrative

**Business context:** 销售管理 → 销售分析(人员角度) → 销售提成统计 — paged report that computes each 销售员's commissionable sales by aggregating receivables, payments, adjustments and rejects across the period. Drives the commission-payout review the sales manager runs at month-end.

**What it does:** Reads `CbxReceivablesType` from `SysSystemSettings`, ensures the `ARAccount`/`ARAccountA` running balance is current for the window (`call Sp_Receivables_AR`, `Insert into ARAccount` from `viw_CahReceipt`, `CahPaymentMaster`, `CahReceiptMaster`, `CahCustomerInit`, `cahfinancialadjust`, `viw_SalRejectGoods` filtered by `sysaccountperiod`). Then joins `viw_salsalesorder`/`viw_MftWorkOrder` against `EleCustomer`, `eleproduct`, `elesupply`, `sissalesman`, `sispayment`, `gdsmodule` to assemble per-salesperson sums; `iSum`/`iType`/`sStatistics` switch between summary and detail layouts. Final paging via `Sp_Outstanding_Query` with `countMapJson` from `countCloumn`.

**Invocation:** Bound to `gdsconfigformmaster.sSqlStr` on form `19211681019715708610310890` (销售提成统计) under 销售分析(人员角度) → 销售管理. Install script `script/标版/30100101/Sp_Sales_PerformanceCommission.sql` and re-issued by `script/标版/20210323/gdsconfigformmaster.sql`.
