Files
expense/resources/views/backend/pages/forms/entertainment/index.blade.php
T
2025-01-09 14:17:28 +07:00

422 lines
15 KiB
PHP

@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 Entertainment & Presentation</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="row">
<!-- Total Expense -->
<div class="col-lg-3 col-6">
<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 -->
<div class="col-lg-3 col-6">
<div class="small-box bg-success">
<div class="inner">
<h3>Rp {{ number_format($forms->whereIn('status', ['Approved', 'Closed'])->sum('approved_total'), 0, ',', '.') }}</h3>
<p>Approved Expenses</p>
</div>
<div class="icon">
<i class="fas fa-check-circle"></i>
</div>
</div>
</div>
<!-- Pending Expense -->
<div class="col-lg-3 col-6">
<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>
<!-- Budget Available -->
<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>
</div>
</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">List Data Forms Entertainment & Presentation</h4>
<p class="float-right mb-2">
@if (auth()->user()->can('forms.entertainment.create'))
<a class="btn btn-primary text-white" href="{{ route('forms.entertainment.create') }}">
Add New Expense Entertainment & Presentation
</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>No Expense</th>
<th>User</th>
<th>Cabang</th>
<th>Nama Penerima</th>
<th>Tanggal</th>
<th>Jenis</th>
<th>Keterangan</th>
<th>Total</th>
<th>Total Approved</th>
<th>Bukti</th>
<th>Account Number</th>
<th>Status</th>
@if (auth()->user()->can('approval.approve'))
<th>Approval</th>
@endif
@if (auth()->user()->can('final_approval.approve'))
<th>Final Approval</th>
@endif
<th>Aksi</th>
</tr>
</thead>
<tbody>
@php
use App\Helpers\NextCloudHelper;
$role = auth()->user()->getRoleNames()[0];
@endphp
@foreach ($forms as $item)
<tr>
<td>{{ $loop->iteration }}</td>
<td>{{ $item->expense_number }}</td>
<td>{{ $item->user->name }}</td>
<td>{{ $item->user->cabang->cabang->name }}</td>
<td>{{ $item->name }}</td>
<td>{{ \Carbon\Carbon::parse($item->tanggal)->locale('id')->isoFormat('D MMMM Y') }}</td>
<td>{{ $item->jenis }}</td>
<td>{{ $item->keterangan }}</td>
<td>{{ number_format($item->total, 0, ',', '.') }}</td>
<td>{{ number_format($item->approved_total, 0, ',', '.') }}</td>
<td>
@if ($item->bukti_total)
<a href="{{ NextCloudHelper::getFileUrl($item->bukti_total) }}" target="_blank">
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>
@elseif ($item->status == 'Approved' || $item->status == 'Final Approved')
<span class="badge badge-success text-white">{{ $item->status }}</span>
@else
<span class="badge badge-danger text-white">{{ $item->status }}</span>
@endif
</td>
@if (auth()->user()->can('approval.approve'))
<td>
{{-- approve / reject button --}}
@if ($item->status == 'On Progress')
<form action="javascript:void(0);" class="d-inline">
<button type="button"
class="btn btn-success btn-sm open-approve-modal"
data-id="{{ route('forms.entertainment.approve', $item->id) }}">
Approve
</button>
</form>
<form action="{{ route('forms.entertainment.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>
@else
@if ($item->approved_at)
{{ \Carbon\Carbon::parse($item->approved_at)->locale('id')->isoFormat('D MMMM Y') }}
@elseif($item->rejected_at)
{{ \Carbon\Carbon::parse($item->rejected_at)->locale('id')->isoFormat('D MMMM Y') }}
@else
-
@endif
@endif
</td>
@endif
@if(auth()->user()->can('final_approval.approve'))
<td>
{{-- approve / reject button --}}
@if ($item->status == 'Approved' && $item->approved_at && !$item->final_approved_at)
<form action="{{ route('forms.entertainment.final-approve', $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">
Final Approve
</button>
</form>
@else
@if ($item->final_approved_at && auth()->user()->can('final_approval.open'))
<form action="{{ route('forms.entertainment.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>
@elseif ($item->final_approved_at)
{{ \Carbon\Carbon::parse($item->approved_at)->locale('id')->isoFormat('D MMMM Y') }}
@else
-
@endif
@endif
</td>
@endif
<td>
@if (auth()->user()->can('forms.entertainment.view'))
<a href="{{ route('forms.entertainment.view', $item->id) }}" class="btn btn-primary btn-sm">
<i class="fas fa-eye text-white"></i>
</a>
@endif
@if (($role != 'Medical Representatif' && auth()->user()->can('forms.entertainment.edit')) || ($role == 'Medical Representatif' && $item->status == 'On Progress'))
<a href="{{ route('forms.entertainment.edit', $item->id) }}" class="btn btn-warning btn-sm">
<i class="fas fa-edit text-white"></i>
</a>
@endif
@if (($role != 'Medical Representatif' && auth()->user()->can('forms.entertainment.delete')) || ($role == 'Medical Representatif' && $item->status == 'On Progress'))
<form action="{{ route('forms.entertainment.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">
<strong>NIK/NPWP Penerima:</strong> <span id="nik_or_npwp"></span>
</li>
<li class="list-group-item">
<strong>Nama Penerima:</strong> <span id="name"></span>
</li>
<li class="list-group-item">
<strong>Alamat Penerima:</strong> <span id="alamat"></span>
</li>
<li class="list-group-item">
<strong>Jenis:</strong> <span id="jenis"></span>
</li>
<li class="list-group-item">
<strong>Tanggal:</strong> <span id="tanggal"></span>
</li>
<li class="list-group-item">
<strong>Keterangan:</strong> <span id="keterangan"></span>
</li>
<li class="list-group-item">
<strong>Bukti Total Pengeluaran:</strong> <span id="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">
<input type="checkbox" class="custom-control-input" id="total_bensin" name="total_bensin">
<label class="custom-control-label" for="total_bensin">Total Pengeluaran (<span id="total_bensin_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
@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,
dom: 'Bfrtip',
buttons: ['excel', 'pdf', 'print', 'colvis'],
});
}
// 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
$('#loadingSpinner').addClass('d-flex');
$('#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
});
$('#total_bensin_value').text(formatter.format(data.total));
$('#total_bensin').data('value', data.total);
// Detail data
$('#user').text(data.user.name);
$('#nik_or_npwp').text(data.nik_or_npwp);
$('#name').text(data.name);
$('#alamat').text(data.alamat);
$('#expense_number').text(data.expense_number);
$('#jenis').text(data.jenis);
$('#keterangan').text(data.keterangan);
$('#tanggal').text(new Date(data.tanggal).toLocaleDateString('id-ID', {
year: 'numeric',
month: 'long',
day: 'numeric',
}));
$('#bukti_total').html(data.bukti_total ? '<a href="' + data.bukti_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);
});
});
// 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