# `Sp_Sales_SalesAnalysiseOfProduct` (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_SalesAnalysiseOfProduct`'`._

## Narrative

**Business context:** 销售管理 → 销售分析(产品角度) → 销售分析表(产品) — paged sales analysis pivoted by 产品 (product), one row per active `eleproduct` entry showing that product's order count / qty / money, max & min unit price, collected money and 占比.

**What it does:** Seeds `SAS` from `eleproduct` for the current 品牌/分公司, fills `sCustomerName` from `elecustomer`. Then `UPDATE ... INNER JOIN`s in counts, qty, money and the min/max `dProductPrice` from `viw_salsalesorder` grouped by `S.sProductId` — restricted to the seven 销售订单 `sFormId` whitelist with `bCheck=1 AND bInvalid=0 AND iOldNew=0`. Brings in 收款 from `viw_cahreceipt` grouped by `sProductId`. Drops zero-money rows, computes `dBalanceMoney`, 平均单价/数量, 占比 columns from `tempSAS`, and finally copies `sCustomerProductNo` from `eleproduct`. Hands `SAS` to `Sp_Do_UpdateByPageSizeBefore` for paging.

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