@extends('layouts.base_pdf')
@section('inner_content')
    <br>
    <htmlpageheader name="page-header">
        <br>
        <table width="100%" style="border-bottom: 1px solid black;">
            <tr>
                <td style="text-align: center; color: red; text-transform: uppercase; font-weight: bold; font-size: 18px;  padding-bottom: 5px;">
                    @if(in_array($transactions->issuer, [2, 1921]))
                        Atvantic Import & Export Snd. Bhd (1309816-P)
                    @endif
                    @if(in_array($transactions->issuer, [1937, 1970]))
                        BK Gemilang Sdn Bhd (1403513-U)
                    @endif
                    @if(in_array($transactions->issuer, [2165, 2185]))
                        YSN SOLUTION TRADING SDN BHD (1393892-D)
                    @endif
                    @if(in_array($transactions->issuer, [2210]))
                        RACK SOLUTION INDUSTRIES SDN BHD (954723-W)
                    @endif
                </td>
            </tr>
        </table>
    </htmlpageheader>
    <br>
    <table>
        <tr>
            <td class="title">
                <strong>Delivery Order</strong>
            </td>
            <td class="document-detail">
                PO#: {{ $transactions->bill_no }} <br>
                Ref#: {{ $transactions->booking->marking }} <br>
                Date: {{ $po_order_transaction->created_at }}
            </td>
        </tr>
    </table>

    <br>

    <table class="buyer-seller">
        <tr>
            <td width="50%" class="top">
                <span class="buyer-seller-title">
                    Buyer
                </span>
                <br>

                <div class="buyer-company">
                    CIEF Worldwide Sdn Bhd (1134596-M)
                </div>

                <span class="buyer-company">
                    Malaysia Global Innovation & CreativityCentre, Level 1 CWS, Block 3730, PersiaranAPEC 63000 Cyberjaya
                </span>
                <span class="reg">
                    {{-- {{ $supplier }} --}}
                </span>
                <br>
                <span class="address">
                    {{-- {{ $buyer['address'] }} --}}
                </span>
                <br>
                <span class="contact-no">
                    Phone: 0182909252
                </span>
            </td>
        </tr>
    </table>

    <br>

    <table class="line-table" style="overflow: wrap" autosize="1">
        <thead>
            <tr>
                <th width="5%">No</th>
                <th class="stock-code" width="10%">Stock Code</th>
                <th class="description">Description</th>
                <th width="10%">Quantity</th>
                <th width="15%">Unit Price (RM)</th>
                <th width="10%">Total Amount<br>(RM)</th>
            </tr>
        </thead>
        <tbody>
            @php
                $subtotal = 0;
            @endphp
            
            @foreach ($po_order_transaction->transactionDetails as $key => $transaction_detail)
                <tr>
                    <td width="5%" class="center top">{{ $key + 1 }}</td>
                    <td class="stock-code top" width="10%">{{ $transaction_detail->product_code }}</td>
                    <td class="description">{{ $transaction_detail->product_name }}</td>
                    <td width="10%" class="center top">{{ $transaction_detail->quantity }}</td>
                    <td width="15%" class="center top">
                        @if($transactions->booking()->first()->fix_currency_id !== 1)
                            {{ number_format( (1/$transactions->currency_rate) * $transaction_detail->price, 2) }}
                        @else
                            {{ number_format($transaction_detail->price, 2) }}
                        @endif
                    </td>
                    <td width="20%" class="right top">
                        @if($transactions->booking()->first()->fix_currency_id !== 1)

                            {{  number_format((float)number_format( (1/$transactions->currency_rate) * $transaction_detail->price, 2,'.','')*$transaction_detail->quantity,2) }}
                            
                            @php
                                $subtotal += number_format((float)number_format( (1/$transactions->currency_rate) * $transaction_detail->price, 2,'.','')*$transaction_detail->quantity,2,'.','');
                            @endphp
                        @else                                                        
                            {{ number_format((float)number_format($transaction_detail->price, 2,'.','')*$transaction_detail->quantity,2) }}

                            @php
                                $subtotal += number_format((float)number_format($transaction_detail->price, 2,'.','')*$transaction_detail->quantity,2,'.','');
                            @endphp
                        @endif
                    </td>
                </tr>
            @endforeach
        </tbody>
        <tfoot>
            <tr class="subtotal">
                <td colspan="4"></td>
                <td class="right middle">Subtotal</td>
                <td class="right middle">
                    {{ number_format($subtotal, 2) }}
                </td>
            </tr>
            <tr class="billingcharges">
                <td colspan="4"></td>
                <td class="right">Adjustment</td>
                <td class="right">
                    @if($transactions->booking()->first()->fix_currency_id !== 1)                        
                        {{ number_format((float)number_format( (1/$transactions->currency_rate) * $transactions->amount, 2,'.','') - (float)number_format($subtotal, 2,'.',''),2) }}
                    @else                        
                        {{ number_format((float)number_format($transactions->amount, 2,'.','') - (float)number_format($subtotal, 2,'.',''),2) }}
                    @endif
                </td>
            </tr>
            <tr>
                <td colspan="4"></td>
                <td class="right middle">Total</td>
                <td class="total right middle">
                    @if($transactions->booking()->first()->fix_currency_id !== 1)
                        {{ number_format( ((1/$transactions->currency_rate) * $transactions->amount), 2) }}
                    @else
                        {{ number_format($transactions->amount, 2) }}
                    @endif
                </td>
            </tr>
        </tfoot>
    </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
