Update: 2026-05-04 02:10:24
This commit is contained in:
@@ -110,19 +110,27 @@ if (move_uploaded_file($_FILES['invoice']['tmp_name'], $targetFile)) {
|
|||||||
|
|
||||||
$invoiceId = $db->lastInsertId();
|
$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'])) {
|
if (!empty($extracted['items'])) {
|
||||||
$lineStmt = $db->prepare("
|
$lineStmt = $db->prepare("
|
||||||
INSERT INTO invoice_lines (invoice_id, description, quantity, unit_price, tax_amount, total)
|
INSERT INTO invoice_lines (invoice_id, line_number, description, quantity, unit_price, tax_rate, line_total)
|
||||||
VALUES (?, ?, ?, ?, ?, ?)
|
VALUES (?, ?, ?, ?, ?, ?, ?)
|
||||||
");
|
");
|
||||||
|
$lineNo = 1;
|
||||||
foreach ($extracted['items'] as $item) {
|
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([
|
$lineStmt->execute([
|
||||||
$invoiceId,
|
$invoiceId,
|
||||||
|
$lineNo++,
|
||||||
$item['description'] ?? 'N/A',
|
$item['description'] ?? 'N/A',
|
||||||
$item['quantity'] ?? 1,
|
$item['quantity'] ?? 1,
|
||||||
$item['unit_price'] ?? 0,
|
$item['unit_price'] ?? 0,
|
||||||
$item['tax_amount'] ?? 0,
|
$taxRate,
|
||||||
$item['total'] ?? 0
|
$item['total'] ?? 0
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,12 +95,12 @@ CREATE TABLE invoices (
|
|||||||
invoice_type ENUM('cash','credit') DEFAULT 'cash',
|
invoice_type ENUM('cash','credit') DEFAULT 'cash',
|
||||||
ubl_type_code CHAR(3) DEFAULT '388',
|
ubl_type_code CHAR(3) DEFAULT '388',
|
||||||
payment_method_code CHAR(3) DEFAULT '013',
|
payment_method_code CHAR(3) DEFAULT '013',
|
||||||
supplier_tin VARCHAR(20) NULL,
|
supplier_tin TEXT NULL,
|
||||||
supplier_name VARCHAR(255) NULL,
|
supplier_name TEXT NULL,
|
||||||
supplier_address TEXT NULL,
|
supplier_address TEXT NULL,
|
||||||
buyer_tin VARCHAR(20) NULL,
|
buyer_tin TEXT NULL,
|
||||||
buyer_national_id VARCHAR(20) NULL,
|
buyer_national_id TEXT NULL,
|
||||||
buyer_name VARCHAR(255) NULL,
|
buyer_name TEXT NULL,
|
||||||
subtotal DECIMAL(15,3) DEFAULT 0,
|
subtotal DECIMAL(15,3) DEFAULT 0,
|
||||||
discount_total DECIMAL(15,3) DEFAULT 0,
|
discount_total DECIMAL(15,3) DEFAULT 0,
|
||||||
tax_amount DECIMAL(15,3) DEFAULT 0,
|
tax_amount DECIMAL(15,3) DEFAULT 0,
|
||||||
|
|||||||
Reference in New Issue
Block a user