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

@@ -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
]);
}
}