<?php
$invoiceNo = 'AMP'.( \Carbon\Carbon::parse($order->created_at)->format('Y') ?? '').'-'.$order->transaction_id ?? '';
?>
<!doctype html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <link rel="shortcut icon" href="{{ asset('favicon.ico') }}" type="image/x-icon">
    <title>{{ config('app.name') . ' | ' . $pdfContent->invoice . ' ' .$invoiceNo ?? '' }}</title>
    <style>
        @page {
            margin: 45px;
        }
        body {
            font-family: Arial, Helvetica, sans-serif;
        }

        table {
            /*border: 1px solid #FFFFFF;*/
            width: 100%;
            border-collapse: collapse;
            font-size: 10pt;
        }

        td, th {
            /*border: 1px solid #000000;*/
            width: auto;
        }

        td {
            padding: 4px 0;
        }

        .page-break {
            page-break-after: always;
        }

        .next-line {
            margin-bottom: 10px;
        }

        .logo {
            height: 50px;
            width: auto;
        }

        #header .h-r {
            width: 60%;
            padding: 5px 10px;
        }

        #header .h-l {
            width: 40%;
            padding: 3px 10px;
        }

        .title {
            font-size: 12pt;
            font-weight: bold;
        }

        .sub-title {
            font-size: 11pt;
            font-weight: bold;
        }

        .content {
            font-size: 10pt;
            width: 50%;
        }

        .sub-content {
            font-size: 10pt;
            line-height: 1.5;
        }

        #footer {
            position: fixed;
            bottom: -20px;
            left: 0px;
            right: 0px;
            height: 50px;
            align-self: center;
        }

        .no-border {
            border: none!important;
        }

        .v-align-baseline{
            vertical-align: baseline;
        }
        .p-0{
            padding: 0;
        }
    </style>
</head>
<body>

<table class="no-border">
    <tr>
        <td class="title no-border" rowspan="3" style="width: 60%; padding: 0">
            <img class="logo" style="height: 90px;" src="data:image/png;base64,{{  base64_encode(file_get_contents(config('amplivo.admin_url')."upload/".$pdfContent->pdf_logo)) }}" alt="logo">
        </td>
    </tr>
    <tr>
        <td class="no-border" style="width: 40%; padding: 0" align="right">
            <b>{{ $pdfContent->su_business_name }}</b> <br>
            {{ $pdfContent->su_address_1 }} <br>
            {{ $pdfContent->su_address_2 }} <br>
            {{ $pdfContent->su_address_3 }} <br>
            {{ $pdfContent->su_address_4 }} <br>
            {{ $pdfContent->su_address_5 }} <br>
        </td>
    </tr>
</table>

<table class="next-line">
    <tr class="no-border">
        <th align="center">
            <h1>INVOICE</h1>
        </th>
    </tr>
</table>

<table>
    <tr>
        <td class="content" style="width: 90%">
            <div><b>{{ $pdfContent->supporter }} :</b></div>
            <div class="sub-content">
                {{ ($userDetail->first_name ?? '') . ' ' . ($userDetail->last_name  ?? '') }} <br>
                {{ (!empty($address->business_name)) ? $address->business_name.'<br>' : '' }}
                @if( (isset($address->address_1) && !empty($address->address_1))) {{ $address->address_1 }} <br> @endif
                @if( (isset($address->address_2) && !empty($address->address_2))) {{ $address->address_2 }} <br> @endif
                {{ (isset($address->state)) ? $address->state->name . ',' : '' }} {{ $address->city ?? '' }}
                @if(((isset($address->state)) && !empty($address->state)) || ((isset($address->city)) && !empty($address->city))) <br> @endif
                {{ (isset($address->postal_code)) ? $address->postal_code . ',' : '' }} {{ $address->country->country_name ?? '' }} <br>
                @if(!empty($order->vat_number))
                    {{ $pdfContent->vat_number }}: {{ $order->vat_number ?? '' }}
                @endif
            </div>
        </td>
        <td class="content v-align-baseline">
            <div class="sub-content">
                <table class="v-align-baseline">
                    <tr>
                        <td class="p-0"><b>Invoice Number:</b></td>
                        <td class="p-0" align="right">{{ $invoiceNo ?? '' }}</td>
                    </tr>
                    <tr>
                        <td class="p-0"><b>Invoice date:</b></td>
                        <td class="p-0" align="right">{{ \Carbon\Carbon::parse($order->created_at)->format($pdfContent->date) ?? '' }}</td>
                    </tr>
                    <tr>
                        <td class="p-0"><b>Payment Due Date:</b></td>
                        <td class="p-0" align="right">{{ \Carbon\Carbon::parse($order->created_at)->format($pdfContent->date) ?? '' }}</td>
                    </tr>
                </table>
            </div>
        </td>
    </tr>
