# `Sp_Manufacture_WorkOrderStatistics` (procedure)

> @author:        qmj
			    @date:20210714  封存
				@describe :     工单统计报表
                                以工单部件为单位，显示成品，材料数量状态


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

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `sLoginId` | `varchar(4000)` |
| 2 | IN | `sBrId` | `varchar(100)` |
| 3 | IN | `sSuId` | `varchar(100)` |
| 4 | IN | `bFilter` | `varchar(5000)` |
| 5 | IN | `pageNum` | `int` |
| 6 | IN | `pageSize` | `int` |
| 7 | OUT | `totalCount` | `int` |
| 8 | IN | `countCloumn` | `varchar(5000)` |
| 9 | OUT | `countMapJson` | `longtext` |
| 10 | IN | `sFilterOrderBy` | `varchar(5000)` |
| 11 | IN | `sGroupby_select_sql` | `varchar(5000)` |
| 12 | IN | `sGroupby_group_sql` | `varchar(5000)` |

## Body

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

## Narrative

**Business context:** 生产管理 → 机台作业任务执行 → 产量汇总 — paged 工单统计报表 (header: "以工单部件为单位，显示成品，材料数量状态"). One row per 工单部件 (work-order component) showing 委印单位 / 印刷品名称 / 部件 / order numbers (册 / 令 / 封面 / 张数 / 吨数) so 生产管理 can monitor whether each component's finished-goods qty and material qty are tracking the order.

**What it does:** Creates the temp table `p_TempTable` with the wide column set (`iOrder, sId, sCustomerId, sCustomerName, sWorkOrderNo, sProductName, sPartsName, dPartsQty, dOrderNumQyt, dCoverQty, dSheetsInfactoryQty, dSheetsSelffactoryQty, dTonnesQyt, dPrintSheetsQyt, ...`), `insert Into p_TempTable` from the work-order / control / parts joins, then several `update p_TempTable` passes that join in the production-report and material totals. Final paged result is returned via `CALL Sp_Outstanding_Query` with `bFilter / sFilterOrderBy / sGroupby_*` splicing. Author qmj, 2021-07-14 封存.

**Invocation:** Bound as the data-source of the 产量汇总 form `gfm.sId 192116811110916275265126420` under 机台作业任务执行 → 产量汇总 (`gdsmodule.sId 192116811110916275265124110`) via `gdsconfigformmaster.sSqlStr`. Loaded when the user opens the report. Ships at `script/标版/30100101/schedule/Sp_Manufacture_WorkOrderStatistics.sql`.
