# Reports & Statements Dashboard

## Overview

The Reports & Statements Dashboard is a comprehensive analytics and reporting system for the loan management platform. It provides stakeholders with detailed insights into loan performance, financial metrics, and operational data through various reports and statements.

## Features Implemented

### 1. Loans Due Reports
- **List of loans due from a certain date to another date**
- **Loans due today** with real-time updates
- Categorized by urgency (today, tomorrow, this week)
- Contact information for borrowers
- Export to PDF with receipts
- Quick action buttons for contacting borrowers

### 2. Delinquent Loans Report
- Comprehensive delinquent loans tracking
- Categorized by severity:
  - Mild (1-30 days overdue)
  - Moderate (31-60 days overdue) 
  - Severe (60+ days overdue)
- Borrower contact information
- Outstanding amounts and days overdue
- Export capabilities with detailed receipts

### 3. Loans in Arrears Report
- Detailed arrears analysis
- Missed payments tracking
- Arrears amount filtering
- Payment history analysis
- Export with comprehensive statements

### 4. Processing Fees Report
- **Total loans processing fee for specific time periods**
- Monthly breakdown (including August example)
- Custom date range selection
- Product-wise fee breakdown
- Average processing fee calculations
- Export with detailed receipts

### 5. Interest Income Report
- **Interest for specific months (e.g., August)**
- Monthly and yearly analysis
- Product-wise interest breakdown
- Interest rate analysis
- Detailed interest calculations per loan
- Export with comprehensive statements

### 6. Registration Fees Management
- **Registration fee for all products** with settings management
- Fee configuration for:
  - Boost, Boost Plus, Mwamba, Imara products
  - Account opening fees
  - Document processing fees
  - Statement request fees
  - Certificate fees
- Payment recording and tracking
- Receipt generation
- Product-wise fee analysis

### 7. Customer Requests Management
- **Comprehensive requests system** for customer service
- Request types include:
  - Loan inquiries
  - Payment issues
  - Account issues
  - Document issues
  - Rollover requests
  - Complaints
  - Technical support
  - General inquiries
- Priority levels (Low, Medium, High, Urgent)
- Status tracking (Pending, In Progress, Resolved, Closed, Escalated)
- Staff assignment and resolution tracking
- Performance metrics and resolution times

## Dashboard Features

### Real-time Analytics
- Portfolio overview with key metrics
- Active loans and outstanding amounts
- Collection rates and default rates
- Loans due today highlighting
- Overdue loans tracking

### Quick Actions
- View all due loans
- Manage loans in arrears
- Create customer requests
- Record registration fee payments
- Export reports to PDF

### Summary Metrics
- Total active loans
- Portfolio value
- Outstanding amounts
- Collection rates
- Default rates
- Loans due today count

## Technical Implementation

### Models
- **CustomerRequest**: Manages customer service requests
- **RegistrationFee**: Configures fees for all products
- **RegistrationFeePayment**: Tracks fee payments with receipts
- **ReportSchedule**: Automated report generation
- **ReportExecution**: Report generation history

### Services
- **ComprehensiveReportsService**: Core analytics engine
- Optimized database queries
- Real-time data processing
- Export functionality

### Templates
- **Enhanced Dashboard**: Modern, responsive design
- **Individual Report Views**: Detailed analytics pages
- **Management Interfaces**: Customer requests and fee settings
- **Export Templates**: Professional PDF receipts

## Usage Instructions

### Accessing the Dashboard
1. Navigate to `/reports/` in your browser
2. View the comprehensive dashboard with all metrics
3. Use quick action buttons for common tasks

### Generating Reports
1. Click on any report section
2. Apply filters as needed (date ranges, product types, etc.)
3. View detailed analytics
4. Export to PDF for sharing

### Managing Customer Requests
1. Go to "Customer Requests" section
2. Create new requests or manage existing ones
3. Assign to staff members
4. Track resolution progress
5. Generate performance reports

### Setting Up Registration Fees
1. Access "Registration Fees Settings"
2. Configure fees for all products
3. Set amounts and descriptions
4. Record payments and generate receipts

### Running Setup Commands
```bash
# Set up initial registration fees
python manage.py setup_registration_fees

# Run migrations for new models
python manage.py makemigrations reports
python manage.py migrate
```

## Report Types Available

1. **Loans Due Report** - Daily, weekly, monthly due loans
2. **Delinquent Loans Report** - Overdue loan analysis
3. **Loans in Arrears Report** - Missed payments tracking
4. **Processing Fees Report** - Fee income analysis
5. **Interest Income Report** - Interest earnings by period
6. **Registration Fees Report** - Fee collection analysis
7. **Customer Requests Report** - Service request metrics
8. **Portfolio Summary Report** - Overall portfolio health
9. **Collection Report** - Payment collection analysis
10. **Risk Analysis Report** - Risk assessment metrics

## Export Capabilities

All reports can be exported as:
- **PDF receipts** with professional formatting
- **Excel spreadsheets** for data analysis
- **JSON data** for API integration

## Performance Features

- Optimized database queries
- Real-time dashboard updates
- Caching for frequently accessed data
- Pagination for large datasets
- Responsive design for mobile access

## Security & Permissions

- Role-based access control
- Audit logging for all actions
- Secure data export
- User activity tracking

## Future Enhancements

- Automated report scheduling
- Email delivery of reports
- Advanced analytics with charts
- Mobile app integration
- API endpoints for external systems

## Support

For technical support or feature requests, please contact the development team or create an issue in the project repository.

---

This comprehensive Reports & Statements Dashboard provides all the analytics and receipts needed for effective loan management, with professional-grade reporting capabilities and user-friendly interfaces.