@extends('layouts.app')

@section('title', \App\Helpers\TranslationHelper::transFromDatabase('Cheque Portfolio', __('Cheque Portfolio')))

@section('content')
<div class="container-fluid p-4">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <h1 class="h3 mb-0 text-gray-800">{{ \App\Helpers\TranslationHelper::transFromDatabase('Cheque Portfolio (Incoming)', __('Cheque Portfolio (Incoming)')) }}</h1>
        <div>
            @permission('banking.checks.create')
            <a href="{{ route('banking.checks.create') }}" class="btn btn-primary">
                <i class="fas fa-plus"></i> {{ \App\Helpers\TranslationHelper::transFromDatabase('Receive New Check', __('Receive New Check')) }}
            </a>
            @endpermission
        </div>
    </div>

    <nav aria-label="breadcrumb">
        <ol class="breadcrumb">
            <li class="breadcrumb-item"><a href="{{ route('dashboard') }}">{{ \App\Helpers\TranslationHelper::transFromDatabase('Dashboard', __('Dashboard')) }}</a></li>
            <li class="breadcrumb-item"><a href="{{ route('banking.checks.index') }}">{{ \App\Helpers\TranslationHelper::transFromDatabase('Checks Management', __('Checks Management')) }}</a></li>
            <li class="breadcrumb-item active">{{ \App\Helpers\TranslationHelper::transFromDatabase('Cheque Portfolio', __('Cheque Portfolio')) }}</li>
        </ol>
    </nav>

    <div class="card shadow mb-4">
        <div class="card-header py-3 bg-light">
            <h6 class="m-0 font-weight-bold text-primary">
                <i class="fas fa-wallet me-2"></i>
                {{ \App\Helpers\TranslationHelper::transFromDatabase('Checks currently in the safe', __('Checks currently in the safe')) }}
            </h6>
        </div>
        <div class="card-body">
            <div class="table-responsive">
                <table class="table table-bordered table-hover" id="portfolioTable">
                    <thead class="bg-gray-100">
                        <tr>
                            <th>{{ \App\Helpers\TranslationHelper::transFromDatabase('Check No.', __('Check No.')) }}</th>
                            <th>{{ \App\Helpers\TranslationHelper::transFromDatabase('Issuer', __('Issuer')) }}</th>
                            <th>{{ \App\Helpers\TranslationHelper::transFromDatabase('Amount', __('Amount')) }}</th>
                            <th>{{ \App\Helpers\TranslationHelper::transFromDatabase('Due Date', __('Due Date')) }}</th>
                            <th>{{ \App\Helpers\TranslationHelper::transFromDatabase('Bank Account (Intermediate)', __('Bank Account (Intermediate)')) }}</th>
                            <th>{{ \App\Helpers\TranslationHelper::transFromDatabase('Actions', __('Actions')) }}</th>
                        </tr>
                    </thead>
                    <tbody>
                        @forelse($checks as $check)
                        <tr>
                            <td class="font-weight-bold text-dark">{{ $check->check_number }}</td>
                            <td>{{ $check->issuer_name }}</td>
                            <td class="text-success font-weight-bold">{{ number_format($check->amount, 2) }}</td>
                            <td>
                                <span class="{{ \Carbon\Carbon::parse($check->due_date)->isPast() ? 'text-danger font-weight-bold' : '' }}">
                                    {{ $check->due_date }}
                                </span>
                            </td>
                            <td>{{ $check->bankAccount->bank->name }} - {{ $check->bankAccount->account_name }}</td>
                            <td>
                                <div class="btn-group" role="group">
                                    @permission('banking.checks.status')
                                    <a href="{{ route('banking.checks.deposit.form', $check) }}" class="btn btn-outline-success btn-sm" title="{{ \App\Helpers\TranslationHelper::transFromDatabase('Deposit to Bank', __('Deposit to Bank')) }}">
                                        <i class="fas fa-university"></i> {{ \App\Helpers\TranslationHelper::transFromDatabase('Deposit', __('Deposit')) }}
                                    </a>
                                    <a href="{{ route('banking.checks.cash.form', $check) }}" class="btn btn-outline-primary btn-sm" title="{{ \App\Helpers\TranslationHelper::transFromDatabase('Cash Check', __('Cash Check')) }}">
                                        <i class="fas fa-money-bill-wave"></i> {{ \App\Helpers\TranslationHelper::transFromDatabase('Cash', __('Cash')) }}
                                    </a>
                                    @endpermission

                                    @permission('banking.checks.view')
                                    <a href="{{ route('banking.checks.show', $check) }}" class="btn btn-outline-info btn-sm" title="{{ \App\Helpers\TranslationHelper::transFromDatabase('View Details', __('View Details')) }}">
                                        <i class="fas fa-eye"></i>
                                    </a>
                                    @endpermission
                                </div>
                            </td>
                        </tr>
                        @empty
                        <tr>
                            <td colspan="6" class="text-center py-4">{{ \App\Helpers\TranslationHelper::transFromDatabase('Portfolio is empty', __('Portfolio is empty')) }}</td>
                        </tr>
                        @endforelse
                    </tbody>
                </table>
            </div>
            <div class="mt-4">
                {{ $checks->links() }}
            </div>
        </div>
    </div>
</div>
@endsection

@section('scripts')
<script>
    $(document).ready(function() {
        $('#portfolioTable').DataTable({
            "language": {
                "url": "//cdn.datatables.net/plug-ins/1.10.25/i18n/Arabic.json"
            },
            "paging": false,
            "info": false,
            "searching": true,
            "order": [[ 3, "asc" ]]
        });
    });
</script>
@endsection
