🚀 مُصادَق: تحديث برمجي جديد 2026-05-03 13:19
This commit is contained in:
@@ -72,38 +72,18 @@ final class InvoiceController
|
||||
'idempotency_key' => bin2hex(random_bytes(16))
|
||||
]);
|
||||
|
||||
// Attempt AI Extraction
|
||||
try {
|
||||
$mimeType = mime_content_type($filePath);
|
||||
$extractedData = $this->aiExtraction->extractInvoiceData($filePath, $mimeType);
|
||||
|
||||
// Update Invoice with extracted data
|
||||
$this->invoiceModel->update($invoiceId, [
|
||||
'status' => 'extracted', // Match schema ENUM
|
||||
'ai_raw_response' => json_encode($extractedData, JSON_UNESCAPED_UNICODE)
|
||||
]);
|
||||
// Push to Queue for AI Extraction
|
||||
\App\Services\QueueService::push('invoice_extraction', [
|
||||
'invoice_id' => $invoiceId,
|
||||
'file_path' => $filePath,
|
||||
'mime_type' => mime_content_type($filePath)
|
||||
]);
|
||||
|
||||
Response::json([
|
||||
'success' => true,
|
||||
'data' => [
|
||||
'invoice_id' => $invoiceId,
|
||||
'extracted_data' => $extractedData
|
||||
],
|
||||
'message' => 'تم رفع الفاتورة واستخراج البيانات بنجاح بالذكاء الاصطناعي'
|
||||
]);
|
||||
|
||||
} catch (Throwable $aiError) {
|
||||
// Keep it uploaded, maybe manual retry later
|
||||
$this->invoiceModel->update($invoiceId, [
|
||||
'status' => 'validation_failed' // Match schema fallback
|
||||
]);
|
||||
|
||||
Response::json([
|
||||
'success' => true,
|
||||
'data' => ['invoice_id' => $invoiceId],
|
||||
'message' => 'تم الرفع ولكن فشل استخراج البيانات. ' . $aiError->getMessage()
|
||||
]);
|
||||
}
|
||||
Response::json([
|
||||
'success' => true,
|
||||
'data' => ['invoice_id' => $invoiceId],
|
||||
'message' => 'تم رفع الفاتورة بنجاح وجاري استخراج البيانات بالذكاء الاصطناعي'
|
||||
], 202);
|
||||
|
||||
} catch (Throwable $e) {
|
||||
Response::error($e->getMessage(), 'UPLOAD_FAILED', 500);
|
||||
|
||||
Reference in New Issue
Block a user