function actionIndex($id_application) { //$id_app_owner_task actually is $id_application //$model = AppOwnerTask::findOne($id_app_owner_task); $UploadModel = new AppDocument(); if (Yii::$app->request->isPost) { $type = intval(Yii::$app->request->post()['AppDocument']['id_document_type']); //$result = Upload::getFileUpload($id_application, $id_application, $type); $result = Upload::uploadFileByApplication($id_application, $_FILES['AppDocument']['tmp_name']['path'], $_FILES['AppDocument']['name']['path'], $type); //$model->appTask->id_application if (!empty($result)) { //delete the same file before upload a new one /* $app_document = AppDocument::find()->andWhere(['id_application' => $id_application,'name' => $result['file_name'],'id_document_type' => $type])->one(); if (!empty($app_document)) { $app_document->delete = 1; $app_document->save(); } $UploadModel->id_application = $id_application; $UploadModel->path = $result['url']; $UploadModel->name = $result['file_name']; $UploadModel->id_document_type = $type; $UploadModel->save(); */ //if ($UploadModel->save()) { //$id_app_owner_task actually is $id_application //active log (betterdebt upload documents file) foreach (DictDocument::$documentType as $key => $val) { switch ($type) { case $key: Active::operationLog($id_application, [Yii::$app->user->getIdentity()->first_name, Yii::$app->user->getIdentity()->last_name, DictDocument::$documentType[$type]], DictActive::USER_UPLOAD_FILE, Yii::$app->user->getIdentity()->id); break; } } echo "<script text='javascript'>alert('Upload Success!');history.go(-1) </script>"; } else { echo "<script text='javascript'>alert('Failed,Please try again!');history.go(-1) </script>"; } //} } }
public static function createLineAgreementPdfByApplication($application) { $primaryAppApplicant = $application->primaryAppApplicant; $coAppApplicant = $application->coAppApplicant; $primarySupernova = $application->primarySupernova; $collateralAccounts = $application->collateralAccounts; $dataJson = json_decode(file_get_contents('../../common/pdf-template/data/data_app_agreements.json'), true); $dataJson['loan_number'] = $application->loan->loan_number; $dataJson['date_month_day'] = date('M. d'); $dataJson['date_year'] = date('y'); $dataJson['print_a_name'] = $primaryAppApplicant->first_name . ' ' . $primaryAppApplicant->last_name; $dataJson['print_co_name'] = $coAppApplicant ? $coAppApplicant->first_name . ' ' . $coAppApplicant->last_name : ''; $dataJson['print_pledgor_name'] = $primarySupernova->first_name . ' ' . $primarySupernova->last_name; $dataJson['print_copledgor_name'] = $coAppApplicant ? $primarySupernova->first_name . ' ' . $primarySupernova->last_name : ''; $dataJson['bd_by'] = $primarySupernova->first_name . ' ' . $primarySupernova->last_name; $dataJson['bd_name'] = $primarySupernova->first_name . ' ' . $primarySupernova->last_name; $dataJson['bd_title'] = 'Loan Officer'; if ($collateralAccounts) { $dataJson['accounts'] = []; foreach ($collateralAccounts as $collateralAccount) { $dataJson['accounts'][] = ['account_name' => $collateralAccount->account_name_title, 'account_number' => $collateralAccount->account_number]; } } if ($applicationModel->charge_fee) { $document = new Document("../../common/pdf-template/config/config_app_agreements.json", $dataJson, "../../common/pdf-template/", Yii::$app->params['outpdfPath'] . $application->id_application . "_loan_agreements.pdf", Yii::$app->params['outpdfPath'] . $application->id_application . "_signaure_spec_loan_agreements.json"); } else { $document = new Document("../../common/pdf-template/config/config_app_agreements.json", $dataJson, "../../common/pdf-template/nofee/", Yii::$app->params['outpdfPath'] . $application->id_application . "_loan_agreements.pdf", Yii::$app->params['outpdfPath'] . $application->id_application . "_signaure_spec_loan_agreements.json"); } $document->render(); $result = Upload::uploadFileByApplication($application->id_application, Yii::$app->params['outpdfPath'] . $application->id_application . '_loan_agreements.pdf', 'loan_agreements.pdf', DictDocument::TYPE_LINE_AGREEMENT); }
/** * Deletes an existing Application model. * If deletion is successful, the browser will be redirected to the 'index' page. * @param integer $id * @return mixed */ public function actionIndex() { $documents_type = ['app_form.pdf' => DictDocument::TYPE_APPLICATION_FORM, 'loan_agreements.pdf' => DictDocument::TYPE_LINE_AGREEMENT, 'g3.pdf' => DictDocument::TYPE_G3, 'w9.pdf' => DictDocument::TYPE_W9]; // log Yii::getLogger()->log(date("Y-m-d h:i:s", time()) . ' - 开始一次定时任务', Logger::LEVEL_ERROR); $dir = Yii::$app->params['outpdfPath']; $envelopes_data = DocusignRecipient::find()->andWhere(['status' => 0])->all(); $envelopes = []; foreach ($envelopes_data as $val) { $envelopes[] = $val->id_envelope; } $envelopes = array_unique($envelopes); if (count($envelopes) > 0) { // DocuSign $client = new DocuSign_Client(); $service = new DocuSign_StatusService($client); // Status foreach ($envelopes as $id_envelope) { $response = $service->status->getRecipientsStatus($id_envelope); $signers = $response->signers; foreach ($signers as $val) { if ($val->status == 'completed') { // DocusignRecipient $recipient = DocusignRecipient::find()->andWhere(['email' => $val->email, 'id_envelope' => $id_envelope])->one(); $user = User::findOne($recipient->id_user); if (isset($recipient) && isset($user) && $recipient->status == 0) { // 获取在线文件 $task = AppTask::findOne($recipient->id_app_task); //active log after E-signed documents switch ($task->id_app_task_type) { case DictTask::TYPE_SIGN_APPLICATION_FORM: Active::operationLog($recipient->id_application, [$user->first_name, $user->last_name, DictTask::$taskType[DictTask::TYPE_APPLICATION_FORM]], DictActive::USER_DOCSIGNED_TASK, $user->id_user); break; case DictTask::TYPE_SIGN_AGREEMENTS: Active::operationLog($recipient->id_application, [$user->first_name, $user->last_name, DictTask::$taskType[DictTask::TYPE_LINE_AGREEMENTS]], DictActive::USER_DOCSIGNED_TASK, $user->id_user); break; } $service_document = new DocuSign_EnvelopeService($client); $document_all = $service_document->envelope->getEnvelopeDocuments($id_envelope); foreach ($document_all->envelopeDocuments as $document) { if ($document->type == 'content') { Yii::getLogger()->log(date("Y-m-d h:i:s", time()) . ' - 将' . $user->first_name . '.' . $user->last_name . '(id_user:'******')' . '-的签名改为已完成-' . $id_envelope, Logger::LEVEL_ERROR); $file = $dir . $recipient->id_application . '_' . $document->name; // 删除旧文件 if (file_exists($file)) { unlink($file); } // 读取 Docusign 新文件 $content = $service_document->envelope->getEnvelopeDocuments($id_envelope, $document->documentId); // 写入文件 $fp = @fopen($file, 'a'); fwrite($fp, $content); fclose($fp); // 上传 document $id_document_type = $documents_type[$document->name]; $result = Upload::uploadFileByApplication($recipient->id_application, $file, $document->name, $id_document_type); if ($result) { //delete local file $outpdf_file = $dir . $recipient->id_application . '_' . $document->name; if (file_exists($outpdf_file)) { unlink($outpdf_file); } //active log (0:present send by System) foreach (DictDocument::$documentType as $key => $val) { switch ($id_document_type) { case $key: Active::operationLog($recipient->id_application, [$val], DictActive::SYSTEM_UPDATED_TASK_WITH_SIGNATURE, 0); break; } } } } } // 变更 DocusignRecipient Status $recipient->status = 1; $recipient->save(false); // 变更 Task Status Yii::getLogger()->log(date("Y-m-d h:i:s", time()) . ' - 变更 task status (id_app_task:' . $recipient->id_app_task . ')', Logger::LEVEL_ERROR); if (AppTask::taskFinish($recipient->id_app_task)) { //再次查询task (finish之后的appTask,每次子task完成之后会相应的改变父类task的status) $after_task = AppTask::findOne($recipient->id_app_task); $parent_status = $after_task->parent->status; if ($parent_status == DictTask::STATUS_FINISH) { //find user $user = SendEmail::findUserByApplication($recipient->id_application); if ($after_task->parent->id_app_task_type == DictTask::TYPE_SIGN_APPLICATION_FORM_BOX) { //system created a task 'Review Application' to loan officer Active::operationLog($recipient->id_application, [DictTask::$taskType[DictTask::TYPE_APPLICATION_REVIEW], $user['supernova']->first_name, $user['supernova']->last_name], DictActive::SYSTEM_CREATE_TASK_TO_USER, 0); //send email to supernova start task Application Review SendEmail::email(DictEmail::EMAIL_TASK_NOTIFICATION, [DictTask::TYPE_APPLICATION_REVIEW, $recipient->id_application, $after_task->parent->id_app_task, DictTask::DOCUSIGN_NOTIFICATION]); } elseif ($after_task->parent->id_app_task_type == DictTask::TYPE_SIGN_AGREEMENTS_BOX) { //active log.system closed the task 'line Agreement' Active::operationLog($recipient->id_application, [DictTask::$taskType[DictTask::TYPE_LINE_AGREEMENTS]], DictActive::SYSTEM_CLOSED_TASK, 0); //active log. system create task line set-up and assign to client/advisor Active::operationLog($recipient->id_application, [DictTask::$taskType[DictTask::TYPE_LINE_SETUP], $user['supernova']->first_name, $user['supernova']->last_name], DictActive::SYSTEM_CREATE_TASK_TO_USER, 0); //system created task line-setup //send email to supernova start task Line Setup SendEmail::email(DictEmail::EMAIL_TASK_NOTIFICATION, [DictTask::TYPE_LINE_SETUP, $recipient->id_application, $after_task->parent->id_app_task, DictTask::DOCUSIGN_NOTIFICATION]); } } } } } } } } Yii::getLogger()->log(date("Y-m-d h:i:s", time()) . ' - 完成 ---------------------', Logger::LEVEL_ERROR); }
public function actionWetSign($id_app_task) { $model = AppTask::findOne($id_app_task); $result = $model->application->checkAppForm(); if ($result['errorCount']) { return $this->renderAjax('wet_sign_errors', ['model' => $model, 'result' => $result]); } $UploadModel = new AppDocument(); $WetSignForm = new WetSignForm(); if (Yii::$app->request->isPost) { $type = intval(Yii::$app->request->get('type')); $id = $this->user->id; //$result = Upload::getFileUpload($id_app_task,$model->id_application,$type); $result = Upload::uploadFileByApplication($model->id_application, $_FILES['WetSignForm']['tmp_name']['wet_sign_path'], $_FILES['WetSignForm']['name']['wet_sign_path'], $type); if (!empty($result['url'])) { //upload success /* $UploadModel->id_application = $model->id_application; $UploadModel->path = $result['url']; $UploadModel->name = $result['file_name']; $UploadModel->id_document_type = $type; $UploadModel->save(); */ //关闭sign application form //完成app form 任务 AppTask::taskFinish($model->id_app_task); $task_wet_sign = AppTask::findOne(['id_application' => $model->id_application, 'id_app_task_type' => DictTask::TYPE_UPLOAD_WETSIGNED_FORM]); $task_wet_sign->active = DictTask::ACTIVE; $task_wet_sign->save(); $task_wet_sign->nextStart($task_wet_sign->id_app_task); $task_e_sign_box = AppTask::findOne(['id_application' => $model->id_application, 'id_app_task_type' => DictTask::TYPE_SIGN_APPLICATION_FORM_BOX]); AppTask::close($task_e_sign_box->id_app_task); AppTask::taskFinish($task_wet_sign->id_app_task); //active log. client upload wet-signed app-form $user = SendEmail::findUserByApplication($model->id_application); //log.client uploaded wetsigned app-form Active::operationLog($model->id_application, [Yii::$app->user->getIdentity()->first_name, Yii::$app->user->getIdentity()->last_name, DictTask::$taskType[DictTask::TYPE_APPLICATION_FORM]], DictActive::USER_UPLOADED_WET_SIGNED_FILE, Yii::$app->user->getIdentity()->id_user); /* $eSignTasks = AppTask::getTaskByType($model->id_application, 2); foreach ($eSignTasks as $task) { $task->delete = Dict::DELETE_YES; $task->save(false); } */ //将 Upload WetSigned Form任务状态改为正常 /* $wet_task = AppTask::getTaskByType($model->id_application, 3); $wet_task[0]['delete'] = Dict::DELETE_NOT; $wet_task[0]->save(false); */ //结束Application Form 任务 //AppTask::taskFinish($id_app_task); //结束 Upload WetSigned Form任务 //AppTask::taskFinish($id_app_task); //active log. system create task supplemental-materials and assign to advisor Active::operationLog($model->id_application, [DictTask::$taskType[DictTask::TYPE_SUPPLEMENTAL_MATERIALS], $user['advisor']->first_name, $user['advisor']->last_name], DictActive::SYSTEM_CREATE_TASK_TO_USER, 0); //System send email new task “Supplemental materials Notification” to client SendEmail::email(DictEmail::EMAIL_TASK_NOTIFICATION, [DictTask::TYPE_SUPPLEMENTAL_MATERIALS, $model->id_application, $id_app_task + 2]); //id_app_task_type:1(app-form);0:表示没有传递id_app_task //active log (create task Application Review to loan officer) Active::operationLog($model->id_application, [DictTask::$taskType[DictTask::TYPE_APPLICATION_REVIEW], $user['supernova']->first_name, $user['supernova']->last_name], DictActive::SYSTEM_CREATE_TASK_TO_USER, 0); //System send email new task "Application Review Notification" to betterdebt SendEmail::email(DictEmail::EMAIL_TASK_NOTIFICATION, [DictTask::TYPE_APPLICATION_REVIEW, $model->id_application, $id_app_task]); //id_app_task_type:1(app-form);0:表示没有传递id_app_task } if (Yii::$app->user->getIdentity()->id_user_role == Dict::USER_ROLE_CLIENT) { return $this->redirect(['loan/application']); } else { return $this->redirect(['application/view', 'id' => $model->id_application]); } } return $this->renderAjax('upload_websigned_form', ['WetSignForm' => $WetSignForm, 'id_app_task' => $id_app_task]); }
public function actionIndex($id_app_task) { $model = AppTask::findOne($id_app_task); $UploadModel = new AppDocument(); if (Yii::$app->request->isPost) { $type = intval(Yii::$app->request->post()['AppDocument']['id_document_type']); //$result = Upload::getFileUpload($id_app_task, $model->id_application, $type); $result = Upload::uploadFileByApplication($model->id_application, $_FILES['AppDocument']['tmp_name']['path'], $_FILES['AppDocument']['name']['path'], $type); if (!empty($result)) { //delete the same file before upload a new one /* $app_document = AppDocument::find()->andWhere(['id_application' => $model->id_application,'name' => $result['file_name'],'id_document_type' => $type])->one(); if (!empty($app_document)) { $app_document->delete = Dict::DELETE_YES; $app_document->save(); } $UploadModel->id_application = $model->id_application; $UploadModel->path = $result['url']; $UploadModel->name = $result['file_name']; $UploadModel->id_document_type = $type; if ($UploadModel->save()) { */ //find by document type // $loanStatements = AppDocument::find()->andWhere(['id_document_type' => DictDocument::TYPE_LOAN_STATEMENT, 'id_application'=>$model->id_application])->orderBy(['id_app_document' => SORT_DESC])->all(); // $accountStatements = AppDocument::find()->andWhere(['id_document_type' => DictDocument::TYPE_ACCOUNT_STATEMENT, 'id_application'=>$model->id_application])->orderBy(['id_app_document' => SORT_DESC])->all(); // $photos = AppDocument::find()->andWhere(['id_document_type' => DictDocument::TYPE_PHOTO_ID, 'id_application'=>$model->id_application])->orderBy(['id_app_document' => SORT_DESC])->all(); // $certification = AppDocument::find()->andWhere(['id_document_type' => DictDocument::TYPE_TRUSTEE_CERTIFICATION, 'id_application'=>$model->id_application])->orderBy(['id_app_document' => SORT_DESC])->all(); //active log (client upload supplementalinformation) foreach (DictDocument::$documentType as $key => $val) { switch ($type) { case $key: Active::operationLog($model->id_application, [Yii::$app->user->getIdentity()->first_name, Yii::$app->user->getIdentity()->last_name, DictDocument::$documentType[$type]], DictActive::USER_UPLOAD_FILE, Yii::$app->user->getIdentity()->id); break; } } } //render to index(exit submit) return $this->redirect(['task-supplemental-information/index', 'id_app_task' => $id_app_task]); } //find by document type $loanStatements = AppDocument::find()->andWhere(['id_document_type' => DictDocument::TYPE_LOAN_STATEMENT, 'id_application' => $model->id_application])->orderBy(['id_app_document' => SORT_DESC])->all(); $accountStatements = AppDocument::find()->andWhere(['id_document_type' => DictDocument::TYPE_ACCOUNT_STATEMENT, 'id_application' => $model->id_application])->orderBy(['id_app_document' => SORT_DESC])->all(); $photos = AppDocument::find()->andWhere(['id_document_type' => DictDocument::TYPE_PHOTO_ID, 'id_application' => $model->id_application])->orderBy(['id_app_document' => SORT_DESC])->all(); $certification = AppDocument::find()->andWhere(['id_document_type' => DictDocument::TYPE_TRUSTEE_CERTIFICATION, 'id_application' => $model->id_application])->orderBy(['id_app_document' => SORT_DESC])->all(); // check $finished_ctrl = true; if (count($accountStatements) > 0 && count($photos) > 0) { //check loan statements $application = Application::find()->andWhere(['id_application' => $model->id_application])->one(); if (!empty($application)) { if ($application->have_existing_loan == 1) { // no Loan Statement if (count($loanStatements) > 0) { $finished_ctrl = true; } else { $finished_ctrl = false; } } else { $finished_ctrl = true; } } else { $finished_ctrl = true; } //check trustee certification $list = AppFormCollateralAccount::find()->andWhere(['id_application' => $model->id_application])->one(); if (!empty($list)) { if ($list->is_trust_account == 1) { //no Trustee Certification if (count($certification) > 0) { $finished_ctrl = true; } else { $finished_ctrl = false; } } else { $finished_ctrl = true; } } else { $finished_ctrl = true; } } else { $finished_ctrl = false; } return $this->render('index', ['model' => $model, 'UploadModel' => $UploadModel, 'loanFile' => $loanStatements, 'accountFile' => $accountStatements, 'photoFile' => $photos, 'certificationFile' => $certification, 'finished_ctrl' => $finished_ctrl]); }
public function actionUploadWebSigned($id_app_task) { $model = AppTask::findOne($id_app_task); $UploadModel = new AppDocument(); if (Yii::$app->request->post()) { //upload signed file // $type = intval(Yii::$app->request->get('type')); $type = intval(Yii::$app->request->post()['AppDocument']['id_document_type']); //$result = Upload::getFileUpload($id_app_task, $model->id_application, $type); $result = Upload::uploadFileByApplication($model->id_application, $_FILES['AppDocument']['tmp_name']['path'], $_FILES['AppDocument']['name']['path'], $type, 1); if (!empty($result)) { //delete local file(in file outpdf) switch ($type) { case 5: $outpdf_file = Yii::getAlias('@frontend') . "/web/outpdf/" . $model->id_application . '_loan_agreements.pdf'; if (file_exists($outpdf_file)) { unlink($outpdf_file); } break; case 6: $outpdf_file = Yii::getAlias('@frontend') . "/web/outpdf/" . $model->id_application . '_g3.pdf'; if (file_exists($outpdf_file)) { unlink($outpdf_file); } break; case 7: $outpdf_file = Yii::getAlias('@frontend') . "/web/outpdf/" . $model->id_application . '_w9.pdf'; if (file_exists($outpdf_file)) { unlink($outpdf_file); } break; } //delete control file $collateral_account = AppFormCollateralAccount::find()->andWhere(['id_application' => $model->id_application])->one(); $outpdf_file = Yii::getAlias('@frontend') . "/web/outpdf/" . $model->id_application . '_control_agreement_schwab_' . $collateral_account['account_number'] . '.pdf'; if (file_exists($outpdf_file)) { unlink($outpdf_file); } //active log (supernova upload line-agreements file) foreach (DictDocument::$documentType as $key => $val) { switch ($type) { case $key: Active::operationLog($model->id_application, [Yii::$app->user->getIdentity()->first_name, Yii::$app->user->getIdentity()->last_name, DictDocument::$documentType[$type]], DictActive::USER_UPLOADED_WET_SIGNED_FILE, Yii::$app->user->getIdentity()->id); break; } } //render to index(exit submit) return $this->redirect(['task-agreements/index', 'id_app_task' => $id_app_task]); //delete the same file before upload a new one /* $app_document = AppDocument::find()->andWhere(['id_application' => $model->id_application,'name' => $result['file_name'],'id_document_type' => $type])->one(); if (!empty($app_document)) { $app_document->delete = Dict::DELETE_YES; $app_document->save(); } $UploadModel->id_application = $model->id_application; $UploadModel->path = $result['url']; $UploadModel->name = $result['file_name']; $UploadModel->id_document_type = $type; $UploadModel->source = 1; $UploadModel->save(); */ } //关闭sign agreements $task_e_sign_box = AppTask::findOne(['id_application' => $model->id_application, 'id_app_task_type' => DictTask::TYPE_SIGN_AGREEMENTS_BOX]); AppTask::close($task_e_sign_box->id_app_task); } //find the latest one by document type and id_application $loanAgreements = AppDocument::find()->andWhere(['id_document_type' => DictDocument::TYPE_LINE_AGREEMENT, 'id_application' => $model->id_application])->orderBy(['id_app_document' => SORT_DESC])->one(); $g3 = AppDocument::find()->andWhere(['id_document_type' => DictDocument::TYPE_G3, 'id_application' => $model->id_application])->orderBy(['id_app_document' => SORT_DESC])->one(); $w9 = AppDocument::find()->andWhere(['id_document_type' => DictDocument::TYPE_W9, 'id_application' => $model->id_application])->orderBy(['id_app_document' => SORT_DESC])->one(); // check $finished_ctrl = true; if ($loanAgreements->source == 1 && $g3->source == 1 && $w9->source == 1) { $finished_ctrl = true; } else { $finished_ctrl = false; } return $this->render('index', ['model' => $model, 'UploadModel' => $UploadModel, 'loanAgreements' => $loanAgreements, 'g3' => $g3, 'w9' => $w9, 'finished_ctrl' => $finished_ctrl]); }