@extends('layouts.base_pdf')

@section('inner_content')
    <br>
    <htmlpageheader name="page-header">
        <br><br>
        <div class="separator"><strong><i>{{ $transaction->bill_no }}</i></strong></div>
    </htmlpageheader>
    <table>
        <!-- Header Section -->
        <tr>
            <td class="header-logo">
                <img src="{{ asset('images/ri_1.png') }}" alt="logo" id="logo" class="logo">
            </td>
            <td class="header-cief-address">
                <span class="company-name"><strong>CIEF WORLDWIDE SDN BHD</strong></span>
                <span class="company-reg">(1134596-M)</span><br>
                No. 72-3, Jalan Jalil 1,<br>
                The Earth Bukit Jalil,<br>
                57000 Kuala Lumpur<br>
                Tel: 03-8082 1252<br>
                TIN: C23880226040, MSIC: 46909<br>
                SST: W10-2403-32000643
            </td>
            <td class="header-details">
                <div class="title"><strong>E-Invoice</strong></div>
                <div class="number">EI#: {{ $autocountId ?? 'NONE'}}</div>
                <div class="ref">Ref# {{ $booking->marking }}</div>
                <div class="date">Date: {{ $document_date->toDateString() }}</div>
                <div>&nbsp;</div>
            </td>
        </tr>
        <tr>
            <td colspan="3" class="bill-to">
                <span class="sub-title">Bill To</span>
            </td>
        </tr>
        <tr>
            <td colspan="3" class="address">
                <div class="label">{{ $supplier->name }}
                @if ($brn)
                    (ROC: {{ $brn->reference }})
                @endif
                </div>
                @php
                    $billingAddress = $supplier->addresses()->where('e_invoice', '=', true)->latest()->first();
                @endphp
                <div class="address">
                    {{ $billingAddress->street_one }}
                    {{ $billingAddress->street_two }},
                    {{ $billingAddress->district()->first()->name }},
                    {{ $billingAddress->postcode }}
                    {{ $billingAddress->state()->first()->name }},
                    {{ $billingAddress->country()->first()->name }}
                </div>
                <div>Phone: {{ $supplier->contacts()->first()->phone }}</div>
                @if ($supplier->e_invoice === 1)
                    <div>Buyer TIN: {{ $supplier->tin }}</div>
                @endif
            </td>
        </tr>
    </table>

    <br>
    <br>

    <!-- Invoice Table -->
    @if($e_invoice_started_for_booking)
        @include('pages.pdfs.purchase_order_table_v2')
    @else
        @include('pages.pdfs.purchase_order_table')
    @endif

    <br>
    <div class="note">
        <strong>Note:</strong> All items purchased are subject to our Terms & Conditions. Please refer to our official website for more information.
    </div>
    <br>

    <table style="width: 100%; border-spacing: 0;">
        <tbody>
            <tr style="border-spacing: 2em;">
                <td width="80%">
                    <table style="border-spacing:10px 10px;">
                        <tbody>
                            <tr>
                                <td style="border-bottom: solid 2px #000000;">
                                    <div class="bank-info">
                                        <span style="font-size: 20px;">Please transfer the payment to:</span><br>
                                        <span style="font-size: 20px;">Bank: Maybank Berhad</span><br>
                                        <span style="font-size: 20px;">Account Name: CIEF Worldwide Sdn Bhd</span><br>
                                        <span style="font-size: 20px;">Account No: 568603010762</span><br>
                                    </div>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </td>
                <td width="20%" valign="top" align="center">
                    <div style="display: inline-block; text-align: center; max-width: 230px; width: 100%;">

                        <img src="{{ url(config('qr.qr_code_img_url') . $autocountEInvoiceValidationLink ) }}"
                            style="width: 25%; height: auto; display: block;" />

                        <div style="margin-top: 5px;
                                    word-break: break-word;
                                    overflow-wrap: break-word;
                                    white-space: normal;
                                    font-size: 12px;
                                    line-height: 1.2;
                                    text-align: center;">
                            <strong>{{ $autocountEInvoiceValidationLink }}</strong>
                        </div>
                    </div>
                </td>
            </tr>
        </tbody>
    </table>
    <htmlpagefooter name="page-footer">
        <table width="100%">
            <tr>
                <td style="text-align: right; ">This is generated by computer. No signature required.</td>
                <td style="text-align: right; ">Page {PAGENO} of {nbpg}</td>
            </tr>
        </table>
    </htmlpagefooter>
@endsection