</table>

<table class="next-line"></table>
<table class="next-line"></table>

<table class="no-border">
    <tr style="border-bottom: 2px solid black">
        <td class="sub-title" style="width:50%">
            <b>{{ $pdfContent->description }}</b>
        </td>
        <td class="sub-title" style="width:16%" align="right">
            <b>{{ $pdfContent->quantity }}</b>
        </td>
        <td class="sub-title" style="width:17%" align="right">
            <b>{{ $pdfContent->unit_price }} <br> ({{ $pdfContent->euro }})</b>
        </td>
        <td class="sub-title" style="width:17%" align="right">
            <b>{{ $pdfContent->amount }} <br> ({{ $pdfContent->euro }})</b>
        </td>
    </tr>
    @foreach($order->purchase->groupBy('product_static_option_id') as $purchase)
        <?php
            $row = $purchase[0];
        ?>
        <tr>
            <td>
                @if(isset($row->ProductStaticOption->title))
                    {{ $row->ProductStaticOption->title  }}
                @else
                    {{ $pdfContent->plastic_neutrality_package }}
                @endif
            </td>
            <td align="right">
                {{ count($purchase) }}
            </td>
            <td align="right">
                {{ formatDisplayNumber(number_format($row->price,2,'.','')) }}
            </td>
            <td align="right">
                {{ formatDisplayNumber(number_format((count($purchase) * $row->price),2,'.','')) }}
            </td>
        </tr>
    @endforeach

    <tr>
        <td><br></td>
        <td></td>
        <td></td>
        <td></td>
    </tr>
    @if(isset($data['tax_data']['details']) && !empty($data['tax_data']['details']))
        @foreach($data['tax_data']['details'] as $tax)
            <tr>
                <td>{{ $tax['name'] ?? 0 }} ({{ $tax['percentage'] ?? 0 }} %)</td>
                <td></td>
                <td></td>
                <td align="right">{{ formatDisplayNumber($tax['value']) ?? 0 }}</td>
            </tr>
        @endforeach
    @else
        <tr>
            <td>VAT</td>
            <td></td>
            <td></td>
            <td align="right">0.00</td>
        </tr>
    @endif

    <tr>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
    </tr>

    <tr style="border-bottom: 2px solid black;border-top: 1.5px solid black;">
        <td colspan="3">{{ $pdfContent->total_payable }}</td>
        <td align="right">{{ formatDisplayNumber(number_format(abs($order->value),2,'.','')) }}</td>
    </tr>
</table>

<table class="next-line"></table>

<table class="next-line"></table>

<table id="footer" class="no-border">
    <tr>
        <td class="no-border" align="center">
            {{ $pdfContent->footer_text_line_1 }} <br>
            {{ $pdfContent->footer_text_line_2 }}.
        </td>
    </tr>
</table>
<table class="no-border">
    <tr>
        <td class="title no-border" rowspan="3" style="width: 60%; padding: 0;text-align: right">
            <img class="logo" style="height: 90px;" src="data:image/png;base64,{{  base64_encode(file_get_contents(config('amplivo.admin_url')."upload/".$pdfContent->paid_image)) }}" alt="logo">
        </td>
    </tr>
</table>
<span class="fw-bold">{{__('Invoice Paid')}}</span>
<p>{{__('Payment for this invoice has been processed using funds from the member’s internal account.')}}</p>
</body>
</html>
