# `Sp_Calc_sDgn` (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_sDgn`'`._

## Narrative

**Business context:** 销售管理 → 销售送货流程 → 送货通知单 — sales delivery-notify check / uncheck on `saldelivernotifymaster`. The 送货通知单 audit is a soft commitment ahead of the actual 送货单: on approval it freezes the notify rows, optionally posts the operator's KPI, and back-writes the notified qty into the upstream sales-order. The same proc also serves the material variant 材料送货通知单单据 (material side of the same notify flow).

**What it does:** Validates `sGuid`, refuses when `bInvalid=1`, and on `iFlag=1` guards on `bCheck` then `Update saldelivernotifymaster`/`saldelivernotifyslave` to set `bCheck=1`, `sStatus=1`, `sCheckPerson`, `tCheckDate`; reads `gdsmodule` + `SysSystemSettings` to decide whether to log a KPI row (`INSERT INTO kpidetail`); calls `Sp_System_CheckFlow` per slave when `CkxDefineCheck=1` to kick off the approval workflow; finally `CALL Sp_Bill_Used` registers consumption. With `iFlag=0`, the symmetric uncheck clears the same flags.

**Invocation:** Bound to `gdsmodule.sProcName` on:
- `送货通知单单据` (sId `15833158840002862255575040533000`) — 销售管理 → 销售送货流程
- `材料送货通知单单据` (sId `101251240115016140461755160`) — 销售单据

Dispatched by Java `BusinessBaseServiceImpl.getPrcName(sFormGuid, …)` on the audit/un-audit (审核/反审核) button — the standard `Sp_Calc_s<Code>` slot. xly-src ships `script/标版/30100101/Sp_Calc_sDgn.sql` (install script) and `script/标版/optimize/Sp_Calc_sDgn.sql` (a performance/lock patch) — verify which is deployed.
