pd changes

This commit is contained in:
gandhimathi 2018-09-27 18:01:40 +05:30
parent 0b093503a3
commit beb703e938
4 changed files with 334 additions and 169 deletions

View File

@ -1,5 +1,5 @@
<mat-card class="p-1"> <mat-card class="p-1">
<form [formGroup]="PDtriggerForm" (submit)="submitPdDetails()"> <form [formGroup]="PDtriggerForm" (submit)="submitPdDetails(PDtriggerForm.value)">
<mat-card-content> <mat-card-content>
<div class="mb-2"></div> <div class="mb-2"></div>
<div fxLayout="row" fxLayoutWrap="wrap"> <div fxLayout="row" fxLayoutWrap="wrap">
@ -66,16 +66,16 @@
<input matInput placeholder="Loan Amount" [formControl]="PDtriggerForm.controls['loan_amount']"> <input matInput placeholder="Loan Amount" [formControl]="PDtriggerForm.controls['loan_amount']">
</mat-form-field> </mat-form-field>
<mat-form-field style="width: 100%"> <mat-form-field style="width: 100%">
<input matInput placeholder="Address 1" [formControl]="PDtriggerForm.controls['addressline1']"> <textarea matInput placeholder="Address 1" [formControl]="PDtriggerForm.controls['addressline1']"></textarea>
</mat-form-field> </mat-form-field>
<mat-form-field style="width: 100%"> <mat-form-field style="width: 100%">
<input matInput placeholder="Address 2" [formControl]="PDtriggerForm.controls['addressline2']"> <textarea matInput placeholder="Address 2" [formControl]="PDtriggerForm.controls['addressline2']"></textarea>
</mat-form-field> </mat-form-field>
<mat-form-field style="width: 100%"> <mat-form-field style="width: 100%">
<input matInput placeholder="Address 3" [formControl]="PDtriggerForm.controls['addressline3']"> <textarea matInput placeholder="Address 3" [formControl]="PDtriggerForm.controls['addressline3']"></textarea>
</mat-form-field> </mat-form-field>
<mat-form-field style="width: 100%;"> <mat-form-field style="width: 100%;">
<mat-select placeholder="Select City" [formControl]="PDtriggerForm.controls['fk_city']" > <mat-select placeholder="Select City" [formControl]="PDtriggerForm.controls['fk_city']" >
@ -146,19 +146,51 @@
</div> </div>
<div fxLayout="row" fxLayoutWrap="wrap"> <div fxLayout="row" fxLayoutWrap="wrap">
<div class="column" fxFlex.xs="100" fxFlex.sm="100" fxFlex.md="30" fxFlex.lg="50" fxFlex.xl="30"> <div class="column" fxFlex.xs="100" fxFlex.sm="100" fxFlex.md="100" fxFlex.lg="100" fxFlex.xl="100">
<mat-card class="p-2" style="opacity: 0.5;"> <mat-card class="p-2" style="opacity: 0.5;">
<!-- <button _ngcontent-c29="" class="mr-1 mb-2 mat-fab1 mat-accent" mat-fab="" (click)="addCoApplicant(createWithLongContent)"><span class="mat-button-wrapper"><mat-icon _ngcontent-c29="" class="mat-icon material-icons" role="img" aria-hidden="true">add</mat-icon></span><div class="mat-button-ripple mat-ripple mat-button-ripple-round" matripple=""></div><div class="mat-button-focus-overlay"></div></button> --> <!-- <button _ngcontent-c29="" class="mr-1 mb-2 mat-fab1 mat-accent" mat-fab="" (click)="addCoApplicant(createWithLongContent)"><span class="mat-button-wrapper"><mat-icon _ngcontent-c29="" class="mat-icon material-icons" role="img" aria-hidden="true">add</mat-icon></span><div class="mat-button-ripple mat-ripple mat-button-ripple-round" matripple=""></div><div class="mat-button-focus-overlay"></div></button> -->
<button _ngcontent-c39="" class="mr-1 mb-1 mat-button" mat-button=""><span style="opacity: 0.5;" (click)="addCoApplicant()" class="mat-button-wrapper">Add More Co-Applicant</span><div class="mat-button-ripple mat-ripple" matripple=""></div><div class="mat-button-focus-overlay"></div></button> <button _ngcontent-c39="" class="mr-1 mb-1 mat-button" type="button"><span style="opacity: 0.5;" (click)="addCoApplicant()" class="mat-button-wrapper">Add More Co-Applicant</span><div class="mat-button-ripple mat-ripple" matripple=""></div><div class="mat-button-focus-overlay"></div></button>
<!-- <button mat-raised-button mat-button-sm color="primary" (click)="addCoApplicant()" type="button">Add More Co-Applicant</button> -->
</mat-card> </mat-card>
</div> </div>
</div> </div>
<div fxLayout="row" fxLayoutWrap="wrap">
<div class="column" fxFlex.xs="100" fxFlex.sm="100" fxFlex.md="100" fxFlex.lg="100" fxFlex.xl="100">
<mat-card class="p-2" formArrayName="documents">
<mat-list>
<mat-list-item>
<!-- <button mat-raised-button mat-button-sm color="primary" type="button">Add Document</button> -->
<button _ngcontent-c39="" class="mr-1 mb-1 mat-button" type="button"><span style="opacity: 0.5;" (click)="addMoreDocs()" class="mat-button-wrapper">Add Document</span><div class="mat-button-ripple mat-ripple" matripple=""></div><div class="mat-button-focus-overlay"></div></button>
</mat-list-item>
</mat-list>
<mat-list *ngFor="let docList of documents.controls; let d = index;" [formGroupName]="d">
<!-- <h3 mat-subheader>Upload Documents</h3> -->
<mat-list-item>
<mat-form-field style="width: 100%">
<input matInput placeholder="Document Name" formControlName="doc_name" type="text">
</mat-form-field>
</mat-list-item>
<mat-list-item>
<input type="file" title="Browse Document" (change)="fileSelectionEvent($event,d)" formControlName="documentFile">
</mat-list-item>
<mat-list-item>
<button mat-raised-button mat-button-sm color="accent" (click)="removeItem(d)" type="button">Remove</button>
</mat-list-item>
</mat-list>
</mat-card>
</div>
</div>
</mat-card-content> </mat-card-content>
<mat-card-actions> <mat-card-actions>
<button mat-raised-button color="primary" type="submit" [disabled]="!PDtriggerForm.valid">Submit</button> <button mat-raised-button color="primary" type="submit" [disabled]="!PDtriggerForm.valid">Submit</button>
</mat-card-actions> </mat-card-actions>
</form> </form>
</mat-card> </mat-card>

