@extends('layouts.app')

@section('title')
  Dashboard
@endsection

@section('admin-content')
    <section class="content-header">
        <div class="container-fluid">
            <div class="row mb-2">
                <div class="col-sm-6">
                    <h1>Active Budgets</h1>
                </div>
                <div class="col-sm-6">
                    <ol class="breadcrumb float-sm-right">
                        <li class="breadcrumb-item"><a href="{{ route('dashboard.index') }}">Dashboard</a></li>
                        </li>
                    </ol>
                </div>
            </div>
        </div>
    </section>
    <section class="content">
        <div class="container-fluid">
            <div class="card card-primary card-outline">
                <div class="card-body">
					<h4 class="header-title float-left">Current Active Budget</h4>
                    <p class="float-right mb-2">
						@if (auth()->user()->can('budget_control.create'))
							<a class="btn btn-primary text-white" href="{{ route('budget_control.create') }}">
								Add New Budget
							</a>
						@endif
                    </p>
                    <div class="clearfix"></div>
                    <div class="dataTables_wrapper dt-bootstrap4 mt-2">
                        @include('backend.layouts.partials.messages')
						<div class="table-responsive">
							<table id="dataTable"
								class="table table-bordered table-striped table-head-fixed dataTable dtr-inline"
								style="width:100%">
								<thead class="bg-light text-capitalize">
									<tr>
										<th>#</th>
										<th>Penerima</th>
										<th>Cabang</th>
										<th>Pengirim</th>
										<th>Total</th>
										<th>Sisa Budget Tersedia</th>
										<th>Keterangan</th>
										<th>Periode</th>
										<th>Status</th>
										<th>Aksi</th>
									</tr>
								</thead>
								<tbody>
									@php
										use App\Helpers\BudgetHelper;
									@endphp
									@foreach ($data as $item)
										<tr>
											<td>{{ $loop->iteration }}</td>
											<td>{{ $item->receiver->name }}</td>
											<td>{{ $item->cabang->name }}</td>
											<td>{{ $item->sender->name }}</td>
											<td>{{ number_format($item->amount, 0, ',', '.') }}</td>
											<td>{{ number_format($item->availableBudget, 0, ',', '.') }}</td>
											<td>{{ $item->remarks }}</td>
											<td>{{ strtoupper($item->periode_month) }} {{ $item->periode_year }}</td>
											<td>
												@if ($item->status == 'Unassigned')
													<span class="badge badge-warning text-white">{{ $item->status }}</span>
												@elseif ($item->status == 'Assigned')
													<span class="badge badge-success text-white">{{ $item->status }}</span>
												@else
													<span class="badge badge-danger text-white">{{ $item->status }}</span>
												@endif
											</td>
											<td>
												@if (auth()->user()->can('budget_control.delete'))
													<form action="{{ route('budget_control.destroy', $item->id) }}" method="POST" class="d-inline" onsubmit="return confirm('Are you sure you want to delete this item?');">
														@csrf
														@method('DELETE')
														<button type="submit" class="btn btn-danger btn-sm">
															<i class="fas fa-trash"></i>
														</button>
													</form>
												@endif
											</td>
										</tr>
									@endforeach
								</tbody>
							</table>
						</div>
					</div>
                </div>
            </div>
        </div>
    </section>
@endsection

@section('scripts')
    <script>
		$(document).ready(function () {
			if ($('#dataTable').length) {
				$('#dataTable').DataTable({
					responsive: false,
					dom: 'Blfrtip',
					lengthMenu: [ [10, 50, 100, -1], [10, 50, 100, "All"] ], // Control the entries dropdown
					buttons: [
						{
							extend: 'excel',
							text: 'Excel'
						},
						{
							extend: 'pdf',
							text: 'PDF',
							orientation: 'landscape',
							pageSize: 'A4',
							exportOptions: {
								columns: ':visible'
							}
						},
						{
							extend: 'print',
							text: 'Print',
							orientation: 'landscape',
							exportOptions: {
								columns: ':visible'
							}
						},
						'colvis'
					]
				});
			}
		});
	</script>
@endsection
