<table>
    <thead>
        <tr></tr>
    </thead>
    <tbody>
        <td></td>
    </tbody>
</table>
<table class="table table-striped mt-2" style="width:100%">
    <thead>
        <tr>
            <th display="none"></th>
            <th display="none"></th>
            <th style="text-align: center">Invoice</th>
            <th style="text-align: center">Tanggal</th>
            <th style="text-align: center">Jam</th>
            <th style="text-align: center">User</th>
            <th style="text-align: center">Staff</th>
            <th style="text-align: center">Qty</th>
            <th style="text-align: center">Sub Total</th>
            <th style="text-align: center">Discount</th>
            <th style="text-align: center">Cashback</th>
            <th style="text-align: center">Grand Total</th>
            <th style="text-align: center">Cash</th>
            <th style="text-align: center">Card</th>
        </tr>
    </thead>
    <tbody>
        @php
            $totalCash = 0;
            $totalTransfer = 0;
            $totalSubtotalQrisCash = 0;
            $totalSubtotalCard = 0;
            $totalGrandtotal = 0;

        @endphp

        @foreach ($invoices as $invoice)
            <tr>
                <td display="none"></td>
                <td display="none"></td>
                <td>{{ $invoice->no }}</td>
                <td>{{ \Carbon\Carbon::parse($invoice->created_at)->format('d/m/y') }}</td>
                <td>{{ \Carbon\Carbon::parse($invoice->created_at)->format('H:i') }}</td>
                <td>{{ $invoice->users_name }}</td>
                <td>{{ $invoice->sales_name }}</td>
                <td>{{ $invoice->total_qty }}</td>
                <td>{{ $invoice->subtotal }}</td>
                <td>{{ number_format($invoice->disc_total ?? 0, 2, ',', '.') }}</td>
                @if ($invoice->cashback !== 'N')
                    <td>{{ $invoice->value }}</td>
                @else
                    <td>0</td>
                @endif

                <td>{{ $invoice->grandtotal }}</td>

                @if ($invoice->payment === 'Multi')
                    @php
                        $totalCash += $invoice->cash;
                        $totalSubtotalCard += $invoice->transfer;
                    @endphp
                    <td>{{ $invoice->cash }}</td>
                    <td>{{ $invoice->transfer }}</td>
                @elseif ($invoice->payment === 'Cash')
                    @php
                        $totalCash += $invoice->grandtotal;
                    @endphp
                    <td>{{ $invoice->grandtotal }}</td>
                    <td>0</td>
                @elseif ($invoice->payment === 'Qris')
                    @php
                        $totalSubtotalCard += $invoice->grandtotal;
                    @endphp
                    <td>0</td>
                    <td>{{ $invoice->grandtotal }}</td>
                @elseif ($invoice->payment === 'Card')
                    @php
                        $totalSubtotalCard += $invoice->grandtotal;
                    @endphp
                    <td>0</td>
                    <td>{{ $invoice->grandtotal }}</td>
                    {{-- mz --}}
                @else
                    <td>0</td>
                    <td>0</td>
                @endif

            </tr>
        @endforeach

        <tr>
            <td display="none"></td>
            <td display="none"></td>
            <td colspan="5">Grand Total</td>
            <td>{{ $invoices->sum('total_qty') }}</td>
            <td>{{ $invoices->sum('subtotal') }}</td>
            <td>{{ $invoices->sum('discount') }}</td>
            <td>{{ $invoices->sum('value') }}</td>
            <td>{{ $invoices->sum('grandtotal') }}</td>
            <td>{{ $totalCash }}</td>
            <td>{{ $totalSubtotalCard }}</td>
        </tr>

    </tbody>
</table>
