# `Sp_Calc_sPsa` (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_sPsa`'`._

## Narrative

**Business context:** 成品库存 → 成品库单据 → 成品库存调整单据 — audit / un-audit of a 成品库存调整 (finished-goods inventory adjustment) bill on `PitProductStoreAdjustmentMaster`/`PitProductStoreAdjustmentSlave`. On approval, the adjusted quantity is posted into the `PitProductStore` inventory ledger and recomputed via the standard product-stock helpers.

**What it does:** Validates `sGuid`, locking checks, then on `iFlag=1` cursors over `PitProductStoreAdjustmentSlave`, `INSERT INTO PitProductStore` an offsetting row per slave, `CALL Sp_calc_productstoreLimit` for warehouse-cap enforcement, and `CALL SP_Inventory_ProductCalcQty` to refresh on-hand counts; `UPDATE PitProductStoreAdjustmentMaster` to flip `bCheck=1`, `sStatus=1`, `sCheckPerson`, `tCheckDate`. `iFlag=0` `DELETE FROM PitProductStore` the posted rows and reverses the master flags.

**Invocation:** Bound to `gdsmodule.sProcName` on `成品库存调整单据` (sId `192116810113315264709817020`) under 成品库存 → 成品库单据. Dispatched by Java `BusinessBaseServiceImpl.getPrcName(sFormGuid, …)` on the audit/un-audit button. Install scripts: `script/标版/30100101/Sp_Calc_sPsa.sql`.
