# `Sp_Receivables_ARDetail` (procedure)


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

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `iType` | `int` |
| 2 | IN | `sCustomerId` | `varchar(100)` |
| 3 | IN | `tStartDate` | `varchar(100)` |
| 4 | IN | `tEndDate` | `varchar(100)` |
| 5 | IN | `sLoginId` | `varchar(100)` |
| 6 | INOUT | `dNoReceiptMoney` | `decimal(18,6)` |
| 7 | INOUT | `dDueReceiptMoney` | `decimal(18,6)` |
| 8 | IN | `sBrId` | `varchar(100)` |
| 9 | IN | `sSuId` | `varchar(100)` |
| 10 | IN | `bFilter` | `varchar(5000)` |
| 11 | IN | `pageNum` | `int` |
| 12 | IN | `pageSize` | `int` |
| 13 | OUT | `totalCount` | `int` |
| 14 | IN | `countCloumn` | `varchar(5000)` |
| 15 | OUT | `countMapJson` | `longtext` |
| 16 | IN | `sFilterOrderBy` | `varchar(5000)` |
| 17 | IN | `sGroupby_select_sql` | `varchar(5000)` |
| 18 | IN | `sGroupby_group_sql` | `varchar(5000)` |
| 19 | OUT | `sCode` | `int` |
| 20 | OUT | `sReturn` | `longtext` |

## Body

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

## Narrative

**Business context:** 常用模块 → 常用设置 → 订单-收款明细表 family — per-order AR detail rows broken out by document type. The single procedure serves seven sibling reports (sales / receipts / invoiceable / invoice / adjustment-票据 / adjustment-金额 / refunds), discriminating by `iType`.

**What it does:** For a given customer (`sCustomerId`) and date range, walks every order's lifecycle: lists `salsalesorderslave` rows, joins delivery (`saldelivergoodsslave`), checking (`salsalescheckingslave`), invoice (`SalSalesInvoiceMaster`), receipt (`CahReceiptMaster`), adjustment (`CahFinancialAdjust`), payment (`CahPaymentMaster`), reject/quality-abnormal slaves. Picks the appropriate slave-money/tax fields per `iType` (`p_sSlaveMoneyField`, `p_sSlaveTaxField`) and unions into a `TmpAll` temp set. Hands the final dynamic SQL to `Sp_Outstanding_Query` for paging, total counts, `bFilter`/`sGroupby_*_sql` splicing. Returns `dNoReceiptMoney`/`dDueReceiptMoney` totals via INOUT.

**Invocation:** Bound as data-source for seven forms under module 常用设置 (`19211681019715652613160550`): 订单-收款明细表(销售) (`gfm 19211681015115285335200010`), (收款) `19211681015115285344460960`, (应开票) `19211681015115285346418610`, (调整票据) `19211681015115285348627730`, (调整金额) `192116810113315317427032430`, (退款) `192116810113315317431675000`, (开票) `192116810113315317436170150`. Also referenced by `Fun_getInitColumnByProName`. Install: `script/标版/30100101/Sp_Receivables_ARDetail.sql`.
