public function actionNew($eid) { $eid = (int) $eid; $id = EnrolledForm::findOne($eid); if ($id !== null) { $model = new AssessmentForm(); $student_id = (int) $id->student_id; $grade_level_id = (int) $id->grade_level_id; $student = StudentForm::findOne($id->student_id); $tuition = Tuition::find()->where(['grade_level_id' => $grade_level_id])->orderBy(['id' => SORT_DESC])->all(); $model->enrolled_id = $eid; $tid = (int) $tuition[0]['id']; $model->tuition_id = $tid; $model->has_sibling_discount = (int) $model->has_sibling_discount; $model->has_book_discount = (int) $model->has_book_discount; $model->has_honor_discount = (int) $model->has_honor_discount; if (!empty($tuition)) { $array = $tuition; } else { throw new NotFoundHttpException('Oops, Something went wrong.'); } //$tuition_detail = Tuition::find()->where(['grade_level_id' => $grade_level_id])->orderBy(['id' => SORT_DESC])->all(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('new', ['model' => $model, 'student' => $student, 'tid' => $tid, 'array' => $array]); } } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function afterSave($insert, $changedAttributes) { if ($insert) { $tuition = Tuition::find()->where(['grade_level_id' => $this->grade_level_id])->orderBy(['id' => SORT_DESC])->all()[0]; $assessment = new AssessmentForm(); //CHECK IF STUDENT HAS SIBLINGS ENROLLED if ((int) $this->student->student_has_sibling_enrolled === 0) { $assessment->has_sibling_discount = 0; $sibling_discount = (double) $tuition->tuition_fee * 0.05; $assessment->percentage_value = 5; $assessment->sibling_discount = $sibling_discount; $assessment->honor_discount = 0; $assessment->book_discount = 0; $assessment->total_assessed = (double) $tuition->yearly + (double) $tuition->books - $sibling_discount; $assessment->balance = (double) $assessment->total_assessed; } else { $assessment->has_sibling_discount = 1; $assessment->sibling_discount = 0; $assessment->percentage_value = 0; $assessment->honor_discount = 0; $assessment->book_discount = 0; $assessment->total_assessed = (double) $tuition->yearly + (double) $tuition->books; $assessment->balance = (double) $assessment->total_assessed; } //die($changedAttributes); $assessment->has_honor_discount = 1; $assessment->has_book_discount = 1; $assessment->enrolled_id = (int) $this->id; $assessment->tuition_id = $tuition->id; $assessment->save(); Yii::$app->session->setFlash('success2', 'New assessment successfully generated!'); } }