Update: 2026-05-15 04:35:25
This commit is contained in:
@@ -113,7 +113,7 @@ class InvoiceExtractionService
|
||||
1. ابحث أولاً في قوائم الإعفاء والصفر والنسب المخفضة. المواد الغذائية الأساسية في السوبرماركت (ألبان، أجبان، حليب، خبز) غالباً معفاة (0% أو 4%). لا تفرض 16% إلا على الكماليات (منظفات، حلويات، عصائر مصنعة، الخ).
|
||||
2. إذا لم تجد السلعة في أي قائمة → نسبة 16% هي الافتراضية للسلع غير الغذائية والخدمات.
|
||||
3. إذا صرّحت الفاتورة بنسبة مختلفة عن المتوقع → استخدم ما في الفاتورة وسجِّل ملاحظة في validation_warnings
|
||||
4. tax_category: استخدم "S" للخاضعة (16% أو مخفضة)، "Z" للصفري، "E" للمعفاة، "O" للخاصة
|
||||
4. tax_category: استخدم "standard" للخاضعة (16% أو مخفضة)، "zero_rated" للصفري، "exempt" للمعفاة، "special" للخاصة
|
||||
|
||||
════════════════════════════════════════
|
||||
## تصنيف طريقة الدفع:
|
||||
@@ -152,7 +152,7 @@ class InvoiceExtractionService
|
||||
"unit_price": 0.000,
|
||||
"discount": 0.000,
|
||||
"tax_rate": 0.16,
|
||||
"tax_category": "S | Z | E | O",
|
||||
"tax_category": "standard | zero_rated | exempt | special",
|
||||
"tax_exempt_reason": "string | null",
|
||||
"line_total": 0.000
|
||||
}
|
||||
|
||||
@@ -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