# `Sp_purpurchaseorder_ProgressOfImplementation` (procedure)

> 采购订单执行情况


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

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `iType` | `int` |
| 2 | IN | `sStatistics` | `varchar(100)` |
| 3 | IN | `bArriveComplete` | `varchar(100)` |
| 4 | IN | `bAll` | `varchar(100)` |
| 5 | IN | `tStartDate` | `datetime` |
| 6 | IN | `tEndDate` | `datetime` |
| 7 | IN | `sBrId` | `varchar(100)` |
| 8 | IN | `sSuId` | `varchar(100)` |
| 9 | IN | `sLoginId` | `varchar(100)` |
| 10 | IN | `bFilter` | `varchar(5000)` |
| 11 | IN | `pageNum` | `int` |
| 12 | IN | `pageSize` | `int` |
| 13 | OUT | `totalCount` | `int` |
| 14 | IN | `countCloumn` | `varchar(5000)` |
| 15 | OUT | `countMapJson` | `longtext` |
| 16 | IN | `sFilterOrderBy` | `varchar(5000)` |
| 17 | IN | `sGroupby_select_sql` | `varchar(5000)` |
| 18 | IN | `sGroupby_group_sql` | `varchar(5000)` |

## Body

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

## Narrative

**Business context:** 采购管理 → 采购分析报表 → 采购执行情况 (form `19211681019715708471237620`, module `19211681019715708471237290`) — paged purchase-order execution report. For each 采购订单 line, joins downstream views to assemble the full execution timeline: ordered → arrived → in-store → checking → invoiced → paid → rejected, with per-stage qty/money/date columns and lag-day counters (`iProductInLag`, `iLag`).

**What it does:** Loops on `iType` / `sStatistics` mode flags and `bArriveComplete`/`bAll` toggles. Builds a 50+ column temp table `p_TmpTb` of every purchase line in the window, then progressively `UPDATE p_TmpTb AS A INNER JOIN (…)` against `viw_purpurchaseinstore_tmp` (in-store), `viw_purpurchasereject` (reject), `purpurchasecheckingslave` (checking/对账), `PurPurchaseInvoiceSlave` (invoice), and `Viw_cahpayment` (payment), filling in `dAuxiliaryInStoreQty`, `dRejectAuxiliaryQty`, `dCheckingAuxiliaryQty`, `dChaseInvoiceAuxiliaryQty`, `dpaymentMoney`, etc. Computes `iProductInLag = DATEDIFF(tInStoreDate, tDeliverDate)`. Finally prepares a dynamic `SELECT * FROM p_TmpTb` and pages it via the inline implementation (this proc does the `bFilter`/paging itself rather than delegating to `Sp_Outstanding_Query`).

**Invocation:** Bound as the data-source for form `19211681019715708471237620` (采购执行情况) under 采购管理 → 采购分析报表 via `gdsconfigformmaster.sSqlStr`. Loaded when the user opens the report. xly-src ships three flavours: `script/标版/30100101/Sp_purpurchaseorder_ProgressOfImplementation.sql`, `script/标版/optimize/…` (performance patch), and `script/客户/千彩/…` (customer override) — verify which is deployed.
