diff --git a/customers/.hta_slug/generate-invoice.php b/customers/.hta_slug/generate-invoice.php index ad93e76..0410024 100644 --- a/customers/.hta_slug/generate-invoice.php +++ b/customers/.hta_slug/generate-invoice.php @@ -105,7 +105,11 @@ $stmt = $db->query("SELECT id FROM invoice WHERE DATE(invoiceDate) = CURDATE() ORDER BY id DESC LIMIT 1"); $lastInvoice = $stmt->fetch(PDO::FETCH_ASSOC); - $invoiceId = "CB" . date('my') . ($lastInvoice ? ($lastInvoice['id'] + 1) : '1'); + + $nextId = $lastInvoice ? ($lastInvoice['id'] + 1) : 1; + + // Ensure the ID is always three digits (e.g., 001, 010, 100) + $invoiceId = "CB" . date('my') . str_pad($nextId, 3, '0', STR_PAD_LEFT); $stmt = $db->query("SELECT invoiceId FROM invoice ORDER BY id DESC LIMIT 1"); $lastInvoicePrint = $stmt->fetch(PDO::FETCH_ASSOC);