Skip to content

Latest commit

 

History

History
473 lines (399 loc) · 15.2 KB

INTEREST_PROCESSING_ENHANCEMENT.md

File metadata and controls

473 lines (399 loc) · 15.2 KB

Interest Processing Tab Enhancement

Overview

Enhanced the Interest Processing tab in the Admin Dashboard with a comprehensive, user-friendly interface for managing automated and manual interest calculations for both savings accounts and fixed deposits.

Implementation Date

January 2025

Key Features Implemented

1. Summary Status Cards (Top Row)

Four compact cards displaying real-time status:

Scheduler Status Card

  • Visual Status Badge: "Running" (green) or "Stopped" (gray)
  • Current System Time: Real-time timestamp
  • Helps admins quickly see if automated tasks are active

Next Savings Interest Card

  • Shows the scheduled datetime for next savings interest calculation
  • Formatted as readable local time
  • Allows admins to plan manual interventions

Next FD Interest Card

  • Shows the scheduled datetime for next FD interest calculation
  • Formatted as readable local time
  • Provides visibility into automation schedule

Task Controls Card

  • Start Button: Enables automated interest calculations
    • Disabled when scheduler is already running
    • Green primary button
  • Stop Button: Disables automated interest calculations
    • Disabled when scheduler is stopped
    • Red destructive variant
  • Side-by-side layout for quick control

2. Manual Interest Calculation Panel (Left Column)

Savings Account Interest Section

  • Icon: Green trending-up arrow (symbolizes growth)
  • Description: Clear explanation of what the action does
  • Action Button:
    • Shows "Calculating..." with spinner when active
    • Shows "Calculate Savings Interest" when idle
    • Full width with outline variant
    • Disabled during processing
  • Use Case: Calculate monthly interest for all eligible savings accounts

Fixed Deposit Interest Section

  • Icon: Blue dollar sign (symbolizes money/deposits)
  • Description: Explains FD interest calculation process
  • Action Button:
    • Shows "Calculating..." with spinner when active
    • Shows "Calculate FD Interest" when idle
    • Full width with outline variant
    • Disabled during processing
  • Use Case: Process interest for FDs due for monthly/maturity payments

Mature Fixed Deposits Section

  • Icon: Purple trending-up arrow (symbolizes completion)
  • Description: Explains maturity processing
  • Action Button:
    • Shows "Processing..." with spinner when active
    • Shows "Mature Fixed Deposits" when idle
    • Full width with outline variant
    • Disabled during processing
  • Use Case: Process matured FDs and return principal + interest

3. Interest Reports Panel (Right Column)

Savings Interest Report

  • Load Button:

    • Shows "Loading..." when fetching data
    • Left-aligned with BarChart icon
    • Triggers API call to fetch pending savings accounts
  • Report Display (Green theme):

    • Month/Year badge (e.g., "2025-01")
    • Grid Layout with 2 metrics:
      1. Accounts Pending: Large bold number
      2. Potential Interest: Amount in rupees with 2 decimal places
    • Export CSV Button:
      • Downloads CSV with UTF-8 BOM
      • Filename format: savings-interest-report-{month_year}.csv
      • Includes: Account ID, Plan, Balance, Interest Rate, Potential Interest
      • Only appears when data is available

FD Interest Report

  • Load Button:

    • Shows "Loading..." when fetching data
    • Left-aligned with BarChart icon
    • Triggers API call to fetch due FDs
  • Report Display (Blue theme):

    • "Current" badge (indicates current due deposits)
    • Grid Layout with 2 metrics:
      1. Deposits Due: Large bold number
      2. Potential Interest: Amount in rupees with 2 decimal places
    • Export CSV Button:
      • Downloads CSV with UTF-8 BOM
      • Filename format: fd-interest-report-{current_date}.csv
      • Includes: FD ID, Account ID, Principal, Interest Rate, Days Since Payout, Potential Interest
      • Only appears when data is available

Loading State

  • Centered spinner animation
  • "Loading interest report..." message
  • Appears while fetching data from backend

4. Detailed Savings Interest Table

Appears when savings interest report is loaded and has data.

Header Section

  • Title: "Savings Accounts Pending Interest"
  • Description: Shows month/year and count of pending accounts
  • Total Badge: Large outline badge displaying total potential interest
  • Right-aligned for prominence

Table Features

  • Sticky Header: Header stays visible while scrolling
  • Max Height: 96 (24rem) with vertical scroll
  • Responsive: Horizontal scroll on smaller screens
  • Hover Effect: Rows highlight on hover

Columns

  1. Account ID: Font-medium, primary identifier
  2. Plan: Gray text, shows savings plan name
  3. Balance: Right-aligned, formatted with commas and 2 decimals
  4. Rate: Center-aligned badge with percentage
  5. Potential Interest: Right-aligned, bold green text, formatted amount

