# `Sp_Sales_SalesAnalysiseOfCustomerClass` (procedure)

> 客户分类销售分析表


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

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `tStartDate` | `datetime` |
| 2 | IN | `tEndDate` | `datetime` |
| 3 | IN | `sBrId` | `varchar(100)` |
| 4 | IN | `sSuId` | `varchar(100)` |
| 5 | IN | `sLoginId` | `varchar(100)` |
| 6 | IN | `bFilter` | `varchar(5000)` |
| 7 | IN | `pageNum` | `int` |
| 8 | IN | `pageSize` | `int` |
| 9 | OUT | `totalCount` | `int` |
| 10 | IN | `countCloumn` | `varchar(5000)` |
| 11 | OUT | `countMapJson` | `longtext` |
| 12 | IN | `sFilterOrderBy` | `varchar(5000)` |
| 13 | IN | `sGroupby_select_sql` | `varchar(5000)` |
| 14 | 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_SalesAnalysiseOfCustomerClass`'`._

## Narrative

**Business context:** 销售管理 → 销售分析(客户角度) → 销售分析表(客户分类) — paged sales analysis pivoted by 客户分类 (customer category), one row per `siscustomerclassify` entry with that category's aggregate ordered / collected / outstanding totals.

**What it does:** Seeds `SAS` from `siscustomerclassify` for the current `sBrId`/`sSuId`, then `UPDATE ... INNER JOIN`s in counts and money from `viw_salSalesOrder` joined to `elecustomer` and grouped by `EP.sParentId` (each 客户's category id), restricted to the seven 销售订单 `sFormId` whitelist and `bCheck=1 AND bInvalid=0`. Brings in 收款 from `cahreceiptmaster` the same way (joined via `elecustomer.sParentId`). Computes `dBalanceMoney = dProductMoney − dPayMoney`, the 平均 columns, and the three percentage columns (`dRate`/`dPayRate`/`dBalanceRate`) via a sum in `tempSAS`. Hands `SAS` to `Sp_Do_UpdateByPageSizeBefore` and returns the page.

**Invocation:** Bound as the data-source of the 销售分析表(客户分类) form `gfm.sId=101251240115015848398353901` via `gdsconfigformmaster.sSqlStr`; module path 销售管理 → 销售分析(客户角度) → 销售分析表(客户分类). 优化版 ships at `script/标版/optimize/Sp_Sales_SalesAnalysiseOfCustomerClass.sql`, original at `script/标版/30100101/Sp_Sales_SalesAnalysiseOfCustomerClass.sql`.
