<table>
    
    <thead>
        <tr>
            <th>S.No</th>
            <th>Username</th>
            <th>Email</th>
            <th>Phone</th>
            <th>Total Earn</th>
            <th>Total Withdraw</th>
            <th>Wallet Amount</th>
            <th>Bank Name</th>
            <th>Account Number</th>
            <th>Ifsc Code</th>
        </tr>
    </thead>
    
    <tbody>
    @foreach($invoices as $key => $invoice)
        <?php
            $total_earn_amount = 0;
            $total_with_amount = 0;
            foreach($invoice['payment_details'] as $key => $value)
            {
                $total_earn_amount += $value->discount; 
            }
            
            foreach($invoice['transaction_history'] as $key => $value1)
            {
                $total_with_amount += $value1->amount; 
            }
            if($invoice->wallet_amount)
            {
                $wallet_amount = number_format($invoice->wallet_amount, 2);
            }
            else
            {
                $wallet_amount = 0;
            }
        ?>
        @if($wallet_amount != 0)
        <tr>
            <td>{{ $key + 1 }}</td>
            <td>{{ $invoice->name }}</td>
            <td>{{ $invoice->email ?? '' }}</td>
            <td>{{ $invoice->phone ?? '' }}</td>
            <td>{{ $total_earn_amount }}</td>
            <td>{{ $total_with_amount }}</td>
            <td>{{ $wallet_amount }}</td>
            <td>{{ $invoice->bank_name ?? '' }}</td>
            <td>{{ $invoice->account_number ?? '' }}</td>
            <td>{{ $invoice->bank_ifsc ?? '' }}</td>
        </tr>
        @endif
    @endforeach
    </tbody>
</table>