# `Sp_System_AccountSquareCheck_material` (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_material`'`._

## Narrative

**Business context:** 成本核算 / 财务月结 — materials-only variant of `Sp_System_AccountSquareCheck`. Triggered before materials-side close so that the 材料价格核算 stage refuses to run while any of the in-period materials documents (生产领料/生产退料/采购入库/采购退货/材料调拨/材料报废/来料入库/材料盘点/材料库存调整/存货调整金额/其他入库) still sits at `bCheck=0`. Same author/date marker (杨恒林 2021-05-21 封存).

**What it does:** Despite the shared `iType`/`iType2` parameter shell, this body only walks the materials documents — for each materials business table it `SELECT sBillNo` rows with `bCheck=0` and `[tStartDate, tEndDate]`, scoped by `sBrandsId`/`sSubsidiaryId` and (where applicable) `sWareHouseGuid`. Any hit sets `sCode=-1` and concatenates the offending BillNos plus a localised "存在未审核单据" message into `sReturn`.

**Invocation:** Called by `Sp_financialClosing_BtnEventCalcMaterialPrice_New` at the start of the 计算材料价格 button-event — that proc is dispatched by `GenericProcedureCallServiceImpl.doGenericProcedureCall()` from the 财务月结 → 计算材料价格 button. If the check fails, the price calc aborts. Install/companion scripts: `script/标版/30100101/cost/Sp_financialClosing_BtnEventCalcMaterialPrice_New.sql`.
