---
title: CashReceiptsService
summary: API reference for CashReceiptsService.
status: draft
owner: SAIF Doc Gen
last_reviewed: 2026-09-24
library: SAIF.Services
reference_type: package
---

# CashReceiptsService

Implements `ICashReceiptsService`, the batch process that applies cash-receipt batches recorded for a run date to their Collections cases. It depends on `IUnitOfWork` for repository access and transactions, `ICollectionsRepository` for the `ApplyPayments` post-processing step, `IUserProfileService` for update attribution, and `IDocumentService` to generate and email a PDF payment-posting report split into fraud and third-party sections.

## Purpose
- Locates unbalanced (`BatchBalancedFlag == "N"`) cash-receipt batches for a run date and processes each one, posting a transaction per receipt and updating the associated case's balance.
- Rejects (rolls back) a batch whose receipt count or total does not match the batch-control record, logging the discrepancy.
- Calls `ICollectionsRepository.ApplyPayments` for each affected case after a batch is successfully posted.
- Generates and emails a PDF report summarizing fraud-related and third-party cash receipts for the run date.

## Context
- Namespace: `SAIF.Services.Collections`
- Assembly/package: `SAIF.Services` (packaged inside the `SAIF.SAIFCode.Core` NuGet package)

## Public members
| Member | Signature | Purpose |
| --- | --- | --- |
| UnitOfWork | `protected readonly IUnitOfWork UnitOfWork` | Repository/transaction gateway used for all batch, cash-receipt, case, and transaction persistence in this service. |
| CollectionsRepo | `protected readonly ICollectionsRepository CollectionsRepo` | Collections-specific repository used to reapply payments to a case after a batch is posted. |
| ProfileService | `protected readonly IUserProfileService ProfileService` | Resolves the current user for attributing posted transactions. |
| DocumentService | `protected readonly IDocumentService DocumentService` | Generates the PDF payment-posting report and sends it by email. |
| CashReceiptsService(...) | `public CashReceiptsService(IUserProfileService profile, IUnitOfWork unitOfWork, ICollectionsRepository collectionsRepo, IDocumentService documentService)` | Wires in the profile, unit-of-work, collections repository, and document-service collaborators, enforcing that the repository and unit of work are non-null. |
| ApplyCashReceipts | `public int ApplyCashReceipts(DateTime runDate, ILogWriter controlReport, ILogWriter controlLog, string emailList)` | Processes every unbalanced batch for `runDate`; returns `6` if no batches are found, `5` if any batch fails to balance (after emailing the report), or `0` after successfully posting all batches and emailing the report. |

## Behavioral notes
- Each batch is processed inside `UnitOfWork.Begin()`/`Commit()`; if the summed receipt count/amount does not match the `BatchControl` record, the transaction is rolled back and the batch is skipped, and `ApplyCashReceipts` returns `5` without processing further batches.
- After a batch balances and is marked `BatchBalancedFlag = "Y"`, `CollectionsRepo.ApplyPayments` is called for each distinct positive case ID in a second `Begin()`/`Commit()` transaction, reapplying payment allocation logic per case.
- Every posted receipt creates a matching `Transaction` row (via the private `AddTransaction` helper) using the receipt's own transaction type/reference/date and decreases the case's current balance by the transaction amount; the transaction's `UpdateUser` is hardcoded to `"LCB0009"` while the case's `UpdateUser` uses the current user.
- The generated PDF report groups receipts into "fraud" (`WRKR`/`FPOL`/`FOTH` collection codes) and "third party" (`THRD`/`CTHRD`) sections and is emailed to every address in `emailList` with `@saif.com` appended, from the hardcoded sender `Helpdesk@saif.com`.

## Sources
- Services/SAIF.Services/Collections/CashReceiptsService.cs
