From 2610ba397b8eb7a26e11a91860e46b8ed2ad4550 Mon Sep 17 00:00:00 2001 From: "venbatechnologies@gmail.com" Date: Fri, 31 May 2019 11:17:24 +0530 Subject: [PATCH] validation msg : ps --- .../other-income/other-income.component.ts | 96 ++++++++++++------- 1 file changed, 62 insertions(+), 34 deletions(-) diff --git a/ng6-seed/src/app/personal-discussion/manage-pd/list-pd/start-pd/forms/other-income/other-income.component.ts b/ng6-seed/src/app/personal-discussion/manage-pd/list-pd/start-pd/forms/other-income/other-income.component.ts index e38e5f79b..2404c6f6e 100755 --- a/ng6-seed/src/app/personal-discussion/manage-pd/list-pd/start-pd/forms/other-income/other-income.component.ts +++ b/ng6-seed/src/app/personal-discussion/manage-pd/list-pd/start-pd/forms/other-income/other-income.component.ts @@ -26,6 +26,9 @@ import { ActivatedRoute, Router } from '@angular/router'; import { RentalVerificationComponent } from './../rental-verification/rental-verification.component'; +/**sweet alert */ +import Swal from 'sweetalert2'; + @Component({ selector: 'app-other-income', templateUrl: './other-income.component.html', @@ -58,7 +61,6 @@ export class OtherIncomeComponent implements OnInit { mergeCompanyApplicant: any = []; isIncomeEarnedBy: any = []; // stringArr = []; - constructor(notifier: NotifierService, private fb: FormBuilder, private route: ActivatedRoute, @@ -301,6 +303,10 @@ export class OtherIncomeComponent implements OnInit { } let records: any = {}; + let rentOptionCount: number = 0; + let validateFlag: number = 0; + // let zeroEntries + records.parent_pdid = this.parent_pdid; records.pdid = this.pdid; records.formid = this.form_id; @@ -308,45 +314,68 @@ export class OtherIncomeComponent implements OnInit { records.other_income = this.otherIncomeForm.controls['other_income'].value; records.otherincome_remarks = this.otherIncomeForm.controls['otherincome_remarks'].value; - - if (this.otherIncomeForm.controls['other_income'].value == 'Yes') { records.income_details = this.otherIncomeForm.controls['income_details'].value; - - let s: number = 0; - let rentOptionCount: number = 0; - records.income_details.forEach(option => { - console.log(option); - console.log(option.source); - if (+option.source == 5) { - rentOptionCount++; - console.log(option.source); - let params: any = {}; - params.parent_pdid = this.parent_pdid; - params.pd_id = this.pdid; - params.pd_form_id = this.rental_form_id; - this._pd.retriveForm(params).subscribe(data => { - data.dataStatus == false ? s = 1 : s = 0; - console.log(s); - if(s == 1){ - this.notifier.notify('warning', "You have choose "+ rentOptionCount +" rent option but you didn't fill the rental verification form please fill it"); - s = 0; - rentOptionCount = 0; - return; - } - - }); - } + if (+option.source == 5) { + rentOptionCount++; + validateFlag = 1; + } }); - if(s == 1){ - this.notifier.notify('warning', "You have choose "+ rentOptionCount +" rent option but you didn't fill the rental verification form please fill it"); - s = 0; - rentOptionCount = 0; - return; + + if(validateFlag == 1){ + let params: any = {}; + let textMessage : any; + params.parent_pdid = this.parent_pdid; + params.pd_id = this.pdid; + params.pd_form_id = this.rental_form_id; + this._pd.retriveForm(params).subscribe(data => { + if(!data.dataStatus){ + let text : any = rentOptionCount > 1 ? rentOptionCount + ' properties' : rentOptionCount + ' property' ; + // this.notifier.notify('warning', "You have chosen "+ rentOptionCount +" properties as rental income, but rental verification form is not filled"); + textMessage = '
You have chosen '+ text +' as rental income, but rental verification form is not filled
'; + Swal({ + title: 'Please Confirm', + type: 'info', + html: textMessage, + showCancelButton: true, + confirmButtonColor: '#3085d6', + cancelButtonColor: '#d33', + confirmButtonText: 'Confirm', + // cancelButtonText:'Cancel And Correct', + }).then((result) => { + if (result.value) { + console.log('rental data status is true',validateFlag); + this.saveAPI(records); + } + else{ + console.log('rental data status is true',validateFlag); + // rentOptionCount = 0; + // validateFlag = 0 ; + return; + } + }) + rentOptionCount = 0; + validateFlag = 0 ; + } + else if(data.dataStatus){ + console.log('rental data status is true',validateFlag); + this.saveAPI(records); + } + }); + } + else{ + console.log('now flag is zero',validateFlag); + this.saveAPI(records); } } + else{ + console.log('now option is no',validateFlag); + this.saveAPI(records); + } + } + saveAPI(records){ this._pd.saveForm(records).subscribe(data => { if (data.status == 200) { this.notifier.notify('success', 'Saved Successfully.'); @@ -361,7 +390,6 @@ export class OtherIncomeComponent implements OnInit { this.notifier.notify('warning', 'Something Wents Wrong Try Again.!' + '-' + error.error_text + ' occur'); }) } - validateAllFormFields(formGroup: any) { Object.keys(formGroup.controls).forEach(field => { const control = formGroup.get(field);