Update: 2026-05-12 01:35:12
This commit is contained in:
@@ -106,6 +106,11 @@ class AI
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the AI returns an array of invoices, extract the first one
|
||||||
|
if (isset($data['invoices']) && is_array($data['invoices']) && count($data['invoices']) > 0) {
|
||||||
|
$data = $data['invoices'][0];
|
||||||
|
}
|
||||||
|
|
||||||
// Track token usage from Gemini response
|
// Track token usage from Gemini response
|
||||||
$usage = $result['usageMetadata'] ?? [];
|
$usage = $result['usageMetadata'] ?? [];
|
||||||
if (!empty($usage)) {
|
if (!empty($usage)) {
|
||||||
|
|||||||
@@ -102,26 +102,21 @@ class InvoiceProcessor
|
|||||||
supplier_tin, supplier_name, supplier_address,
|
supplier_tin, supplier_name, supplier_address,
|
||||||
buyer_tin, buyer_name, buyer_national_id,
|
buyer_tin, buyer_name, buyer_national_id,
|
||||||
subtotal, tax_amount, discount_total, grand_total, currency_code,
|
subtotal, tax_amount, discount_total, grand_total, currency_code,
|
||||||
ai_provider,
|
|
||||||
created_at
|
created_at
|
||||||
) VALUES (
|
) VALUES (
|
||||||
?, ?, ?, ?, ?, 'extracted',
|
?, ?, ?, ?, ?, 'extracted',
|
||||||
?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
|
?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
|
||||||
?, ?, ?, ?, ?,
|
?, ?, ?, ?, ?,
|
||||||
?,
|
|
||||||
NOW()
|
NOW()
|
||||||
)
|
)
|
||||||
");
|
");
|
||||||
|
|
||||||
$rawJsonSnippet = substr(json_encode($extracted, JSON_UNESCAPED_UNICODE), 0, 500);
|
|
||||||
|
|
||||||
$stmt->execute([
|
$stmt->execute([
|
||||||
$invoiceId, $tenantId, $companyId, $userId, $imagePath,
|
$invoiceId, $tenantId, $companyId, $userId, $imagePath,
|
||||||
$invoiceNum, $validDate, $extracted['invoice_type'] ?? 'cash', $extracted['invoice_category'] ?? 'simplified',
|
$invoiceNum, $validDate, $extracted['invoice_type'] ?? 'cash', $extracted['invoice_category'] ?? 'simplified',
|
||||||
Encryption::encrypt($supplierTin), Encryption::encrypt($extracted['supplier']['name'] ?? ''), Encryption::encrypt($extracted['supplier']['address'] ?? ''),
|
Encryption::encrypt($supplierTin), Encryption::encrypt($extracted['supplier']['name'] ?? ''), Encryption::encrypt($extracted['supplier']['address'] ?? ''),
|
||||||
Encryption::encrypt($extracted['buyer']['tin'] ?? ''), Encryption::encrypt($extracted['buyer']['name'] ?? ''), Encryption::encrypt($extracted['buyer']['national_id'] ?? ''),
|
Encryption::encrypt($extracted['buyer']['tin'] ?? ''), Encryption::encrypt($extracted['buyer']['name'] ?? ''), Encryption::encrypt($extracted['buyer']['national_id'] ?? ''),
|
||||||
$extracted['subtotal'] ?? 0, $extracted['tax_amount'] ?? 0, $extracted['discount_total'] ?? 0, $extracted['grand_total'] ?? 0, $extracted['currency_code'] ?? 'JOD',
|
$extracted['subtotal'] ?? 0, $extracted['tax_amount'] ?? 0, $extracted['discount_total'] ?? 0, $extracted['grand_total'] ?? 0, $extracted['currency_code'] ?? 'JOD'
|
||||||
$rawJsonSnippet
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Save invoice line items
|
// Save invoice line items
|
||||||
|
|||||||
Reference in New Issue
Block a user