<br>
<table>
    <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
        </td>
        <td class="header-details">
            <div class="title" style="font-size: 20px; text-transform: uppercase;">
                <strong>
                    Packing List Measurements
                </strong>
            </div>

            <div class="date">Date: {{ $invoice_transaction->created_at }}</div>
        </td>
    </tr>
</table>

<br>
<br>
<table class="line-table" style="overflow: wrap" autosize="1">
    <thead>
        <tr>
            <th width="5%">No</th>
            <th class="description">Description</th>
            <th width="15%">Measurement</th>
            <th width="15%">CBM</th>
            <th width="10%">Quantity</th>
            <th width="15%">Total CBM</th>
        </tr>
    </thead>
    <tbody>
        @php
            $billable_packing_list = $invoice_transaction->owner->packingLists()->first();
            $billable_packing_list = $billable_packing_list ? $billable_packing_list : $invoice_transaction->owner;
            $packages = $billable_packing_list->packages;
            $totalCBM = 0;
            $totalQty = 0;
            $order_reference = $invoice_transaction->owner->owner ? $invoice_transaction->owner->owner->reference : null;
        @endphp
        @foreach ($packages as $key => $package)
            @php
                $measurement = "{$package->length} (L) <br> {$package->width} (W) <br> {$package->height} (H)";
                $itemCBM = ($package->width / 100) * ($package->height / 100) * ($package->length / 100);
                $itemTotalCBM = $itemCBM * $package->quantity;
                $totalCBM += $itemTotalCBM;
                $totalQty += $package->quantity;
            @endphp
            <tr>
                <td width="5%" class="center top">{{ $key + 1 }}</td>
                <!-- <td class="description">{!! $package->description  !!}</td> -->
                <td class="description">{!! $order_reference . '<br>' . $billable_packing_list->owner->reference  !!}</td>
                <td width="15%" class="center top" style="text-align: center">
                    {!! $measurement !!}
                </td>
                <td width="15%" class="center top" style="text-align: center">
                    {{ round($itemCBM, 5) }}
                </td>
                <td width="10%" class="center top" style="text-align: center">{{ $package->quantity }}</td>
                <td width="15%" class="right top">
                    {{ round($itemTotalCBM, 5) }}
                </td>
            </tr>
        @endforeach
    </tbody>
    <tfoot>
        <tr>
            <td colspan="3"></td>
            <td class="right middle">Total</td>
            <td class="total" style="text-align: center">
                {{ $totalQty }}
            </td>
            <td class="total right middle">
                {{ round($totalCBM, 5) }}
            </td>
        </tr>
    </tfoot>
</table>