add refund logic and fix books inventory logic
This commit is contained in:
@@ -163,6 +163,12 @@ final class SchoolYearManagementService
|
||||
if (! SchoolYearStatus::canTransition($from, SchoolYearStatus::ACTIVE)) {
|
||||
throw new InvalidArgumentException('Only draft or approved reopened school years can be activated.');
|
||||
}
|
||||
if ($this->configurationTotalInstructionalWeeks() <= 0) {
|
||||
throw new InvalidArgumentException('Set total instructional weeks before activating this school year.');
|
||||
}
|
||||
if ((int) ($year['annual_fee_includes_books'] ?? 1) !== 1) {
|
||||
throw new InvalidArgumentException('The withdrawal refund policy requires annual tuition to include books.');
|
||||
}
|
||||
|
||||
$this->db->transStart();
|
||||
$activeYears = $this->schoolYearModel->where('status', SchoolYearStatus::ACTIVE)->findAll();
|
||||
@@ -348,6 +354,9 @@ final class SchoolYearManagementService
|
||||
'registration_starts_on' => $this->nullableDate($payload['registration_starts_on'] ?? null),
|
||||
'registration_ends_on' => $this->nullableDate($payload['registration_ends_on'] ?? null),
|
||||
'fall_makeup_exam_on' => $this->nullableDate($payload['fall_makeup_exam_on'] ?? null),
|
||||
'total_instructional_weeks' => $this->nullableInt($payload['total_instructional_weeks'] ?? null),
|
||||
'annual_fee_includes_books' => 1,
|
||||
'withdrawal_policy_version' => trim((string) ($payload['withdrawal_policy_version'] ?? 'studied_weeks_v1')) ?: 'studied_weeks_v1',
|
||||
'previous_school_year_id' => $this->nullableInt($payload['previous_school_year_id'] ?? null),
|
||||
];
|
||||
}
|
||||
@@ -377,6 +386,7 @@ final class SchoolYearManagementService
|
||||
|
||||
$configValues = [
|
||||
'school_year' => $name,
|
||||
'total_instructional_weeks' => (string) ($schoolYear['total_instructional_weeks'] ?? ''),
|
||||
'date_age_reference' => $ageReferenceDate,
|
||||
'refund_deadline' => $ageReferenceDate,
|
||||
'school_year_start_date' => $yearStart,
|
||||
@@ -409,6 +419,13 @@ final class SchoolYearManagementService
|
||||
}
|
||||
}
|
||||
|
||||
private function configurationTotalInstructionalWeeks(): int
|
||||
{
|
||||
$weeks = filter_var($this->configurationModel->getConfig('total_instructional_weeks'), FILTER_VALIDATE_INT);
|
||||
|
||||
return $weeks !== false && $weeks > 0 ? (int) $weeks : 0;
|
||||
}
|
||||
|
||||
private function withCalendarDefaults(array $payload, string $schoolYearName): array
|
||||
{
|
||||
$calendar = $this->calendarPayloadForSchoolYear($schoolYearName);
|
||||
|
||||
Reference in New Issue
Block a user