fix(hr): automatically show RD status for rest days based on global settings even if no record exists
This commit is contained in:
@@ -893,19 +893,34 @@ class AttendanceRecordController extends Controller
|
||||
->get()
|
||||
->groupBy('employee_id');
|
||||
|
||||
$users = $usersRaw->map(function($user) use ($dates, $dailyRecords, $approvedLeaves) {
|
||||
// Fetch working days indices from settings [0=Sun, 1=Mon, ..., 6=Sat]
|
||||
$globalSettings = settings();
|
||||
$workingDaysIndices = json_decode($globalSettings['working_days'] ?? '[1,2,3,4,5]', true);
|
||||
|
||||
$users = $usersRaw->map(function($user) use ($dates, $dailyRecords, $approvedLeaves, $workingDaysIndices) {
|
||||
$grid = [];
|
||||
$userRecords = $dailyRecords->has($user->id) ? $dailyRecords[$user->id]->keyBy('date') : collect();
|
||||
|
||||
foreach ($dates as $d) {
|
||||
$dateKey = $d['date'];
|
||||
|
||||
// Default matrix values based on time mechanics
|
||||
$isPast = \Carbon\Carbon::parse($dateKey)->isBefore(\Carbon\Carbon::today());
|
||||
// Default matrix values based on time mechanics and global settings
|
||||
$dateObj = \Carbon\Carbon::parse($dateKey);
|
||||
$isPast = $dateObj->isBefore(\Carbon\Carbon::today());
|
||||
$dateIndex = $dateObj->dayOfWeek;
|
||||
$isWeekend = ($d['day_name'] === 'Sat' || $d['day_name'] === 'Sun');
|
||||
$isRestDay = !in_array($dateIndex, $workingDaysIndices);
|
||||
|
||||
$status = $isPast ? '--' : ($isWeekend ? 'W' : '--');
|
||||
$label = 'Not Marked';
|
||||
if ($isRestDay) {
|
||||
$status = 'RD';
|
||||
$label = 'Rest Day';
|
||||
} else if ($isWeekend) {
|
||||
$status = 'W';
|
||||
$label = 'Weekend';
|
||||
} else {
|
||||
$status = '--';
|
||||
$label = 'Not Marked';
|
||||
}
|
||||
|
||||
$recordDetail = null;
|
||||
if ($userRecords->has($dateKey)) {
|
||||
|
||||
Reference in New Issue
Block a user