Skip to content

thomasdreyer/invoyce

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Invoice Management System

A modern, mobile-friendly invoice management application with OTP authentication for creating, editing, viewing, and managing invoices. Perfect for small businesses and freelancers.

✨ Features

Feature Description
πŸ” OTP Login Secure one-time password authentication
πŸ“ Create Invoices Create new invoices with customer details and line items
✏️ Edit Invoices Modify existing invoices and update details
πŸ‘οΈ View Invoices View detailed invoice information
πŸ—‘οΈ Delete Invoices Remove unwanted invoices
πŸ“„ Export to PDF Generate and download PDF versions
πŸ”— Share Invoices Create shareable public links
πŸ“± Responsive Design Works perfectly on phones, tablets, and desktops
πŸ”’ Auto Numbering Automatic invoice number generation (INV-2026-00001)
πŸ’° Flexible Discounts Item-level and invoice-level discounts
πŸ“Š Tax Calculation Automatic VAT/tax calculation (15%)

βœ… Authentication & Testing

OTP (One-Time Password) Login System

  • Login via OTP code sent to email
  • Test credentials available for all environments (localhost and deployed):
    • Email: test@invoyce.com
    • OTP Code: 123456
  • On production (cPanel), OTP codes are emailed via PHP mail() function
  • On localhost, OTP code is shown in debug message for convenience

πŸ“‹ Requirements

  • PHP 7.4 or higher with mail() support (for production OTP emails)
  • MySQL 5.7 or higher
  • Web Server Apache, Nginx, or built-in PHP server
  • Modern Browser (Chrome, Firefox, Safari, Edge)

πŸš€ Quick Start

1. Setup Database

Create the database and run all SQL to create tables:

CREATE DATABASE IF NOT EXISTS invoice_app;
USE invoice_app;

