# `Sp_Calc_sScd` (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` | `varchar(5000)` | | 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_Calc_sScd`'`._ ## Narrative **Business context:** 销售管理 — 长期合同 (long-term sales contract) audit / un-audit on `salsalesContractmaster`. A 长期合同 is a frame contract that pre-commits a customer to volume; auditing it freezes the slave rows, locks the linked quotation, and seeds downstream receivables. **What it does:** Validates `sGuid`, refuses when `bInvalid=1`, and on `iFlag=1` guards on `bCheck` then `Update salsalesContractmaster`/`salsalesContractSlave` to set `bCheck=1`, `sCheckPerson`, `tCheckDate`; also locks the originating `quoquotationslave`, optionally registers a `kpidetail` row, seeds `CahReceivables`, may upsert `EleProduct`/`eleproductcustomer`/`EleProductStock`, and calls `Sp_System_CheckFlow` per slave when define-check is on. `iFlag=0` reverses the same chain (delete `CahReceivables`, clear flags) and `CALL Sp_Bill_Used` registers consumption either way. **Invocation:** Bound to `gdsmodule.sProcName` on: - `长期合同单据` (sId `16033546780009409151975037702000`) — 销售管理 - `长期合同明细` (sId `16033543010008296913785356518000`) Dispatched by `BusinessBaseServiceImpl.getPrcName(sFormGuid, …)` on the 审核/反审核 button — the standard `Sp_Calc_s` slot. xly-src ships `script/标版/30100101/Sp_Calc_sScd.sql` (install) and `script/标版/optimize/Sp_Calc_sScd.sql` (perf patch) — verify which is deployed.