Commit 786bc219 by Muhammad Aniq bin Mohd Nizam

Merge branch 'master' of https://coders.3fresources.com/trainee/mileage-claim

# Conflicts:
#	packages/portal/mileage/routes/web.php
parents c40125a6 470f1281
<title>HR Dashboard</title>
@extends('ui::layouts.app') @extends('ui::layouts.app')
@section('content') @section('content')
<style>
body {
background-color: #f0f2f5;
}
.ui.container { <div class="ui segment">
max-width: 100% !important; <a class="ui teal left ribbon label">Senarai Tuntutan Mileage (HR)</a><br/>
overflow-x: hidden; <div class="ui segment">
padding: 0 5rem 0 2rem;
box-sizing: border-box; @if(session('success'))
margin-top: 3rem; <div class="ui success message">{{ session('success') }}</div>
} @endif
@if(session('error'))
h2.ui.header { <div class="ui error message">{{ session('error') }}</div>
font-size: 1.8rem; @endif
font-weight: 700;
color: #1b1c1d; @php
margin-bottom: 0.5rem; $bulan = [
} 1=>'Januari', 2=>'Februari', 3=>'Mac', 4=>'April',
5=>'Mei', 6=>'Jun', 7=>'Julai', 8=>'Ogos',
h3.ui.dividing.header { 9=>'September', 10=>'Oktober', 11=>'November', 12=>'Disember'
font-size: 1.3rem; ];
font-weight: 600; $currentYear = \Carbon\Carbon::now()->year;
color: #444; $statusOptions = [
margin-top: 0.5rem; 11 => 'Disemak Kewangan',
margin-bottom: 1.5rem; 12 => 'Dibayar',
border-bottom: 2px solid #ddd; ];
padding-bottom: 0.5rem; @endphp
}
<form method="GET" action="{{ route('mileage::HR.index') }}" class="ui form" style="margin-bottom: 1rem;">
.ui.table { <div class="four fields">
margin-top: 1rem !important; <div class="field">
background: white; <label>Tahun</label>
border-radius: 10px; <select name="tahun" class="ui dropdown">
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); <option value="">Semua Tahun</option>
} @for($y = $currentYear; $y >= $currentYear - 4; $y--)
<option value="{{ $y }}" {{ request('tahun') == $y ? 'selected' : '' }}>{{ $y }}</option>
.ui.table th { @endfor
background: #f9fafb !important; </select>
color: #444;
font-weight: 600;
}
.ui.button {
margin-right: 0.3rem !important;
}
/* Filter bar (aligned right side of header) */
.header-with-filter {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 1.2rem;
}
.filter-bar {
display: flex;
align-items: center;
gap: 1rem;
background: white;
border-radius: 8px;
box-shadow: 0 3px 6px rgba(0, 0, 0, 0.08);
padding: 0.5rem 1rem;
width: fit-content;
}
.filter-bar label {
font-weight: 600;
color: #333;
margin-right: 0.5rem;
}
.filter-bar input[type="month"] {
border: 1px solid #dcdcdc;
border-radius: 6px;
padding: 0.4rem 0.6rem;
font-size: 1rem;
color: #333;
transition: all 0.2s ease;
}
.filter-bar input[type="month"]:focus {
border-color: #21ba45;
outline: none;
box-shadow: 0 0 0 2px rgba(33, 186, 69, 0.15);
}
@media (max-width: 768px) {
.ui.container {
padding: 0 2rem;
}
.header-row {
flex-direction: column;
align-items: flex-start;
gap: 1rem;
}
.filter-bar {
flex-direction: column;
align-items: flex-start;
width: 100%;
}
.filter-bar button {
width: 100%;
}
}
</style>
<div class="ui container mt-5" style="margin-top: 10px">
{{-- Header --}}
<br>
<div class="header-row" style="display: flex; justify-content: space-between; align-items: center;">
<h2 class="ui header">Human Resources (HR) Dashboard</h2>
{{-- Excel Export Button --}}
<button class="ui teal button" id="openExportModal">
<i class="file excel icon"></i> Muat Turun Laporan Excel
</button>
</div> </div>
<br><br> <div class="field">
<label>Bulan</label>
{{-- Header + Filter Bar in same row --}} <select name="bulan" class="ui dropdown">
<div class="header-with-filter"> <option value="">Semua Bulan</option>
<h3 class="ui dividing header" style="margin-bottom: 0;">Senarai Tuntutan Mengikut Staf</h3> @foreach($bulan as $num => $nama)
<option value="{{ $num }}" {{ request('bulan') == $num ? 'selected' : '' }}>{{ $nama }}</option>
<form method="GET" class="filter-bar"> @endforeach
<label for="month">Bulan:</label> </select>
<input type="month" id="month" name="month" value="{{ $month ?? now()->format('Y-m') }}" required>
<button class="ui teal button">
<i class="filter icon"></i> Tapis
</button>
</form>
</div> </div>
<div class="field">
<label>Status</label>
<select name="status" class="ui dropdown">
<option value="">Semua Status</option>
@foreach($statusOptions as $val => $label)
<option value="{{ $val }}" {{ request('status') == $val ? 'selected' : '' }}>{{ $label }}</option>
@endforeach
</select>
</div>
<div class="field">
<label>Cari</label>
<input type="text" name="search" value="{{ request('search') }}" placeholder="No. permohonan / nama pemohon">
</div>
</div>
<div style="text-align: right;">
@if(request()->hasAny(['tahun', 'bulan', 'status', 'search']))
<a href="{{ route('mileage::HR.index') }}" class="ui button">Reset</a>
@endif
<button type="submit" class="ui teal button"><i class="search icon"></i> Cari</button>
</div>
</form>
{{-- Staff Table --}}
<table class="ui celled table"> <table class="ui celled table">
<thead> <thead>
<tr> <tr>
<th>Nama Staf</th> <th>No</th>
<th>Jumlah Tuntutan</th> <th>No. Permohonan</th>
<th>Jumlah Keseluruhan (RM)</th> <th>Nama Pemohon</th>
<th>Bulan Tuntutan</th>
<th>Tarikh Hantar</th>
<th>Status</th>
<th>Tindakan</th> <th>Tindakan</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@forelse($users as $user) @forelse($list as $index => $claim)
<tr> <tr>
<td>{{ $user['name'] }}</td> <td>{{ $list->firstItem() + $index }}</td>
<td>{{ $user['total_claims'] }}</td> <td>{{ $claim->mm_apply_no }}</td>
<td>RM {{ number_format($user['total_amount'], 2) }}</td> <td>{{ $claim->mm_staff_name ?? '-' }}</td>
<td>{{ ($bulan[$claim->mm_claim_month] ?? '-') . ' ' . $claim->mm_claim_year }}</td>
<td>{{ $claim->mm_submit_date ? \Carbon\Carbon::parse($claim->mm_submit_date)->format('d/m/Y') : '-' }}</td>
<td>
<span class="ui {{ $claim->status == 12 ? 'green' : 'blue' }} label">
{{ $claim->lkpStatus?->description ?? '-' }}
</span>
</td>
<td> <td>
<a href="{{ route('mileage::HR.show', ['userId' => $user['id'], 'month' => $month]) }}" <a href="{{ route('mileage::HR.show', $claim->id) }}" class="ui blue small button">
class="ui blue button tiny">Lihat</a> <i class="eye icon"></i> Lihat
</a>
</td> </td>
</tr> </tr>
@empty @empty
<tr> <tr>
<td colspan="4" class="center aligned">Tiada rekod tuntutan untuk bulan ini.</td> <td colspan="7" class="center aligned">Tiada rekod dijumpai.</td>
</tr> </tr>
@endforelse @endforelse
</tbody> </tbody>
</table> </table>
</div>
{{-- Filter Modal for Excel Export --}}
<div class="ui modal" id="exportModal">
<div class="header">Penapis Laporan Excel</div>
<div class="content">
<form class="ui form" action="{{ route('mileage::HR.export') }}" method="GET">
<div class="field">
<label>Nama Staf</label>
<select name="user_id" class="ui dropdown" required>
<option value="">-- Pilih Staf --</option>
@foreach($users as $user)
<option value="{{ $user['id'] }}">{{ $user['name'] }}</option>
@endforeach
</select>
</div>
<div class="field"> {{ $list->withQueryString()->links() }}
<label>Bulan Tuntutan</label>
<input type="month" name="month" required>
</div>
<div class="actions" style="text-align: right; margin-top: 2rem;">
<button type="button" class="ui button" id="cancelExport">Batal</button>
<button type="submit" class="ui teal button">
<i class="download icon"></i> Muat Turun
</button>
</div>
</form>
</div> </div>
</div> </div>
{{-- JS --}} @endsection
<script>
document.getElementById('openExportModal').addEventListener('click', function() {
$('#exportModal').modal('show');
});
document.getElementById('cancelExport').addEventListener('click', function() { @push('script')
$('#exportModal').modal('hide'); <script>
}); $(document).ready(function () {
$('.ui.dropdown').dropdown();
});
</script> </script>
@endsection @endpush
<title>Butiran Tuntutan Staf</title>
@extends('ui::layouts.app') @extends('ui::layouts.app')
@section('content') @section('content')
<style>
body { background-color: #f0f2f5; }
.ui.container { padding: 0 5rem 3rem 2rem; margin-top: 3rem; }
h2.ui.header { font-size: 1.8rem; font-weight: 700; margin-bottom: .5rem; }
.ui.table { background: white; border-radius: 10px; box-shadow: 0 4px 6px rgba(0,0,0,0.1); }
.ui.segment {
background: white;
border-radius: 10px;
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
margin-top: 2rem;
padding: 1.5rem;
}
.ui.button { margin-top: 1rem; }
.status-label {
display: inline-block;
padding: 6px 12px;
border-radius: 8px;
font-size: 0.85rem;
font-weight: 600;
text-transform: capitalize;
opacity: 0.9;
}
.status-Diproses { background-color: rgba(33, 133, 208, 0.3); color: #1b4f72; }
.status-Disokong { background-color: rgba(46, 204, 113, 0.3); color: #1d5d38; }
.status-Disahkan { background-color: rgba(241, 196, 15, 0.3); color: #7a6000; }
.status-Disemak { background-color: rgba(155, 89, 182, 0.3); color: #4a2c63; }
.status-Diluluskan { background-color: rgba(26, 188, 156, 0.3); color: #0b5449; }
.status-Ditolak { background-color: rgba(231, 76, 60, 0.3); color: #7e2018; }
@media (max-width: 768px) {
.ui.container { padding: 0 2rem; }
}
.totals-row td {
font-weight: 700;
background: #f7f7f8;
}
</style>
<div class="ui container"> <div class="ui segment">
{{-- Header --}} <a class="ui teal left ribbon label">Butiran Tuntutan Mileage (HR) - {{ $claim->mm_apply_no }}</a><br/><br/>
<h2 class="ui header">{{ $user->name }}</h2>
<p><strong>Bulan:</strong> {{ \Carbon\Carbon::parse($month)->translatedFormat('F Y') }}</p>
{{-- Back button --}} {{-- Maklumat Permohonan --}}
<a href="{{ route('mileage::HR.index', ['month' => $month]) }}" class="ui grey button"> <div class="ui segment">
<i class="arrow left icon"></i> Kembali <h3 class="ui header">Maklumat Permohonan</h3>
</a> @php
$bulan = [
1=>'Januari', 2=>'Februari', 3=>'Mac', 4=>'April',
5=>'Mei', 6=>'Jun', 7=>'Julai', 8=>'Ogos',
9=>'September', 10=>'Oktober', 11=>'November', 12=>'Disember'
];
@endphp
<table class="ui definition table">
<tr>
<td>No. Permohonan</td>
<td>{{ $claim->mm_apply_no }}</td>
</tr>
<tr>
<td>Nama Pemohon</td>
<td>{{ $claim->mm_staff_name ?? '-' }}</td>
</tr>
<tr>
<td>Kategori FA</td>
<td>{{ $claim->faCategory?->fa_category ?? '-' }}</td>
</tr>
<tr>
<td>Bulan Tuntutan</td>
<td>{{ ($bulan[$claim->mm_claim_month] ?? '-') . ' ' . $claim->mm_claim_year }}</td>
</tr>
<tr>
<td>Tarikh Hantar</td>
<td>{{ $claim->mm_submit_date ? \Carbon\Carbon::parse($claim->mm_submit_date)->format('d/m/Y') : '-' }}</td>
</tr>
<tr>
<td>Disokong Oleh (HOD)</td>
<td>{{ $claim->verifiedBy?->name ?? '-' }}{{ $claim->mm_verified_date ? ' (' . \Carbon\Carbon::parse($claim->mm_verified_date)->format('d/m/Y') . ')' : '' }}</td>
</tr>
<tr>
<td>Diluluskan Oleh (BOD)</td>
<td>{{ $claim->approvedBy?->name ?? '-' }}{{ $claim->mm_approved_date ? ' (' . \Carbon\Carbon::parse($claim->mm_approved_date)->format('d/m/Y') . ')' : '' }}</td>
</tr>
<tr>
<td>Status</td>
<td>
<span class="ui {{ $claim->status == 12 ? 'green' : 'blue' }} label">
{{ $claim->lkpStatus?->description ?? '-' }}
</span>
</td>
</tr>
</table>
</div>
{{-- Claims Table --}} {{-- Butiran Tuntutan --}}
<div class="ui segment">
<h3 class="ui header">Butiran Tuntutan</h3>
<table class="ui celled table"> <table class="ui celled table">
<thead> <thead>
<tr> <tr>
<th>No</th>
<th>Tarikh</th> <th>Tarikh</th>
<th>Kenderaan</th>
<th>Projek</th>
<th>Butiran</th> <th>Butiran</th>
<th>Dari</th> <th class="right aligned">Jumlah Jarak (KM)</th>
<th>Ke</th> <th class="right aligned">Jumlah Tol (RM)</th>
<th>Jumlah KM</th> <th class="right aligned">Jumlah Parking (RM)</th>
<th>Tol (RM)</th> <th class="right aligned">Anggaran Tuntutan (RM)</th>
<th>Lain-lain (RM)</th>
<th>Status</th>
<th>Jumlah (RM)</th>
<th>Tindakan</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@php @php
$total = 0; $grandAnggaran = 0; $grandTol = 0; $grandParking = 0; $grandJarak = 0;
$totalMileage = 0; $deductionCount = 0;
$totalToll = 0; $sortedDetails = $claim->details->sortBy('md_claim_date')->values();
$totalOthers = 0; $dateCounts = [];
foreach ($sortedDetails as $d) {
$dk = $d->md_claim_date;
$dateCounts[$dk] = ($dateCounts[$dk] ?? 0) + 1;
}
$dateFirstSeen = [];
$cumulativeKm = 0;
@endphp @endphp
@forelse($claims as $claim) @forelse($sortedDetails as $index => $detail)
@php @php
$total += $claim->total_claim_amount; $jumlahJarak = (float) $detail->md_total_mileage;
$totalMileage += $claim->total_mileage ?? 0; $dateKey = $detail->md_claim_date;
$totalToll += $claim->toll_amount ?? 0; $isFirstOfDate = !isset($dateFirstSeen[$dateKey]);
$totalOthers += $claim->others_amount ?? 0; if ($isFirstOfDate) $dateFirstSeen[$dateKey] = true;
if ($isFirstOfDate && $deductionCount < 10) {
$claimableKm = max(0, $jumlahJarak - 40);
$deductionCount++;
} else {
$claimableKm = $jumlahJarak;
}
$startKm = $cumulativeKm;
$endKm = $cumulativeKm + $claimableKm;
$mileageAmount = 0;
foreach ($detail->jenisKenderaan?->rates ?? collect() as $tier) {
$kmInTier = max(0, min($tier->km_to, $endKm) - max($tier->km_from, $startKm));
$mileageAmount += $kmInTier * (float) $tier->rate;
}
$cumulativeKm = $endKm;
$jumlahTol = (float) $detail->md_total_toll;
$jumlahParking = (float) $detail->md_total_parking_fee;
$anggaranTuntutan = $mileageAmount + $jumlahTol + $jumlahParking;
$grandJarak += $jumlahJarak;
$grandTol += $jumlahTol;
$grandParking += $jumlahParking;
$grandAnggaran += $anggaranTuntutan;
@endphp @endphp
<tr> <tr>
<td>{{ \Carbon\Carbon::parse($claim->claim_date)->format('d/m/Y') }}</td> <td>{{ $index + 1 }}</td>
<td>{{ $claim->description ?? '-' }}</td> @if($isFirstOfDate)
<td>{{ $claim->distance_from ?? '-' }}</td> <td rowspan="{{ $dateCounts[$dateKey] }}">{{ \Carbon\Carbon::parse($dateKey)->format('d/m/Y') }}</td>
<td>{{ $claim->distance_to ?? '-' }}</td>
<td>{{ $claim->total_mileage }}</td>
<td>{{ number_format($claim->toll_amount ?? 0, 2) }}</td>
<td>{{ number_format($claim->others_amount ?? 0, 2) }}</td>
<td>
<span class="status-label status-{{ $claim->status }}">
{{ $claim->status }}
</span>
</td>
<td>{{ number_format($claim->total_claim_amount, 2) }}</td>
<td style="text-align:center;">
{{-- Lihat (View) --}}
<a href="{{ route('mileage::HR.viewEach', ['id' => $claim->id]) }}" class="ui blue button tiny">
<i class="eye icon"></i> Lihat
</a>
{{-- Tolak (Reject) --}}
@if(!in_array($claim->status, ['Ditolak', 'Diluluskan']))
<form action="{{ route('mileage::HR.reject', $claim->id) }}" method="POST" style="display:inline;">
@csrf
<button type="submit" class="ui red button tiny" onclick="return confirm('Tolak tuntutan ini?')">
<i class="times icon"></i> Tolak
</button>
</form>
@endif @endif
</td> <td>{{ $detail->jenisKenderaan?->name ?? '-' }}</td>
<td>{{ $detail->project ? $detail->project->p_project_code . ' - ' . $detail->project->p_project_description : 'Tiada Projek' }}</td>
<td>{{ $detail->md_description }}</td>
<td class="right aligned">{{ number_format($jumlahJarak, 1) }}</td>
<td class="right aligned">{{ number_format($jumlahTol, 2) }}</td>
<td class="right aligned">{{ number_format($jumlahParking, 2) }}</td>
<td class="right aligned">{{ number_format($anggaranTuntutan, 2) }}</td>
</tr> </tr>
@empty @empty
<tr> <tr>
<td colspan="10" class="center aligned">Tiada tuntutan untuk bulan ini.</td> <td colspan="9" class="center aligned">Tiada butiran.</td>
</tr> </tr>
@endforelse @endforelse
</tbody> </tbody>
@if($claim->details->count() > 0)
<tfoot>
<tr>
<th colspan="5" class="right aligned">JUMLAH KESELURUHAN</th>
<th class="right aligned">{{ number_format($grandJarak, 1) }}</th>
<th class="right aligned">{{ number_format($grandTol, 2) }}</th>
<th class="right aligned">{{ number_format($grandParking, 2) }}</th>
<th class="right aligned">{{ number_format($grandAnggaran, 2) }}</th>
</tr>
</tfoot>
@endif
</table> </table>
</div>
{{-- combined Calculation + Penalty Summary --}} {{-- Pelarasan Kewangan --}}
@if($claims->count() > 0) @if($claim->financeDetail)
@php <div class="ui segment">
$uniqueDates = $claims->pluck('claim_date')->unique()->count(); <h3 class="ui header">Pelarasan Kewangan</h3>
$deduction = 40 * $uniqueDates; <table class="ui definition table">
$claimableDistance = max(0, $totalMileage - $deduction); <tr>
<td>Jumlah Asal (RM)</td>
// Vehicle-based rate note <td>{{ number_format($claim->financeDetail->fin_original_amount, 2) }}</td>
$vehicleType = strtolower($claims->first()->jenisKenderaan->name ?? 'kereta'); </tr>
if ($vehicleType === 'motosikal' || $vehicleType === 'motorcycle') { <tr>
$rateNote = "Motosikal – RM0.30/km"; <td>Kadar Penalti</td>
} else { <td>
$rateNote = ($claimableDistance <= 500) @if($claim->financeDetail->fin_penalty_rate === null)
? "Kereta – RM0.55/km (≤500km)" Budi Bicara BOD
: "Kereta – 500km × RM0.55 + " . number_format($claimableDistance - 500, 1) . "km × RM0.50"; @elseif($claim->financeDetail->fin_penalty_rate == 0)
} Tiada Penalti
@else
{{ $claim->financeDetail->fin_penalty_rate }}%
@endif
</td>
</tr>
<tr>
<td>Potongan Penalti (RM)</td>
<td>{{ number_format($claim->financeDetail->fin_penalty_amount, 2) }}</td>
</tr>
@if($claim->financeDetail->fin_amendment_remark)
<tr>
<td>Catatan Kewangan</td>
<td>{{ $claim->financeDetail->fin_amendment_remark }}</td>
</tr>
@endif
<tr>
<td><strong>Jumlah Akhir Tuntutan (RM)</strong></td>
<td><strong style="color:green;">{{ number_format($claim->financeDetail->fin_final_amount, 2) }}</strong></td>
</tr>
</table>
</div>
@endif
// Penalty data {{-- Lampiran --}}
$latestClaim = $claims->sortByDesc('claim_date')->first(); <div class="ui segment">
$penaltyAmount = $latestClaim->penalty_amount ?? 0; <h3 class="ui header">Lampiran / Bukti Transaksi</h3>
$penaltyReason = $latestClaim->penalty_reason ?? '-'; @if($claim->attachments->count() > 0)
@endphp <table class="ui celled table">
<thead>
<tr>
<th>No</th>
<th>Nama Fail</th>
</tr>
</thead>
<tbody>
@foreach($claim->attachments as $index => $file)
<tr>
<td>{{ $index + 1 }}</td>
<td>
<a href="{{ asset('storage/' . $file->file_path) }}" target="_blank">
<i class="file icon"></i> {{ $file->file_name }}
</a>
</td>
</tr>
@endforeach
</tbody>
</table>
@else
<p class="ui grey text">Tiada lampiran.</p>
@endif
</div>
{{-- Sejarah Kuiri --}}
@if($claim->auditQueries->count() > 0)
<div class="ui segment"> <div class="ui segment">
<h4><i class="calculator icon"></i> Ringkasan Pengiraan (Mengikut Rekod Sistem)</h4> <h3 class="ui header">Sejarah Kuiri</h3>
<table class="ui definition table"> <table class="ui celled table">
<thead>
<tr>
<th>Bil</th>
<th>Dikuiri Oleh</th>
<th>Catatan</th>
<th>Respons Pemohon</th>
<th>Tarikh</th>
</tr>
</thead>
<tbody> <tbody>
<tr><td><strong>Jumlah Jarak (Sebenar)</strong></td><td>{{ number_format($totalMileage, 1) }} KM</td></tr> @foreach($claim->auditQueries as $index => $q)
<tr><td><strong>Jumlah Hari Tuntutan</strong></td><td>{{ $uniqueDates }} hari</td></tr> <tr>
<tr><td><strong>Potongan 40KM/Hari</strong></td><td>40 × {{ $uniqueDates }} = {{ $deduction }} KM</td></tr> <td>{{ $index + 1 }}</td>
<tr><td><strong>Jumlah Jarak Layak Tuntut</strong></td><td>{{ number_format($claimableDistance, 1) }} KM</td></tr> <td>
<tr><td><strong>Kadar Kiraan</strong></td><td>{{ $rateNote }}</td></tr> @if($q->kuiri_by === 'PM')
<tr><td><strong>Jumlah Tol</strong></td><td>RM {{ number_format($totalToll, 2) }}</td></tr> <span class="ui olive label">PM</span>
<tr><td><strong>Jumlah Lain-lain</strong></td><td>RM {{ number_format($totalOthers, 2) }}</td></tr> @elseif($q->kuiri_by === 'HOD')
<tr><td><strong>Penalti</strong></td><td>RM {{ number_format($penaltyAmount, 2) }}</td></tr> <span class="ui teal label">HOD</span>
<tr><td><strong>Sebab Penalti</strong></td><td>{{ $penaltyReason }}</td></tr> @elseif($q->kuiri_by === 'BOD')
<tr class="totals-row"> <span class="ui violet label">BOD</span>
<td><strong>Jumlah Keseluruhan Akhir</strong></td> @else
<td><strong>RM {{ number_format($total - $penaltyAmount, 2) }}</strong></td> -
@endif
</td>
<td>{{ $q->comment ?? '-' }}</td>
<td>
@if($q->response)
{{ $q->response }}
@else
<span class="ui orange label">Belum Dijawab</span>
@endif
</td>
<td>{{ \Carbon\Carbon::parse($q->created_at)->format('d/m/Y H:i') }}</td>
</tr> </tr>
@endforeach
</tbody> </tbody>
</table> </table>
</div> </div>
@endif @endif
{{-- Info Section --}} {{-- Buttons --}}
<div class="ui segment"> <div style="text-align: right;">
<h4><i class="info circle icon"></i> Seksyen Pengiraan:</h4> <a href="{{ route('mileage::HR.index') }}" class="ui button">
<p> <i class="arrow left icon"></i> Kembali
• Tuntutan bermula selepas 40KM pertama setiap hari.<br> </a>
• Kadar (Kereta): RM0.55/km (&lt;500km), RM0.50/km (&gt;500km).<br> <a href="{{ route('mileage::mileage.claim.downloadPdf', $claim->id) }}" class="ui teal button" target="_blank">
• Kadar (Motosikal): RM0.30/km.<br> <i class="file pdf icon"></i> Muat Turun PDF
• Penalti dikenakan sekiranya tuntutan lewat dihantar (&gt;1 bulan). </a>
</p>
</div> </div>
<br><br>
</div> </div>
@endsection @endsection
@push('script')
<script>
$(document).ready(function () {
$('#modalAnggaran').modal({ closable: true });
});
</script>
@endpush
<title>Maklumat Tuntutan (HR)</title>
@extends('ui::layouts.app')
@section('content')
<style>
body { background-color: #f0f2f5; }
.ui.container { max-width: 70% !important; margin-top: 2rem; }
.ui.segment {
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
border-radius: 10px;
background-color: #fff;
padding: 2rem;
}
table.ui.definition.table td:first-child {
width: 40%;
font-weight: 600;
background-color: #f9fafb;
}
.totals-row td {
font-weight: 700;
background: #f7f7f8;
}
.button-bar { margin-top: 2rem; display: flex; justify-content: space-between; }
</style>
<div class="ui container">
<h2 class="ui header">Maklumat Tuntutan (HR)</h2>
<div class="ui segment">
<table class="ui definition table">
<tr><td>Tarikh Tuntutan</td><td>{{ \Carbon\Carbon::parse($claim->claim_date)->format('d/m/Y') }}</td></tr>
<tr><td>Jenis Kenderaan</td><td>{{ $claim->jenisKenderaan->keterangan ?? $claim->jenisKenderaan->name ?? '-' }}</td></tr>
<tr><td>Nama Projek</td><td>{{ $claim->project->p_project_description ?? 'Tanpa Projek' }}</td></tr>
<tr><td>Butiran</td><td>{{ $claim->description ?? '-' }}</td></tr>
<tr><td>Jarak Dari</td><td>{{ $claim->distance_from ?? '-' }}</td></tr>
<tr><td>Jarak Ke</td><td>{{ $claim->distance_to ?? '-' }}</td></tr>
<tr><td>Jumlah Perbatuan</td><td>{{ number_format($claim->total_mileage, 2) }} km</td></tr>
<tr><td>Toll</td><td>RM {{ number_format($claim->toll_amount ?? 0, 2) }}</td></tr>
<tr><td>Lain-lain</td><td>RM {{ number_format($claim->others_amount ?? 0, 2) }}</td></tr>
<tr><td>Butiran Lain-lain</td><td>{{ $claim->others_description ?? '-' }}</td></tr>
<tr><td>Status</td><td><strong>{{ $claim->status }}</strong></td></tr>
<tr class="totals-row"><td>Jumlah Akhir</td><td><strong>RM {{ number_format($claim->total_claim_amount, 2) }}</strong></td></tr>
</table>
</div>
<div class="button-bar">
<form action="{{ url()->previous() }}" method="GET" style="display:inline;">
<button type="submit" class="ui grey button">
<i class="arrow left icon"></i> Kembali
</button>
</form>
@if(!in_array($claim->status, ['Ditolak', 'Diluluskan']))
<form action="{{ route('mileage::HR.reject', $claim->id) }}" method="POST" style="display:inline;">
@csrf
<button type="submit" class="ui red button" onclick="return confirm('Tolak tuntutan ini?')">
<i class="times icon"></i> Tolak
</button>
</form>
@endif
</div>
</div>
@endsection
...@@ -455,8 +455,14 @@ ...@@ -455,8 +455,14 @@
<a href="{{ route('mileage::mileage.listmileage') }}" class="ui right floated button"> <a href="{{ route('mileage::mileage.listmileage') }}" class="ui right floated button">
<i class="arrow left icon"></i> Kembali ke Senarai <i class="arrow left icon"></i> Kembali ke Senarai
</a> </a>
@if(in_array($claim->status, [11, 12]))
<a href="{{ route('mileage::mileage.claim.downloadPdf', $claim->id) }}" class="ui right floated teal button" target="_blank">
<i class="file pdf icon"></i> Muat Turun PDF
</a>
@endif
@endif @endif
<br> <br>
<br> <br>
......
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Tuntutan Mileage - {{ $claim->mm_apply_no }}</title>
<style>
body { font-family: Arial, sans-serif; font-size: 12px; color: #333; margin: 20px; }
h2 { font-size: 13px; border-bottom: 2px solid #333; padding-bottom: 4px; margin-top: 20px; }
table { width: 100%; border-collapse: collapse; margin-bottom: 10px; font-size: 11px; }
th { background-color: #f0f0f0; border: 1px solid #ccc; padding: 5px 8px; text-align: left; }
td { border: 1px solid #ccc; padding: 5px 8px; vertical-align: top; }
.right { text-align: right; }
.center { text-align: center; }
.label { background-color: #f9f9f9; font-weight: bold; width: 25%; }
tfoot td { background-color: #f0f0f0; font-weight: bold; }
.footer { margin-top: 30px; font-size: 10px; color: #666; text-align: center; border-top: 1px solid #ccc; padding-top: 8px; }
</style>
</head>
<body>
{{-- Header --}}
<div style="text-align:center; margin-bottom:20px;">
<div style="font-size:15px; font-weight:bold;">SISTEM TUNTUTAN MILEAGE</div>
<div style="font-size:13px; font-weight:bold; margin-top:4px;">BORANG TUNTUTAN MILEAGE</div>
<div style="margin-top:4px;">No. Permohonan: <strong>{{ $claim->mm_apply_no }}</strong></div>
</div>
{{-- 1. Maklumat Permohonan --}}
<h2>1. Maklumat Permohonan</h2>
@php
$bulan = [
1=>'Januari', 2=>'Februari', 3=>'Mac', 4=>'April',
5=>'Mei', 6=>'Jun', 7=>'Julai', 8=>'Ogos',
9=>'September', 10=>'Oktober', 11=>'November', 12=>'Disember'
];
@endphp
<table>
<tr>
<td class="label">No. Permohonan</td>
<td>{{ $claim->mm_apply_no }}</td>
<td class="label">Status</td>
<td>{{ $claim->lkpStatus?->description ?? '-' }}</td>
</tr>
<tr>
<td class="label">Nama Pemohon</td>
<td>{{ $claim->mm_staff_name ?? '-' }}</td>
<td class="label">Kategori FA</td>
<td>{{ $claim->faCategory?->fa_category ?? '-' }}</td>
</tr>
<tr>
<td class="label">Bulan Tuntutan</td>
<td>{{ ($bulan[$claim->mm_claim_month] ?? '-') . ' ' . $claim->mm_claim_year }}</td>
<td class="label">Tarikh Hantar</td>
<td>{{ $claim->mm_submit_date ? \Carbon\Carbon::parse($claim->mm_submit_date)->format('d/m/Y') : '-' }}</td>
</tr>
<tr>
<td class="label">Disokong Oleh (HOD)</td>
<td>{{ $claim->verifiedBy?->name ?? '-' }}{{ $claim->mm_verified_date ? ' (' . \Carbon\Carbon::parse($claim->mm_verified_date)->format('d/m/Y') . ')' : '' }}</td>
<td class="label">Diluluskan Oleh (BOD)</td>
<td>{{ $claim->approvedBy?->name ?? '-' }}{{ $claim->mm_approved_date ? ' (' . \Carbon\Carbon::parse($claim->mm_approved_date)->format('d/m/Y') . ')' : '' }}</td>
</tr>
</table>
{{-- 2. Butiran Tuntutan --}}
<h2>2. Butiran Tuntutan</h2>
@php
$grandAnggaran = 0; $grandTol = 0; $grandParking = 0; $grandJarak = 0;
$deductionCount = 0;
$sortedDetails = $claim->details->sortBy('md_claim_date')->values();
$dateFirstSeen = [];
$cumulativeKm = 0;
@endphp
<table>
<thead>
<tr>
<th>No</th>
<th>Tarikh</th>
<th>Kenderaan</th>
<th>Projek</th>
<th>Butiran</th>
<th class="right">Jarak (KM)</th>
<th class="right">Tol (RM)</th>
<th class="right">Parking (RM)</th>
<th class="right">Anggaran (RM)</th>
</tr>
</thead>
<tbody>
@forelse($sortedDetails as $index => $detail)
@php
$jumlahJarak = (float) $detail->md_total_mileage;
$dateKey = $detail->md_claim_date;
$isFirstOfDate = !isset($dateFirstSeen[$dateKey]);
if ($isFirstOfDate) $dateFirstSeen[$dateKey] = true;
if ($isFirstOfDate && $deductionCount < 10) {
$claimableKm = max(0, $jumlahJarak - 40);
$deductionCount++;
} else {
$claimableKm = $jumlahJarak;
}
$startKm = $cumulativeKm;
$endKm = $cumulativeKm + $claimableKm;
$mileageAmount = 0;
foreach ($detail->jenisKenderaan?->rates ?? collect() as $tier) {
$kmInTier = max(0, min($tier->km_to, $endKm) - max($tier->km_from, $startKm));
$mileageAmount += $kmInTier * (float) $tier->rate;
}
$cumulativeKm = $endKm;
$jumlahTol = (float) $detail->md_total_toll;
$jumlahParking = (float) $detail->md_total_parking_fee;
$anggaranTuntutan = $mileageAmount + $jumlahTol + $jumlahParking;
$grandJarak += $jumlahJarak;
$grandTol += $jumlahTol;
$grandParking += $jumlahParking;
$grandAnggaran += $anggaranTuntutan;
@endphp
<tr>
<td class="center">{{ $index + 1 }}</td>
<td>{{ \Carbon\Carbon::parse($dateKey)->format('d/m/Y') }}</td>
<td>{{ $detail->jenisKenderaan?->name ?? '-' }}</td>
<td>{{ $detail->project ? $detail->project->p_project_code . ' - ' . $detail->project->p_project_description : 'Tiada Projek' }}</td>
<td>{{ $detail->md_description }}</td>
<td class="right">{{ number_format($jumlahJarak, 1) }}</td>
<td class="right">{{ number_format($jumlahTol, 2) }}</td>
<td class="right">{{ number_format($jumlahParking, 2) }}</td>
<td class="right">{{ number_format($anggaranTuntutan, 2) }}</td>
</tr>
@empty
<tr><td colspan="9" class="center">Tiada butiran.</td></tr>
@endforelse
</tbody>
@if($claim->details->count() > 0)
<tfoot>
<tr>
<td colspan="5" class="right">JUMLAH KESELURUHAN</td>
<td class="right">{{ number_format($grandJarak, 1) }}</td>
<td class="right">{{ number_format($grandTol, 2) }}</td>
<td class="right">{{ number_format($grandParking, 2) }}</td>
<td class="right">{{ number_format($grandAnggaran, 2) }}</td>
</tr>
</tfoot>
@endif
</table>
{{-- 3. Pelarasan Kewangan --}}
@if($claim->financeDetail)
<h2>3. Pelarasan Kewangan</h2>
<table>
<tr>
<td class="label">Jumlah Asal (RM)</td>
<td class="right">{{ number_format($claim->financeDetail->fin_original_amount, 2) }}</td>
<td class="label">Kadar Penalti</td>
<td class="right">
@if($claim->financeDetail->fin_penalty_rate === null)
Budi Bicara BOD
@else
{{ $claim->financeDetail->fin_penalty_rate }}%
@endif
</td>
</tr>
<tr>
<td class="label">Jumlah Penalti (RM)</td>
<td class="right">{{ number_format($claim->financeDetail->fin_penalty_amount, 2) }}</td>
<td class="label">Jumlah Akhir (RM)</td>
<td class="right"><strong>{{ number_format($claim->financeDetail->fin_final_amount, 2) }}</strong></td>
</tr>
@if($claim->financeDetail->fin_amendment_remark)
<tr>
<td class="label">Catatan Pindaan</td>
<td colspan="3">{{ $claim->financeDetail->fin_amendment_remark }}</td>
</tr>
@endif
</table>
@endif
{{-- 4. Lampiran --}}
@if($claim->attachments->count() > 0)
<h2>4. Lampiran / Bukti Transaksi</h2>
<table>
<thead>
<tr><th>No</th><th>Nama Fail</th></tr>
</thead>
<tbody>
@foreach($claim->attachments as $index => $file)
<tr>
<td class="center">{{ $index + 1 }}</td>
<td>{{ $file->file_name }}</td>
</tr>
@endforeach
</tbody>
</table>
@endif
{{-- 5. Sejarah Kuiri --}}
@if($claim->auditQueries->count() > 0)
<h2>5. Sejarah Kuiri</h2>
<table>
<thead>
<tr>
<th>Bil</th>
<th>Dikuiri Oleh</th>
<th>Catatan</th>
<th>Respons Pemohon</th>
<th>Tarikh</th>
</tr>
</thead>
<tbody>
@foreach($claim->auditQueries as $index => $q)
<tr>
<td class="center">{{ $index + 1 }}</td>
<td class="center">{{ $q->kuiri_by ?? '-' }}</td>
<td>{{ $q->comment ?? '-' }}</td>
<td>{{ $q->response ?? 'Belum Dijawab' }}</td>
<td class="center">{{ \Carbon\Carbon::parse($q->created_at)->format('d/m/Y H:i') }}</td>
</tr>
@endforeach
</tbody>
</table>
@endif
<div class="footer">
Dokumen ini dijana secara automatik oleh sistem pada {{ \Carbon\Carbon::now()->format('d/m/Y H:i') }}.
</div>
</body>
</html>
...@@ -85,11 +85,8 @@ function () { ...@@ -85,11 +85,8 @@ function () {
// HR // HR
Route::prefix('HR')->name('HR')->group(function () { Route::prefix('HR')->name('HR')->group(function () {
Route::get('/dashboard', [HRController::class, 'index'])->name('.index'); Route::get('/', [HRController::class, 'index'])->name('.index');
Route::get('/show/{userId}', [HRController::class, 'show'])->name('.show'); Route::get('/{id}', [HRController::class, 'show'])->name('.show');
Route::get('/view/claim/{id}', [HRController::class, 'viewEach'])->name('.viewEach');
Route::post('/{id}/reject', [HRController::class, 'reject'])->name('.reject');
Route::get('/export', [HRController::class, 'export'])->name('.export');
}); });
Route::get('index', ['uses' => 'MileageController@index', 'as' => 'mileage.index']); Route::get('index', ['uses' => 'MileageController@index', 'as' => 'mileage.index']);
...@@ -121,6 +118,9 @@ function () { ...@@ -121,6 +118,9 @@ function () {
Route::put('department/{id}', [DepartmentController::class, 'update'])->name('department.update'); Route::put('department/{id}', [DepartmentController::class, 'update'])->name('department.update');
Route::delete('department/{id}', [DepartmentController::class, 'destroy'])->name('department.destroy'); Route::delete('department/{id}', [DepartmentController::class, 'destroy'])->name('department.destroy');
} }
Route::get('claim/{id}/pdf', ['uses' => 'MileageController@downloadPdf', 'as' => 'mileage.claim.downloadPdf']);
}
); );
// Guest group (currently unused) // Guest group (currently unused)
......
...@@ -2,128 +2,57 @@ ...@@ -2,128 +2,57 @@
namespace Portal\Mileage\Http\Controllers; namespace Portal\Mileage\Http\Controllers;
use Portal\Mileage\Model\Users; use Portal\Mileage\Model\MileageClaimMain;
use Portal\Mileage\Model\Project;
use Portal\Mileage\Model\JenisKenderaan;
use Portal\Mileage\Model\Claim;
use Portal\Mileage\Model\ProjectTeam;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Carbon\Carbon; use Carbon\Carbon;
use Illuminate\Support\Facades\Auth;
use Maatwebsite\Excel\Facades\Excel;
use Portal\Mileage\Exports\ClaimsExport;
use DB;
class HRController extends Controller class HRController extends Controller
{ {
public function index(Request $request) public function index(Request $request)
{ {
$month = $request->input('month', Carbon::now()->format('Y-m')); $search = $request->get('search');
$parsedMonth = Carbon::parse($month); $tahun = $request->get('tahun');
$bulan = $request->get('bulan');
// Group claims by staff for the selected month $status = $request->get('status');
$claims = Claim::with('user')
->whereMonth('claim_date', $parsedMonth->month) $list = MileageClaimMain::with(['lkpStatus', 'staffInfo'])
->whereYear('claim_date', $parsedMonth->year) ->whereIn('status', [11, 12])
->get() ->when($search, function ($q) use ($search) {
->groupBy('user_id'); $q->where(function ($q2) use ($search) {
$q2->where('mm_apply_no', 'like', '%' . $search . '%')
$users = $claims->map(function ($claimsForUser) { ->orWhere('mm_staff_name', 'like', '%' . $search . '%');
$user = $claimsForUser->first()->user;
return [
'id' => $user->id,
'name' => $user->name ?? '-',
'total_claims' => $claimsForUser->count(),
'total_amount' => $claimsForUser->sum('total_claim_amount'),
];
}); });
})
return view('mileage::hr.index', compact('users', 'month')); ->when($tahun, fn($q) => $q->where('mm_claim_year', $tahun))
} ->when($bulan, fn($q) => $q->where('mm_claim_month', $bulan))
->when($status, fn($q) => $q->where('status', $status))
/** ->orderBy('created_at', 'desc')
* Show individual claim details ->paginate(15);
*/
public function show($userId, Request $request) return view('mileage::HR.index', compact('list'));
{
$month = $request->input('month', Carbon::now()->format('Y-m'));
$parsedMonth = Carbon::parse($month);
$user = Users::findOrFail($userId);
$claims = Claim::where('user_id', $userId)
->whereMonth('claim_date', $parsedMonth->month)
->whereYear('claim_date', $parsedMonth->year)
->orderBy('claim_date', 'asc')
->get();
return view('mileage::hr.show', compact('user', 'claims', 'month'));
}
/**
* Show a single claim (HR detailed view)
*/
public function viewEach($id)
{
$claim = Claim::with(['user', 'project', 'jenisKenderaan'])->findOrFail($id);
return view('mileage::HR.view', compact('claim'));
} }
public function show($id)
/**
* Reject claim (HR decision)
*/
public function reject($id)
{ {
$hr = Auth::user(); $claim = MileageClaimMain::with([
$claim = Claim::findOrFail($id); 'details.jenisKenderaan.rates',
'details.project',
$claim->status = 'Ditolak'; 'details.pmReviews',
$claim->rejected_by = $hr->id; // record who rejected it 'lkpStatus',
$claim->save(); 'staffInfo',
'auditQueries',
return back()->with('error', 'Tuntutan telah ditolak oleh HR.'); 'attachments',
'faCategory',
'financeDetail',
'verifiedBy',
'approvedBy',
])->findOrFail($id);
if (!in_array($claim->status, [11, 12])) {
abort(403, 'Permohonan ini tidak tersedia untuk semakan HR.');
} }
/** return view('mileage::HR.show', compact('claim'));
* Export all claims to Excel
*/
public function export(Request $request)
{
$userId = $request->input('user_id');
$month = $request->input('month');
// parse month safely
$parsedMonth = $month ? Carbon::parse($month) : null;
// fetch user
$user = $userId ? Users::find($userId) : null;
// query claims by filter
$claims = Claim::with(['user', 'project'])
->when($userId, fn($q) => $q->where('user_id', $userId))
->when($parsedMonth, fn($q) =>
$q->whereMonth('claim_date', $parsedMonth->month)
->whereYear('claim_date', $parsedMonth->year)
)
->orderBy('claim_date', 'asc')
->get();
// if no data found, return with warning
if ($claims->isEmpty()) {
return back()->with('error', 'Tiada tuntutan dijumpai untuk penapis yang dipilih.');
}
// build filename dynamically
$staffName = $user ? str_replace(' ', '_', strtoupper($user->name)) : 'SEMUA_STAF';
$monthName = $parsedMonth ? $parsedMonth->format('m-Y') : Carbon::now()->format('m-Y');
$fileName = "Tuntutan_{$staffName}_{$monthName}.xlsx";
// generate Excel using filtered data
return Excel::download(new ClaimsExport($user, $claims), $fileName);
} }
} }
...@@ -4,10 +4,12 @@ ...@@ -4,10 +4,12 @@
use Illuminate\Routing\Controller; use Illuminate\Routing\Controller;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\Input; use Illuminate\Support\Facades\Input;
use Carbon\Carbon; use Carbon\Carbon;
use Auth;
use DB; use DB;
use Event; use Event;
use File; use File;
...@@ -175,5 +177,39 @@ public function deleteClaim(Request $request, $id) ...@@ -175,5 +177,39 @@ public function deleteClaim(Request $request, $id)
return redirect()->route('mileage::mileage.listmileage')->with('success', 'Draf permohonan berjaya dipadam.'); return redirect()->route('mileage::mileage.listmileage')->with('success', 'Draf permohonan berjaya dipadam.');
} }
public function downloadPdf(Request $request, $id)
{
$claim = \Portal\Mileage\Model\MileageClaimMain::with([
'details.jenisKenderaan.rates',
'details.project',
'details.pmReviews',
'lkpStatus',
'staffInfo',
'auditQueries',
'attachments',
'faCategory',
'financeDetail',
])->findOrFail($id);
if (!in_array($claim->status, [11, 12])) {
abort(403, 'PDF tidak tersedia untuk status ini.');
}
$staff = \Portal\Mileage\Model\StaffInfo::where('fk_users', Auth::id())->first();
$isOwner = $staff && $claim->fk_lkp_staff_info == $staff->id;
$isHR = Gate::allows(\App\Enums\Permission::HR);
if (!$isOwner && !$isHR) {
abort(403, 'Anda tidak mempunyai akses untuk memuat turun dokumen ini.');
}
$html = view('mileage::mileage.pdf', compact('claim'))->render();
$pdf = \Barryvdh\DomPDF\Facade\Pdf::loadHTML($html)->setPaper('A4', 'portrait');
return $pdf->download('Tuntutan_Mileage_' . $claim->mm_apply_no . '.pdf');
}
} }
...@@ -122,10 +122,10 @@ protected function menu() ...@@ -122,10 +122,10 @@ protected function menu()
->data('permission', Permission::BOD); ->data('permission', Permission::BOD);
// $menu->add(__('HR Dashboard'), route('mileage::HR.index')) $menu->add(__('HR Dashboard'), route('mileage::HR.index'))
// ->data('icon', 'id badge') ->data('icon', 'id badge')
// ->active('HR/*') ->active('HR/*')
// ->data('permission', Permission::HR); ->data('permission', Permission::HR);
$menu->add(__('Finance Dashboard'), route('mileage::finance.index')) $menu->add(__('Finance Dashboard'), route('mileage::finance.index'))
->data('icon', 'calculator') ->data('icon', 'calculator')
......
...@@ -43,6 +43,12 @@ ...@@ -43,6 +43,12 @@
</div> </div>
<div class="actions"> <div class="actions">
<button class="ui teal button" type="button" id="btn-vm-download" disabled>
<i class="download icon"></i> Download
</button>
<button class="ui blue button" type="button" id="btn-vm-print" disabled>
<i class="print icon"></i> Print
</button>
<button class="ui grey button" onclick="$('#modalViewTuntutan').modal('hide');"> <button class="ui grey button" onclick="$('#modalViewTuntutan').modal('hide');">
<i class="times icon"></i> Close <i class="times icon"></i> Close
</button> </button>
...@@ -56,6 +62,7 @@ ...@@ -56,6 +62,7 @@
'January','February','March','April','May','June', 'January','February','March','April','May','June',
'July','August','September','October','November','December' 'July','August','September','October','November','December'
]; ];
var VCM_CLAIM_TITLE = 'Overtime Claim Form';
function vcmPad(n) { return String(n).padStart(2, '0'); } function vcmPad(n) { return String(n).padStart(2, '0'); }
function vcmEsc(s) { function vcmEsc(s) {
...@@ -71,7 +78,8 @@ function vcmFmtDate(str) { ...@@ -71,7 +78,8 @@ function vcmFmtDate(str) {
} }
function viewTuntutan(id) { function viewTuntutan(id) {
$('#vm-claim-content').html( $('#btn-vm-download, #btn-vm-print').prop('disabled', true);
$('#vm-claim-content').removeAttr('data-claim-id data-claim-number').html(
'<div class="vm-loading"><i class="spinner loading icon"></i> Loading data…</div>' '<div class="vm-loading"><i class="spinner loading icon"></i> Loading data…</div>'
); );
$('#modalViewTuntutan').modal({ blurring: true, closable: true }).modal('show'); $('#modalViewTuntutan').modal({ blurring: true, closable: true }).modal('show');
...@@ -81,7 +89,12 @@ function viewTuntutan(id) { ...@@ -81,7 +89,12 @@ function viewTuntutan(id) {
method : 'GET', method : 'GET',
success: function (res) { success: function (res) {
if (res.success) { if (res.success) {
$('#vm-claim-content').html(vcmBuildHtml(res.data.main, res.data.details)); $('#vm-claim-content')
.attr('data-claim-id', res.data.main.id)
.attr('data-claim-number', res.data.main.ocm_apply_no)
.html(vcmBuildHtml(res.data.main, res.data.details));
var canExport = Number(res.data.main.ocm_status) === 11;
$('#btn-vm-download, #btn-vm-print').prop('disabled', !canExport);
} else { } else {
$('#vm-claim-content').html( $('#vm-claim-content').html(
'<div class="ui negative message"><p>' '<div class="ui negative message"><p>'
...@@ -98,6 +111,29 @@ function viewTuntutan(id) { ...@@ -98,6 +111,29 @@ function viewTuntutan(id) {
}); });
} }
function vcmDownload() {
var id = $('#vm-claim-content').data('claim-id');
if (!id) return;
window.location.href = "{{ url('overtime/claim') }}/" + id + "/pdf";
}
function vcmPrint() {
var id = $('#vm-claim-content').data('claim-id');
var claimNumber = $('#vm-claim-content').data('claim-number');
if (!id || !claimNumber) return;
var printWindow = window.open(
"{{ url('overtime/claim') }}/" + id + "/pdf/" + encodeURIComponent(claimNumber) + "?inline=1",
'_blank'
);
if (!printWindow) {
alert('Unable to open the print window. Please allow pop-ups and try again.');
return;
}
}
$(document).on('click', '#btn-vm-download', vcmDownload);
$(document).on('click', '#btn-vm-print', vcmPrint);
function vcmBuildHtml(main, details) { function vcmBuildHtml(main, details) {
var badge = '<span class="ui label" style="font-size:.78rem;">' + vcmEsc(main.ocm_status_label || '-') + '</span>'; var badge = '<span class="ui label" style="font-size:.78rem;">' + vcmEsc(main.ocm_status_label || '-') + '</span>';
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
? ($monthNames[(int) $main['ocm_month'] - 1] ?? '-') . ' ' . $main['ocm_year'] ? ($monthNames[(int) $main['ocm_month'] - 1] ?? '-') . ' ' . $main['ocm_year']
: '-'; : '-';
$badge = '<span class="ui label" style="font-size:.78rem;">' . $escape($main['ocm_status_label'] ?? '-') . '</span>'; $badge = '<span class="ui label vm-status-badge">' . $escape($main['ocm_status_label'] ?? '-') . '</span>';
$grandTotalTotal = 0; $grandTotalTotal = 0;
$grandTotalEffective = 0; $grandTotalEffective = 0;
?> ?>
...@@ -95,12 +95,12 @@ ...@@ -95,12 +95,12 @@
<td> <td>
@php $isNoProject = (!empty($detail['project_id']) && $detail['project_id'] == 110) || (!empty($detail['fk_lkp_project']) && $detail['fk_lkp_project'] == 110); @endphp @php $isNoProject = (!empty($detail['project_id']) && $detail['project_id'] == 110) || (!empty($detail['fk_lkp_project']) && $detail['fk_lkp_project'] == 110); @endphp
@if($isNoProject) @if($isNoProject)
<span class="ui tiny blue label">Auto</span> <span class="ui tiny blue label vm-review-badge">Auto</span>
@else @else
@if (!empty($detail['ocd_pm_reviewed'])) @if (!empty($detail['ocd_pm_reviewed']))
<span class="ui green label">Reviewed</span> <span class="ui green label vm-review-badge">Reviewed</span>
@else @else
<span class="ui orange label">Pending</span> <span class="ui orange label vm-review-badge">Pending</span>
@endif @endif
@endif @endif
</td> </td>
......
...@@ -21,6 +21,7 @@ function () { ...@@ -21,6 +21,7 @@ function () {
Route::post('claim/store', ['uses' => 'OvertimeClaimController@storeOvertimeClaim', 'as' => 'overtime.storeovertimeclaim']); Route::post('claim/store', ['uses' => 'OvertimeClaimController@storeOvertimeClaim', 'as' => 'overtime.storeovertimeclaim']);
Route::get('claim/existing-months', ['uses' => 'OvertimeClaimController@getExistingMonths', 'as' => 'overtime.existingmonths']); Route::get('claim/existing-months', ['uses' => 'OvertimeClaimController@getExistingMonths', 'as' => 'overtime.existingmonths']);
Route::get('claim/{id}/view', ['uses' => 'OvertimeClaimController@viewOvertimeClaim', 'as' => 'overtime.viewovertimeclaim']); Route::get('claim/{id}/view', ['uses' => 'OvertimeClaimController@viewOvertimeClaim', 'as' => 'overtime.viewovertimeclaim']);
Route::get('claim/{id}/pdf/{filename?}', ['uses' => 'OvertimeClaimController@downloadOvertimeClaim', 'as' => 'overtime.downloadovertimeclaim']);
Route::get('claim/{id}/edit', ['uses' => 'OvertimeClaimController@editOvertimeClaim', 'as' => 'overtime.editovertimeclaim']); Route::get('claim/{id}/edit', ['uses' => 'OvertimeClaimController@editOvertimeClaim', 'as' => 'overtime.editovertimeclaim']);
Route::post('claim/{id}/detail/add', ['uses' => 'OvertimeClaimController@addOvertimeClaimDetail', 'as' => 'overtime.addovertimeclaim']); Route::post('claim/{id}/detail/add', ['uses' => 'OvertimeClaimController@addOvertimeClaimDetail', 'as' => 'overtime.addovertimeclaim']);
Route::post('claim/detail/{id}/update', ['uses' => 'OvertimeClaimController@updateOvertimeClaimDetail', 'as' => 'overtime.updateovertimeclaimdetail']); Route::post('claim/detail/{id}/update', ['uses' => 'OvertimeClaimController@updateOvertimeClaimDetail', 'as' => 'overtime.updateovertimeclaimdetail']);
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Illuminate\Validation\ValidationException; use Illuminate\Validation\ValidationException;
use Barryvdh\DomPDF\Facade\Pdf;
use Portal\Overtime\Data\Repo\OvertimeClaimRepo; use Portal\Overtime\Data\Repo\OvertimeClaimRepo;
use Portal\Overtime\Model\OvertimeClaimMain; use Portal\Overtime\Model\OvertimeClaimMain;
...@@ -200,6 +201,102 @@ public function viewOvertimeClaim(Request $request, int $id): JsonResponse ...@@ -200,6 +201,102 @@ public function viewOvertimeClaim(Request $request, int $id): JsonResponse
]); ]);
} }
public function downloadOvertimeClaim(Request $request, int $id, ?string $filename = null)
{
$main = $this->repos->findOvertimeClaim($id);
$staffInfoId = DB::table('staff_info')->where('fk_users', Auth::id())->value('id');
abort_unless((int) $main->fk_lkp_staff_info === (int) $staffInfoId, 403);
abort_unless((int) $main->ocm_status === 11, 404);
$details = $this->repos->findOvertimeClaimDetails($id);
$projectNames = DB::table('lkp_project')
->whereIn('id', $details->pluck('fk_lkp_project')->filter()->unique())
->pluck('p_project_description', 'id');
$statusLabel = DB::table('lkp_status')
->where('module', 'ot')
->where('ref_id', $main->ocm_status)
->value('description');
$staffInfo = DB::table('staff_info')->where('id', $main->fk_lkp_staff_info)->first();
$departmentId = $staffInfo->fk_lkp_department ?? $main->ocm_division;
$mainData = [
'ocm_apply_no' => $main->ocm_apply_no,
'ocm_staff_name' => $main->ocm_staff_name,
'ocm_division_label' => $departmentId
? (DB::table('lkp_department')->where('id', $departmentId)->value('description')
?: DB::table('lkp_department')->where('id', $departmentId)->value('name') ?: '-')
: '-',
'ocm_status_label' => $statusLabel ?: '-',
'ocm_month' => $main->ocm_month,
'ocm_year' => $main->ocm_year,
'ocm_submit_date' => $main->ocm_submit_date,
'ocm_approved_by_name' => $main->ocm_approved_by
? (DB::table('staff_info')->where('fk_users', $main->ocm_approved_by)->value('fullname')
?: DB::table('users')->where('id', $main->ocm_approved_by)->value('name') ?: '-')
: '-',
'ocm_approved_date' => $main->ocm_approved_date,
];
$detailData = $details->map(fn ($detail) => [
'ocd_date' => $detail->ocd_date,
'ocd_day_type' => $detail->ocd_day_type,
'ocd_office_hour' => $detail->ocd_office_hour,
'ocd_overtime_from' => $detail->ocd_overtime_from,
'ocd_overtime_to' => $detail->ocd_overtime_to,
'ocd_total_hours' => $detail->ocd_total_hours,
'ocd_effective_hours' => $detail->ocd_effective_hours,
'ocd_tasks' => $detail->ocd_tasks,
'fk_lkp_project' => $detail->fk_lkp_project,
'project_name' => $projectNames[$detail->fk_lkp_project] ?? '',
'ocd_pm_reviewed' => $detail->ocd_pm_reviewed,
])->all();
$claimContent = view('overtime::overtime.overtimeclaim.view_modal_content', [
'main' => $mainData,
'details' => $detailData,
])->render();
$pdfStyles = <<<'CSS'
@page { size: A4 landscape; margin: 10mm; }
body { font-family: DejaVu Sans, sans-serif; color: #222; margin: 0; font-size: 9px; }
.vm-summary { background: #ddeeff; border-radius: 6px; padding: 8px 11px; margin-bottom: 10px; line-height: 1.75; }
.vm-summary .apply-no { font-size: 12px; font-weight: 700; color: #1a56a0; }
.vm-summary .meta-line { font-size: 9px; color: #333; }
.vm-tbl { width: 100%; border-collapse: collapse; table-layout: fixed; font-size: 8px; }
.vm-tbl th, .vm-tbl td { border: 1px solid #cfd8e3; padding: 5px 4px; min-width: 0 !important; vertical-align: middle; text-align: center; word-wrap: break-word; }
.vm-tbl thead tr.grp th { background: #2185d0; color: #fff; font-weight: 600; }
.vm-tbl thead tr.grp th.vm-light { background: #5aace8; }
.vm-tbl thead tr.grp th.vm-plain { background: #e8f0fa; color: #444; }
.vm-tbl tbody td.vm-shade { background: #f0f7ff; }
.vm-tbl tbody td.vm-left { text-align: left; }
.vm-tbl tfoot td { background: #ddeeff; font-weight: 700; color: #1a56a0; border-top: 2px solid #2185d0; }
.vm-tbl tfoot .lbl { text-align: right; font-size: 8px; }
.vm-empty { text-align: center; color: #bbb; font-style: italic; padding: 16px; }
.ui.label { display: inline-block; padding: 3px 6px; border-radius: 3px; background: #e8e8e8; font-size: 8px; }
.vm-status-badge, .vm-review-badge { vertical-align: middle; line-height: 1.2; white-space: nowrap; }
.vm-status-badge { margin-left: 2px; }
.ui.tiny.label, .ui.blue.label { background: #2185d0; color: #fff; }
.ui.green.label { background: #21ba45; color: #fff; }
.ui.orange.label { background: #f2711c; color: #fff; }
CSS;
$pdf = Pdf::loadHTML('<!doctype html><html><head><meta charset="utf-8"><style>'
. $pdfStyles . '</style></head><body>' . $claimContent . '</body></html>')
->setPaper('a4', 'landscape');
$filename = $main->ocm_apply_no . '.pdf';
if ($request->boolean('inline')) {
return response($pdf->output(), 200, [
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'inline; filename="' . $filename . '"',
]);
}
return response($pdf->output(), 200, [
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'attachment; filename="' . $filename . '"',
]);
}
// EDIT // EDIT
......
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