# `Sp_Calc_sSod` (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_sSod`'`._

## Narrative

**Business context:** 销售管理 → 销售订单 (sales order — `SalSalesOrderMaster`/`Slave`) audit / un-audit. This is the central sales-order approval proc: on audit it freezes the order, expands BOM/process snapshots, reserves stock, seeds AR, refreshes the customer product file, and may auto-trigger the workflow engine. Reused across many order variants (轮转 / 丝印 / 膜类 / 套装 / 书刊 / 材料 / 项目申请 / 补货 / 打样申请 / 配送任务 / 备货 / 代收 / 项目立项-related forms).

**What it does:** Validates `sGuid`/`bInvalid`/`SysLocking`/`sysaccountperiod`, then on `iFlag=1` sets `bCheck=1`, `sCheckPerson`, `tCheckDate` on `SalSalesOrderMaster`/`SalSalesOrderSlave`; cleans-and-rewrites order children (`DELETE FROM salsalesordercontrol`, `salsalesordercontrolcombine`, `salsalesordermaterials`, `salsalesorderprocess`, `salSalesOrderChild`, `CahReceivables` then re-`INSERT` from authoritative sources); upserts `EleProduct`/`eleproductcustomer`/`EleProductStock` to refresh the customer product file; calls `Sp_ProductStoreVirtual` to reserve virtual stock against `PitProductStoreVirtual`, `SP_Sis_GetMaxNo` for new product/lot codes, `Sp_System_CheckFlow` per slave when define-check is on, `Sp_System_AutoSendMobileCheckMsg` to push the audit notification, and `Sp_Bill_Used` to register consumption. `iFlag=0` reverses every step.

**Invocation:** Bound to `gdsmodule.sProcName` on 30+ forms — the canonical ones being `1/3 新增销售订单` (sId `101251240115016086186007360`, with `sSaveProName=Sp_Check_sSod`, `sSaveProNameBefore=Sp_beforeSave_sSod`, `sDeleteProName=Sp_afterSave_sSod`) and `1/3 新增轮转销售订单` (sId `101251240115015878710737470`). Also reused on `销售订单单据(兼容停用)`, `轮转/丝印/膜类/套装/书刊/材料类销售订单`, `打样申请`, `项目申请(S-BOM)`, `合版订单处理`, `印前文件处理单据`, `配送任务`/`配送记录`/`备货记录`/`代收记录`, `补货订单`, `异常待处理订单`, `工单任务预测`, etc.

Dispatched dynamically by `BusinessBaseServiceImpl.getPrcName(sFormGuid, …)` on the 审核/反审核 button. Also called directly from Java by `ErpOrderProcurementServiceImpl.doCallSsod()` via the `CheckErpOrderThread` flow when an online (线上) order or business-card single-page order auto-audits after import — and immediately followed by `doCallSsodAfter()` which calls `Sp_Calc_sSodAfter`. A 高旺 customer override (`script/客户/高旺/20211101成品库存多单位/Sp_Calc_sSod.sql`) and a 千彩 override (`script/客户/千彩/Sp_Calc_sSod.sql`) exist — verify which is deployed.
