# `Sp_mftworkorderprocesslost` (procedure)


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

## Parameters

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

## Body

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

## Narrative

**Business context:** 生产管理 → 生产工单 → 工序损耗分析 — paged process-loss report driven by `mftworkorderprocess` (per-工序 row of a work-order). For each process step the report computes input qty, output qty, declared loss, prior-reported qty, and active-loss rate, so production controllers can spot machines/processes with abnormal scrap.

**What it does:** Allocates `TMP_viw_mftworkorderprocesslost_Tvlb` then dynamically `INSERT INTO TMP_… SELECT … FROM mftworkorderprocess A JOIN mftworkordermaster B ON A.sParentId=B.sId JOIN mftworkorderslave S ON S.sParentId=B.sId AND S.iOrder=1 LEFT JOIN mftworkordercontrol D ON D.sId=A.sControlId WHERE B.bCheck=1 AND B.bInvalid=0 …`. Computes `totalCount` and `countMapJson` (`dLossQty`, `dAllProductionReportQty`). Denormalises customer/product/process/work-centre/outside-supply names via UPDATE-joins on `elecustomer`, `eleproduct`, `eleprocess`, `elemachine + sisworkcenter`, and `opsoutsideprocessslave + opsoutsideprocessmaster + elesupply`. Calls `Fun_GetPreProcessQty` for the prior-process reported qty, then derives `dActiveLossQty`, `dLossQtyRate`, `dActiveLossQtyRate`, `dActiveLossRate`. Final `SELECT * FROM TMP_…` paged.

**Invocation:** Status: appears orphaned. No caller found in any channel (form-master `sSqlStr`/`sConfigSqlStr`/`sSqlCondition`, gdsmodule hooks, other routines, xly-src grep across all extensions). Body parameter shape is the standard outstanding-query report signature, so the report grid likely exists in a tenant-specific form-master not present in this DB snapshot — candidate for maintainer audit.
