Overview
The Invoices module provides comprehensive billing and payment management. Track invoice statuses, monitor due dates, and manage payment collections with integrated client and sales data.Payment Tracking
Monitor invoice statuses: Paid, Pending, and Overdue
Due Date Management
Automatic tracking of emission and due dates
Client Integration
Link invoices to client records and sales transactions
Financial Reports
Monthly revenue tracking and payment analytics
Factura Model
TheFactura model manages all invoice operations:
app/Models/Factura.php
Model Relationships
- Cliente Relationship
- Venta Relationship
Each invoice belongs to a client (Usage Example:
belongsTo):Date Casting
The model automatically casts date fields to Carbon instances:Database Schema
Thefacturas table structure from the migration:
database/migrations/2026_03_03_191710_create_facturas_table.php
Table Fields
| Field | Type | Constraints | Description |
|---|---|---|---|
id | bigint | Primary key | Unique invoice identifier |
numero_factura | string | Unique | Invoice number (e.g., FAC-2024-001) |
cliente_id | foreignId | Required | Reference to clients table |
venta_id | foreignId | Nullable | Optional reference to sales table |
concepto | string | Required | Invoice description/concept |
monto | decimal(10,2) | Required | Invoice amount |
fecha_emision | date | Required | Emission/issue date |
fecha_vencimiento | date | Required | Due date |
estado | enum | Default: ‘pendiente’ | Payment status |
timestamps | timestamps | Auto | created_at, updated_at |
Foreign Key Constraints
Cascade Deletion: When a client is deleted, all their invoices are automatically removed.Set Null: When a sale is deleted, the
venta_id in related invoices is set to null, preserving the invoice record.Payment Statuses
- Pagada
- Pendiente
- Vencida
Paid InvoicesInvoices that have been fully paid by the client.Dashboard Metrics:
- Count: 186 invoices
- Total: $42,300
Invoice View Features
The invoice interface (facturas.blade.php) provides:
Dashboard Cards
Paid
186 invoices
$42,300 total
Pending
34 invoices
$8,900 pending
Overdue
12 invoices
$3,200 in arrears
Total Issued
232 invoices
This month
Analytics Charts
Monthly Revenue Chart
Stacked bar chart showing paid vs pending amounts by month
- Green bars: Paid invoices
- Yellow bars: Pending invoices
Invoice Status Chart
Doughnut chart displaying status distribution:
- Paid: 186 (80%)
- Pending: 34 (15%)
- Overdue: 12 (5%)
Invoice Management Table
The main invoice table displays:- Invoice number (FAC-2024-XXX)
- Client name
- Invoice concept/description
- Amount (formatted currency)
- Emission date
- Due date
- Status badge (color-coded)
- Action buttons (View, Download PDF)
The interface includes search functionality and status filtering for efficient invoice management.
Usage Examples
Creating a New Invoice
Querying Invoices with Related Data
Marking Invoice as Paid
Finding Overdue Invoices
Client Invoice Summary
Monthly Revenue Report
Invoices Due This Week
Key Features
Unique Invoice Numbers
Each invoice has a unique identifier (FAC-2024-XXX)
Client Integration
Direct relationship with client records
Optional Sales Link
Nullable foreign key to sales table
Decimal Precision
Amounts stored with 2 decimal precision
Date Casting
Automatic Carbon instance conversion for dates
Three Payment States
Paid, Pending, and Overdue status tracking
Cascade Deletion
Auto-delete when client is removed
Set Null on Sale Delete
Preserve invoice when sale is deleted
Timestamp Tracking
Automatic created_at and updated_at timestamps
Best Practices
Automatic Status Updates: Consider implementing a scheduled task to automatically update pending invoices to ‘vencida’ when they pass their due date.Payment Reminders: Send automated reminders to clients with pending invoices approaching their due date.PDF Generation: Integrate PDF generation for downloadable invoice documents.
