# `Sp_Calc_sPaj` (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_sPaj`'`._

## Narrative

**Business context:** Two-bind audit for 成品调拨 (finished-goods inter-warehouse transfer) on `pitproductadjustmaster`/`PitProductAdjustSlave`. Serves the 成品库存 → 成品库单据 → 成品调拨 doc and the parent 成品调拨(入) report list. On approval it freezes the transfer and posts inventory movements into `EleProductStock_master` (the electronic stock ledger) using a cursor (`Cur_OrderSlave`) over the slave lines.

**What it does:** Standard validate-and-flip with stock-side mutation — guards `sGuid`/`bInvalid`/`bCheck`, then `Update PitProductAdjustMaster` + `PitProductAdjustSlave` to set `bCheck=1, sStatus=1, sCheckPerson, tCheckDate=NOW()`. Opens a cursor over the slave rows, for each line `INSERT INTO EleProductStock_master` to record the from-warehouse decrement and to-warehouse increment, and links the movements back via `sParentId`/`sSlaveId`. `iFlag=0` reverses the flags and the stock entries.

**Invocation:** Bound to `gdsmodule.sProcName` on:
- `成品调拨` (sId `192116810113315264648983180`) — 成品库存 → 成品库单据
- `成品调拨(入)` (sId `192116810111915318167333520`) — 成品库存 (entry-side variant)

Dispatched by `BusinessBaseServiceImpl.getPrcName(sFormGuid, …)`. The body is large (~48K chars) due to the per-line cursor work and conditional stock-cost rebuild — defer to `script/标版/30100101/Sp_Calc_sPaj.sql` plus the optimize patch for the canonical version. Paired pre-flight guard ships as `Sp_Check_sPaj.sql`.
