269 lines
16 KiB
PHP
269 lines
16 KiB
PHP
<?php $__env->startSection('content'); ?>
|
|
<div class="max-w-4xl mx-auto space-y-6">
|
|
<!-- Page Header -->
|
|
<div class="flex items-center gap-4">
|
|
<a href="<?php echo e(route('expenses.index')); ?>" class="p-2 text-gray-500 hover:text-gray-900 hover:bg-gray-100 rounded-lg transition-colors">
|
|
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 19l-7-7m0 0l7-7m-7 7h18"/></svg>
|
|
</a>
|
|
<h1 class="text-2xl font-bold text-gray-900"><?php echo e($expense->title); ?></h1>
|
|
<span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium
|
|
<?php echo e($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'))); ?>">
|
|
<?php echo e($expense->status_label); ?>
|
|
|
|
</span>
|
|
<div class="ms-auto flex items-center gap-2">
|
|
<a href="<?php echo e(route('expenses.edit', $expense)); ?>" class="px-3 py-1.5 text-sm font-medium text-teal-700 bg-teal-50 rounded-lg hover:bg-teal-100 transition-colors">
|
|
<?php echo e(__('common.edit')); ?>
|
|
|
|
</a>
|
|
<?php if($expense->status === 'pending'): ?>
|
|
<button onclick="approveExpense(<?php echo e($expense->id); ?>)" class="px-3 py-1.5 text-sm font-medium text-emerald-700 bg-emerald-50 rounded-lg hover:bg-emerald-100 transition-colors">
|
|
<?php echo e(__('expense.approve')); ?>
|
|
|
|
</button>
|
|
<button onclick="rejectExpense(<?php echo e($expense->id); ?>)" class="px-3 py-1.5 text-sm font-medium text-red-700 bg-red-50 rounded-lg hover:bg-red-100 transition-colors">
|
|
<?php echo e(__('expense.reject')); ?>
|
|
|
|
</button>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Expense Details -->
|
|
<div class="bg-white rounded-xl border border-gray-200 overflow-hidden">
|
|
<div class="grid grid-cols-1 md:grid-cols-2">
|
|
<!-- Left Column -->
|
|
<div class="p-6 space-y-4 border-e border-gray-100">
|
|
<div>
|
|
<p class="text-xs font-medium text-gray-400 mb-1"><?php echo e(__('expense.project')); ?></p>
|
|
<p class="text-sm font-medium text-gray-900"><?php echo e($expense->project?->name ?? '-'); ?></p>
|
|
</div>
|
|
<div>
|
|
<p class="text-xs font-medium text-gray-400 mb-1"><?php echo e(__('expense.category')); ?></p>
|
|
<p class="text-sm text-gray-700"><?php echo e(__('expense.category_' . $expense->category)); ?></p>
|
|
</div>
|
|
<div>
|
|
<p class="text-xs font-medium text-gray-400 mb-1"><?php echo e(__('expense.amount')); ?></p>
|
|
<p class="text-lg font-bold text-gray-900"><?php echo e(format_currency((float)$expense->amount, $expense->currency?->code)); ?></p>
|
|
<?php if($expense->original_amount && $expense->original_amount != $expense->amount): ?>
|
|
<p class="text-xs text-gray-400 mt-0.5">(<?php echo e(format_currency((float)$expense->original_amount, $expense->currency?->code)); ?>)</p>
|
|
<?php endif; ?>
|
|
</div>
|
|
<div>
|
|
<p class="text-xs font-medium text-gray-400 mb-1"><?php echo e(__('expense.date')); ?></p>
|
|
<p class="text-sm text-gray-700"><?php echo e($expense->expense_date ? calendar_date($expense->expense_date) : '-'); ?></p>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Right Column -->
|
|
<div class="p-6 space-y-4">
|
|
<?php if($expense->invoice_number): ?>
|
|
<div>
|
|
<p class="text-xs font-medium text-gray-400 mb-1"><?php echo e(__('expense.invoice_number')); ?></p>
|
|
<p class="text-sm text-gray-700" dir="ltr"><?php echo e($expense->invoice_number); ?></p>
|
|
</div>
|
|
<?php endif; ?>
|
|
<div>
|
|
<p class="text-xs font-medium text-gray-400 mb-1"><?php echo e(__('expense.requested_by') ?? __('common.project')); ?></p>
|
|
<p class="text-sm text-gray-700"><?php echo e($expense->requestedBy?->name ?? '-'); ?></p>
|
|
</div>
|
|
<?php if($expense->approvedBy): ?>
|
|
<div>
|
|
<p class="text-xs font-medium text-gray-400 mb-1"><?php echo e(__('expense.approved_by') ?? 'تأییدکننده'); ?></p>
|
|
<p class="text-sm text-gray-700"><?php echo e($expense->approvedBy?->name); ?></p>
|
|
</div>
|
|
<?php endif; ?>
|
|
<?php if($expense->approval_date): ?>
|
|
<div>
|
|
<p class="text-xs font-medium text-gray-400 mb-1"><?php echo e(__('expense.approval_date') ?? 'تاریخ تأیید'); ?></p>
|
|
<p class="text-sm text-gray-700"><?php echo e(calendar_date($expense->approval_date)); ?></p>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Description -->
|
|
<?php if($expense->description): ?>
|
|
<div class="px-6 py-4 border-t border-gray-100 bg-gray-50/50">
|
|
<p class="text-xs font-medium text-gray-400 mb-1"><?php echo e(__('expense.description')); ?></p>
|
|
<p class="text-sm text-gray-700 whitespace-pre-line"><?php echo e($expense->description); ?></p>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<!-- Legacy Receipt -->
|
|
<?php if($expense->receipt_path): ?>
|
|
<div class="bg-white rounded-xl border border-gray-200 p-6">
|
|
<h3 class="text-sm font-semibold text-gray-900 mb-3"><?php echo e(__('expense.receipt')); ?></h3>
|
|
<div class="flex items-center gap-3 p-3 bg-gray-50 rounded-lg border border-gray-200">
|
|
<?php if(str_ends_with(strtolower($expense->receipt_path), '.pdf')): ?>
|
|
<div class="w-10 h-10 bg-red-50 rounded-lg flex items-center justify-center">
|
|
<svg class="w-5 h-5 text-red-500" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 21h10a2 2 0 002-2V9.414a1 1 0 00-.293-.707l-5.414-5.414A1 1 0 0012.586 3H7a2 2 0 00-2 2v14a2 2 0 002 2z"/></svg>
|
|
</div>
|
|
<?php else: ?>
|
|
<div class="w-16 h-16 rounded-lg overflow-hidden border border-gray-200">
|
|
<img src="<?php echo e(Storage::url($expense->receipt_path)); ?>" alt="Receipt" class="w-full h-full object-cover">
|
|
</div>
|
|
<?php endif; ?>
|
|
<div class="flex-1">
|
|
<p class="text-sm font-medium text-gray-900"><?php echo e(basename($expense->receipt_path)); ?></p>
|
|
</div>
|
|
<a href="<?php echo e(Storage::url($expense->receipt_path)); ?>" target="_blank" class="px-3 py-1.5 text-xs font-medium text-teal-700 bg-teal-50 rounded-lg hover:bg-teal-100 transition-colors">
|
|
<?php echo e(__('letter.download')); ?>
|
|
|
|
</a>
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<!-- Attachments -->
|
|
<div class="bg-white rounded-xl border border-gray-200 p-6">
|
|
<div class="flex items-center justify-between mb-4">
|
|
<h3 class="text-sm font-semibold text-gray-900"><?php echo e(__('attachment.attachments')); ?></h3>
|
|
<button type="button" onclick="document.getElementById('uploadSection').classList.toggle('hidden')"
|
|
class="px-3 py-1.5 text-xs font-medium text-teal-700 bg-teal-50 rounded-lg hover:bg-teal-100 transition-colors">
|
|
+ <?php echo e(__('attachment.add_file')); ?>
|
|
|
|
</button>
|
|
</div>
|
|
|
|
<!-- Upload Section (hidden by default) -->
|
|
<div id="uploadSection" class="hidden mb-4 p-4 bg-gray-50 rounded-lg border border-dashed border-gray-300">
|
|
<form id="uploadForm" enctype="multipart/form-data">
|
|
<?php echo csrf_field(); ?>
|
|
<input type="hidden" name="attachable_type" value="App\Models\Expense">
|
|
<input type="hidden" name="attachable_id" value="<?php echo e($expense->id); ?>">
|
|
<input type="hidden" name="category" value="receipt">
|
|
<div class="flex items-center gap-3">
|
|
<input type="file" name="files[]" multiple accept=".jpg,.jpeg,.png,.pdf,.doc,.docx"
|
|
class="flex-1 text-sm text-gray-500 file:me-4 file:py-2 file:px-4 file:rounded-lg file:border-0 file:text-sm file:font-medium file:bg-teal-50 file:text-teal-700 hover:file:bg-teal-100">
|
|
<button type="submit" class="px-4 py-2 bg-teal-600 text-white text-sm font-medium rounded-lg hover:bg-teal-700 transition-colors">
|
|
<?php echo e(__('common.upload')); ?>
|
|
|
|
</button>
|
|
</div>
|
|
<p class="text-xs text-gray-400 mt-2"><?php echo e(__('attachment.max_files_help')); ?></p>
|
|
</form>
|
|
</div>
|
|
|
|
<!-- Attachment List -->
|
|
<div id="attachmentList" class="space-y-2">
|
|
<?php $__empty_1 = true; $__currentLoopData = $expense->attachments; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $attachment): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
|
|
<div class="flex items-center gap-3 p-3 bg-gray-50 rounded-lg border border-gray-200 hover:bg-gray-100 transition-colors" id="attachment-<?php echo e($attachment->id); ?>">
|
|
<?php if($attachment->is_image): ?>
|
|
<div class="w-12 h-12 rounded-lg overflow-hidden border border-gray-200 flex-shrink-0">
|
|
<img src="<?php echo e($attachment->url); ?>" alt="<?php echo e($attachment->file_name); ?>" class="w-full h-full object-cover">
|
|
</div>
|
|
<?php elseif($attachment->is_pdf): ?>
|
|
<div class="w-12 h-12 bg-red-50 rounded-lg flex items-center justify-center flex-shrink-0">
|
|
<svg class="w-6 h-6 text-red-500" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 21h10a2 2 0 002-2V9.414a1 1 0 00-.293-.707l-5.414-5.414A1 1 0 0012.586 3H7a2 2 0 00-2 2v14a2 2 0 002 2z"/></svg>
|
|
</div>
|
|
<?php else: ?>
|
|
<div class="w-12 h-12 bg-blue-50 rounded-lg flex items-center justify-center flex-shrink-0">
|
|
<svg class="w-6 h-6 text-blue-500" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"/></svg>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<div class="flex-1 min-w-0">
|
|
<p class="text-sm font-medium text-gray-900 truncate"><?php echo e($attachment->file_name); ?></p>
|
|
<p class="text-xs text-gray-400"><?php echo e($attachment->formatted_size); ?> • <?php echo e($attachment->created_at?->format('Y/m/d H:i')); ?></p>
|
|
</div>
|
|
|
|
<div class="flex items-center gap-2">
|
|
<a href="<?php echo e(route('attachments.download', $attachment)); ?>" class="p-1.5 text-teal-600 hover:bg-teal-50 rounded-lg transition-colors" title="<?php echo e(__('letter.download')); ?>">
|
|
<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 10v6m0 0l-3-3m3 3l3-3m2 8H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"/></svg>
|
|
</a>
|
|
<button type="button" onclick="deleteAttachment(<?php echo e($attachment->id); ?>)" class="p-1.5 text-red-500 hover:bg-red-50 rounded-lg transition-colors" title="<?php echo e(__('common.delete')); ?>">
|
|
<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="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"/></svg>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
|
|
<div class="text-center py-8">
|
|
<svg class="w-10 h-10 mx-auto text-gray-300 mb-2" 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>
|
|
<p class="text-sm text-gray-400"><?php echo e(__('attachment.no_attachments')); ?></p>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Image Preview Modal -->
|
|
<div id="imagePreviewModal" class="hidden fixed inset-0 z-50 flex items-center justify-center bg-black/70" onclick="this.classList.add('hidden')">
|
|
<img id="previewImage" src="" alt="Preview" class="max-w-[90vw] max-h-[90vh] rounded-lg shadow-xl">
|
|
</div>
|
|
</div>
|
|
|
|
<?php $__env->startPush('scripts'); ?>
|
|
<script>
|
|
// Upload form
|
|
document.getElementById('uploadForm')?.addEventListener('submit', async function(e) {
|
|
e.preventDefault();
|
|
const formData = new FormData(this);
|
|
try {
|
|
const res = await fetch('<?php echo e(route("attachments.store")); ?>', {
|
|
method: 'POST',
|
|
headers: { 'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').content, 'Accept': 'application/json' },
|
|
body: formData
|
|
});
|
|
const data = await res.json();
|
|
if (data.success) {
|
|
location.reload();
|
|
} else {
|
|
alert(data.message || '<?php echo e(__("common.error")); ?>');
|
|
}
|
|
} catch (err) {
|
|
alert('<?php echo e(__("common.error")); ?>');
|
|
}
|
|
});
|
|
|
|
// Delete attachment
|
|
async function deleteAttachment(id) {
|
|
if (!confirm('<?php echo e(__("common.confirm_delete")); ?>')) return;
|
|
try {
|
|
const res = await fetch(`/attachments/${id}`, {
|
|
method: 'DELETE',
|
|
headers: { 'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').content, 'Accept': 'application/json' }
|
|
});
|
|
const data = await res.json();
|
|
if (data.success) {
|
|
const el = document.getElementById('attachment-' + id);
|
|
if (el) el.remove();
|
|
}
|
|
} catch (err) {
|
|
alert('<?php echo e(__("common.error")); ?>');
|
|
}
|
|
}
|
|
|
|
// Approve / Reject
|
|
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('<?php echo e(__("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();
|
|
}
|
|
|
|
// Image preview on click
|
|
document.querySelectorAll('#attachmentList img').forEach(img => {
|
|
img.style.cursor = 'pointer';
|
|
img.addEventListener('click', (e) => {
|
|
e.stopPropagation();
|
|
document.getElementById('previewImage').src = img.src;
|
|
document.getElementById('imagePreviewModal').classList.remove('hidden');
|
|
});
|
|
});
|
|
</script>
|
|
<?php $__env->stopPush(); ?>
|
|
<?php $__env->stopSection(); ?>
|
|
|
|
<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\xampp\htdocs\projectra\resources\views/expenses/show.blade.php ENDPATH**/ ?>
|