diff --git a/src/app/deposits/recurring-deposits/recurring-deposits-account-view/custom-dialogs/recurring-deposit-confirmation-dialog/recurring-deposit-confirmation-dialog.component.ts b/src/app/deposits/recurring-deposits/recurring-deposits-account-view/custom-dialogs/recurring-deposit-confirmation-dialog/recurring-deposit-confirmation-dialog.component.ts index 683a3b764..ccd4c8dbe 100644 --- a/src/app/deposits/recurring-deposits/recurring-deposits-account-view/custom-dialogs/recurring-deposit-confirmation-dialog/recurring-deposit-confirmation-dialog.component.ts +++ b/src/app/deposits/recurring-deposits/recurring-deposits-account-view/custom-dialogs/recurring-deposit-confirmation-dialog/recurring-deposit-confirmation-dialog.component.ts @@ -1,6 +1,5 @@ import { Component, OnInit, Inject } from '@angular/core'; import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material'; -import { DeleteDialogComponent } from 'app/shared/delete-dialog/delete-dialog.component'; @Component({ selector: 'mifosx-recurring-deposit-confirmation-action', @@ -13,7 +12,7 @@ export class RecurringDepositConfirmationDialogComponent implements OnInit { * @param {MatDialogRef} dialogRef Component reference to dialog. * @param {any} data Provides a confirmation for all the recurring deposit actions. */ - constructor(public dialogRef: MatDialogRef, + constructor(public dialogRef: MatDialogRef, @Inject(MAT_DIALOG_DATA) public data: any) { } ngOnInit() { diff --git a/src/app/loans/common-resolvers/loan-action-button.resolver.ts b/src/app/loans/common-resolvers/loan-action-button.resolver.ts index c1e161a45..2161ad3e4 100644 --- a/src/app/loans/common-resolvers/loan-action-button.resolver.ts +++ b/src/app/loans/common-resolvers/loan-action-button.resolver.ts @@ -44,6 +44,10 @@ export class LoanActionButtonResolver implements Resolve { return this.loansService.getLoanActionTemplate(loanId, 'prepayLoan'); } else if (loanActionButton === 'recovery-payment') { return this.loansService.getLoanActionTemplate(loanId, 'recoverypayment'); + } else if (loanActionButton === 'view-guarantors') { + return this.loansService.getLoanAccountResource(loanId, 'guarantors'); + } else if (loanActionButton === 'create-guarantor') { + return this.loansService.getGuarantorTemplate(loanId); } else { return undefined; } diff --git a/src/app/loans/loans-account-add-collateral-dialog/loans-account-add-collateral-dialog.component.html b/src/app/loans/custom-dialog/loans-account-add-collateral-dialog/loans-account-add-collateral-dialog.component.html similarity index 100% rename from src/app/loans/loans-account-add-collateral-dialog/loans-account-add-collateral-dialog.component.html rename to src/app/loans/custom-dialog/loans-account-add-collateral-dialog/loans-account-add-collateral-dialog.component.html diff --git a/src/app/loans/loans-account-add-collateral-dialog/loans-account-add-collateral-dialog.component.scss b/src/app/loans/custom-dialog/loans-account-add-collateral-dialog/loans-account-add-collateral-dialog.component.scss similarity index 100% rename from src/app/loans/loans-account-add-collateral-dialog/loans-account-add-collateral-dialog.component.scss rename to src/app/loans/custom-dialog/loans-account-add-collateral-dialog/loans-account-add-collateral-dialog.component.scss diff --git a/src/app/loans/loans-account-add-collateral-dialog/loans-account-add-collateral-dialog.component.spec.ts b/src/app/loans/custom-dialog/loans-account-add-collateral-dialog/loans-account-add-collateral-dialog.component.spec.ts similarity index 100% rename from src/app/loans/loans-account-add-collateral-dialog/loans-account-add-collateral-dialog.component.spec.ts rename to src/app/loans/custom-dialog/loans-account-add-collateral-dialog/loans-account-add-collateral-dialog.component.spec.ts diff --git a/src/app/loans/loans-account-add-collateral-dialog/loans-account-add-collateral-dialog.component.ts b/src/app/loans/custom-dialog/loans-account-add-collateral-dialog/loans-account-add-collateral-dialog.component.ts similarity index 94% rename from src/app/loans/loans-account-add-collateral-dialog/loans-account-add-collateral-dialog.component.ts rename to src/app/loans/custom-dialog/loans-account-add-collateral-dialog/loans-account-add-collateral-dialog.component.ts index a6c43c497..a38935e0d 100644 --- a/src/app/loans/loans-account-add-collateral-dialog/loans-account-add-collateral-dialog.component.ts +++ b/src/app/loans/custom-dialog/loans-account-add-collateral-dialog/loans-account-add-collateral-dialog.component.ts @@ -26,8 +26,6 @@ export class LoansAccountAddCollateralDialogComponent implements OnInit { ngOnInit() { this.dialogRef.updateSize('400px'); - console.log('collateral: ', this.data.collateralTypeOptions); - this.collateralTypeData = this.data.collateralTypeOptions; } diff --git a/src/app/loans/custom-dialog/loans-account-view-guarantor-details-dialog/loans-account-view-guarantor-details-dialog.component.html b/src/app/loans/custom-dialog/loans-account-view-guarantor-details-dialog/loans-account-view-guarantor-details-dialog.component.html new file mode 100644 index 000000000..c673dff74 --- /dev/null +++ b/src/app/loans/custom-dialog/loans-account-view-guarantor-details-dialog/loans-account-view-guarantor-details-dialog.component.html @@ -0,0 +1,44 @@ +

