fix enrollment logic, add financial aid, fix class distribution
Tests / PHPUnit (push) Failing after 1m6s
Tests / PHPUnit (push) Failing after 1m6s
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Administrator;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
use App\Models\FinancialAidRequestModel;
|
||||
use App\Models\StudentModel;
|
||||
use App\Models\UserModel;
|
||||
use Throwable;
|
||||
|
||||
class FinancialAidController extends BaseController
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$schoolYear = $this->request->getGet('school_year');
|
||||
$model = new FinancialAidRequestModel();
|
||||
$builder = $model->orderBy('created_at', 'DESC');
|
||||
if (is_string($schoolYear) && trim($schoolYear) !== '') {
|
||||
$builder->where('school_year', trim($schoolYear));
|
||||
}
|
||||
|
||||
$requests = $builder->findAll();
|
||||
$parentIds = array_values(array_unique(array_filter(array_map('intval', array_column($requests, 'parent_id')))));
|
||||
$parents = [];
|
||||
if ($parentIds !== []) {
|
||||
foreach ((new UserModel())->select('id, firstname, lastname, email')->whereIn('id', $parentIds)->findAll() as $parent) {
|
||||
$parents[(int) $parent['id']] = $parent;
|
||||
}
|
||||
}
|
||||
|
||||
return view('administrator/financial_aid_queue', [
|
||||
'requests' => $requests,
|
||||
'parents' => $parents,
|
||||
'schoolYear' => is_string($schoolYear) ? trim($schoolYear) : '',
|
||||
]);
|
||||
}
|
||||
|
||||
public function show(int $id)
|
||||
{
|
||||
$request = (new FinancialAidRequestModel())->find($id);
|
||||
if ($request === null) {
|
||||
return redirect()->to('/administrator/financial-aid')->with('error', 'Financial aid request was not found.');
|
||||
}
|
||||
|
||||
$parent = (new UserModel())->find((int) $request['parent_id']);
|
||||
$studentIds = json_decode((string) ($request['student_ids_json'] ?? '[]'), true);
|
||||
$studentIds = is_array($studentIds) ? array_map('intval', $studentIds) : [];
|
||||
$students = $studentIds !== []
|
||||
? (new StudentModel())->whereIn('id', $studentIds)->findAll()
|
||||
: [];
|
||||
|
||||
return view('administrator/financial_aid_review', [
|
||||
'requestRow' => $request,
|
||||
'parent' => $parent,
|
||||
'students' => $students,
|
||||
]);
|
||||
}
|
||||
|
||||
public function approve(int $id)
|
||||
{
|
||||
try {
|
||||
$model = new FinancialAidRequestModel();
|
||||
$request = $model->find($id);
|
||||
if ($request === null) {
|
||||
return redirect()->to('/administrator/financial-aid')->with('error', 'Financial aid request was not found.');
|
||||
}
|
||||
if (! in_array((string) ($request['status'] ?? ''), ['submitted', 'under_review'], true)) {
|
||||
return redirect()->back()->with('error', 'Only open requests can be approved.');
|
||||
}
|
||||
|
||||
$amount = (float) $this->request->getPost('admin_amount');
|
||||
$note = trim((string) $this->request->getPost('admin_note'));
|
||||
service('financialAid')->applyApprovedAmount($request, $amount, (int) session()->get('user_id'), $note);
|
||||
|
||||
return redirect()->to('/administrator/financial-aid')->with('success', 'Financial aid was approved and applied to the invoice.');
|
||||
} catch (Throwable $e) {
|
||||
return redirect()->back()->withInput()->with('error', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function deny(int $id)
|
||||
{
|
||||
$model = new FinancialAidRequestModel();
|
||||
$request = $model->find($id);
|
||||
if ($request === null) {
|
||||
return redirect()->to('/administrator/financial-aid')->with('error', 'Financial aid request was not found.');
|
||||
}
|
||||
if (! in_array((string) ($request['status'] ?? ''), ['submitted', 'under_review'], true)) {
|
||||
return redirect()->back()->with('error', 'Only open requests can be denied.');
|
||||
}
|
||||
|
||||
$note = trim((string) $this->request->getPost('admin_note'));
|
||||
if ($note === '') {
|
||||
return redirect()->back()->with('error', 'A denial note is required.');
|
||||
}
|
||||
|
||||
$model->update($id, [
|
||||
'status' => 'denied',
|
||||
'admin_note' => $note,
|
||||
'reviewed_by' => (int) session()->get('user_id'),
|
||||
'reviewed_at' => date('Y-m-d H:i:s'),
|
||||
]);
|
||||
|
||||
return redirect()->to('/administrator/financial-aid')->with('success', 'Financial aid request was denied.');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user