# `Sp_System_AccountSquareCheck` (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 | `sBrId` | `varchar(100)` |
| 7 | IN | `sSuId` | `varchar(100)` |
| 8 | IN | `sLoginId` | `varchar(100)` |
| 9 | OUT | `sCode` | `int` |
| 10 | OUT | `sReturn` | `varchar(5000)` |

## Body

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

## Narrative

**Business context:** 成本核算 / 财务月结 — pre-close validator that scans the closing period for un-audited 业务单据 across stock / AR / AP. Header comment marks it `封存` (sealed/frozen, 2021-05-21 杨恒林) — superseded by `Sp_System_AccountSquareCheck_New`/`Sp_System_AccountSquareCheck_material`. Branches on `iType`: `0` 库存单据 (with `iType2=0/1` materials side: 生产领料/生产退料/采购入库/采购退货/材料调拨/材料报废/来料入库/材料盘点/材料库存调整/存货调整金额/其他入库; `iType2=0/2` products: 成品入库/成品报废/送货单/退货单/成品调拨/发外入库/成品盘点); `1` 应收 (1 送货单, 2 印刷工单, 3 销售订单, 4 销售合同, 5 销售对账); `2` 应付 (0 采购订单, 1 采购入库, 2 采购对账).

**What it does:** For each branch the body assembles a list of `sBillNo` rows with `bCheck=0` (or equivalent un-audited flag) inside `[tStartDate, tEndDate]`, optionally filtered by `sWareHouseGuid`. Hits set `sCode=-1` and `sReturn` to the localised "存在未审核单据" message via `Fun_Sis_GetConst`/`Sp_Sis_GetConst` plus the offending BillNo list. The pre-close caller is expected to abort if `sCode=-1`.

**Invocation:** Called by `Sp_Cost_CheckBusinessData` from the 财务结账 flow — the latter resolves the active period from `sysaccountperiod`, then `CALL Sp_System_AccountSquareCheck(0, p_tStart, p_tEnd, 0, '', '1111111111', '1111111111', 'admin', sCode, sReturn)` on the stock branch. Also referenced by `Sp_financialClosing_BtnEventCalcMaterialPrice_New`. Install script: `script/标版/30100101/cost/Sp_System_AccountSquareCheck.sql`. Verify the deployed body is the sealed one or its `_New` successor before changes.
