# `Sp_saveReturn_sPod` (procedure)

> 采购订单单据反写


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

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `sGuid` | `longtext` |
| 2 | IN | `sBrId` | `varchar(100)` |
| 3 | IN | `sSuId` | `varchar(100)` |
| 4 | IN | `iTag` | `int` |
| 5 | OUT | `sCode` | `int` |
| 6 | OUT | `sReturn` | `longtext` |

## Body

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

## Narrative

**Business context:** 采购管理 → 采购订单 — back-write helper for 采购订单 (`PurPurchaseOrderMaster`). When an order is saved or cancelled, it fans the ordered qty back to every upstream demand — 采购申请、生产工单 BOM、销售订单材料、半成品配套单 — so each demand row's "已订" stays in sync, and it stamps the order's `tMcDate` (制单日期) on the source rows.

**What it does:** Builds `t_data_temp` with `sSrcSlaveId` aggregates from `PurPurchaseOrderSlave`, then updates `PurPurchaseApplySlave`, `mitproductionapplyslave`, `MftWorkOrderMaterials`, `salsalesordermaterials` and `sgdsemigoodsmatchbillmaterials` — setting `dPurchaseAuxiliaryQty/dOrderQty` and `tMcDate`. Two passes within the body handle the `sReelMaterialsStyle <> sMaterialsStyle` (轮转 paper-swap) branch separately. `iTag=1` (before/delete) excludes current doc; `iTag=2` (after) includes it.

**Invocation:** Wrapped by `Sp_afterSave_sPod` (iTag=2) and `Sp_beforeSave_sPod` (iTag=1). 采购订单 binds `Sp_Check_sPod`/`Sp_beforeSave_sPod` on `gdsmodule`; `Sp_afterSave_sPod` is dispatched by `Sp_Invalid_backwriting` (matches form `sId 192116810113315217757747140`). Install script: `xly-src/script/标版/30100101/Sp_afterSave_sPod.sql`.
