This commit is contained in:
@@ -11,6 +11,7 @@ use App\Models\StudentClassModel;
|
||||
use App\Models\ClassSectionModel;
|
||||
use App\Models\AttendanceDataModel;
|
||||
use App\Models\AttendanceRecordModel;
|
||||
use App\Exceptions\SchoolYear\SchoolYearWriteConflictException;
|
||||
use App\Services\SemesterRangeService;
|
||||
|
||||
class ParentAttendanceReportController extends BaseController
|
||||
@@ -58,7 +59,8 @@ class ParentAttendanceReportController extends BaseController
|
||||
[$sundays, $defaultDate] = $this->computeSundays();
|
||||
|
||||
// Load upcoming reports for preview/edit (today and forward within this school year)
|
||||
$schoolYear = $this->currentSchoolYearName((string) ($this->configModel->getConfig('school_year') ?? ''));
|
||||
$schoolYearContext = $this->resolveSchoolYearContext();
|
||||
$schoolYear = $schoolYearContext->yearName();
|
||||
$todayYmd = local_date(utc_now(), 'Y-m-d');
|
||||
$previewRows = $this->reportModel->builder()
|
||||
->select('parent_attendance_reports.*, s.firstname, s.lastname')
|
||||
@@ -80,6 +82,8 @@ class ParentAttendanceReportController extends BaseController
|
||||
'defaultDate' => $defaultDate, // preselected date (upcoming Sunday)
|
||||
'myReports' => $previewRows,
|
||||
'cutoffThreshold' => $cutoffThreshold,
|
||||
'selectedYear' => $schoolYear,
|
||||
'isEditable' => ! $schoolYearContext->isReadonly(),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -91,6 +95,13 @@ class ParentAttendanceReportController extends BaseController
|
||||
return redirect()->to('/login');
|
||||
}
|
||||
|
||||
$schoolYearContext = $this->resolveSchoolYearContext();
|
||||
try {
|
||||
$this->assertSchoolYearWritable($schoolYearContext);
|
||||
} catch (SchoolYearWriteConflictException $e) {
|
||||
return redirect()->back()->withInput()->with('error', $e->getMessage());
|
||||
}
|
||||
|
||||
$post = $this->request->getPost();
|
||||
|
||||
$rules = [
|
||||
@@ -141,7 +152,7 @@ class ParentAttendanceReportController extends BaseController
|
||||
$dismissTime = $post['dismiss_time'] ?? null;
|
||||
$reasonRaw = $post['reason'] ?? null;
|
||||
$reason = is_string($reasonRaw) ? trim($reasonRaw) : null;
|
||||
$schoolYear = $this->currentSchoolYearName((string) ($this->configModel->getConfig('school_year') ?? ''));
|
||||
$schoolYear = $schoolYearContext->yearName();
|
||||
|
||||
// Enforce Sunday-only and future-or-today selection
|
||||
$todayCheck = new \DateTime('today');
|
||||
@@ -1508,6 +1519,13 @@ class ParentAttendanceReportController extends BaseController
|
||||
return redirect()->to('/login');
|
||||
}
|
||||
|
||||
$schoolYearContext = $this->resolveSchoolYearContext();
|
||||
try {
|
||||
$this->assertSchoolYearWritable($schoolYearContext);
|
||||
} catch (SchoolYearWriteConflictException $e) {
|
||||
return redirect()->back()->with('error', $e->getMessage());
|
||||
}
|
||||
|
||||
$id = (int) ($this->request->getPost('id') ?? 0);
|
||||
if ($id <= 0) {
|
||||
return redirect()->back()->with('error', 'Invalid report.');
|
||||
@@ -1517,6 +1535,9 @@ class ParentAttendanceReportController extends BaseController
|
||||
if (!$row || (int)($row['parent_id'] ?? 0) !== (int)$parentId) {
|
||||
return redirect()->back()->with('error', 'Report not found.');
|
||||
}
|
||||
if ((string) ($row['school_year'] ?? '') !== $schoolYearContext->yearName()) {
|
||||
return redirect()->back()->with('error', 'Report not found for the selected school year.');
|
||||
}
|
||||
|
||||
// Only allow editing for 'new' status entries
|
||||
$status = (string) ($row['status'] ?? '');
|
||||
|
||||
Reference in New Issue
Block a user