import React, { useState } from 'react'; import { Head } from '@inertiajs/react'; import EmployerLayout from '../../Layouts/EmployerLayout'; import { useTranslation } from '../../lib/LanguageContext'; import { CreditCard, CheckCircle2, Search, FileText, Download, Printer, Copy, FileSpreadsheet, ArrowUpRight, TrendingUp, Filter, Calendar, ChevronRight, DollarSign, RefreshCw } from 'lucide-react'; import { toast } from 'sonner'; export default function PaymentHistory({ payments = [], currentPlan, expiresAt, subscriptionStatus }) { const { t } = useTranslation(); const [searchTerm, setSearchTerm] = useState(''); const [statusFilter, setStatusFilter] = useState('all'); const [sortBy, setSortBy] = useState('date_desc'); // Calculate dynamic stats const totalSpent = payments.reduce((acc, curr) => acc + (curr.status === 'success' ? curr.amount : 0), 0); const successfulCount = payments.filter(p => p.status === 'success').length; const failedCount = payments.filter(p => p.status === 'failed').length; // Filter and Sort Logic const filteredPayments = payments .filter(payment => { const matchesSearch = payment.description.toLowerCase().includes(searchTerm.toLowerCase()) || payment.invoice_no.toLowerCase().includes(searchTerm.toLowerCase()); const matchesStatus = statusFilter === 'all' || payment.status === statusFilter; return matchesSearch && matchesStatus; }) .sort((a, b) => { if (sortBy === 'date_desc') { return new Date(b.date) - new Date(a.date); } if (sortBy === 'date_asc') { return new Date(a.date) - new Date(b.date); } if (sortBy === 'amount_desc') { return b.amount - a.amount; } if (sortBy === 'amount_asc') { return a.amount - b.amount; } return 0; }); const downloadReceipt = (invoice) => { // Calculate UAE VAT (5%) const total = parseFloat(invoice.amount); const subtotal = total / 1.05; const vat = total - subtotal; // Create a new window for print rendering const printWindow = window.open('', '_blank', 'width=900,height=900'); if (!printWindow) { toast.error(t('popup_blocked', 'Popup blocked! Please allow popups to download receipts.')); return; } printWindow.document.write(`
MOHRE Domestic Labor Portal
Domestic Labor Marketplace
billing@marketplace.ae
Abu Dhabi, UAE
Phone: 800-MOHRE
TRN: 100293810200003
Employer Account
Domestic Sponsor Household
sponsor@marketplace.ae
Dubai, UAE
Phone: +971 50 123 4567
Invoice Number: ${invoice.invoice_no}
Invoice Date: ${invoice.date}
Invoice Due Date: ${invoice.date}
| Items | Description | QTY | Price | Sales Tax | Total |
|---|---|---|---|---|---|
| 1 | ${invoice.description} | 1 | ${subtotal.toFixed(2)} AED | 5% VAT | ${total.toFixed(2)} AED |
{t('payment_history_desc', 'Track subscription plans, document vetting, and direct hiring invoice details.')}
{subscriptionStatus || 'Active'}
{t('auto_renew_enabled', 'Auto-renewal is enabled')}
{t('across_all_periods', 'Across active subscription periods')}
{t('fully_vat_compliant', 'Fully UAE compliant & VAT logged')}
| {t('invoice_id', 'Invoice ID')} | {t('date_time', 'Date & Time')} | {t('description', 'Description')} | {t('status', 'Status')} | {t('amount', 'Amount')} | {t('actions', 'Actions')} |
|---|---|---|---|---|---|
|
|
{payment.date}
{payment.time}
|
{payment.description}
PayTabs Secured Transfer
|
{payment.status.toUpperCase()} | {payment.amount.toFixed(2)}{' '} {payment.currency} | |
|
{t('no_payments_logged', 'No transaction items logged')}
{t('try_adjusting_filters', 'Try adjusting your search criteria or filter levels.')} |
|||||