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]);
 }
 public function actionDoupdate()
 {
     $loc = loan::find()->where(['id_loan' => $this->loan->id_loan])->one();
     // 读取 payment
     if (!empty($this->loan->id_loan) && $this->loan->status == Dict::LOAN_STATUS_ACTIVE) {
         $payment = LoanBorrower::find()->where(['id_loan' => $this->loan->id_loan])->one();
         $LoanPaymentPreferenceModel = LoanPaymentPreference::find()->where(['id_loan' => $this->loan->id_loan])->one();
         $type_checked = $LoanPaymentPreferenceModel['type'];
         $bankAccountModel = LoanBankAcount::find()->andWhere(['id_loan' => $this->loan->id_loan, 'account_type' => '2'])->one();
         $bankAccountModel_1 = LoanBankAcount::find()->andWhere(['id_loan' => $this->loan->id_loan, 'account_type' => '1'])->one();
         $acheck = 2;
         if ($bankAccountModel['bank_name'] == $bankAccountModel_1['bank_name'] && $bankAccountModel['routing_number'] == $bankAccountModel_1['routing_number'] && $bankAccountModel['account_name'] == $bankAccountModel_1['account_name'] && $bankAccountModel['account_number'] == $bankAccountModel_1['account_number']) {
             $acheck = 1;
         }
         if (empty($bankAccountModel)) {
             $bankAccountModel = $bankAccountModel_1;
             $acheck = 1;
             $no_val = null;
         } else {
             $no_val = $bankAccountModel;
         }
         if ($type_checked != 1) {
             $acheck = 1;
         }
     } else {
         return $this->render("payment", ['status' => 0]);
     }
     // 读取 bank account
     if ($LoanPaymentPreferenceModel->load(Yii::$app->request->post())) {
         $paymentPost = Yii::$app->request->post('LoanPaymentPreference');
         $achchecked = Yii::$app->request->post('optionsRadios');
         $LoanBankAcount = Yii::$app->request->post('LoanBankAcount');
         //得到LoanPaymentPreference数据
         if (!empty($LoanPaymentPreferenceModel)) {
             $LoanPaymentPreferenceModel->type = $paymentPost['type'];
             $LoanPaymentPreferenceModel->save();
         }
         $bankaccoun = LoanBankAcount::find()->andWhere(['id_loan' => $this->loan->id_loan, 'account_type' => '2'])->one();
         if (empty($bankaccoun)) {
             $bankaccoun = new LoanBankAcount();
         }
         if ($paymentPost['type'] == Dict::LOAN_PAYMENT_ACH) {
             if ($achchecked == 1) {
                 $bannaccoun1 = LoanBankAcount::find()->andWhere(['id_loan' => $this->loan->id_loan, 'account_type' => '1'])->one();
                 $bankaccoun->bank_name = $bannaccoun1->bank_name;
                 $bankaccoun->routing_number = $bannaccoun1->routing_number;
                 $bankaccoun->account_name = $bannaccoun1->account_name;
                 $bankaccoun->account_number = $bannaccoun1->account_number;
             } else {
                 $bankaccoun->bank_name = $LoanBankAcount['bank_name'];
                 $bankaccoun->routing_number = $LoanBankAcount['routing_number'];
                 $bankaccoun->account_name = $LoanBankAcount['account_name'];
                 $bankaccoun->account_number = $LoanBankAcount['account_number'];
             }
             $bankaccoun->id_loan = $this->loan->id_loan;
             $bankaccoun->account_type = 2;
             $bankaccoun->save(false);
         } else {
             $bankaccoun->id_loan = $this->loan->id_loan;
             $bankaccoun->account_type = 2;
             $bankaccoun->save(false);
         }
         $this->redirect('/loan/payment');
     }
     $config_pay = Config::find()->where(['config_name' => "pay_to_adress"])->one();
     $config_fee = Config::find()->where(['config_name' => "check_processing_fee"])->one();
     $config['pay'] = $config_pay['config_value'];
     $config['fee'] = $config_fee['config_value'];
     $config['loc'] = $loc['loc'] * Dict::LOAN_PAYMENT_RATE / Dict::LOAN_PAYMENT_MONTH;
     $config['acheck'] = $acheck;
     $LoanPaymentPreferenceModel->type = $type_checked;
     return $this->render('update_payment', ['config' => $config, 'status' => Dict::LOAN_STATUS_ACTIVE, 'type_checked' => $type_checked, 'loan' => $this->loan, 'payment' => $payment, 'no_val' => $no_val, 'bankAccountModel' => $bankAccountModel, 'LoanPaymentPreference' => $LoanPaymentPreferenceModel, 'bankAccountModel_1' => $bankAccountModel_1]);
 }