Update: 2026-05-08 15:18:01
This commit is contained in:
@@ -155,16 +155,18 @@ class InvoiceProcessor
|
||||
// Check if entire batch is complete
|
||||
self::checkBatchCompletion($batchId);
|
||||
|
||||
// Send push notification (non-critical, don't fail on error)
|
||||
// Progress/Completion Push
|
||||
try {
|
||||
$stmt = $db->prepare("SELECT total_images, processed_images, uploaded_by FROM invoice_batches WHERE id = ?");
|
||||
$stmt->execute([$batchId]);
|
||||
$currentBatch = $stmt->fetch();
|
||||
if ($currentBatch) {
|
||||
$notifier = new NotificationService();
|
||||
// Send data notification with invoice_id for auto-navigation
|
||||
$notifier->sendDataNotification($currentBatch['uploaded_by'], [
|
||||
'type' => 'batch_progress',
|
||||
'type' => 'invoice_processed',
|
||||
'batch_id' => $batchId,
|
||||
'invoice_id' => $invoiceId,
|
||||
'processed' => $currentBatch['processed_images'],
|
||||
'total' => $currentBatch['total_images']
|
||||
]);
|
||||
@@ -194,12 +196,21 @@ class InvoiceProcessor
|
||||
self::log("Batch $batchId: COMPLETE ({$batch['processed_images']}/{$batch['total_images']})");
|
||||
|
||||
try {
|
||||
// Try to get the last invoice_id for this batch for completion navigation
|
||||
$invStmt = $db->prepare("SELECT id FROM invoices WHERE original_file_path IN (SELECT image_path FROM invoice_processing_queue WHERE batch_id = ?) ORDER BY created_at DESC LIMIT 1");
|
||||
$invStmt->execute([$batchId]);
|
||||
$lastInvoiceId = $invStmt->fetchColumn();
|
||||
|
||||
$notifier = new NotificationService();
|
||||
$notifier->sendNotification(
|
||||
$batch['uploaded_by'],
|
||||
"اكتملت معالجة الدفعة",
|
||||
"تمت معالجة جميع الفواتير بنجاح. يمكنك الآن مراجعتها وتدقيقها في لوحة التحكم قبل اعتمادها.",
|
||||
['batch_id' => $batchId]
|
||||
"تمت معالجة جميع الفواتير بنجاح. يمكنك الآن مراجعتها وتدقيقها.",
|
||||
[
|
||||
'type' => 'batch_complete',
|
||||
'batch_id' => $batchId,
|
||||
'invoice_id' => $lastInvoiceId ?: ''
|
||||
]
|
||||
);
|
||||
} catch (\Throwable $e) {
|
||||
self::log("Batch $batchId: Completion notification failed: " . $e->getMessage());
|
||||
|
||||
@@ -17,8 +17,15 @@ class NotificationService
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->projectId = env('FIREBASE_PROJECT_ID', '');
|
||||
$this->serviceAccountPath = env('FIREBASE_SERVICE_ACCOUNT_PATH', APP_PATH . '/config/firebase-service-account.json');
|
||||
|
||||
// Auto-detect Project ID from Service Account JSON to prevent RESOURCE_PROJECT_INVALID
|
||||
if (file_exists($this->serviceAccountPath)) {
|
||||
$sa = json_decode(file_get_contents($this->serviceAccountPath), true);
|
||||
$this->projectId = $sa['project_id'] ?? env('FIREBASE_PROJECT_ID', '');
|
||||
} else {
|
||||
$this->projectId = env('FIREBASE_PROJECT_ID', '');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user