165 lines
10 KiB
PHP
165 lines
10 KiB
PHP
@extends('layouts.app')
|
|
|
|
@section('content')
|
|
<div class="space-y-6">
|
|
<!-- Page Header -->
|
|
<div class="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4">
|
|
<h1 class="text-2xl font-bold text-gray-900">{{ __('pettyCash.pettyCash') }}</h1>
|
|
<a href="{{ route('petty-cashes.create') }}" class="inline-flex items-center gap-2 px-4 py-2 bg-teal-600 text-white text-sm font-medium rounded-lg hover:bg-teal-700 transition-colors">
|
|
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"/></svg>
|
|
{{ __('pettyCash.create') }}
|
|
</a>
|
|
</div>
|
|
|
|
<!-- Summary Stats -->
|
|
<div class="grid grid-cols-1 sm:grid-cols-3 gap-4">
|
|
<div class="bg-white rounded-xl border border-gray-200 p-4">
|
|
<p class="text-xs font-medium text-gray-500 mb-1">{{ __('pettyCash.total_amount') }}</p>
|
|
<p class="text-lg font-bold text-gray-900">{{ format_currency((float)$totalAmount) }}</p>
|
|
</div>
|
|
<div class="bg-white rounded-xl border border-gray-200 p-4">
|
|
<p class="text-xs font-medium text-gray-500 mb-1">{{ __('pettyCash.total_expenses') }}</p>
|
|
<p class="text-lg font-bold text-red-600">{{ format_currency((float)$totalExpenses) }}</p>
|
|
</div>
|
|
<div class="bg-white rounded-xl border border-gray-200 p-4">
|
|
<p class="text-xs font-medium text-gray-500 mb-1">{{ __('pettyCash.total_remaining') }}</p>
|
|
<p class="text-lg font-bold {{ $totalRemaining > 0 ? 'text-emerald-600' : ($totalRemaining < 0 ? 'text-red-600' : 'text-gray-900') }}">{{ format_currency((float)$totalRemaining) }}</p>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Filters -->
|
|
<div class="bg-white rounded-xl border border-gray-200 p-4">
|
|
<form method="GET" action="{{ route('petty-cashes.index') }}" class="flex flex-wrap gap-3 items-end">
|
|
<div class="w-44">
|
|
<label class="block text-xs font-medium text-gray-500 mb-1">{{ __('pettyCash.project') }}</label>
|
|
<select name="project_id" class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-teal-500">
|
|
<option value="">{{ __('common.all') }}</option>
|
|
@foreach($projects as $project)
|
|
<option value="{{ $project->id }}" {{ request('project_id') == $project->id ? 'selected' : '' }}>{{ $project->name }}</option>
|
|
@endforeach
|
|
</select>
|
|
</div>
|
|
<div class="w-36">
|
|
<label class="block text-xs font-medium text-gray-500 mb-1">{{ __('pettyCash.status') }}</label>
|
|
<select name="status" class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-teal-500">
|
|
<option value="">{{ __('common.all') }}</option>
|
|
@foreach($statuses as $status)
|
|
<option value="{{ $status }}" {{ request('status') === $status ? 'selected' : '' }}>{{ __('pettyCash.' . $status) }}</option>
|
|
@endforeach
|
|
</select>
|
|
</div>
|
|
<div class="w-36">
|
|
<label class="block text-xs font-medium text-gray-500 mb-1">{{ __('common.from') }}</label>
|
|
<input type="text" name="from_date" value="{{ request('from_date') }}" placeholder="1403/01/01"
|
|
class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-teal-500">
|
|
</div>
|
|
<div class="w-36">
|
|
<label class="block text-xs font-medium text-gray-500 mb-1">{{ __('common.to') }}</label>
|
|
<input type="text" name="to_date" value="{{ request('to_date') }}" placeholder="1403/12/29"
|
|
class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-teal-500">
|
|
</div>
|
|
<button type="submit" class="px-4 py-2 bg-gray-100 text-gray-700 text-sm font-medium rounded-lg hover:bg-gray-200 transition-colors">
|
|
{{ __('common.filter') }}
|
|
</button>
|
|
<a href="{{ route('petty-cashes.index') }}" class="px-4 py-2 text-gray-500 text-sm hover:text-gray-700">{{ __('common.reset') }}</a>
|
|
</form>
|
|
</div>
|
|
|
|
<!-- Petty Cash List -->
|
|
<div class="bg-white rounded-xl border border-gray-200 overflow-hidden">
|
|
<div class="overflow-x-auto">
|
|
<table class="w-full">
|
|
<thead class="bg-gray-50 border-b border-gray-200">
|
|
<tr>
|
|
<th class="px-5 py-3 text-start text-xs font-medium text-gray-500">{{ __('pettyCash.title') }}</th>
|
|
<th class="px-5 py-3 text-start text-xs font-medium text-gray-500">{{ __('pettyCash.project') }}</th>
|
|
<th class="px-5 py-3 text-start text-xs font-medium text-gray-500">{{ __('pettyCash.amount') }}</th>
|
|
<th class="px-5 py-3 text-start text-xs font-medium text-gray-500">{{ __('pettyCash.total_expenses') }}</th>
|
|
<th class="px-5 py-3 text-start text-xs font-medium text-gray-500">{{ __('pettyCash.remaining') }}</th>
|
|
<th class="px-5 py-3 text-start text-xs font-medium text-gray-500">{{ __('pettyCash.request_date') }}</th>
|
|
<th class="px-5 py-3 text-start text-xs font-medium text-gray-500">{{ __('pettyCash.status') }}</th>
|
|
<th class="px-5 py-3 text-start text-xs font-medium text-gray-500">{{ __('common.actions') }}</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody class="divide-y divide-gray-100">
|
|
@forelse($pettyCashes as $pc)
|
|
<tr class="hover:bg-gray-50 transition-colors">
|
|
<td class="px-5 py-3">
|
|
<a href="{{ route('petty-cashes.show', $pc) }}" class="text-sm font-medium text-gray-900 hover:text-teal-600">{{ $pc->title ?? '-' }}</a>
|
|
</td>
|
|
<td class="px-5 py-3 text-sm text-gray-600">{{ $pc->project?->name ?? '-' }}</td>
|
|
<td class="px-5 py-3 text-sm font-medium text-gray-900">
|
|
{{ format_currency((float)$pc->amount, $pc->currency?->code) }}
|
|
</td>
|
|
<td class="px-5 py-3 text-sm text-red-600">
|
|
{{ format_currency((float)$pc->total_expenses, $pc->currency?->code) }}
|
|
</td>
|
|
<td class="px-5 py-3 text-sm font-medium {{ $pc->remaining > 0 ? 'text-emerald-600' : ($pc->remaining < 0 ? 'text-red-600' : 'text-gray-900') }}">
|
|
{{ $pc->remaining !== null ? format_currency((float)$pc->remaining, $pc->currency?->code) : '-' }}
|
|
</td>
|
|
<td class="px-5 py-3 text-sm text-gray-600">{{ $pc->request_date ? calendar_date($pc->request_date) : '-' }}</td>
|
|
<td class="px-5 py-3">
|
|
<span class="inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium
|
|
{{ $pc->status === 'approved' ? 'bg-emerald-50 text-emerald-700' :
|
|
($pc->status === 'rejected' ? 'bg-red-50 text-red-700' :
|
|
($pc->status === 'settled' ? 'bg-blue-50 text-blue-700' : 'bg-amber-50 text-amber-700')) }}">
|
|
{{ $pc->status_label }}
|
|
</span>
|
|
</td>
|
|
<td class="px-5 py-3">
|
|
<div class="flex items-center gap-1">
|
|
@if($pc->status === 'pending')
|
|
<button onclick="approvePC({{ $pc->id }})" class="px-2 py-1 text-xs font-medium text-emerald-700 bg-emerald-50 rounded hover:bg-emerald-100 transition-colors">{{ __('common.approve') }}</button>
|
|
<button onclick="rejectPC({{ $pc->id }})" class="px-2 py-1 text-xs font-medium text-red-700 bg-red-50 rounded hover:bg-red-100 transition-colors">{{ __('common.reject') }}</button>
|
|
@elseif($pc->status === 'approved')
|
|
<a href="{{ route('petty-cashes.create-expense', $pc) }}" class="px-2 py-1 text-xs font-medium text-teal-700 bg-teal-50 rounded hover:bg-teal-100 transition-colors">{{ __('pettyCash.add_expense') }}</a>
|
|
<button onclick="settlePC({{ $pc->id }})" class="px-2 py-1 text-xs font-medium text-blue-700 bg-blue-50 rounded hover:bg-blue-100 transition-colors">{{ __('pettyCash.settle') }}</button>
|
|
@endif
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
@empty
|
|
<tr>
|
|
<td colspan="8" class="text-center py-12 text-gray-500">{{ __('pettyCash.no_petty_cashes') }}</td>
|
|
</tr>
|
|
@endforelse
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Pagination -->
|
|
<div class="flex justify-center">
|
|
{{ $pettyCashes->withQueryString()->links() }}
|
|
</div>
|
|
</div>
|
|
|
|
@push('scripts')
|
|
<script>
|
|
async function approvePC(id) {
|
|
const res = await fetch(`/petty-cashes/${id}/approve`, {
|
|
method: 'PUT',
|
|
headers: { 'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').content, 'Accept': 'application/json' }
|
|
});
|
|
if ((await res.json()).success) location.reload();
|
|
}
|
|
async function rejectPC(id) {
|
|
if (!confirm('{{ __("common.areYouSure") }}')) return;
|
|
const res = await fetch(`/petty-cashes/${id}/reject`, {
|
|
method: 'PUT',
|
|
headers: { 'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').content, 'Accept': 'application/json' }
|
|
});
|
|
if ((await res.json()).success) location.reload();
|
|
}
|
|
async function settlePC(id) {
|
|
if (!confirm('{{ __("pettyCash.confirm_settle") }}')) return;
|
|
const res = await fetch(`/petty-cashes/${id}/settle`, {
|
|
method: 'PUT',
|
|
headers: { 'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').content, 'Accept': 'application/json' }
|
|
});
|
|
if ((await res.json()).success) location.reload();
|
|
}
|
|
</script>
|
|
@endpush
|
|
@endsection
|