Files
expense/resources/views/backend/pages/forms/vehicle/index.blade.php
T

606 lines
22 KiB
PHP
Raw Normal View History

@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>Forms Vehicle Running Cost</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>
2024-12-24 11:40:49 +07:00
<section class="content">
<div class="container-fluid">
<div class="row">
<!-- Total Expense -->
2025-01-11 13:31:44 +07:00
<div class="col-6 {{ $availableBudget > 0 ? 'col-lg-3' : 'col-lg-4' }}">
2024-12-24 11:40:49 +07:00
<div class="small-box bg-info">
<div class="inner">
<h3>Rp {{ number_format($forms->sum('total'), 0, ',', '.') }}</h3>
<p>Total Expense</p>
</div>
<div class="icon">
<i class="fas fa-wallet"></i>
</div>
</div>
</div>
<!-- Approved Expense -->
2025-01-11 13:31:44 +07:00
<div class="col-6 {{ $availableBudget > 0 ? 'col-lg-3' : 'col-lg-4' }}">
2024-12-24 11:40:49 +07:00
<div class="small-box bg-success">
<div class="inner">
<h3>Rp {{ number_format($forms->whereIn('status', ['Approved', 'Closed'])->sum('approved_total'), 0, ',', '.') }}</h3>
2024-12-24 11:40:49 +07:00
<p>Approved Expenses</p>
</div>
<div class="icon">
<i class="fas fa-check-circle"></i>
</div>
</div>
</div>
<!-- Pending Expense -->
2025-01-11 13:31:44 +07:00
<div class="col-6 {{ $availableBudget > 0 ? 'col-lg-3' : 'col-lg-4' }}">
2024-12-24 11:40:49 +07:00
<div class="small-box bg-warning">
<div class="inner">
<h3 class="text-white">Rp {{ number_format($forms->where('status', 'On Progress')->sum('total'), 0, ',', '.') }}</h3>
<p class="text-white">Pending Expenses</p>
</div>
<div class="icon">
<i class="fas fa-hourglass-half"></i>
</div>
</div>
</div>
2025-01-11 13:31:44 +07:00
@if($availableBudget > 0)
<div class="col-lg-3 col-6">
<div class="small-box bg-purple">
<div class="inner">
<h3 class="text-white">Rp {{ number_format($availableBudget, 0, ',', '.') }}</h3>
<p class="text-white">Available Budget</p>
</div>
<div class="icon">
<i class="fas fa-money-bill"></i>
</div>
2025-01-09 14:17:28 +07:00
</div>
</div>
2025-01-11 13:31:44 +07:00
@endif
2024-12-24 11:40:49 +07:00
</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">List Data Forms Vehicle Running Cost Anda</h4>
<p class="float-right mb-2">
@if (auth()->user()->can('forms.vehicle.create'))
<a class="btn btn-primary text-white" href="{{ route('forms.vehicle.create') }}">
Add New Expense Vehicle Running Cost
</a>
@endif
</p>
<div class="clearfix"></div>
<div class="dataTables_wrapper dt-bootstrap4 mt-2">
@include('backend.layouts.partials.messages')
2024-12-27 13:03:19 +07:00
<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>
2024-12-27 13:03:19 +07:00
<th>#</th>
2025-01-08 15:36:08 +07:00
<th>No Expense</th>
2024-12-27 13:03:19 +07:00
<th>Nama</th>
2025-01-08 14:12:45 +07:00
<th>Cabang</th>
2024-12-27 13:03:19 +07:00
<th>Tanggal</th>
2025-06-19 19:39:20 +07:00
<th>Type</th>
2024-12-27 13:03:19 +07:00
<th>Liter</th>
2025-05-08 20:04:12 +07:00
<th>Keterangan</th>
2024-12-27 13:03:19 +07:00
<th>Total</th>
<th>Total Approved</th>
2025-05-25 15:14:23 +07:00
<th>Km (Odometer)</th>
2024-12-27 13:03:19 +07:00
<th>Tipe Bensin</th>
<th>Nomor Polisi</th>
<th>Bukti</th>
2024-12-27 13:03:19 +07:00
<th>Account Number</th>
<th>Status</th>
2025-01-19 14:57:01 +07:00
@if (auth()->user()->can('approval.view'))
2025-01-16 15:56:22 +07:00
<th>Approval 1</th>
@endif
2025-01-19 14:57:01 +07:00
@if (auth()->user()->can('approval2.view'))
2025-01-16 15:56:22 +07:00
<th>Approval 2</th>
2024-12-27 13:03:19 +07:00
@endif
2025-01-19 14:57:01 +07:00
@if (auth()->user()->can('final_approval.view'))
2024-12-27 13:03:19 +07:00
<th>Final Approval</th>
@endif
<th>Aksi</th>
</tr>
</thead>
<tbody>
@php
use App\Helpers\NextCloudHelper;
2025-01-07 17:23:42 +07:00
$role = auth()->user()->getRoleNames()[0];
2024-12-27 13:03:19 +07:00
@endphp
@foreach ($forms as $item)
<tr>
<td>{{ $loop->iteration }}</td>
2025-01-08 15:36:08 +07:00
<td>{{ $item->expense_number }}</td>
2024-12-27 13:03:19 +07:00
<td>{{ $item->user->name }}</td>
2025-01-08 14:12:45 +07:00
<td>{{ $item->user->cabang->cabang->name }}</td>
2024-12-27 13:03:19 +07:00
<td>{{ \Carbon\Carbon::parse($item->tanggal)->locale('id')->isoFormat('dddd, D MMMM Y HH:mm:ss') }}</td>
2025-06-19 19:39:20 +07:00
<td>
{{-- gunakan badge --}}
@if ($item->type == 'gasoline')
<span class="badge badge-info">Gasoline</span>
@elseif ($item->type == 'parking_toll')
<span class="badge badge-warning text-white">Parking / Toll</span>
@else
<span class="badge badge-secondary">Unknown</span>
@endif
</td>
2024-12-27 13:03:19 +07:00
<td>{{ $item->liter }}</td>
2025-05-08 20:04:12 +07:00
<td>{{ $item->keterangan }}</td>
2024-12-27 13:03:19 +07:00
<td>{{ number_format($item->total, 0, ',', '.') }}</td>
<td>{{ number_format($item->approved_total, 0, ',', '.') }}</td>
2025-01-02 13:12:42 +07:00
<td>{{ $item->jarak }} km</td>
2024-12-27 13:03:19 +07:00
<td>{{ $item->tipe_bensin }}</td>
<td>{{ $item->nopol }}</td>
<td>
@if ($item->bukti_total)
<a href="{{ NextCloudHelper::getFileUrl($item->bukti_total) }}" target="_blank">
2024-12-27 13:03:19 +07:00
Download
</a>
@else
-
@endif
</td>
<td>{{ $item->account_number }}</td>
<td>
@if ($item->status == 'On Progress')
<span class="badge badge-warning text-white">{{ $item->status }}</span>
2025-01-16 15:56:22 +07:00
@elseif ($item->status == 'Approved 1' || $item->status == 'Approved 2' || $item->status == 'Final Approved')
2024-12-27 13:03:19 +07:00
<span class="badge badge-success text-white">{{ $item->status }}</span>
@else
2024-12-27 13:03:19 +07:00
<span class="badge badge-danger text-white">{{ $item->status }}</span>
@endif
</td>
2025-01-19 14:57:01 +07:00
@if (auth()->user()->can('approval.view'))
2024-12-27 13:03:19 +07:00
<td>
{{-- approve / reject button --}}
2025-01-19 14:57:01 +07:00
@if (auth()->user()->can('approval.approve'))
@if ($item->status == 'On Progress')
<form action="javascript:void(0);" class="d-inline">
<button type="button"
2025-01-23 17:46:38 +07:00
class="btn btn-success btn-sm final-approve-modal"
2025-01-19 14:57:01 +07:00
data-id="{{ route('forms.vehicle.approve', $item->id) }}">
Approve 1
</button>
</form>
<form action="{{ route('forms.vehicle.reject', $item->id) }}" method="POST" class="d-inline" onsubmit="return confirm('Are you sure you want to reject this item?');">
@csrf
@method('PUT')
<button type="submit" class="btn btn-danger btn-sm">
Reject
</button>
</form>
2024-12-27 13:03:19 +07:00
@endif
@endif
2025-01-19 14:57:01 +07:00
@if ($item->approved_at)
2025-01-23 17:46:38 +07:00
{{ \Carbon\Carbon::parse($item->approved_at)->locale('id')->isoFormat('D MMMM Y HH:mm') }}
2025-01-19 14:57:01 +07:00
@endif
2024-12-27 13:03:19 +07:00
</td>
@endif
2025-01-19 14:57:01 +07:00
@if (auth()->user()->can('approval2.view'))
2024-12-27 13:03:19 +07:00
<td>
{{-- approve / reject button --}}
2025-01-19 14:57:01 +07:00
@if (auth()->user()->can('approval2.approve'))
@if ($item->status == 'Approved 1' && $item->approved_at)
<form action="javascript:void(0);" class="d-inline">
<button type="button"
class="btn btn-success btn-sm open-approve-modal"
data-id="{{ route('forms.vehicle.approve2', $item->id) }}">
Approve 2
</button>
</form>
2025-01-16 15:56:22 +07:00
2025-01-19 14:57:01 +07:00
<form action="{{ route('forms.vehicle.reject', $item->id) }}" method="POST" class="d-inline" onsubmit="return confirm('Are you sure you want to reject this item?');">
@csrf
@method('PUT')
<button type="submit" class="btn btn-danger btn-sm">
Reject
</button>
</form>
2025-01-16 15:56:22 +07:00
@endif
@endif
2025-01-19 14:57:01 +07:00
@if ($item->approved2_at)
2025-01-23 17:46:38 +07:00
{{ \Carbon\Carbon::parse($item->approved2_at)->locale('id')->isoFormat('D MMMM Y HH:mm') }}
2025-01-19 14:57:01 +07:00
@endif
2025-01-16 15:56:22 +07:00
</td>
@endif
2025-01-19 14:57:01 +07:00
@if(auth()->user()->can('final_approval.view'))
2025-01-16 15:56:22 +07:00
<td>
{{-- approve / reject button --}}
2025-01-19 14:57:01 +07:00
@if(auth()->user()->can('final_approval.approve'))
@if ($item->status == 'Approved 2' && $item->approved2_at && !$item->final_approved_at)
<form action="javascript:void(0);" class="d-inline">
<button type="button"
2025-01-23 17:46:38 +07:00
class="btn btn-success btn-sm open-approve-modal"
2025-01-19 14:57:01 +07:00
data-id="{{ route('forms.vehicle.final-approve', $item->id) }}">
Final Approve
2024-12-27 13:03:19 +07:00
</button>
</form>
@else
2025-01-19 14:57:01 +07:00
@if ($item->final_approved_at && auth()->user()->can('final_approval.open'))
<form action="{{ route('forms.vehicle.open', $item->id) }}" method="POST" class="d-inline"onsubmit="return confirm('Are you sure you want to approve this item?');">
@csrf
@method('PUT')
<button type="submit" class="btn btn-success btn-sm">
Open
</button>
</form>
@endif
2024-12-27 13:03:19 +07:00
@endif
@endif
2025-01-19 14:57:01 +07:00
@if ($item->final_approved_at)
2025-01-23 17:46:38 +07:00
{{ \Carbon\Carbon::parse($item->final_approved_at)->locale('id')->isoFormat('D MMMM Y HH:mm') }}
2025-01-19 14:57:01 +07:00
@endif
2024-12-27 13:03:19 +07:00
</td>
@endif
2024-12-27 13:03:19 +07:00
<td>
@if (auth()->user()->can('forms.vehicle.view'))
<a href="{{ route('forms.vehicle.view', $item->id) }}" class="btn btn-primary btn-sm">
<i class="fas fa-eye text-white"></i>
</a>
@endif
2025-01-07 17:23:42 +07:00
@if (($role != 'Medical Representatif' && auth()->user()->can('forms.vehicle.edit')) || ($role == 'Medical Representatif' && $item->status == 'On Progress'))
2024-12-27 13:03:19 +07:00
<a href="{{ route('forms.vehicle.edit', $item->id) }}" class="btn btn-warning btn-sm">
<i class="fas fa-edit text-white"></i>
</a>
@endif
2025-01-07 17:23:42 +07:00
@if (($role != 'Medical Representatif' && auth()->user()->can('forms.vehicle.delete')) || ($role == 'Medical Representatif' && $item->status == 'On Progress'))
2024-12-27 13:03:19 +07:00
<form action="{{ route('forms.vehicle.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>
<section>
<div class="modal fade" id="approveModal" tabindex="-1" role="dialog" aria-labelledby="approveModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<form id="approveForm" method="POST" action="">
@csrf
@method('PUT')
<div class="modal-header">
<h5 class="modal-title" id="approveModalLabel">Approve Item</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<!-- Loading spinner -->
<div id="loadingSpinner" class="d-flex justify-content-center align-items-center" style="height: 200px;">
<div class="spinner-border text-primary" role="status">
<span class="sr-only">Loading...</span>
</div>
</div>
<!-- Modal content (hidden initially) -->
<div id="modalContent" class="d-none">
<p>Please review the details below:</p>
<ul class="list-group">
<li class="list-group-item">
<strong>Expense Number:</strong> <span id="expense_number"></span>
</li>
<li class="list-group-item">
<strong>User:</strong> <span id="user"></span>
</li>
<li class="list-group-item">
2025-06-19 19:39:20 +07:00
<strong>Tipe:</strong> <span id="type"></span>
</li>
<li class="list-group-item">
<strong>Tanggal & Waktu:</strong> <span id="tanggal"></span>
</li>
<li class="list-group-item">
<strong>Jarak:</strong> <span id="jarak"></span> km
</li>
<li class="list-group-item">
<strong>Total Liter Bensin:</strong> <span id="liter"></span> liter
</li>
<li class="list-group-item">
<strong>No Polisi:</strong> <span id="nopol"></span>
</li>
<li class="list-group-item">
<strong>Tipe Bensin:</strong> <span id="tipe_bensin"></span>
</li>
<li class="list-group-item">
2025-01-16 15:56:22 +07:00
<strong>Bukti Total:</strong> <span id="bukti_total"></span>
</li>
<li class="list-group-item">
<strong>Nominal Total:</strong> <span id="total_value"></span>
</li>
</ul>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-primary">Approve</button>
</div>
</form>
</div>
</div>
</div>
</section>
<section>
<div class="modal fade" id="finalApproveModal" tabindex="-1" role="dialog" aria-labelledby="finalApproveModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<form id="finalApproveForm" method="POST" action="">
@csrf
@method('PUT')
<div class="modal-header">
<h5 class="modal-title" id="approveModalLabel">Approve Item</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<!-- Loading spinner -->
<div id="finalLoadingSpinner" class="d-flex justify-content-center align-items-center" style="height: 200px;">
<div class="spinner-border text-primary" role="status">
<span class="sr-only">Loading...</span>
</div>
</div>
<!-- Modal content (hidden initially) -->
<div id="finalModalContent" class="d-none">
<p>Please review the details below:</p>
<ul class="list-group">
<li class="list-group-item">
<strong>Expense Number:</strong> <span id="final_expense_number"></span>
</li>
<li class="list-group-item">
<strong>User:</strong> <span id="final_user"></span>
</li>
<li class="list-group-item">
2025-06-19 19:39:20 +07:00
<strong>Tipe:</strong> <span id="final_type"></span>
2025-01-16 15:56:22 +07:00
</li>
<li class="list-group-item">
<strong>Tanggal & Waktu:</strong> <span id="final_tanggal"></span>
</li>
<li class="list-group-item">
<strong>Jarak:</strong> <span id="final_jarak"></span> km
</li>
<li class="list-group-item">
<strong>Total Liter Bensin:</strong> <span id="final_liter"></span> liter
</li>
<li class="list-group-item">
2025-01-16 15:56:22 +07:00
<strong>No Polisi:</strong> <span id="final_nopol"></span>
</li>
<li class="list-group-item">
<strong>Tipe Bensin:</strong> <span id="final_tipe_bensin"></span>
</li>
<li class="list-group-item">
<strong>Bukti Total:</strong> <span id="final_bukti_total"></span>
</li>
</ul>
<p class="mt-2">Please select the items you want to approve:</p>
<ul class="list-group list-unstyled">
<li>
<div class="form-group">
<div class="custom-control custom-checkbox">
2025-01-16 15:56:22 +07:00
<input type="checkbox" class="custom-control-input" id="final_total" name="total" required>
<label class="custom-control-label" for="final_total">Total (<span id="final_total_value"></span>)</label>
</div>
</div>
</li>
</ul>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-primary">Approve</button>
</div>
</form>
</div>
</div>
</div>
</section>
@endsection
2024-12-24 11:40:49 +07:00
@section('scripts')
<script>
$(document).ready(function () {
// Uncheck all checkboxes on page refresh
$('.custom-control-input').prop('checked', false);
if ($('#dataTable').length) {
$('#dataTable').DataTable({
responsive: false,
2025-01-15 14:50:53 +07:00
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'
]
});
}
// Handle Approve Button Click
2025-03-04 13:27:51 +07:00
$(document).on('click', '.open-approve-modal', function() {
const approveUrl = $(this).data('id');
// Show spinner and hide content initially
$('#loadingSpinner').show();
$('#modalContent').addClass('d-none');
$('#approveForm').attr('action', approveUrl); // Set the form action
$('#loadingSpinner').addClass('d-flex');
$('#approveModal').modal('show'); // Show the modal
2025-01-16 15:56:22 +07:00
// Get detail from /forms/vehicle/detail/{id}
2025-01-23 17:46:38 +07:00
$.get(approveUrl.replace(/approve2|final-approve/g, 'detail'), function (data) {
const formatter = new Intl.NumberFormat('id-ID', {
style: 'currency',
currency: 'IDR',
minimumFractionDigits: 0
});
2025-01-16 15:56:22 +07:00
$('#total_value').text(formatter.format(data.total));
// Detail data
$('#user').text(data.user.name);
$('#expense_number').text(data.expense_number);
2025-01-16 15:56:22 +07:00
$('#tanggal').text(new Date(data.created_at).toLocaleDateString('id-ID', {
year: 'numeric',
month: 'long',
2025-01-16 15:56:22 +07:00
day: 'numeric'
}));
2025-06-19 19:39:20 +07:00
// untuk type gunakan badge
$('#type').html(data.type.split('_').map(w => w.charAt(0).toUpperCase() + w.slice(1)).join(' '));
2025-01-16 15:56:22 +07:00
$('#jarak').text(data.jarak);
$('#liter').text(data.liter);
$('#tipe_bensin').text(data.tipe_bensin);
$('#nopol').text(data.nopol);
2025-01-16 15:56:22 +07:00
$('#bukti_total').html(data.total ? '<a href="' + data.total + '" target="_blank">Download</a>' : '-');
// Hide spinner and show content
$('#loadingSpinner').hide();
$('#loadingSpinner').removeClass('d-flex');
$('#loadingSpinner').addClass('d-none');
$('#modalContent').removeClass('d-none');
// Reset the total to zero
$('#total').val(0);
});
});
2025-01-16 15:56:22 +07:00
// Handle Approve Button Click
2025-03-04 13:27:51 +07:00
$(document).on('click', '.final-approve-modal', function() {
2025-01-16 15:56:22 +07:00
const approveUrl = $(this).data('id');
// Show spinner and hide content initially
$('#finalLoadingSpinner').show();
$('#finalModalContent').addClass('d-none');
$('#finalApproveForm').attr('action', approveUrl); // Set the form action
$('#finalLoadingSpinner').addClass('d-flex');
$('#finalApproveModal').modal('show'); // Show the modal
// Get detail from /forms/vehicle/detail/{id}
2025-01-23 17:46:38 +07:00
$.get(approveUrl.replace('approve', 'detail'), function (data) {
2025-01-16 15:56:22 +07:00
console.log(data);
const formatter = new Intl.NumberFormat('id-ID', {
style: 'currency',
currency: 'IDR',
minimumFractionDigits: 0
});
$('#final_total_value').text(formatter.format(data.total));
// Assign data values to checkboxes
$('#final_total').data('value', data.total);
// Detail data
$('#final_user').text(data.user.name);
$('#final_expense_number').text(data.expense_number);
$('#final_tanggal').text(new Date(data.created_at).toLocaleDateString('id-ID', {
year: 'numeric',
month: 'long',
day: 'numeric'
}));
2025-06-19 19:39:20 +07:00
$('#final_type').html(data.type.split('_').map(w => w.charAt(0).toUpperCase() + w.slice(1)).join(' '));
2025-01-16 15:56:22 +07:00
$('#final_jarak').text(data.jarak);
$('#final_liter').text(data.liter);
$('#final_tipe_bensin').text(data.tipe_bensin);
$('#final_nopol').text(data.nopol);
$('#final_bukti_total').html(data.bukti_total ? '<a href="' + data.bukti_total + '" target="_blank">Download</a>' : '-');
// Hide spinner and show content
$('#finalLoadingSpinner').hide();
$('#finalLoadingSpinner').removeClass('d-flex');
$('#finalLoadingSpinner').addClass('d-none');
$('#finalModalContent').removeClass('d-none');
// Reset the total to zero
$('#total').val(0);
});
});
// Update total dynamically
$('.custom-control-input').on('change', function () {
let total = 0;
$('.custom-control-input:checked').each(function () {
total += parseFloat($(this).data('value') || 0);
});
const formatter = new Intl.NumberFormat('id-ID', {
style: 'currency',
currency: 'IDR',
2025-01-16 15:56:22 +07:00
minimumFractionDigits: 0,
});
$('#total').val(formatter.format(total));
});
2025-01-16 15:56:22 +07:00
// Uncheck all checkboxes when the modal is closed
2025-01-16 15:56:22 +07:00
$('#finalApproveModal').on('hidden.bs.modal', function () {
$('.custom-control-input').prop('checked', false); // Uncheck all checkboxes
$('#total').val('0'); // Reset total to 0
});
});
</script>
2024-12-26 15:07:24 +07:00
@endsection