# `Sp_AfterPost_sQtt` (procedure)

> 报价单


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

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `iFlag` | `int` |
| 2 | IN | `iTmpCheck` | `int` |
| 3 | IN | `sFormGuid` | `varchar(100)` |
| 4 | IN | `sGuid` | `varchar(100)` |
| 5 | IN | `sLoginId` | `varchar(100)` |
| 6 | OUT | `sReturn` | `text` |
| 7 | IN | `sBrId` | `varchar(100)` |
| 8 | IN | `sSuId` | `varchar(100)` |
| 9 | OUT | `sCode` | `int` |

## Body

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

## Narrative

**Business context:** 报价单 (quotation / quote) — historic post-审核/反审核 hook for the quotation form. The `Sp_AfterPost_*` family is the canonical post-审核 calc-proc tier in xly's bill lifecycle (alongside `Sp_beforeSave_*`, `Sp_afterSave_*`, `Sp_Calc_*`, `Sp_Check_*`, `Sp_saveReturn_*`). For `_sQtt` (sQtt = QuoQuotation) the proc supervised the audit-approval side-effects: locking check, cross-flow validation, master flag updates, and downstream propagation to sales-chance and product-customer rows.

**What it does:** `iFlag=1` (审核 path) — refuses if the bill is locked in `SysLocking`; if `CkxDefineCheck=1`, cursors over `quoquotationslave` and `viw_quoquotation × quoquotationprocess × quoquotationcontrol` calling `Sp_System_CheckFlow` to enforce cross-document flow rules; updates `QuoQuotationMaster` (`bCheck=1`, `sStatus=1`, `sCheckPerson`, `tCheckDate`); sets `salsaleschanceproduct.sQuotationId` from `viw_QuoQuotation`; rebuilds `bFailure`/`tFailureDate` so prior approved quotes for the same customer+product become expired; mirrors price into `eleproductcustomer (dQuotationPrice, tQuotationDate)`. `iFlag=0` (反审 path) — refuses uncheck if `bCheck=0`; calls `Sp_Bill_Used('QuoQuotationMaster', ..., 'SaleTrial', ...)` to refuse uncheck if downstream-used; clears the same fields and rolls `bFailure` back to the most recent surviving quote.

**Invocation:** Status: appears orphaned. No caller found in any channel (form-master, gdsmodule hooks, other routines, xly-src grep, schema `*Post*` columns) — candidate for maintainer audit. Despite the rich body, the `Sp_AfterPost_*` lifecycle slot is not wired in the current Java Bill flow; equivalent quotation post-审核 logic now flows through `Sp_Check_sQtt` / `QuoquotationServiceImpl`.

Caveats: the second cursor inside `iFlag=1` sets `ReplaceField_Sum` from `viw_mftworkorderprocess` (work-order view), not from the `viw_quoquotation × quoquotationprocess × quoquotationcontrol` join its own cursor uses — likely copy-paste, the loop bound is wrong; hardcodes `M.sFormId = '101251240115016036175782700'` (tenant-specific form GUID) in the failure-flag propagation.
