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

## Body

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

## Narrative

**Business context:** 生产管理 / 生产报表 — production output report grouped by 工序分类 / 工序 (process classification / process), showing today's and the current month's output qty, edition count, and machine-hours per process. The page header carries the unrelated label "现金日记帐" — a copy-paste leftover; the body and joins are entirely production-side, not finance.

**What it does:** Builds temp table `SAS` keyed by `(sProcessClassifyId, sProcessId)`, seeded from `viw_mftproductionreport` joined to `eleprocess` and `sisprocessclassify`. Calls `Sp_Do_UpdateByPageSizeBefore` for paging/filter/groupby plumbing. Two follow-up updates: today's totals (`DATE_FORMAT(tCheckDate,'%m-%d-%Y')=NOW()`) and this month's totals (`'%m-%Y'`) — each summing `dProductQty`, `iStick` (edition qty from `mftproductionplanslave`), and `dHour` per `sProcessId`. Returns `SELECT * FROM SAS`.

**Invocation:** Customer-specific report — xly-src ships only `script/客户/千彩/Sp_ProductionDepartmentsReports.sql` (the 千彩 tenant variant). No live form-master, gdsmodule hook, or other-proc reference in `xlyweberp_saas_ai`. The standard form-data-source binding would live on a tenant `gdsconfigformmaster.sSqlStr` — verify on the 千彩 deployment before relying on it on a standard install. Note the spurious `select * from xlyweberp.sisprocessclassify;` mid-body which leaks a cross-schema reference.