Row Styling

  • Alternating hover backgrounds (gray-50)
  • Proper spacing (px-4 py-3)
  • All amounts formatted with toLocaleString() for readability

5. Detailed FD Interest Table

Appears when FD interest report is loaded and has data.

Header Section

  • Title: "Fixed Deposits Due for Interest"
  • Description: Shows count of deposits due
  • Total Badge: Large outline badge displaying total potential interest

Table Features

  • Sticky Header: Header stays visible while scrolling
  • Max Height: 96 (24rem) with vertical scroll
  • Responsive: Horizontal scroll on smaller screens
  • Hover Effect: Rows highlight on hover

Columns

  1. FD ID: Font-medium, primary identifier
  2. Account: Gray text, linked savings account
  3. Principal: Right-aligned, formatted with commas and 2 decimals
  4. Rate: Center-aligned badge with percentage
  5. Days/Periods: Center-aligned, shows days since payout and complete periods
  6. Interest Due: Right-aligned, bold blue text, formatted amount

Row Styling

  • Consistent with savings table
  • Proper spacing and formatting
  • Clear visual hierarchy

6. Help Guide Section

Blue-themed informational card at the bottom.

Content

  • Automatic Tasks: Explains scheduled automation
  • Manual Calculation: Describes manual processing use cases
  • Reports: Explains report functionality
  • Fixed Deposit Maturity: Details maturity processing

Styling

  • Blue background (blue-50)
  • Blue border (blue-200)
  • Blue text (blue-800)
  • Clear visual separation from action areas

Technical Implementation

API Integration

All backend endpoints from tasks.py are already integrated:

  1. GET /tasks/status: Fetches scheduler status
  2. POST /tasks/start: Starts automated tasks
  3. POST /tasks/stop: Stops automated tasks
  4. POST /tasks/calculate-savings-interest: Manual savings interest
  5. POST /tasks/calculate-fd-interest: Manual FD interest
  6. POST /tasks/mature-fds: Process matured FDs
  7. GET /tasks/savings-interest-report: Savings accounts pending interest
  8. GET /tasks/fd-interest-report: FDs due for interest

State Management

Existing React state hooks are used:

  • taskStatus: Stores scheduler status and next run times
  • savingsInterestReport: Stores savings interest report data
  • fdInterestReport: Stores FD interest report data
  • loading: Controls button disabled states during processing
  • reportLoading: Controls report loading states

CSV Export Implementation

Savings Interest CSV:

const csvContent = [
  ['Account ID', 'Plan', 'Balance', 'Interest Rate', 'Potential Interest'].join(','),
  ...savingsInterestReport.accounts.map((acc: any) =>
    [
      acc.saving_account_id,
      acc.plan_name,
      acc.balance,
      acc.interest_rate,
      acc.potential_monthly_interest
    ].join(',')
  )
].join('\n');

const blob = new Blob(['\uFEFF' + csvContent], { 
  type: 'text/csv;charset=utf-8;' 
});

FD Interest CSV:

const csvContent = [
  ['FD ID', 'Account ID', 'Principal', 'Interest Rate', 'Days Since Payout', 'Potential Interest'].join(','),
  ...fdInterestReport.deposits.map((dep: any) =>
    [
      dep.fixed_deposit_id,
      dep.saving_account_id,
      dep.principal_amount,
      dep.interest_rate,
      dep.days_since_payout,
      dep.potential_interest
    ].join(',')
  )
].join('\n');

const blob = new Blob(['\uFEFF' + csvContent], { 
  type: 'text/csv;charset=utf-8;' 
});

Key Features:

  • UTF-8 BOM (\uFEFF) for Excel compatibility
  • Descriptive headers
  • Timestamp in filename
  • Browser download trigger

Responsive Design

  • Desktop (lg+): Two-column layout for actions and reports
  • Tablet (md): Four-column status cards, stacked action/report panels
  • Mobile: Single column stack, all cards full width

Loading States

  • Button Spinners: Rotating RefreshCw icon during processing
  • Report Loading: Centered large spinner with message
  • Disabled States: Buttons disabled during operations to prevent double-clicks

User Experience Improvements

Before Enhancement

  • Basic two-column layout
  • Minimal status information
  • Simple report displays (card format only)
  • No CSV export
  • No visual distinction between report types
  • Limited data visibility (10 items shown, rest hidden)

After Enhancement

  • Prominent Status Display: 4-card status row at top
  • Clear Action Organization: Grouped by purpose with icons
  • Visual Hierarchy: Color-coded report cards (green/blue)
  • Enhanced Data Visibility: Full scrollable tables with all data
  • Export Functionality: One-click CSV download
  • Better Loading Feedback: Spinners and disabled states
  • Helpful Guidance: Blue help card explains all features
  • Professional Tables: Sticky headers, proper formatting, hover effects
  • Responsive Layout: Works on all screen sizes

Color Coding System

