bug fixes, leave managment refactoring, report points

This commit is contained in:
Kwesi Banson
2026-11-03 12:05:59 +00:00
parent 965892ac62
commit b393dcdf0e
14 changed files with 144 additions and 117 deletions

View File

@@ -1,63 +0,0 @@
<?php
namespace App\Http\Controllers;
use Session;
use App\Models;
use Illuminate\Http\Request;
class CommentsController extends Controller
{
public function index(){
$user_id = \Auth::user()->id;
$result = Models\Comment::with('projectStatus')
->where('assignee_id', $user_id)
->orderBy('project_id', 'DESC')
->get();
$data = [
'page_title' => 'Projects Status List',
'project_statuses' => $result
];
return view('comments.index', $data);
}
public function add_comment($id){
$result = Models\ProjectStatus::with('comments', 'project')->where('id', $id)->firstOrFail();
// dd($result);
$data = [
'page_title' => 'Projects Status Comment',
'project_arr' => $result
];
// dump($data);
return view('comments.create', $data);
}
public function store(Request $request) {
// Save a new post
$this->validate($request, [
'description' => 'required',
'status' => 'required',
'project_id' => 'required',
'assignee_id' => 'required'
]);
$project_status_arr = $request->except('_token');
$result = Models\ProjectStatus::create($project_status_arr);
Session::flash('success_message', 'Project status added successfully!');
return redirect(url('project-status'));
}
public function show($id) {
// Show a specific post
}
public function edit($id) {
// Show form to edit a post
}
public function update(Request $request, $id) {
// Update a specific post
return redirect(url('project-status'));
}
public function destroy($id) {
// Delete a specific post
}
}

View File

@@ -4,6 +4,7 @@ namespace App\Http\Controllers;
use App\Models\DailyReport;
use App\Models\ReportOverride;
use App\Models\StaffMember;
use App\Http\Requests\StoreDailyReportRequest;
use Illuminate\Support\Facades\Mail;
use App\Mail\DailyReportSubmitted;
@@ -18,6 +19,7 @@ class DailyReportController extends Controller
return view('reports.index', compact('reports'));
}
public function store(StoreDailyReportRequest $request)
{
$report = DailyReport::create([
@@ -26,20 +28,25 @@ class DailyReportController extends Controller
'content' => $request->content,
]);
// If they used an override, optionally delete or mark it as used so it can't be reused
// Reward the staff member with points (e.g., 10 points per report)
$staff = auth()->user();
$staff->increment('report_points', 10);
ReportOverride::where('user_id', auth()->id())
->where('report_date', $request->report_date)
->delete();
$managementEmails = ['kwesi@click-mobile.com'];
// $managementEmails = User::whereIn('group', ['directors'])
// ->pluck('email')
// ->toArray();
Mail::to($managementEmails)->send(new DailyReportSubmitted($report, auth()->user()));
/// modify this to make it dynamic
$managementEmails = StaffMember::with('department')->whereIn('department_id', [5])->pluck('email')->toArray();
if (env('APP_ENV') == 'production') {
Mail::to($managementEmails)->send(new DailyReportSubmitted($report, auth()->user()));
}
return response()->json([
'success' => true,
'message' => 'Daily report submitted successfully.'
'message' => 'Daily report submitted successfully! You earned 10 points.',
'new_points_total' => $staff->report_points // Optional: send back to update UI dynamically
]);
}
}

View File

@@ -16,7 +16,7 @@ class LeaveRequestController extends Controller
{
$query = LeaveRequest::with('staff');
// Search by Staff Name
if ($request->filled('search')) {
$search = $request->search;
$query->whereHas('staff', function($q) use ($search) {
@@ -24,18 +24,17 @@ class LeaveRequestController extends Controller
});
}
// Filter by Status
if ($request->filled('status')) {
$query->where('status', $request->status);
} else {
// Default to showing pending requests first if no filter is applied
}
else {
$query->orderByRaw("FIELD(status, 'PENDING', 'APPROVED', 'REJECTED')");
}
$leaveRequests = $query->orderBy('created_at', 'desc')->paginate(15);
$leaveRequests->appends($request->query());
// KPIs for HR
$pendingCount = LeaveRequest::where('status', 'PENDING')->count();
$approvedThisMonth = LeaveRequest::where('status', 'APPROVED')
->whereMonth('start_date', Carbon::now()->month)
@@ -52,11 +51,8 @@ class LeaveRequestController extends Controller
}
public function myLeave()
{
// Find the staff profile of the currently logged-in user
// Adjust this logic if you link Users to StaffMembers differently (e.g., via a staff_id foreign key)
$staff = StaffMember::where('email', auth()->user()->email)->firstOrFail();
// Fetch their leave history, latest first
$staff = StaffMember::where('email', auth()->user()->email)->firstOrFail();
$leaveRequests = LeaveRequest::where('staff_member_id', $staff->id)
->orderBy('created_at', 'desc')
->paginate(10);
@@ -82,7 +78,6 @@ class LeaveRequestController extends Controller
$start = Carbon::parse($validated['start_date']);
$end = Carbon::parse($validated['end_date']);
// Calculate total days excluding weekends
$totalDays = $start->diffInDaysFiltered(function (Carbon $date) {
return !$date->isWeekend();
}, $end) + 1; // +1 to include both the start and end day
@@ -107,7 +102,7 @@ class LeaveRequestController extends Controller
}
public function updateStatus(Request $request, $id)
public function updateStatusOld(Request $request, $id)
{
$leaveRequest = LeaveRequest::findOrFail($id);
@@ -140,4 +135,42 @@ class LeaveRequestController extends Controller
return response()->json(['success' => true, 'message' => 'Leave status updated successfully!']);
}
}
public function updateStatus(Request $request, $id)
{
$leaveRequest = LeaveRequest::findOrFail($id);
$incomingStatus = strtoupper($request->status);
$request->merge(['status' => $incomingStatus]);
$validated = $request->validate([
'status' => 'required|in:APPROVED,REJECTED',
'admin_remarks' => 'nullable|string',
]);
$currentStatus = strtoupper($leaveRequest->status);
$newStatus = $validated['status'];
$staff = $leaveRequest->staff;
if ($staff && strtolower($leaveRequest->leave_type) === 'annual') { // only annual leave affects leave balance
if ($newStatus === 'APPROVED' && $currentStatus !== 'APPROVED') {
$staff->annual_leave_balance -= $leaveRequest->total_days;
$staff->save();
}
if ($newStatus === 'REJECTED' && $currentStatus === 'APPROVED') {
$staff->annual_leave_balance += $leaveRequest->total_days;
$staff->save();
}
}
$leaveRequest->update([
'status' => $newStatus,
'admin_remarks' => $validated['admin_remarks'] ?? null,
'approved_by' => auth()->id(),
]);
return response()->json(['success' => true, 'message' => 'Leave status updated successfully!']);
}
}

