@extends('layouts.admin')

@section('content')
    <div class="content-wrapper pb-0">
        <div class="page-header flex-wrap">
            <h3 class="mb-0">Daftar Nasabah</h3>
        </div>

        <div class="col-lg-12 grid-margin stretch-card">
            <div class="card">
                <div class="card-body">
                    @if (auth()->user()->level == 'Bendahara')
                        <a href="{{ route('nasabah.tambah') }}" class="btn btn-primary mb-3">Tambah Nasabah</a>
                    @endif
                    @if (session('success'))
                        <div class="alert alert-success">{{ session('success') }}</div>
                    @endif

                    <div class="table-responsive">
                        <table class="table table-striped" id="datatable">
                            <thead class="table-dark">
                                <tr>
                                    <th>Nama</th>
                                    <th>Gol. <br> Pekerjaan</th>
                                    <th>Status <br> Pekerjaan</th>
                                    <th>Jumlah <br> Pinjaman</th>
                                    <th>History <br> Pinjaman</th>
                                    <th>Tabungan <br> Wajib</th>
                                    <th>Slip <br> Gaji</th>
                                    <th>Tanggal </th>
                                    @if (auth()->user()->level == 'Bendahara')
                                        <th>Aksi</th>
                                    @endif

                                </tr>
                            </thead>
                            <tbody>
                                @foreach ($nasabah as $n)
                                    <tr>
                                        <td>{{ $n->nama }}</td>
                                        <td>{{ $n->golongan_pekerjaan }}</td>
                                        <td>{{ $n->status_pekerjaan }}</td>
                                        <td>Rp. {{ number_format($n->jumlah_pinjaman, 0, ',', '.') }}</td>
                                        <td>Rp. {{ number_format($n->history_pinjaman, 0, ',', '.') }}</td>
                                        <td>Rp. {{ number_format($n->tabungan_simpanan_wajib, 0, ',', '.') }}</td>
                                        <td>
                                            @if ($n->slip_gaji)
                                                <a href="{{ asset('uploads/' . $n->slip_gaji) }}" target="_blank">Lihat
                                                    Slip</a>
                                            @else
                                                Tidak ada
                                            @endif
                                        </td>
                                        <td>{{ \Carbon\Carbon::parse($n->created_at)->format('d-m-Y') }}</td>
                                        @if (auth()->user()->level == 'Bendahara')
                                            <td>
                                                <a href="{{ route('nasabah.edit', $n->id_nasabah) }}"
                                                    class="btn btn-warning btn-sm">Edit</a><br>
                                                <a href="{{ route('nasabah.hapus', $n->id_nasabah) }}"
                                                    class="btn btn-danger btn-sm"
                                                    onclick="return confirm('Yakin ingin menghapus?')">Hapus</a>
                                            </td>
                                        @endif

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