﻿@extends('layouts.app')

@section('title', 'تفاصيل الحساب البنكي')

@section('content')
<div class="container m-auto p-4 sm:p-6 lg:p-8 py-8">
    <div class="flex justify-between items-center mb-6">
        <h1 class="text-2l font-semibold text-gray-900">{{ \App\Helpers\TranslationHelper::transFromDatabase('Account Details', __('Account Details')) }}: {{ $account->account_name }}</h1>
        <div class="flex space-y-2 rtl:space-y-reverse">
            <a href="{{ route('banking.accounts.index') }}" class="bg-gray-500 hover:bg-gray-700 text-white font-bold py-2 p-4 rounded">
                <i class="fas fa-arrow-right ml-1"></i> {{ \App\Helpers\TranslationHelper::transFromDatabase('Back to List', __('Back to List')) }}
            </a>
            @permission('banking.edit')
            <a href="{{ route('banking.accounts.edit', $account) }}" class="bg-blue-600 hover:bg-blue-700 text-white font-bold py-2 p-4 rounded">
                <i class="fas fa-edit ml-1"></i> {{ \App\Helpers\TranslationHelper::transFromDatabase('Edit', __('Edit')) }}
            </a>
            @endpermission
        </div>
    </div>

    <div class="bg-white shadow-md rounded-lg overflow-hidden mb-6">
        <div class="p-6">
            <h2 class="text-l font-semibold mb-4">{{ \App\Helpers\TranslationHelper::transFromDatabase('Account Information', __('Account Information')) }}</h2>
            <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                <div>
                    <p class="text-gray-600 mb-1">{{ \App\Helpers\TranslationHelper::transFromDatabase('Bank', __('Bank')) }}:</p>
                    <p class="font-semibold">{{ $account->bank->name }}</p>
                </div>
                <div>
                    <p class="text-gray-600 mb-1">{{ \App\Helpers\TranslationHelper::transFromDatabase('Branch', __('Branch')) }}:</p>
                    <p class="font-semibold">{{ $account->branch ? $account->branch->name : \App\Helpers\TranslationHelper::transFromDatabase('Not Set', __('Not Set')) }}</p>
                </div>
                <div>
                    <p class="text-gray-600 mb-1">{{ \App\Helpers\TranslationHelper::transFromDatabase('Account Number', __('Account Number')) }}:</p>
                    <p class="font-semibold">{{ $account->account_number }}</p>
                </div>
                <div>
                    <p class="text-gray-600 mb-1">{{ \App\Helpers\TranslationHelper::transFromDatabase('Account Name', __('Account Name')) }}:</p>
                    <p class="font-semibold">{{ $account->account_name }}</p>
                </div>
                <div>
                    <p class="text-gray-600 mb-1">{{ \App\Helpers\TranslationHelper::transFromDatabase('IBAN Number', __('IBAN Number')) }}:</p>
                    <p class="font-semibold">{{ $account->iban ?? \App\Helpers\TranslationHelper::transFromDatabase('Not Set', __('Not Set')) }}</p>
                </div>
                <div>
                    <p class="text-gray-600 mb-1">{{ \App\Helpers\TranslationHelper::transFromDatabase('Currency', __('Currency')) }}:</p>
                    <p class="font-semibold">{{ $account->currency }}</p>
                </div>
                <div>
                    <p class="text-gray-600 mb-1">{{ \App\Helpers\TranslationHelper::transFromDatabase('Opening Balance', __('Opening Balance')) }}:</p>
                    <p class="font-semibold">{{ number_format($account->opening_balance, 2) }}</p>
                </div>
                <div>
                    <p class="text-gray-600 mb-1">{{ \App\Helpers\TranslationHelper::transFromDatabase('Current Balance', __('Current Balance')) }}:</p>
                    <p class="font-semibold">{{ number_format($account->current_balance, 2) }}</p>
                </div>
                <div>
                    <p class="text-gray-600 mb-1">{{ \App\Helpers\TranslationHelper::transFromDatabase('Opening Date', __('Opening Date')) }}:</p>
                    <p class="font-semibold">{{ $account->opening_date }}</p>
                </div>
                <div>
                    <p class="text-gray-600 mb-1">{{ \App\Helpers\TranslationHelper::transFromDatabase('Status', __('Status')) }}:</p>
                    <p class="font-semibold">
                        @if($account->is_active)
                        <span class="p-2 inline-flex text-s leading-5 font-semibold rounded-full bg-green-100 text-green-800">
                            {{ \App\Helpers\TranslationHelper::transFromDatabase('Active', __('Active')) }}
                        </span>
                        @else
                        <span class="p-2 inline-flex text-s leading-5 font-semibold rounded-full bg-red-100 text-red-800">
                            غير {{ \App\Helpers\TranslationHelper::transFromDatabase('Active', __('Active')) }}
                        </span>
                        @endif
                    </p>
                </div>
                <div>
                    <p class="text-gray-600 mb-1">{{ \App\Helpers\TranslationHelper::transFromDatabase('Chart of Account', __('Chart of Account')) }}:</p>
                    <p class="font-semibold">{{ $account->chartOfAccount->name }} ({{ $account->chartOfAccount->code }})</p>
                </div>
            </div>
            
            @if($account->notes)
            <div class="mt-4">
                <p class="text-gray-600 mb-1">{{ \App\Helpers\TranslationHelper::transFromDatabase('Notes', __('Notes')) }}:</p>
                <p>{{ $account->notes }}</p>
            </div>
            @endif
        </div>
    </div>

    <div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-6">
        <div class="bg-white shadow-md rounded-lg overflow-hidden">
            <div class="p-6">
                <div class="flex justify-between items-center mb-4">
                    <h2 class="text-l font-semibold">{{ \App\Helpers\TranslationHelper::transFromDatabase('Bank Deposits', __('Bank Deposits')) }}</h2>
                    @permission('banking.create')
                    <a href="{{ route('banking.deposits.create', ['account_id' => $account->id]) }}" class="bg-green-600 hover:bg-green-700 text-white font-bold py-2 p-4 rounded">
                        <i class="fas fa-plus ml-1"></i> {{ \App\Helpers\TranslationHelper::transFromDatabase('New Deposit', __('New Deposit')) }}
                    </a>
                    @endpermission
                </div>
                <div class="overflow--auto">
                    <table class="min-w-full divide-y divide-gray-200">
                        <thead class="bg-gray-50">
                            <tr>
                                <th scope="col" class="p-6 py-3 text-right text-s font-medium text-gray-500 uppercase tracking-wider">
                                    التاريخ
                                </th>
                                <th scope="col" class="p-6 py-3 text-right text-s font-medium text-gray-500 uppercase tracking-wider">
                                    المبلغ
                                </th>
                                <th scope="col" class="p-6 py-3 text-right text-s font-medium text-gray-500 uppercase tracking-wider">
                                    الحالة
                                </th>
                            </tr>
                        </thead>
                        <tbody class="bg-white divide-y divide-gray-200">
                            @forelse($deposits as $deposit)
                            <tr>
                                <td class="p-6 py-4 whitespace-nowrap">
                                    <div class="text-sm text-gray-900">{{ $deposit->deposit_date }}</div>
                                </td>
                                <td class="p-6 py-4 whitespace-nowrap">
                                    <div class="text-sm text-gray-900">{{ number_format($deposit->amount, 2) }}</div>
                                </td>
                                <td class="p-6 py-4 whitespace-nowrap">
                                    @if($deposit->status == 'pending')
                                    <span class="p-2 inline-flex text-s leading-5 font-semibold rounded-full bg-yellow-100 text-yellow-800">
                                        {{ \App\Helpers\TranslationHelper::transFromDatabase('Pending', __('Pending')) }}
                                    </span>
                                    @elseif($deposit->status == 'approved')
                                    <span class="p-2 inline-flex text-s leading-5 font-semibold rounded-full bg-green-100 text-green-800">
                                        {{ \App\Helpers\TranslationHelper::transFromDatabase('Approved', __('Approved')) }}
                                    </span>
                                    @elseif($deposit->status == 'rejected')
                                    <span class="p-2 inline-flex text-s leading-5 font-semibold rounded-full bg-red-100 text-red-800">
                                        {{ \App\Helpers\TranslationHelper::transFromDatabase('Rejected', __('Rejected')) }}
                                    </span>
                                    @endif
                                </td>
                            </tr>
                            @empty
                            <tr>
                                <td colspan="3" class="p-6 py-4 whitespace-nowrap text-sm text-gray-500 text-center">
                                    {{ \App\Helpers\TranslationHelper::transFromDatabase('No Deposits Registered', __('No Deposits Registered')) }}
                                </td>
                            </tr>
                            @endforelse
                        </tbody>
                    </table>
                </div>
                <div class="mt-4 text-center">
                    <a href="{{ route('banking.deposits.index', ['account_id' => $account->id]) }}" class="text-blue-600 hover:text-blue-900">
                        {{ \App\Helpers\TranslationHelper::transFromDatabase('View All Deposits', __('View All Deposits')) }}
                    </a>
                </div>
            </div>
        </div>

        <div class="bg-white shadow-md rounded-lg overflow-hidden">
            <div class="p-6">
                <div class="flex justify-between items-center mb-4">
                    <h2 class="text-l font-semibold">{{ \App\Helpers\TranslationHelper::transFromDatabase('Withdrawal Vouchers', __('Withdrawal Vouchers')) }}</h2>
                    @permission('banking.create')
                    <a href="{{ route('banking.withdrawals.create', ['account_id' => $account->id]) }}" class="bg-red-600 hover:bg-red-700 text-white font-bold py-2 p-4 rounded">
                        <i class="fas fa-plus ml-1"></i> {{ \App\Helpers\TranslationHelper::transFromDatabase('New Withdrawal', __('New Withdrawal')) }}
                    </a>
                    @endpermission
                </div>
                <div class="overflow--auto">
                    <table class="min-w-full divide-y divide-gray-200">
                        <thead class="bg-gray-50">
                            <tr>
                                <th scope="col" class="p-6 py-3 text-right text-s font-medium text-gray-500 uppercase tracking-wider">
                                    التاريخ
                                </th>
                                <th scope="col" class="p-6 py-3 text-right text-s font-medium text-gray-500 uppercase tracking-wider">
                                    المبلغ
                                </th>
                                <th scope="col" class="p-6 py-3 text-right text-s font-medium text-gray-500 uppercase tracking-wider">
                                    الحالة
                                </th>
                            </tr>
                        </thead>
                        <tbody class="bg-white divide-y divide-gray-200">
                            @forelse($withdrawals as $withdrawal)
                            <tr>
                                <td class="p-6 py-4 whitespace-nowrap">
                                    <div class="text-sm text-gray-900">{{ $withdrawal->withdrawal_date }}</div>
                                </td>
                                <td class="p-6 py-4 whitespace-nowrap">
                                    <div class="text-sm text-gray-900">{{ number_format($withdrawal->amount, 2) }}</div>
                                </td>
                                <td class="p-6 py-4 whitespace-nowrap">
                                    @if($withdrawal->status == 'pending')
                                    <span class="p-2 inline-flex text-s leading-5 font-semibold rounded-full bg-yellow-100 text-yellow-800">
                                        {{ \App\Helpers\TranslationHelper::transFromDatabase('Pending', __('Pending')) }}
                                    </span>
                                    @elseif($withdrawal->status == 'approved')
                                    <span class="p-2 inline-flex text-s leading-5 font-semibold rounded-full bg-green-100 text-green-800">
                                        {{ \App\Helpers\TranslationHelper::transFromDatabase('Approved', __('Approved')) }}
                                    </span>
                                    @elseif($withdrawal->status == 'rejected')
                                    <span class="p-2 inline-flex text-s leading-5 font-semibold rounded-full bg-red-100 text-red-800">
                                        {{ \App\Helpers\TranslationHelper::transFromDatabase('Rejected', __('Rejected')) }}
                                    </span>
                                    @endif
                                </td>
                            </tr>
                            @empty
                            <tr>
                                <td colspan="3" class="p-6 py-4 whitespace-nowrap text-sm text-gray-500 text-center">
                                    {{ \App\Helpers\TranslationHelper::transFromDatabase('No Withdrawals Registered', __('No Withdrawals Registered')) }}
                                </td>
                            </tr>
                            @endforelse
                        </tbody>
                    </table>
                </div>
                <div class="mt-4 text-center">
                    <a href="{{ route('banking.withdrawals.index', ['account_id' => $account->id]) }}" class="text-blue-600 hover:text-blue-900">
                        عرض كل {{ \App\Helpers\TranslationHelper::transFromDatabase('Withdrawal Vouchers', __('Withdrawal Vouchers')) }}
                    </a>
                </div>
            </div>
        </div>
    </div>

    <div class="bg-white shadow-md rounded-lg overflow-hidden">
        <div class="p-6">
            <div class="flex justify-between items-center mb-4">
                <h2 class="text-l font-semibold">{{ \App\Helpers\TranslationHelper::transFromDatabase('Associated Checks', __('Associated Checks')) }}</h2>
                @permission('banking.create')
                <a href="{{ route('banking.checks.create', ['account_id' => $account->id]) }}" class="bg-purple-600 hover:bg-purple-700 text-white font-bold py-2 p-4 rounded">
                    <i class="fas fa-plus ml-1"></i> {{ \App\Helpers\TranslationHelper::transFromDatabase('New Check', __('New Check')) }}
                </a>
                @endpermission
            </div>
            <div class="overflow--auto">
                <table class="min-w-full divide-y divide-gray-200">
                    <thead class="bg-gray-50">
                        <tr>
                            <th scope="col" class="p-6 py-3 text-right text-s font-medium text-gray-500 uppercase tracking-wider">
                                رقم الشيك
                            </th>
                            <th scope="col" class="p-6 py-3 text-right text-s font-medium text-gray-500 uppercase tracking-wider">
                                النوع
                            </th>
                            <th scope="col" class="p-6 py-3 text-right text-s font-medium text-gray-500 uppercase tracking-wider">
                                تاريخ الاستحقاق
                            </th>
                            <th scope="col" class="p-6 py-3 text-right text-s font-medium text-gray-500 uppercase tracking-wider">
                                المبلغ
                            </th>
                            <th scope="col" class="p-6 py-3 text-right text-s font-medium text-gray-500 uppercase tracking-wider">
                                الحالة
                            </th>
                        </tr>
                    </thead>
                    <tbody class="bg-white divide-y divide-gray-200">
                        @forelse($checks as $check)
                        <tr>
                            <td class="p-6 py-4 whitespace-nowrap">
                                <div class="text-sm text-gray-900">{{ $check->check_number }}</div>
                            </td>
                            <td class="p-6 py-4 whitespace-nowrap">
                                <div class="text-sm text-gray-900">
                                    @if($check->check_type == 'incoming')
                                    <span class="p-2 inline-flex text-s leading-5 font-semibold rounded-full bg-blue-100 text-blue-800">
                                        {{ \App\Helpers\TranslationHelper::transFromDatabase('Incoming', __('Incoming')) }}
                                    </span>
                                    @else
                                    <span class="p-2 inline-flex text-s leading-5 font-semibold rounded-full bg-orange-100 text-orange-800">
                                        {{ \App\Helpers\TranslationHelper::transFromDatabase('Outgoing', __('Outgoing')) }}
                                    </span>
                                    @endif
                                </div>
                            </td>
                            <td class="p-6 py-4 whitespace-nowrap">
                                <div class="text-sm text-gray-900">{{ $check->due_date }}</div>
                            </td>
                            <td class="p-6 py-4 whitespace-nowrap">
                                <div class="text-sm text-gray-900">{{ number_format($check->amount, 2) }}</div>
                            </td>
                            <td class="p-6 py-4 whitespace-nowrap">
                                @if($check->status == 'pending')
                                <span class="p-2 inline-flex text-s leading-5 font-semibold rounded-full bg-yellow-100 text-yellow-800">
                                    {{ \App\Helpers\TranslationHelper::transFromDatabase('Pending', __('Pending')) }}
                                </span>
                                @elseif($check->status == 'deposited')
                                <span class="p-2 inline-flex text-s leading-5 font-semibold rounded-full bg-blue-100 text-blue-800">
                                    {{ \App\Helpers\TranslationHelper::transFromDatabase('Deposited', __('Deposited')) }}
                                </span>
                                @elseif($check->status == 'cashed')
                                <span class="p-2 inline-flex text-s leading-5 font-semibold rounded-full bg-green-100 text-green-800">
                                    مصروف
                                </span>
                                @elseif($check->status == 'returned')
                                <span class="p-2 inline-flex text-s leading-5 font-semibold rounded-full bg-red-100 text-red-800">
                                    مرتجع
                                </span>
                                @elseif($check->status == 'cancelled')
                                <span class="p-2 inline-flex text-s leading-5 font-semibold rounded-full bg-gray-100 text-gray-800">
                                    ملغي
                                </span>
                                @endif
                            </td>
                        </tr>
                        @empty
                        <tr>
                            <td colspan="5" class="p-6 py-4 whitespace-nowrap text-sm text-gray-500 text-center">
                                {{ \App\Helpers\TranslationHelper::transFromDatabase('No Checks Registered', __('No Checks Registered')) }}
                            </td>
                        </tr>
                        @endforelse
                    </tbody>
                </table>
            </div>
            <div class="mt-4 text-center">
                <a href="{{ route('banking.checks.index', ['account_id' => $account->id]) }}" class="text-blue-600 hover:text-blue-900">
                    عرض كل الشيكات
                </a>
            </div>
        </div>
    </div>
</div>
@endsection
