# Accounting PDF Reports - Haven Grazuri Investment Limited

## Overview

The accounting system now includes comprehensive PDF export functionality for all major accounting reports. Each PDF features professional branding with the company name and logo at the top of every page.

## Available PDF Reports

### 1. Chart of Accounts PDF
**Access:** Reports → Financial Reports → Chart of Accounts → "Download PDF" button

**Description:** Complete listing of all general ledger accounts organized by type (Assets, Liabilities, Equity, Income, Expenses)

**Includes:**
- Account codes and names
- Account types and subtypes
- Current balances (as of today)
- Color-coded sections by account type
- Total count per account type

**File Format:** `chart_of_accounts_YYYY-MM-DD.pdf`

---

### 2. Trial Balance PDF
**Access:** Reports → Financial Reports → Chart of Accounts → "Trial Balance PDF" button

**Description:** Summary of all account balances showing debit and credit totals to verify the books are balanced

**Includes:**
- All active accounts with their balances
- Debit column for asset and expense accounts
- Credit column for liability, equity, and income accounts
- Total debits and credits
- Balance verification (✅ Balanced or ⚠️ Out of Balance)

**File Format:** `trial_balance_YYYY-MM-DD.pdf`

---

### 3. Account Ledger PDF
**Access:** Reports → Financial Reports → Chart of Accounts → Click any account → "Export PDF" button

**Description:** Detailed transaction history for a specific account

**Includes:**
- Account code and name
- Date range filter
- All transactions with:
  - Transaction date
  - Description
  - Debit amount
  - Credit amount
  - Running balance
- Paginated for large datasets

**File Format:** `account_ledger_{CODE}_YYYY-MM-DD_to_YYYY-MM-DD.pdf`

---

## Report Features

### Professional Branding
Every page includes:
- **Company Name:** Haven Grazuri Investment Limited
- **Tagline:** Trusted Microfinance Partner
- Company logo (if configured)
- Clean separator line

### Page Elements
- **Header:** Company branding on every page
- **Footer:** 
  - Page numbers
  - Generation date and time
  - Professional styling

### Report Design
- Color-coded sections for easy navigation
- Clean, professional table layouts
- Alternating row backgrounds for readability
- Bold headers and clear typography
- Responsive column widths

---

## How to Use

### Generate Chart of Accounts PDF

1. Navigate to **Reports** → **Financial Reports**
2. Click **Chart of Accounts**
3. Click the **"Download PDF"** button (red button, top right)
4. PDF will download automatically with filename: `chart_of_accounts_2026-07-15.pdf`

### Generate Trial Balance PDF

1. Navigate to **Reports** → **Financial Reports**
2. Click **Chart of Accounts**
3. Click the **"Trial Balance PDF"** button (green button, top right)
4. PDF will download automatically with filename: `trial_balance_2026-07-15.pdf`

### Generate Account Ledger PDF

1. Navigate to **Reports** → **Financial Reports**
2. Click **Chart of Accounts**
3. Click on any account code (e.g., "202001 - Cash and Bank Balances")
4. Optionally, filter by date range using the filter form
5. Click the **"📄 Export PDF"** button
6. PDF will download with filename: `account_ledger_202001_2026-04-15_to_2026-07-15.pdf`

---

## Date Range Filtering

All reports support date filtering:

- **Chart of Accounts:** Shows balances as of today
- **Trial Balance:** Can specify "as of" date in the future via URL parameter
- **Account Ledger:** 
  - Default: Last 90 days
  - Custom: Use date range filters before exporting

---

## Technical Details

### PDF Library
- **ReportLab:** Professional PDF generation library
- Version: 4.4.9 (already installed)

### File Locations
- **PDF Generator:** `accounting/pdf_reports.py`
- **Export Views:** `reports/financial_reports_views.py`
- **URL Routes:** `reports/urls.py`

### URL Endpoints

```python
# Chart of Accounts PDF
/reports/financial/chart-of-accounts/pdf/

# Trial Balance PDF
/reports/financial/trial-balance/pdf/?as_of=YYYY-MM-DD

# Account Ledger PDF
/reports/financial/account/<code>/pdf/?start_date=YYYY-MM-DD&end_date=YYYY-MM-DD
```

---

## Customization

### Company Logo
To add your company logo to all PDF reports:

1. Upload logo to `media/company/logo.png`
2. Update the PDF generator initialization:

```python
pdf_generator = AccountingPDFGenerator(logo_path='path/to/logo.png')
```

### Report Colors
Colors are defined in `accounting/pdf_reports.py`:
- Assets: Green (#059669)
- Liabilities: Red (#dc2626)
- Equity: Orange (#d97706)
- Income: Purple (#7c3aed)
- Expenses: Pink (#be123c)

---

## Report Contents Summary

### Chart of Accounts
- **Assets Section:** Cash, loans, receivables, fixed assets
- **Liabilities Section:** Client deposits, payables, borrowings
- **Equity Section:** Share capital, retained earnings
- **Income Section:** Interest, fees, penalties
- **Expenses Section:** Operating costs, salaries, administrative

### Trial Balance
- All active accounts with current balances
- Debit/Credit columns
- Totals verification
- Balance status indicator

### Account Ledger
- Full transaction history for one account
- Chronological order
- Reference numbers
- Posted by (user who created entry)
- Running balance after each transaction

---

## Best Practices

1. **Regular Exports:** Download PDFs monthly for record-keeping
2. **Date Ranges:** Use specific date ranges for period reports
3. **Trial Balance:** Run monthly to verify books are balanced
4. **Archive PDFs:** Store PDFs securely for audit trails
5. **Custom Filters:** Use search and date filters before exporting large ledgers

---

## Future Enhancements

Potential additions:
- Balance Sheet PDF
- Income Statement PDF
- Cash Flow Statement PDF
- General Ledger (all accounts) PDF
- Journal Entry report PDF
- Custom report date ranges
- Multi-branch filtering
- Comparative period reports

---

## Support

For technical issues or feature requests related to PDF reports:
- Check PDF is downloaded (not blocked by browser)
- Ensure ReportLab is installed: `pip install reportlab`
- Check browser console for errors
- Verify accounting system is properly configured

---

**Last Updated:** July 15, 2026  
**Version:** 1.0  
**System:** Haven Grazuri Microfinance Accounting System
