@php use App\Enums\InvoiceStatus; @endphp
@extends('layouts.pdf')

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

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

    .paid {
        position: absolute;
        top: 1rem;
        right: 0.5rem;
        font-size: 3rem;
        font-weight: bold;
    }
</style>

@if($invoice->status === InvoiceStatus::PAID)
    <div class="paid">
        PAID
    </div>
@endif

<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
    </div>

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

        <div class="text-end pe-2">
            <div class="fw-bold">
                INVOICE#
            </div>
            <div class="fw-bold">
                DATE
            </div>
            <div class="fw-bold">
                DUE DATE
            </div>
        </div>

        <div>
            <div class="text-start">
                @if(isset($invoice->internal_id))
                    {{$invoice->internal_id}}
                @endif
            </div>
            <div class="text-start">
                @if(isset($invoice->date))
                    {{$invoice->date->format('Y-m-d')}}
                @endif
            </div>
            <div class="text-start">
                @if(isset($invoice->due_date))
                    {{$invoice->due_date->format('Y-m-d')}}
                @endif
            </div>
        </div>
    </div>

    <hr>

    <table class="table table-sm table-striped">
        <tr>
            <th>WO#</th>
            <th>PO#</th>
            <th>PRODUCT SERVICES</th>
            <th>QTY</th>
            <th>RATE</th>
            <th>AMOUNT</th>
        </tr>

        @foreach($invoice->productServices as $service)
            <tr>
                <td class="text-nowrap">
                    <span style="font-size: 0.8rem">
                    {{$service->order->internal_po}}
                    </span>
                </td>
                <td>
                    {{$service->order->customer_po}}
                </td>
                <td>
                    <span class="fw-bold">
                    {{$service->order->order_type->name}} <br>
                    </span>
                    {{$service->service_details}}
                </td>
                <td class="text-end">
                    {{$service->amount}}
                </td>
                <td class="text-end">
                    {{number_format($service->amount_price, 2)}}
                </td>
                <td class="text-end">
                    ${{number_Format($service->price, 2)}}
                </td>
            </tr>
        @endforeach
    </table>

    <div class="d-flex flex-row-reverse">

        <div class="text-end ps-5">
            <div>${{number_format($invoice->subtotal, 2)}}</div>

            @if($invoice->has_hst)
                <div>${{number_format($invoice->hst_amount, 2)}}</div>
            @else
                <div>${{number_format($invoice->gst_amount, 2)}}</div>
                <div>{{$invoice->has_pst ? '$'.number_format($invoice->pst_amount, 2) : '-'}}</div>
            @endif

            <div>${{number_format($invoice->total, 2)}}</div>
            <br>
            <div class="fw-bold">${{number_format($invoice->remainingBalance(), 2)}}</div>
        </div>

        <div class="fw-bold text-end">
            <div>Subtotal</div>

            @if($invoice->has_hst)
                <div>HST @ {{$invoice->hst_rate}}%</div>
            @else
                <div>GST @ {{$invoice->gst_rate}}%</div>
                <div>PST (BC) @ {{$invoice->pst_rate}}%</div>
            @endif

            <div>TOTAL</div>
            <br>
            <div>BALANCE DUE</div>
        </div>
    </div>

</div>
