Update: 2026-05-15 04:35:25
This commit is contained in:
@@ -121,11 +121,34 @@ class InvoiceProcessor
|
||||
|
||||
// Save invoice line items
|
||||
if (!empty($extracted['lines'])) {
|
||||
$lineStmt = $db->prepare("INSERT INTO invoice_lines (id, invoice_id, line_number, description, quantity, unit_price, tax_rate, line_total) VALUES (?,?,?,?,?,?,?,?)");
|
||||
$lineStmt = $db->prepare("
|
||||
INSERT INTO invoice_lines (
|
||||
id, invoice_id, line_number, description,
|
||||
quantity, unit_price, tax_rate, tax_amount,
|
||||
discount_amount, net_total, tax_category
|
||||
) VALUES (?,?,?,?,?,?,?,?,?,?,?)
|
||||
");
|
||||
foreach ($extracted['lines'] as $idx => $line) {
|
||||
$quantity = (float)($line['quantity'] ?? 1);
|
||||
$unitPrice = (float)($line['unit_price'] ?? 0);
|
||||
$taxRate = (float)($line['tax_rate'] ?? 0);
|
||||
$discount = (float)($line['discount'] ?? $line['discount_amount'] ?? 0);
|
||||
$subtotal = $quantity * $unitPrice;
|
||||
$taxAmount = (float)($line['tax_amount'] ?? ($subtotal * $taxRate));
|
||||
$netTotal = (float)($line['net_total'] ?? ($line['line_total'] ?? ($subtotal + $taxAmount - $discount)));
|
||||
|
||||
$lineStmt->execute([
|
||||
vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex(random_bytes(16)), 4)),
|
||||
$invoiceId, $line['line_number'] ?? ($idx + 1), $line['description'] ?? '', $line['quantity'] ?? 1, $line['unit_price'] ?? 0, $line['tax_rate'] ?? 0, $line['line_total'] ?? $line['total_amount'] ?? 0
|
||||
$invoiceId,
|
||||
$line['line_number'] ?? ($idx + 1),
|
||||
$line['description'] ?? '',
|
||||
$quantity,
|
||||
$unitPrice,
|
||||
$taxRate,
|
||||
$taxAmount,
|
||||
$discount,
|
||||
$netTotal,
|
||||
$line['tax_category'] ?? 'standard'
|
||||
]);
|
||||
}
|
||||
self::log("Queue ID $queueId: Saved " . count($extracted['lines']) . " line items.");
|
||||
|
||||
Reference in New Issue
Block a user