GenerateTasksService¶
Implements IGenerateTasksService, the nightly batch job that creates follow-up Task records for Collections credit representatives based on policy/third-party payment activity, expired debtor locations, cases at minimum balance, and expiring judgments. It depends on IUserProfileService to attribute the created/removed tasks to the running batch user, IUnitOfWork for all task/case/policy persistence, and ICollectionsRepository for the underlying payment and expired-location queries.
Purpose¶
- Removes tasks previously created by the current batch user on today's date before regenerating them, avoiding duplicate task accumulation across re-runs.
- Creates tasks for cases with missing policy payments and third-party payments posted since the previous work day.
- Creates tasks for debtors whose policy address/location has expired.
- Creates tasks for cases whose balance has just been brought to the $100 minimum.
- Creates tasks for cases with a judgment expiring within 90 days.
Context¶
- Namespace:
SAIF.Services.Collections - Assembly/package:
SAIF.Services(packaged inside theSAIF.SAIFCode.CoreNuGet package)
Public members¶
| Member | Signature | Purpose |
|---|---|---|
| UnitOfWork | protected readonly IUnitOfWork UnitOfWork |
Repository/transaction gateway used for all task, case, and policy persistence in this service. |
| CollectionsRepo | protected readonly ICollectionsRepository CollectionsRepo |
Supplies the missing-policy-payment, third-party-payment, expired-location, and minimum-balance query results consumed when generating tasks. |
| ProfileService | protected readonly IUserProfileService ProfileService |
Resolves the current batch user for create/update attribution and for identifying the tasks to remove before regeneration. |
| PolicyQuery | protected IQueryable<SAIF.Data.Model.Policies.Policy> PolicyQuery { get; } |
Query root over the Policy repository, used to look up the policy associated with each task's case. |
| GenerateTasksService(...) | public GenerateTasksService(IUserProfileService profile, IUnitOfWork unitOfWork, ICollectionsRepository collectionsRepo) |
Wires in the profile, unit-of-work, and collections repository collaborators, enforcing that the repository and unit of work are non-null. |
| BatchTasks | public void BatchTasks(DateTime prevWorkDay, ILogWriter controlLog, ILogWriter errorReport) |
Runs the full nightly task-generation sequence in order: removes existing tasks, then adds policy-payment, third-party-payment, expired-location, minimum-balance, and expiring-judgment tasks, logging progress to controlLog. |
| ThirdPartyPaymentTasks | public void ThirdPartyPaymentTasks(DateTime prevWorkDay, ILogWriter controlLog, ILogWriter errorReport) |
Adds a task for each third-party payment posted since prevWorkDay, describing the amount and posting date, inside one committed unit-of-work transaction. |
| DebtorsWithExpiredLocTasks | public void DebtorsWithExpiredLocTasks(DateTime selectDate, ILogWriter controlLog, ILogWriter errorReport) |
Adds a "Policy address expired. Please review." task for each debtor whose policy location expired as of selectDate, inside one committed unit-of-work transaction. |
| JudgmentExpiringTasks | public void JudgmentExpiringTasks(DateTime selectDate, ILogWriter controlLog, ILogWriter errorReport) |
Adds a task noting the judgment expiration date for each active case whose judgment will expire between selectDate and 90 days from today, inside one committed unit-of-work transaction, and logs the count generated. |
Behavioral notes¶
BatchTasksfirst deletes (soft-deletes viaIsDeleted = true) all tasks created by the current user on today's date, so re-running the batch on the same day does not duplicate tasks*.- All task-creation methods open a single
UnitOfWork.Begin()/Commit()transaction per phase, so a failure partway through one phase would leave that phase's changes uncommitted*. - Every created task is stamped with fixed reference codes:
TaskSource = "COLL",TaskCategory = "COLL",TaskAction = "NONE", andTaskPriority = "MED", and is attributed to the current user viaProfileService.GetCurrentUser().UserId. - The judgment-expiration query filters at the database level (years, balance, non-closed status) but performs the actual 90-day expiration-window comparison in memory because the underlying date-arithmetic comparison is not supported by the LINQ provider (noted in-code as "this throws a not supported error").
Note: Statements marked with * were inferred from code structure, naming conventions, or contextual evidence where direct confirmation was not available in source artifacts. Statements marked with ** could not be confirmed; treat as unknown until verified.
Sources¶
- Services/SAIF.Services/Collections/GenerateTasksService.cs