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>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 @@
<a href="{{ route('mileage::mileage.listmileage') }}" class="ui right floated button">
<i class="arrow left icon"></i> Kembali ke Senarai
</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
<br>
<br>
......
......@@ -85,11 +85,8 @@ function () {
// HR
Route::prefix('HR')->name('HR')->group(function () {
Route::get('/dashboard', [HRController::class, 'index'])->name('.index');
Route::get('/show/{userId}', [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('/', [HRController::class, 'index'])->name('.index');
Route::get('/{id}', [HRController::class, 'show'])->name('.show');
});
Route::get('index', ['uses' => 'MileageController@index', 'as' => 'mileage.index']);
......@@ -121,6 +118,9 @@ function () {
Route::put('department/{id}', [DepartmentController::class, 'update'])->name('department.update');
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)
......
......@@ -2,128 +2,57 @@
namespace Portal\Mileage\Http\Controllers;
use Portal\Mileage\Model\Users;
use Portal\Mileage\Model\Project;
use Portal\Mileage\Model\JenisKenderaan;
use Portal\Mileage\Model\Claim;
use Portal\Mileage\Model\ProjectTeam;
use Portal\Mileage\Model\MileageClaimMain;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Carbon\Carbon;
use Illuminate\Support\Facades\Auth;
use Maatwebsite\Excel\Facades\Excel;
use Portal\Mileage\Exports\ClaimsExport;
use DB;
class HRController extends Controller
{
public function index(Request $request)
{
$month = $request->input('month', Carbon::now()->format('Y-m'));
$parsedMonth = Carbon::parse($month);
// Group claims by staff for the selected month
$claims = Claim::with('user')
->whereMonth('claim_date', $parsedMonth->month)
->whereYear('claim_date', $parsedMonth->year)
->get()
->groupBy('user_id');
$users = $claims->map(function ($claimsForUser) {
$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'));
}
/**
* Show individual claim details
*/
public function show($userId, Request $request)
{
$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'));
$search = $request->get('search');
$tahun = $request->get('tahun');
$bulan = $request->get('bulan');
$status = $request->get('status');
$list = MileageClaimMain::with(['lkpStatus', 'staffInfo'])
->whereIn('status', [11, 12])
->when($search, function ($q) use ($search) {
$q->where(function ($q2) use ($search) {
$q2->where('mm_apply_no', 'like', '%' . $search . '%')
->orWhere('mm_staff_name', 'like', '%' . $search . '%');
});
})
->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')
->paginate(15);
return view('mileage::HR.index', compact('list'));
}
/**
* Reject claim (HR decision)
*/
public function reject($id)
public function show($id)
{
$hr = Auth::user();
$claim = Claim::findOrFail($id);
$claim->status = 'Ditolak';
$claim->rejected_by = $hr->id; // record who rejected it
$claim->save();
return back()->with('error', 'Tuntutan telah ditolak oleh HR.');
}
/**
* 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.');
$claim = MileageClaimMain::with([
'details.jenisKenderaan.rates',
'details.project',
'details.pmReviews',
'lkpStatus',
'staffInfo',
'auditQueries',
'attachments',
'faCategory',
'financeDetail',
'verifiedBy',
'approvedBy',
])->findOrFail($id);
if (!in_array($claim->status, [11, 12])) {
abort(403, 'Permohonan ini tidak tersedia untuk semakan HR.');
}
// 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);
return view('mileage::HR.show', compact('claim'));
}
}
......@@ -4,10 +4,12 @@
use Illuminate\Routing\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\Input;
use Carbon\Carbon;
use Auth;
use DB;
use Event;
use File;
......@@ -175,5 +177,39 @@ public function deleteClaim(Request $request, $id)
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()
->data('permission', Permission::BOD);
// $menu->add(__('HR Dashboard'), route('mileage::HR.index'))
// ->data('icon', 'id badge')
// ->active('HR/*')
// ->data('permission', Permission::HR);
$menu->add(__('HR Dashboard'), route('mileage::HR.index'))
->data('icon', 'id badge')
->active('HR/*')
->data('permission', Permission::HR);
$menu->add(__('Finance Dashboard'), route('mileage::finance.index'))
->data('icon', 'calculator')
......
......@@ -43,6 +43,12 @@
</div>
<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');">
<i class="times icon"></i> Close
</button>
......@@ -56,6 +62,7 @@
'January','February','March','April','May','June',
'July','August','September','October','November','December'
];
var VCM_CLAIM_TITLE = 'Overtime Claim Form';
function vcmPad(n) { return String(n).padStart(2, '0'); }
function vcmEsc(s) {
......@@ -71,7 +78,8 @@ function vcmFmtDate(str) {
}
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>'
);
$('#modalViewTuntutan').modal({ blurring: true, closable: true }).modal('show');
......@@ -81,7 +89,12 @@ function viewTuntutan(id) {
method : 'GET',
success: function (res) {
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 {
$('#vm-claim-content').html(
'<div class="ui negative message"><p>'
......@@ -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) {
var badge = '<span class="ui label" style="font-size:.78rem;">' + vcmEsc(main.ocm_status_label || '-') + '</span>';
......
......@@ -31,7 +31,7 @@
? ($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;
$grandTotalEffective = 0;
?>
......@@ -95,12 +95,12 @@
<td>
@php $isNoProject = (!empty($detail['project_id']) && $detail['project_id'] == 110) || (!empty($detail['fk_lkp_project']) && $detail['fk_lkp_project'] == 110); @endphp
@if($isNoProject)
<span class="ui tiny blue label">Auto</span>
<span class="ui tiny blue label vm-review-badge">Auto</span>
@else
@if (!empty($detail['ocd_pm_reviewed']))
<span class="ui green label">Reviewed</span>
<span class="ui green label vm-review-badge">Reviewed</span>
@else
<span class="ui orange label">Pending</span>
<span class="ui orange label vm-review-badge">Pending</span>
@endif
@endif
</td>
......
......@@ -21,6 +21,7 @@ function () {
Route::post('claim/store', ['uses' => 'OvertimeClaimController@storeOvertimeClaim', 'as' => 'overtime.storeovertimeclaim']);
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}/pdf/{filename?}', ['uses' => 'OvertimeClaimController@downloadOvertimeClaim', 'as' => 'overtime.downloadovertimeclaim']);
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/detail/{id}/update', ['uses' => 'OvertimeClaimController@updateOvertimeClaimDetail', 'as' => 'overtime.updateovertimeclaimdetail']);
......
......@@ -8,6 +8,7 @@
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Illuminate\Validation\ValidationException;
use Barryvdh\DomPDF\Facade\Pdf;
use Portal\Overtime\Data\Repo\OvertimeClaimRepo;
use Portal\Overtime\Model\OvertimeClaimMain;
......@@ -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
......
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