No | Bayar | Kota | Customer | No Nota | Tanggal | Tenggat | Grand Total | Status | Metode Pembayaran | Jumlah Terbayar | Sisa | |
---|---|---|---|---|---|---|---|---|---|---|---|---|
{{ $loop->iteration }} | @if(Auth::user()->role_id == 1)@else | - | @endif{{ $item->customer->kota->nama ?? '-' }} | {{ $item->customer->nama ?? '-' }} | {{ $item->no_faktur ?? '-' }} | {{ date('d-m-Y', strtotime($item->tanggal_faktur)) ?? '-' }} | @php // Jika $item->jatuh_tempo sudah format tanggal, tampilkan langsung $tenggat = $item->jatuh_tempo; if (preg_match('/^\d{4}-\d{2}-\d{2}$/', $tenggat)) { $tenggat = date('d-m-Y', strtotime($tenggat)); } else { // Jika integer, hitung dari tanggal_faktur $tenggat = date('d-m-Y', strtotime($item->tanggal_faktur . ' + ' . (int)$item->jatuh_tempo . ' days')); } @endphp {{ $tenggat ?? '-' }} | @php $grand_total = 0; foreach ($item->barangTransaksis as $barang) { $subtotal = $barang->jumlah * $barang->harga_jual; $diskon = $barang->diskon > 0 ? ($subtotal * $barang->diskon / 100) : 0; $setelah_diskon = $subtotal - $diskon; $pajak = $barang->pajak > 0 ? ($setelah_diskon * $barang->pajak / 100) : 0; $total = $setelah_diskon + $pajak; $grand_total += $total; } $grand_total += ($item->biaya_ekspedisi ?? 0); $uang_muka = $item->pembayarans->where('status_pembayaran', 'Uang Muka')->sum('jumlah_bayar'); $termin1 = $item->pembayarans->where('status_pembayaran', 'Pembayaran Pertama')->sum('jumlah_bayar'); $termin2 = $item->pembayarans->where('status_pembayaran', 'Pembayaran Kedua')->sum('jumlah_bayar'); $lunas = $item->pembayarans->where('status_pembayaran', 'Lunas')->sum('jumlah_bayar'); $total_bayar = $uang_muka + $termin1 + $termin2 + $lunas; $retur_potong_nota = 0; if (isset($item->returPenjualan)) { foreach ($item->returPenjualan as $retur) { foreach ($retur->barangTransaksis as $barangRetur) { if ($barangRetur->tipe_retur == 'potong_nota') { $retur_potong_nota += $barangRetur->harga_total; } } } } $sisa = $grand_total - ($total_bayar + $retur_potong_nota); if ($sisa < 0) $sisa = 0; @endphp Rp {{ number_format($grand_total, 0, ',', '.') }} | @php $status = strtolower($item->status_pembayaran); @endphp @if ($status == 'lunas') Lunas @elseif ($total_bayar == 0) Belum ada pembayaran @elseif ($uang_muka > 0 && $termin1 == 0 && $termin2 == 0 && $lunas == 0) Uang Muka @else {{ str_replace('_', ' ', $item->status_pembayaran) ?? '-' }} @endif | {{ $item->pembayarans->last()->metode_pembayaran ?? '-' }} |
@php
$is_tunai = strtolower($item->pembayarans->last()->metode_pembayaran ?? '') == 'cash' ||
strtolower($item->pembayarans->last()->metode_pembayaran ?? '') == 'tunai';
$is_lunas = strtolower($item->status_pembayaran) == 'lunas';
@endphp
@if($is_tunai && $is_lunas)
Lunas:
Rp {{ number_format($grand_total, 0, ',', '.') }}
@else
@if ($total_bayar > 0)
@if ($uang_muka > 0)
@endif
@if ($retur_potong_nota > 0)
Uang Muka:
Rp {{ number_format($uang_muka, 0, ',', '.') }}
@endif
@if ($termin1 > 0)
Pembayaran Pertama:
Rp {{ number_format($termin1, 0, ',', '.') }}
@endif
@if ($termin2 > 0)
Pembayaran Kedua:
Rp {{ number_format($termin2, 0, ',', '.') }}
@endif
@if ($lunas > 0)
Lunas:
Rp {{ number_format($lunas, 0, ',', '.') }}
@endif
Retur Potong Nota:
Rp {{ number_format($retur_potong_nota, 0, ',', '.') }}
- {{ date('d-m-Y', strtotime($item->tanggal_faktur)) }}
@endif
@if ($total_bayar == 0 && $retur_potong_nota == 0)
-
@endif
@endif
|
@if($is_tunai && $is_lunas) Rp 0 @else Rp {{ number_format($sisa, 0, ',', '.') }} @endif |