added pm flow, show project that belong to the user

parent 49fda619
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('mileage_claim_pm_review', function (Blueprint $table) {
$table->id();
$table->integer('fk_claim_id')->index();
$table->integer('fk_detail_id')->index();
$table->string('pm_employee_code', 50)->index();
$table->enum('status', ['pending', 'reviewed', 'queried'])->default('pending');
$table->text('note')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('mileage_claim_pm_review');
}
};
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
DB::table('lkp_mileage_task')->insert([
['description' => 'PM Semak Permohonan', 'status' => 1, 'created_at' => now(), 'updated_at' => now()],
['description' => 'PM Kuiri Permohonan', 'status' => 1, 'created_at' => now(), 'updated_at' => now()],
]);
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
DB::table('lkp_mileage_task')->whereIn('description', ['PM Semak Permohonan', 'PM Kuiri Permohonan'])->delete();
}
};
...@@ -84,11 +84,12 @@ ...@@ -84,11 +84,12 @@
<i class="info circle icon" style="cursor:pointer; color:#2185d0;" <i class="info circle icon" style="cursor:pointer; color:#2185d0;"
onclick="$('#modalAnggaran').modal('show');"></i> onclick="$('#modalAnggaran').modal('show');"></i>
</th> </th>
<th class="center aligned">Status</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@php @php
$grandAnggaran = 0; $grandTol = 0; $grandParking = 0; $grandAnggaran = 0; $grandTol = 0; $grandParking = 0; $grandJarak = 0; $deductionCount = 0;
$sortedDetails = $claim->details->sortBy('md_claim_date')->values(); $sortedDetails = $claim->details->sortBy('md_claim_date')->values();
$dateCounts = []; $dateCounts = [];
foreach ($sortedDetails as $d) { foreach ($sortedDetails as $d) {
...@@ -105,7 +106,12 @@ ...@@ -105,7 +106,12 @@
$dateKey = $detail->md_claim_date; $dateKey = $detail->md_claim_date;
$isFirstOfDate = !isset($dateFirstSeen[$dateKey]); $isFirstOfDate = !isset($dateFirstSeen[$dateKey]);
if ($isFirstOfDate) $dateFirstSeen[$dateKey] = true; if ($isFirstOfDate) $dateFirstSeen[$dateKey] = true;
$claimableKm = $isFirstOfDate ? max(0, $jumlahJarak - 40) : $jumlahJarak; if ($isFirstOfDate && $deductionCount < 10) {
$claimableKm = max(0, $jumlahJarak - 40);
$deductionCount++;
} else {
$claimableKm = $jumlahJarak;
}
$startKm = $cumulativeKmByDate[$dateKey] ?? 0; $startKm = $cumulativeKmByDate[$dateKey] ?? 0;
$endKm = $startKm + $claimableKm; $endKm = $startKm + $claimableKm;
$mileageAmount = 0; $mileageAmount = 0;
...@@ -118,6 +124,7 @@ ...@@ -118,6 +124,7 @@
$jumlahParking = (float) $detail->md_total_parking_fee; $jumlahParking = (float) $detail->md_total_parking_fee;
$jumlahBelanja = $jumlahTol + $jumlahParking; $jumlahBelanja = $jumlahTol + $jumlahParking;
$anggaranTuntutan = $mileageAmount + $jumlahBelanja; $anggaranTuntutan = $mileageAmount + $jumlahBelanja;
$grandJarak += $jumlahJarak;
$grandTol += $jumlahTol; $grandTol += $jumlahTol;
$grandParking += $jumlahParking; $grandParking += $jumlahParking;
$grandAnggaran += $anggaranTuntutan; $grandAnggaran += $anggaranTuntutan;
...@@ -134,20 +141,38 @@ ...@@ -134,20 +141,38 @@
<td class="right aligned">{{ number_format($jumlahTol, 2) }}</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($jumlahParking, 2) }}</td>
<td class="right aligned">{{ number_format($anggaranTuntutan, 2) }}</td> <td class="right aligned">{{ number_format($anggaranTuntutan, 2) }}</td>
@php
$totalReviews = $detail->pmReviews->count();
$reviewedCount = $detail->pmReviews->where('status', 'reviewed')->count();
$queriedCount = $detail->pmReviews->where('status', 'queried')->count();
@endphp
<td class="center aligned">
@if($totalReviews === 0)
<span class="ui grey label">-</span>
@elseif($queriedCount > 0)
<span class="ui yellow label">Dikuiri</span>
@elseif($reviewedCount === $totalReviews)
<span class="ui green label">Disemak</span>
@else
<span class="ui orange label">{{ $reviewedCount }}/{{ $totalReviews }} Disemak</span>
@endif
</td>
</tr> </tr>
@empty @empty
<tr> <tr>
<td colspan="9" class="center aligned">Tiada butiran.</td> <td colspan="10" class="center aligned">Tiada butiran.</td>
</tr> </tr>
@endforelse @endforelse
</tbody> </tbody>
@if($claim->details->count() > 0) @if($claim->details->count() > 0)
<tfoot> <tfoot>
<tr> <tr>
<th colspan="6" class="right aligned">JUMLAH KESELURUHAN (RM)</th> <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($grandTol, 2) }}</th>
<th class="right aligned">{{ number_format($grandParking, 2) }}</th> <th class="right aligned">{{ number_format($grandParking, 2) }}</th>
<th class="right aligned">{{ number_format($grandAnggaran, 2) }}</th> <th class="right aligned">{{ number_format($grandAnggaran, 2) }}</th>
<th></th>
</tr> </tr>
</tfoot> </tfoot>
@endif @endif
...@@ -220,7 +245,9 @@ ...@@ -220,7 +245,9 @@
<tr> <tr>
<td>{{ $index + 1 }}</td> <td>{{ $index + 1 }}</td>
<td> <td>
@if($q->kuiri_by == 'HOD') @if($q->kuiri_by === 'PM')
<span class="ui olive label">PM</span>
@elseif($q->kuiri_by == 'HOD')
<span class="ui teal label">HOD</span> <span class="ui teal label">HOD</span>
@elseif($q->kuiri_by == 'BOD') @elseif($q->kuiri_by == 'BOD')
<span class="ui violet label">BOD</span> <span class="ui violet label">BOD</span>
......
...@@ -80,11 +80,13 @@ ...@@ -80,11 +80,13 @@
<i class="info circle icon" style="cursor:pointer; color:#2185d0;" <i class="info circle icon" style="cursor:pointer; color:#2185d0;"
onclick="$('#modalAnggaran').modal('show');"></i> onclick="$('#modalAnggaran').modal('show');"></i>
</th> </th>
<th class="center aligned">Status</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@php @php
$grandAnggaran = 0; $grandTol = 0; $grandParking = 0; $grandAnggaran = 0; $grandTol = 0; $grandParking = 0; $grandJarak = 0; $deductionCount = 0;
$sortedDetails = $claim->details->sortBy('md_claim_date')->values(); $sortedDetails = $claim->details->sortBy('md_claim_date')->values();
$dateCounts = []; $dateCounts = [];
foreach ($sortedDetails as $d) { foreach ($sortedDetails as $d) {
...@@ -101,7 +103,12 @@ ...@@ -101,7 +103,12 @@
$dateKey = $detail->md_claim_date; $dateKey = $detail->md_claim_date;
$isFirstOfDate = !isset($dateFirstSeen[$dateKey]); $isFirstOfDate = !isset($dateFirstSeen[$dateKey]);
if ($isFirstOfDate) $dateFirstSeen[$dateKey] = true; if ($isFirstOfDate) $dateFirstSeen[$dateKey] = true;
$claimableKm = $isFirstOfDate ? max(0, $jumlahJarak - 40) : $jumlahJarak; if ($isFirstOfDate && $deductionCount < 10) {
$claimableKm = max(0, $jumlahJarak - 40);
$deductionCount++;
} else {
$claimableKm = $jumlahJarak;
}
$startKm = $cumulativeKmByDate[$dateKey] ?? 0; $startKm = $cumulativeKmByDate[$dateKey] ?? 0;
$endKm = $startKm + $claimableKm; $endKm = $startKm + $claimableKm;
$mileageAmount = 0; $mileageAmount = 0;
...@@ -114,6 +121,7 @@ ...@@ -114,6 +121,7 @@
$jumlahParking = (float) $detail->md_total_parking_fee; $jumlahParking = (float) $detail->md_total_parking_fee;
$jumlahBelanja = $jumlahTol + $jumlahParking; $jumlahBelanja = $jumlahTol + $jumlahParking;
$anggaranTuntutan = $mileageAmount + $jumlahBelanja; $anggaranTuntutan = $mileageAmount + $jumlahBelanja;
$grandJarak += $jumlahJarak;
$grandTol += $jumlahTol; $grandTol += $jumlahTol;
$grandParking += $jumlahParking; $grandParking += $jumlahParking;
$grandAnggaran += $anggaranTuntutan; $grandAnggaran += $anggaranTuntutan;
...@@ -130,20 +138,38 @@ ...@@ -130,20 +138,38 @@
<td class="right aligned">{{ number_format($jumlahTol, 2) }}</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($jumlahParking, 2) }}</td>
<td class="right aligned">{{ number_format($anggaranTuntutan, 2) }}</td> <td class="right aligned">{{ number_format($anggaranTuntutan, 2) }}</td>
@php
$totalReviews = $detail->pmReviews->count();
$reviewedCount = $detail->pmReviews->where('status', 'reviewed')->count();
$queriedCount = $detail->pmReviews->where('status', 'queried')->count();
@endphp
<td class="center aligned">
@if($totalReviews === 0)
<span class="ui grey label">-</span>
@elseif($queriedCount > 0)
<span class="ui yellow label"> Dikuiri</span>
@elseif($reviewedCount === $totalReviews)
<span class="ui green label"><i class="check icon"></i> Disemak</span>
@else
<span class="ui orange label">{{ $reviewedCount }}/{{ $totalReviews }} Disemak</span>
@endif
</td>
</tr> </tr>
@empty @empty
<tr> <tr>
<td colspan="9" class="center aligned">Tiada butiran.</td> <td colspan="10" class="center aligned">Tiada butiran.</td>
</tr> </tr>
@endforelse @endforelse
</tbody> </tbody>
@if($claim->details->count() > 0) @if($claim->details->count() > 0)
<tfoot> <tfoot>
<tr> <tr>
<th colspan="6" class="right aligned">JUMLAH KESELURUHAN (RM)</th> <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($grandTol, 2) }}</th>
<th class="right aligned">{{ number_format($grandParking, 2) }}</th> <th class="right aligned">{{ number_format($grandParking, 2) }}</th>
<th class="right aligned">{{ number_format($grandAnggaran, 2) }}</th> <th class="right aligned">{{ number_format($grandAnggaran, 2) }}</th>
<th></th>
</tr> </tr>
</tfoot> </tfoot>
@endif @endif
...@@ -220,7 +246,9 @@ ...@@ -220,7 +246,9 @@
<tr> <tr>
<td>{{ $index + 1 }}</td> <td>{{ $index + 1 }}</td>
<td> <td>
@if($q->kuiri_by == 'HOD') @if($q->kuiri_by === 'PM')
<span class="ui olive label">PM</span>
@elseif($q->kuiri_by == 'HOD')
<span class="ui teal label">HOD</span> <span class="ui teal label">HOD</span>
@elseif($q->kuiri_by == 'BOD') @elseif($q->kuiri_by == 'BOD')
<span class="ui violet label">BOD</span> <span class="ui violet label">BOD</span>
...@@ -245,7 +273,7 @@ ...@@ -245,7 +273,7 @@
@endif @endif
{{-- Action Buttons --}} {{-- Action Buttons --}}
@if(in_array($claim->status, [2, 3])) @if(in_array($claim->status, [5, 8]))
<div class="ui segment"> <div class="ui segment">
<h3 class="ui header">Tindakan HOD</h3> <h3 class="ui header">Tindakan HOD</h3>
<form id="formTindakan" method="POST"> <form id="formTindakan" method="POST">
...@@ -322,7 +350,7 @@ function submitTindakan() { ...@@ -322,7 +350,7 @@ function submitTindakan() {
<a href="{{ route('mileage::HOD.index') }}" class="ui button"> <a href="{{ route('mileage::HOD.index') }}" class="ui button">
<i class="arrow left icon"></i> Kembali <i class="arrow left icon"></i> Kembali
</a> </a>
@if(in_array($claim->status, [2, 3])) @if(in_array($claim->status, [5, 8]))
<button type="button" onclick="submitTindakan()" class="ui violet button"> <button type="button" onclick="submitTindakan()" class="ui violet button">
<i class="send icon"></i> Hantar Tindakan <i class="send icon"></i> Hantar Tindakan
</button> </button>
......
@extends('ui::layouts.app')
@section('content')
<div class="ui segment">
<a class="ui olive left ribbon label">PM Dashboard - Tuntutan Mileage</a><br/>
<div class="ui segment">
@if(session('success'))
<div class="ui success message">{{ session('success') }}</div>
@endif
@if(session('error'))
<div class="ui error message">{{ session('error') }}</div>
@endif
<form method="GET" action="{{ route('mileage::PM.index') }}" class="ui form" style="margin-bottom: 1rem;">
<div class="ui action input">
<input type="text" name="search" value="{{ request('search') }}" placeholder="Cari no. permohonan...">
<button type="submit" class="ui olive button">Cari</button>
@if(request('search'))
<a href="{{ route('mileage::PM.index') }}" class="ui button">Reset</a>
@endif
</div>
</form>
<table class="ui celled table">
<thead>
<tr>
<th>No</th>
<th>No. Permohonan</th>
<th>Nama Pemohon</th>
<th>Bulan</th>
<th>Tarikh Hantar</th>
<th>Status</th>
<th>Tindakan</th>
</tr>
</thead>
<tbody>
@forelse($list as $index => $claim)
@php
$refId = $claim->lkpStatus?->ref_id ?? 0;
$color = match($refId) {
2 => 'blue',
3 => 'yellow',
6 => 'orange',
default => 'grey',
};
$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
<tr>
<td>{{ $list->firstItem() + $index }}</td>
<td>{{ $claim->mm_apply_no }}</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 {{ $color }} label">{{ $claim->lkpStatus?->description ?? '-' }}</span></td>
<td>
<a href="{{ route('mileage::PM.show', $claim->id) }}" class="ui blue small button">
<i class="eye icon"></i>
</a>
</td>
</tr>
@empty
<tr>
<td colspan="7" class="center aligned">Tiada permohonan untuk disemak.</td>
</tr>
@endforelse
</tbody>
</table>
{{ $list->withQueryString()->links() }}
</div>
</div>
@endsection
...@@ -83,12 +83,18 @@ ...@@ -83,12 +83,18 @@
<i class="info circle icon" style="cursor:pointer; color:#2185d0;" <i class="info circle icon" style="cursor:pointer; color:#2185d0;"
onclick="$('#modalAnggaran').modal('show');"></i> onclick="$('#modalAnggaran').modal('show');"></i>
</th> </th>
<th>Tindakan</th> @if($claim->status == 1)
<th>Tindakan</th>
@endif
@if($claim->status != 1)
<th class="center aligned">Status</th>
@endif
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@php @php
$grandAnggaran = 0; $grandTol = 0; $grandParking = 0; $grandAnggaran = 0; $grandTol = 0; $grandParking = 0; $grandJarak = 0; $deductionCount = 0;
$sortedDetails = $claim->details->sortBy('md_claim_date')->values(); $sortedDetails = $claim->details->sortBy('md_claim_date')->values();
$dateCounts = []; $dateCounts = [];
foreach ($sortedDetails as $d) { foreach ($sortedDetails as $d) {
...@@ -105,7 +111,12 @@ ...@@ -105,7 +111,12 @@
$dateKey = $detail->md_claim_date; $dateKey = $detail->md_claim_date;
$isFirstOfDate = !isset($dateFirstSeen[$dateKey]); $isFirstOfDate = !isset($dateFirstSeen[$dateKey]);
if ($isFirstOfDate) $dateFirstSeen[$dateKey] = true; if ($isFirstOfDate) $dateFirstSeen[$dateKey] = true;
$claimableKm = $isFirstOfDate ? max(0, $jumlahJarak - 40) : $jumlahJarak; if ($isFirstOfDate && $deductionCount < 10) {
$claimableKm = max(0, $jumlahJarak - 40);
$deductionCount++;
} else {
$claimableKm = $jumlahJarak;
}
$startKm = $cumulativeKmByDate[$dateKey] ?? 0; $startKm = $cumulativeKmByDate[$dateKey] ?? 0;
$endKm = $startKm + $claimableKm; $endKm = $startKm + $claimableKm;
$mileageAmount = 0; $mileageAmount = 0;
...@@ -118,6 +129,7 @@ ...@@ -118,6 +129,7 @@
$jumlahParking = (float) $detail->md_total_parking_fee; $jumlahParking = (float) $detail->md_total_parking_fee;
$jumlahBelanja = $jumlahTol + $jumlahParking; $jumlahBelanja = $jumlahTol + $jumlahParking;
$anggaranTuntutan = $mileageAmount + $jumlahBelanja; $anggaranTuntutan = $mileageAmount + $jumlahBelanja;
$grandJarak += $jumlahJarak;
$grandTol += $jumlahTol; $grandTol += $jumlahTol;
$grandParking += $jumlahParking; $grandParking += $jumlahParking;
$grandAnggaran += $anggaranTuntutan; $grandAnggaran += $anggaranTuntutan;
...@@ -134,34 +146,48 @@ ...@@ -134,34 +146,48 @@
<td class="right aligned">{{ number_format($jumlahTol, 2) }}</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($jumlahParking, 2) }}</td>
<td class="right aligned">{{ number_format($anggaranTuntutan, 2) }}</td> <td class="right aligned">{{ number_format($anggaranTuntutan, 2) }}</td>
<td> @if($claim->status == 1)
@if($claim->status == 1) <td>
<div class="ui small icon buttons"> <div class="ui small icon buttons">
<button type="button" class="ui blue button btn-edit-detail" <button type="button" class="ui blue button btn-edit-detail"
data-update-url="{{ route('mileage::mileage.claim.detail.update', ['id' => $detail->id]) }}" data-update-url="{{ route('mileage::mileage.claim.detail.update', ['id' => $detail->id]) }}"
data-date="{{ \Carbon\Carbon::parse($detail->md_claim_date)->format('Y-m-d') }}" data-date="{{ \Carbon\Carbon::parse($detail->md_claim_date)->format('Y-m-d') }}"
data-kenderaan="{{ $detail->fk_lkp_jenis_kenderaan }}" data-kenderaan="{{ $detail->fk_lkp_jenis_kenderaan }}"
data-project="{{ $detail->fk_lkp_project }}" data-project="{{ $detail->fk_lkp_project }}"
data-description="{{ $detail->md_description }}" data-description="{{ $detail->md_description }}"
data-from="{{ $detail->md_distance_from }}" data-from="{{ $detail->md_distance_from }}"
data-to="{{ $detail->md_distance_to }}" data-to="{{ $detail->md_distance_to }}"
data-mileage="{{ $detail->md_total_mileage }}" data-mileage="{{ $detail->md_total_mileage }}"
data-toll="{{ $detail->md_total_toll }}" data-toll="{{ $detail->md_total_toll }}"
data-parking="{{ $detail->md_total_parking_fee }}"> data-parking="{{ $detail->md_total_parking_fee }}">
<i class="edit icon"></i> <i class="edit icon"></i>
</button> </button>
<form action="{{ route('mileage::mileage.claim.detail.destroy', ['id' => $detail->id]) }}" method="POST" onsubmit="return confirm('Padam butiran ini?');" style="display:inline;"> <form action="{{ route('mileage::mileage.claim.detail.destroy', ['id' => $detail->id]) }}" method="POST" onsubmit="return confirm('Padam butiran ini?');" style="display:inline;">
@csrf @csrf
@method('DELETE') @method('DELETE')
<button type="submit" class="ui red button"><i class="trash icon"></i></button> <button type="submit" class="ui red button"><i class="trash icon"></i></button>
</form> </form>
</div> </div>
@else </td>
- @endif
@endif @if($claim->status != 1)
</td> @php
$totalReviews = $detail->pmReviews->count();
$reviewedCount = $detail->pmReviews->where('status', 'reviewed')->count();
$queriedCount = $detail->pmReviews->where('status', 'queried')->count();
@endphp
<td class="center aligned">
@if($totalReviews === 0)
<span class="ui grey label">-</span>
@elseif($queriedCount > 0)
<span class="ui yellow label"> Dikuiri</span>
@elseif($reviewedCount === $totalReviews)
<span class="ui green label"></i> Disemak</span>
@else
<span class="ui orange label">{{ $reviewedCount }}/{{ $totalReviews }} Disemak</span>
@endif
</td>
@endif
</tr> </tr>
@empty @empty
...@@ -173,7 +199,8 @@ ...@@ -173,7 +199,8 @@
@if($claim->details->count() > 0) @if($claim->details->count() > 0)
<tfoot> <tfoot>
<tr> <tr>
<th colspan="6" class="right aligned">JUMLAH KESELURUHAN (RM)</th> <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($grandTol, 2) }}</th>
<th class="right aligned">{{ number_format($grandParking, 2) }}</th> <th class="right aligned">{{ number_format($grandParking, 2) }}</th>
<th class="right aligned">{{ number_format($grandAnggaran, 2) }}</th> <th class="right aligned">{{ number_format($grandAnggaran, 2) }}</th>
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Route;
use Portal\Mileage\Http\Controllers\ApplyformController; use Portal\Mileage\Http\Controllers\ApplyformController;
use Portal\Mileage\Http\Controllers\ApplicationsController; use Portal\Mileage\Http\Controllers\ApplicationsController;
use Portal\Mileage\Http\Controllers\ProjectManagerController; use Portal\Mileage\Http\Controllers\PMController;
use Portal\Mileage\Http\Controllers\ProjectDirectorController; use Portal\Mileage\Http\Controllers\ProjectDirectorController;
use Portal\Mileage\Http\Controllers\HODController; use Portal\Mileage\Http\Controllers\HODController;
use Portal\Mileage\Http\Controllers\BODController; use Portal\Mileage\Http\Controllers\BODController;
...@@ -35,14 +35,13 @@ function () { ...@@ -35,14 +35,13 @@ function () {
Route::put('applications/{id}', [ApplicationsController::class, 'update']) Route::put('applications/{id}', [ApplicationsController::class, 'update'])
->name('applications.update'); ->name('applications.update');
// Project Manager /// PM
Route::prefix('projectManager')->name('projectManager')->group(function () { Route::prefix('PM')->name('PM')->group(function () {
Route::get('/', [ProjectManagerController::class, 'index'])->name('.index'); Route::get('/dashboard', [PMController::class, 'index'])->name('.index');
Route::get('/show/{projectId}/{userId}', [ProjectManagerController::class, 'show'])->name('.show'); Route::get('/show/{id}', [PMController::class, 'show'])->name('.show');
Route::post('/approve-month', [ProjectManagerController::class, 'approveMonth'])->name('.approveMonth'); Route::post('/detail/{detailId}/review', [PMController::class, 'reviewDetail'])->name('.reviewDetail');
Route::post('/reject-month', [ProjectManagerController::class, 'rejectMonth'])->name('.rejectMonth'); Route::post('/detail/{detailId}/kuiri', [PMController::class, 'kuiriDetail'])->name('.kuiriDetail');
Route::post('/claim/{id}/approve', [ProjectManagerController::class, 'approveClaim'])->name('.approveClaim'); Route::post('/{id}/submitTindakan', [PMController::class, 'submitTindakan'])->name('.submitTindakan');
Route::post('/claim/{id}/reject', [ProjectManagerController::class, 'rejectClaim'])->name('.rejectClaim');
}); });
// Project Director // Project Director
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
use Portal\Mileage\Model\AuditQuery; use Portal\Mileage\Model\AuditQuery;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
// use App\Models\User;
// use Portal\Mileage\Http\Notifications\MileageMailer;
class BODRepo class BODRepo
{ {
...@@ -31,6 +33,7 @@ public function findClaim($id) ...@@ -31,6 +33,7 @@ public function findClaim($id)
return MileageClaimMain::with([ return MileageClaimMain::with([
'details.jenisKenderaan.rates', 'details.jenisKenderaan.rates',
'details.project', 'details.project',
'details.pmReviews',
'lkpStatus', 'lkpStatus',
'staffInfo', 'staffInfo',
'auditQueries', 'auditQueries',
...@@ -56,6 +59,26 @@ public function luluskanClaim($id) ...@@ -56,6 +59,26 @@ public function luluskanClaim($id)
'remark' => Auth::user()->name . ' Telah Luluskan Permohonan Tuntutan Mileage (mileage_claim_main.id = ' . $id . ')', 'remark' => Auth::user()->name . ' Telah Luluskan Permohonan Tuntutan Mileage (mileage_claim_main.id = ' . $id . ')',
]); ]);
// $claim->load('staffInfo');
// $staff = User::find($claim->staffInfo?->fk_users);
// if ($staff && filter_var($staff->email, FILTER_VALIDATE_EMAIL)) {
// $message = collect([
// 'title' => 'Makluman Tuntutan Mileage Anda Telah Diluluskan',
// 'level' => 'success',
// 'content' => [
// 'Assalamualaikum w.b.t ' . $staff->name . ',',
// 'No. Permohonan: ' . $claim->mm_apply_no,
// 'Tuntutan mileage anda telah diluluskan dan dikemukakan kepada Kewangan untuk semakan.',
// 'Sila log masuk ke sistem untuk maklumat lanjut.',
// ],
// 'footer' => [
// 'Ini adalah mesej automatik dari sistem. Sila jangan balas emel ini.',
// ],
// ]);
// $staff->notify(new MileageMailer($message));
// }
return $claim; return $claim;
} }
......
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
use Carbon\Carbon; use Carbon\Carbon;
// use App\Models\User;
// use Portal\Mileage\Http\Notifications\MileageMailer;
class FinanceRepo class FinanceRepo
{ {
...@@ -45,6 +47,7 @@ public function findClaim($id) ...@@ -45,6 +47,7 @@ public function findClaim($id)
return MileageClaimMain::with([ return MileageClaimMain::with([
'details.jenisKenderaan.rates', 'details.jenisKenderaan.rates',
'details.project', 'details.project',
'details.pmReviews',
'lkpStatus', 'lkpStatus',
'staffInfo', 'staffInfo',
'auditQueries', 'auditQueries',
...@@ -119,6 +122,27 @@ public function semakClaim($id, $remark = null) ...@@ -119,6 +122,27 @@ public function semakClaim($id, $remark = null)
'remark' => Auth::user()->name . ' Telah Semak Permohonan Tuntutan Mileage (mileage_claim_main.id = ' . $id . ')', 'remark' => Auth::user()->name . ' Telah Semak Permohonan Tuntutan Mileage (mileage_claim_main.id = ' . $id . ')',
]); ]);
// $claim->load('staffInfo');
// $staff = User::find($claim->staffInfo?->fk_users);
// if ($staff && filter_var($staff->email, FILTER_VALIDATE_EMAIL)) {
// $message = collect([
// 'title' => 'Makluman Tuntutan Mileage Anda Telah Disemak Kewangan',
// 'level' => 'success',
// 'content' => [
// 'Assalamualaikum w.b.t ' . $staff->name . ',',
// 'No. Permohonan: ' . $claim->mm_apply_no,
// 'Tuntutan mileage anda telah disemak oleh Kewangan.',
// 'Jumlah Akhir Tuntutan: RM ' . number_format($finalAmount, 2),
// 'Sila log masuk ke sistem untuk melihat butiran pelarasan kewangan.',
// ],
// 'footer' => [
// 'Ini adalah mesej automatik dari sistem. Sila jangan balas emel ini.',
// ],
// ]);
// $staff->notify(new MileageMailer($message));
// }
return $claim; return $claim;
} }
...@@ -143,13 +167,19 @@ private function calculateTotal($claim) ...@@ -143,13 +167,19 @@ private function calculateTotal($claim)
$sortedDetails = $claim->details->sortBy('md_claim_date')->values(); $sortedDetails = $claim->details->sortBy('md_claim_date')->values();
$dateFirstSeen = []; $dateFirstSeen = [];
$cumulativeKmByDate = []; $cumulativeKmByDate = [];
$deductionCount = 0;
foreach ($sortedDetails as $detail) { foreach ($sortedDetails as $detail) {
$jumlahJarak = (float) $detail->md_total_mileage; $jumlahJarak = (float) $detail->md_total_mileage;
$dateKey = $detail->md_claim_date; $dateKey = $detail->md_claim_date;
$isFirstOfDate = !isset($dateFirstSeen[$dateKey]); $isFirstOfDate = !isset($dateFirstSeen[$dateKey]);
if ($isFirstOfDate) $dateFirstSeen[$dateKey] = true; if ($isFirstOfDate) $dateFirstSeen[$dateKey] = true;
$claimableKm = $isFirstOfDate ? max(0, $jumlahJarak - 40) : $jumlahJarak; if ($isFirstOfDate && $deductionCount < 10) {
$claimableKm = max(0, $jumlahJarak - 40);
$deductionCount++;
} else {
$claimableKm = $jumlahJarak;
}
$startKm = $cumulativeKmByDate[$dateKey] ?? 0; $startKm = $cumulativeKmByDate[$dateKey] ?? 0;
$endKm = $startKm + $claimableKm; $endKm = $startKm + $claimableKm;
$mileageAmount = 0; $mileageAmount = 0;
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
use Portal\Mileage\Model\AuditQuery; use Portal\Mileage\Model\AuditQuery;
// use App\Models\User;
// use Portal\Mileage\Http\Notifications\MileageMailer;
class HODRepo class HODRepo
{ {
...@@ -15,7 +17,7 @@ public function getHodList($request) ...@@ -15,7 +17,7 @@ public function getHodList($request)
$search = $request->get('search'); $search = $request->get('search');
return MileageClaimMain::with(['lkpStatus', 'staffInfo']) return MileageClaimMain::with(['lkpStatus', 'staffInfo'])
->whereIn('status', [2, 3]) ->whereIn('status', [5])
->whereHas('staffInfo', function ($q) { ->whereHas('staffInfo', function ($q) {
$q->where('penyokong', Auth::id()); $q->where('penyokong', Auth::id());
}) })
...@@ -61,8 +63,16 @@ public function getHodHistory($request) ...@@ -61,8 +63,16 @@ public function getHodHistory($request)
public function findClaim($id) public function findClaim($id)
{ {
return MileageClaimMain::with(['details.jenisKenderaan.rates', 'details.project', 'lkpStatus', 'staffInfo', 'auditQueries', 'attachments', 'faCategory']) return MileageClaimMain::with([
->findOrFail($id); 'details.jenisKenderaan.rates',
'details.project',
'details.pmReviews',
'lkpStatus',
'staffInfo',
'auditQueries',
'attachments',
'faCategory'
])->findOrFail($id);
} }
...@@ -83,6 +93,26 @@ public function sokongClaim($id, $comment = null) ...@@ -83,6 +93,26 @@ public function sokongClaim($id, $comment = null)
'remark' => Auth::user()->name . ' Telah Sokong Permohonan Tuntutan Mileage (mileage_claim_main.id = ' . $id . ')', 'remark' => Auth::user()->name . ' Telah Sokong Permohonan Tuntutan Mileage (mileage_claim_main.id = ' . $id . ')',
]); ]);
// $claim->load('staffInfo');
// $staff = User::find($claim->staffInfo?->fk_users);
// if ($staff && filter_var($staff->email, FILTER_VALIDATE_EMAIL)) {
// $message = collect([
// 'title' => 'Makluman Tuntutan Mileage Anda Telah Disokong',
// 'level' => 'success',
// 'content' => [
// 'Assalamualaikum w.b.t ' . $staff->name . ',',
// 'No. Permohonan: ' . $claim->mm_apply_no,
// 'Tuntutan mileage anda telah disokong dan dikemukakan kepada BOD untuk kelulusan.',
// 'Sila log masuk ke sistem untuk maklumat lanjut.',
// ],
// 'footer' => [
// 'Ini adalah mesej automatik dari sistem. Sila jangan balas emel ini.',
// ],
// ]);
// $staff->notify(new MileageMailer($message));
// }
return $claim; return $claim;
} }
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
use Portal\Mileage\Model\MileageClaimAuditTrail; use Portal\Mileage\Model\MileageClaimAuditTrail;
use Portal\Mileage\Model\AuditQuery; use Portal\Mileage\Model\AuditQuery;
use Portal\Mileage\Model\MileageClaimAttachment; use Portal\Mileage\Model\MileageClaimAttachment;
use Portal\Mileage\Model\MileageClaimPmReview;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
use Illuminate\Http\Request; use Illuminate\Http\Request;
...@@ -19,7 +20,7 @@ ...@@ -19,7 +20,7 @@
use Carbon\Carbon; use Carbon\Carbon;
use App\Events\AuditLog; use App\Events\AuditLog;
use DB; use Illuminate\Support\Facades\DB;
use Event; use Event;
use File; use File;
use Mail; use Mail;
...@@ -88,7 +89,16 @@ public function storeClaim($request) ...@@ -88,7 +89,16 @@ public function storeClaim($request)
public function findClaim($id) public function findClaim($id)
{ {
return MileageClaimMain::with(['details.jenisKenderaan.rates', 'details.project', 'auditQueries', 'attachments', 'faCategory', 'lkpStatus', 'financeDetail'])->findOrFail($id); return MileageClaimMain::with([
'details.jenisKenderaan.rates',
'details.project',
'details.pmReviews',
'auditQueries',
'attachments',
'faCategory',
'lkpStatus',
'financeDetail'
])->findOrFail($id);
} }
...@@ -99,11 +109,19 @@ public function getJenisKenderaan() ...@@ -99,11 +109,19 @@ public function getJenisKenderaan()
} }
public function getProjects() public function getProjects()
{ {
return Project::where('p_project_sts', 1) $employeeCode = Auth::user()->employeeCode;
->orderBy('p_project_code')
->get(); return Project::where('p_project_sts', 1)
} ->whereHas('projectTeam', function ($q) use ($employeeCode) {
$q->where('pt_staff_id', $employeeCode);
})
->orderBy('p_project_code')
->get();
}
public function getFaCategories() public function getFaCategories()
...@@ -165,7 +183,7 @@ public function updateDetail($request, $detailId) ...@@ -165,7 +183,7 @@ public function updateDetail($request, $detailId)
public function submitClaim($id) public function submitClaim($id)
{ {
$claim = MileageClaimMain::findOrFail($id); $claim = MileageClaimMain::with('details')->findOrFail($id);
$claim->update([ $claim->update([
'status' => 2, 'status' => 2,
...@@ -179,37 +197,70 @@ public function submitClaim($id) ...@@ -179,37 +197,70 @@ public function submitClaim($id)
'remark' => Auth::user()->name . ' Telah Hantar Permohonan Tuntutan Mileage (mileage_claim_main.id = ' . $id . ')', 'remark' => Auth::user()->name . ' Telah Hantar Permohonan Tuntutan Mileage (mileage_claim_main.id = ' . $id . ')',
]); ]);
foreach ($claim->details as $detail) {
if (!$detail->fk_lkp_project) continue;
$pms = DB::table('project_team')
->where('fk_project_id', $detail->fk_lkp_project)
->where('role_id', 1)
->pluck('pt_staff_id');
foreach ($pms as $pmCode) {
MileageClaimPmReview::create([
'fk_claim_id' => $id,
'fk_detail_id' => $detail->id,
'pm_employee_code' => $pmCode,
'status' => 'pending',
]);
}
}
return $claim; return $claim;
} }
public function resubmitClaim($id, $response) public function resubmitClaim($id, $response)
{ {
$claim = MileageClaimMain::findOrFail($id); $claim = MileageClaimMain::findOrFail($id);
$query = AuditQuery::where('fk_main', $id) $query = AuditQuery::where('fk_main', $id)
->whereNull('response') ->whereNull('response')
->latest() ->latest()
->first(); ->first();
if ($query) { if ($query) {
$query->update(['response' => $response]); $query->update(['response' => $response]);
} }
$claim->update([ if ($claim->status == 6) {
'status' => 3, // PM kuiri: only reset the specific butiran that were queried
'query_status' => null, // Other PMs' reviewed records stay intact
'mm_submit_date' => now(), MileageClaimPmReview::where('fk_claim_id', $id)
]); ->where('status', 'queried')
->update(['status' => 'pending', 'note' => null]);
} elseif (in_array($claim->status, [8, 10])) {
// HOD or BOD kuiri: reset ALL pm_review records
// Claim must start over from PM level
MileageClaimPmReview::where('fk_claim_id', $id)
->update(['status' => 'pending', 'note' => null]);
}
MileageClaimAuditTrail::create([ $claim->update([
'fk_lkp_mileage_task' => 8, 'status' => 3,
'fk_mileage_claim_main' => $id, 'query_status' => null,
'action_by' => Auth::id(), 'mm_submit_date' => now(),
'remark' => Auth::user()->name . ' Telah Hantar Semula Permohonan Tuntutan Mileage (mileage_claim_main.id = ' . $id . ')', ]);
]);
MileageClaimAuditTrail::create([
'fk_lkp_mileage_task' => 8,
'fk_mileage_claim_main' => $id,
'action_by' => Auth::id(),
'remark' => Auth::user()->name . ' Telah Hantar Semula Permohonan Tuntutan Mileage (mileage_claim_main.id = ' . $id . ')',
]);
return $claim;
}
return $claim;
}
public function saveDraftClaim($id) public function saveDraftClaim($id)
{ {
......
<?php
namespace Portal\Mileage\Data\Repo;
use Portal\Mileage\Model\MileageClaimMain;
use Portal\Mileage\Model\MileageClaimPmReview;
use Portal\Mileage\Model\MileageClaimAuditTrail;
use Portal\Mileage\Model\AuditQuery;
use Illuminate\Support\Facades\Auth;
use Carbon\Carbon;
class PMRepo
{
public function getPmList($request)
{
$search = $request->get('search');
$employeeCode = Auth::user()->employeeCode;
return MileageClaimMain::with(['lkpStatus', 'staffInfo'])
->whereIn('status', [2, 3])
->whereHas('pmReviews', function ($q) use ($employeeCode) {
$q->where('pm_employee_code', $employeeCode);
})
->when($search, function ($q) use ($search) {
$q->where('mm_apply_no', 'like', '%' . $search . '%');
})
->orderBy('created_at', 'desc')
->paginate(10);
}
public function findClaim($id)
{
return MileageClaimMain::with([
'details.jenisKenderaan.rates',
'details.project',
'details.pmReviews',
'lkpStatus',
'staffInfo',
'auditQueries',
'attachments',
'faCategory',
])->findOrFail($id);
}
public function reviewDetail($detailId)
{
$employeeCode = Auth::user()->employeeCode;
$review = MileageClaimPmReview::where('fk_detail_id', $detailId)
->where('pm_employee_code', $employeeCode)
->firstOrFail();
$review->update(['status' => 'reviewed']);
}
public function kuiriDetail($detailId, $note)
{
$employeeCode = Auth::user()->employeeCode;
$review = MileageClaimPmReview::where('fk_detail_id', $detailId)
->where('pm_employee_code', $employeeCode)
->firstOrFail();
$review->update(['status' => 'queried', 'note' => $note]);
}
public function submitTindakan($claimId)
{
$employeeCode = Auth::user()->employeeCode;
$claim = MileageClaimMain::findOrFail($claimId);
$myReviews = MileageClaimPmReview::where('fk_claim_id', $claimId)
->where('pm_employee_code', $employeeCode)
->with('claimDetail.project')
->get();
$queriedReviews = $myReviews->where('status', 'queried');
if ($queriedReviews->count() > 0) {
$lines = $queriedReviews->map(function ($r) {
$detail = $r->claimDetail;
$projCode = $detail->project?->p_project_code ?? 'Tiada Projek';
$date = Carbon::parse($detail->md_claim_date)->format('d/m/Y');
return "({$date} | {$projCode} | {$detail->md_description}): {$r->note}";
})->implode("\n");
AuditQuery::create([
'fk_main' => $claimId,
'user_id' => Auth::id(),
'comment' => $lines,
'kuiri_by' => 'PM',
]);
$claim->update([
'status' => 6,
'query_status' => 1,
]);
MileageClaimAuditTrail::create([
'fk_lkp_mileage_task' => 15,
'fk_mileage_claim_main' => $claimId,
'action_by' => Auth::id(),
'remark' => Auth::user()->name . ' Telah Kuiri Permohonan Tuntutan Mileage (mileage_claim_main.id = ' . $claimId . ')',
]);
} else {
$this->checkAllReviewed($claimId);
}
}
private function checkAllReviewed($claimId)
{
$pendingCount = MileageClaimPmReview::where('fk_claim_id', $claimId)
->where('status', 'pending')
->count();
if ($pendingCount === 0) {
$claim = MileageClaimMain::findOrFail($claimId);
$claim->update(['status' => 5]);
MileageClaimAuditTrail::create([
'fk_lkp_mileage_task' => 14,
'fk_mileage_claim_main' => $claimId,
'action_by' => Auth::id(),
'remark' => 'Semua PM telah menyemak. Permohonan dikemukakan kepada HOD. (mileage_claim_main.id = ' . $claimId . ')',
]);
}
}
}
...@@ -70,11 +70,12 @@ public function storeClaim(Request $request) ...@@ -70,11 +70,12 @@ public function storeClaim(Request $request)
public function formClaim(Request $request, $id) public function formClaim(Request $request, $id)
{ {
$claim = $this->repos->findClaim($id); $claim = $this->repos->findClaim($id);
$jenisKenderaan = $this->repos->getJenisKenderaan(); $jenisKenderaan = $this->repos->getJenisKenderaan();
$projects = $this->repos->getProjects(); $projects = $this->repos->getProjects();
if (in_array($claim->status, [8, 10])) { if (in_array($claim->status, [6, 8, 10])) {
$query = $claim->auditQueries()->whereNull('response')->latest()->first(); $query = $claim->auditQueries()->whereNull('response')->latest()->first();
return view('mileage::mileage.queryForm', compact('claim', 'jenisKenderaan', 'projects', 'query')); return view('mileage::mileage.queryForm', compact('claim', 'jenisKenderaan', 'projects', 'query'));
} }
......
<?php
namespace Portal\Mileage\Http\Controllers;
use Illuminate\Routing\Controller;
use Illuminate\Http\Request;
use Portal\Mileage\Data\Repo\PMRepo;
class PMController extends Controller
{
protected $repos;
public function __construct(PMRepo $repos)
{
$this->repos = $repos;
}
public function index(Request $request)
{
$list = $this->repos->getPmList($request);
return view('mileage::PM.index', compact('list'));
}
public function show($id)
{
$claim = $this->repos->findClaim($id);
return view('mileage::PM.show', compact('claim'));
}
public function reviewDetail(Request $request, $detailId)
{
$this->repos->reviewDetail($detailId);
return redirect()->back()->with('success', 'Butiran berjaya disemak.');
}
public function kuiriDetail(Request $request, $detailId)
{
$request->validate([
'kuiri_note' => 'required|string|max:500',
]);
$this->repos->kuiriDetail($detailId, $request->kuiri_note);
return redirect()->back()->with('success', 'Butiran telah ditandakan sebagai kuiri.');
}
public function submitTindakan(Request $request, $id)
{
$this->repos->submitTindakan($id);
return redirect()->route('mileage::PM.index')
->with('success', 'Tindakan berjaya dihantar.');
}
}
<?php
namespace Portal\Mileage\Http\Controllers;
use Portal\Mileage\Model\Users;
use Portal\Mileage\Model\Claim;
use Portal\Mileage\Model\Project;
use Portal\Mileage\Model\ProjectTeam;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Carbon\Carbon;
class ProjectManagerController extends Controller
{
/**
* Display the project manager dashboard (monthly view only).
*/
public function index(Request $request)
{
$manager = Auth::user();
$month = $request->input('month', Carbon::now()->format('Y-m'));
try {
// validate the format (YYYY-MM)
if (!preg_match('/^\d{4}-\d{2}$/', $month)) {
$month = now()->format('Y-m');
}
$parsedMonth = Carbon::createFromFormat('Y-m', $month);
} catch (\Exception $e) {
$month = now()->format('Y-m');
$parsedMonth = Carbon::createFromFormat('Y-m', $month);
}
// Get project IDs assigned to this Project Manager
$projectIds = \Portal\Mileage\Model\ProjectTeam::where('pt_staff_id', $manager->employeeCode)
->where('role_id', 1) // "Project Manager" role
->pluck('fk_project_id');
// Get projects under the PM
$projects = \Portal\Mileage\Model\Project::whereIn('id', $projectIds)->get();
// Get all claims for those projects in the selected month
$claims = \Portal\Mileage\Model\Claim::with(['user', 'project'])
->whereIn('project_id', $projectIds)
->whereMonth('claim_date', $parsedMonth->month)
->whereYear('claim_date', $parsedMonth->year)
->get();
return view('mileage::projectManager.index', compact('projects', 'claims', 'month'));
}
/**
* Show all claims for one staff for the selected month.
*/
public function show($projectId, $userId, Request $request)
{
$month = $request->input('month', Carbon::now()->format('Y-m'));
try {
if (!preg_match('/^\d{4}-\d{2}$/', $month)) {
$month = now()->format('Y-m');
}
$parsedMonth = Carbon::createFromFormat('Y-m', $month);
} catch (\Exception $e) {
$month = now()->format('Y-m');
$parsedMonth = Carbon::createFromFormat('Y-m', $month);
}
$project = \Portal\Mileage\Model\Project::findOrFail($projectId);
$user = \Portal\Mileage\Model\Users::findOrFail($userId);
$claims = \Portal\Mileage\Model\Claim::with(['project'])
->where('project_id', $projectId)
->where('user_id', $userId)
->whereMonth('claim_date', $parsedMonth->month)
->whereYear('claim_date', $parsedMonth->year)
->orderBy('claim_date', 'asc')
->get();
return view('mileage::projectManager.show', compact('project', 'user', 'claims', 'month'));
}
/**
* Approve all pending claims for a specific project in the selected month.
*/
public function approveMonth(Request $request)
{
$manager = Auth::user();
$monthLabel = $request->input('month');
$projectId = $request->input('project_id');
// require project_id
if (!$projectId) {
return back()->with('error', 'Sila pilih projek untuk disokong.');
}
// validate month format (expects YYYY-MM)
try {
if (!preg_match('/^\d{4}-\d{2}$/', $monthLabel)) {
throw new \Exception('Invalid month format');
}
$parsedMonth = Carbon::createFromFormat('Y-m', $monthLabel);
} catch (\Exception $e) {
return back()->with('error', 'Format bulan tidak sah. Sila pilih semula bulan dalam format YYYY-MM.');
}
// ensure manager oversees this project
$allowedProjectIds = ProjectTeam::where('pt_staff_id', $manager->employeeCode)
->where('role_id', 1) // project manager role
->pluck('fk_project_id')
->toArray();
if (!in_array($projectId, $allowedProjectIds)) {
return back()->with('error', 'Anda tidak dibenarkan melakukan tindakan ini untuk projek terpilih.');
}
// update only claims for this project and month with status 'Diproses'
$approvedCount = Claim::where('project_id', $projectId)
->whereMonth('claim_date', $parsedMonth->month)
->whereYear('claim_date', $parsedMonth->year)
->where('status', 'Diproses')
->update([
'status' => 'Disokong',
'approved_by' => $manager->id,
'updated_at' => now(),
]);
if ($approvedCount > 0) {
return back()->with('success', $approvedCount . ' tuntutan telah disokong untuk projek ini bagi bulan ' . $monthLabel . '.');
}
return back()->with('warning', 'Tiada tuntutan "Diproses" untuk disokong bagi projek ini pada bulan ' . $monthLabel . '.');
}
/**
* Reject all pending claims for a specific project in the selected month.
*/
public function rejectMonth(Request $request)
{
$request->validate([
'project_id' => 'required|integer',
'user_id' => 'required|integer',
'month' => 'required|string',
'reject_reason' => 'required|string|max:500',
]);
$month = Carbon::createFromFormat('Y-m', $request->month);
$claims = Claim::where('project_id', $request->project_id)
->where('user_id', $request->user_id)
->whereMonth('claim_date', $month->month)
->whereYear('claim_date', $month->year)
->get();
foreach ($claims as $claim) {
$claim->status = 'Ditolak';
$claim->rejected_by = auth()->id();
$claim->reject_reason = $request->reject_reason;
$claim->save();
}
return redirect()->back()->with('success', 'Semua tuntutan telah ditolak dengan sebab: ' . $request->reject_reason);
}
public function approveClaim($id)
{
$claim = Claim::findOrFail($id);
$claim->status = 'Disokong';
$claim->verified_by = auth()->id();
$claim->save();
return back()->with('success', 'Tuntutan telah disahkan.');
}
public function rejectClaim(Request $request, $id)
{
$request->validate(['reject_reason' => 'required|string|max:500']);
$claim = Claim::findOrFail($id);
$claim->status = 'Ditolak';
$claim->rejected_by = auth()->id();
$claim->reject_reason = $request->reject_reason;
$claim->save();
return back()->with('success', 'Tuntutan telah ditolak dengan sebab: ' . $request->reject_reason);
}
}
<?php
namespace Portal\Mileage\Http\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
class PpjMailer extends Notification implements ShouldQueue
{
use Queueable;
protected $view = 'ecuti::emails.layouts.simple';
public $message;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct($message , $view = FALSE)
{
$this->message = $message;
$this->view = ($view) ? $view : $this->view;
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['mail'];
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
$mailMessage = new MailMessage;
if($this->view) $mailMessage->view = $this->view;
$mailMessage->subject($this->message->get('title', 'Email From ' ));
// $mailMessage->title($this->message->get('title', 'Email From ' ));
$mailMessage->level($this->message->get('level'));
// $mailMessage->greeting('Hi,' . ' ' .$notifiable->name. ', ');
$content = $this->message->get('content',[]);
// dd($content);
foreach($content as $cont){
$mailMessage->line($cont);
}
$action = $this->message->get('action', FALSE);
if($action):
foreach($action as $title => $uri){
$mailMessage->action($title,$uri);
}
endif;
$footer = $this->message->get('footer',[]);
foreach($footer as $foot){
$mailMessage->line($foot);
}
// dd($mailMessage);
// $mailMessage->cc('portalppjadmin@ppj.gov.my');
// $mailMessage->bcc('pss3frsb@gmail.com'); // bcc email ke pss3frsb
return $mailMessage;
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
}
}
...@@ -35,4 +35,9 @@ public function project() ...@@ -35,4 +35,9 @@ public function project()
{ {
return $this->belongsTo(Project::class, 'fk_lkp_project'); return $this->belongsTo(Project::class, 'fk_lkp_project');
} }
public function pmReviews()
{
return $this->hasMany(MileageClaimPmReview::class, 'fk_detail_id');
}
} }
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Portal\Mileage\Model\AuditQuery; use Portal\Mileage\Model\AuditQuery;
use Portal\Mileage\Model\MileageClaimFinance; use Portal\Mileage\Model\MileageClaimFinance;
use Portal\Mileage\Model\MileageClaimPmReview;
class MileageClaimMain extends Model class MileageClaimMain extends Model
{ {
...@@ -106,6 +107,10 @@ public function financeDetail() ...@@ -106,6 +107,10 @@ public function financeDetail()
return $this->hasOne(MileageClaimFinance::class, 'fk_mileage_claim_main'); return $this->hasOne(MileageClaimFinance::class, 'fk_mileage_claim_main');
} }
public function pmReviews()
{
return $this->hasMany(MileageClaimPmReview::class, 'fk_claim_id');
}
} }
<?php
namespace Portal\Mileage\Model;
use Illuminate\Database\Eloquent\Model;
class MileageClaimPmReview extends Model
{
protected $table = 'mileage_claim_pm_review';
protected $fillable = [
'fk_claim_id',
'fk_detail_id',
'pm_employee_code',
'status',
'note',
];
public function claimMain()
{
return $this->belongsTo(MileageClaimMain::class, 'fk_claim_id');
}
public function claimDetail()
{
return $this->belongsTo(MileageClaimDetail::class, 'fk_detail_id');
}
}
...@@ -23,9 +23,10 @@ public function project() ...@@ -23,9 +23,10 @@ public function project()
// if you want, link to App user model (pt_staff_id commonly stores App user id or employee code) // if you want, link to App user model (pt_staff_id commonly stores App user id or employee code)
public function user() public function user()
{ {
return $this->belongsTo(\App\Models\User::class, 'pt_staff_id', 'id'); return $this->belongsTo(\App\Models\User::class, 'pt_staff_id', 'employeeCode');
} }
public function role() public function role()
{ {
return $this->belongsTo(ProjectRole::class, 'role_id'); return $this->belongsTo(ProjectRole::class, 'role_id');
......
...@@ -91,10 +91,10 @@ protected function menu() ...@@ -91,10 +91,10 @@ protected function menu()
->active('mileage/*') ->active('mileage/*')
->data('permission', Permission::STAFF); ->data('permission', Permission::STAFF);
// $menu->add(__('Project Manager Dashboard'), route('mileage::projectManager.index')) $menu->add(__('Project Manager Dashboard'), route('mileage::PM.index'))
// ->data('icon', 'briefcase') ->data('icon', 'briefcase')
// ->active('projectManager/*') ->active('projectManager/*')
// ->data('permission', Permission::PROJECT_MANAGER); ->data('permission', Permission::PROJECT_MANAGER);
// $menu->add(__('Project Director Dashboard'), route('mileage::projectDirector.index')) // $menu->add(__('Project Director Dashboard'), route('mileage::projectDirector.index'))
// ->data('icon', 'compass') // ->data('icon', 'compass')
......
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