# `Sp_Calc_sScc` (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_sScc`'`._

## Narrative

**Business context:** 销售管理 → 销售单据 → 商机机会单据 (and 销售管理 → KPI事项 → 01/07 报价申请单据) — audit / un-audit of a 销售机会 (sales-opportunity / lead) bill on `salsaleschancemaster`. The audit locks the opportunity as committed before downstream quotes and orders are created against it.

**What it does:** Validates `sGuid`, refuses when `bInvalid=1`. On `iFlag=1` guards on already-checked, `CALL Sp_Bill_Used('salsaleschancemaster', …, 'SaleTrial', …)` to verify the opportunity has not already been consumed downstream; then `UPDATE salsaleschancemaster` to set `bCheck=1`, `sStatus=1`, stamp `sCheckPerson`/`tCheckDate`. `iFlag=0` reverses the flags.

**Invocation:** Bound to `gdsmodule.sProcName` on two modules — `商机机会单据` (sId `101251240115016035903299520`, under 销售管理 → 销售单据; the binding string has a trailing space — `'Sp_Calc_sScc '`) and `01/07 报价申请单据` (sId `172129113112117422778572910`, under 销售管理 → KPI事项). Dispatched by Java `BusinessBaseServiceImpl.getPrcName(sFormGuid, …)` on the audit/un-audit button. Install scripts: `script/标版/30100101/Sp_Calc_sScc.sql` plus `script/标版/optimize/Sp_Calc_sScc.sql`.

Caveat: the trailing-space binding on `商机机会单据` is fragile — anything that string-compares `sProcName` without `RTRIM` would miss it. Worth normalizing.
