MIF_E31220412/resources/views/admin/riwayat.blade.php

124 lines
6.5 KiB
PHP

@extends('layouts.app')
@section('title', 'Riwayat Sewa - Admin INUFA')
@section('header', 'Manajemen Riwayat Sewa')
@section('content')
<div class="bg-white rounded-lg shadow-lg p-6">
@if(count($sewas) > 0)
<div class="overflow-x-auto">
<table class="min-w-full bg-white">
<thead>
<tr class="bg-gray-100">
<th class="py-3 px-4 text-left">No</th>
<th class="py-3 px-4 text-left">Tanggal</th>
<th class="py-3 px-4 text-left">Customer</th>
<th class="py-3 px-4 text-left">Paket</th>
<th class="py-3 px-4 text-left">Total Harga</th>
<th class="py-3 px-4 text-left">Nominal Pembayaran</th>
<th class="py-3 px-4 text-left">Sisa Pembayaran</th>
<th class="py-3 px-4 text-left">Status</th>
<th class="py-3 px-4 text-center">Aksi</th>
</tr>
</thead>
<tbody>
@foreach($sewas as $index => $sewa)
@php
$user = optional($sewa->user);
$paket = optional($sewa->paket);
$sisaPembayaran = $sewa->total_harga - ($sewa->nominal_pembayaran ?? 0);
@endphp
<tr class="border-b hover:bg-gray-50">
<td class="py-3 px-4">{{ $index + 1 }}</td>
<td class="py-3 px-4">{{ $sewa->created_at->format('d/m/Y') }}</td>
<td class="py-3 px-4">
<div class="text-sm">
<p class="font-medium text-gray-900">{{ $user->name ?? '-' }}</p>
<p class="text-gray-500">{{ $user->email ?? '-' }}</p>
</div>
</td>
<td class="py-3 px-4">{{ $paket->nama_paket ?? '-' }}</td>
<td class="py-3 px-4">Rp {{ number_format($sewa->total_harga, 0, ',', '.') }}</td>
<td class="py-3 px-4">
Rp {{ number_format($sewa->nominal_pembayaran ?? 0, 0, ',', '.') }}
</td>
<td class="py-3 px-4">
@if($sisaPembayaran > 0)
<span class="text-red-600 font-medium">
Rp {{ number_format($sisaPembayaran, 0, ',', '.') }}
</span>
@else
<span class="text-green-600 font-medium">Lunas</span>
@endif
</td>
<td class="py-3 px-4">
<span class="px-2 py-1 rounded-full text-xs font-semibold
@if($sewa->status == 'pending') bg-yellow-100 text-yellow-800
@elseif($sewa->status == 'confirmed') bg-blue-100 text-blue-800
@elseif($sewa->status == 'ongoing') bg-indigo-100 text-indigo-800
@elseif($sewa->status == 'completed') bg-green-100 text-green-800
@elseif($sewa->status == 'dibatalkan') bg-red-100 text-red-800
@endif">
{{ ucfirst($sewa->status) }}
</span>
</td>
<td class="py-3 px-4">
<div class="flex flex-col sm:flex-row justify-center sm:space-x-2 space-y-2 sm:space-y-0">
<!-- Tombol Detail -->
<a href="{{ route('admin.riwayat.show', $sewa->id) }}"
class="bg-blue-600 text-white px-3 py-1 rounded hover:bg-blue-700 text-sm">
Detail
</a>
<!-- Tombol Chat -->
<a href="{{ route('chat.show', $sewa->user_id) }}"
class="bg-green-500 text-white px-3 py-1 rounded hover:bg-green-600 text-sm">
Chat
</a>
@if($sewa->status === 'confirmed')
<!-- Tombol Tandai Selesai -->
<form action="{{ route('admin.riwayat.status', $sewa->id) }}" method="POST" class="inline">
@csrf
@method('PUT')
<input type="hidden" name="status" value="completed">
<button type="submit"
onclick="return confirm('Ubah status menjadi Completed?')"
class="bg-purple-600 text-white px-3 py-1 rounded hover:bg-purple-700 text-sm">
Tandai Selesai
</button>
</form>
@endif
@if(!in_array($sewa->status, ['completed', 'dibatalkan']))
<!-- Form Update Status -->
<form action="{{ route('admin.riwayat.status', $sewa->id) }}" method="POST">
@csrf
@method('PUT')
<select name="status"
onchange="this.form.submit()"
class="rounded-md border-gray-300 text-sm shadow-sm focus:border-blue-300 focus:ring focus:ring-blue-200 focus:ring-opacity-50">
<option value="pending" {{ $sewa->status == 'pending' ? 'selected' : '' }}>Pending</option>
<option value="confirmed" {{ $sewa->status == 'confirmed' ? 'selected' : '' }}>Confirmed</option>
<option value="ongoing" {{ $sewa->status == 'ongoing' ? 'selected' : '' }}>Ongoing</option>
<option value="completed" {{ $sewa->status == 'completed' ? 'selected' : '' }}>Completed</option>
<option value="dibatalkan" {{ $sewa->status == 'dibatalkan' ? 'selected' : '' }}>Dibatalkan</option>
</select>
</form>
@endif
</div>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@else
<div class="text-center py-8">
<p class="text-gray-500">Belum ada riwayat pemesanan</p>
</div>
@endif
</div>
@endsection