🚀 مُصادَق: تحديث برمجي جديد 2026-05-03 13:19
This commit is contained in:
48
queue/Jobs/ExtractInvoiceJob.php
Normal file
48
queue/Jobs/ExtractInvoiceJob.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Queue\Jobs;
|
||||
|
||||
use App\Modules\Invoices\InvoiceModel;
|
||||
use App\Services\AiExtractionService;
|
||||
use Throwable;
|
||||
|
||||
final class ExtractInvoiceJob
|
||||
{
|
||||
public function __construct(
|
||||
private readonly InvoiceModel $invoiceModel,
|
||||
private readonly AiExtractionService $aiExtraction
|
||||
) {}
|
||||
|
||||
public function handle(array $payload): void
|
||||
{
|
||||
$invoiceId = $payload['invoice_id'];
|
||||
$filePath = $payload['file_path'];
|
||||
$mimeType = $payload['mime_type'];
|
||||
|
||||
// Update status to extracting
|
||||
$this->invoiceModel->update($invoiceId, ['status' => 'extracting']);
|
||||
|
||||
try {
|
||||
$extractedData = $this->aiExtraction->extractInvoiceData($filePath, $mimeType);
|
||||
|
||||
// Map AI data to schema columns if needed, or just store in ai_raw_response
|
||||
$this->invoiceModel->update($invoiceId, [
|
||||
'status' => 'extracted',
|
||||
'invoice_number' => $extractedData['invoice_number'] ?? null,
|
||||
'invoice_date' => $extractedData['invoice_date'] ?? null,
|
||||
'grand_total' => $extractedData['total_amount'] ?? 0,
|
||||
'tax_amount' => $extractedData['tax_amount'] ?? 0,
|
||||
'supplier_name' => $extractedData['vendor_name'] ?? null,
|
||||
'supplier_tin' => $extractedData['vendor_tax_number'] ?? null,
|
||||
'ai_raw_response' => json_encode($extractedData, JSON_UNESCAPED_UNICODE)
|
||||
]);
|
||||
} catch (Throwable $e) {
|
||||
$this->invoiceModel->update($invoiceId, [
|
||||
'status' => 'validation_failed'
|
||||
]);
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user