# `Sp_Sales_SalesAnalysiseProductOfMonth` (procedure)


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

## Parameters

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

## Narrative

**Business context:** Generic product×month sales-pivot template — builds a per-month horizontal cross-tab of `dProductMoney` parameterised by source bill (`iBillType` 0=`Viw_MftWorkOrder` / 1=`Viw_SalSalesOrder` / 2=`Viw_SalDeliverGoods` / 3=`Viw_SalSalesInvoice`), classification axis (`iClassifyType` 0=`EleProduct.sParentId` (产品大类) / 1=`A.sProductName` (产品)) and a secondary statistics axis (`iStatisticsType` 0=none / 1=客户 / 2=业务员). Sibling of `Sp_Sales_SalesAnalysiseOfMonth` but with the product axis instead of the customer axis.

**What it does:** Walks `tStartDate`→`tEndDate` month-by-month, splicing one correlated-subquery column per month (`(Select Sum(dProductMoney) From :sSubTableName :sSubJoin Where bCheck=1 AND bInvalid=0 AND date_format(tCreateDate,'%Y-%m-%d') between start and end AND :sKeyFieldName) As YYYYMM`) onto the outer `Select :sFieldName, Sum(dProductMoney) As dTotalMoney`. Then the `iBillType`/`iClassifyType`/`iStatisticsType` switches replace placeholders (`:sTableName`/`:sFieldName`/`:sJoin`/`:sSubJoin`/`:sGroupBy`/`:sKeyFieldName`) with the right view, group key and join. Output is paged via `Sp_Outstanding_Query`. Note: the `Set p_iStatisticsType = IFNULL(p_iStatisticsType, 0)` self-reference is a typo (intended `IFNULL(iStatisticsType, 0)`) — the parameter is effectively ignored.

**Invocation:** Status: appears orphaned. No `gdsconfigformmaster.sSqlStr` binding, no `gdsmodule` hook, no other-routine caller. Only reference is the install script `script/标版/30100101/Sp_Sales_SalesAnalysiseProductOfMonth.sql`. Likely either pre-dispatch template called dynamically from BACK's JS, or a legacy fixture superseded by per-axis procs. Candidate for maintainer audit.
