prepare(" SELECT id, tenant_id, status, total_images, processed_images, failed_images, created_at, completed_at FROM invoice_batches WHERE id = ? "); $stmt->execute([$batchId]); $batch = $stmt->fetch(); if (!$batch || ($decoded['role'] !== 'super_admin' && $batch['tenant_id'] !== $tenantId)) { json_error('الدفعة غير موجودة', 404); } // 2. Get items $stmt = $db->prepare(" SELECT id, invoice_id, image_order, status, error_message, created_at, processed_at FROM invoice_processing_queue WHERE batch_id = ? ORDER BY image_order ASC "); $stmt->execute([$batchId]); $items = $stmt->fetchAll(); json_success([ 'batch' => $batch, 'items' => $items ], 'تم جلب حالة الدفعة');