# VECCU Banking System — StormerHost Deployment Guide

## Project Structure
```
veccu/
├── index.php              ← Login page
├── dashboard.php          ← Main dashboard
├── members.php            ← Members list
├── member-new.php         ← Register new member (matching loan form PDF)
├── member-view.php        ← Member profile & accounts
├── loans.php              ← Loans list, approval, rejection
├── loan-apply.php         ← Loan application form
├── loan-view.php          ← Loan details & repayment schedule
├── deposit.php            ← Teller deposit
├── withdraw.php           ← Withdrawal
├── transactions.php       ← Transaction history
├── passbook.php           ← Digital passbook (printable)
├── field-collect.php      ← Field worker deposit collection & sync
├── sms-center.php         ← SMS broadcasts to members
├── logout.php
├── config.php             ← ⚠ Edit this first
├── includes/
│   ├── db.php
│   ├── functions.php
│   ├── sms.php            ← Africa's Talking integration
│   ├── header.php
│   └── footer.php
├── api/
│   └── member-search.php  ← Live member search API
└── sql/
    └── veccu.sql          ← Full database schema
```

---

## Step 1 — StormerHost: Create MySQL Database
1. Log in to **StormerHost cPanel**
2. Go to **MySQL Databases**
3. Create a new database: `veccu`
4. Create a new user (e.g., `veccu_user`) with a strong password
5. Add the user to the database with **ALL PRIVILEGES**
6. Go to **phpMyAdmin** → Select `veccu` database → Import `sql/veccu.sql`

---

## Step 2 — Update config.php
Edit `config.php` with your actual database credentials:

```php
define('DB_HOST', 'localhost');
define('DB_NAME', 'veccu');     // or yourcpanelusername_veccu
define('DB_USER', 'veccu_user'); // or yourcpanelusername_veccu_user
define('DB_PASS', 'YourPassword');
define('APP_URL',  'https://yourdomain.com');
```

---

## Step 3 — Africa's Talking SMS Setup
1. Register at **https://africastalking.com**
2. Create an app (or use `sandbox` for testing)
3. Get your **API Key** and **Username**
4. Register `VECCU` as your Sender ID (takes 2-7 days for approval in Ghana)
5. Update `config.php`:

```php
define('AT_USERNAME', 'your_at_username');
define('AT_API_KEY',  'your_api_key_here');
define('AT_SENDER',   'VECCU');
define('AT_SANDBOX',  false); // true for testing
```

**Ghana-supported networks:** MTN, Vodafone, AirtelTigo

---

## Step 4 — Upload Files
### Method A: File Manager (Recommended)
1. cPanel → **File Manager** → `public_html/`
2. Create folder: `public_html/veccu/`
3. Upload all files maintaining folder structure

### Method B: FTP
```bash
# Using FileZilla, WinSCP, or command line:
scp -r ./veccu/* username@yourdomain.com:public_html/veccu/
```

---

## Step 5 — .htaccess Security
Create `public_html/veccu/.htaccess`:

```apache
# Protect config file
<Files "config.php">
    Order Allow,Deny
    Deny from all
</Files>

# Protect includes directory
<Directory "includes">
    Order Allow,Deny
    Deny from all
</Directory>

# Enable compression
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/css application/javascript
</IfModule>

# Cache static assets
<FilesMatch "\.(css|js|png|jpg)$">
    Header set Cache-Control "max-age=86400, public"
</FilesMatch>

# Force HTTPS
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
```

---

## Step 6 — Enable SSL
- StormerHost cPanel → **SSL/TLS** → **AutoSSL** → Enable Let's Encrypt
- SSL is free and auto-renews

---

## Default Login Credentials
| Role | Email | Password |
|------|-------|----------|
| Admin | admin@veccu.gh | veccu2024 |
| Loan Officer | loans@veccu.gh | veccu2024 |
| Field Worker | field1@veccu.gh | veccu2024 |

**⚠ Change all passwords immediately after first login!**

---

## System Features

### Member Management
- Full registration form (matches the VECCU Loan Application PDF exactly)
- Auto-generates: Member No, Savings Account No, Passbook No
- Sends welcome SMS on registration
- Field worker assignment

### Loan System
- Apply → Approve/Reject (Loan Officer) → Disburse (Admin)
- Built-in loan calculator (reducing balance method)
- SMS notifications at each stage
- Repayment recording
- Overdue tracking

### Deposit / Withdrawal
- Teller: real-time deposit posting
- SMS confirmation to member on every transaction

### Field Worker Module
- Field workers record deposits offline using their phone/tablet
- Collections stored as "unsynced"
- Admin/Supervisor syncs to main ledger in bulk
- SMS sent to members upon sync

### Passbook
- Digital passbook with full transaction history
- Printable (Ctrl+P or Print button)
- Balances, running balance column

### SMS Centre
- Broadcast to: All members, Loan defaulters, Loan reminder (3 days), Specific number
- Pre-built message templates
- Full SMS delivery log with costs
- Character counter (160 chars = 1 SMS)

---

## PHP Requirements
- PHP 8.0+ ✓ (StormerHost supports this)
- PDO + PDO_MySQL extension ✓
- cURL extension ✓ (for SMS API)
- Sessions ✓

---

## Troubleshooting

**"Database Connection Failed"** → Check credentials in `config.php`. On StormerHost, the DB user format is usually `cpanelusername_dbusername`

**SMS not sending** → Enable sandbox mode first (`AT_SANDBOX = true`), test, then switch to live. Ensure cURL is enabled.

**Session issues** → Ensure `session.save_path` is writable; set `session.save_path = '/tmp'` in cPanel PHP settings

**White screen** → Enable `DEBUG_MODE = true` in `config.php` temporarily to see errors

---

*Built for Visionary Elders Co-operative Credit Union, Box 388 Sunyani, Bono Region*
*Tech: PHP 8 + MySQL + Africa's Talking SMS + StormerHost*
