Update: 2026-05-04 02:10:24

This commit is contained in:
Hamza-Ayed
2026-05-04 02:10:24 +03:00
parent ea1d78cb85
commit b21951e4c8
2 changed files with 17 additions and 9 deletions

View File

@@ -110,19 +110,27 @@ if (move_uploaded_file($_FILES['invoice']['tmp_name'], $targetFile)) {
$invoiceId = $db->lastInsertId();
// Save Line Items (No encryption for lines for now, usually not sensitive but can be)
// Save Line Items
if (!empty($extracted['items'])) {
$lineStmt = $db->prepare("
INSERT INTO invoice_lines (invoice_id, description, quantity, unit_price, tax_amount, total)
VALUES (?, ?, ?, ?, ?, ?)
INSERT INTO invoice_lines (invoice_id, line_number, description, quantity, unit_price, tax_rate, line_total)
VALUES (?, ?, ?, ?, ?, ?, ?)
");
$lineNo = 1;
foreach ($extracted['items'] as $item) {
// Calculate tax rate if not provided (fallback to 0.16 for Jordan)
$taxRate = 0.16;
if (!empty($item['unit_price']) && !empty($item['tax_amount'])) {
$taxRate = round($item['tax_amount'] / ($item['unit_price'] * ($item['quantity'] ?: 1)), 4);
}
$lineStmt->execute([
$invoiceId,
$lineNo++,
$item['description'] ?? 'N/A',
$item['quantity'] ?? 1,
$item['unit_price'] ?? 0,
$item['tax_amount'] ?? 0,
$taxRate,
$item['total'] ?? 0
]);
}

View File

@@ -95,12 +95,12 @@ CREATE TABLE invoices (
invoice_type ENUM('cash','credit') DEFAULT 'cash',
ubl_type_code CHAR(3) DEFAULT '388',
payment_method_code CHAR(3) DEFAULT '013',
supplier_tin VARCHAR(20) NULL,
supplier_name VARCHAR(255) NULL,
supplier_tin TEXT NULL,
supplier_name TEXT NULL,
supplier_address TEXT NULL,
buyer_tin VARCHAR(20) NULL,
buyer_national_id VARCHAR(20) NULL,
buyer_name VARCHAR(255) NULL,
buyer_tin TEXT NULL,
buyer_national_id TEXT NULL,
buyer_name TEXT NULL,
subtotal DECIMAL(15,3) DEFAULT 0,
discount_total DECIMAL(15,3) DEFAULT 0,
tax_amount DECIMAL(15,3) DEFAULT 0,