akuntansi-sia/resources/views/partials/table_penjualan.blade.php

108 lines
5.0 KiB
PHP

<div class="table-responsive">
<table class="table table-bordered table-striped table-hover mb-0">
<thead class="thead-light">
<tr>
<th class="text-center" width="50">#</th>
<th>Tanggal / Hari</th>
<th>Barang</th>
<th class="text-right">Jumlah</th>
<th class="text-right">Total</th>
@if(isset($showBranch) && $showBranch)
<th class="text-center">Cabang</th>
@endif
@if(!isset($readonly) || !$readonly)
<th class="text-center" width="120">Aksi</th>
@endif
</tr>
</thead>
<tbody>
@php
$currentDate = '';
$dailyTotal = 0;
@endphp
@forelse($sales as $index => $s)
@php
\Carbon\Carbon::setLocale('id');
$date = \Carbon\Carbon::parse($s->date);
$dateString = $date->translatedFormat('l, d F Y');
$dailyTotal += $s->total_price;
@endphp
@if($dateString !== $currentDate)
@php $currentDate = $dateString; @endphp
@php
$colspan = 5;
if(isset($showBranch) && $showBranch) $colspan++;
if(!isset($readonly) || !$readonly) $colspan++;
@endphp
<tr class="bg-light font-weight-bold">
<td colspan="{{ $colspan }}">{{ $dateString }}</td>
</tr>
@endif
<tr>
<td class="text-center">{{ $index + 1 }}</td>
<td></td>
<td><strong>{{ $s->product ? $s->product->name : $s->item }}</strong></td>
<td class="text-right">{{ $s->quantity }}</td>
<td class="text-right">Rp{{ number_format($s->total_price, 0, ',', '.') }}</td>
@if(isset($showBranch) && $showBranch)
<td class="text-center"><span class="badge badge-info">{{ $s->branch }}</span></td>
@endif
@if(!isset($readonly) || !$readonly)
<td class="text-center">
<form action="/laporan/penjualan/{{ $s->id }}" method="POST" class="d-inline" onsubmit="return confirm('Yakin ingin menghapus?')">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-danger btn-sm" title="Hapus">
<i class="fas fa-trash"></i>
</button>
</form>
</td>
@endif
</tr>
@php
// Determine if the next item has a different date, or if this is the last item
$nextDateString = '';
if(isset($sales[$index + 1])) {
$nextDate = \Carbon\Carbon::parse($sales[$index + 1]->date);
$nextDateString = $nextDate->translatedFormat('l, d F Y');
}
@endphp
@if($loop->last || $nextDateString !== $currentDate)
@php
$subtotalColspan = 4;
if(isset($showBranch) && $showBranch) $subtotalColspan++;
@endphp
<tr class="bg-light font-weight-boldtext-muted">
<td colspan="{{ $subtotalColspan }}" class="text-right text-muted" style="font-size: 0.9rem;">Total Pendapatan {{ $currentDate }}:</td>
<td class="text-right text-dark" style="font-size: 0.95rem; font-weight: bold;">Rp{{ number_format($dailyTotal, 0, ',', '.') }}</td>
@if(!isset($readonly) || !$readonly)
<td></td>
@endif
</tr>
@php $dailyTotal = 0; @endphp <!-- Reset for the next day -->
@endif
@empty
<tr>
<td colspan="6" class="text-center text-muted py-4">Belum ada data transaksi.</td>
</tr>
@endforelse
</tbody>
@if(!$sales->isEmpty())
<tfoot class="bg-light">
@php
$totalKeseluruhan = $sales->sum('total_price');
$footerColspan = 4;
if(isset($showBranch) && $showBranch) $footerColspan++;
@endphp
<tr class="font-weight-bold">
<td colspan="{{ $footerColspan }}" class="text-right">TOTAL KESELURUHAN:</td>
<td class="text-right text-orange" style="font-size: 1.1rem;">Rp{{ number_format($totalKeseluruhan, 0, ',', '.') }}</td>
@if(!isset($readonly) || !$readonly)
<td></td>
@endif
</tr>
</tfoot>
@endif
</table>
</div>