# Pak Installment ERP

A complete installment business management system built with PHP + MySQL.

## Features

- **Dashboard** — Investment, sell price, profit, avg profit %, defaulters, monthly collection stats, low stock alerts
- **Customers** — Add with photo, CNIC front/back, multiple guarantors, thumb impression, auto account number, portal credentials
- **Inventory** — Products with category/brand/model, purchase/sale/installment pricing, stock tracking, low stock alerts, edit products
- **Sales** — Cash and installment sales, manual price override, auto agreement + installment schedule generation
- **Agreements** — Manual sell price (actual price hidden), advance amount, product serial/brand/model, Urdu RTL printable agreement
- **Installments** — Collect payments with discount, admin confirmation panel, printable payment slip, WhatsApp receipt
- **Expenses** — Shop expenses, employee salary/advance tracking
- **Employees** — Add staff with designation, salary, login credentials
- **Reports** — Collections, Monthly Collection, Sales, Overdue, Customers, Agreements, Profit, Expenses — all with CSV export and print
- **WhatsApp** — Auto reminders for due/overdue installments, payment receipts
- **Customer Portal** — Self-service portal (CNIC login), view installment schedule and payment history
- **Settings** — Shop details, WhatsApp gateway, thumb device, system settings, cron token

## Default Login

- **URL:** `http://localhost/installment/admin/login.php`
- **Username:** `admin`
- **Password:** `admin123`

> Change the password immediately after first login via Settings → Employees.

## Installation (XAMPP / Localhost)

1. Copy the `installment` folder to `c:\xampp\htdocs\`
2. Start Apache and MySQL in XAMPP
3. Open `http://localhost/installment/install.php`
4. Fill in database details and complete the installer wizard
5. Login at `http://localhost/installment/admin/login.php`

## Installation (cPanel / Shared Hosting)

1. Upload all files to your hosting directory (e.g. `public_html/installment`)
2. Create a MySQL database and user in cPanel → MySQL Databases
3. Grant ALL PRIVILEGES to the user on the database
4. Visit `https://yourdomain.com/installment/install.php`
5. Fill in the form with your database credentials
6. After installation, delete or rename `install.php` for security

## WhatsApp Reminders (Cron)

Set up a daily cron job in cPanel:
```
0 9 * * * curl "https://yourdomain.com/installment/api/cron_reminders.php?token=YOUR_TOKEN"
```

Set the token in **Settings → System → Cron Secret Token**.

## Thumb Device (BMS_2)

1. Install USB driver for SecureTech BMS_2
2. Run the Python bridge: `python api/thumb_bridge.py --port 8765`
3. Enable in **Settings → Thumb Device**
4. Test connection from the settings page

## File Structure

```
installment/
├── admin/          — Login, dashboard, logout
├── api/            — Cron reminders, WhatsApp, thumb capture
├── assets/         — CSS and JS
├── includes/       — Config, database, functions, init
├── modules/        — All feature modules
├── sql/            — Database schema files
├── uploads/        — Customer photos, CNIC, thumbs
├── customer_portal.php
├── index.php
└── install.php
```

## Security Notes

- All forms use CSRF tokens
- Passwords hashed with bcrypt
- SQL uses PDO prepared statements
- Uploads directory blocks PHP execution
- SQL files blocked via .htaccess
- Config file blocked via .htaccess
