# `Sp_Daysalecustomer` (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_Daysalecustomer`'`._

## Narrative

**Business context:** 销售管理 → 销售分析(客户角度) — paged daily-sales pivot keyed by customer. For the month containing `tStartDate`, returns one row per customer with the monthly total `dProductMoney` plus 31 day-buckets `d1..d31` showing each day's revenue from `viw_salsalesorder` (the consolidated sales-order view).

**What it does:** Formats the month-key `%Y%m` from `tStartDate`, then builds a dynamic SQL that `SELECT sId, sSlaveId, sCustomerId, sSalesManId, sCustomerName, SUM(dProductMoney) AS dTotalMoney, COUNT(1) AS dSum, SUM(CASE WHEN DAY(tCreateDate)=N THEN dProductMoney ELSE 0 END) AS dN`-style for N=1..31. Pulls from `viw_salsalesorder` filtered to `bInvalid=0` and the seven `sFormId`s representing the standard 销售订单 form variants. Groups by `sCustomerId`. The dynamic SQL is handed to `Sp_Outstanding_Query` for paging, total-count, group-by extension, and `bFilter` user-condition splicing.

**Invocation:** Bound as the data-source of the 销售分析(按日累计) form `gfm.sId=192116811011016400861831491` via `gdsconfigformmaster.sSqlStr` — under module 销售分析(客户角度) (`sId 16316212900007840201152805231000`) inside 销售管理. Loaded when the user opens the report; the form-binding dispatcher fetches the proc name from the form-master row and passes the page/filter params. Not in xly-src 30100101 install scripts — DB-only.
