@php
// 1. Calculate Totals Upfront
$totalRoll = 0;
$totalWeight = 0;
$totalLength = 0;
$totalArea = 0;
$totalAmount = 0;
$currency = strtoupper($ET_HEADER->first()->CURRENCY ?? 'JPY');
$amountMultiplier = (in_array($currency, ['JPY', 'IDR'])) ? 100 : 1;
$backendTotalAmount = (float) ($ET_HEADER->first()->TOTALAMOUNT ?? 0) * $amountMultiplier;
$backendDiscountAmt = (float) ($ET_HEADER->first()->DISCOUNTAMT ?? 0) * $amountMultiplier;
$backendTransCostAmt = (float) ($ET_HEADER->first()->TRANSCOSTAMT ?? 0) * $amountMultiplier;
$backendNetAmount = (float) ($ET_HEADER->first()->NETAMOUNT ?? 0) * $amountMultiplier;
$backendVatAmount = (float) ($ET_HEADER->first()->VATAMOUNT ?? 0) * $amountMultiplier;
$backendGrandTotal = (float) ($ET_HEADER->first()->GRANDTOTAL ?? 0) * $amountMultiplier;
$vatRate = (float) ($ET_HEADER->first()->VATRATE ?? 0);
$vatRateUnit = $ET_HEADER->first()->VATRATEUNIT ?? '%';
if ($backendVatAmount == 0) {
$calculatedAmount = $backendNetAmount;
} else {
$calculatedAmount = round($backendNetAmount * 11 / 12);
}
if (!function_exists('numberToWords')) {
function numberToWords($number, $currency = 'JPY') {
if ($number == 0) return '(' . strtoupper($currency) . ') Zero';
// For USD and other decimal currencies, handle cents
$hasCents = !in_array(strtoupper($currency), ['JPY', 'IDR']);
$integerPart = (int) $number;
$decimalPart = 0;
if ($hasCents) {
$decimalPart = round(($number - $integerPart) * 100);
}
$ones = ['', 'One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine'];
$tens = ['', '', 'Twenty', 'Thirty', 'Forty', 'Fifty', 'Sixty', 'Seventy', 'Eighty', 'Ninety'];
$teens = ['Ten', 'Eleven', 'Twelve', 'Thirteen', 'Fourteen', 'Fifteen', 'Sixteen', 'Seventeen', 'Eighteen', 'Nineteen'];
$units = [['', 'Thousand', 'Million', 'Billion', 'Trillion'], ['', 'Thousand', 'Million', 'Milliard', 'Billion']];
$convertNumber = function($num) use ($ones, $tens, $teens, $units, &$convertNumber) {
if ($num == 0) return 'Zero';
if ($num < 0) return 'Minus ' . $convertNumber(abs($num));
$words = '';
if ($num < 10) $words = $ones[$num];
elseif ($num < 20) $words = $teens[$num - 10];
elseif ($num < 100) { $words = $tens[(int) ($num / 10)]; if ($num % 10) $words .= ' ' . $ones[$num % 10]; }
elseif ($num < 1000) { $words = $ones[(int) ($num / 100)] . ' Hundred'; if ($num % 100) $words .= ' ' . $convertNumber($num % 100); }
else {
$unit_index = 0; $unit_words = '';
while ($num > 0) {
$chunk = $num % 1000;
if ($chunk) {
$chunk_words = $convertNumber($chunk);
if ($unit_index > 0) $chunk_words .= ' ' . $units[0][$unit_index];
$unit_words = $chunk_words . ($unit_words ? ' ' . $unit_words : '');
}
$num = (int) ($num / 1000);
$unit_index++;
}
$words = $unit_words;
}
return trim($words);
};
$result = $convertNumber($integerPart);
if ($hasCents && $decimalPart > 0) {
$result .= ' and ' . $convertNumber($decimalPart) . ' Cents';
}
return '(' . strtoupper($currency) . ') ' . trim($result);
}
}
// Loop to calculate totals only
foreach ($ET_ITEM as $item) {
$totalRoll += (float) ($item->ORDERQTY ?? 0);
$totalWeight += (float) ($item->WEIGHT ?? 0);
$totalLength += (float) ($item->LENGTHTOTAL ?? 0);
$totalArea += (float) ($item->AREATOTAL ?? 0);
$totalAmount += (float) ($item->NETAMOUNT ?? 0) * $amountMultiplier;
}
// --- PAGINATION LOGIC ---
$chunks = \App\Helpers\DocumentPagination_Helper::paginate($ET_ITEM, 'internal_order');
@endphp
@foreach ($chunks as $pageIndex => $chunk)
@if ($pageIndex > 0)
@endif
@if ($pageIndex == 0)
|
Consignee
{{ $ET_HEADER->first()->CONSIGNEENAME1 ?? '' }}
@if ($ET_HEADER->first()->CONSIGNEENAME2 ?? null)
{{ $ET_HEADER->first()->CONSIGNEENAME2 }}
@endif
@if ($ET_HEADER->first()->CONSIGNEESTREET ?? null)
{{ $ET_HEADER->first()->CONSIGNEESTREET ?? '' }}
@endif
@if ($ET_HEADER->first()->CONSIGNEESTRSUPPL1 ?? null)
{{ $ET_HEADER->first()->CONSIGNEESTRSUPPL1 ?? '' }}
@endif
@if ( $ET_HEADER->first()->CONSIGNEESTRSUPPL2 ?? null)
{{ $ET_HEADER->first()->CONSIGNEESTRSUPPL2 ?? '' }}
@endif
@if ($ET_HEADER->first()->CONSIGNEESTRSUPPL3 ?? null)
{{ $ET_HEADER->first()->CONSIGNEESTRSUPPL3 ?? '' }}
@endif
@if ($ET_HEADER->first()->CONSIGNEECITY ?? null)
{{ $ET_HEADER->first()->CONSIGNEECITY ?? '' }}
@endif
{{ $ET_HEADER->first()->CONSIGNEECOUNTRY ?? '' }}
|
| SO/PI No |
: |
{{ ltrim($ET_HEADER->first()->SALESDOCUMENT ?? '', '0') }} |
Date {{ $ET_HEADER->first()->DOCUMENTDATE ?
\Carbon\Carbon::parse($ET_HEADER->first()->DOCUMENTDATE)->format('d-m-Y') : '' }}
|
| Our Ref |
: |
{{ $ET_HEADER->first()->OURREFERENCE ?? '' }} |
| No PO |
: |
{{ $ET_HEADER->first()->CUSTOMERPO ?? '' }} |
| End User |
: |
{{ $ET_HEADER->first()->ENDUSER ?? '' }} |
| Payment Term |
: |
{{ $ET_HEADER->first()->ZTERMTXT ?? '' }} |
| Price Condition |
: |
{{ $ET_HEADER->first()->PRICECOND ?? '' }} |
|
|
Buyer / Notify Party ( if other than consignee )
{{ $ET_HEADER->first()->BUYERNAME1 ?? '' }}
@if ($ET_HEADER->first()->BUYERNAME2 ?? null)
{{ $ET_HEADER->first()->BUYERNAME2 }}
@endif
@if ($ET_HEADER->first()->BUYERSTREET ?? null)
{{ $ET_HEADER->first()->BUYERSTREET ?? '' }}
@endif
@if ($ET_HEADER->first()->BUYERSTRSUPPL1 ?? null)
{{ $ET_HEADER->first()->BUYERSTRSUPPL1 ?? '' }}
@endif
@if ( $ET_HEADER->first()->BUYERSTRSUPPL2 ?? null)
{{ $ET_HEADER->first()->BUYERSTRSUPPL2 ?? '' }}
@endif
@if ($ET_HEADER->first()->BUYERSTRSUPPL3 ?? null)
{{ $ET_HEADER->first()->BUYERSTRSUPPL3 ?? '' }}
@endif
@if ($ET_HEADER->first()->BUYERCITY ?? null)
{{ $ET_HEADER->first()->BUYERCITY ?? '' }}
@endif
{{ $ET_HEADER->first()->BUYERCOUNTRY ?? '' }}
|
| Loading Port |
: |
{{ $ET_HEADER->first()->LOADPORT ?? '' }} |
| Destination |
: |
{{ $ET_HEADER->first()->DESTINATION ?? '' }} |
| Shipment by |
: |
{{ $ET_HEADER->first()->SHIPMENTBY ?? '' }} |
| Packing |
: |
{{ $ET_HEADER->first()->PACKING ?? '' }} |
| Shipment Date |
: |
{{ $ET_HEADER->first()->SHIPMENTDATE ?? '' }} |
|
@else
@endif
| PRODUCT DESCRIPTION |
Spec Reference |
| Gsm |
Color |
Width (m) |
Length (m/Roll) |
Roll |
Weight (kg) |
Length (mtr) |
Area (mtr2) |
@foreach($chunk as $item)
|
{{ $item->DESCRIPTION ?? '' }} {{ $item->MATERIAL ?? '' }}
@if($item->CUSTOMERMATERIAL ?? null)
// {{ $item->CUSTOMERMATERIAL }}
@endif
|
|
| {{ $item->GSM ?? '' }} |
{{ $item->COLOR ?? '' }} |
{{ number_format((float)($item->WIDTHPERROLL ?? 0), 3, ',', '.') }} |
{{ number_format((float)($item->LENGTHPERROLL ?? 0), 0, ',', '.') }} |
{{ $item->ORDERQTY ?? '' }} |
{{ number_format((float)($item->WEIGHT ?? 0), 2, ',', '.') }} |
{{ number_format((float)($item->LENGTHTOTAL ?? 0), 2, ',', '.') }} |
{{ number_format((float)($item->AREATOTAL ?? 0), 2, ',', '.') }} |
@endforeach
@if ($loop->last)
| TOTAL AMOUNT
|
{{ number_format($totalRoll, 0, ',', '.') }} |
{{ number_format($totalWeight, 2, ',', '.') }} |
{{ number_format($totalLength, 0, ',', '.') }} |
{{ number_format($totalArea, 0, ',', '.') }} |
|
@endif
@if ($loop->last)
@endif
@endforeach