# `Sp_salsalesorderVirtual_sDgd` (procedure)

> 订单-虚拟库存明细


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

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `sGuids` | `longtext` |
| 2 | IN | `sGuid` | `varchar(100)` |
| 3 | IN | `sBrId` | `varchar(100)` |
| 4 | IN | `sSuId` | `varchar(100)` |

## Body

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

## Narrative

**Business context:** 销售管理 → 销售订单 → 订单-虚拟库存明细 — 送货单-aware (`_sDgd` = 送货单) refresh of the order virtual-stock reservation. Same purpose as `Sp_salsalesorderVirtual` (rebuild `salsalesproductionordervirtual` from a given 销售订单从表 set) but additionally **deducts** the qty that the master 送货单 (`sGuid`) has already shipped from a `bRemainder=1` warehouse, so the virtual reservation reflects post-delivery state.

**What it does:** Parses `sGuids` into `p_t_sId` and `p_t_sId_T`. Deletes the existing virtual rows that match the input slave set, then re-inserts via the same `salsalesorderslave` JOIN as the base proc. Follows with an `UPDATE salsalesproductionordervirtual a ... -= c.dProductQty` deduction join: `c` aggregates `saldelivergoodsslavechildren.dProductQty` from the given `sGuid` 送货单 master across `saldelivergoodsslave` (matched on `sOrderSlaveId`) only for `siswarehouse.bRemainder=1` lines. Finally drops any virtual rows with `dProductQty<=0`.

**Invocation:** Called by `Sp_Calc_sDgd` and `Sp_Calc_sDgd_20250612` — the 送货单 audit-time triggers (variant for the post-2025-06-12 patch). No direct form binding. The proc exists to keep `salsalesproductionordervirtual` consistent when a 送货单 is checked / audited against a `bRemainder=1` warehouse.
