Commit ac889b9d by Hannah Zahra

Fourth Update

parent 5961a3ce
......@@ -138,6 +138,7 @@
<br>
@else
<div class="ui message">Tiada tuntutan untuk projek ini bulan ini.</div>
<br>
@endif
</div>
@empty
......
......@@ -21,8 +21,8 @@ function () {
Route::prefix('applyform')->name('applyform')->group(function () {
Route::get('/', [ApplyformController::class, 'index'])->name('.index');
Route::get('/noproject', [ApplyformController::class, 'noproject'])->name('.noproject');
Route::get('/applyform/getDates', [ApplyformController::class, 'getDates'])->name('.getDates');
});
// Route::resource('applyform', ApplyformController::class);
// Applications
......@@ -32,8 +32,6 @@ function () {
Route::get('applications/view/claim/{id}', [ApplicationsController::class, 'viewEach'])->name('applications.viewEach');
Route::put('applications/{id}', [ApplicationsController::class, 'update'])
->name('applications.update');
Route::get('/applications/dates', [\Portal\Mileage\Http\Controllers\ApplicationsController::class, 'getClaimDates'])
->name('mileage::applications.getDates');
// Project Manager
Route::prefix('projectManager')->name('projectManager')->group(function () {
......
......@@ -9,6 +9,7 @@
use Illuminate\Routing\Controller;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Auth;
use Illuminate\Http\Request;
use Carbon\Carbon;
......@@ -68,53 +69,29 @@ public function index(Request $request)
public function store(Request $request)
{
// Validate request data
$validated = $request->validate([
'claim_date' => 'required|date',
'jenis_kenderaan_id' => 'required|exists:lkp_jenis_kenderaans,id',
'project_id' => 'nullable|exists:lkp_project,id',
'description' => 'required',
'distance_from' => 'nullable',
'distance_to' => 'nullable',
'total_mileage' => 'required|numeric',
'toll_amount' => 'nullable|numeric',
'others_amount' => 'nullable|numeric',
'others_description' => 'nullable|string|max:255',
]);
$validated['user_id'] = auth()->id(); // Get the current authenticated user
// Calculate the total claim amount and mileage
$calculatedAmount = $this->calculateClaimAmount($validated);
$validated['calculated_amount'] = $calculatedAmount;
// Handle the status based on actions (e.g., project manager, director, finance)
$validated['status'] = 'Diproses'; // Initial status
// Store the claim in the database
$claim = Claim::create($validated);
// Now, we need to manage the role and verify the project
// Example: If project_id is set, link the claim with the project and handle roles
if ($claim->project) {
$project = $claim->project;
// Here, you can check if the claim should be verified by a Project Manager (HOD)
// For now, we’re assuming you use the role directly to set verified_by
if ($project->project_manager_id) {
$claim->verified_by = $project->project_manager_id;
}
// Similarly, you can handle who approves and reviews (e.g., Project Director or BOD)
if ($project->project_director_id) {
$claim->approved_by = $project->project_director_id;
}
// your existing store logic
$calculation = $this->calculateClaimAmount($request);
$claim->save();
}
Claim::create([
'user_id' => Auth::id(),
'project_id' => $request->project_id,
'claim_date' => $request->claim_date,
'jenis_kenderaan_id' => $request->jenis_kenderaan_id,
'description' => $request->description,
'distance_from' => $request->distance_from,
'distance_to' => $request->distance_to,
'total_mileage' => $request->total_mileage,
'toll_amount' => $request->toll_amount ?? 0,
'others_amount' => $request->others_amount ?? 0,
'claimable_mileage' => $calculation['claimable_mileage'],
'rate' => $calculation['rate'],
'mileage_amount' => $calculation['mileage_amount'],
'total_claim_amount' => $calculation['total_claim'],
'status' => 'Diproses',
]);
return redirect()->route('mileage::applications.index')->with('success', 'Claim submitted successfully!');
return redirect()->route('mileage::applications.index')
->with('success', 'Tuntutan berjaya dihantar!');
}
public function edit($id)
......@@ -265,5 +242,26 @@ public function updateStatus(Request $request, $id)
return back()->with('success', 'Claim status updated to ' . $claim->status);
}
private function calculateClaimAmount($request)
{
$totalMileage = (float) $request->total_mileage;
$toll = (float) $request->toll_amount;
$others = (float) $request->others_amount;
// Deduct first 40km
$claimableMileage = $totalMileage > 40 ? $totalMileage - 40 : 0;
// Apply rate logic
$rate = $claimableMileage > 500 ? 0.50 : 0.55;
$mileageAmount = $claimableMileage * $rate;
$totalClaim = $mileageAmount + $toll + $others;
return [
'claimable_mileage' => $claimableMileage,
'rate' => $rate,
'mileage_amount' => $mileageAmount,
'total_claim' => $totalClaim,
];
}
}
......@@ -130,4 +130,15 @@ public function noproject()
return view('mileage::applyform.noproject', compact('jenisKenderaan'));
}
public function getDates()
{
$userId = auth()->id();
$dates = Claim::where('user_id', $userId)
->pluck('claim_date') // get all submitted dates
->map(fn($d) => \Carbon\Carbon::parse($d)->format('Y-m-d')); // format to yyyy-mm-dd
return response()->json($dates);
}
}
......@@ -6,7 +6,7 @@
class AclRole extends Model
{
protected $table = 'acl_roles'; // ⚠️ must be your roles definition table
protected $table = 'acl_roles'; // must be your roles definition table
protected $primaryKey = 'id';
public $timestamps = false;
......
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