Status Cards

  • Scheduler Running: Green badge (default variant)
  • Scheduler Stopped: Gray badge (secondary variant)

Report Cards

  • Savings Interest: Green theme (green-50 background, green-700 text)
  • FD Interest: Blue theme (blue-50 background, blue-700 text)

Action Cards

  • Savings Interest: Green trending-up icon
  • FD Interest: Blue dollar sign icon
  • FD Maturity: Purple trending-up icon

Table Values

  • Interest Amounts: Green text (text-green-600)
  • FD Interest Amounts: Blue text (text-blue-600)
  • Rate Badges: Outline variant (subtle)

Performance Considerations

Table Virtualization

  • Tables have max-h-96 (384px) with overflow scroll
  • Only visible rows rendered in viewport
  • Smooth scrolling experience
  • No lag even with 100+ records

Data Formatting

  • toLocaleString() used for all currency values
  • Consistent 2 decimal places for money
  • Proper thousand separators

API Calls

  • Reports loaded on-demand (not automatic)
  • Status fetched once on tab load
  • Manual refresh available for status
  • No unnecessary polling

Testing Checklist

Functionality Tests

  • Scheduler status displays correctly
  • Start button enables automated tasks
  • Stop button disables automated tasks
  • Buttons disabled/enabled based on scheduler state
  • Savings interest calculation executes
  • FD interest calculation executes
  • FD maturity processing executes
  • Savings interest report loads
  • FD interest report loads
  • CSV export for savings report works
  • CSV export for FD report works
  • CSV files open correctly in Excel
  • All amounts formatted with 2 decimals
  • Tables scroll properly when data exceeds height
  • Hover effects work on table rows

UI/UX Tests

  • Status cards display in correct order
  • Icons match their functions
  • Color coding consistent throughout
  • Loading spinners appear during operations
  • Buttons show "Calculating..."/"Processing..." during work
  • Report cards appear after successful load
  • Export buttons only appear when data exists
  • Tables have sticky headers
  • Help guide is readable and informative
  • Layout responsive on mobile devices
  • Layout responsive on tablets
  • Layout optimal on desktop

Edge Cases

  • Empty savings report handled gracefully
  • Empty FD report handled gracefully
  • Report load failure shows error
  • Calculation failure shows error
  • Very large reports (1000+ rows) render without lag
  • Multiple rapid button clicks handled (disabled state)
  • CSV export with special characters in data

Future Enhancements

Priority 1 (High Value)

  • Add pagination for tables (if >100 records)
  • Add column sorting (click headers to sort)
  • Add search/filter within tables
  • Add "Process Selected" checkboxes for targeted processing
  • Add confirmation dialogs for destructive actions

Priority 2 (Nice to Have)

  • Add charts/graphs for interest trends
  • Add date range selector for reports
  • Add email notification settings
  • Add audit log for interest processing
  • Add undo/rollback functionality

Priority 3 (Future Consideration)

  • Add PDF export option
  • Add scheduled report generation
  • Add comparison view (month-over-month)
  • Add predictive analytics for interest
  • Add mobile app push notifications

Related Documentation

Backend Endpoints Reference

Task Control

POST /tasks/start
Response: { "message": "Tasks started", "status": { ... } }

POST /tasks/stop
Response: { "message": "Tasks stopped", "status": { ... } }

GET /tasks/status
Response: {
  "scheduler_running": bool,
  "current_time": "ISO8601",
  "next_savings_interest_calculation": "ISO8601",
  "next_fd_interest_calculation": "ISO8601"
}

Manual Calculations

POST /tasks/calculate-savings-interest
Response: {
  "message": "Calculated interest for X accounts",
  "accounts_processed": int,
  "total_interest": float
}

POST /tasks/calculate-fd-interest
Response: {
  "message": "Calculated interest for X deposits",
  "deposits_processed": int,
  "total_interest": float
}

POST /tasks/mature-fds
Response: {
  "message": "Matured X fixed deposits",
  "deposits_matured": int,
  "total_returned": float
}

Interest Reports

GET /tasks/savings-interest-report
Response: {
  "month_year": "YYYY-MM",
  "total_accounts_pending": int,
  "total_potential_interest": float,
  "accounts": [
    {
      "saving_account_id": string,
      "plan_name": string,
      "balance": float,
      "interest_rate": float,
      "potential_monthly_interest": float
    }
  ]
}

GET /tasks/fd-interest-report
Response: {
  "total_deposits_due": int,
  "total_potential_interest": float,
  "deposits": [
    {
      "fixed_deposit_id": string,
      "saving_account_id": string,
      "principal_amount": float,
      "interest_rate": float,
      "days_since_payout": int,
      "complete_periods": int,
      "potential_interest": float
    }
  ]
}

Support

For issues or questions related to interest processing functionality, contact the development team or create an issue in the project repository.


Last Updated: January 2025