# `Sp_Calc_sLok` (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_sLok`'`._

## Narrative

**Business context:** 物流管理 → 10.物流单据 → 物流对账单单据 — logistics-reconciliation check / uncheck on `opsoutsidecheckingmaster`. Approves a 物流对账单 (carrier reconciliation against a batch of 物流单), which freezes the matched logistics rows and posts an accounts-payable line to the carrier supplier.

**What it does:** Validates `sGuid`, refuses when `bInvalid=1`, checks `sysaccountperiod.bFrozen` per `SysSystemSettings.CkxIntervalMonthModifyBill` and `SysLocking` against the carrier supplier. With `iFlag=1`: opens a cursor over `opsoutsidecheckingslave` rows, calls `Sp_System_CheckFlow` per slave when `CkxDefineCheck=1` to drive the approval workflow, `Update opsoutsidecheckingmaster` to set the audit flags, `Update logisticsorderslave` / `Update OpsOutsideInStoreSlave` to flag the source rows as reconciled, `INSERT INTO CahPaymentables` to post the AP line for the carrier, `Update CahSupplyInit` to refresh the supplier opening-balance running total, conditionally `INSERT INTO kpidetail` for the operator, and finally `CALL Sp_Bill_Used`. Symmetric uncheck on `iFlag=0`.

**Invocation:** Bound to `gdsmodule.sProcName` on `物流对账单单据` (sId `101251240115016270323854760`), parent `10.物流单据` → 物流管理. Dispatched by Java `BusinessBaseServiceImpl.getPrcName(...)` on the audit/un-audit button. xly-src ships `script/标版/30100101/Sp_Calc_sLok.sql` (install) and `script/标版/optimize/Sp_Calc_sLok.sql` (patch).
