Пример #1
0
 public function actionDeleteCollateral($id)
 {
     $model = AppFormCollateralAccount::findOne($id);
     $model->delete = Dict::DELETE_YES;
     $model->save();
     $appFormModel = AppForm::find()->andWhere(['id_application' => $model->id_application])->one();
     $appFormModel->save(false);
     return $this->redirect(['collateral-information', 'id_application' => $model->id_application]);
 }
Пример #2
0
 public function checkAppForm()
 {
     $form = $this->appForm;
     $appModel = $this->primaryAppApplicant;
     $coAppModel = $this->coAppApplicant;
     $errorCount = 0;
     $totalCount = 1;
     $errorList = [];
     $tmpModel = new AppForm(['scenario' => 'complate-rate-check', 'id_application' => $this->id_application]);
     $tmpModel->validate();
     $totalCount += count($tmpModel->getErrors());
     $tmpModel = new AppApplicant(['scenario' => 'complate-rate-check']);
     $tmpModel->validate();
     $totalCount += count($tmpModel->getErrors());
     if ($coAppModel) {
         $tmpModel = new AppApplicant(['scenario' => 'co-complate-rate-check']);
         $tmpModel->validate();
         $totalCount += count($tmpModel->getErrors());
     }
     $form->setScenario('complate-rate-check');
     $form->validate();
     $errorCount += count($form->getErrors());
     $errorList = array_merge($errorList, $form->getErrors());
     $appModel->setScenario('complate-rate-check');
     $appModel->validate();
     $errorCount += count($appModel->getErrors());
     $errorList = array_merge($errorList, $appModel->getErrors());
     if ($coAppModel) {
         $coAppModel->setScenario('co-complate-rate-check');
         $coAppModel->validate();
         $errorCount += count($coAppModel->getErrors());
         $errorList = array_merge($errorList, $coAppModel->getErrors());
     }
     $collateralAccount = AppFormCollateralAccount::find()->andWhere(['id_application' => $this->id_application])->all();
     if (!$collateralAccount) {
         $errorCount += 1;
         $errorList['collateral_account'] = ['need add one collateral account'];
     }
     return ['totalCount' => $totalCount, 'errorCount' => $errorCount, 'errorList' => $errorList];
 }
 public function actionIndex($id_app_task)
 {
     $model = AppTask::findOne($id_app_task);
     // loan
     $loan = Loan::find()->where(['id_application' => $model->id_application])->one();
     // application
     $application = Application::findOne($model->id_application);
     // applicants
     $app_applicants = $application->appApplicants;
     $applicants = [];
     foreach ($app_applicants as $val) {
         $applicants[] = $val->first_name;
     }
     // advisors
     $advisors = [];
     foreach ($model->application->advisors as $advisor) {
         if (isset($advisor->user)) {
             $advisors[] = $advisor->user->first_name;
         }
     }
     // 读取所以检查项
     $checkPointsData = AppTaskCheckpoint::find()->where(['id_app_task' => $id_app_task])->all();
     $checkPoints = [];
     $check_ctrl = true;
     foreach ($checkPointsData as $val) {
         $checkPoints[$val['id_app_task_checkpoint_type']] = $val;
     }
     if ($application->have_existing_loan) {
         $check_ctrl = $checkPoints[4]->status && $checkPoints[5]->status ? true : false;
     } else {
         $check_ctrl = $checkPoints[4]->status ? true : false;
     }
     if (Yii::$app->request->post()) {
         $loanModel = Loan::find()->andWhere(['id_application' => $model->id_application])->one();
         $loanModel->status = 1;
         $loanModel->save();
         if (AppTask::taskFinish($id_app_task)) {
             //active log.loan officer finished the task line set-up
             Active::operationLog($model->id_application, [Yii::$app->user->getIdentity()->first_name, Yii::$app->user->getIdentity()->last_name, 'finished', DictTask::$taskType[DictTask::TYPE_LINE_SETUP]], DictActive::USER_FINISH_TASK, Yii::$app->user->getIdentity()->id);
         }
         // 拷贝 form/financial info/LOC Disbursement
         $app_form = AppForm::find()->andWhere(['id_application' => $model->id_application])->one();
         $LoanBankAcount = new LoanBankAcount();
         $LoanBankAcount->account_type = 1;
         $LoanBankAcount->id_loan = $loanModel->id_loan;
         $LoanBankAcount->bank_name = $app_form->bank_name;
         $LoanBankAcount->routing_number = $app_form->routing_number;
         $LoanBankAcount->account_name = $app_form->account_name;
         $LoanBankAcount->account_number = $app_form->account_number;
         $LoanBankAcount->save();
         // 拷贝 collateral_data 数据
         LineAccount::copyData($model->id_application, $loanModel->id_loan);
         CollateralAccount::copyData($model->id_application, $loanModel->id_loan);
         //send loan approval email to client and cc to advisor(email($email_type,[$task_type,$id_app_task,$loan]))
         $res = SendEmail::email(DictEmail::EMAIL_LETTER_ABOUT_LINE, [DictEmail::LETTER_TASK_LOAN_APPROVAL, $id_app_task, $loan]);
         if ($res) {
             //active log.system sent an email 'Your Line is Live' to client and advisor
             //判断是否有两个client参与
             $user = SendEmail::findUserByApplication($model->id_application);
             if (is_null($user['co_applicant'])) {
                 Active::operationLog($model->id_application, [$user['applicant']->first_name, $user['applicant']->last_name, '', $user['advisor']->first_name, $user['advisor']->last_name], DictActive::SYSTEM_SEND_LINE_ALIVE_LETTER, 0);
             } else {
                 Active::operationLog($model->id_application, [$user['applicant']->first_name, $user['applicant']->last_name, ',' . $user['co_applicant']->first_name . ' ' . $user['co_applicant']->last_name, $user['advisor']->first_name, $user['advisor']->last_name], DictActive::SYSTEM_SEND_LINE_ALIVE_LETTER, 0);
             }
         }
         //active log.system closed the application
         Active::operationLog($model->id_application, [], DictActive::SYSTEM_CLOSED_THE_APPLICATION, 0);
         // collateral_data 拷贝 Line
         $application = Application::findOne($model->id_application);
         $application->id_application_status = DictApplication::STATUS_CLOSED;
         $application->save(false);
         return $this->redirect(['/application/view', 'id' => $model->id_application]);
     }
     return $this->render('index', ['model' => $model, 'application' => $application, 'loan' => $loan, 'applicants' => $applicants, 'advisors' => $advisors, 'checkPoints' => $checkPoints, 'check_ctrl' => $check_ctrl]);
 }
 /**
  * Creates a new Application model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Application();
     $appModel = new AppApplicant(['scenario' => 'primary-create']);
     $coAppModel = new AppApplicant(['scenario' => 'co-create']);
     $appFormModel = new AppForm();
     //加载数据并验证
     if ($model->load(Yii::$app->request->post()) && $appModel->load(Yii::$app->request->post()) && $coAppModel->load(Yii::$app->request->post()) && $appFormModel->load(Yii::$app->request->post()) && $model->validate() && $appModel->validate() && ($model->is_joint_application == 1 ? $coAppModel->validate() : true) && ($model->is_joint_application == 1 ? $appModel->email_address != $coAppModel->email_address : true)) {
         //开启事务
         $transaction = Yii::$app->db->beginTransaction();
         try {
             if (!$appModel->id_user) {
                 $user = User::createUser(Dict::USER_ROLE_CLIENT, ['User' => ['first_name' => $appModel->first_name, 'last_name' => $appModel->last_name, 'mid_name' => $appModel->mid_name, 'email' => $appModel->email_address], 'Client' => ['id_group' => $model->id_group]]);
                 //设置applicant的id_user
                 $appModel->id_user = $user->id_user;
                 SendEmail::email(DictEmail::EMAIL_INVITE_USER, [$user]);
             }
             if ($model->is_joint_application && !$coAppModel->id_user) {
                 $user = User::createUser(Dict::USER_ROLE_CLIENT, ['User' => ['first_name' => $coAppModel->first_name, 'last_name' => $coAppModel->last_name, 'mid_name' => $coAppModel->mid_name, 'email' => $coAppModel->email_address], 'Client' => ['id_group' => $model->id_group]]);
                 //设置co-applicant的id_user
                 $coAppModel->id_user = $user->id_user;
                 SendEmail::email(DictEmail::EMAIL_INVITE_USER, [$user]);
             }
             $model->application_name = $appModel->first_name . ($model->is_joint_application ? ' and ' . $coAppModel->first_name : '') . "'s application";
             $model->charge_fee = Advisor::findOne(['id_user' => Yii::$app->user->getId()])->will_charge_fee;
             if (!$model->save()) {
                 $transaction->rollBack();
             }
             $user = Yii::$app->user->getIdentity();
             Active::operationLog($model->id_application, [$user->first_name, $user->last_name], DictActive::CREATE_APPLICATION, $user->id);
             $appModel->id_application = $model->id_application;
             $appModel->id_app_applicant_type = 1;
             if (!$appModel->save()) {
                 $transaction->rollBack();
             }
             if ($model->is_joint_application == 1) {
                 $coAppModel->id_application = $model->id_application;
                 $coAppModel->id_app_applicant_type = 2;
                 if (!$coAppModel->save()) {
                     $transaction->rollBack();
                 }
             }
             $appFormModel->id_application = $model->id_application;
             if (!$appFormModel->save()) {
                 $transaction->rollBack();
             }
             //初始化任务
             AppTask::initialize($model->id_application);
             // 将AppTaskCheckpoint中的模板转换为实例
             AppTaskCheckpoint::initialize($model->appTask);
             //创建AppUser记录
             AppUser::createByApplication($model);
             //send email to notificate advisor create application success.method email([$task_type,$id_application,$id_app_owner_task],$notify_type)
             SendEmail::email(DictEmail::EMAIL_TASK_NOTIFICATION, [DictTask::TYPE_APPLICATION_FORM, $model->id_application, 0]);
             //id_app_owner_task_type:1(app-form);0:表示没有传递id_app_owner_task
             $transaction->commit();
         } catch (Exception $e) {
             $transaction->rollBack();
         }
         return $this->redirect(['/app-form/basic-info', 'id_application' => $model->id_application]);
     }
     return $this->render('create', ['model' => $model, 'appModel' => $appModel, 'coAppModel' => $coAppModel, 'appFormModel' => $appFormModel]);
 }