# `Sp_Calc_sPpa1` (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_sPpa1`'`._

## Narrative

**Business context:** 采购管理 → 采购单据 → 采购申请(新) — newer purchase-application variant tied to whole-bill outsourcing (`COMMENT '生产工单—整单发外'`). Audits a `mftworkordermaster` row when the entire work-order is sent out for processing, generating the outsourced material-request automatically.

**What it does:** Guards on `bInvalid`/`SysLocking`/`bFrozen` (accounting-period via `CkxIntervalMonthModifyBill`). When `CkxDefineCheck=1` & `iTmpCheck<>1` drives `Sp_System_CheckFlow` for approval. On `iFlag=1` flips `bCheck=1, sStatus=1, sCheckPerson, tCheckDate` on `mftworkordermaster` and updates `MftWorkOrderMaterials` to mark the materials as fully-outsourced. `iFlag=0` calls `Sp_Bill_Used` to refuse uncheck when downstream rows exist, then reverses.

**Invocation:** Bound to `gdsmodule.sProcName` on 采购申请(新) (sId `192116811110216195779824320`, parent 采购单据 → 采购管理) — dispatched by `BusinessBaseServiceImpl.getPrcName(sFormGuid, …)` on the audit/un-audit button. xly-src only ships the `gdsmodule.sql` binding line (no separate install SQL file) — the proc lives directly in the DB; verify the deployed body if customising.
