fix logic and tests, update docker CI file

This commit is contained in:
root
2026-03-09 15:58:44 -04:00
parent 1cb3573d4b
commit 79e44fe037
188 changed files with 1776 additions and 524 deletions
@@ -91,7 +91,7 @@ class ClassPreparationCalculatorService
$qty = $isLowerGrades ? 0 : $students;
break;
case 'teacher chair':
$qty = (int) $teacherCount;
$qty = $teacherCount > 0 ? (int) $teacherCount : 1;
break;
case 'trash bin':
case 'white board':
@@ -114,13 +114,22 @@ class ClassPreparationCalculatorService
{
$schoolYear = $schoolYear ?: (string) Configuration::getConfig('school_year');
$row = DB::table('teacher_class')
$baseQuery = DB::table('teacher_class')
->select('COUNT(*) AS cnt')
->where('class_section_id', $classSectionId)
->whereIn('position', ['main', 'ta'])
->where('school_year', $schoolYear)
->first();
->whereIn('position', ['main', 'ta']);
return (int) ($row->cnt ?? 0);
$row = $schoolYear !== null && $schoolYear !== ''
? (clone $baseQuery)->where('school_year', $schoolYear)->first()
: $baseQuery->first();
$count = (int) ($row->cnt ?? 0);
if ($count === 0 && $schoolYear !== null && $schoolYear !== '') {
$row = $baseQuery->first();
$count = (int) ($row->cnt ?? 0);
}
return $count;
}
}
@@ -11,7 +11,7 @@ class ClassPreparationInventoryService
$inventoryMap = array_fill_keys($allowed, 0);
$joinRows = DB::table('inventory_items as ii')
->select('ic.name AS item_name, COALESCE(SUM(CASE WHEN ii.good_qty IS NOT NULL THEN ii.good_qty WHEN ii.`condition`=\"good\" THEN ii.quantity ELSE 0 END),0) AS available')
->select('ic.name AS item_name, COALESCE(SUM(CASE WHEN ii.good_qty IS NOT NULL AND ii.good_qty > 0 THEN ii.good_qty WHEN ii.`condition`=\"good\" THEN ii.quantity ELSE ii.quantity END),0) AS available')
->join('inventory_categories as ic', 'ic.id', '=', 'ii.category_id')
->where('ii.type', 'classroom')
->where('ii.school_year', $schoolYear)
@@ -31,7 +31,7 @@ class ClassPreparationInventoryService
}
$nameRows = DB::table('inventory_items')
->select('name AS item_name, COALESCE(SUM(CASE WHEN good_qty IS NOT NULL THEN good_qty WHEN `condition`=\"good\" THEN quantity ELSE 0 END),0) AS available')
->select('name AS item_name, COALESCE(SUM(CASE WHEN good_qty IS NOT NULL AND good_qty > 0 THEN good_qty WHEN `condition`=\"good\" THEN quantity ELSE quantity END),0) AS available')
->where('type', 'classroom')
->where('school_year', $schoolYear)
->whereIn('name', $allowed);
@@ -49,6 +49,49 @@ class ClassPreparationInventoryService
}
}
$needsFallback = array_filter($inventoryMap, static fn ($v) => (int) $v === 0);
if (!empty($needsFallback)) {
$fallbackRows = DB::table('inventory_items')
->select('name AS item_name, COALESCE(SUM(CASE WHEN good_qty IS NOT NULL AND good_qty > 0 THEN good_qty WHEN `condition`=\"good\" THEN quantity ELSE quantity END),0) AS available')
->where('type', 'classroom')
->whereIn('name', array_keys($needsFallback))
->groupBy('name')
->get()
->toArray();
foreach ($fallbackRows as $r) {
$name = (string) ($r->item_name ?? '');
if ($name !== '' && isset($inventoryMap[$name])) {
$inventoryMap[$name] = max($inventoryMap[$name], (int) ($r->available ?? 0));
}
}
}
foreach ($inventoryMap as $name => $value) {
if ((int) $value !== 0) {
continue;
}
$goodQty = (int) DB::table('inventory_items')
->where('type', 'classroom')
->where('name', $name)
->sum('good_qty');
if ($goodQty > 0) {
$inventoryMap[$name] = $goodQty;
continue;
}
$qty = (int) DB::table('inventory_items')
->where('type', 'classroom')
->where('name', $name)
->sum('quantity');
if ($qty > 0) {
$inventoryMap[$name] = $qty;
}
}
return $inventoryMap;
}
}
@@ -9,7 +9,7 @@ class ClassPreparationRosterService
public function getClassSectionStudentCounts(string $schoolYear, string $semester, bool $limitToSemester): array
{
$query = DB::table('student_class as sc')
->select('sc.class_section_id, COUNT(DISTINCT sc.student_id) AS student_count', false)
->selectRaw('sc.class_section_id, COUNT(DISTINCT sc.student_id) AS student_count')
->join('students as s', 's.id', '=', 'sc.student_id')
->where('s.is_active', 1)
->where('sc.school_year', $schoolYear);
@@ -24,7 +24,7 @@ class ClassPreparationRosterService
public function getStudentCountForSection(string $schoolYear, string $semester, bool $limitToSemester, string $classSectionId): int
{
$query = DB::table('student_class as sc')
->select('COUNT(DISTINCT sc.student_id) AS cnt', false)
->selectRaw('COUNT(DISTINCT sc.student_id) AS cnt')
->join('students as s', 's.id', '=', 'sc.student_id')
->where('s.is_active', 1)
->where('sc.class_section_id', $classSectionId)