# `Sp_Cashier_BankJournal` (procedure)

> 银行日记帐


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

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `tStartDate` | `datetime` |
| 2 | IN | `tEndDate` | `datetime` |
| 3 | IN | `sBankInfo` | `varchar(100)` |
| 4 | OUT | `dOutBMoney` | `decimal(18,6)` |
| 5 | IN | `sBrId` | `varchar(100)` |
| 6 | IN | `sSuId` | `varchar(100)` |
| 7 | IN | `sLoginId` | `varchar(100)` |
| 8 | IN | `bFilter` | `varchar(5000)` |
| 9 | IN | `pageNum` | `int` |
| 10 | IN | `pageSize` | `int` |
| 11 | OUT | `totalCount` | `int` |
| 12 | IN | `countCloumn` | `varchar(5000)` |
| 13 | OUT | `countMapJson` | `longtext` |
| 14 | IN | `sFilterOrderBy` | `varchar(5000)` |
| 15 | IN | `sGroupby_select_sql` | `varchar(5000)` |
| 16 | IN | `sGroupby_group_sql` | `varchar(5000)` |

## Body

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

## Narrative

**Business context:** 财务管理 → 出纳 → 银行日记账 — paged bank-journal report for one settlement account. Computes opening balance from `CahCashierInit` plus all prior `CahWasteBook` rows up to the period start, then lists every `CahWasteBook` entry in the requested window with running balance, joining receipt/payment masters so each row carries customer/supplier name and expense item.

**What it does:** Reads the cashier cutoff `tCashierDate` from `SysAccountPeriod`, sums prior in/out money from `CahWasteBook` to seed `p_dInitMoney`, then opens a cursor over `CahWasteBook` for the chosen `sBankInfo` and inserts each line into temporary `Cash` with running balance. Enriches `sMemo` by joining `CahReceiptMaster`+`elecustomer` (inbound) and `CahPaymentMaster`+`elesupply` (outbound). Trims pre-period rows, inserts a "上期结余" carry-row, fills `sBankName` from `sisbank`, and finally builds dynamic SQL routed through `Sp_Outstanding_Query`/`Sp_Do_UpdateByPageSizeBefore` for pagination/total-count.

**Invocation:** Bound as the data-source of the 银行日记账 form (sId `15782950790001381104094341598500`) via `gdsconfigformmaster.sSqlStr`. Loaded when the user opens 出纳 → 银行日记账; the form-binding dispatcher fetches the proc name from the form-master row. xly-src ships an `optimize/Sp_Cashier_BankJournal.sql` patch alongside the base `30100101/` script — verify which is deployed.
