fix tests
This commit is contained in:
@@ -2,10 +2,9 @@
|
||||
|
||||
namespace App\Services\Reports\ReportCards;
|
||||
|
||||
use App\Models\Calendar;
|
||||
use App\Models\AttendanceData;
|
||||
use App\Models\AttendanceRecord;
|
||||
use App\Models\ClassSection;
|
||||
use App\Models\Calendar;
|
||||
use App\Models\Configuration;
|
||||
use App\Models\ReportCardAcknowledgement;
|
||||
use App\Models\ScoreComment;
|
||||
@@ -13,13 +12,12 @@ use App\Models\SemesterScore;
|
||||
use App\Models\Student;
|
||||
use App\Models\StudentClass;
|
||||
use App\Models\TeacherClass;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Query\Builder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ReportCardService
|
||||
{
|
||||
private string $schoolYear;
|
||||
|
||||
private string $semester;
|
||||
|
||||
public function __construct()
|
||||
@@ -56,7 +54,7 @@ class ReportCardService
|
||||
->get();
|
||||
foreach ($q2->all() as $r) {
|
||||
$val = (string) ($r->school_year ?? '');
|
||||
if ($val !== '' && !in_array($val, $schoolYears, true)) {
|
||||
if ($val !== '' && ! in_array($val, $schoolYears, true)) {
|
||||
$schoolYears[] = $val;
|
||||
}
|
||||
}
|
||||
@@ -84,7 +82,7 @@ class ReportCardService
|
||||
->get();
|
||||
foreach ($rs2->all() as $r) {
|
||||
$val = (string) ($r->semester ?? '');
|
||||
if ($val !== '' && !in_array($val, $semesters, true)) {
|
||||
if ($val !== '' && ! in_array($val, $semesters, true)) {
|
||||
$semesters[] = $val;
|
||||
}
|
||||
}
|
||||
@@ -93,14 +91,14 @@ class ReportCardService
|
||||
|
||||
$defaults = array_values(array_filter([(string) ($this->semester ?? ''), 'Fall', 'Spring'], static fn ($v) => $v !== ''));
|
||||
foreach ($defaults as $d) {
|
||||
if (!in_array($d, $semesters, true)) {
|
||||
if (! in_array($d, $semesters, true)) {
|
||||
$semesters[] = $d;
|
||||
}
|
||||
}
|
||||
$semesters = array_values(array_unique($semesters));
|
||||
if ($sem === '' && !empty($semesters)) {
|
||||
if ($sem === '' && ! empty($semesters)) {
|
||||
$sem = $semesters[0];
|
||||
} elseif ($sem !== '' && !in_array($sem, $semesters, true)) {
|
||||
} elseif ($sem !== '' && ! in_array($sem, $semesters, true)) {
|
||||
array_unshift($semesters, $sem);
|
||||
$semesters = array_values(array_unique($semesters));
|
||||
}
|
||||
@@ -128,7 +126,7 @@ class ReportCardService
|
||||
->get()
|
||||
->map(fn ($r) => (array) $r)
|
||||
->all();
|
||||
if (!empty($stuRows)) {
|
||||
if (! empty($stuRows)) {
|
||||
$students = $stuRows;
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
@@ -254,7 +252,7 @@ class ReportCardService
|
||||
$students = $this->fetchStudentsByClass($sectionId, $year);
|
||||
}
|
||||
$rosterSemester = '';
|
||||
$usedFallback = !empty($students);
|
||||
$usedFallback = ! empty($students);
|
||||
}
|
||||
|
||||
if (empty($students)) {
|
||||
@@ -301,7 +299,7 @@ class ReportCardService
|
||||
$scoreByStudent = [];
|
||||
foreach ($scoreRows as $row) {
|
||||
$sid = (int) ($row['student_id'] ?? 0);
|
||||
if ($sid > 0 && !isset($scoreByStudent[$sid])) {
|
||||
if ($sid > 0 && ! isset($scoreByStudent[$sid])) {
|
||||
$scoreByStudent[$sid] = $row;
|
||||
}
|
||||
}
|
||||
@@ -326,7 +324,7 @@ class ReportCardService
|
||||
->all();
|
||||
foreach ($otherRows as $row) {
|
||||
$sid = (int) ($row['student_id'] ?? 0);
|
||||
if ($sid > 0 && !isset($firstScoreByStudent[$sid])) {
|
||||
if ($sid > 0 && ! isset($firstScoreByStudent[$sid])) {
|
||||
$firstScoreByStudent[$sid] = $row;
|
||||
}
|
||||
}
|
||||
@@ -389,7 +387,7 @@ class ReportCardService
|
||||
->all();
|
||||
foreach ($ackRows as $row) {
|
||||
$sid = (int) ($row['student_id'] ?? 0);
|
||||
if ($sid > 0 && !isset($ackMap[$sid])) {
|
||||
if ($sid > 0 && ! isset($ackMap[$sid])) {
|
||||
$ackMap[$sid] = $row;
|
||||
}
|
||||
}
|
||||
@@ -402,7 +400,7 @@ class ReportCardService
|
||||
$warningCount = 0;
|
||||
foreach ($students as $student) {
|
||||
$sid = (int) ($student['id'] ?? 0);
|
||||
$name = trim(((string) ($student['firstname'] ?? '')) . ' ' . ((string) ($student['lastname'] ?? '')));
|
||||
$name = trim(((string) ($student['firstname'] ?? '')).' '.((string) ($student['lastname'] ?? '')));
|
||||
$missing = [];
|
||||
$warnings = [];
|
||||
|
||||
@@ -417,7 +415,7 @@ class ReportCardService
|
||||
$semesterScore = null;
|
||||
$hasAllComponents = false;
|
||||
|
||||
if (!$score) {
|
||||
if (! $score) {
|
||||
$missing[] = 'Score record';
|
||||
} else {
|
||||
$attendanceScore = $score['attendance_score'] ?? null;
|
||||
@@ -430,11 +428,11 @@ class ReportCardService
|
||||
$score['project_avg'] ?? null,
|
||||
$score['test_avg'] ?? null,
|
||||
];
|
||||
$hasAllComponents = !in_array(false, array_map($isNumeric, $components), true);
|
||||
$hasAllComponents = ! in_array(false, array_map($isNumeric, $components), true);
|
||||
|
||||
if ($isSecond) {
|
||||
$examScore = $score['final_exam_score'] ?? null;
|
||||
if (!$isNumeric($examScore) && $isNumeric($score['midterm_exam_score'] ?? null)) {
|
||||
if (! $isNumeric($examScore) && $isNumeric($score['midterm_exam_score'] ?? null)) {
|
||||
$examScore = $score['midterm_exam_score'];
|
||||
$warnings[] = 'Final exam stored as midterm';
|
||||
}
|
||||
@@ -444,13 +442,13 @@ class ReportCardService
|
||||
$examScore = $score['final_exam_score'] ?? ($score['midterm_exam_score'] ?? null);
|
||||
}
|
||||
|
||||
if (!$isNumeric($examScore)) {
|
||||
if (! $isNumeric($examScore)) {
|
||||
$missing[] = $isSecond ? 'Final exam score' : ($isFirst ? 'Midterm exam score' : 'Exam score');
|
||||
}
|
||||
if (!$isNumeric($attendanceScore)) {
|
||||
if (! $isNumeric($attendanceScore)) {
|
||||
$missing[] = 'Attendance score';
|
||||
}
|
||||
if (!$isNumeric($ptapScore)) {
|
||||
if (! $isNumeric($ptapScore)) {
|
||||
if ($hasAllComponents) {
|
||||
$warnings[] = 'PTAP computed from components';
|
||||
} else {
|
||||
@@ -459,7 +457,7 @@ class ReportCardService
|
||||
}
|
||||
|
||||
$canComputeSemester = $isNumeric($examScore) && $isNumeric($attendanceScore) && ($isNumeric($ptapScore) || $hasAllComponents);
|
||||
if (!$isNumeric($semesterScore)) {
|
||||
if (! $isNumeric($semesterScore)) {
|
||||
if ($canComputeSemester) {
|
||||
$warnings[] = 'Semester score computed';
|
||||
} else {
|
||||
@@ -469,7 +467,7 @@ class ReportCardService
|
||||
|
||||
if ($isSecond) {
|
||||
$firstScore = $firstScoreByStudent[$sid]['semester_score'] ?? null;
|
||||
if (!$isNumeric($firstScore)) {
|
||||
if (! $isNumeric($firstScore)) {
|
||||
$missing[] = 'First semester score';
|
||||
}
|
||||
}
|
||||
@@ -482,7 +480,7 @@ class ReportCardService
|
||||
? ($commentSet[$commentKey] ?? '')
|
||||
: ($commentSet['final'] ?? ($commentSet['midterm'] ?? ''));
|
||||
if (trim((string) $examComment) === '') {
|
||||
$missing[] = $commentLabel . ' comment';
|
||||
$missing[] = $commentLabel.' comment';
|
||||
}
|
||||
if (trim((string) ($commentSet['ptap'] ?? '')) === '') {
|
||||
$missing[] = 'PTAP comment';
|
||||
@@ -495,7 +493,7 @@ class ReportCardService
|
||||
if ($isComplete) {
|
||||
$completeCount++;
|
||||
}
|
||||
if (!empty($warnings)) {
|
||||
if (! empty($warnings)) {
|
||||
$warningCount++;
|
||||
}
|
||||
|
||||
@@ -564,7 +562,7 @@ class ReportCardService
|
||||
$reportDate = $this->sanitizeReportDate((string) ($params['report_date'] ?? ''));
|
||||
$data = $this->prepareStudentReportData($studentId, $schoolYear, $semester);
|
||||
|
||||
if (!$data) {
|
||||
if (! $data) {
|
||||
return ['ok' => false, 'message' => 'Student not found or missing scores.'];
|
||||
}
|
||||
|
||||
@@ -574,7 +572,7 @@ class ReportCardService
|
||||
$pdf = new \FPDF('P', 'mm', 'Letter');
|
||||
$this->formatReportPDF($pdf, $data);
|
||||
|
||||
$filename = 'ReportCard_' . ($data['student']['lastname'] ?? 'student') . '.pdf';
|
||||
$filename = 'ReportCard_'.($data['student']['lastname'] ?? 'student').'.pdf';
|
||||
|
||||
$pdfContent = $pdf->Output('S');
|
||||
|
||||
@@ -596,10 +594,10 @@ class ReportCardService
|
||||
->join('students as s', 's.id', '=', 'semester_scores.student_id')
|
||||
->where('s.is_active', 1)
|
||||
->where('semester_scores.class_section_id', $classSectionId);
|
||||
if (!empty($schoolYear)) {
|
||||
if (! empty($schoolYear)) {
|
||||
$q->where('semester_scores.school_year', $schoolYear);
|
||||
}
|
||||
if (!empty($semester)) {
|
||||
if (! empty($semester)) {
|
||||
$this->applySemesterFilter($q, $semester, 'semester_scores.semester');
|
||||
}
|
||||
$scores = $q
|
||||
@@ -609,7 +607,7 @@ class ReportCardService
|
||||
->map(fn ($r) => $r->toArray())
|
||||
->all();
|
||||
|
||||
if (!$scores) {
|
||||
if (! $scores) {
|
||||
return ['ok' => false, 'message' => 'No students found for this class section.'];
|
||||
}
|
||||
|
||||
@@ -625,7 +623,7 @@ class ReportCardService
|
||||
}
|
||||
}
|
||||
|
||||
$filename = 'ClassReport_Section_' . $classSectionId . '.pdf';
|
||||
$filename = 'ClassReport_Section_'.$classSectionId.'.pdf';
|
||||
$pdfContent = $pdf->Output('S');
|
||||
|
||||
return [
|
||||
@@ -667,7 +665,7 @@ class ReportCardService
|
||||
->orderBy('s.firstname', 'ASC')
|
||||
->orderBy('s.lastname', 'ASC');
|
||||
|
||||
if (!empty($schoolYear)) {
|
||||
if (! empty($schoolYear)) {
|
||||
$query->where('student_class.school_year', $schoolYear);
|
||||
}
|
||||
|
||||
@@ -683,6 +681,7 @@ class ReportCardService
|
||||
if ($s === 'spring' || $s === 'second' || str_contains($s, 'spring') || str_contains($s, '2')) {
|
||||
return 'spring';
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
@@ -709,7 +708,7 @@ class ReportCardService
|
||||
private function applySemesterFilter($builder, ?string $semester, string $field = 'semester'): void
|
||||
{
|
||||
$vals = $this->semesterVariants($semester);
|
||||
if (!empty($vals)) {
|
||||
if (! empty($vals)) {
|
||||
$builder->whereIn($field, $vals);
|
||||
}
|
||||
}
|
||||
@@ -717,7 +716,7 @@ class ReportCardService
|
||||
private function applySemesterExclusion($builder, ?string $semester, string $field = 'semester'): void
|
||||
{
|
||||
$vals = $this->semesterVariants($semester);
|
||||
if (!empty($vals)) {
|
||||
if (! empty($vals)) {
|
||||
$builder->whereNotIn($field, $vals);
|
||||
}
|
||||
}
|
||||
@@ -761,6 +760,7 @@ class ReportCardService
|
||||
if ($weekday === 0) {
|
||||
return $now->format('Y-m-d');
|
||||
}
|
||||
|
||||
return $now->modify('next sunday')->format('Y-m-d');
|
||||
}
|
||||
|
||||
@@ -788,13 +788,14 @@ class ReportCardService
|
||||
$sundays[] = $cursor->format('Y-m-d');
|
||||
$cursor = $cursor->modify('+7 days');
|
||||
}
|
||||
|
||||
return $sundays;
|
||||
}
|
||||
|
||||
private function prepareStudentReportData(int $studentId, ?string $schoolYear = null, ?string $semester = null)
|
||||
{
|
||||
$student = Student::query()->find($studentId);
|
||||
if (!$student || (int) ($student->is_active ?? 1) !== 1) {
|
||||
if (! $student || (int) ($student->is_active ?? 1) !== 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -815,7 +816,7 @@ class ReportCardService
|
||||
$this->applySemesterFilter($qb, $refSemester, 'semester');
|
||||
}
|
||||
$score = $qb->orderBy('updated_at', 'DESC')->orderBy('id', 'DESC')->first();
|
||||
if (!$score) {
|
||||
if (! $score) {
|
||||
return null;
|
||||
}
|
||||
$score = $score->toArray();
|
||||
@@ -845,7 +846,7 @@ class ReportCardService
|
||||
}
|
||||
}
|
||||
|
||||
if (!$sectionId || $sectionCode <= 0) {
|
||||
if (! $sectionId || $sectionCode <= 0) {
|
||||
try {
|
||||
$scRow = DB::table('student_class')
|
||||
->select('class_section_id')
|
||||
@@ -854,7 +855,7 @@ class ReportCardService
|
||||
->orderByRaw('COALESCE(updated_at, created_at) DESC')
|
||||
->limit(1)
|
||||
->first();
|
||||
if (!empty($scRow->class_section_id)) {
|
||||
if (! empty($scRow->class_section_id)) {
|
||||
$sectionCode = (int) $scRow->class_section_id;
|
||||
$row = DB::table('classSection')
|
||||
->select('id')
|
||||
@@ -887,7 +888,7 @@ class ReportCardService
|
||||
if (empty($taNames)) {
|
||||
$taNames = $names['ta_names'];
|
||||
}
|
||||
if (empty($teacherNamesList) && !empty($names['teacher_names'])) {
|
||||
if (empty($teacherNamesList) && ! empty($names['teacher_names'])) {
|
||||
$teacherNamesList = $names['teacher_names'];
|
||||
}
|
||||
}
|
||||
@@ -915,22 +916,22 @@ class ReportCardService
|
||||
if ($commentVal === '') {
|
||||
continue;
|
||||
}
|
||||
if (!isset($commentMap[$typeRaw])) {
|
||||
if (! isset($commentMap[$typeRaw])) {
|
||||
$commentMap[$typeRaw] = $commentVal;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($commentMap['attendance']) && !isset($score['attendance_comment'])) {
|
||||
if (isset($commentMap['attendance']) && ! isset($score['attendance_comment'])) {
|
||||
$score['attendance_comment'] = $commentMap['attendance'];
|
||||
}
|
||||
|
||||
$att = $score['attendance_score'] ?? null;
|
||||
$attendanceCommentVal = $commentMap['attendance'] ?? $score['attendance_comment'] ?? null;
|
||||
if ((!is_string($attendanceCommentVal) || trim($attendanceCommentVal) === '') && is_numeric($att) && function_exists('attendance_comment_from_score')) {
|
||||
if ((! is_string($attendanceCommentVal) || trim($attendanceCommentVal) === '') && is_numeric($att) && function_exists('attendance_comment_from_score')) {
|
||||
$autoAttendance = attendance_comment_from_score((float) $att, (string) ($student->firstname ?? ''));
|
||||
if (is_string($autoAttendance) && $autoAttendance !== '') {
|
||||
$commentMap['attendance'] = $autoAttendance;
|
||||
if (!isset($score['attendance_comment'])) {
|
||||
if (! isset($score['attendance_comment'])) {
|
||||
$score['attendance_comment'] = $autoAttendance;
|
||||
}
|
||||
}
|
||||
@@ -942,7 +943,7 @@ class ReportCardService
|
||||
if ($normSemester !== '') {
|
||||
$events = Calendar::getEventsBySchoolYearAndSemester($refYear, $normSemester);
|
||||
$dates = array_values(array_filter(array_map(static fn ($r) => (string) ($r['date'] ?? ''), $events)));
|
||||
if (!empty($dates)) {
|
||||
if (! empty($dates)) {
|
||||
$start = min($dates);
|
||||
$end = max($dates);
|
||||
$sundays = $this->listSundays($start, $end);
|
||||
@@ -967,7 +968,7 @@ class ReportCardService
|
||||
static fn ($r) => isset($r['total_attendance']) ? (int) $r['total_attendance'] : null,
|
||||
$attRows
|
||||
), static fn ($v) => $v !== null));
|
||||
if (!empty($vals)) {
|
||||
if (! empty($vals)) {
|
||||
$totalSemesterDays = max($vals);
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
@@ -1024,7 +1025,8 @@ class ReportCardService
|
||||
$withPrefix = static function (array $row): string {
|
||||
$first = trim((string) ($row['firstname'] ?? ''));
|
||||
$last = trim((string) ($row['lastname'] ?? ''));
|
||||
$name = trim($last . ', ' . $first, ' ,');
|
||||
$name = trim($last.', '.$first, ' ,');
|
||||
|
||||
return $name !== '' ? $name : 'N/A';
|
||||
};
|
||||
$normalizePos = static function (?string $pos): string {
|
||||
@@ -1032,6 +1034,7 @@ class ReportCardService
|
||||
if ($pos === 'ta' || $pos === 'assistant') {
|
||||
return 'ta';
|
||||
}
|
||||
|
||||
return 'main';
|
||||
};
|
||||
|
||||
@@ -1065,7 +1068,7 @@ class ReportCardService
|
||||
|
||||
$ids = [$sectionIdOrCode];
|
||||
$rows = $runner($ids, (string) $schoolYear, (string) $semester);
|
||||
if (!empty($rows)) {
|
||||
if (! empty($rows)) {
|
||||
$consume($rows);
|
||||
}
|
||||
|
||||
@@ -1120,6 +1123,7 @@ class ReportCardService
|
||||
if (is_numeric($val)) {
|
||||
return number_format((float) $val, 1);
|
||||
}
|
||||
|
||||
return (string) $val;
|
||||
};
|
||||
$splitText = static function ($text, int $limit = 55): array {
|
||||
@@ -1129,6 +1133,7 @@ class ReportCardService
|
||||
}
|
||||
$lines = explode("\n", wordwrap($text, $limit));
|
||||
$lines[] = '';
|
||||
|
||||
return $lines;
|
||||
};
|
||||
$drawLabeledCell = static function (\FPDF $pdf, string $label, string $value, float $width = 95) {
|
||||
@@ -1143,6 +1148,7 @@ class ReportCardService
|
||||
return $item;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
$wrapLinesToWidth = static function (\FPDF $pdf, string $text, float $width) {
|
||||
@@ -1153,18 +1159,19 @@ class ReportCardService
|
||||
if ($width <= 0) {
|
||||
return [$text];
|
||||
}
|
||||
$segments = preg_split("/\\r?\\n+/", $text);
|
||||
$segments = preg_split('/\\r?\\n+/', $text);
|
||||
$lines = [];
|
||||
foreach ($segments as $seg) {
|
||||
$seg = trim($seg);
|
||||
if ($seg === '') {
|
||||
$lines[] = ' ';
|
||||
|
||||
continue;
|
||||
}
|
||||
$words = preg_split('/\\s+/u', $seg);
|
||||
$current = '';
|
||||
foreach ($words as $word) {
|
||||
$trial = trim($current === '' ? $word : ($current . ' ' . $word));
|
||||
$trial = trim($current === '' ? $word : ($current.' '.$word));
|
||||
if ($pdf->GetStringWidth($trial) <= $width) {
|
||||
$current = $trial;
|
||||
} else {
|
||||
@@ -1178,6 +1185,7 @@ class ReportCardService
|
||||
$lines[] = $current;
|
||||
}
|
||||
}
|
||||
|
||||
return $lines;
|
||||
};
|
||||
$draw3ColumnRow = static function (\FPDF $pdf, string $label, $score, $feedback) use ($wrapLinesToWidth) {
|
||||
@@ -1235,12 +1243,13 @@ class ReportCardService
|
||||
$seg = trim($seg);
|
||||
if ($seg === '') {
|
||||
$out[] = ' ';
|
||||
|
||||
continue;
|
||||
}
|
||||
$words = preg_split('/\\s+/u', $seg);
|
||||
$current = '';
|
||||
foreach ($words as $word) {
|
||||
$trial = $current === '' ? $word : ($current . ' ' . $word);
|
||||
$trial = $current === '' ? $word : ($current.' '.$word);
|
||||
if ($pdf->GetStringWidth($trial) <= ($width - 2)) {
|
||||
$current = $trial;
|
||||
} else {
|
||||
@@ -1254,14 +1263,15 @@ class ReportCardService
|
||||
$out[] = $current;
|
||||
}
|
||||
}
|
||||
return !empty($out) ? $out : [' '];
|
||||
|
||||
return ! empty($out) ? $out : [' '];
|
||||
};
|
||||
|
||||
if ($startY !== null) {
|
||||
$pdf->SetY($startY);
|
||||
}
|
||||
foreach ($rows as $row) {
|
||||
if (!is_array($row) || count($row) < 4) {
|
||||
if (! is_array($row) || count($row) < 4) {
|
||||
continue;
|
||||
}
|
||||
[$labelLeft, $valueLeft, $labelRight, $valueRight] = $row;
|
||||
@@ -1316,6 +1326,7 @@ class ReportCardService
|
||||
$currentY += $rowHeight;
|
||||
$pdf->SetY($currentY);
|
||||
}
|
||||
|
||||
return $currentY;
|
||||
};
|
||||
|
||||
@@ -1332,7 +1343,7 @@ class ReportCardService
|
||||
}
|
||||
|
||||
$teacherNamesList = $data['teacher_names'] ?? [];
|
||||
if (empty($teacherNamesList) && !empty($data['teacher_name'])) {
|
||||
if (empty($teacherNamesList) && ! empty($data['teacher_name'])) {
|
||||
$teacherNamesList = [trim((string) $data['teacher_name'])];
|
||||
}
|
||||
$teacherNamesList = array_values(array_filter(
|
||||
@@ -1365,9 +1376,9 @@ class ReportCardService
|
||||
|
||||
$schoolYear = (string) ($data['score']['school_year'] ?? ($data['score']['year'] ?? 'N/A'));
|
||||
if (preg_match('/^(\\d{4})-(\\d{4})$/', $schoolYear, $m)) {
|
||||
$schoolYear = $m[1] . '/' . $m[2];
|
||||
$schoolYear = $m[1].'/'.$m[2];
|
||||
}
|
||||
$studentName = trim(($data['student']['firstname'] ?? '') . ' ' . ($data['student']['lastname'] ?? ''));
|
||||
$studentName = trim(($data['student']['firstname'] ?? '').' '.($data['student']['lastname'] ?? ''));
|
||||
$gradeLabel = (string) ($data['grade'] ?? ($data['class_section_name'] ?? 'N/A'));
|
||||
$today = (string) ($data['report_date_display'] ?? date('m-d-Y'));
|
||||
$firstSemScore = $data['first_semester_score'] ?? null;
|
||||
@@ -1396,9 +1407,9 @@ class ReportCardService
|
||||
};
|
||||
|
||||
$afterInfoY = $drawInfoRows($pdf, [
|
||||
["Teachers' Names: ", ' ' . ($teacherNames !== '' ? $teacherNames : 'N/A'), 'School Year: ', ' ' . $schoolYear],
|
||||
['Student Name: ', ' ' . ($studentName !== '' ? $studentName : 'N/A'), 'Grade: ', ' ' . ($gradeLabel !== '' ? $gradeLabel : 'N/A')],
|
||||
['Term: ', ' ' . $semFriendly, 'Date: ', ' ' . $today],
|
||||
["Teachers' Names: ", ' '.($teacherNames !== '' ? $teacherNames : 'N/A'), 'School Year: ', ' '.$schoolYear],
|
||||
['Student Name: ', ' '.($studentName !== '' ? $studentName : 'N/A'), 'Grade: ', ' '.($gradeLabel !== '' ? $gradeLabel : 'N/A')],
|
||||
['Term: ', ' '.$semFriendly, 'Date: ', ' '.$today],
|
||||
]);
|
||||
$pdf->SetY($afterInfoY);
|
||||
|
||||
@@ -1475,7 +1486,7 @@ class ReportCardService
|
||||
$pdf->Rect($x, $startY, $statW, $statH);
|
||||
$pdf->SetXY($x + 2, $startY + 3);
|
||||
$pdf->SetFont('Helvetica', 'B', 11);
|
||||
$pdf->Write(5, $lbl . ' ');
|
||||
$pdf->Write(5, $lbl.' ');
|
||||
$pdf->SetFont('Helvetica', '', 11);
|
||||
$pdf->Write(5, $val);
|
||||
}
|
||||
@@ -1483,7 +1494,7 @@ class ReportCardService
|
||||
|
||||
$effectiveSecond = $secondSemScore ?? $data['score']['semester_score'] ?? $data['total_score'] ?? null;
|
||||
$finalScoreVal = $finalAverage;
|
||||
if (!is_numeric($finalScoreVal)) {
|
||||
if (! is_numeric($finalScoreVal)) {
|
||||
$finalScoreVal = (is_numeric($firstSemScore) && is_numeric($effectiveSecond))
|
||||
? number_format(((float) $firstSemScore + (float) $effectiveSecond) / 2, 1)
|
||||
: $numFmt($effectiveSecond);
|
||||
@@ -1498,8 +1509,8 @@ class ReportCardService
|
||||
$pdf->Rect($x, $y, $w, $h);
|
||||
$pdf->SetXY($x + $pad, $y + 3);
|
||||
$pdf->SetFont('Helvetica', 'B', 11);
|
||||
$pdf->Write(5, $label . ' ');
|
||||
$labelWidth = $pdf->GetStringWidth($label . ' ');
|
||||
$pdf->Write(5, $label.' ');
|
||||
$labelWidth = $pdf->GetStringWidth($label.' ');
|
||||
$pdf->SetFont('Helvetica', '', 12);
|
||||
$pdf->SetXY($x + 2 + $labelWidth, $y + 3);
|
||||
$pdf->Write(5, $value);
|
||||
@@ -1507,14 +1518,14 @@ class ReportCardService
|
||||
|
||||
if ($semNum === 2) {
|
||||
$firstLabel = ' 1st Semester Grade:';
|
||||
$firstValue = $numFmt($firstSemScore) . '/100';
|
||||
$firstValue = $numFmt($firstSemScore).'/100';
|
||||
$secondLabel = ' 2nd Semester Grade:';
|
||||
$secondValue = $numFmt($effectiveSecond) . '/100';
|
||||
$secondValue = $numFmt($effectiveSecond).'/100';
|
||||
$drawGradeCell($pdf, $gradeX, $gradeY, $gradeCellWidth, $gradeCellHeight, $firstLabel, $firstValue, $gradePad);
|
||||
$drawGradeCell($pdf, $gradeX + $gradeCellWidth, $gradeY, $gradeCellWidth, $gradeCellHeight, $secondLabel, $secondValue, $gradePad);
|
||||
} else {
|
||||
$gradeLabel = ' 1st Semester Grade:';
|
||||
$gradeValue = $numFmt($effectiveSecond) . '/100';
|
||||
$gradeValue = $numFmt($effectiveSecond).'/100';
|
||||
$drawGradeCell($pdf, $gradeX, $gradeY, $gradeCellWidth, $gradeCellHeight, $gradeLabel, $gradeValue, $gradePad);
|
||||
}
|
||||
$pdf->SetY($gradeY + $gradeCellHeight);
|
||||
@@ -1523,7 +1534,7 @@ class ReportCardService
|
||||
$finalScoreEndY = null;
|
||||
if ($semNum === 2) {
|
||||
$finalLabel = 'Final Score****:';
|
||||
$finalValue = (is_string($finalScoreVal) ? $finalScoreVal : $numFmt($finalScoreVal)) . '/100';
|
||||
$finalValue = (is_string($finalScoreVal) ? $finalScoreVal : $numFmt($finalScoreVal)).'/100';
|
||||
$finalCellWidth = 65;
|
||||
$finalCellHeight = $finalScoreRowHeight;
|
||||
$finalX = $pdf->GetX();
|
||||
@@ -1532,8 +1543,8 @@ class ReportCardService
|
||||
$finalPad = max(0, 2 - (4 * 0.3528));
|
||||
$pdf->SetXY($finalX + $finalPad, $finalY + 3);
|
||||
$pdf->SetFont('Helvetica', 'B', 11);
|
||||
$pdf->Write(5, ' ' . $finalLabel . ' ');
|
||||
$finalLabelWidth = $pdf->GetStringWidth(' ' . $finalLabel . ' ');
|
||||
$pdf->Write(5, ' '.$finalLabel.' ');
|
||||
$finalLabelWidth = $pdf->GetStringWidth(' '.$finalLabel.' ');
|
||||
$pdf->SetFont('Helvetica', '', 12);
|
||||
$pdf->SetXY($finalX + 2 + $finalLabelWidth, $finalY + 3);
|
||||
$pdf->Write(5, $finalValue);
|
||||
@@ -1545,11 +1556,11 @@ class ReportCardService
|
||||
$examLegendLabel = ($semNum === 1) ? 'Midterm Exam' : 'Final Exam';
|
||||
$legendLines = [
|
||||
"(*) {$examLegendLabel} (Weight: 60% of semester score)",
|
||||
"(**) PTAP - Participation, Tests, Assignments, Projects (Weight: 20%)",
|
||||
'(**) PTAP - Participation, Tests, Assignments, Projects (Weight: 20%)',
|
||||
"(***) Attendance = ({$totalDays} - Total Absences + One Sick Day) / {$totalDays} ) x 100 (Weight: 20%)",
|
||||
];
|
||||
if ($semNum === 2) {
|
||||
$legendLines[] = "(****) Final Score = (1st Semester Score + 2nd Semester Score) / 2";
|
||||
$legendLines[] = '(****) Final Score = (1st Semester Score + 2nd Semester Score) / 2';
|
||||
}
|
||||
$legendLines[] = ['text' => 'If you have any questions, please contact the school via email at alrahma.isgl@gmail.com', 'bold' => true];
|
||||
$lineHeight = 4;
|
||||
@@ -1608,6 +1619,7 @@ class ReportCardService
|
||||
return $path;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ class SlipPrinterConfigService
|
||||
if ($userId && $userId > 0) {
|
||||
$user = User::query()->select('firstname', 'lastname')->find($userId);
|
||||
if ($user) {
|
||||
$full = trim(($user->firstname ?? '') . ' ' . ($user->lastname ?? ''));
|
||||
$full = trim(($user->firstname ?? '').' '.($user->lastname ?? ''));
|
||||
if ($full !== '') {
|
||||
return $full;
|
||||
}
|
||||
@@ -40,6 +40,7 @@ class SlipPrinterConfigService
|
||||
return $val;
|
||||
}
|
||||
}
|
||||
|
||||
return $default;
|
||||
};
|
||||
|
||||
|
||||
@@ -15,13 +15,16 @@ class SlipPrinterFormatterService
|
||||
}
|
||||
if (preg_match('/^\d{1,2}\/\d{1,2}\/\d{4}$/', $value)) {
|
||||
$dt = \DateTime::createFromFormat('!m/d/Y', $value);
|
||||
|
||||
return $dt ? $dt->format('Y-m-d') : null;
|
||||
}
|
||||
if (preg_match('/^\d{1,2}-\d{1,2}-\d{4}$/', $value)) {
|
||||
$dt = \DateTime::createFromFormat('!m-d-Y', $value);
|
||||
|
||||
return $dt ? $dt->format('Y-m-d') : null;
|
||||
}
|
||||
$ts = strtotime($value);
|
||||
|
||||
return $ts ? date('Y-m-d', $ts) : null;
|
||||
}
|
||||
|
||||
@@ -32,6 +35,7 @@ class SlipPrinterFormatterService
|
||||
return null;
|
||||
}
|
||||
$ts = strtotime($value);
|
||||
|
||||
return $ts ? date('H:i:s', $ts) : null;
|
||||
}
|
||||
|
||||
@@ -42,6 +46,7 @@ class SlipPrinterFormatterService
|
||||
return '';
|
||||
}
|
||||
$ts = strtotime($value);
|
||||
|
||||
return $ts ? date('m/d/Y', $ts) : '';
|
||||
}
|
||||
|
||||
@@ -53,8 +58,9 @@ class SlipPrinterFormatterService
|
||||
}
|
||||
$ts = strtotime($value);
|
||||
if ($ts === false) {
|
||||
$ts = strtotime('today ' . $value);
|
||||
$ts = strtotime('today '.$value);
|
||||
}
|
||||
|
||||
return $ts ? date('h:i A', $ts) : '';
|
||||
}
|
||||
|
||||
@@ -64,17 +70,19 @@ class SlipPrinterFormatterService
|
||||
if (strlen($line) > $width) {
|
||||
return substr($line, 0, $width);
|
||||
}
|
||||
return $line . str_repeat(' ', $width - strlen($line));
|
||||
|
||||
return $line.str_repeat(' ', $width - strlen($line));
|
||||
}
|
||||
|
||||
public function buildSlipLines(array $data, int $width): array
|
||||
{
|
||||
$lines = [];
|
||||
$lines[] = $this->fitLine('Student Name: ' . (string) ($data['student_name'] ?? ''), $width);
|
||||
$lines[] = $this->fitLine('Date: ' . (string) ($data['date'] ?? '') . ' Time In: ' . (string) ($data['time_in'] ?? ''), $width);
|
||||
$lines[] = $this->fitLine('Grade: ' . (string) ($data['grade'] ?? ''), $width);
|
||||
$lines[] = $this->fitLine('Reason: ' . (string) ($data['reason'] ?? ''), $width);
|
||||
$lines[] = $this->fitLine('Admin: ' . (string) ($data['admin_name'] ?? ''), $width);
|
||||
$lines[] = $this->fitLine('Student Name: '.(string) ($data['student_name'] ?? ''), $width);
|
||||
$lines[] = $this->fitLine('Date: '.(string) ($data['date'] ?? '').' Time In: '.(string) ($data['time_in'] ?? ''), $width);
|
||||
$lines[] = $this->fitLine('Grade: '.(string) ($data['grade'] ?? ''), $width);
|
||||
$lines[] = $this->fitLine('Reason: '.(string) ($data['reason'] ?? ''), $width);
|
||||
$lines[] = $this->fitLine('Admin: '.(string) ($data['admin_name'] ?? ''), $width);
|
||||
|
||||
return $lines;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,9 +8,7 @@ use Dompdf\Options;
|
||||
|
||||
class SlipPrinterPdfService
|
||||
{
|
||||
public function __construct(private SlipPrinterConfigService $configService)
|
||||
{
|
||||
}
|
||||
public function __construct(private SlipPrinterConfigService $configService) {}
|
||||
|
||||
public function render(array $data, array $lines, array $options = []): array
|
||||
{
|
||||
@@ -63,7 +61,7 @@ class SlipPrinterPdfService
|
||||
'h_mm' => $hMm,
|
||||
]);
|
||||
|
||||
$optionsObj = new Options();
|
||||
$optionsObj = new Options;
|
||||
$optionsObj->set('isRemoteEnabled', true);
|
||||
$optionsObj->set('defaultFont', 'Courier');
|
||||
|
||||
@@ -76,7 +74,7 @@ class SlipPrinterPdfService
|
||||
$dompdf->setPaper([0, 0, $wPt, $hPt]);
|
||||
$dompdf->render();
|
||||
|
||||
$filename = 'LateSlip_' . preg_replace('/[^A-Za-z0-9]+/', '_', (string) ($data['student_name'] ?? 'slip')) . '_' . date('Ymd_His') . '.pdf';
|
||||
$filename = 'LateSlip_'.preg_replace('/[^A-Za-z0-9]+/', '_', (string) ($data['student_name'] ?? 'slip')).'_'.date('Ymd_His').'.pdf';
|
||||
|
||||
return [
|
||||
'content' => $dompdf->output(),
|
||||
|
||||
@@ -10,8 +10,7 @@ class SlipPrinterService
|
||||
private SlipPrinterConfigService $configService,
|
||||
private SlipPrinterFormatterService $formatter,
|
||||
private SlipPrinterPdfService $pdfService
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
|
||||
public function print(array $input, ?int $userId): array
|
||||
{
|
||||
@@ -45,7 +44,7 @@ class SlipPrinterService
|
||||
|
||||
return [
|
||||
'ok' => true,
|
||||
'text' => $header . $body . $footer,
|
||||
'text' => $header.$body.$footer,
|
||||
'width' => $width,
|
||||
];
|
||||
}
|
||||
@@ -97,7 +96,7 @@ class SlipPrinterService
|
||||
public function reprint(int $id, ?int $userId): array
|
||||
{
|
||||
$row = LateSlipLog::query()->find($id);
|
||||
if (!$row) {
|
||||
if (! $row) {
|
||||
return ['ok' => false, 'message' => 'Slip not found.'];
|
||||
}
|
||||
|
||||
@@ -173,6 +172,7 @@ class SlipPrinterService
|
||||
{
|
||||
$cfg = $this->configService->printerConfig();
|
||||
$width = (int) ($cfg['chars_per_line'] ?? 48);
|
||||
|
||||
return $width > 0 ? $width : 48;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,9 +14,10 @@ class StickerPresetService
|
||||
];
|
||||
|
||||
return array_map(static function (array $row): array {
|
||||
$row['title'] = $row['title'] ?? ($row['label'] ?? ($row['value'] . ' mm'));
|
||||
$row['title'] = $row['title'] ?? ($row['label'] ?? ($row['value'].' mm'));
|
||||
$row['text'] = $row['text'] ?? $row['title'];
|
||||
$row['per_page'] = $row['per_page'] ?? ($row['ppg'] ?? null);
|
||||
|
||||
return $row;
|
||||
}, $rows);
|
||||
}
|
||||
|
||||
@@ -6,9 +6,7 @@ use Illuminate\Support\Facades\Log;
|
||||
|
||||
class StickerPrintService
|
||||
{
|
||||
public function __construct(private StickerQueryService $queryService)
|
||||
{
|
||||
}
|
||||
public function __construct(private StickerQueryService $queryService) {}
|
||||
|
||||
public function generate(array $payload): array
|
||||
{
|
||||
@@ -23,7 +21,7 @@ class StickerPrintService
|
||||
|
||||
if ($studentId > 0) {
|
||||
$student = $this->queryService->findStudent($studentId);
|
||||
if (!$student) {
|
||||
if (! $student) {
|
||||
return ['ok' => false, 'message' => 'Student not found.'];
|
||||
}
|
||||
$students = [$student];
|
||||
@@ -102,7 +100,7 @@ class StickerPrintService
|
||||
$minPt = 8;
|
||||
$hPad = 2;
|
||||
|
||||
$fullName = trim(($student['firstname'] ?? '') . ' ' . ($student['lastname'] ?? '')) ?: 'Student';
|
||||
$fullName = trim(($student['firstname'] ?? '').' '.($student['lastname'] ?? '')) ?: 'Student';
|
||||
|
||||
$bestPt = $maxPt;
|
||||
$textW = 0.0;
|
||||
@@ -158,6 +156,7 @@ class StickerPrintService
|
||||
for ($k = 0; $k < $qty; $k++) {
|
||||
$printList[] = $students[0];
|
||||
}
|
||||
|
||||
return $printList;
|
||||
}
|
||||
|
||||
@@ -221,19 +220,19 @@ class StickerPrintService
|
||||
|| (abs($stickerWidth - 100.0) < 0.6 && abs($stickerHeight - 24.5) < 0.6);
|
||||
|
||||
if ($isXSmallPreset) {
|
||||
if (!$marginLeftProvided) {
|
||||
if (! $marginLeftProvided) {
|
||||
$marginLeft = 4.0;
|
||||
if (!$marginRightProvided) {
|
||||
if (! $marginRightProvided) {
|
||||
$marginRight = 4.0;
|
||||
}
|
||||
}
|
||||
if (!$marginRightProvided && $marginRight < 4.0) {
|
||||
if (! $marginRightProvided && $marginRight < 4.0) {
|
||||
$marginRight = 4.0;
|
||||
}
|
||||
if (!$gapXProvided) {
|
||||
if (! $gapXProvided) {
|
||||
$gapX = 0.0;
|
||||
}
|
||||
if (!$gapYProvided) {
|
||||
if (! $gapYProvided) {
|
||||
$gapY = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,9 +6,7 @@ use Illuminate\Support\Facades\DB;
|
||||
|
||||
class StickerQueryService
|
||||
{
|
||||
public function __construct(private StickerContextService $context)
|
||||
{
|
||||
}
|
||||
public function __construct(private StickerContextService $context) {}
|
||||
|
||||
public function resolveSchoolYear(?string $schoolYear): string
|
||||
{
|
||||
@@ -108,7 +106,8 @@ class StickerQueryService
|
||||
if ($sectionName === '') {
|
||||
return false;
|
||||
}
|
||||
return !preg_match('/^(youth|kg)(?:\b|-)/i', $sectionName);
|
||||
|
||||
return ! preg_match('/^(youth|kg)(?:\b|-)/i', $sectionName);
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user