/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = LoanDrawRequest::find(); if (!isset($params['sort'])) { $query->orderBy(['id_loan_draw_request' => SORT_DESC]); } $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id_loan_draw_request' => $this->id_loan_draw_request, 'id_loan' => $this->id_loan, 'id_user' => $this->id_user, 'status' => $this->status, 'amount' => $this->amount, 'requested_date' => $this->requested_date, 'approved_date' => $this->approved_date, 'rejected_date' => $this->rejected_date, 'delete' => $this->delete, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); return $dataProvider; }
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]); } }