# `Sp_financialClosing_BtnEventCheckout_Check` (procedure)

> @author:杨恒林 
		    
			@date:20210521 封存 
				 
			@describe: 检验期间内未审核单据：
				 
			iType = 0 库存单据： 
				     
			材料 iType2 = 0 
			或 1 生产领料,生产退料,采购入库,采购退货,材料调拨,材料报废,来料入库,材料盘点,材料库存调整,

			存货调整金额,其他入库	
						
			产品 iType2 = 0 或 2  	成品入库,成品报废,送货单,退货单,成品调拨,发外入库,成品盘点 
				 
			iType = 1 应收单据： 根据应收类型，找到相应单据销售发票 1 送货单 2印刷工单 3销售订单 4销售合同 5销售对账
				 
			iType = 2 应付单据： 根据应付类弄，找到相应单据 0 采购订单 1 采购入库 2采购对账


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

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `iType` | `int` |
| 2 | IN | `tStartDate` | `datetime` |
| 3 | IN | `tEndDate` | `datetime` |
| 4 | IN | `iType2` | `int` |
| 5 | IN | `sWareHouseGuid` | `varchar(100)` |
| 6 | IN | `p_sPeriodId` | `varchar(100)` |
| 7 | IN | `sBrId` | `varchar(100)` |
| 8 | IN | `sSuId` | `varchar(100)` |
| 9 | IN | `sLoginId` | `varchar(100)` |
| 10 | OUT | `sCode` | `int` |
| 11 | OUT | `sReturn` | `varchar(5000)` |

## Body

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

## Narrative

**Business context:** 系统设置 → 系统参数 → 财务结账 — "unaudited-bill scan" helper for month-end close. Before a period can be frozen, every inventory / AR / AP bill dated inside the period must already be audited. This proc walks the relevant bill tables and lists offenders into `accchecking`.

**What it does:** Normalizes the date window (`tStartDate` → `tEndDate+1`), prepares temp table `p_Sp_financialClosing_BtnEventCheckout_Check(sAllBillNo, sFormName, sFormId)`. Branches on `iType`: 0 = 库存单据 (further split by `iType2` — 0 or 1 covers 生产领料/退料, 采购入库/退货, 材料调拨/报废/来料/盘点/库存调整, 存货调整, 其他入库; 0 or 2 covers 成品入库/报废, 送货单/退货单, 成品调拨, 发外入库, 成品盘点), 1 = 应收单据 (销售发票 → 送货单/印刷工单/销售订单/销售合同/销售对账 by 应收类型), 2 = 应付单据 (0 采购订单 / 1 采购入库 / 2 采购对账). Deletes prior `accchecking` rows for the period, then `INSERT INTO accchecking` one row per unaudited bill found. On any bills found returns `sCode=-1` with localized `sReturn`.

**Invocation:** Called by `Sp_financialClosing_BtnEventCalcMaterialPrice` before re-rolling prices, by `Sp_Calc_sPdt` (the 成品检验单据 audit) when verifying that downstream 入库 is allowed, and by `Sp_financialClosing_BtnEventCheckoutCheckNew` (its newer wrapper). No direct front-end binding — only invoked indirectly through those callers. Install script: `script/标版/30100101/Sp_financialClosing_BtnEventCheckout_Check.sql`.
