From 4b36a605173802bd387a1006123abfc18695313b Mon Sep 17 00:00:00 2001 From: Karan Takalkar Date: Wed, 24 Jun 2020 02:38:13 +0530 Subject: [PATCH] feat: shares account actions (apply-shares) (#902) Fixes: #901 --- .../activate-shares-account.component.ts | 9 +- .../apply-shares/apply-shares.component.html | 47 ++++++++++ .../apply-shares/apply-shares.component.scss | 3 + .../apply-shares.component.spec.ts | 25 +++++ .../apply-shares/apply-shares.component.ts | 93 +++++++++++++++++++ .../approve-shares-account.component.ts | 9 +- .../close-shares-account.component.ts | 9 +- .../reject-shares-account.component.ts | 9 +- .../shares-account-actions.component.html | 3 +- .../shares-account-actions.component.ts | 9 +- ...ndo-approval-shares-account.component.html | 2 +- .../undo-approval-shares-account.component.ts | 7 +- .../shares-account-view.component.ts | 23 ++--- src/app/shares/shares-routing.module.ts | 12 +-- src/app/shares/shares.module.ts | 4 +- 15 files changed, 231 insertions(+), 33 deletions(-) create mode 100644 src/app/shares/shares-account-actions/apply-shares/apply-shares.component.html create mode 100644 src/app/shares/shares-account-actions/apply-shares/apply-shares.component.scss create mode 100644 src/app/shares/shares-account-actions/apply-shares/apply-shares.component.spec.ts create mode 100644 src/app/shares/shares-account-actions/apply-shares/apply-shares.component.ts diff --git a/src/app/shares/shares-account-actions/activate-shares-account/activate-shares-account.component.ts b/src/app/shares/shares-account-actions/activate-shares-account/activate-shares-account.component.ts index 86db4c7e7..0e78124b3 100644 --- a/src/app/shares/shares-account-actions/activate-shares-account/activate-shares-account.component.ts +++ b/src/app/shares/shares-account-actions/activate-shares-account/activate-shares-account.component.ts @@ -26,12 +26,19 @@ export class ActivateSharesAccountComponent implements OnInit { /** Shares Account Id */ accountId: any; + /** + * @param {FormBuilder} formBuilder Form Builder + * @param {SharesService} sharesService Shares Service + * @param {DatePipe} datePipe Date Pipe + * @param {ActivatedRoute} route Activated Route + * @param {Router} router Router + */ 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']; + this.accountId = this.route.parent.snapshot.params['shareAccountId']; } /** diff --git a/src/app/shares/shares-account-actions/apply-shares/apply-shares.component.html b/src/app/shares/shares-account-actions/apply-shares/apply-shares.component.html new file mode 100644 index 000000000..5240d012a --- /dev/null +++ b/src/app/shares/shares-account-actions/apply-shares/apply-shares.component.html @@ -0,0 +1,47 @@ +
+ + + +
+ + + +
+ + + Request Date + + + + + Request Date is required + + + + + Total No. of Shares + + + Requested Shares is required + + + + + Today's Price + + + +
+ +
+ + + + + + +
+ +
+ +
diff --git a/src/app/shares/shares-account-actions/apply-shares/apply-shares.component.scss b/src/app/shares/shares-account-actions/apply-shares/apply-shares.component.scss new file mode 100644 index 000000000..d774f68da --- /dev/null +++ b/src/app/shares/shares-account-actions/apply-shares/apply-shares.component.scss @@ -0,0 +1,3 @@ +.container { + max-width: 37rem; +} diff --git a/src/app/shares/shares-account-actions/apply-shares/apply-shares.component.spec.ts b/src/app/shares/shares-account-actions/apply-shares/apply-shares.component.spec.ts new file mode 100644 index 000000000..e0d39407f --- /dev/null +++ b/src/app/shares/shares-account-actions/apply-shares/apply-shares.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { ApplySharesComponent } from './apply-shares.component'; + +describe('ApplySharesComponent', () => { + let component: ApplySharesComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ ApplySharesComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(ApplySharesComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/shares/shares-account-actions/apply-shares/apply-shares.component.ts b/src/app/shares/shares-account-actions/apply-shares/apply-shares.component.ts new file mode 100644 index 000000000..c2bd9933c --- /dev/null +++ b/src/app/shares/shares-account-actions/apply-shares/apply-shares.component.ts @@ -0,0 +1,93 @@ +/** Angular Imports */ +import { Component, OnInit, Input } 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'; + +/** + * App;y Shares Component + */ +@Component({ + selector: 'mifosx-apply-shares', + templateUrl: './apply-shares.component.html', + styleUrls: ['./apply-shares.component.scss'] +}) +export class ApplySharesComponent implements OnInit { + + + /** Minimum date allowed. */ + minDate = new Date(2000, 0, 1); + /** Maximum date allowed. */ + maxDate = new Date(); + /** Apply Share Account form. */ + applySharesForm: FormGroup; + /** Shares Account Id */ + accountId: any; + /** Unit Price */ + unitPrice: any; + + /** + * @param {FormBuilder} formBuilder Form Builder + * @param {SharesService} sharesService Shares Service + * @param {DatePipe} datePipe Date Pipe + * @param {ActivatedRoute} route Activated Route + * @param {Router} router Router + */ + constructor(private formBuilder: FormBuilder, + private sharesService: SharesService, + private datePipe: DatePipe, + private route: ActivatedRoute, + private router: Router) { + this.accountId = this.route.parent.snapshot.params['shareAccountId']; + } + + /** + * Creates the apply shares form. + * Fetching data from service as action buttons malfunction + * in clients view upon using a common resolver. + */ + ngOnInit() { + this.createApplySharesAccountForm(); + this.sharesService.getSharesAccountData(this.accountId, false).subscribe((response: any) => { + this.applySharesForm.get('unitPrice').patchValue(response.currentMarketPrice || ''); + }); + } + + /** + * Creates the apply shares form. + */ + createApplySharesAccountForm() { + this.applySharesForm = this.formBuilder.group({ + 'requestedDate': ['', Validators.required], + 'requestedShares': ['', Validators.required], + 'unitPrice': [{value: '', disabled: true}] + }); + } + + /** + * Submits the form and applies additional shares to 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 prevRequestedDate: Date = this.applySharesForm.value.requestedDate; + this.applySharesForm.patchValue({ + requestedDate: this.datePipe.transform(prevRequestedDate, dateFormat), + }); + const data = { + ...this.applySharesForm.value, + unitPrice: this.unitPrice, + dateFormat, + locale + }; + this.sharesService.executeSharesAccountCommand(this.accountId, 'applyadditionalshares', data).subscribe(() => { + this.router.navigate(['../../'], { relativeTo: this.route }); + }); + } + +} diff --git a/src/app/shares/shares-account-actions/approve-shares-account/approve-shares-account.component.ts b/src/app/shares/shares-account-actions/approve-shares-account/approve-shares-account.component.ts index ee59c45ed..ab361743d 100644 --- a/src/app/shares/shares-account-actions/approve-shares-account/approve-shares-account.component.ts +++ b/src/app/shares/shares-account-actions/approve-shares-account/approve-shares-account.component.ts @@ -26,12 +26,19 @@ export class ApproveSharesAccountComponent implements OnInit { /** Shares Account Id */ accountId: any; + /** + * @param {FormBuilder} formBuilder Form Builder + * @param {SharesService} sharesService Shares Service + * @param {DatePipe} datePipe Date Pipe + * @param {ActivatedRoute} route Activated Route + * @param {Router} router Router + */ 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']; + this.accountId = this.route.parent.snapshot.params['shareAccountId']; } /** 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 index 62508a238..0ddcb3862 100644 --- 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 @@ -26,12 +26,19 @@ export class CloseSharesAccountComponent implements OnInit { /** Shares Account Id */ accountId: any; + /** + * @param {FormBuilder} formBuilder Form Builder + * @param {SharesService} sharesService Shares Service + * @param {DatePipe} datePipe Date Pipe + * @param {ActivatedRoute} route Activated Route + * @param {Router} router Router + */ 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']; + this.accountId = this.route.parent.snapshot.params['shareAccountId']; } /** diff --git a/src/app/shares/shares-account-actions/reject-shares-account/reject-shares-account.component.ts b/src/app/shares/shares-account-actions/reject-shares-account/reject-shares-account.component.ts index efbdf899c..990ba69c0 100644 --- a/src/app/shares/shares-account-actions/reject-shares-account/reject-shares-account.component.ts +++ b/src/app/shares/shares-account-actions/reject-shares-account/reject-shares-account.component.ts @@ -26,12 +26,19 @@ export class RejectSharesAccountComponent implements OnInit { /** Shares Account Id */ accountId: any; + /** + * @param {FormBuilder} formBuilder Form Builder + * @param {SharesService} sharesService Shares Service + * @param {DatePipe} datePipe Date Pipe + * @param {ActivatedRoute} route Activated Route + * @param {Router} router Router + */ 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']; + this.accountId = this.route.parent.snapshot.params['shareAccountId']; } /** 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 58b4c4eb1..fb446b5e4 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 @@ -2,4 +2,5 @@ - \ 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 e0680e846..818a61103 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 @@ -12,6 +12,8 @@ import { ActivatedRoute } from '@angular/router'; }) export class SharesAccountActionsComponent { + /** Shares Account Data */ + sharesAccountData: any; /** Flag object to store possible actions and render appropriate UI to the user */ actions: { 'Approve': boolean @@ -19,14 +21,19 @@ export class SharesAccountActionsComponent { 'Close': boolean 'Activate': boolean 'Undo Approval': boolean + 'Apply Additional Shares': boolean } = { 'Approve': false, 'Reject': false, 'Close': false, 'Activate': false, - 'Undo Approval': false + 'Undo Approval': false, + 'Apply Additional Shares': false }; + /** + * @param {ActivatedRoute} route Activated Route + */ constructor(private route: ActivatedRoute) { const name = this.route.snapshot.params['name']; this.actions[name] = true; diff --git a/src/app/shares/shares-account-actions/undo-approval-shares-account/undo-approval-shares-account.component.html b/src/app/shares/shares-account-actions/undo-approval-shares-account/undo-approval-shares-account.component.html index 6c1bfddbc..15d939e5c 100644 --- a/src/app/shares/shares-account-actions/undo-approval-shares-account/undo-approval-shares-account.component.html +++ b/src/app/shares/shares-account-actions/undo-approval-shares-account/undo-approval-shares-account.component.html @@ -9,7 +9,7 @@

- Are you sure you want to undo aprroval of shares account with ID: {{accountId}} ? + Are you sure you want to undo approval of shares account with ID: {{accountId}} ?

diff --git a/src/app/shares/shares-account-actions/undo-approval-shares-account/undo-approval-shares-account.component.ts b/src/app/shares/shares-account-actions/undo-approval-shares-account/undo-approval-shares-account.component.ts index 851d94b71..b514059f7 100644 --- a/src/app/shares/shares-account-actions/undo-approval-shares-account/undo-approval-shares-account.component.ts +++ b/src/app/shares/shares-account-actions/undo-approval-shares-account/undo-approval-shares-account.component.ts @@ -18,10 +18,15 @@ export class UndoApprovalSharesAccountComponent { /** Shares Account Id */ accountId: any; + /** + * @param {SharesService} sharesService Shares Service + * @param {ActivatedRoute} route Activated Route + * @param {Router} router Router + */ constructor(private sharesService: SharesService, private route: ActivatedRoute, private router: Router) { - this.accountId = this.route.parent.parent.snapshot.params['shareAccountId']; + this.accountId = this.route.parent.snapshot.params['shareAccountId']; } /** 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 4417a4917..49202427f 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 @@ -82,24 +82,17 @@ export class SharesAccountViewComponent implements OnInit { */ doAction(name: string) { switch (name) { + case 'Approve': + case 'Reject': + case 'Close': + case 'Activate': + case 'Undo Approval': + case 'Apply Additional Shares': + this.router.navigate([`actions/${name}`], { relativeTo: this.route }); + break; case 'Modify Application': this.router.navigate(['edit-shares-account'], { relativeTo: this.route }); break; - case 'Approve': - this.router.navigate(['actions/Approve'], { relativeTo: this.route }); - break; - case 'Reject': - this.router.navigate(['actions/Reject'], { relativeTo: this.route }); - break; - case 'Close': - this.router.navigate(['actions/Close'], { relativeTo: this.route }); - break; - case 'Activate': - this.router.navigate(['actions/Activate'], { relativeTo: this.route }); - break; - case 'Undo Approval': - this.router.navigate(['actions/Undo Approval'], { relativeTo: this.route }); - break; case 'Delete': this.deleteSharesAccount(); break; diff --git a/src/app/shares/shares-routing.module.ts b/src/app/shares/shares-routing.module.ts index 1a4c1668c..bec5f131c 100644 --- a/src/app/shares/shares-routing.module.ts +++ b/src/app/shares/shares-routing.module.ts @@ -69,15 +69,9 @@ const routes: Routes = [ } }, { - path: 'actions', - data: { title: extract('Shares Account Actions'), breadcrumb: 'Actions', routeParamBreadcrumb: false }, - children: [ - { - path: ':name', - data: { routeParamBreadcrumb: 'name' }, - component: SharesAccountActionsComponent - } - ] + path: 'actions/:name', + data: { title: extract('Shares Account Actions'), breadcrumb: 'Actions', routeParamBreadcrumb: 'name' }, + component: SharesAccountActionsComponent } ] }, diff --git a/src/app/shares/shares.module.ts b/src/app/shares/shares.module.ts index add5ce279..0058a8305 100644 --- a/src/app/shares/shares.module.ts +++ b/src/app/shares/shares.module.ts @@ -23,6 +23,7 @@ import { RejectSharesAccountComponent } from './shares-account-actions/reject-sh import { CloseSharesAccountComponent } from './shares-account-actions/close-shares-account/close-shares-account.component'; import { ActivateSharesAccountComponent } from './shares-account-actions/activate-shares-account/activate-shares-account.component'; import { UndoApprovalSharesAccountComponent } from './shares-account-actions/undo-approval-shares-account/undo-approval-shares-account.component'; +import { ApplySharesComponent } from './shares-account-actions/apply-shares/apply-shares.component'; /** * Shares Module @@ -52,7 +53,8 @@ import { UndoApprovalSharesAccountComponent } from './shares-account-actions/und RejectSharesAccountComponent, CloseSharesAccountComponent, ActivateSharesAccountComponent, - UndoApprovalSharesAccountComponent + UndoApprovalSharesAccountComponent, + ApplySharesComponent ], providers: [DatePipe] })