fix financial and certificates

This commit is contained in:
root
2026-06-05 01:51:08 -04:00
parent d28d11e2e5
commit ad968eaff7
94 changed files with 9654 additions and 214 deletions
@@ -5,9 +5,19 @@ namespace App\Services\Grading;
use App\Models\GradingLock;
use App\Models\ClassSection;
use RuntimeException;
use App\Services\Grading\Policy\GradingPolicyResolver;
use App\Services\Grading\Validation\GradebookFinalizationValidator;
class GradingLockService
{
public function __construct(
private ?GradingPolicyResolver $policyResolver = null,
private ?GradebookFinalizationValidator $finalizationValidator = null
) {
$this->policyResolver = $this->policyResolver ?? new GradingPolicyResolver();
$this->finalizationValidator = $this->finalizationValidator ?? new GradebookFinalizationValidator();
}
public function toggle(int $classSectionId, string $semester, string $schoolYear, ?int $userId): bool
{
if ($classSectionId <= 0 || $semester === '' || $schoolYear === '') {
@@ -25,6 +35,8 @@ class GradingLockService
return false;
}
$this->assertCanLock($classSectionId, $semester, $schoolYear);
if ($existing) {
$existing->update([
'is_locked' => 1,
@@ -83,6 +95,8 @@ class GradingLockService
$count = 0;
foreach ($sectionIds as $sid) {
$this->assertCanLock($sid, $semester, $schoolYear);
if (!empty($existingBySection[$sid])) {
if ($existingBySection[$sid]->is_locked) {
continue;
@@ -115,4 +129,18 @@ class GradingLockService
return $count;
}
private function assertCanLock(int $classSectionId, string $semester, string $schoolYear): void
{
$mode = $this->policyResolver->calculationMode($classSectionId, $semester, $schoolYear);
if ($mode !== GradingPolicyResolver::STRONG_MODE) {
return;
}
$result = $this->finalizationValidator->validateClassSectionBeforeLock($classSectionId, $semester, $schoolYear);
if (!$result['valid']) {
$count = count($result['errors']);
throw new RuntimeException("Cannot lock class section {$classSectionId}; strong grading validation failed with {$count} error(s).");
}
}
}