apply the school year concept
Tests / PHPUnit (push) Failing after 1m19s

This commit is contained in:
root
2026-07-14 00:59:00 -04:00
parent 504c3bc9f9
commit feb1b29a32
73 changed files with 4288 additions and 620 deletions
@@ -1235,6 +1235,10 @@ public function updateBatchAssignment()
$status = $this->request->getGet('status') ?: null;
$filterYear = $this->request->getGet('school_year') ?: $this->schoolYear;
$userId = $this->request->getGet('user_id') ?: null;
$hasBatchSchoolYear = $this->db->fieldExists('school_year', 'reimbursement_batches');
$hasExpenseSchoolYear = $this->db->fieldExists('school_year', 'expenses');
$hasExpenseSemester = $this->db->fieldExists('semester', 'expenses');
$hasReimbursementSchoolYear = $this->db->fieldExists('school_year', 'reimbursements');
$filters = [
'school_year' => $filterYear,
@@ -1251,13 +1255,11 @@ public function updateBatchAssignment()
// Build closed batch summaries/details (all closed batches)
$batchSummaries = [];
$batchDetails = [];
$batchQuery = $this->db->table('reimbursement_batches b')
->select("
$batchSelect = "
b.id AS batch_id,
b.title AS batch_title,
b.yearly_batch_number,
b.closed_at,
b.school_year AS batch_school_year,
e.id AS expense_id,
e.amount AS expense_amount,
e.description,
@@ -1268,7 +1270,13 @@ public function updateBatchAssignment()
u.firstname AS purchaser_firstname,
u.lastname AS purchaser_lastname,
r.amount AS reimb_amount
")
";
if ($hasBatchSchoolYear) {
$batchSelect .= ', b.school_year AS batch_school_year';
}
$batchQuery = $this->db->table('reimbursement_batches b')
->select($batchSelect)
->join('reimbursement_batch_items bi', 'bi.batch_id = b.id', 'inner')
->join('expenses e', 'e.id = bi.expense_id', 'inner')
->join('users u', 'u.id = e.purchased_by', 'left')
@@ -1277,10 +1285,16 @@ public function updateBatchAssignment()
->where('bi.unassigned_at IS NULL', null, false);
if (!empty($filterYear)) {
$batchQuery->groupStart()
->where('b.school_year', $filterYear)
->orWhere('e.school_year', $filterYear)
->groupEnd();
if ($hasBatchSchoolYear && $hasExpenseSchoolYear) {
$batchQuery->groupStart()
->where('b.school_year', $filterYear)
->orWhere('e.school_year', $filterYear)
->groupEnd();
} elseif ($hasBatchSchoolYear) {
$batchQuery->where('b.school_year', $filterYear);
} elseif ($hasExpenseSchoolYear) {
$batchQuery->where('e.school_year', $filterYear);
}
}
if (!empty($userId)) {
$batchQuery->where('e.purchased_by', $userId);
@@ -1401,27 +1415,33 @@ public function updateBatchAssignment()
'items' => [],
'checks' => [],
];
$donationQuery = $this->db->table('expenses e')
->select('
$donationSelect = '
e.id AS expense_id,
e.amount AS expense_amount,
e.description,
e.retailor,
e.receipt_path AS expense_receipt,
e.purchased_by,
e.school_year,
e.semester,
e.status,
u.firstname AS purchaser_firstname,
u.lastname AS purchaser_lastname
')
';
if ($hasExpenseSchoolYear) {
$donationSelect .= ', e.school_year';
}
if ($hasExpenseSemester) {
$donationSelect .= ', e.semester';
}
$donationQuery = $this->db->table('expenses e')
->select($donationSelect)
->join('users u', 'u.id = e.purchased_by', 'left')
->where('e.category', 'Donation');
if (!empty($filterYear)) {
if (!empty($filterYear) && $hasExpenseSchoolYear) {
$donationQuery->where('e.school_year', $filterYear);
}
if (!empty($semester)) {
if (!empty($semester) && $hasExpenseSemester) {
$donationQuery->where('e.semester', $semester);
}
if (!empty($userId)) {
@@ -1488,13 +1508,25 @@ public function updateBatchAssignment()
$users = $this->recipientOptions();
$years = $this->db->table('reimbursements')
->select('school_year')
->distinct()
->orderBy('school_year', 'DESC')
->get()
->getResultArray();
$schoolYears = array_column($years, 'school_year');
$schoolYears = [];
if ($hasReimbursementSchoolYear) {
$years = $this->db->table('reimbursements')
->select('school_year')
->distinct()
->orderBy('school_year', 'DESC')
->get()
->getResultArray();
$schoolYears = array_column($years, 'school_year');
} elseif ($hasExpenseSchoolYear) {
$years = $this->db->table('expenses')
->select('school_year')
->distinct()
->where('school_year IS NOT NULL', null, false)
->orderBy('school_year', 'DESC')
->get()
->getResultArray();
$schoolYears = array_column($years, 'school_year');
}
// Add school years from fallback expenses (closed batches without reimbursements)
if (!empty($fallbackRows)) {