View File

@ -2,6 +2,7 @@ import { Component, OnInit, ViewEncapsulation } from '@angular/core';
import { FormBuilder, FormGroup, Validators, FormControl, FormArray } from '@angular/forms'; import { FormBuilder, FormGroup, Validators, FormControl, FormArray } from '@angular/forms';
import { CustomValidators } from 'ng2-validation'; import { CustomValidators } from 'ng2-validation';
import { PdTrigerService } from '../pd-service/pd-triger.service'; import { PdTrigerService } from '../pd-service/pd-triger.service';
import { AwsService } from '../../AwsService/aws.service';
@Component({ @Component({
selector: 'app-add-pd', selector: 'app-add-pd',
@ -25,10 +26,14 @@ export class AddPdComponent implements OnInit {
// Dynamic co applicant // Dynamic co applicant
createWithLongContent = false; createWithLongContent = false;
dynamicCoApplicant = []; dynamicCoApplicant = [];
constructor(private _fb: FormBuilder,
private _pd: PdTrigerService) { }
constructor(private _fb: FormBuilder,
private _pd: PdTrigerService, private _aws:AwsService) { }
public totalfiles: Array<File> =[];
public totalFileName = [];
public lengthCheckToaddMore =0;
ngOnInit() { ngOnInit() {
this.PDtriggerForm = this._fb.group({ this.PDtriggerForm = this._fb.group({
fk_lender_id: [null, Validators.compose([Validators.required])], fk_lender_id: [null, Validators.compose([Validators.required])],
lender_applicant_id: [null, Validators.compose([Validators.required])], lender_applicant_id: [null, Validators.compose([Validators.required])],
@ -36,7 +41,7 @@ export class AddPdComponent implements OnInit {
fk_subproduct_id: [null, Validators.compose([Validators.required])], fk_subproduct_id: [null, Validators.compose([Validators.required])],
fk_pd_type: [null, Validators.compose([Validators.required])], fk_pd_type: [null, Validators.compose([Validators.required])],
fk_customer_segment: [null, Validators.compose([Validators.required])], fk_customer_segment: [null, Validators.compose([Validators.required])],
loan_amount: [null], loan_amount: [null, Validators.compose([Validators.required])],
applicant_name: [null, Validators.compose([Validators.required])], applicant_name: [null, Validators.compose([Validators.required])],
mobile_no: [null, Validators.compose([Validators.required])], mobile_no: [null, Validators.compose([Validators.required])],
email: [null, Validators.compose([Validators.required, CustomValidators.email])], email: [null, Validators.compose([Validators.required, CustomValidators.email])],
@ -45,8 +50,9 @@ export class AddPdComponent implements OnInit {
addressline3: [null], addressline3: [null],
fk_city: [null, Validators.compose([Validators.required])], fk_city: [null, Validators.compose([Validators.required])],
fk_state: [null, Validators.compose([Validators.required])], fk_state: [null, Validators.compose([Validators.required])],
  pincode : [null],   pincode : [null, Validators.compose([Validators.required])],
items: this._fb.array([]) items: this._fb.array([]),
documents: this._fb.array([])
}); });
this._pd.getAllMasterDatas('CITY') this._pd.getAllMasterDatas('CITY')
@ -142,11 +148,132 @@ this._pd.getAllMasterDatas('PDTYPE')
this.items.push(this.createItem()); this.items.push(this.createItem());
} }
} }
submitPdDetails() {
if(this.PDtriggerForm.valid){ addMoreDocs() {
var my_array = this.PDtriggerForm.value; if(this.totalfiles.length!=0){
Object.keys(my_array).forEach((key) => ( my_array[key] == null) && delete my_array[key]);
if( this.documents.value[0].doc_name != "" && ((this.lengthCheckToaddMore) === (this.totalfiles.length)) )
{
this.documents.insert(0, this.generateDocuments())
this.lengthCheckToaddMore=this.lengthCheckToaddMore+1;
} }
} }
else if(this.totalfiles.length===0 && this.lengthCheckToaddMore===0){
this.documents.insert(0, this.generateDocuments())
this.lengthCheckToaddMore=this.lengthCheckToaddMore+1;
}
}
generateDocuments(): FormGroup {
return this._fb.group({
doc_name: [null, Validators.compose([Validators.required])],
documentFile : [null, Validators.compose([Validators.required])],
});
}
get documents(): FormArray {
return this.PDtriggerForm.get('documents') as FormArray;
};
removeItem(index: number) {
this.totalfiles.splice(index,1);
this.totalFileName.splice(index,1);
this.documents.removeAt(index);
this.lengthCheckToaddMore=this.lengthCheckToaddMore-1;
}
public fileSelectionEvent(fileInput: any,oldIndex:number) {
if (fileInput.target.files && fileInput.target.files[0]) {
var reader = new FileReader();
reader.onload = (event: any) => {
}
if(oldIndex==0)
{
this.totalfiles.unshift((fileInput.target.files[0]))
this.totalFileName.unshift(fileInput.target.files[0].name)
}
else
{
this.totalfiles[oldIndex]=(fileInput.target.files[0]);
this.totalFileName[oldIndex]=fileInput.target.files[0].name
}
reader.readAsDataURL(fileInput.target.files[0]);
}
if(this.totalfiles.length == 1)
{
this.lengthCheckToaddMore=1;
}
}
submitPdDetails(formValue: any) {
if(this.PDtriggerForm.valid){
// let my_array = this.PDtriggerForm.value;
// Object.keys(my_array).forEach((key) => ( my_array[key] == null) && delete my_array[key]);
let pd_details:any={
"fk_lender_id":formValue.fk_lender_id,
"lender_applicant_id":formValue.lender_applicant_id,
"fk_product_id":formValue.fk_product_id.product_id,
"fk_subproduct_id":formValue.fk_subproduct_id.subproduct_id,
"fk_pd_type":formValue.fk_pd_type,
"fk_customer_segment":formValue.fk_customer_segment,
"loan_amount":formValue.loan_amount,
"addressline1":formValue.addressline1,
"addressline2":formValue.addressline2,
"addressline3":formValue.addressline3,
"fk_city":formValue.fk_city.city_id,
"fk_state":formValue.fk_state.state_id,
"pincode ":formValue.pincode ,
"fk_createdby" : this._aws.getlocale(),
"createdon": new Date().toJSON().slice(0,19).replace('T',' ')
};
let pd_applicant_details : any=[{
"applicant_name":formValue.applicant_name,
"email":formValue.email,
"mobile_no":formValue.mobile_no,
"applicant_type":1,
"relationship":"",
}];
formValue.items.forEach((itemElement, itemIndex) => {
let obj1 = {
"applicant_name":itemElement.coapplicantName,
"relationship":itemElement.relationship,
"email":"",
"mobile_no":"",
"applicant_type":0,
}
pd_applicant_details.push(obj1)
});
// docs details
let pd_form: FormData = new FormData();
for(let j=0;j<this.totalfiles.length; j++)
{
pd_form.append(this.totalFileName[j],<File>this.totalfiles[j])
}
//reverseFileNames=this.totalFileName.reverse();
let AllFilesObj= []
formValue.documents.forEach((element, index) => {
// let eachObj=
// {
// 'doc_name' : element.doc_name,
// 'file_name' : this.totalFileName[index]
// }
AllFilesObj.push(element.doc_name);
});
pd_form.append("pd_details",JSON.stringify(pd_details))
pd_form.append("pd_applicant_details",JSON.stringify(pd_applicant_details))
pd_form.append("pd_document_titles",JSON.stringify(AllFilesObj))
this._pd.addPdDetails(pd_form).subscribe();
}
}
} }

View File

@ -32,6 +32,12 @@ export class PdTrigerService {
catchError(this.handleError('role', [])) catchError(this.handleError('role', []))
) )
} }
addPdDetails(pdForm: any): Observable<any> {
return this._http.post<any>(this.apiUrl+"triggerNewPD", pdForm)
.pipe(
catchError(this.handleError('operation', []))
)
}
private handleError<T>(operation = 'operation', result?: T) { private handleError<T>(operation = 'operation', result?: T) {
return (error: any): Observable<T> => { return (error: any): Observable<T> => {

View File

@ -8,7 +8,7 @@ import {
MatRadioModule, MatRadioModule,
MatButtonModule,MatTableModule,MatPaginatorModule, MatButtonModule,MatTableModule,MatPaginatorModule,
MatProgressBarModule,MatDialogModule, MatSortModule, MatProgressBarModule,MatDialogModule, MatSortModule,
MatToolbarModule,MatSelectModule } from '@angular/material'; MatToolbarModule,MatSelectModule, MatListModule } from '@angular/material';
import {MatSlideToggleModule} from '@angular/material/slide-toggle'; import {MatSlideToggleModule} from '@angular/material/slide-toggle';
import { FormsModule, ReactiveFormsModule } from '@angular/forms'; import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { FileUploadModule } from 'ng2-file-upload/ng2-file-upload'; import { FileUploadModule } from 'ng2-file-upload/ng2-file-upload';
@ -39,7 +39,7 @@ import { PdTrigerService } from './pd-service/pd-triger.service';
FlexLayoutModule, FlexLayoutModule,
NgxDatatableModule, NgxDatatableModule,
FormsModule,MatSlideToggleModule, FormsModule,MatSlideToggleModule,
MatSelectModule, MatSelectModule, MatListModule,
ReactiveFormsModule, ReactiveFormsModule,
FileUploadModule, FileUploadModule,
TreeModule, TreeModule,