{{-- <div class="mb-2">
    <button class="btn btn-primary" onclick="export2csv()">Download csv</button>
</div> --}}
<div>
    <a class="noprint btn btn-primary"
        href="{{ route('bandwidthSaleExport') }}?export=yes&from_date={{ request()->from_date }}&to_date={{ request()->to_date }}&service={{ request()->service }}&provider={{ request()->company }}"
        target="_blank"><i class="fa fa-download"></i>Export
    </a>
</div>
<div class="col-md-12">
    <div class="badge badge-info float-right m-1" style="text-align: ">Total Row: {{ $list->count() }}</div>
</div>
<div class="table-responsive">
    <table class="table table-bordered table-condensed table-striped" id="tableId">
        <thead class="bg-blue-50">
            <tr>
                <th>SL</th>
                <th>Invoice</th>
                <th>Customer</th>
                <th>Service</th>
                <th>Billing Date</th>
                <th>Total</th>
                <th>Discount</th>
                <th>Paid</th>
                <th>Due</th>
                <th style="width: 100px;">Action</th>
            </tr>
        </thead>
        <tbody class="bg-white divide-y divide-gray-200">
            @php
                $total = 0;
                $discount = 0;
                $paid = 0;
                $due = 0;
            @endphp
            @foreach ($list as $item)
                <tr>
                    <td>{{ $item->id }}</td>
                    <td>{{ $item->invoice_no }}</td>
                    <td>{{ $item->bandwidthSaleCustomer->customer_name ?? '' }}</td>
                    <td>
                        <table>
                            <tr>
                                <th>Service</th>
                                <th>Quantity</th>
                                <th>Rate</th>
                                <th>Vat</th>
                                <th>From</th>
                                <th>To</th>
                                <th>Line Total</th>
                            </tr>
                            @foreach ($item->sateItems as $row)
                                <tr>
                                    <td style="width: 200px">
                                        <span class="badge badge-info">{{ $row->service->name ?? '' }}</span>
                                    </td>
                                    <td style="text-align: right; width: 100px">
                                        {{ $row->quantity ?? '' }}
                                    </td>
                                    <td style="text-align: right; width: 100px">
                                        {{ $row->rate ?? '' }}
                                    </td>
                                    <td style="text-align: right; width: 100px">
                                        {{ $row->vat ?? '' }}
                                    </td>
                                    <td style="width: 200px">
                                        {{ date('d-M-Y', strtotime($row->from_date)) }}
                                    </td>
                                    <td style="width: 200px">
                                        {{ date('d-M-Y', strtotime($row->to_date)) }}
                                    </td>
                                    <td style="text-align: right; width: 100px">
                                        {{ number_format($row->line_total, 2) }}
                                    </td>
                                </tr>
                            @endforeach
                        </table>
                    </td>
                    <td>{{ $item->billing_date }}</td>
                    <td style="text-align: right">{{ $item->total }}</td>
                    <td style="text-align: right">{{ $item->discount }}</td>
                    <td style="text-align: right">{{ $item->paid }}</td>
                    <td style="text-align: right">
                        @php
                            $d_amount = $item->total - ($item->paid + $item->discount);
                        @endphp
                        {{ number_format($d_amount, 2) }}
                    </td>
                    @php
                        $total += $item->total;
                        $discount += $item->discount;
                        $paid += $item->paid;
                        $due += $item->total - ($item->paid + $item->discount);
                    @endphp
                    <td>
                        <div class="row">
                            <div class="ml-1">
                                <a href="{{ route('bw-sale.edit', $item->id) }}"
                                    class="form-control btn btn-warning">Edit</a>
                            </div>
                        </div>
                    </td>
                </tr>
            @endforeach
            <tr>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td style="text-align: right"><b>Total</b></td>
                <td style="text-align: right"><b>{{ number_format($total, 2) }}</b></td>
                <td style="text-align: right"><b>{{ number_format($discount, 2) }}</b></td>
                <td style="text-align: right"><b>{{ number_format($paid, 2) }}</b></td>
                <td style="text-align: right"><b>{{ number_format($due, 2) }}</b></td>
                <td></td>
            </tr>
        </tbody>
    </table>
</div>