View File

@@ -11,25 +11,24 @@ class ManagementDashboardController extends Controller
{
public function index(Request $request)
{
// 1. Fetch Pending Leaves (Adjust status/model names to match your schema)
$pendingLeaves = LeaveRequest::with('staff')
->where('status', 'Pending')
->orderBy('created_at', 'asc')
->get();
$startDate = $request->input('start_date', Carbon::now()->startOfMonth()->format('Y-m-d'));
$endDate = $request->input('end_date', Carbon::now()->endOfMonth()->format('Y-m-d'));
$staffReports = StaffMember::withCount(['dailyReports' => function ($query) use ($startDate, $endDate) {
$query->whereBetween('report_date', [$startDate, $endDate]);
}])
->orderBy('name')
->get();
$staffReports = StaffMember::where('department_id', '!=', 5)
->withCount(['dailyReports' => function ($query) use ($startDate, $endDate) {
$query->whereBetween('report_date', [$startDate, $endDate]);
}])
->orderBy('name')
->get();
return view('management.index', compact('pendingLeaves', 'staffReports', 'startDate', 'endDate'));
}
public function updateLeaveStatus(Request $request, $id)
{
$request->validate(['status' => 'required|in:Approved,Rejected']);

View File

@@ -79,8 +79,9 @@ class NetworkOperatorsController extends Controller
$request->validate([
'name' => 'required|string|max:200',
'country' => 'required|string',
'contract_auto_renew' => 'required|boolean',
'next_renewal_date' => 'nullable|required_if:contract_auto_renew,0|date',
'connection_status' => 'required|string',
// 'contract_auto_renew' => 'required|boolean',
// 'next_renewal_date' => 'nullable|required_if:contract_auto_renew,0|date',
]);
$operator->update([
@@ -109,7 +110,7 @@ class NetworkOperatorsController extends Controller
return response()->json(['message' => 'MNO Partner updated successfully!']);
}
// Fetch single record JSON for editing modal
public function getJson($id)
{
$operator = NetworkOperator::findOrFail($id);
@@ -118,8 +119,6 @@ class NetworkOperatorsController extends Controller
public function show($id)
{
$operator = NetworkOperator::findOrFail($id);
// Fetch all services for the dropdown
$allServices = \App\Models\Service::orderBy('name')->get();
$staffMembers = \App\Models\StaffMember::orderBy('name')->get();
@@ -134,13 +133,9 @@ class NetworkOperatorsController extends Controller
'required',
'string',
function ($attribute, $value, $fail) {
// 1. Check if valid IP Address (IPv4 or IPv6)
$isIp = filter_var($value, FILTER_VALIDATE_IP);
// 2. Check if valid Domain Name (e.g., smpp.operator.com)
$isDomain = preg_match('/^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$/i', $value);
// 3. Check if valid CIDR Subnet (e.g., 196.200.15.0/24)
$isDomain = preg_match('/^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$/i', $value);
$isSubnet = preg_match('/^([0-9]{1,3}\.){3}[0-9]{1,3}\/([0-9]|[1-2][0-9]|3[0-2])$/', $value);
if (!$isIp && !$isDomain && !$isSubnet) {
@@ -192,7 +187,7 @@ class NetworkOperatorsController extends Controller
\App\Models\MnoNote::create([
'mno_id' => $operatorId,
'services' => $request->services ?? '',
'user_id' => auth()->id(), // Automatically assign the logged-in user
'user_id' => auth()->id(),
'notes_body' => $request->notes_body,
]);