# `Sp_financial_CustomerGrossProfit` (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` | `longtext` |
| 7 | IN | `pageNum` | `int` |
| 8 | IN | `pageSize` | `int` |
| 9 | OUT | `totalCount` | `int` |
| 10 | IN | `countCloumn` | `longtext` |
| 11 | OUT | `countMapJson` | `longtext` |
| 12 | IN | `sFilterOrderBy` | `longtext` |
| 13 | IN | `sGroupby_select_sql` | `longtext` |
| 14 | IN | `sGroupby_group_sql` | `longtext` |

## Body

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

## Narrative

**Business context:** Intended as the per-customer gross-profit report — aggregates 订单总金额 / 直接材料 / 生产补料 / 发外加工 over a date window, grouped by customer, with paging and dynamic column-filter inputs. Sister procs `Sp_financial_OrderGrossProfit`, `Sp_financial_SaleManGrossProfit`, `Sp_financial_EasyCost` share the same canonical paginated-report signature `(tStartDate, tEndDate, sBrId, sSuId, sLoginId, bFilter, pageNum, pageSize, totalCount, countCloumn, countMapJson, sFilterOrderBy, sGroupby_select_sql, sGroupby_group_sql)`.

**What it does:** Materialises temp tables `p_TmpWorkOrder` and `p_TmpTb` to assemble per-order cost breakdowns from `mftworkorder*`, joins to customer/sales-man/product master tables for grouping fields, then builds dynamic SQL (`p_sSql`) honoring the caller's `bFilter`/`sFilterOrderBy`/`sGroupby_*` clauses. Returns paginated rows plus aggregate `countMapJson` and total `totalCount` for the BACK report grid.

**Invocation:** Status: appears orphaned. No `gdsmodule.sProcName`, no `gdsconfigformmaster` data-source binding, no `sysreport` registration, no other-routine caller, and no xly-src reference beyond the install scripts at `script/标版/30100101/Sp_financial_CustomerGrossProfit.sql` and `script/标版/optimize/Sp_financial_CustomerGrossProfit.sql` — candidate for maintainer audit (looks like a deprecated customer-gross-profit report whose form binding was dropped).
