@extends('layouts.app') @section('content') @php $__roundOrderAmount = function ($amount) { $amount = max((float) $amount, 0); $minimumOrder = 10000; $roundTo = 1000; if ($amount <= 0) { return 0; } if ($amount < $minimumOrder) { $amount = $minimumOrder; } return (float) (ceil($amount / $roundTo) * $roundTo); }; $__normalizeUnit = function ($unit) { $unit = strtolower(trim((string) $unit)); return match ($unit) { 'm2', 'm²', 'm�' => 'm2', 'meter', 'm' => 'meter', 'pcs', 'pc', 'piece', 'lembar' => 'lembar', default => $unit !== '' ? $unit : 'lembar', }; }; $__parseM2FromDescription = function ($description) { $description = strtolower(trim((string) $description)); if ($description === '') { return 1; } $description = str_replace(['²', '�', '*'], ['2', 'x', 'x'], $description); if (!preg_match('/^\s*(\d+(?:\.\d+)?)\s*x\s*(\d+(?:\.\d+)?)\s*$/', $description, $matches)) { return 1; } $a = (float) $matches[1]; $b = (float) $matches[2]; if ($a >= 10 || $b >= 10) { $a = $a / 100; $b = $b / 100; } return round($a * $b, 4); }; $__itemDisplaySubtotal = function ($item) use ($__roundOrderAmount, $__normalizeUnit, $__parseM2FromDescription) { $storedSubtotal = max((float) ($item->subtotal ?? 0), 0); if ($storedSubtotal > 0) { return $__roundOrderAmount($storedSubtotal); } $unit = $__normalizeUnit($item->size_unit ?? 'lembar'); $qty = max((float) ($item->qty ?? 1), 0); $basePrice = max((float) ($item->base_price ?? $item->calculated_price ?? 0), 0); $sizeValue = (float) ($item->size_value ?? 0); if ($unit === 'm2') { if ($sizeValue <= 0) { $sizeValue = $__parseM2FromDescription($item->size_description ?? ''); } if ($sizeValue <= 0) { $sizeValue = 1; } return $__roundOrderAmount($basePrice * $sizeValue * $qty); } if ($unit === 'meter') { $sizeValue = $sizeValue > 0 ? $sizeValue : 1; return $__roundOrderAmount($basePrice * $sizeValue * $qty); } return $__roundOrderAmount($basePrice * $qty); }; $__orderDisplaySubtotalBeforePpn = function ($order) use ($__itemDisplaySubtotal, $__roundOrderAmount) { $items = method_exists($order, 'items') ? ($order->relationLoaded('items') ? $order->items : $order->items()->get()) : collect(); $activeItems = $items->filter(function ($item) { if (method_exists($item, 'isCancelled')) { return !$item->isCancelled(); } return !(bool) ($item->is_cancelled ?? false); }); if ($activeItems->isNotEmpty()) { return (float) $activeItems->sum(fn ($item) => $__itemDisplaySubtotal($item)); } $subtotalBeforePpn = (float) ($order->subtotal_before_ppn ?? 0); if ($subtotalBeforePpn > 0) { return $__roundOrderAmount($subtotalBeforePpn); } $total = (float) ($order->total_price ?? 0); $ppn = (float) ($order->ppn_amount ?? 0); if ((bool) ($order->use_ppn ?? false) && $ppn > 0 && $total > $ppn) { return $__roundOrderAmount($total - $ppn); } return $__roundOrderAmount($total); }; $__orderDisplayTotal = function ($order) use ($__orderDisplaySubtotalBeforePpn) { $subtotal = $__orderDisplaySubtotalBeforePpn($order); $ppn = ((bool) ($order->use_ppn ?? false) || (float) ($order->ppn_amount ?? 0) > 0) ? (float) ($order->ppn_amount ?? 0) : 0; return (float) ($subtotal + $ppn); }; $__orderDisplayRemaining = function ($order) use ($__orderDisplayTotal) { $paid = method_exists($order, 'getTotalPaid') ? (float) $order->getTotalPaid() : (float) ($order->paid_amount ?? 0); return max((float) $__orderDisplayTotal($order) - $paid, 0); }; $isCredit = $order->is_credit; $isPartialPaid = $order->isPartiallyPaid(); $totalPaid = $order->getTotalPaid(); $displayOrderTotal = $__orderDisplayTotal($order); $displaySubtotalBeforePpn = $__orderDisplaySubtotalBeforePpn($order); $remainingBalance = $__orderDisplayRemaining($order); $taxSetting = $taxSetting ?? null; $ppnRate = (float) old('ppn_rate', $order->ppn_rate ?: ($taxSetting->rate ?? 11)); $totalBeforePpn = (float) $displaySubtotalBeforePpn; $canChoosePpn = ((float) $totalPaid <= 0); $defaultUsePpn = old('use_ppn') !== null ? (bool) old('use_ppn') : ((bool) ($order->use_ppn ?? false) || ($canChoosePpn && (bool) ($taxSetting->is_active ?? false))); $baseRemainingForPayment = $canChoosePpn ? $totalBeforePpn : (float) $remainingBalance; $previewPpnAmount = $defaultUsePpn && $canChoosePpn ? round($baseRemainingForPayment * ($ppnRate / 100)) : 0; $previewRemainingBalance = $canChoosePpn ? ($baseRemainingForPayment + $previewPpnAmount) : (float) $remainingBalance; @endphp
{{-- Order Details --}}

Detail Order

@if($isCredit) PIUTANG @endif
No. Invoice
{{ $order->invoice_number }}
Pelanggan
{{ $order->customer_name }}
@if($isPartialPaid || ($isCredit && $totalPaid > 0))
Pembayaran Cicilan
Sudah Dibayar: Rp {{ number_format($totalPaid, 0, ',', '.') }}
Sisa: Rp {{ number_format($remainingBalance, 0, ',', '.') }}
@endif
Item Order ({{ $order->items->count() }})
@foreach($order->items as $item)
{{ $item->product_name }}

{{ $item->file_name }} • {{ $item->size_description }}

@if($item->material_name)

Bahan: {{ $item->material_name }}

@endif
Rp {{ number_format($__itemDisplaySubtotal($item), 0, ',', '.') }}
{{ $item->qty }} pcs × Rp {{ number_format($item->calculated_price, 0, ',', '.') }}
@endforeach

TOTAL
Rp {{ number_format($displayOrderTotal, 0, ',', '.') }}
@if($remainingBalance < $displayOrderTotal)
Sisa Tagihan
Rp {{ number_format($remainingBalance, 0, ',', '.') }}
@endif
{{-- Payment Form --}}

Pembayaran

@csrf

{{ $remainingBalance < $displayOrderTotal ? 'Sisa Tagihan' : 'Total Tagihan' }}

Rp {{ number_format($previewRemainingBalance, 0, ',', '.') }}

@if($canChoosePpn)
Subtotal sebelum PPN
PPN
@elseif(($order->use_ppn ?? false))
Order ini menggunakan PPN {{ rtrim(rtrim(number_format((float) ($order->ppn_rate ?? $ppnRate), 2, ',', '.'), '0'), ',') }}%. PPN sudah tersimpan di data order.
@endif
@if($isCredit)
Bayar Lunas
DP / Cicilan

Kolom ini hanya muncul saat pembayaran DP / Cicilan.

@else @endif
@error('payments')

{{ $message }}

@enderror
@foreach([10000, 20000, 50000, 100000] as $amount) @endforeach
Total Pembayaran
@if($isCredit)
Jatuh Tempo
@endif
Batal
@endsection