@extends('layouts.app')
@section('content')

<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-12">
            <div class="card">
                
                <nav aria-label="breadcrumb">
                    <ol class="breadcrumb pb-3">
                      <li class="breadcrumb-item"><a href="{{ route('home') }}">Home</a></li>
                      <li class="breadcrumb-item"><a href="{{ route('permohonan.index') }}">Permohonan</a></li>
                      <li class="breadcrumb-item active" aria-current="page">Rekod</li>
                    </ol>
                </nav>

                <div class="card-body mx-auto col-12">   
                    
                    @if(session()->has('message'))
                    <div class="alert alert-success">
                        {{ session()->get('message') }}
                    </div>
                    @endif

                    @if(session()->has('error'))
                    <div class="alert alert-danger">
                        {{ session()->get('error') }}
                    </div>
                    @endif

                    <div class="d-flex justify-content-between mb-2">
                        <h5 class="mt-2">Senarai Rekod Permohonan</h5>
                    </div>
                    <div class="row">
                        <div class="col-md-12">
                            <table class="table table-striped table-hover" id="permohonantable">
                                <thead class="thead-dark text-center">
                                    <tr>
                                        <th>Bil</th>
                                        <th>No Permohonan</th>
                                        <th>Tarikh Mohon</th>
                                        <th>Jumlah Mohon (RM)</th>
                                        <th>Jumlah Lulus (RM)</th>
                                        <th>Semak</th>
                                        <th>Jenis Permohonan</th>
                                        <th>Status</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    @foreach($permohonan as $mohon)
                                    <tr class="text-center">
                                        <td>{{ $loop->iteration }}</td>
                                        <td>{{ $mohon['nopermohonan'] }}</td>
                                        <td>{{ $mohon['tarikh_permohonan'] }}</td>
                                        <td>{{ number_format($mohon['amaun_mohon'],2) }}</td>
                                        <td>{{ number_format($mohon['jumlah_diluluskan'],2) }}</td>
                                        <td>
                                            <a href="{{ route('permohonan.status', ['mohonid' => $mohon['nopermohonan']]) }}" class="btn btn-info"><i class="fas fa-eye"></i></a>
                                        </td>
                                        <td>{{ $mohon['jenismohon'] }}</td>
                                        <td>@php 
                                            if($mohon['tagterima'] === 1 || ($mohon['jenismohon'] == 'bayaranbalik' && $mohon['tagoperasi'] === 1 && $mohon['tagcit'] === 1 && $mohon['tagakaun'] === 1))
                                             echo '<span class="p-2 badge badge-success">BERJAYA</span>'; 
                                             else echo '<span class="p-2 badge badge-danger">BATAL</span>'; @endphp</td>

                                    </tr>
                                    @endforeach
                                </tbody>
                            </table>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">

    var tablemohon = $('#permohonantable').DataTable({
        "ordering": false
    });

    var api_url = '{{ $api_url }}';

</script>
@endsection
