revised approve system and some minor fixes

This commit is contained in:
Jagad R R
2025-01-02 17:59:33 +07:00
parent ff004299c1
commit 8255a530af
21 changed files with 422 additions and 31 deletions
@@ -22,7 +22,8 @@ class AuditTrailController extends Controller
return view( return view(
'backend.pages.audit_trail.index', 'backend.pages.audit_trail.index',
[ [
'data' => AuditTrail::orderBy('id', 'desc')->get(), // sort by newest
'data' => AuditTrail::orderBy('created_at', 'desc')->get(),
'pageInfo' => $pageInfo, 'pageInfo' => $pageInfo,
] ]
); );
@@ -63,7 +63,7 @@ class DashboardController extends Controller
// Sum the filtered queries // Sum the filtered queries
foreach ($forms as $key => $query) { foreach ($forms as $key => $query) {
$forms[$key] = $query->sum('total'); $forms[$key] = $query->sum('approved_total');
} }
return view( return view(
@@ -65,6 +65,17 @@ class FormUpCountryController extends Controller
]); ]);
} }
public function detail($id)
{
$this->checkAuthorization(auth()->user(), ['forms.country.view']);
$form = FormUpCountry::with(['rayon', 'user'])->findOrFail($id);
$form->bukti1 = NextCloudHelper::getFileUrl($form->bukti1);
$form->bukti2 = NextCloudHelper::getFileUrl($form->bukti2);
$form->bukti3 = NextCloudHelper::getFileUrl($form->bukti3);
return response()->json($form);
}
public function create() public function create()
{ {
$this->checkAuthorization(auth()->user(), ['forms.country.create']); $this->checkAuthorization(auth()->user(), ['forms.country.create']);
@@ -273,15 +284,28 @@ class FormUpCountryController extends Controller
return redirect()->back(); return redirect()->back();
} }
public function approve($id) public function approve(Request $request, $id)
{ {
$this->checkAuthorization(auth()->user(), ['approval.approve']); $this->checkAuthorization(auth()->user(), ['approval.approve']);
$form = FormUpCountry::findOrfail($id); $form = FormUpCountry::findOrfail($id);
$approved_data = [
'allowance' => $request->allowance ? $form->allowance : 0,
'transport_dalkot' => $request->transport_dalkot ? $form->transport_dalkot : 0,
'transport_ankot' => $request->transport_ankot ? $form->transport_ankot : 0,
'hotel' => $request->hotel ? $form->hotel : 0,
];
$form->update([ $form->update([
'approved_at' => now(), 'approved_at' => now(),
'approved_by' => auth()->user()->id, 'approved_by' => auth()->user()->id,
'status' => 'Approved' 'status' => 'Approved',
'approved_allowance' => $approved_data['allowance'],
'approved_transport_dalkot' => $approved_data['transport_dalkot'],
'approved_transport_ankot' => $approved_data['transport_ankot'],
'approved_hotel' => $approved_data['hotel'],
'approved_total' => array_sum($approved_data),
]); ]);
$heads = $form->user->getCabangAndRegionHead(); $heads = $form->user->getCabangAndRegionHead();
@@ -17,6 +17,7 @@ class FormEntertaimentPresentation extends Model
'jenis', 'jenis',
'keterangan', 'keterangan',
'total', 'total',
'approved_total',
'name', 'name',
'alamat', 'alamat',
'nik_or_npwp', 'nik_or_npwp',
+4
View File
@@ -17,6 +17,10 @@ class FormMeetingSeminar extends Model
'transport_ankot', 'transport_ankot',
'hotel', 'hotel',
'total', 'total',
'approved_allowance',
'approved_transport_ankot',
'approved_hotel',
'approved_total',
'bukti1', 'bukti1',
'bukti2', 'bukti2',
'bukti3', 'bukti3',
+1
View File
@@ -17,6 +17,7 @@ class FormOthers extends Model
'tanggal', 'tanggal',
'keterangan', 'keterangan',
'total', 'total',
'approved_total',
'bukti1', 'bukti1',
'bukti2', 'bukti2',
'bukti3', 'bukti3',
+5
View File
@@ -22,6 +22,11 @@ class FormUpCountry extends Model
'transport_ankot', 'transport_ankot',
'hotel', 'hotel',
'total', 'total',
'approved_allowance',
'approved_transport_dalkot',
'approved_transport_ankot',
'approved_hotel',
'approved_total',
'bukti1', 'bukti1',
'bukti2', 'bukti2',
'bukti3', 'bukti3',
+1
View File
@@ -16,6 +16,7 @@ class FormVehicleRunningCost extends Model
'tanggal', 'tanggal',
'liter', 'liter',
'total', 'total',
'approved_total',
'jarak', 'jarak',
'tipe_bensin', 'tipe_bensin',
'nopol', 'nopol',
@@ -0,0 +1,36 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('form_up_country', function (Blueprint $table) {
$table->integer('approved_allowance')->after('total')->nullable();
$table->integer('approved_transport_dalkot')->after('approved_allowance')->nullable();
$table->integer('approved_transport_ankot')->after('approved_transport_dalkot')->nullable();
$table->integer('approved_hotel')->after('approved_transport_ankot')->nullable();
$table->integer('approved_total')->after('approved_hotel')->nullable();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('form_up_country', function (Blueprint $table) {
$table->dropColumn('approved_allowance');
$table->dropColumn('approved_transport_dalkot');
$table->dropColumn('approved_transport_ankot');
$table->dropColumn('approved_hotel');
$table->dropColumn('approved_total');
});
}
};
@@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('form_vehicle_running_cost', function (Blueprint $table) {
$table->integer('approved_total')->after('total')->nullable();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('form_vehicle_running_cost', function (Blueprint $table) {
$table->dropColumn('approved_total');
});
}
};
@@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('form_entertainment_presentation', function (Blueprint $table) {
$table->integer('approved_total')->after('total')->nullable();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('form_entertainment_presentation', function (Blueprint $table) {
$table->dropColumn('approved_total');
});
}
};
@@ -0,0 +1,34 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('form_meeting_seminar', function (Blueprint $table) {
$table->integer('approved_allowance')->after('total')->nullable();
$table->integer('approved_transport_ankot')->after('approved_allowance')->nullable();
$table->integer('approved_hotel')->after('approved_transport_ankot')->nullable();
$table->integer('approved_total')->after('approved_hotel')->nullable();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('form_meeting_seminar', function (Blueprint $table) {
$table->dropColumn('approved_allowance');
$table->dropColumn('approved_transport_ankot');
$table->dropColumn('approved_hotel');
$table->dropColumn('approved_total');
});
}
};
@@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('form_others', function (Blueprint $table) {
$table->integer('approved_total')->after('total')->nullable();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('form_others', function (Blueprint $table) {
$table->dropColumn('approved_total');
});
}
};
@@ -42,7 +42,8 @@
<th width="15%">{{ __('Activity') }}</th> <th width="15%">{{ __('Activity') }}</th>
<th width="5%">Browser</th> <th width="5%">Browser</th>
<th width="15%">User Agent</th> <th width="15%">User Agent</th>
<th width="5%">Time</th> <th width="5%">Tanggal</th>
<th width="5%">Waktu</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@@ -70,6 +71,7 @@
<td>{{ $item->activity }}</td> <td>{{ $item->activity }}</td>
<td>{{ $item->browser }}</td> <td>{{ $item->browser }}</td>
<td>{{ $item->user_agent }}</td> <td>{{ $item->user_agent }}</td>
<td>{{ $item->created_at }}</td>
<td>{{ $item->created_at->diffForHumans() }}</td> <td>{{ $item->created_at->diffForHumans() }}</td>
</tr> </tr>
@endforeach @endforeach
@@ -93,7 +95,8 @@
dom: 'Bfrtip', dom: 'Bfrtip',
buttons: [ buttons: [
'excel', 'pdf', 'print' 'excel', 'pdf', 'print'
] ],
order: [[6, 'desc']]
}); });
} }
}); });
@@ -246,7 +246,7 @@
$(document).ready(function () { $(document).ready(function () {
if ($('#dataTable').length) { if ($('#dataTable').length) {
$('#dataTable').DataTable({ $('#dataTable').DataTable({
responsive: true, responsive: false,
dom: 'Bfrtip', dom: 'Bfrtip',
buttons: [ buttons: [
'excel', 'pdf', 'print' 'excel', 'pdf', 'print'
@@ -246,7 +246,7 @@
$(document).ready(function () { $(document).ready(function () {
if ($('#dataTable').length) { if ($('#dataTable').length) {
$('#dataTable').DataTable({ $('#dataTable').DataTable({
responsive: true, responsive: false,
dom: 'Bfrtip', dom: 'Bfrtip',
buttons: [ buttons: [
'excel', 'pdf', 'print' 'excel', 'pdf', 'print'
@@ -244,7 +244,7 @@
$(document).ready(function () { $(document).ready(function () {
if ($('#dataTable').length) { if ($('#dataTable').length) {
$('#dataTable').DataTable({ $('#dataTable').DataTable({
responsive: true, responsive: false,
dom: 'Bfrtip', dom: 'Bfrtip',
buttons: [ buttons: [
'excel', 'pdf', 'print' 'excel', 'pdf', 'print'
@@ -39,7 +39,7 @@
<div class="col-lg-4 col-6"> <div class="col-lg-4 col-6">
<div class="small-box bg-success"> <div class="small-box bg-success">
<div class="inner"> <div class="inner">
<h3>Rp {{ number_format($forms->whereIn('status', ['Approved', 'Closed'])->sum('total'), 0, ',', '.') }}</h3> <h3>Rp {{ number_format($forms->whereIn('status', ['Approved', 'Closed'])->sum('approved_total'), 0, ',', '.') }}</h3>
<p>Approved Expenses</p> <p>Approved Expenses</p>
</div> </div>
<div class="icon"> <div class="icon">
@@ -90,6 +90,7 @@
<th>Tujuan</th> <th>Tujuan</th>
<th>Jarak</th> <th>Jarak</th>
<th>Total</th> <th>Total</th>
<th>Total Approved</th>
<th>Bukti 1</th> <th>Bukti 1</th>
<th>Bukti 2</th> <th>Bukti 2</th>
<th>Bukti 3</th> <th>Bukti 3</th>
@@ -117,9 +118,16 @@
<td>{{ $item->tujuan }}</td> <td>{{ $item->tujuan }}</td>
<td>{{ $item->jarak }} km</td> <td>{{ $item->jarak }} km</td>
<td>{{ number_format($item->total, 0, ',', '.') }}</td> <td>{{ number_format($item->total, 0, ',', '.') }}</td>
<td>
@if ($item->approved_total)
{{ number_format($item->approved_total, 0, ',', '.') }}
@else
-
@endif
</td>
<td> <td>
@if ($item->bukti1) @if ($item->bukti1)
<a href="{{ NextCloudHelper::getFileUrl($item->bukti1) }}" target="_blank"> <a href="{{ NextCloudHelper::getFileUrl($item->bukti1) }}">
Download Download
</a> </a>
@else @else
@@ -128,7 +136,7 @@
</td> </td>
<td> <td>
@if ($item->bukti2) @if ($item->bukti2)
<a href="{{ NextCloudHelper::getFileUrl($item->bukti2) }}" target="_blank"> <a href="{{ NextCloudHelper::getFileUrl($item->bukti2) }}">
Download Download
</a> </a>
@else @else
@@ -137,7 +145,7 @@
</td> </td>
<td> <td>
@if ($item->bukti3) @if ($item->bukti3)
<a href="{{ NextCloudHelper::getFileUrl($item->bukti3) }}" target="_blank"> <a href="{{ NextCloudHelper::getFileUrl($item->bukti3) }}">
Download Download
</a> </a>
@else @else
@@ -158,15 +166,15 @@
<td> <td>
{{-- approve / reject button --}} {{-- approve / reject button --}}
@if ($item->status == 'On Progress') @if ($item->status == 'On Progress')
<form action="{{ route('forms.up-country.approve', $item->id) }}" method="POST" class="d-inline"onsubmit="return confirm('Are you sure you want to approve this item?');"> <form action="javascript:void(0);" class="d-inline">
@csrf <button type="button"
@method('PUT') class="btn btn-success btn-sm open-approve-modal"
<button type="submit" class="btn btn-success btn-sm"> data-id="{{ route('forms.up-country.approve', $item->id) }}">
Approve Approve
</button> </button>
</form> </form>
<form action="{{ route('forms.up-country.reject', $item->id) }}" method="POST" class="d-inline"onsubmit="return confirm('Are you sure you want to reject this item?');"> <form action="{{ route('forms.up-country.reject', $item->id) }}" method="POST" class="d-inline" onsubmit="return confirm('Are you sure you want to reject this item?');">
@csrf @csrf
@method('PUT') @method('PUT')
<button type="submit" class="btn btn-danger btn-sm"> <button type="submit" class="btn btn-danger btn-sm">
@@ -239,20 +247,203 @@
</div> </div>
</div> </div>
</section> </section>
<section>
<div class="modal fade" id="approveModal" tabindex="-1" role="dialog" aria-labelledby="approveModalLabel" aria-hidden="true">
<div class="modal-dialog modal-xl" 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">
<table class="table table-bordered">
<thead>
<tr>
<th>User</th>
<th>Rayon</th>
<th>Tanggal</th>
<th>Tujuan</th>
<th>Jarak</th>
<th>Bukti 1</th>
<th>Bukti 2</th>
<th>Bukti 3</th>
</tr>
</thead>
<tbody>
<tr>
<td id="user"></td>
<td id="rayon"></td>
<td id="tanggal"></td>
<td id="tujuan"></td>
<td id="jarak"></td>
<td id="bukti1"></td>
<td id="bukti2"></td>
<td id="bukti3"></td>
</tr>
</tbody>
</table>
<p>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">
<input type="checkbox" class="custom-control-input" id="allowance" name="allowance">
<label class="custom-control-label" for="allowance">Allowance (<span id="allowance_value"></span>)</label>
</div>
</div>
</li>
<li>
<div class="form-group">
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" id="transport_dalkot" name="transport_dalkot">
<label class="custom-control-label" for="transport_dalkot">Transport Dalkot (<span id="transport_dalkot_value"></span>)</label>
</div>
</div>
</li>
<li>
<div class="form-group">
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" id="transport_ankot" name="transport_ankot">
<label class="custom-control-label" for="transport_ankot">Transport Ankot (<span id="transport_ankot_value"></span>)</label>
</div>
</div>
</li>
<li>
<div class="form-group">
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" id="hotel" name="hotel">
<label class="custom-control-label" for="hotel">Hotel (<span id="hotel_value"></span>)</label>
</div>
</div>
</li>
<li>
<div class="form-group">
<label for="total">Total</label>
<input type="text" class="form-control" id="total" name="total" value="0" readonly>
</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 @endsection
@section('scripts') @section('scripts')
<script> <script>
$(document).ready(function () { $(document).ready(function () {
if ($('#dataTable').length) { // Uncheck all checkboxes on page refresh
$('#dataTable').DataTable({ $('.custom-control-input').prop('checked', false);
responsive: true,
dom: 'Bfrtip', if ($('#dataTable').length) {
buttons: [ $('#dataTable').DataTable({
'excel', 'pdf', 'print' responsive: false,
] dom: 'Bfrtip',
}); buttons: ['excel', 'pdf', 'print']
} });
}); }
</script>
// Handle Approve Button Click
$('.open-approve-modal').on('click', 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
$('#approveModal').modal('show'); // Show the modal
// Get detail from /forms/up-country/detail/{id}
$.get(approveUrl.replace('approve', 'detail'), function (data) {
const formatter = new Intl.NumberFormat('id-ID', {
style: 'currency',
currency: 'IDR',
minimumFractionDigits: 0
});
$('#allowance_value').text(formatter.format(data.allowance));
$('#transport_dalkot_value').text(formatter.format(data.transport_dalkot));
$('#transport_ankot_value').text(formatter.format(data.transport_ankot));
$('#hotel_value').text(formatter.format(data.hotel));
// Assign data values to checkboxes
$('#allowance').data('value', data.allowance);
$('#transport_dalkot').data('value', data.transport_dalkot);
$('#transport_ankot').data('value', data.transport_ankot);
$('#hotel').data('value', data.hotel);
// Detail data
$('#user').text(data.user.name);
$('#rayon').text(data.rayon.code);
$('#tanggal').text(new Date(data.tanggal).toLocaleDateString('id-ID', {
year: 'numeric',
month: 'long',
day: 'numeric'
}));
$('#tujuan').text(data.tujuan);
$('#jarak').text(data.jarak + ' km');
$('#bukti1').html(data.bukti1 ? '<a href="' + data.bukti1 + '" target="_blank">Download</a>' : '-');
$('#bukti2').html(data.bukti2 ? '<a href="' + data.bukti2 + '" target="_blank">Download</a>' : '-');
$('#bukti3').html(data.bukti3 ? '<a href="' + data.bukti3 + '" 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);
});
});
// Update total dynamically
$('.custom-control-input').on('change', function () {
let total = 0;
// Calculate the total based on checked checkboxes
$('.custom-control-input:checked').each(function () {
total += parseFloat($(this).data('value') || 0);
});
// Update the total field with formatted value
const formatter = new Intl.NumberFormat('id-ID', {
style: 'currency',
currency: 'IDR',
minimumFractionDigits: 0
});
$('#total').val(formatter.format(total));
});
// Uncheck all checkboxes when the modal is closed
$('#approveModal').on('hidden.bs.modal', function () {
$('.custom-control-input').prop('checked', false); // Uncheck all checkboxes
$('#total').val('0'); // Reset total to 0
});
});
</script>
@endsection @endsection
@@ -248,7 +248,7 @@
$(document).ready(function () { $(document).ready(function () {
if ($('#dataTable').length) { if ($('#dataTable').length) {
$('#dataTable').DataTable({ $('#dataTable').DataTable({
responsive: true, responsive: false,
dom: 'Bfrtip', dom: 'Bfrtip',
buttons: [ buttons: [
'excel', 'pdf', 'print' 'excel', 'pdf', 'print'
@@ -25,6 +25,11 @@
<meta name="csrf-token" content="{{ csrf_token() }}"> <meta name="csrf-token" content="{{ csrf_token() }}">
<style type="text/css"> <style type="text/css">
.table-responsive {
overflow-x: scroll;
white-space: nowrap;
}
/* Chart.js */ /* Chart.js */
@keyframes chartjs-render-animation { @keyframes chartjs-render-animation {
from { from {
+1
View File
@@ -76,6 +76,7 @@ Route::middleware(['auth:admin', 'menu'])->group(function () {
Route::prefix('forms')->group(function () { Route::prefix('forms')->group(function () {
// Up Country // Up Country
Route::get('/up-country', [FormUpCountryController::class, 'index'])->name('forms.up-country'); Route::get('/up-country', [FormUpCountryController::class, 'index'])->name('forms.up-country');
Route::get('/up-country/detail/{id}', [FormUpCountryController::class, 'detail'])->name('forms.up-country.detail');
Route::get('/up-country/create', [FormUpCountryController::class, 'create'])->name('forms.up-country.create'); Route::get('/up-country/create', [FormUpCountryController::class, 'create'])->name('forms.up-country.create');
Route::post('/up-country/store', [FormUpCountryController::class, 'store'])->name('forms.up-country.store'); Route::post('/up-country/store', [FormUpCountryController::class, 'store'])->name('forms.up-country.store');
Route::get('/up-country/edit/{id}', [FormUpCountryController::class, 'edit'])->name('forms.up-country.edit'); Route::get('/up-country/edit/{id}', [FormUpCountryController::class, 'edit'])->name('forms.up-country.edit');