168 lines
11 KiB
PHP
168 lines
11 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">{{ __('expense.expenses') }}</h1>
|
|
<a href="{{ route('expenses.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>
|
|
{{ __('expense.new') }}
|
|
</a>
|
|
</div>
|
|
|
|
<!-- Filters -->
|
|
<div class="bg-white rounded-xl border border-gray-200 p-4">
|
|
<form method="GET" action="{{ route('expenses.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">{{ __('expense.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">{{ __('expense.category') }}</label>
|
|
<select name="category" 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($categories as $cat)
|
|
<option value="{{ $cat }}" {{ request('category') === $cat ? 'selected' : '' }}">{{ __('expense.category_' . $cat) }}</option>
|
|
@endforeach
|
|
</select>
|
|
</div>
|
|
<div class="w-36">
|
|
<label class="block text-xs font-medium text-gray-500 mb-1">{{ __('expense.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' : '' }}">{{ __('expense.status_' . $status) }}</option>
|
|
@endforeach
|
|
</select>
|
|
</div>
|
|
<div class="w-36">
|
|
<label class="block text-xs font-medium text-gray-500 mb-1">{{ __('expense.from_date') }}</label>
|
|
<x-date-input name="from_date" :value="request('from_date')" />
|
|
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">{{ __('expense.to_date') }}</label>
|
|
<x-date-input name="to_date" :value="request('to_date')" />
|
|
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>
|
|
</form>
|
|
</div>
|
|
|
|
<!-- Expense 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">{{ __('expense.title') }}</th>
|
|
<th class="px-5 py-3 text-start text-xs font-medium text-gray-500">{{ __('expense.project') }}</th>
|
|
<th class="px-5 py-3 text-start text-xs font-medium text-gray-500">{{ __('expense.amount') }}</th>
|
|
<th class="px-5 py-3 text-start text-xs font-medium text-gray-500">{{ __('expense.category') }}</th>
|
|
<th class="px-5 py-3 text-start text-xs font-medium text-gray-500">{{ __('expense.date') }}</th>
|
|
<th class="px-5 py-3 text-start text-xs font-medium text-gray-500">{{ __('expense.status') }}</th>
|
|
<th class="px-5 py-3 text-start text-xs font-medium text-gray-500 w-28">{{ __('common.actions') }}</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody class="divide-y divide-gray-100">
|
|
@forelse($expenses as $expense)
|
|
<tr class="hover:bg-gray-50 transition-colors group">
|
|
<td class="px-5 py-3">
|
|
<div class="flex items-center gap-2">
|
|
<a href="{{ route('expenses.show', $expense) }}" class="text-sm font-medium text-gray-900 hover:text-teal-600 transition-colors">
|
|
{{ $expense->title ?? '-' }}
|
|
</a>
|
|
{{-- Attachment indicator --}}
|
|
@if($expense->attachments_count > 0 || $expense->receipt_path)
|
|
<span class="inline-flex items-center" title="{{ __('attachment.attachments') }}">
|
|
<svg class="w-3.5 h-3.5 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15.172 7l-6.586 6.586a2 2 0 102.828 2.828l6.414-6.586a4 4 0 00-5.656-5.656l-6.415 6.585a6 6 0 108.486 8.486L20.5 13"/></svg>
|
|
@if($expense->attachments_count > 0)
|
|
<span class="text-[10px] text-gray-400 ms-0.5">{{ $expense->attachments_count }}</span>
|
|
@endif
|
|
</span>
|
|
@endif
|
|
</div>
|
|
</td>
|
|
<td class="px-5 py-3 text-sm text-gray-600">{{ $expense->project?->name }}</td>
|
|
<td class="px-5 py-3 text-sm font-medium text-gray-900">
|
|
{{ format_currency((float)$expense->amount, $expense->currency?->code) }}
|
|
@if($expense->original_amount)
|
|
<span class="text-xs text-gray-400 block">({{ format_currency((float)$expense->original_amount, $expense->currency?->code) }})</span>
|
|
@endif
|
|
</td>
|
|
<td class="px-5 py-3 text-sm text-gray-600">{{ __('expense.category_' . $expense->category) }}</td>
|
|
<td class="px-5 py-3 text-sm text-gray-600">{{ $expense->expense_date ? calendar_date($expense->expense_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
|
|
{{ $expense->status === 'approved' ? 'bg-emerald-50 text-emerald-700' :
|
|
($expense->status === 'rejected' ? 'bg-red-50 text-red-700' :
|
|
($expense->status === 'paid' ? 'bg-blue-50 text-blue-700' : 'bg-amber-50 text-amber-700')) }}">
|
|
{{ $expense->status_label }}
|
|
</span>
|
|
</td>
|
|
<td class="px-5 py-3">
|
|
<div class="flex items-center gap-1">
|
|
{{-- View button --}}
|
|
<a href="{{ route('expenses.show', $expense) }}" class="p-1.5 text-gray-400 hover:text-teal-600 hover:bg-teal-50 rounded-lg transition-colors" title="{{ __('common.view') ?? 'مشاهده' }}">
|
|
<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="M15 12a3 3 0 11-6 0 3 3 0 016 0z"/><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"/></svg>
|
|
</a>
|
|
{{-- Edit button --}}
|
|
<a href="{{ route('expenses.edit', $expense) }}" class="p-1.5 text-gray-400 hover:text-blue-600 hover:bg-blue-50 rounded-lg transition-colors" title="{{ __('common.edit') }}">
|
|
<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="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"/></svg>
|
|
</a>
|
|
@if($expense->status === 'pending')
|
|
<button onclick="approveExpense({{ $expense->id }})" class="p-1.5 text-gray-400 hover:text-emerald-600 hover:bg-emerald-50 rounded-lg transition-colors" title="{{ __('expense.approve') }}">
|
|
<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="M5 13l4 4L19 7"/></svg>
|
|
</button>
|
|
<button onclick="rejectExpense({{ $expense->id }})" class="p-1.5 text-gray-400 hover:text-red-600 hover:bg-red-50 rounded-lg transition-colors" title="{{ __('expense.reject') }}">
|
|
<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="M6 18L18 6M6 6l12 12"/></svg>
|
|
</button>
|
|
@endif
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
@empty
|
|
<tr>
|
|
<td colspan="7" class="text-center py-12 text-gray-500">{{ __('expense.no_expenses') }}</td>
|
|
</tr>
|
|
@endforelse
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Pagination -->
|
|
<div class="flex justify-center">
|
|
{{ $expenses->withQueryString()->links() }}
|
|
</div>
|
|
</div>
|
|
|
|
@push('scripts')
|
|
<script>
|
|
async function approveExpense(id) {
|
|
const res = await fetch(`/expenses/${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 rejectExpense(id) {
|
|
if (!confirm('{{ __("expense.confirm_reject") }}')) return;
|
|
const res = await fetch(`/expenses/${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();
|
|
}
|
|
</script>
|
|
@endpush
|
|
@endsection
|