public function actionDrawConfirm($id) { $model = new LoanDrawRequest(); $model->id_user = Yii::$app->user->getId(); $model->id_loan = $id; $model->status = 1; $loanModel = Loan::findOne($id); $loanBank = LoanBankAcount::find()->andWhere(['id_loan' => $id])->one(); if (!$loanModel->application->checkOnwerAccess(Yii::$app->user->getId()) && $this->user->id_user_role != Dict::USER_ROLE_BETTERDEBT) { throw new UnauthorizedHttpException("Sorry, you don't have permission to access this page."); } $request = LoanDrawRequest::find()->where(['id_loan' => $loanModel->id_loan, 'status' => 1])->one(); $request = is_null($request) ? [] : $request; if (count($request) > 0) { $model->addError('amount', 'Your draw request was submitted successfully!Better Debt is working on it.'); } if ($model->load(Yii::$app->request->post()) && $model->save()) { //send draw request email to client (and cc to co_applicant).Method email($email_type,[$letter_type,$id_application,$user_type,$drawModel]) SendEmail::email(DictEmail::EMAIL_LETTER_ABOUT_LINE, [DictEmail::LETTER_DRAW_REQUEST, $loanModel->id_application, DictEmail::DRAW_REQUEST_TYPE_CLIENT, $model]); //send draw request email to advisor.Method email($email_type,[$letter_type,$id_application,$user_type,$drawModel,$loanModel]) SendEmail::email(DictEmail::EMAIL_LETTER_ABOUT_LINE, [DictEmail::LETTER_DRAW_REQUEST, $loanModel->id_application, DictEmail::DRAW_REQUEST_TYPE_ADVISOR, $model, $loanModel]); //send draw request email to betterdebt.Method email($email_type,[$letter_type,$id_application,$user_type,$drawModel,$loanModel]) SendEmail::email(DictEmail::EMAIL_LETTER_ABOUT_LINE, [DictEmail::LETTER_DRAW_REQUEST, $loanModel->id_application, DictEmail::DRAW_REQUEST_TYPE_LOAN_OFFICER, $model, $loanModel]); return $this->render('draw_success'); } else { return $this->render('draw_confirm', ['model' => $model, 'loanModel' => $loanModel, 'loanBank' => is_null($loanBank) ? new LoanBankAcount() : $loanBank, 'request' => $request]); } }