Update: 2026-05-04 02:12:25
This commit is contained in:
@@ -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("
|
||||
|
||||
Reference in New Issue
Block a user