From 303205d52db62f1c7135a87d759c752e98b6e4fc Mon Sep 17 00:00:00 2001 From: Hamza-Ayed Date: Mon, 4 May 2026 02:12:25 +0300 Subject: [PATCH] Update: 2026-05-04 02:12:25 --- app/modules_app/invoices/upload.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/app/modules_app/invoices/upload.php b/app/modules_app/invoices/upload.php index 7f557ec..065580e 100644 --- a/app/modules_app/invoices/upload.php +++ b/app/modules_app/invoices/upload.php @@ -77,18 +77,25 @@ if (move_uploaded_file($_FILES['invoice']['tmp_name'], $targetFile)) { try { $db->beginTransaction(); + $invoiceId = bin2hex(random_bytes(16)); // Generate UUID (simple version for now or use a lib) + // Let's use a standard UUID format if possible, but MySQL CHAR(36) accepts anything. + // Actually, let's just use the DB's UUID() function but FETCH it back or generate it here. + // I'll use a better UUID generator logic. + $invoiceId = vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex(random_bytes(16)), 4)); + $stmt = $db->prepare(" INSERT INTO invoices ( - tenant_id, company_id, uploaded_by, original_file_path, status, + id, tenant_id, company_id, uploaded_by, original_file_path, status, invoice_number, invoice_date, invoice_type, invoice_category, supplier_tin, supplier_name, supplier_address, buyer_tin, buyer_name, buyer_national_id, subtotal, tax_amount, discount_total, grand_total, currency_code, created_at - ) VALUES (?, ?, ?, ?, 'extracted', ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, NOW()) + ) VALUES (?, ?, ?, ?, ?, ?, 'extracted', ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, NOW()) "); $stmt->execute([ + $invoiceId, $tenantId, $companyId, $userId, $targetFile, $extracted['invoice_number'] ?? null, $extracted['invoice_date'] ?? null, @@ -108,8 +115,6 @@ if (move_uploaded_file($_FILES['invoice']['tmp_name'], $targetFile)) { $extracted['currency'] ?? 'JOD' ]); - $invoiceId = $db->lastInsertId(); - // Save Line Items if (!empty($extracted['items'])) { $lineStmt = $db->prepare("