Guarantor Detail

+ +
+ +
+ +
+ First Name: + {{ data.guarantorData.firstname }} +
+ +
+ Last Name: + {{ data.guarantorData.lastname }} +
+ +
+ Relationship: + {{ data.guarantorData.clientRelationshipType.name }} +
+ +
+ Guarantor Type: + {{ data.guarantorData.guarantorType.value }} +
+ +
+ Status: + + + Active + + + Deleted + +
+ +
+ +
+ + + + diff --git a/src/app/loans/custom-dialog/loans-account-view-guarantor-details-dialog/loans-account-view-guarantor-details-dialog.component.scss b/src/app/loans/custom-dialog/loans-account-view-guarantor-details-dialog/loans-account-view-guarantor-details-dialog.component.scss new file mode 100644 index 000000000..e69de29bb diff --git a/src/app/loans/custom-dialog/loans-account-view-guarantor-details-dialog/loans-account-view-guarantor-details-dialog.component.spec.ts b/src/app/loans/custom-dialog/loans-account-view-guarantor-details-dialog/loans-account-view-guarantor-details-dialog.component.spec.ts new file mode 100644 index 000000000..1722e597b --- /dev/null +++ b/src/app/loans/custom-dialog/loans-account-view-guarantor-details-dialog/loans-account-view-guarantor-details-dialog.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { LoansAccountViewGuarantorDetailsDialogComponent } from './loans-account-view-guarantor-details-dialog.component'; + +describe('LoansAccountViewGuarantorDetailsDialogComponent', () => { + let component: LoansAccountViewGuarantorDetailsDialogComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ LoansAccountViewGuarantorDetailsDialogComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(LoansAccountViewGuarantorDetailsDialogComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/loans/custom-dialog/loans-account-view-guarantor-details-dialog/loans-account-view-guarantor-details-dialog.component.ts b/src/app/loans/custom-dialog/loans-account-view-guarantor-details-dialog/loans-account-view-guarantor-details-dialog.component.ts new file mode 100644 index 000000000..0f1a690cb --- /dev/null +++ b/src/app/loans/custom-dialog/loans-account-view-guarantor-details-dialog/loans-account-view-guarantor-details-dialog.component.ts @@ -0,0 +1,19 @@ +import { Component, OnInit, Inject } from '@angular/core'; +import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material'; + +@Component({ + selector: 'mifosx-loans-account-view-guarantor-details-dialog', + templateUrl: './loans-account-view-guarantor-details-dialog.component.html', + styleUrls: ['./loans-account-view-guarantor-details-dialog.component.scss'] +}) +export class LoansAccountViewGuarantorDetailsDialogComponent implements OnInit { + + constructor(public dialogRef: MatDialogRef, + @Inject(MAT_DIALOG_DATA) public data: any) { + } + + ngOnInit() { + this.dialogRef.updateSize('400px'); + } + +} diff --git a/src/app/loans/custom-dialog/loans-confirmation-dialog-box/loans-confirmation-dialog-box.component.html b/src/app/loans/custom-dialog/loans-confirmation-dialog-box/loans-confirmation-dialog-box.component.html new file mode 100644 index 000000000..71e6ca6b0 --- /dev/null +++ b/src/app/loans/custom-dialog/loans-confirmation-dialog-box/loans-confirmation-dialog-box.component.html @@ -0,0 +1,8 @@ +

{{data.heading}}

+
+

{{ data.dialogContext }}

+
+ + + + \ No newline at end of file diff --git a/src/app/loans/custom-dialog/loans-confirmation-dialog-box/loans-confirmation-dialog-box.component.scss b/src/app/loans/custom-dialog/loans-confirmation-dialog-box/loans-confirmation-dialog-box.component.scss new file mode 100644 index 000000000..e69de29bb diff --git a/src/app/loans/custom-dialog/loans-confirmation-dialog-box/loans-confirmation-dialog-box.component.spec.ts b/src/app/loans/custom-dialog/loans-confirmation-dialog-box/loans-confirmation-dialog-box.component.spec.ts new file mode 100644 index 000000000..052b07604 --- /dev/null +++ b/src/app/loans/custom-dialog/loans-confirmation-dialog-box/loans-confirmation-dialog-box.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { LoansConfirmationDialogBoxComponent } from './loans-confirmation-dialog-box.component'; + +describe('LoansConfirmationDialogBoxComponent', () => { + let component: LoansConfirmationDialogBoxComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ LoansConfirmationDialogBoxComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(LoansConfirmationDialogBoxComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/loans/custom-dialog/loans-confirmation-dialog-box/loans-confirmation-dialog-box.component.ts b/src/app/loans/custom-dialog/loans-confirmation-dialog-box/loans-confirmation-dialog-box.component.ts new file mode 100644 index 000000000..d03225a72 --- /dev/null +++ b/src/app/loans/custom-dialog/loans-confirmation-dialog-box/loans-confirmation-dialog-box.component.ts @@ -0,0 +1,22 @@ +import { Component, OnInit, Inject } from '@angular/core'; +import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material'; +import { DeleteDialogComponent } from 'app/shared/delete-dialog/delete-dialog.component'; + +@Component({ + selector: 'mifosx-loans-confirmation-dialog-box', + templateUrl: './loans-confirmation-dialog-box.component.html', + styleUrls: ['./loans-confirmation-dialog-box.component.scss'] +}) +export class LoansConfirmationDialogBoxComponent implements OnInit { + + /** + * @param {MatDialogRef} dialogRef Component reference to dialog. + * @param {any} data Provides a confirmation for all the loans account actions. + */ + constructor(public dialogRef: MatDialogRef, + @Inject(MAT_DIALOG_DATA) public data: any) { } + + ngOnInit() { + } + +} diff --git a/src/app/loans/loans-account-stepper/loans-account-charges-step/loans-account-charges-step.component.ts b/src/app/loans/loans-account-stepper/loans-account-charges-step/loans-account-charges-step.component.ts index 931e25574..97796359e 100644 --- a/src/app/loans/loans-account-stepper/loans-account-charges-step/loans-account-charges-step.component.ts +++ b/src/app/loans/loans-account-stepper/loans-account-charges-step/loans-account-charges-step.component.ts @@ -6,7 +6,7 @@ import { MatDialog } from '@angular/material'; /** Dialog Components */ import { DeleteDialogComponent } from 'app/shared/delete-dialog/delete-dialog.component'; import { FormDialogComponent } from 'app/shared/form-dialog/form-dialog.component'; -import { LoansAccountAddCollateralDialogComponent } from 'app/loans/loans-account-add-collateral-dialog/loans-account-add-collateral-dialog.component'; +import { LoansAccountAddCollateralDialogComponent } from 'app/loans/custom-dialog/loans-account-add-collateral-dialog/loans-account-add-collateral-dialog.component'; /** Custom Services */ import { DatePipe } from '@angular/common'; @@ -211,7 +211,6 @@ export class LoansAccountChargesStepComponent implements OnInit, OnChanges { }); addCollateralDialogRef.afterClosed().subscribe((response: any) => { if (response.addCollateralForm) { - console.log('formdata: ', response.addCollateralForm); const collateralData = { type: response.addCollateralForm.value.type, value: response.addCollateralForm.value.value, diff --git a/src/app/loans/loans-view/button-config.ts b/src/app/loans/loans-view/button-config.ts index f52603e1c..d0bcd8839 100644 --- a/src/app/loans/loans-view/button-config.ts +++ b/src/app/loans/loans-view/button-config.ts @@ -74,7 +74,7 @@ export const ButtonConfig = { taskPermissionName: 'CREATE_LOANCHARGE', }, { - name: 'List Guarantor', + name: 'View Guarantors', taskPermissionName: 'READ_GUARANTOR', }, { @@ -137,7 +137,7 @@ export const ButtonConfig = { taskPermissionName: 'READ_LOAN', }, { - name: 'List Guarantor', + name: 'View Guarantors', taskPermissionName: 'READ_GUARANTOR', }, { @@ -145,7 +145,7 @@ export const ButtonConfig = { taskPermissionName: 'CREATE_GUARANTOR', }, { - name: 'Recover Guarantee', + name: 'Recover From Guarantor', taskPermissionName: 'RECOVERGUARANTEES_LOAN', }, ], diff --git a/src/app/loans/loans-view/loan-account-actions/create-guarantor/create-guarantor.component.html b/src/app/loans/loans-view/loan-account-actions/create-guarantor/create-guarantor.component.html new file mode 100644 index 000000000..0add49ca3 --- /dev/null +++ b/src/app/loans/loans-view/loan-account-actions/create-guarantor/create-guarantor.component.html @@ -0,0 +1,100 @@ +
+
+ + + +
+ + + Existing Client + + + + + + Name + + + Name is required + + + + + + + Relationship + + + {{ relationType.name }} + + + + + + + First Name + + + First Name is required + + + + + Last Name + + + Last Name is required + + + + + Date Of Birth + + + + + + + Address Line 1 + + + + + Address Line 2 + + + + + City + + + + + Zip + + + + + Mobile + + + + + Residence Phone # + + + + + +
+ + + + + + +
+ +
+
\ No newline at end of file diff --git a/src/app/loans/loans-view/loan-account-actions/create-guarantor/create-guarantor.component.scss b/src/app/loans/loans-view/loan-account-actions/create-guarantor/create-guarantor.component.scss new file mode 100644 index 000000000..e69de29bb diff --git a/src/app/loans/loans-view/loan-account-actions/create-guarantor/create-guarantor.component.spec.ts b/src/app/loans/loans-view/loan-account-actions/create-guarantor/create-guarantor.component.spec.ts new file mode 100644 index 000000000..029382373 --- /dev/null +++ b/src/app/loans/loans-view/loan-account-actions/create-guarantor/create-guarantor.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { CreateGuarantorComponent } from './create-guarantor.component'; + +describe('CreateGuarantorComponent', () => { + let component: CreateGuarantorComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ CreateGuarantorComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(CreateGuarantorComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/loans/loans-view/loan-account-actions/create-guarantor/create-guarantor.component.ts b/src/app/loans/loans-view/loan-account-actions/create-guarantor/create-guarantor.component.ts new file mode 100644 index 000000000..feacd649b --- /dev/null +++ b/src/app/loans/loans-view/loan-account-actions/create-guarantor/create-guarantor.component.ts @@ -0,0 +1,125 @@ +/** Angular Imports */ +import { Component, OnInit, Input } from '@angular/core'; +import { FormGroup, FormBuilder, Validators, FormControl } from '@angular/forms'; +import { ActivatedRoute, Router } from '@angular/router'; + +/** Custom Services */ +import { LoansService } from 'app/loans/loans.service'; +import { DatePipe } from '@angular/common'; + +/** + * Create Guarantor Action + */ +@Component({ + selector: 'mifosx-create-guarantor', + templateUrl: './create-guarantor.component.html', + styleUrls: ['./create-guarantor.component.scss'] +}) +export class CreateGuarantorComponent implements OnInit { + + @Input() dataObject: any; + /** New Guarantor Form */ + newGuarantorForm: FormGroup; + /** Loan ID */ + loanId: string; + /** Relation Types */ + relationTypes: any; + /** Show Client Details Form */ + showClientDetailsForm = false; + /** Minimum date allowed. */ + minDate = new Date(2000, 0, 1); + /** Maximum date allowed. */ + maxDate = new Date(); + + /** + * @param {FormBuilder} formBuilder Form Builder. + * @param {LoansService} loanService Loan Service. + * @param {ActivatedRoute} route Activated Route. + * @param {Router} router Router for navigation. + * @param {DatePipe} datePipe Date Pipe. + */ + constructor(private formBuilder: FormBuilder, + private loanService: LoansService, + private route: ActivatedRoute, + private router: Router, + private datePipe: DatePipe) { + this.loanId = this.route.parent.snapshot.params['loanId']; + } + + ngOnInit() { + this.createNewGuarantorForm(); + this.setNewGuarantorDetailsForm(); + this.buildDependencies(); + } + + /** Create Guarantor Details Form */ + createNewGuarantorForm() { + this.newGuarantorForm = this.formBuilder.group({ + 'existingClient': [''], + 'name': ['', Validators.required], + 'clientRelationshipTypeId': [''] + }); + } + + /** Sets Guarantor Details Form */ + setNewGuarantorDetailsForm() { + this.relationTypes = this.dataObject.allowedClientRelationshipTypes; + this.newGuarantorForm.patchValue({ + existingClient: true + }); + } + + /** + * Add guarantor detail fields to the UI. + */ + buildDependencies() { + this.newGuarantorForm.get('existingClient').valueChanges.subscribe(() => { + this.showClientDetailsForm = !this.showClientDetailsForm; + if (this.showClientDetailsForm) { + this.newGuarantorForm.addControl('firstname', new FormControl('')); + this.newGuarantorForm.addControl('lastname', new FormControl('')); + this.newGuarantorForm.addControl('dob', new FormControl('')); + this.newGuarantorForm.addControl('addressLine1', new FormControl('')); + this.newGuarantorForm.addControl('addressLine2', new FormControl('')); + this.newGuarantorForm.addControl('city', new FormControl('')); + this.newGuarantorForm.addControl('zip', new FormControl('')); + this.newGuarantorForm.addControl('mobileNumber', new FormControl('')); + this.newGuarantorForm.addControl('housePhoneNumber', new FormControl('')); + this.newGuarantorForm.removeControl('name'); + } else { + this.newGuarantorForm.addControl('name', new FormControl('')); + this.newGuarantorForm.removeControl('firstname'); + this.newGuarantorForm.removeControl('lastname'); + this.newGuarantorForm.removeControl('dob'); + this.newGuarantorForm.removeControl('addressLine1'); + this.newGuarantorForm.removeControl('addressLine2'); + this.newGuarantorForm.removeControl('city'); + this.newGuarantorForm.removeControl('zip'); + this.newGuarantorForm.removeControl('mobileNumber'); + this.newGuarantorForm.removeControl('housePhoneNumber'); + } + }); + } + + /** Submits the new guarantor details form */ + submit() { + const prevdob: Date = this.newGuarantorForm.value.dob; + const guarantorTypeId: number = this.newGuarantorForm.value.existingClient ? this.dataObject.guarantorTypeOptions[0].id : this.dataObject.guarantorTypeOptions[2].id; + // TODO: Update once language and date settings are setup + const dateFormat = 'dd-MM-yyyy'; + const locale = 'en'; + const newGuarantorData = { + ... this.newGuarantorForm.value, + dob: this.datePipe.transform(prevdob, dateFormat), + locale, + dateFormat, + guarantorTypeId + }; + delete newGuarantorData.existingClient; + this.loanService.createNewGuarantor(this.loanId, newGuarantorData) + .subscribe((response: any) => { + this.router.navigate(['../general'], { relativeTo: this.route }); + }); + } + +} diff --git a/src/app/loans/loans-view/loan-account-actions/loan-account-actions.component.html b/src/app/loans/loans-view/loan-account-actions/loan-account-actions.component.html index ecdc63a73..10f14b1b7 100644 --- a/src/app/loans/loans-view/loan-account-actions/loan-account-actions.component.html +++ b/src/app/loans/loans-view/loan-account-actions/loan-account-actions.component.html @@ -11,5 +11,7 @@ + + diff --git a/src/app/loans/loans-view/loan-account-actions/loan-account-actions.component.ts b/src/app/loans/loans-view/loan-account-actions/loan-account-actions.component.ts index 014e19a02..810dda06d 100644 --- a/src/app/loans/loans-view/loan-account-actions/loan-account-actions.component.ts +++ b/src/app/loans/loans-view/loan-account-actions/loan-account-actions.component.ts @@ -23,7 +23,9 @@ export class LoanAccountActionsComponent { waive_interest: boolean, close_as_rescheduled: boolean, reschedule: boolean, - recovery_payment: boolean } = { + recovery_payment: boolean, + view_guarantors: boolean, + create_guarantor: boolean } = { close: false, undo_approval: false, write_off: false, @@ -34,7 +36,9 @@ export class LoanAccountActionsComponent { waive_interest: false, close_as_rescheduled: false, reschedule: false, - recovery_payment: false }; + recovery_payment: false, + view_guarantors: false, + create_guarantor: false }; actionButtonData: any; actionName: any; diff --git a/src/app/loans/loans-view/loan-account-actions/view-guarantors/view-guarantors.component.html b/src/app/loans/loans-view/loan-account-actions/view-guarantors/view-guarantors.component.html new file mode 100644 index 000000000..a6c0e717d --- /dev/null +++ b/src/app/loans/loans-view/loan-account-actions/view-guarantors/view-guarantors.component.html @@ -0,0 +1,174 @@ + + +
+ + +
+
+
+

Guarantors Details

+
+
+
+
+ +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Name + + {{guarantor.firstname}}   {{guarantor.lastname}} + + Relationship + + {{guarantor.clientRelationshipType.name}} + + Guarantor Type + + {{guarantor.guarantorType.value}} + + Deposit Account + + + + Amount + + + + Remaining Amount + + + + Status + + + Active + + + Deleted + + + Action + + + + + + + +
+
diff --git a/src/app/loans/loans-view/loan-account-actions/view-guarantors/view-guarantors.component.scss b/src/app/loans/loans-view/loan-account-actions/view-guarantors/view-guarantors.component.scss new file mode 100644 index 000000000..842902d06 --- /dev/null +++ b/src/app/loans/loans-view/loan-account-actions/view-guarantors/view-guarantors.component.scss @@ -0,0 +1,31 @@ +.viewGuarantors-account-tables { + padding: 1%; + margin: 1%; + .table-headers { + margin: 0; + padding: 6px; + } + td { + padding: 3px; + } +} + +table { + width: 100%; + .account-action-button{ + min-width: 26px; + padding: 0 6px; + margin: 4px; + line-height: 25px; + } +} + +.headingContent{ + margin-bottom: 1%; + margin-top: 1%; + width: 100%; +} + +.headingName { + display: block; +} diff --git a/src/app/loans/loans-view/loan-account-actions/view-guarantors/view-guarantors.component.spec.ts b/src/app/loans/loans-view/loan-account-actions/view-guarantors/view-guarantors.component.spec.ts new file mode 100644 index 000000000..682653ed1 --- /dev/null +++ b/src/app/loans/loans-view/loan-account-actions/view-guarantors/view-guarantors.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { ViewGuarantorsComponent } from './view-guarantors.component'; + +describe('ViewGuarantorsComponent', () => { + let component: ViewGuarantorsComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ ViewGuarantorsComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(ViewGuarantorsComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/loans/loans-view/loan-account-actions/view-guarantors/view-guarantors.component.ts b/src/app/loans/loans-view/loan-account-actions/view-guarantors/view-guarantors.component.ts new file mode 100644 index 000000000..3f7d346ef --- /dev/null +++ b/src/app/loans/loans-view/loan-account-actions/view-guarantors/view-guarantors.component.ts @@ -0,0 +1,83 @@ +/** Angular Imports */ +import { Component, OnInit, Input } from '@angular/core'; +import { FormGroup, FormBuilder, Validators, FormControl } from '@angular/forms'; +import { ActivatedRoute, Router } from '@angular/router'; +import { MatDialog } from '@angular/material'; + +/** Custom Services */ +import { LoansService } from 'app/loans/loans.service'; +import { DatePipe } from '@angular/common'; + +/** Dialog Components */ +import { DeleteDialogComponent } from 'app/shared/delete-dialog/delete-dialog.component'; +import { LoansAccountViewGuarantorDetailsDialogComponent } from 'app/loans/custom-dialog/loans-account-view-guarantor-details-dialog/loans-account-view-guarantor-details-dialog.component'; + +/** + * View Guarantors Action + */ +@Component({ + selector: 'mifosx-view-guarantors', + templateUrl: './view-guarantors.component.html', + styleUrls: ['./view-guarantors.component.scss'] +}) +export class ViewGuarantorsComponent implements OnInit { + + @Input() dataObject: any; + guarantorDetails: any; + showDeletedGuarantorsAccounts = false; + loanId: any; + guarantorsDisplayedColumns: string[] = ['fullname', 'relationship', 'guarantortype', 'depositAccount', 'amount', 'remainingAmount', 'status', 'action']; + + /** View and perform various action on existing list of guarantors + * @param {MatDialog} dialog Dialog + * @param {LoansService} loansService Loans Service + * @param {route} Route Route + * @param {router} Router Router + */ + constructor(public dialog: MatDialog, + public loansService: LoansService, + private route: ActivatedRoute, + private router: Router) { + this.loanId = this.route.parent.snapshot.params['loanId']; + } + + ngOnInit() { + this.guarantorDetails = this.dataObject.guarantors; + } + + toggleGuarantorsDetailsOverview() { + this.showDeletedGuarantorsAccounts = !this.showDeletedGuarantorsAccounts; + } + + deleteGuarantor(id: any) { + const deleteGuarantorDialogRef = this.dialog.open(DeleteDialogComponent, { + data: { deleteContext: `the guarantor id: ${id}` } + }); + deleteGuarantorDialogRef.afterClosed().subscribe((response: any) => { + if (response.delete) { + this.loansService.deleteGuarantor(this.loanId, id).subscribe(() => { + this.reload(); + }); + } + }); + } + + viewGuarantorDetails(guarantorData: any) { + const viewGuarantorDetailsDialogRef = this.dialog.open(LoansAccountViewGuarantorDetailsDialogComponent, { + data: { guarantorData: guarantorData } + }); + viewGuarantorDetailsDialogRef.afterClosed().subscribe(() => {}); + } + + /** + * Refetches data for the component + * TODO: Replace by a custom reload component instead of hard-coded back-routing. + */ + private reload() { + const clientId = this.dataObject.clientId; + const url: string = this.router.url; + this.router.navigateByUrl(`/clients/${clientId}/loans`, { skipLocationChange: true }) + .then(() => this.router.navigate([url])); + } + +} diff --git a/src/app/loans/loans-view/loans-view.component.ts b/src/app/loans/loans-view/loans-view.component.ts index f0a2f403c..e81c6b60c 100644 --- a/src/app/loans/loans-view/loans-view.component.ts +++ b/src/app/loans/loans-view/loans-view.component.ts @@ -1,10 +1,18 @@ +/** Angular Imports */ import { Component, OnInit } from '@angular/core'; import { ActivatedRoute, Router } from '@angular/router'; +import { MatDialog } from '@angular/material'; + +/** Custom Services */ import { LoansService } from '../loans.service'; -// Custom Imports +/** Custom Buttons Configuration */ import { ButtonConfig } from './button-config'; +/** Dialog Components */ +import { LoansConfirmationDialogBoxComponent } from '../custom-dialog/loans-confirmation-dialog-box/loans-confirmation-dialog-box.component'; +import { DeleteDialogComponent } from 'app/shared/delete-dialog/delete-dialog.component'; + @Component({ selector: 'mifosx-loans-view', templateUrl: './loans-view.component.html', @@ -28,14 +36,18 @@ export class LoansViewComponent implements OnInit { }[] }; loanId: number; + clientId: any; constructor(private route: ActivatedRoute, - private router: Router) { + private router: Router, + public loansService: LoansService, + public dialog: MatDialog) { this.route.data.subscribe((data: { loanDetailsData: any, loanDatatables: any}) => { this.loanDetailsData = data.loanDetailsData; this.loanDatatables = data.loanDatatables; }); this.loanId = this.route.snapshot.params['loanId']; + this.clientId = this.loanDetailsData.clientId; } ngOnInit() { @@ -111,10 +123,62 @@ export class LoansViewComponent implements OnInit { } loanAction(button: string) { - button = button.replace(/\s/g, '-').toLowerCase(); - button = button.replace(/\(/g, ''); - button = button.replace(/\)/g, ''); - this.router.navigate([button], { relativeTo: this.route }); + console.log('button: ', button); + + switch (button) { + case 'Recover From Guarantor': + this.recoverFromGuarantor(); + break; + case 'Delete': + this.deleteLoanAccount(); + break; + default: + button = button.replace(/\s/g, '-').toLowerCase(); + button = button.replace(/\(/g, ''); + button = button.replace(/\)/g, ''); + this.router.navigate([button], { relativeTo: this.route }); + break; + } + } + + /** + * Recover from guarantor action + */ + private recoverFromGuarantor() { + const recoverFromGuarantorDialogRef = this.dialog.open(LoansConfirmationDialogBoxComponent, { + data: { heading: 'Recover from Guarantor', dialogContext: 'Are you sure you want recover from Guarantor ?' } + }); + recoverFromGuarantorDialogRef.afterClosed().subscribe((response: any) => { + if (response.confirm) { + this.loansService.loanActionButtons(this.loanId, 'recoverGuarantees').subscribe(() => { + this.reload(); + }); + } + }); + } + + private deleteLoanAccount() { + const deleteGuarantorDialogRef = this.dialog.open(DeleteDialogComponent, { + data: { deleteContext: `with loan id: ${this.loanId}` } + }); + deleteGuarantorDialogRef.afterClosed().subscribe((response: any) => { + if (response.delete) { + this.loansService.deleteLoanAccount(this.loanId).subscribe(() => { + this.router.navigate(['../../'], { relativeTo: this.route }); + }); + } + }); + } + + /** + * Refetches data for the component + * TODO: Replace by a custom reload component instead of hard-coded back-routing. + */ + private reload() { + const clientId = this.clientId; + const url: string = this.router.url; + this.router.navigateByUrl(`/clients/${clientId}/loans`, { skipLocationChange: true }) + .then(() => this.router.navigate([url])); } } diff --git a/src/app/loans/loans.module.ts b/src/app/loans/loans.module.ts index 69eb3fa5a..1cff362e1 100644 --- a/src/app/loans/loans.module.ts +++ b/src/app/loans/loans.module.ts @@ -41,8 +41,14 @@ import { LoansAccountDetailsStepComponent } from './loans-account-stepper/loans- import { LoansAccountTermsStepComponent } from './loans-account-stepper/loans-account-terms-step/loans-account-terms-step.component'; import { LoansAccountChargesStepComponent } from './loans-account-stepper/loans-account-charges-step/loans-account-charges-step.component'; import { LoansAccountPreviewStepComponent } from './loans-account-stepper/loans-account-preview-step/loans-account-preview-step.component'; -import { LoansAccountAddCollateralDialogComponent } from './loans-account-add-collateral-dialog/loans-account-add-collateral-dialog.component'; import { RecoveryRepaymentComponent } from './loans-view/loan-account-actions/recovery-repayment/recovery-repayment.component'; +import { ViewGuarantorsComponent } from './loans-view/loan-account-actions/view-guarantors/view-guarantors.component'; +import { CreateGuarantorComponent } from './loans-view/loan-account-actions/create-guarantor/create-guarantor.component'; + +/** Dialog Components */ +import { LoansAccountViewGuarantorDetailsDialogComponent } from './custom-dialog/loans-account-view-guarantor-details-dialog/loans-account-view-guarantor-details-dialog.component'; +import { LoansAccountAddCollateralDialogComponent } from './custom-dialog/loans-account-add-collateral-dialog/loans-account-add-collateral-dialog.component'; +import { LoansConfirmationDialogBoxComponent } from './custom-dialog/loans-confirmation-dialog-box/loans-confirmation-dialog-box.component'; /** * Loans Module @@ -86,9 +92,15 @@ import { RecoveryRepaymentComponent } from './loans-view/loan-account-actions/re LoansAccountPreviewStepComponent, LoansAccountAddCollateralDialogComponent, RecoveryRepaymentComponent, + ViewGuarantorsComponent, + CreateGuarantorComponent, + LoansAccountViewGuarantorDetailsDialogComponent, + LoansConfirmationDialogBoxComponent, ], entryComponents: [ - LoansAccountAddCollateralDialogComponent + LoansAccountAddCollateralDialogComponent, + LoansAccountViewGuarantorDetailsDialogComponent, + LoansConfirmationDialogBoxComponent ], providers: [DatePipe], }) diff --git a/src/app/loans/loans.service.ts b/src/app/loans/loans.service.ts index ea8e94268..99a2a3294 100644 --- a/src/app/loans/loans.service.ts +++ b/src/app/loans/loans.service.ts @@ -26,6 +26,27 @@ export class LoansService { return this.http.get(`/loans/${loanId}/transactions/template`, { params: httpParams }); } + getLoanAccountResource(loanId: string, associations: string): Observable { + const httpParams = new HttpParams().set('associations', associations); + return this.http.get(`/loans/${loanId}`, { params: httpParams }); + } + + getGuarantorTemplate(loanId: string): Observable { + return this.http.get(`/loans/${loanId}/guarantors/template`); + } + + createNewGuarantor(loanId: string, data: any): Observable { + return this.http.post(`/loans/${loanId}/guarantors`, data); + } + + deleteGuarantor(loanId: any, guarantorId: any): Observable { + return this.http.delete(`/loans/${loanId}/guarantors/${guarantorId}`); + } + + deleteLoanAccount(loanId: any): Observable { + return this.http.delete(`/loans/${loanId}`); + } + /** * Returns the loan template data with specific condition * @param loanId Loan Id @@ -169,7 +190,7 @@ export class LoansService { * @param {any} data Data. * @returns {Observable} */ - loanActionButtons(loanId: string, data: any, command: any): Observable { + loanActionButtons(loanId: any, command: any, data?: any): Observable { const httpParams = new HttpParams().set('command', command); return this.http.post(`/loans/${loanId}`, data, {params: httpParams}); } diff --git a/src/app/pipes/accounts-filter.pipe.ts b/src/app/pipes/accounts-filter.pipe.ts index 2a09b7299..665228f5a 100644 --- a/src/app/pipes/accounts-filter.pipe.ts +++ b/src/app/pipes/accounts-filter.pipe.ts @@ -69,6 +69,15 @@ export class AccountsFilterPipe implements PipeTransform { }); } } + if (type === 'guarantor') { + if (status === false) { + accounts = accounts.filter((account: any) => { + return (account.status === true); + }); + } else { + return accounts; + } + } return accounts; } }