@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, 'sales_contract'); @endphp @foreach ($chunks as $pageIndex => $chunk) @if ($pageIndex > 0)
@endif
@if ($pageIndex == 0)
@php $logoPath = public_path('storage/logo_large.png'); if (file_exists($logoPath)) { $logoData = base64_encode(file_get_contents($logoPath)); $logoSrc = 'data:image/png;base64,' . $logoData; } else { $logoSrc = asset('storage/logo_large.png'); } @endphp Logo

PT. MULTI SPUNINDO JAYA Tbk

Ds. Jabaran RT. 008 RW. 003, Jabaran, Balongbendo, Kab. Sidoarjo

Jawa Timur - Indonesia

Telp. +62-31-8975555 (H), Fax +62-31-8976666, 8971300

SALES CONTRACT

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 @foreach ($chunk as $item) @endforeach @if ($loop->last) @if(!isset($is_no_amount_no_vat_rate_n_rate_unit) || !$is_no_amount_no_vat_rate_n_rate_unit) @endif @endif
PRODUCT DESCRIPTION Price / Unit
{{ $ET_HEADER->first()->CURRENCY ?? 'JPY' }} / {{ ($ET_ITEM->first()->PRICECONDITIONBASEUOM ?? 'KG') === 'M' ? 'METER' : ($ET_ITEM->first()->PRICECONDITIONBASEUOM ?? 'KG') }}
Amount
( {{ $ET_HEADER->first()->CURRENCY ?? 'JPY' }} )
Gsm Color Width
(m)
Length
(m/Roll)
Roll Weight
(kg)
Length
(mtr)
Area
(mtr2)
{{ $item->DESCRIPTION ?? '' }} @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), 0, ',', '.') }} {{ number_format((float) ($item->AREATOTAL ?? 0), 0, ',', '.') }} {{ number_format((float) ($item->PRICECONDITIONRATE ?? 0), 2, ',', '.') }} / {{ $item->PRICECONDITIONBASEQTY ?? '1' }} {{ number_format((float) ($item->NETAMOUNT ?? 0) * $amountMultiplier, 2, ',', '.') }}
TOTAL AMOUNT {{ $totalRoll }} {{ number_format($totalWeight, 2, ',', '.') }} {{ number_format($totalLength, 0, ',', '.') }} {{ number_format($totalArea, 0, ',', '.') }} {{ number_format($backendTotalAmount, 2, ',', '.') }}
Discount {{ number_format($backendDiscountAmt, 2, ',', '.') }}
Transportation Cost {{ number_format($backendTransCostAmt, 2, ',', '.') }}
TOTAL AMOUNT - Discount + Trans. Cost {{ number_format($backendNetAmount, 2, ',', '.') }}
Amount {{ number_format($calculatedAmount, 2, ',', '.') }}
@if(isset($is_no_amount_no_vat_rate_n_rate_unit) && $is_no_amount_no_vat_rate_n_rate_unit) VAT @else VAT {{ number_format($vatRate, 0) }}{{ $vatRateUnit }} @endif {{ number_format($backendVatAmount, 2, ',', '.') }}
TOTAL {{ number_format($backendGrandTotal, 2, ',', '.') }}
{{ numberToWords($backendGrandTotal, $currency) }}
@if ($loop->last)
@endif
@endforeach