DONE: optimize loading page on employee, append the online payment under same batch

This commit is contained in:
ISMAIL MASSERAN
2026-09-06 10:21:04 +08:00
parent effe268e3b
commit 9fbcf86325
4 changed files with 117 additions and 87 deletions
+36 -3
View File
@@ -20,10 +20,43 @@ class KakitanganController extends Controller
public function daftarKakitangan(){
$api_url = config('api.url');
$auth_user = Auth::user();
$cawangan_info = Http::withOptions(['verify' => config('app.api_verify')])->get(config('api.url') . '/api/cawangan/'. $auth_user['cawangan'])->json();
$http = Http::withOptions(['verify' => config('app.api_verify')]);
$cawangan_all = $http->get($api_url . '/api/cawangan')->json();
$cawangan_all = is_array($cawangan_all) ? $cawangan_all : [];
$cawangan_by_kod = collect($cawangan_all)->keyBy('kodcaw');
$cawangan_info = $cawangan_by_kod->get($auth_user['cawangan'], []);
$role = Role::get();
$kakitangan = User::all();
return view('operasi.daftar_kakitangan',compact('cawangan_info','api_url','role','kakitangan','auth_user'));
$kakitangan_rows = User::where('roles', '!=', 'admin')
->get()
->values()
->map(function ($staff) use ($cawangan_by_kod) {
$kod = (string) $staff->cawangan;
if (in_array($kod, ['operasi', 'callcenter', 'admin'], true)) {
$cawangan_nama = ucwords($kod);
} else {
$cawangan_nama = ucwords((string) data_get($cawangan_by_kod, $kod . '.details_caw', $kod));
}
return [
'id' => $staff->id,
'name' => $staff->name,
'roles' => strtoupper((string) $staff->roles),
'role_harian' => $staff->role_harian ? strtoupper($staff->role_harian) : '-',
'role_asal' => $staff->role_asal ? strtoupper($staff->role_asal) : '-',
'cawangan' => $cawangan_nama,
];
});
return view('operasi.daftar_kakitangan', compact(
'cawangan_info',
'api_url',
'role',
'kakitangan_rows',
'auth_user',
'cawangan_all'
));
}
public function registerStaff(Request $request){
@@ -132,9 +132,14 @@ class PembiayaanOnlineController extends Controller
return redirect()->back()->with('error', $msg);
}
$batchNo = $res->json()['batch']['batch_no'] ?? '';
return redirect()->route('pembiayaan.online.pc')
->with('message', 'Batch dihantar ke Operasi' . ($batchNo ? ': ' . $batchNo : '.'));
$payload = $res->json();
$batchNo = is_array($payload) ? ($payload['batch']['batch_no'] ?? '') : '';
$appended = is_array($payload) && !empty($payload['appended']);
$message = $appended
? ('Rekod ditambah ke batch' . ($batchNo ? ' ' . $batchNo : '') . '.')
: ('Batch dihantar ke Operasi' . ($batchNo ? ': ' . $batchNo : '.'));
return redirect()->route('pembiayaan.online.pc')->with('message', $message);
}
/**
@@ -43,9 +43,6 @@
<b>Cawangan</b>
</div>
<div class='col-md-7'>
@php
$cawangan_all = Http::withOptions(['verify' => config('app.api_verify')])->get($api_url . '/api/cawangan')->json();
@endphp
<select class="form-control" name="cawangan" data-placeholder="Pilih Cawangan" id="cawangan">
<option disabled selected value> -- Pilih Cawangan -- </option>
<option value="operasi">Operasi</option>
@@ -106,81 +103,12 @@
<div class="card-body text-center">
<div class="row">
<div class="col-md-12">
<table id="rekod_kakitangan" class="table table-striped table-hover">
<thead class="thead-dark">
<tr>
<th>Bil</th>
<th>Nama Staff</th>
<th>Jawatan</th>
<th>Cawangan</th>
<th>Tindakan</th>
</tr>
</thead>
<tbody>
@foreach($kakitangan as $index=>$staff)
@if($staff->roles != 'admin')
<tr>
<td>{{ $loop->iteration }}</td>
<td>{{ $staff->name }}</td>
<td>{{ strtoupper($staff->roles) }}</td>
<td>
@if($staff->cawangan == 'operasi' || $staff->cawangan == 'callcenter' || $staff->cawangan == 'admin')
{{ ucwords($staff->cawangan) }}
@else
@php
$cawangan_staff = Http::withOptions(['verify' => config('app.api_verify')])->get(config('api.url') . '/api/cawangan/'. $staff->cawangan)->json();
echo (isset($cawangan_staff['details_caw'])) ? ucwords($cawangan_staff['details_caw']) : 'test';
@endphp
@endif
</td>
<td>
@if($auth_user->roles == 'operasi')
<a href="{{ route('kakitangan.tukartaraf',['id'=>$staff->id]) }}" class="btn btn-warning" title="Tukar Taraf"><i class="material-icons">edit</i></a>
<a href="{{ route('kakitangan.tukarcawangan',['id'=>$staff->id]) }}" class="btn btn-info" title="Tukar Cawangan"><i class="material-icons">work</i></a>
<a href="{{ route('operasi.kakitangan.edit',['id'=>$staff->id]) }}" class="btn btn-success" title="Edit Maklumat"><i class="material-icons">settings</i></a>
@if(
app()->environment(['local', 'staging'])
&&
in_array($auth_user->roles, ['admin'])
&& $staff->roles != 'admin'
&& $staff->id != $auth_user->id
&& !(Auth::check() && method_exists(Auth::user(), 'isImpersonated') && Auth::user()->isImpersonated())
)
<form method="post" action="{{ route('impersonate.start', ['id' => $staff->id]) }}" style="display:inline;">
@csrf
<button type="button" class="btn btn-secondary btn-impersonate" data-staff-name="{{ $staff->name }}" title="Impersonate"><i class="material-icons">supervised_user_circle</i></button>
</form>
@endif
<button type="button" class="btn btn-danger btn-delete" data-roles="{{ $auth_user->roles }}" data-staff-id="{{ $staff->id }}" data-token="{{ csrf_token() }}" title="Delete Kakitangan"><i class="material-icons">delete</i></button>
@elseif($auth_user->roles == 'admin')
{{-- <form method="post" action="{{ route('admin.kakitangan.delete') }}">
{{ @csrf_field() }} --}}
<input type="hidden" name="staff_id" value="{{ $staff->id }}"/>
<a href="{{ route('admin.kakitangan.tukartaraf',['id'=>$staff->id]) }}" class="btn btn-warning" title="Tukar Taraf"><i class="material-icons">edit</i></a>
<a href="{{ route('admin.kakitangan.tukarcawangan',['id'=>$staff->id]) }}" class="btn btn-info" title="Tukar Cawangan"><i class="material-icons">work</i></a>
<a href="{{ route('admin.kakitangan.edit',['id'=>$staff->id]) }}" class="btn btn-success" title="Edit Maklumat"><i class="material-icons">settings</i></a>
<a href="{{ route('admin.kakitangan.resetcredentials',['id'=>$staff->id]) }}" class="btn btn-primary" title="Reset Password"><i class="material-icons">restore</i></a>
@if(
app()->environment(['local', 'staging'])
&&
$staff->roles != 'admin'
&& $staff->id != $auth_user->id
&& !(Auth::check() && method_exists(Auth::user(), 'isImpersonated') && Auth::user()->isImpersonated())
)
<form method="post" action="{{ route('impersonate.start', ['id' => $staff->id]) }}" style="display:inline;">
@csrf
<button type="button" class="btn btn-secondary btn-impersonate" data-staff-name="{{ $staff->name }}" title="Impersonate"><i class="material-icons">supervised_user_circle</i></button>
</form>
@endif
<button type="button" class="btn btn-danger btn-delete" data-staff-id="{{ $staff->id }}" data-token="{{ csrf_token() }}" title="Delete Kakitangan"><i class="material-icons">delete</i></button>
{{-- </form> --}}
@endif
</td>
</tr>
@endif
@endforeach
</tbody>
</table>
<x-datatable
id="rekod_kakitangan"
filename="Senarai_Kakitangan"
:columns="['Bil', 'Tindakan', 'Nama Staff', 'Jawatan', 'Role Harian', 'Role Asal', 'Cawangan']"
:skipExport="['Bil', 'Tindakan']"
/>
</div>
</div>
</div>
@@ -189,8 +117,72 @@
</div>
</div>
<script>
@php
$isOperasi = $auth_user->roles == 'operasi';
$canImpersonate = app()->environment(['local', 'staging'])
&& $auth_user->roles === 'admin'
&& !(Auth::check() && method_exists(Auth::user(), 'isImpersonated') && Auth::user()->isImpersonated());
@endphp
var tablerekod = $('#rekod_kakitangan').DataTable();
function escapeHtml(value) {
return $('<div>').text(value == null ? '' : String(value)).html();
}
function staffTindakanHtml(staff) {
var id = staff.id;
var html = '';
html += '<a href="' + staffRoutes.tukarTaraf.replace('__ID__', id) + '" class="btn btn-warning" title="Tukar Taraf"><i class="material-icons">edit</i></a> ';
html += '<a href="' + staffRoutes.tukarCawangan.replace('__ID__', id) + '" class="btn btn-info" title="Tukar Cawangan"><i class="material-icons">work</i></a> ';
html += '<a href="' + staffRoutes.edit.replace('__ID__', id) + '" class="btn btn-success" title="Edit Maklumat"><i class="material-icons">settings</i></a> ';
if (authRole === 'admin') {
html += '<a href="' + staffRoutes.reset.replace('__ID__', id) + '" class="btn btn-primary" title="Reset Password"><i class="material-icons">restore</i></a> ';
}
if (canImpersonate && id !== authUserId) {
html += '<form method="post" action="' + staffRoutes.impersonate.replace('__ID__', id) + '" style="display:inline;">' +
csrfField +
'<button type="button" class="btn btn-secondary btn-impersonate" data-staff-name="' + escapeHtml(staff.name) + '" title="Impersonate"><i class="material-icons">supervised_user_circle</i></button>' +
'</form> ';
}
html += '<button type="button" class="btn btn-danger btn-delete" data-roles="' + authRole + '" data-staff-id="' + id + '" title="Delete Kakitangan"><i class="material-icons">delete</i></button>';
return html;
}
var authRole = @json($auth_user->roles);
var authUserId = @json($auth_user->id);
var canImpersonate = @json($canImpersonate);
var csrfField = '<input type="hidden" name="_token" value="' + @json(csrf_token()) + '">';
var staffRoutes = {
tukarTaraf: @json($isOperasi ? route('kakitangan.tukartaraf', ['id' => '__ID__']) : route('admin.kakitangan.tukartaraf', ['id' => '__ID__'])),
tukarCawangan: @json($isOperasi ? route('kakitangan.tukarcawangan', ['id' => '__ID__']) : route('admin.kakitangan.tukarcawangan', ['id' => '__ID__'])),
edit: @json($isOperasi ? route('operasi.kakitangan.edit', ['id' => '__ID__']) : route('admin.kakitangan.edit', ['id' => '__ID__'])),
reset: @json(route('admin.kakitangan.resetcredentials', ['id' => '__ID__'])),
impersonate: @json(route('impersonate.start', ['id' => '__ID__']))
};
var tablerekod = initErahnDatatable('#rekod_kakitangan', {
columnDefs: [
{ targets: 0, orderable: false, width: '40px' },
{ targets: 1, orderable: false, searchable: false }
]
});
$.each(@json($kakitangan_rows), function (index, staff) {
tablerekod.row.add([
index + 1,
staffTindakanHtml(staff),
escapeHtml(staff.name),
escapeHtml(staff.roles),
escapeHtml(staff.role_harian),
escapeHtml(staff.role_asal),
escapeHtml(staff.cawangan)
]);
});
tablerekod.draw();
$("#rekod_kakitangan").on('click', ".btn-delete", function(){
//$('.btn-delete').on('click', function(){
@@ -253,7 +245,7 @@
var staffName = $(this).data('staff-name');
Swal.fire({
title: 'Menyamar sebagai Kakitangan?',
title: 'Menyamar sebagai ' + staffName + '?',
text: "Anda akan log masuk sebagai " + staffName + ".",
type: 'warning',
showCancelButton: true,
@@ -3,7 +3,7 @@
@php
$pendingCount = collect($lines)->whereIn('status', ['IN_BATCH', 'OPS_REVIEW'])->count();
$approvedCount = collect($lines)->where('status', 'APPROVED')->count();
$cawName = $cawangan_info['nama'] ?? $cawangan_info['namacaw'] ?? $kodcaw;
$cawName = $cawangan_info['details_caw'] ?? $cawangan_info['namacaw'] ?? $kodcaw;
@endphp
<div class="container-fluid">
<div class="row justify-content-center">