CREATE TABLE customers (
  id INT AUTO_INCREMENT PRIMARY KEY,
  name VARCHAR(255) NOT NULL,
  email VARCHAR(255),
  phone VARCHAR(20),
  address TEXT,
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  INDEX idx_email (email),
  INDEX idx_name (name)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE invoices (
  id INT AUTO_INCREMENT PRIMARY KEY,
  invoice_number VARCHAR(20) UNIQUE,
  customer_id INT NOT NULL,
  invoice_date DATE NOT NULL,
  due_date DATE NOT NULL,
  subtotal DECIMAL(10,2) NOT NULL DEFAULT 0.00,
  tax DECIMAL(10,2) NOT NULL DEFAULT 0.00,
  discount_percent DECIMAL(5,2) DEFAULT 0.00,
  discount_amount DECIMAL(10,2) DEFAULT 0.00,
  total DECIMAL(10,2) NOT NULL DEFAULT 0.00,
  status ENUM('draft', 'sent', 'paid', 'overdue') DEFAULT 'draft',
  share_token VARCHAR(64) UNIQUE,
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  FOREIGN KEY (customer_id) REFERENCES customers(id) ON DELETE CASCADE,
  INDEX idx_customer (customer_id),
  INDEX idx_status (status),
  INDEX idx_date (invoice_date),
  INDEX idx_invoice_number (invoice_number)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE invoice_items (
  id INT AUTO_INCREMENT PRIMARY KEY,
  invoice_id INT NOT NULL,
  description VARCHAR(255) NOT NULL,
  quantity DECIMAL(10,2) NOT NULL DEFAULT 1,
  unit_price DECIMAL(10,2) NOT NULL DEFAULT 0.00,
  discount_percent DECIMAL(5,2) DEFAULT 0.00,
  discount_amount DECIMAL(10,2) DEFAULT 0.00,
  line_total DECIMAL(10,2) NOT NULL DEFAULT 0.00,
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  FOREIGN KEY (invoice_id) REFERENCES invoices(id) ON DELETE CASCADE,
  INDEX idx_invoice (invoice_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE users (
  id INT AUTO_INCREMENT PRIMARY KEY,
  email VARCHAR(255) NOT NULL UNIQUE,
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE otp_codes (
  id INT AUTO_INCREMENT PRIMARY KEY,
  email VARCHAR(255) NOT NULL,
  code VARCHAR(10) NOT NULL,
  expires_at DATETIME NOT NULL,
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  INDEX idx_email (email),
  INDEX idx_expires_at (expires_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

2. Configure Database

Edit config/db.php:

<?php
$host = "localhost";
$db   = "invoice_app";
$user = "root";
$pass = "";
$charset = "utf8mb4";

$dsn = "mysql:host=$host;dbname=$db;charset=$charset";
$options = [
    PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
    PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
];

$pdo = new PDO($dsn, $user, $pass, $options);

4. Run the Application

Using PHP's built-in server:

php -S localhost:8000

Then open http://localhost:8000/login.html in your browser to login.

Use test credentials:

  • Email: test@invoyce.com
  • OTP: 123456

πŸ” OTP Login Setup

The application uses OTP (One-Time Password) authentication. Users login with their email and receive a code.

Test on Localhost

  1. Open http://localhost:8000/login.html
  2. Enter test@invoyce.com
  3. Click "Request OTP"
  4. A debug message shows the code: 123456
  5. Enter the code and click "Verify OTP"
  6. You'll be logged in and redirected to the dashboard

Test on Deployed Server (cPanel, etc.)

  1. Open login.html on your domain
  2. Enter test@invoyce.com
  3. Click "Request OTP"
  4. Check your email for the OTP code (uses server's mail() function)
  5. Enter the code and verify
  6. Access your dashboard

Production Use (Real Users)

TODO

πŸ“ Project Structure

invoyce/
β”œβ”€β”€ login.html              # OTP Login page
β”œβ”€β”€ index.html              # Dashboard - List all invoices (protected)
β”œβ”€β”€ create_invoice.html     # Create new invoice (protected)
β”œβ”€β”€ view_invoice.html       # View invoice details (protected)
β”œβ”€β”€ edit_invoice.html       # Edit existing invoice (protected)
β”œβ”€β”€ config/
β”‚   └── db.php             # Database configuration
β”œβ”€β”€ api/
β”‚   β”œβ”€β”€ auth.php           # OTP authentication (request & verify)
β”‚   β”œβ”€β”€ invoices.php       # Main invoice API (create, read, update, delete)
β”‚   β”œβ”€β”€ customers.php      # Customer management
β”‚   β”œβ”€β”€ invoices_list.php  # List all invoices
β”‚   β”œβ”€β”€ delete_invoice.php # Delete invoice endpoint
β”‚   β”œβ”€β”€ export_pdf.php     # PDF export
β”‚   └── share_invoice.php  # Public invoice view
β”œβ”€β”€ assets/
β”‚   β”œβ”€β”€ styles.css         # Main stylesheet (responsive, modern design)
β”‚   └── app.js             # Frontend logic (auth guard, invoice forms)
β”œβ”€β”€ sql/
β”‚   β”œβ”€β”€ add_invoice_number.sql  # Add invoice_number column migration
β”‚   └── add_auth_tables.sql     # Create users & otp_codes tables
β”œβ”€β”€ tools/
β”‚   β”œβ”€β”€ extract_pdf.py     # PDF extraction tool (internal)
β”‚   └── extract_images.py  # Image extraction tool (internal)
└── README.md              # This file - setup & usage guide

🎯 Usage

1. Login

  1. Go to /login.html
  2. Enter email (use test@invoyce.com for testing)
  3. Click "Request OTP"
  4. Check email (or see debug code on localhost)
  5. Enter OTP code and verify
  6. You're logged in and redirected to dashboard

2. Creating an Invoice

  1. Click "Create Invoice" on dashboard or nav
  2. Select or add a customer
  3. Set invoice and due dates
  4. Add line items with descriptions, quantities, and prices
  5. Set item-level or invoice-level discounts
  6. Review totals (auto-calculated with 15% VAT)
  7. Save invoice

3. Editing an Invoice

  1. Go to dashboard and click "Edit" on any invoice
  2. Modify customer, dates, items, or discounts
  3. Totals update automatically
  4. Save changes

4. Viewing an Invoice

  1. Click "View" on the dashboard
  2. See full details, customer info, and line items
  3. Options to edit, delete, export PDF, or generate share link

5. Sharing an Invoice

  1. Open invoice and click "Get Share Link"
  2. Share the URL with customer
  3. Customer can view invoice without login (public link)

6. Logout

  1. Click your email in the top-right nav
  2. Click "Logout"
  3. You're logged out and redirected to login page

πŸ”§ API Endpoints

Method Endpoint Action
POST /api/invoices.php?action=create_invoice Create invoice
GET /api/invoices.php?action=get_invoice&id=1 Get invoice details
POST /api/invoices.php?action=update_invoice Update invoice
POST /api/invoices.php?action=delete_invoice Delete invoice
GET /api/invoices_list.php List all invoices
GET/POST /api/customers.php Get/create customers

πŸ“± Mobile Features

βœ… Fully responsive design for all devices βœ… Touch-friendly buttons and inputs βœ… Optimized form layouts for mobile βœ… Hidden columns on small screens βœ… 16px font size (prevents iOS zoom) βœ… 48px minimum button height

πŸ› Troubleshooting

Login Issues

"OTP sent to email" but I don't receive it

  • βœ“ On localhost: code is shown in debug alert (not emailed)
  • βœ“ On production: ensure mail() is configured on your server
  • βœ“ Check email spam folder
  • βœ“ Verify cPanel mail settings if hosted

Test credentials not working

  • βœ“ Ensure sql/add_auth_tables.sql has been run
  • βœ“ Try email: test@invoyce.com and OTP: 123456
  • βœ“ Reload the page if it seems stuck

Database Connection Error

  • βœ“ Check config/db.php credentials match your MySQL setup
  • βœ“ Verify MySQL is running (mysql -u root should connect)
  • βœ“ Confirm database exists: mysql -u root -e "SHOW DATABASES"
  • βœ“ Ensure all migrations have been run

Missing Tables

Run all migrations:

mysql -u root invoice_app < sql/add_invoice_number.sql
mysql -u root invoice_app < sql/add_auth_tables.sql

Page Redirects to Login

  • βœ“ You must login first (OTP required)
  • βœ“ All pages except login.html require authentication
  • βœ“ Clear browser storage: localStorage.removeItem('invoyce_user')

Page Not Found (404)

  • βœ“ Ensure all files are in correct directories
  • βœ“ Check web server is serving the app root
  • βœ“ Verify file permissions (644 for files, 755 for folders)

Buttons Not Working

  • βœ“ Check browser console for JavaScript errors (F12 β†’ Console)
  • βœ“ Ensure assets/app.js is loading
  • βœ“ Clear browser cache (Ctrl+Shift+Delete)
  • βœ“ Try incognito/private browsing mode

βš™οΈ Configuration

Changing Tax Rate

Edit assets/app.js, find the recalc() function:

const tax = subtotal * 0.15;  // Change 0.15 to desired rate (e.g., 0.10 for 10%)

Changing Currency Symbol

Edit currency symbol in:

  • assets/app.js (search for R in display functions)
  • view_invoice.html (search for R in totals display)

Replace R with your currency (e.g., $, €, Β£, Β₯)

Changing Email For OTP Sender

Edit api/auth.php, find the email sending section:

$headers = "From: admin@dreyerventures\r\n" .
           "Reply-To: admin@dreyerventures\r\n";

Replace with your email address.

Customizing OTP Expiry Time

Edit api/auth.php, find OTP generation:

$expiresAt = (new DateTime('+10 minutes'))->format('Y-m-d H:i:s');
// Change '+10 minutes' to desired timeframe

πŸ” Security Notes

⚠️ Important: Production deployment checklist:

Authentication & Access

  • βœ… OTP login system implemented
  • βœ… Session storage via localStorage (can be improved to server sessions)
  • βœ“ Add authorization checks (users can only see their own invoices)
  • βœ“ Implement server-side session validation

Network & Transport

  • βœ“ Use HTTPS (SSL certificate required)
  • βœ“ Update domain in api/auth.php for email sender
  • βœ“ Configure proper mail() or SMTP for email delivery
  • βœ“ Add CORS headers if API is accessed from different domain

Data & Validation

  • βœ… All inputs are validated and sanitized
  • βœ… PDO prepared statements prevent SQL injection
  • βœ“ Add rate limiting on OTP requests (prevent brute force)
  • βœ“ Add audit logging for invoice changes
  • βœ“ Implement IP-based rate limiting

Environment

  • βœ“ Set display_errors = Off in production php.ini
  • βœ“ Store database credentials securely (not in repo)
  • βœ“ Use environment variables for sensitive config
  • βœ“ Keep PHP and MySQL updated
  • βœ“ Regular database backups

πŸ“„ License

MIT License - Free to use and modify for personal or commercial projects.

πŸ’‘ Future Enhancements

  • Payment gateway integration (Stripe, PayPal)
  • Email invoice delivery to customers
  • Recurring/subscription invoices
  • Invoice templates (different styles/layouts)
  • Analytics and financial reports
  • Multi-currency support
  • Advanced search and filtering
  • Invoice reminders (automatic emails)
  • Multi-user teams (shared access)
  • Two-factor authentication (2FA)
  • Webhook support for integrations
  • Mobile app (iOS/Android)

About

a invoice web app

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors