public static function createAppFormPdfByApplication($application) { $appForm = $application->appForm; $primaryAppApplicant = $application->primaryAppApplicant; $dataJson = json_decode(file_get_contents('../../common/pdf-template/data/data_app_form.json'), true); $dataJson['a.full_name'] = $primaryAppApplicant->first_name . ($primaryAppApplicant->mid_name ? ' ' . $primaryAppApplicant->mid_name : '') . ' ' . $primaryAppApplicant->last_name; $dataJson['a.street'] = $primaryAppApplicant->address_street; $dataJson['a.city_state_zip'] = $primaryAppApplicant->getFullAddress(); $dataJson['a.home_phone'] = $primaryAppApplicant->home_phone; $dataJson['a.work_phone'] = $primaryAppApplicant->work_phone; $dataJson['a.cell_phone'] = $primaryAppApplicant->cell_phone; $dataJson['a.email'] = $primaryAppApplicant->email_address; $dataJson['a.ssn'] = $primaryAppApplicant->social_security_number; $dataJson['a.dob'] = $primaryAppApplicant->date_of_birth ? date('m/d/Y', $primaryAppApplicant->date_of_birth) : ''; if ($primaryAppApplicant->is_united_states_citizen === DictApplicant::AMERICAN_CITIZEN_NOT) { $dataJson['a.us_n'] = 'checked'; } elseif ($primaryAppApplicant->is_united_states_citizen === DictApplicant::AMERICAN_CITIZEN_YES) { $dataJson['a.us_y'] = 'checked'; } switch ($primaryAppApplicant->identification_type) { case DictApplicant::IDENTIFICATION_DRIVERS_LICENSE: $dataJson['a.id_dl'] = 'checked'; break; case DictApplicant::IDENTIFICATION_PASSPORT: $dataJson['a.id_pp'] = 'checked'; break; case DictApplicant::IDENTIFICATION_PHOTO_ID: $dataJson['a.id_gid'] = 'checked'; break; } $dataJson['a.id_no'] = $primaryAppApplicant->identification_number; $dataJson['a.id_state'] = $primaryAppApplicant->identification_state; $dataJson['a.id_ed'] = $primaryAppApplicant->identification_expiration_date ? date('m/d/Y', $primaryAppApplicant->identification_expiration_date) : ''; $dataJson['a.occupation'] = $primaryAppApplicant->occupation; $dataJson['a.employer'] = $primaryAppApplicant->employer; switch ($primaryAppApplicant->total_annual_income) { case DictApplicant::TOTAL_ANNUAL_INCOME_1: $dataJson['a.income_less'] = 'checked'; break; case DictApplicant::TOTAL_ANNUAL_INCOME_2: $dataJson['a.income_5010'] = 'checked'; break; case DictApplicant::TOTAL_ANNUAL_INCOME_3: $dataJson['a.income_1025'] = 'checked'; break; case DictApplicant::TOTAL_ANNUAL_INCOME_4: $dataJson['a.income_2550'] = 'checked'; break; case DictApplicant::TOTAL_ANNUAL_INCOME_5: $dataJson['a.income_500100'] = 'checked'; break; case DictApplicant::TOTAL_ANNUAL_INCOME_6: $dataJson['a.income_1000'] = 'checked'; break; } switch ($primaryAppApplicant->marital_status) { case DictApplicant::MARITAL_MARRIED: $dataJson['a.marital_m'] = 'checked'; break; case DictApplicant::MARITAL_SEPARATED: $dataJson['a.marital_s'] = 'checked'; break; case DictApplicant::MARITAL_UNMARRIED: $dataJson['a.marital_u'] = 'checked'; break; } if ($coAppApplicant = $application->coAppApplicant) { $dataJson['co.full_name'] = $coAppApplicant->first_name . ($coAppApplicant->mid_name ? ' ' . $coAppApplicant->mid_name : '') . ' ' . $coAppApplicant->last_name; $dataJson['co.street'] = $coAppApplicant->address_street; $dataJson['co.city_state_zip'] = $coAppApplicant->getFullAddress(); $dataJson['co.home_phone'] = $coAppApplicant->home_phone; $dataJson['co.work_phone'] = $coAppApplicant->work_phone; $dataJson['co.cell_phone'] = $coAppApplicant->cell_phone; $dataJson['co.email'] = $coAppApplicant->email_address; $dataJson['co.ssn'] = $coAppApplicant->social_security_number; $dataJson['co.dob'] = $coAppApplicant->date_of_birth ? date('m/d/Y', $coAppApplicant->date_of_birth) : ''; if ($coAppApplicant->is_united_states_citizen === DictApplicant::AMERICAN_CITIZEN_NOT) { $dataJson['co.us_n'] = 'checked'; } elseif ($coAppApplicant->is_united_states_citizen === DictApplicant::AMERICAN_CITIZEN_YES) { $dataJson['co.us_y'] = 'checked'; } switch ($coAppApplicant->identification_type) { case DictApplicant::IDENTIFICATION_DRIVERS_LICENSE: $dataJson['co.id_dl'] = 'checked'; break; case DictApplicant::IDENTIFICATION_PASSPORT: $dataJson['co.id_pp'] = 'checked'; break; case DictApplicant::IDENTIFICATION_PHOTO_ID: $dataJson['co.id_gid'] = 'checked'; break; } $dataJson['co.id_no'] = $coAppApplicant->identification_number; $dataJson['co.id_state'] = $coAppApplicant->identification_state; $dataJson['co.id_ed'] = $coAppApplicant->identification_expiration_date ? date('m/d/Y', $coAppApplicant->identification_expiration_date) : ''; $dataJson['co.occupation'] = $coAppApplicant->occupation; $dataJson['co.employer'] = $coAppApplicant->employer; switch ($coAppApplicant->total_annual_income) { case DictApplicant::TOTAL_ANNUAL_INCOME_1: $dataJson['co.income_less'] = 'checked'; break; case DictApplicant::TOTAL_ANNUAL_INCOME_2: $dataJson['co.income_5010'] = 'checked'; break; case DictApplicant::TOTAL_ANNUAL_INCOME_3: $dataJson['co.income_1025'] = 'checked'; break; case DictApplicant::TOTAL_ANNUAL_INCOME_4: $dataJson['co.income_2550'] = 'checked'; break; case DictApplicant::TOTAL_ANNUAL_INCOME_5: $dataJson['co.income_500100'] = 'checked'; break; case DictApplicant::TOTAL_ANNUAL_INCOME_6: $dataJson['co.income_1000'] = 'checked'; break; } switch ($coAppApplicant->marital_status) { case DictApplicant::MARITAL_MARRIED: $dataJson['co.marital_m'] = 'checked'; break; case DictApplicant::MARITAL_SEPARATED: $dataJson['co.marital_s'] = 'checked'; break; case DictApplicant::MARITAL_UNMARRIED: $dataJson['co.marital_u'] = 'checked'; break; } } switch ($primaryAppApplicant->years_with_advisor) { case DictApplicant::YEARS_WITH_ADVISOR_1: $dataJson['with_advisor_1'] = 'checked'; break; case DictApplicant::YEARS_WITH_ADVISOR_2: $dataJson['with_advisor_14'] = 'checked'; break; case DictApplicant::YEARS_WITH_ADVISOR_3: $dataJson['with_advisor_59'] = 'checked'; break; case DictApplicant::YEARS_WITH_ADVISOR_4: $dataJson['with_advisor_10'] = 'checked'; break; } switch ($primaryAppApplicant->net_worth) { case DictApplicant::NET_WORTH_1: $dataJson['net_worth_10'] = 'checked'; break; case DictApplicant::NET_WORTH_2: $dataJson['net_worth_1025'] = 'checked'; break; case DictApplicant::NET_WORTH_3: $dataJson['net_worth_2550'] = 'checked'; break; case DictApplicant::NET_WORTH_4: $dataJson['net_worth_50100'] = 'checked'; break; case DictApplicant::NET_WORTH_5: $dataJson['net_worth_100500'] = 'checked'; break; case DictApplicant::NET_WORTH_6: $dataJson['net_worth_500'] = 'checked'; break; } $dataJson['value_account'] = number_format($primaryAppApplicant->total_value_with_advisor ?: 0); $dataJson['loc_amount'] = number_format($application->loc ?: 0); $dataJson['loc_max'] = $application->loc_max ? 'checked' : ''; $application->have_existing_loan ? $dataJson['exsting_loan_y'] = 'checked' : ($dataJson['exsting_loan_n'] = 'checked'); $dataJson['payoff_amount'] = number_format($application->existing_loan_amount ?: 0); $dataJson['lender_name'] = $application->name_of_lender; $dataJson['exsting_loan_number'] = $application->loan_number; switch ($appForm->primary_purpose) { case DictApplication::PRIMARY_PURPOSE_TAX_PAYMENTS: $dataJson['purpose_tax'] = 'checked'; break; case DictApplication::PRIMARY_PURPOSE_PERSONAL_PURCHASE: $dataJson['purpose_luxury'] = 'checked'; break; case DictApplication::PRIMARY_PURPOSE_REAL_ESTATE: $dataJson['purpose_real_estate'] = 'checked'; break; case DictApplication::PRIMARY_PURPOSE_GENERAL_LIQUIDITY_PURPOSES: $dataJson['purpos_general'] = 'checked'; break; } if ($collateralAccounts = $application->collateralAccounts) { $dataJson['accounts'] = []; foreach ($collateralAccounts as $collateralAccount) { $account = []; $account['account_namer'] = $collateralAccount->account_name_title; $account['registration'] = $collateralAccount->registration; $account['custodian'] = $collateralAccount->custodian; $account['account_number'] = $collateralAccount->account_number; $collateralAccount->has_regular_distribution ? $account['distribution_y'] = 'checked' : ($account['distribution_n'] = 'checked'); $account['distribution_amount'] = number_format($collateralAccount->regular_distribution_amount ?: 0); $account['distribution_payee'] = $collateralAccount->payee; $account['revocable_trust'] = $collateralAccount->is_trust_account ? 'checked' : ''; $account['trust_name'] = $collateralAccount->trust_name; $account['grantor_name'] = $collateralAccount->names_of_grantors; $account['trustee_name'] = $collateralAccount->names_of_trustees; $account['tax_id'] = $collateralAccount->tax_id; $account['address_street'] = $collateralAccount->address_street; $account['address_state'] = $collateralAccount->address_state_where_organized; $account['address_city_state_zip'] = $collateralAccount->getFullAddress(); $account['trustee_phone'] = $collateralAccount->trustee_phone_number; $dataJson['accounts'][] = $account; } } $dataJson['bank_name'] = $appForm->bank_name; $dataJson['routing'] = $appForm->routing_number; $dataJson['account_name'] = $appForm->account_name; $dataJson['account_number'] = $appForm->account_number; if ((string) $appForm->applicant_has_a_freeze === '0') { $dataJson['a_freeze_n'] = 'checked'; } elseif ((string) $appForm->applicant_has_a_freeze === '1') { $dataJson['a_freeze_y'] = 'checked'; } if ($application->coAppApplicant) { if ((string) $appForm->co_applicant_has_a_freeze === '0') { $dataJson['co_freeze_n'] = 'checked'; } elseif ((string) $appForm->co_applicant_has_a_freeze === '1') { $dataJson['co_freeze_y'] = 'checked'; } } $advisor = Advisor::findOne(['id_user' => $application->primaryAdvisor->id_user]); $dataJson['advisor_firm_name'] = $advisor->institution->institution_name; $dataJson['print_name'] = $advisor->user->first_name . ' ' . $advisor->user->last_name; $dataJson['advisor_name'] = $advisor->user->first_name . ' ' . $advisor->user->last_name; $dataJson['firm_name'] = $advisor->institution->institution_name; $dataJson['firm_phone'] = $advisor->institution->phone; $dataJson['firm_address'] = $advisor->office->address; $dataJson['firm_city'] = $advisor->office->city; $dataJson['firm_state'] = $advisor->office->state; $dataJson['firm_zip'] = $advisor->office->zip; $dataJson['advisor_email'] = $advisor->user->email; if (file_exists(Yii::$app->params['outpdfPath'] . $application->id_application . '_app_form.pdf')) { unlink(Yii::$app->params['outpdfPath'] . $application->id_application . '_app_form.pdf'); } if (file_exists(Yii::$app->params['outpdfPath'] . $application->id_application . '_signaure_spec_app_form.json')) { unlink(Yii::$app->params['outpdfPath'] . $application->id_application . '_signaure_spec_app_form.json'); } if ($application->charge_fee) { $document = new Document("../../common/pdf-template/config/config_app_form.json", $dataJson, "../../common/pdf-template/", Yii::$app->params['outpdfPath'] . $application->id_application . "_app_form.pdf", Yii::$app->params['outpdfPath'] . $application->id_application . "_signaure_spec_app_form.json"); } else { $document = new Document("../../common/pdf-template/config/config_app_form.json", $dataJson, "../../common/pdf-template/nofee/", Yii::$app->params['outpdfPath'] . $application->id_application . "_app_form.pdf", Yii::$app->params['outpdfPath'] . $application->id_application . "_signaure_spec_app_form.json"); } $document->render(); return $result = Upload::uploadFileByApplication($application->id_application, Yii::$app->params['outpdfPath'] . $application->id_application . '_app_form.pdf', 'app_form.pdf', DictDocument::TYPE_APPLICATION_FORM); }
public function afterSave($insert, $changeAttributes) { if ($insert) { $applicationModel = $this->application; $primaryAppApplicant = $applicationModel->primaryAppApplicant; $coAppApplicant = $applicationModel->coAppApplicant; $loanBorrowerModel = new LoanBorrower(); $loanBorrowerModel->id_loan = $this->id_loan; $loanBorrowerModel->id_user = $primaryAppApplicant->id_user; $loanBorrowerModel->type = 1; $loanBorrowerModel->save(); if ($applicationModel->coAppApplicant) { $loanBorrowerModel = new LoanBorrower(); $loanBorrowerModel->id_loan = $this->id_loan; $loanBorrowerModel->id_user = $coAppApplicant->id_user; $loanBorrowerModel->type = 0; $loanBorrowerModel->save(); } $loanPaymentPreferenceModel = new LoanPaymentPreference(); $loanPaymentPreferenceModel->id_loan = $this->id_loan; $loanPaymentPreferenceModel->type = 2; $loanPaymentPreferenceModel->ach_max_debtied_amount = 0; $loanPaymentPreferenceModel->ach_id_loan_bank_acount = 0; $loanPaymentPreferenceModel->save(); $loanCollateralAccountModel = new LoanCollateralAccount(); $loanCollateralAccountModel->id_loan = $this->id_loan; $loanCollateralAccountModel->id_institution = Advisor::findOne(['id_user' => $applicationModel->primaryAdvisor->id_user])->id_institution; $loanCollateralAccountModel->id_group = $applicationModel->id_group; $appFormCollateralAccountModels = AppFormCollateralAccount::find()->andWhere(['id_application' => $this->id_application])->all(); foreach ($appFormCollateralAccountModels as $appFormCollateralAccountModel) { $newLoanCollateralAccountModel = clone $loanCollateralAccountModel; $newLoanCollateralAccountModel->load([$newLoanCollateralAccountModel->formName() => $appFormCollateralAccountModel->getAttributes()]); $newLoanCollateralAccountModel->save(); } } }
/** * 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]); }
use yii\helpers\Html; use yii\widgets\ActiveForm; use yii\helpers\Url; use common\models\Client; use common\models\Group; use kartik\widgets\DepDrop; use yii\helpers\ArrayHelper; use kartik\date\DatePicker; use common\models\Advisor; use common\models\AppApplicant; use yii\widgets\MaskedInput; use common\models\State; use kartik\widgets\Select2; use common\models\Betterdebt; if ($model->getIsNewRecord()) { $advisor = Advisor::findOne(['id_user' => Yii::$app->user->getId()]); $group = ArrayHelper::map($advisor->groups, 'id_group', 'group_id'); } $betterdebt = Betterdebt::find()->andWhere(['id_user' => Yii::$app->user->getId()])->one(); if (Yii::$app->user->getIdentity()->id_user_role == Dict::USER_ROLE_ADVISOR && !$model->isNewRecord && !$model->isNewRecord || Yii::$app->user->getIdentity()->id_user_role == Dict::USER_ROLE_CLIENT || Yii::$app->user->getIdentity()->id_user_role == Dict::USER_ROLE_BETTERDEBT) { // $readonly = true; //判断不属于service team的supernova只能有读的权限 if (Yii::$app->user->getIdentity()->id_user_role == Dict::USER_ROLE_BETTERDEBT) { if ($betterdebt->is_in_service_team == Dict::BD_SERVICE_TEAM_YES) { $readonly = false; } else { $readonly = true; } } else { $readonly = true; }
public function actionUpdate($id) { $model = $this->findModel($id); $userModel = User::find()->andWhere(['id_user' => $model->id_user])->one(); if ($this->user->id_user_role == Dict::USER_ROLE_CLIENT) { if ($model->id_user != $this->user->id) { throw new UnauthorizedHttpException("Sorry, you don't have permission to access this page."); } } else { if ($this->user->id_user_role == dict::USER_ROLE_ADVISOR) { $advisor = Advisor::findOne(['id_user' => $this->user->id_user]); $groups = AdvisorGroup::find()->andWhere(['id_advisor' => $advisor->id_advisor])->all(); $id_groups = []; foreach ($groups as $val) { $id_groups[] = $val->id_group; } // check if (!in_array($model->id_group, $id_groups)) { throw new UnauthorizedHttpException("Sorry, you don't have permission to access this page."); } } } //validate email if (Yii::$app->request->isAjax && $userModel->load(Yii::$app->request->post())) { Yii::$app->response->format = Response::FORMAT_JSON; return ActiveForm::validate($userModel); } if ($model->load(Yii::$app->request->post()) && $userModel->load(Yii::$app->request->post())) { $arr = ['User' => $_POST['User'], 'Client' => $_POST['Client']]; $result = $userModel->UserUpdate($this->_roleId, $arr, $id); if ($result) { return $this->redirect(['index']); } else { return $this->render('update', ['model' => $model, 'userModel' => $userModel]); } } else { return $this->render('update', ['model' => $model, 'userModel' => $userModel]); } }
/** * Finds the Advisor model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Advisor the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Advisor::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }