@extends('layouts.pdf')

<title>Top Notch Invoice Report {{$invoiceReport->internal_id}}</title>

<style>
    * {
        font-size: 0.9rem;
    }
</style>

<div class="container-fluid pt-4 font-serif" style="">

    <div class="fw-bold">
        TOP NOTCH EMBROIDERY & DIGITIZING LTD.
    </div>
    <div>
        108-618 EAST KENT AVE. SOUTH <br>
        VANCOUVER BC <br>
        (604) 871-9991 <br>
        info@sewtopnotch.com <br>
        GST# 846025062RT0001 <br>
    </div>

    <div class="fs-3 fw-bold text-primary mt-2">
        INVOICE STATEMENT
    </div>


    <div class="d-flex flex-row">
        <div class="me-auto">
            <div class="fw-bold">
                BILL TO
            </div>
            <div>
                {{$invoiceReport->customer->company_name}} <br>
                {{$invoiceReport->customer->billing_address_line_1}} <br>
                {{$invoiceReport->customer->billing_address_line_2}} <br>
            </div>
        </div>

        <div class="text-end pe-2">
            <div class="fw-bold">
                INVOICE REPORT #
            </div>
            <div class="fw-bold">
                DATE
            </div>
            <div class="fw-bold">
                DATE FROM
            </div>
            <div class="fw-bold">
                DATE TO
            </div>
            <br>
            <div class="fw-bold">
                TOTAL BALANCE DUE
            </div>
        </div>

        <div>
            <div>
                {{$invoiceReport->internal_id}}
            </div>
            <div>
                {{Date::make($invoiceReport->created_at)->format('Y-m-d')}}
            </div>
            <div>
                {{$invoiceReport->date_start->format('Y-m-d')}}
            </div>
            <div>
                {{$invoiceReport->date_end->format('Y-m-d')}}
            </div>
            <br>
            <div>
                ${{number_format($invoiceReport->invoices->sum(fn ($invoice) => $invoice->remainingBalance()) , 2)}}
            </div>
        </div>
    </div>

    <br>


    <table class="table table-sm table-striped">
        <tr>
            <th>Date</th>
            <th>Invoice</th>
            <th class="text-end">Subtotal</th>
            <th class="text-end">GST/HST</th>
            <th class="text-end">PST</th>
            <th class="text-end">Total</th>
            <th class="text-end">Balance</th>
            <th class="text-end">Status</th>
        </tr>

        @foreach($invoiceReport->invoices->sortBy('id') as $invoice)
            <tr>
                <td>{{Date::make($invoice->created_at)->format('Y-m-d')}}</td>
                <td>{{$invoice->internal_id}}</td>
                <td class="text-end">${{number_format($invoice->subtotal, 2)}}</td>

                <td class="text-end">
                    @if($invoice->has_hst)
                        ${{number_format($invoice->hst_amount, 2)}}
                    @elseif($invoice->has_gst)
                        ${{number_format($invoice->gst_amount, 2)}}
                    @else
                        -
                    @endif
                </td>

                <td class="text-end">{{$invoice->has_pst ? '$'.number_format($invoice->pst_amount, 2) : '-'}}</td>
                <td class="text-end">${{number_format($invoice->total, 2)}}</td>
                <td class="text-end">${{number_format($invoice->remainingBalance(), 2)}}</td>
                <td class="text-end">{{$invoice->status->getLabel()}}</td>
            </tr>
        @endforeach

        <tr class="font-bold">
            <td></td>
            <td></td>
            <td class="text-end pt-2">${{number_format($invoiceReport->invoices()->sum('subtotal'), 2)}}</td>
            <td class="text-end pt-2">${{number_format($invoiceReport->combinedGstHstSum(), 2)}}</td>
            <td class="text-end pt-2">${{number_format($invoiceReport->invoices()->sum('pst_amount'), 2)}}</td>
            <td class="text-end pt-2">${{number_format($invoiceReport->total, 2)}}</td>
            <td class="text-end pt-2">${{number_format($invoiceReport->balance, 2)}}</td>
            <td></td>
        </tr>

    </table>
</div>