Homepage update

parent 00bade44
...@@ -48,6 +48,7 @@ ...@@ -48,6 +48,7 @@
@section('content') @section('content')
{{-- First Card (Main / Staff Info) --}}
<div class="ui raised segment"> <div class="ui raised segment">
<a class="ui red ribbon label">Selamat Kembali</a> <a class="ui red ribbon label">Selamat Kembali</a>
<br><br> <br><br>
...@@ -58,53 +59,48 @@ ...@@ -58,53 +59,48 @@
<tr> <tr>
<td width="50%"> <td width="50%">
<h4 class="ui image header"> <h4 class="ui image header">
<i class="id card icon" class="ui mini rounded image"></i> <i class="id card icon"></i>
<div class="content"> <div class="content">
<span <span style="font-size: 14px !important;font-weight: normal !important;padding-left:10px">Nama</span>
style="font-size: 14px !important;font-weight: normal !important;padding-left:10px">Nama</span>
</div> </div>
</h4> </h4>
</td> </td>
<td>{{ data_get($staff, 'name',auth()->user()->name) }}</td> <td>{{ data_get($staff, 'name', auth()->user()->name ?? '-') }}</td>
</tr> </tr>
<tr> <tr>
<td width="50%"> <td width="50%">
<h4 class="ui image header"> <h4 class="ui image header">
<i class="certificate icon" class="ui mini rounded image"></i> <i class="certificate icon"></i>
<div class="content"> <div class="content">
<span <span style="font-size: 14px !important;font-weight: normal !important;padding-left:10px">No. Pekerja</span>
style="font-size: 14px !important;font-weight: normal !important;padding-left:10px">No.
Pekerja</span>
</div> </div>
</h4> </h4>
</td> </td>
<td>{{ data_get($staff, 'employeeCode',auth()->user()->id) }}</td> <td>{{ data_get($staff, 'employeeCode', auth()->user()->id ?? '-') }}</td>
</tr> </tr>
<tr> <tr>
<td width="50%"> <td width="50%">
<h4 class="ui image header"> <h4 class="ui image header">
<i class="sitemap icon" class="ui mini rounded image"></i> <i class="sitemap icon"></i>
<div class="content" style="font-style: unset"> <div class="content" style="font-style: unset">
<span <span style="font-size: 14px !important;font-weight: normal !important;padding-left:10px">Department</span>
style="font-size: 14px !important;font-weight: normal !important;padding-left:10px">Department</span>
</div> </div>
</h4> </h4>
</td> </td>
<td>{{ data_get($staff, 'staffinfo.department.description') }}</td> <td>{{ data_get($staff, 'staffinfo.department.description', '-') }}</td>
</tr> </tr>
<tr> <tr>
<td width="50%"> <td width="50%">
<h4 class="ui image header"> <h4 class="ui image header">
<i class="user tie icon" class="ui mini rounded image"></i> <i class="user tie icon"></i>
<div class="content" style="font-style: unset"> <div class="content" style="font-style: unset">
<span <span style="font-size: 14px !important;font-weight: normal !important;padding-left:10px">Peranan</span>
style="font-size: 14px !important;font-weight: normal !important;padding-left:10px">Peranan</span>
</div> </div>
</h4> </h4>
</td> </td>
<td> <td>
@php @php
$roles = $staff->roles->pluck('name')->toArray(); $roles = optional($staff)->roles ? $staff->roles->pluck('name')->toArray() : [];
@endphp @endphp
{{ !empty($roles) ? implode(', ', $roles) : '-' }} {{ !empty($roles) ? implode(', ', $roles) : '-' }}
</td> </td>
...@@ -114,17 +110,98 @@ ...@@ -114,17 +110,98 @@
</div> </div>
</div> </div>
</div> </div>
@endsection
@push('script') {{-- Second Card (Overtime System Info) --}}
<script src="{{ asset('web/vendor/fullcalendar/lib/moment.min.js') }}"></script> <div class="ui raised segment">
<script src="{{ asset('web/vendor/fullcalendar/fullcalendar.min.js') }}"></script> <a class="ui blue ribbon label">Maklumat Kerja Lebih Masa (OT)</a>
<script src="{{ asset('web/vendor/fullcalendar/locale/ms-my.js') }}"></script> <br><br>
<div class="ui stackable grid">
<script> <div class="sixteen wide column">
$(document).ready(function() { <table class="ui celled table" style="width:100% !important">
<tbody>
}); <tr>
</script> <td width="50%">
<h4 class="ui image header">
<i class="clock icon"></i>
<div class="content">
<span style="font-size: 14px !important;font-weight: normal !important;padding-left:10px">Jumlah Jam OT (Bulan Ini)</span>
</div>
</h4>
</td>
<td>{{ data_get($overtime ?? [], 'total_hours', '0') }} Jam</td>
</tr>
<tr>
<td width="50%">
<h4 class="ui image header">
<i class="calculator icon"></i>
<div class="content">
<span style="font-size: 14px !important;font-weight: normal !important;padding-left:10px">Anggaran Bayaran OT</span>
</div>
</h4>
</td>
<td>RM {{ number_format((float) data_get($overtime ?? [], 'estimated_pay', 0), 2) }}</td>
</tr>
<tr>
<td width="50%">
<h4 class="ui image header">
<i class="tasks icon"></i>
<div class="content" style="font-style: unset">
<span style="font-size: 14px !important;font-weight: normal !important;padding-left:10px">Status Permohonan</span>
</div>
</h4>
</td>
<td>{{ data_get($overtime ?? [], 'status', '-') }}</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
@endpush {{-- Third Card (Mileage Claim Info) --}}
<div class="ui raised segment">
<a class="ui teal ribbon label">Maklumat Tuntutan Mileage</a>
<br><br>
<div class="ui stackable grid">
<div class="sixteen wide column">
<table class="ui celled table" style="width:100% !important">
<tbody>
<tr>
<td width="50%">
<h4 class="ui image header">
<i class="car icon"></i>
<div class="content">
<span style="font-size: 14px !important;font-weight: normal !important;padding-left:10px">Jumlah Jarak Perjalanan</span>
</div>
</h4>
</td>
<td>{{ number_format((float) data_get($mileage ?? [], 'total_distance', 0), 1) }} KM</td>
</tr>
<tr>
<td width="50%">
<h4 class="ui image header">
<i class="money bill alternate icon"></i>
<div class="content">
<span style="font-size: 14px !important;font-weight: normal !important;padding-left:10px">Jumlah Tuntutan Mileage</span>
</div>
</h4>
</td>
<td>RM {{ number_format((float) data_get($mileage ?? [], 'total_amount', 0), 2) }}</td>
</tr>
<tr>
<td width="50%">
<h4 class="ui image header">
<i class="file alternate icon"></i>
<div class="content" style="font-style: unset">
<span style="font-size: 14px !important;font-weight: normal !important;padding-left:10px">Status Permohonan Terkini</span>
</div>
</h4>
</td>
<td>{{ data_get($mileage ?? [], 'status', '-') }}</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
@endsection
\ No newline at end of file
...@@ -4,28 +4,82 @@ ...@@ -4,28 +4,82 @@
use Illuminate\Routing\Controller; use Illuminate\Routing\Controller;
use Portal\Mileage\Model\Users; use Portal\Mileage\Model\Users;
use Portal\Mileage\Model\MileageClaimMain;
class DashboardController extends Controller class DashboardController extends Controller
{ {
public function __construct() public function __construct()
{ {
}
}
public function index() public function index()
{ {
// logic filter role kat user yang nak login // Role filtering logic if needed
if (auth()->user()->hasRole(['Administrator'])) {
if (auth()->user()->hasRole(['Administrator'])){
// allow access to dashboard // allow access to dashboard
} }
// Fetch staff details with staffinfo, department, and roles
$staff = Users::where('employeeCode', auth()->user()->employeeCode) $staff = Users::where('employeeCode', auth()->user()->employeeCode)
->with('staffinfo.department', 'roles') // added nested relationship ->with(['staffinfo.department', 'roles'])
->first(); ->first();
// Default / Fallback overtime structure
$overtime = [
'total_hours' => 0,
'estimated_pay' => 0.00,
'status' => '-'
];
// Fetch Mileage Claim stats for the logged-in user
$staffInfoId = optional($staff)->staffinfo ? $staff->staffinfo->id : null;
$totalMileageDistance = 0;
$totalMileageAmount = 0;
$latestClaimStatus = '-';
if ($staffInfoId) {
$userClaims = MileageClaimMain::where('fk_lkp_staff_info', $staffInfoId)
->with(['details', 'finance', 'lkpStatus'])
->get();
foreach ($userClaims as $claim) {
// Sum distance from details or main table
if ($claim->details && $claim->details->count() > 0) {
$totalMileageDistance += $claim->details->sum(function ($d) {
return (float) ($d->md_total_mileage ?? $d->md_distance ?? $d->md_mileage ?? 0);
});
} else {
$totalMileageDistance += (float) ($claim->mm_total_mileage ?? 0);
}
// Sum claim amount from finance or detail
$amount = (float) (
optional($claim->finance)->fin_final_amount ??
$claim->fin_final_amount ??
$claim->total_amount ??
0
);
$totalMileageAmount += $amount;
}
// Grab latest claim status
$latestClaim = $userClaims->sortByDesc('mm_submit_date')->first();
if ($latestClaim) {
$latestClaimStatus = optional($latestClaim->lkpStatus)->ref_description
?? $latestClaim->status_label
?? $latestClaim->status
?? '-';
}
}
$mileage = [
'total_distance' => $totalMileageDistance,
'total_amount' => $totalMileageAmount,
'status' => $latestClaimStatus,
];
return view('mileage::dashboard.pegawai',compact('staff')); return view('mileage::dashboard.pegawai', compact('staff', 'overtime', 'mileage'));
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment