Monetize360
WorkflowsFunctionsSystem Functions

Statement Processor

Process bank statements by mapping categories, forex rates, and other data. Enriches parsed statement data with category mappings, currency conversions, and interbank rates

Statement Processor

Process bank statements by mapping categories, forex rates, and interbank rates. This function enriches parsed statement data with category mappings, performs currency conversions, maps price book details, and calculates reporting values. It processes statements in batches and updates the statement group status.

Technical Name: StatementProcessor

Properties

  • Execution Mode: SYNC
  • Type: NATIVE
  • Category: System Functions
  • Function ID: ef13a8f3-8388-47b1-9354-6be62f241965

Input Schema

Required Parameters

ParameterTypeDescription
statementGroupIdstring (UUID)UUID of the statement group to process (must exist and be parsed)

[Image placeholder: StatementProcessor function configuration panel]

Input Example

{
  "statementGroupId": "a7b9c4d2-3e5f-4a1b-9c8d-7e6f5a4b3c2d"
}

Output Schema

FieldTypeDescription
statusstringProcessing status: PROCESSING, PROCESSED, DUPLICATE, or ERROR
commentsstringComments or error message (if status is ERROR or DUPLICATE)
duplicatebooleanWhether the statement was detected as a duplicate
Additional fieldsobjectAll statement group fields

Output Example

Success Response

{
  "status": "PROCESSED",
  "duplicate": false,
  "bankName": "Chase Bank",
  "fileName": "statement_2024_01.pdf",
  "statementFrom": "2024-01-01",
  "statementTo": "2024-01-31"
}

Duplicate Response

{
  "status": "DUPLICATE",
  "duplicate": true,
  "comments": "Duplicate file detected, processing aborted."
}

Error Response

{
  "status": "ERROR",
  "comments": "Error processing statement: Category mapping not found"
}

[Image placeholder: StatementProcessor output visualization]

How It Works

The function performs the following steps:

  1. Load Statement Group: Retrieves the statement group by ID and sets status to PROCESSING
  2. Check for Duplicates: If duplicate flag is set, aborts processing and sets status to DUPLICATE
  3. Initialize Caches: Loads category mappings, forex rates, and interbank rates into memory caches
  4. Process Statement Services: For each statement service in the group:
    • Validates Dates: Ensures fromDate and toDate are valid
    • Finds Interbank Rate: Looks up interbank rate based on currency, country, and date range
    • Finds Category Mapping: Maps bank service description to category using AFP codes and bank ID
    • Finds Forex Rate: Looks up forex rate for currency conversion to reporting currency
    • Maps Price Book: If category mapping found, maps price book details
    • Calculates Reporting Values: Converts charges to reporting currency
    • Updates Status: Sets service status to IMPORTED if all mappings found, otherwise UNMAPPED
  5. Updates Statement Account: Calculates reporting balances, NII (Net Interest Income), and wallet balance
  6. Final Status: Sets statement group status to PROCESSED, DUPLICATE, or ERROR

Processing Details

Category Mapping

Maps bank service descriptions to categories using:

  • AFP Category Code
  • AFP Service Code
  • Bank Service Description
  • Bank ID

Forex Rate Conversion

Converts service charges to reporting currency:

  • Looks up forex rate for currency pair and date range
  • Calculates totalChargesReporting = totalCharges × forexRate
  • Updates statement account reporting values

Interbank Rate

Finds interbank rate for:

  • Currency
  • Country
  • Date range (fromDate to toDate)

Price Book Mapping

If category mapping includes price book service description:

  • Finds active price book for the bank
  • Matches price book details by country, currency, and service description
  • Calculates agreed price (with forex conversion if needed)

NII Calculation

Calculates Net Interest Income:

NII = ((Balance × ForexRate) × ((InterbankRate/100) - (InterestRate/100))) / 12

Service Status

  • IMPORTED: All mappings found (category, forex, interbank rate)
  • UNMAPPED: One or more mappings missing

Use Cases

Process Parsed Statement

Process a statement after parsing:

{
  "statementGroupId": "{{parsedStatement.statementGroupId}}"
}

Complete Statement Workflow

Full statement processing workflow:

Start → UploadFile → ParseStatement → StatementProcessor → AnalyzeFees → End

[Image placeholder: Workflow example]

Batch Processing

The function processes statement services in batches of 50 for optimal performance.

Status Values

StatusDescription
PROCESSINGStatement is currently being processed
PROCESSEDStatement processing completed successfully
DUPLICATEStatement was detected as duplicate, processing aborted
ERRORAn error occurred during processing

Notes

  • Prerequisites: Statement must be parsed first using ParseStatement or StatementParser
  • Batch Processing: Processes statement services in batches of 50 for performance
  • Caching: Uses in-memory caches for category mappings, forex rates, and interbank rates
  • Currency Conversion: Converts to reporting currency from tenant settings
  • Date Validation: Validates that fromDate is not after toDate
  • Rate Validation: Validates rates are within acceptable range (0.000001 to 1000000)
  • Duplicate Detection: Checks duplicate flag before processing
  • Error Handling: Continues processing other services if one fails