add tests batch 20

This commit is contained in:
root
2026-06-09 01:03:53 -04:00
parent 95efb9652e
commit 6be4875c5e
1502 changed files with 13797 additions and 11313 deletions
+14 -20
View File
@@ -2,6 +2,7 @@
namespace App\Models;
use App\Models\BaseModel;
use Illuminate\Support\Facades\DB;
class AttendanceRecord extends BaseModel
@@ -27,14 +28,14 @@ class AttendanceRecord extends BaseModel
];
protected $casts = [
'class_section_id' => 'integer',
'student_id' => 'integer',
'school_id' => 'integer',
'total_absence' => 'integer',
'total_late' => 'integer',
'total_presence' => 'integer',
'total_attendance' => 'integer',
'modified_by' => 'integer',
'class_section_id' => 'integer',
'student_id' => 'integer',
'school_id' => 'integer',
'total_absence' => 'integer',
'total_late' => 'integer',
'total_presence' => 'integer',
'total_attendance' => 'integer',
'modified_by' => 'integer',
];
/* =========================
@@ -85,7 +86,6 @@ class AttendanceRecord extends BaseModel
public static function updateAttendanceRecord(int $attendanceId, array $data): bool
{
$affected = static::query()->whereKey($attendanceId)->update($data);
return $affected >= 0;
}
@@ -101,26 +101,20 @@ class AttendanceRecord extends BaseModel
string $schoolYear,
array $increments
): bool {
$allowed = ['total_absence', 'total_late', 'total_presence', 'total_attendance'];
$allowed = ['total_absence','total_late','total_presence','total_attendance'];
$inc = array_intersect_key($increments, array_flip($allowed));
if (empty($inc)) {
return true;
}
if (empty($inc)) return true;
// Build atomic update: field = field + X
$update = [];
foreach ($inc as $field => $value) {
$value = (int) $value;
if ($value === 0) {
continue;
}
if ($value === 0) continue;
$update[$field] = DB::raw("COALESCE($field,0) + {$value}");
}
if (empty($update)) {
return true;
}
if (empty($update)) return true;
$affected = static::query()
->where('student_id', $studentId)
@@ -145,4 +139,4 @@ class AttendanceRecord extends BaseModel
->where('school_year', $schoolYear)
->sum('total_absence');
}
}
}