From 4e2f9ce2eecd2822e9c18cc3adc4d002d5cf6192 Mon Sep 17 00:00:00 2001 From: Karan Takalkar Date: Tue, 23 Jun 2020 20:40:46 +0530 Subject: [PATCH] feat: shares account actions (close) (#896) Fixes: #895 --- .../close-shares-account.component.html | 39 ++++++++++ .../close-shares-account.component.scss | 3 + .../close-shares-account.component.spec.ts | 25 ++++++ .../close-shares-account.component.ts | 76 +++++++++++++++++++ .../shares-account-actions.component.html | 3 +- .../shares-account-actions.component.ts | 6 +- .../shares-account-view.component.ts | 3 + src/app/shares/shares.module.ts | 4 +- 8 files changed, 155 insertions(+), 4 deletions(-) create mode 100644 src/app/shares/shares-account-actions/close-shares-account/close-shares-account.component.html create mode 100644 src/app/shares/shares-account-actions/close-shares-account/close-shares-account.component.scss create mode 100644 src/app/shares/shares-account-actions/close-shares-account/close-shares-account.component.spec.ts create mode 100644 src/app/shares/shares-account-actions/close-shares-account/close-shares-account.component.ts diff --git a/src/app/shares/shares-account-actions/close-shares-account/close-shares-account.component.html b/src/app/shares/shares-account-actions/close-shares-account/close-shares-account.component.html new file mode 100644 index 000000000..a399cd7b9 --- /dev/null +++ b/src/app/shares/shares-account-actions/close-shares-account/close-shares-account.component.html @@ -0,0 +1,39 @@ +
+ + + +
+ + + +
+ + + Closed On Date + + + + + Closed On Date is required + + + + + Note + + + +
+ +
+ + + + + + +
+ +
+ +
diff --git a/src/app/shares/shares-account-actions/close-shares-account/close-shares-account.component.scss b/src/app/shares/shares-account-actions/close-shares-account/close-shares-account.component.scss new file mode 100644 index 000000000..d774f68da --- /dev/null +++ b/src/app/shares/shares-account-actions/close-shares-account/close-shares-account.component.scss @@ -0,0 +1,3 @@ +.container { + max-width: 37rem; +} diff --git a/src/app/shares/shares-account-actions/close-shares-account/close-shares-account.component.spec.ts b/src/app/shares/shares-account-actions/close-shares-account/close-shares-account.component.spec.ts new file mode 100644 index 000000000..1cc2fc39f --- /dev/null +++ b/src/app/shares/shares-account-actions/close-shares-account/close-shares-account.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { CloseSharesAccountComponent } from './close-shares-account.component'; + +describe('CloseSharesAccountComponent', () => { + let component: CloseSharesAccountComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ CloseSharesAccountComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(CloseSharesAccountComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/shares/shares-account-actions/close-shares-account/close-shares-account.component.ts b/src/app/shares/shares-account-actions/close-shares-account/close-shares-account.component.ts new file mode 100644 index 000000000..62508a238 --- /dev/null +++ b/src/app/shares/shares-account-actions/close-shares-account/close-shares-account.component.ts @@ -0,0 +1,76 @@ +/** Angular Imports */ +import { Component, OnInit } from '@angular/core'; +import { FormGroup, FormBuilder, Validators } from '@angular/forms'; +import { DatePipe } from '@angular/common'; +import { ActivatedRoute, Router } from '@angular/router'; + +/** Custom Services */ +import { SharesService } from 'app/shares/shares.service'; + +/** + * Close Shares Account Component + */ +@Component({ + selector: 'mifosx-close-shares-account', + templateUrl: './close-shares-account.component.html', + styleUrls: ['./close-shares-account.component.scss'] +}) +export class CloseSharesAccountComponent implements OnInit { + + /** Minimum date allowed. */ + minDate = new Date(2000, 0, 1); + /** Maximum date allowed. */ + maxDate = new Date(); + /** Close Share Account form. */ + closeSharesAccountForm: FormGroup; + /** Shares Account Id */ + accountId: any; + + constructor(private formBuilder: FormBuilder, + private sharesService: SharesService, + private datePipe: DatePipe, + private route: ActivatedRoute, + private router: Router) { + this.accountId = this.route.parent.parent.snapshot.params['shareAccountId']; + } + + /** + * Creates the close shares form. + */ + ngOnInit() { + this.createCloseSharesAccountForm(); + } + + /** + * Creates the close shares account form. + */ + createCloseSharesAccountForm() { + this.closeSharesAccountForm = this.formBuilder.group({ + 'closedDate': ['', Validators.required], + 'note': [''] + }); + } + + /** + * Submits the form and closes the share account, + * if successful redirects to the share account. + */ + submit() { + // TODO: Update once language and date settings are setup + const locale = 'en'; + const dateFormat = 'dd MMMM yyyy'; + const prevClosedDate: Date = this.closeSharesAccountForm.value.closedDate; + this.closeSharesAccountForm.patchValue({ + closedDate: this.datePipe.transform(prevClosedDate, dateFormat), + }); + const data = { + ...this.closeSharesAccountForm.value, + dateFormat, + locale + }; + this.sharesService.executeSharesAccountCommand(this.accountId, 'close', data).subscribe(() => { + this.router.navigate(['../../'], { relativeTo: this.route }); + }); + } + +} diff --git a/src/app/shares/shares-account-actions/shares-account-actions.component.html b/src/app/shares/shares-account-actions/shares-account-actions.component.html index 881213489..7a0c4faf0 100644 --- a/src/app/shares/shares-account-actions/shares-account-actions.component.html +++ b/src/app/shares/shares-account-actions/shares-account-actions.component.html @@ -1,2 +1,3 @@ - \ No newline at end of file + + \ No newline at end of file diff --git a/src/app/shares/shares-account-actions/shares-account-actions.component.ts b/src/app/shares/shares-account-actions/shares-account-actions.component.ts index a76fbfea9..6b16155aa 100644 --- a/src/app/shares/shares-account-actions/shares-account-actions.component.ts +++ b/src/app/shares/shares-account-actions/shares-account-actions.component.ts @@ -16,9 +16,11 @@ export class SharesAccountActionsComponent { actions: { Approve: boolean Reject: boolean + Close: boolean } = { - Approve: false , - Reject: false + Approve: false, + Reject: false, + Close: false }; constructor(private route: ActivatedRoute) { diff --git a/src/app/shares/shares-account-view/shares-account-view.component.ts b/src/app/shares/shares-account-view/shares-account-view.component.ts index 0f6deaaef..8fafc878b 100644 --- a/src/app/shares/shares-account-view/shares-account-view.component.ts +++ b/src/app/shares/shares-account-view/shares-account-view.component.ts @@ -91,6 +91,9 @@ export class SharesAccountViewComponent implements OnInit { case 'Reject': this.router.navigate(['actions/Reject'], { relativeTo: this.route }); break; + case 'Close': + this.router.navigate(['actions/Close'], { relativeTo: this.route }); + break; case 'Delete': this.deleteSharesAccount(); break; diff --git a/src/app/shares/shares.module.ts b/src/app/shares/shares.module.ts index 540689f0c..0a0627a02 100644 --- a/src/app/shares/shares.module.ts +++ b/src/app/shares/shares.module.ts @@ -20,6 +20,7 @@ import { EditSharesAccountComponent } from './edit-shares-account/edit-shares-ac import { SharesAccountActionsComponent } from './shares-account-actions/shares-account-actions.component'; import { ApproveSharesAccountComponent } from './shares-account-actions/approve-shares-account/approve-shares-account.component'; import { RejectSharesAccountComponent } from './shares-account-actions/reject-shares-account/reject-shares-account.component'; +import { CloseSharesAccountComponent } from './shares-account-actions/close-shares-account/close-shares-account.component'; /** * Shares Module @@ -46,7 +47,8 @@ import { RejectSharesAccountComponent } from './shares-account-actions/reject-sh EditSharesAccountComponent, SharesAccountActionsComponent, ApproveSharesAccountComponent, - RejectSharesAccountComponent + RejectSharesAccountComponent, + CloseSharesAccountComponent ], providers: [DatePipe] })