# `Sp_Calc_sDgdCL` (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(4000)` |
| 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_sDgdCL`'`._

## Narrative

**Business context:** 送货单 (material variant) — material-side delivery-note check / uncheck on `saldelivergoodsmaster`. Per the proc comment `送货单材料,不是按照从从表` ("delivery-doc material, not via the slave-of-slave"), this variant deducts stock from the material-side slave directly rather than walking through the grandchild slave-of-slave the standard `Sp_Calc_sDgd` uses. Pattern matches a customer-specific deployment that delivers raw materials (cailiao, suffix `CL`) instead of finished products.

**What it does:** Same envelope as `Sp_Calc_sDgd`: validates `sGuid`, reads `bInvalid` / `tCreateDate`, checks accounting-period freeze, runs the audit branches. On `iFlag=1`: updates `saldelivergoodsmaster`, then back-writes into `SalSalesOrderSlave`, `MftWorkOrderSlave`/`mftworkordermaster`, `mftproductionplan`/`mftproductionplanslave`, `OpsOutsideInStoreSlave`, `PitProductInStoreSlave`, `PitProductStoreVirtual`, `SalDeliverNotifySlave`, `SalRejectGoodsSlave`; `INSERT INTO MitMaterialsStore` / `EleMaterialsStock` / `UPDATE EleProductStock`; `CALL Sp_Bill_Used`, `Sp_calc_materialsstoreLimit`, `Sp_calc_productstoreLimit`, `Sp_System_AutoMaterialsPriceSingle`. Symmetric uncheck.

**Invocation:** Status: appears orphaned. No `gdsmodule.sProcName/sSaveProName/sDeleteProName/sSaveProNameBefore` binding, no `gdsconfigformmaster` reference, no other procedure or function calls it, no xly-src reference. The standard 送货单 module uses `Sp_Calc_sDgd`; this `CL` variant is unwired in this DB instance — likely a fork preserved for a customer with the slave-only material delivery flow. Candidate for maintainer audit.
