# `Sp_Monthlysalesman` (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(255)` |
| 4 | IN | `sSuId` | `varchar(255)` |
| 5 | IN | `bFilter` | `varchar(5000)` |
| 6 | IN | `pageNum` | `int` |
| 7 | IN | `pageSize` | `int` |
| 8 | OUT | `totalCount` | `int` |
| 9 | IN | `countCloumn` | `varchar(5000)` |
| 10 | OUT | `countMapJson` | `longtext` |
| 11 | IN | `sFilterOrderBy` | `varchar(5000)` |
| 12 | IN | `sGroupby_select_sql` | `varchar(5000)` |
| 13 | IN | `sGroupby_group_sql` | `varchar(5000)` |

## Body

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

## Narrative

**Business context:** 销售管理 → 销售分析(人员角度) → 销售人员月销售额统计 — paged annual-sales pivot keyed by sales rep with one column per calendar month. Twin of `Sp_Monthlysalecustomer` but groups by `sSalesManId`; returns one row per 销售员 with `dTotalMoney` plus `dJan..dDece` for the year inferred from `tStartDate`.

**What it does:** Sets the year filter to `YEAR(tStartDate)`. Builds a dynamic SQL `SELECT sId, sSlaveId, sSalesManId, SUM(dProductMoney) AS dTotalMoney, SUM(CASE WHEN MONTH(tCreateDate)=N THEN dProductMoney ELSE 0 END) AS d{Mon} for N=1..12 FROM viw_salsalesorder AS T WHERE sFormId IN (the seven 销售订单 sFormIds) AND bInvalid=0 AND YEAR(tCreateDate) = <year> GROUP BY sSalesManId`. Hands the dynamic SQL to `Sp_Outstanding_Query` for paging, total-count, and `bFilter` condition splicing.

**Invocation:** Bound as the data-source of the 销售人员月销售额统计 form `gfm.sId 101801153119616634989456840` via `gdsconfigformmaster.sSqlStr` — under module 销售人员月销售额统计 (`sId 101801153119616634989456610`) → 销售分析(人员角度) → 销售管理. Loaded when the user opens the report. Daily-bucket twin: `Sp_DaysaleSalesMan` (per-day instead of per-month).
