# Bank Statement Converter

Converts password-protected FNB and Standard Bank PDF statements to CSV.

## Requirements

- PHP 8.2 FPM
- Composer 2
- `pdftk` CLI tool (for unlocking bank PDFs)

## Setup

### 1. Install pdftk

```bash
sudo apt-get install -y pdftk
```

> **Why pdftk?** Bank statements from FNB and Standard Bank are encrypted with an owner
> password that allows printing but restricts copying. `pdftk` can strip these restrictions
> using an empty owner password — no password input needed from the user.

### 2. Install PHP dependencies

```bash
composer install --no-dev --optimize-autoloader
```

### 3. Point your web server document root to `public/`

**Nginx example:**
```nginx
server {
    listen 80;
    server_name your-domain.com;
    root /var/www/bank-converter/public;
    index index.php;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        fastcgi_pass unix:/run/php/php8.2-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

    # Block access to non-public directories
    location ~* ^/(src|vendor|composer\.) {
        deny all;
    }
}
```

### 4. Set permissions

```bash
chmod 755 public/
chmod 644 public/index.php
```

## Output CSV Columns

| Date | Description | Debit | Credit | Balance |
|------|-------------|-------|--------|---------|

- **FNB**: Date format `06 Oct 2025`
- **Standard Bank**: Date format `27 Feb 2023`
- Amounts are plain numbers (no currency symbol, no commas)
- Standard Bank service fees emitted as separate `Bank Service Fee` rows

## Supported Statement Types

| Bank | Account Type |
|------|-------------|
| FNB | Gold Business Account |
| Standard Bank | Business Current Account |

## Security Notes

- PDFs are processed in memory via a temp file — never written to a permanent path
- Temp files are always cleaned up in a `finally` block
- CSRF protection on the upload form
- File type validated by extension AND mime type
- No transactions are logged or stored
