# `Sp_Sales_SalesAnalysiseOfSalesperson` (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_SalesAnalysiseOfSalesperson`'`._

## Narrative

**Business context:** 销售管理 → 销售分析(人员角度) → 销售分析表(业务人员) — paged sales analysis pivoted by 销售员/业务员 (`sissalesman`), one row per active salesperson with that user's ordered, collected, reconciled and invoiced totals plus 未对账 / 未开票 deltas. (The `COMMENT '现金日记帐'` on the proc is a copy-paste artifact — actual purpose is per-salesperson sales analysis.)

**What it does:** Seeds `SAS` from `sissalesman` for the current 品牌/分公司, then `UPDATE ... INNER JOIN`s in order counts, qty and money from `viw_salsalesorder` grouped by `S.sSalesManId` — restricted to the seven 销售订单 `sFormId` whitelist, `bCheck=1 AND bInvalid=0`, filtered by `tCheckDate` rather than `tCreateDate`. Three more inner joins bring in 收款 (`viw_cahreceipt.dSlaveTotalMoney` → `dPayMoney`), 对账 (`viw_salsaleschecking.dProductMoney` → `dCheckMoney`), and 开票 (`SalSalesInvoiceMaster.dTotalMoney` → `dInvoiceMoney`). Computes `dBalanceMoney`/`dNoCheckMoney`/`dNoInvoiceMoney` deltas, averages and 占比 columns, then runs `Sp_Do_UpdateByPageSizeBefore` and returns paged rows with a `RowNum` sequence.

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