get('user_id'); if ($parentId <= 0) { return redirect()->to('/login'); } $schoolYear = (string) ((new ConfigurationModel())->getConfig('school_year') ?? ''); $model = new FinancialAidRequestModel(); $requests = $model ->where('parent_id', $parentId) ->where('school_year', $schoolYear) ->orderBy('id', 'DESC') ->findAll(); return view('parent/financial_aid', [ 'schoolYear' => $schoolYear, 'requests' => $requests, 'openRequest' => $model->openRequestForParent($parentId, $schoolYear), 'existingRequest' => $model->requestForParentYear($parentId, $schoolYear), ]); } public function submit() { $parentId = (int) session()->get('user_id'); if ($parentId <= 0) { return redirect()->to('/login'); } $schoolYear = (string) ((new ConfigurationModel())->getConfig('school_year') ?? ''); $model = new FinancialAidRequestModel(); if ($model->requestForParentYear($parentId, $schoolYear) !== null) { return redirect()->back()->with('error', 'You can submit only one financial aid application per school year.'); } $studentIds = array_map('intval', array_column( (new StudentModel())->select('id')->where('parent_id', $parentId)->findAll(), 'id' )); if ($studentIds === []) { return redirect()->back()->withInput()->with('error', 'No students are linked to your account.'); } $householdIncomeRaw = trim((string) $this->request->getPost('household_income')); if ($householdIncomeRaw === '' || ! is_numeric($householdIncomeRaw) || (float) $householdIncomeRaw < 0) { return redirect()->back()->withInput()->with('error', 'Enter your household income.'); } $householdSize = (int) $this->request->getPost('household_size'); if ($householdSize < 1) { return redirect()->back()->withInput()->with('error', 'Enter your household size.'); } $requestedAmountRaw = trim((string) $this->request->getPost('requested_amount')); if ($requestedAmountRaw === '' || ! is_numeric($requestedAmountRaw) || (float) $requestedAmountRaw <= 0) { return redirect()->back()->withInput()->with('error', 'Enter the amount you are requesting.'); } $needStatement = trim((string) $this->request->getPost('need_statement')); if ($needStatement === '') { return redirect()->back()->withInput()->with('error', 'Please describe why you are requesting financial aid.'); } $model->insert([ 'parent_id' => $parentId, 'school_year' => $schoolYear, 'student_ids_json' => json_encode(array_values($studentIds)), 'household_size' => $householdSize, 'household_income' => round((float) $householdIncomeRaw, 2), 'need_statement' => $needStatement, 'requested_amount' => round((float) $requestedAmountRaw, 2), 'status' => 'submitted', ]); return redirect()->to('/parent/financial-aid')->with('success', 'Your financial aid request was submitted.'); } }