diff --git a/src/app/savings/saving-account-actions/post-interest-as-on-savings-account/post-interest-as-on-savings-account.component.html b/src/app/savings/saving-account-actions/post-interest-as-on-savings-account/post-interest-as-on-savings-account.component.html new file mode 100644 index 000000000..7b701adb5 --- /dev/null +++ b/src/app/savings/saving-account-actions/post-interest-as-on-savings-account/post-interest-as-on-savings-account.component.html @@ -0,0 +1,30 @@ +
+ + + +
+ + + + + Transaction Date + + + + + Transaction Date is required + + + + + + + + + + +
+ +
+ +
diff --git a/src/app/savings/saving-account-actions/post-interest-as-on-savings-account/post-interest-as-on-savings-account.component.scss b/src/app/savings/saving-account-actions/post-interest-as-on-savings-account/post-interest-as-on-savings-account.component.scss new file mode 100644 index 000000000..d774f68da --- /dev/null +++ b/src/app/savings/saving-account-actions/post-interest-as-on-savings-account/post-interest-as-on-savings-account.component.scss @@ -0,0 +1,3 @@ +.container { + max-width: 37rem; +} diff --git a/src/app/savings/saving-account-actions/post-interest-as-on-savings-account/post-interest-as-on-savings-account.component.spec.ts b/src/app/savings/saving-account-actions/post-interest-as-on-savings-account/post-interest-as-on-savings-account.component.spec.ts new file mode 100644 index 000000000..0d1d6580d --- /dev/null +++ b/src/app/savings/saving-account-actions/post-interest-as-on-savings-account/post-interest-as-on-savings-account.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { PostInterestAsOnSavingsAccountComponent } from './post-interest-as-on-savings-account.component'; + +describe('PostInterestAsOnSavingsAccountComponent', () => { + let component: PostInterestAsOnSavingsAccountComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ PostInterestAsOnSavingsAccountComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(PostInterestAsOnSavingsAccountComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/savings/saving-account-actions/post-interest-as-on-savings-account/post-interest-as-on-savings-account.component.ts b/src/app/savings/saving-account-actions/post-interest-as-on-savings-account/post-interest-as-on-savings-account.component.ts new file mode 100644 index 000000000..4e5f5dbe7 --- /dev/null +++ b/src/app/savings/saving-account-actions/post-interest-as-on-savings-account/post-interest-as-on-savings-account.component.ts @@ -0,0 +1,83 @@ +/** 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 { SavingsService } from 'app/savings/savings.service'; + +/** + * Post Interest Savings Account Component + */ +@Component({ + selector: 'mifosx-post-interest-as-on-savings-account', + templateUrl: './post-interest-as-on-savings-account.component.html', + styleUrls: ['./post-interest-as-on-savings-account.component.scss'] +}) +export class PostInterestAsOnSavingsAccountComponent implements OnInit { + + /** Minimum date allowed. */ + minDate = new Date(2000, 0, 1); + /** Maximum date allowed. */ + maxDate = new Date(); + /** Post Interest Savings Account form. */ + postInterestSavingsAccountForm: FormGroup; + /** Savings Account Id */ + accountId: any; + + /** + * @param {FormBuilder} formBuilder Form Builder + * @param {SavingsService} savingsService Savings Service + * @param {DatePipe} datePipe Date Pipe + * @param {ActivatedRoute} route Activated Route + * @param {Router} router Router + */ + constructor(private formBuilder: FormBuilder, + private savingsService: SavingsService, + private datePipe: DatePipe, + private route: ActivatedRoute, + private router: Router) { + this.accountId = this.route.parent.snapshot.params['savingAccountId']; + } + + /** + * Creates the post interest savings form. + */ + ngOnInit() { + this.createPostInterestSavingsAccountForm(); + } + + /** + * Creates the post interest savings account form. + */ + createPostInterestSavingsAccountForm() { + this.postInterestSavingsAccountForm = this.formBuilder.group({ + 'transactionDate': ['', Validators.required] + }); + } + + /** + * Submits the form and post interests of the saving account, + * if successful redirects to the saving account. + */ + submit() { + // TODO: Update once language and date settings are setup + const locale = 'en'; + const dateFormat = 'dd MMMM yyyy'; + const prevTransactionDate: Date = this.postInterestSavingsAccountForm.value.transactionDate; + this.postInterestSavingsAccountForm.patchValue({ + transactionDate: this.datePipe.transform(prevTransactionDate, dateFormat), + }); + const data = { + ...this.postInterestSavingsAccountForm.value, + IsPostInterestAsOn: true, + dateFormat, + locale + }; + this.savingsService.executeSavingsAccountTransactionsCommand(this.accountId, 'postInterestAsOn', data).subscribe(() => { + this.router.navigate(['../../'], { relativeTo: this.route }); + }); + } + +} diff --git a/src/app/savings/saving-account-actions/saving-account-actions.component.html b/src/app/savings/saving-account-actions/saving-account-actions.component.html index f188cac41..62b6ba688 100644 --- a/src/app/savings/saving-account-actions/saving-account-actions.component.html +++ b/src/app/savings/saving-account-actions/saving-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/savings/saving-account-actions/saving-account-actions.component.ts b/src/app/savings/saving-account-actions/saving-account-actions.component.ts index 6dc59fb45..d1f731f6d 100644 --- a/src/app/savings/saving-account-actions/saving-account-actions.component.ts +++ b/src/app/savings/saving-account-actions/saving-account-actions.component.ts @@ -21,12 +21,14 @@ export class SavingAccountActionsComponent { 'Withdraw': boolean 'Activate': boolean 'Undo Approval': boolean + 'Post Interest As On': boolean } = { 'Approve': false, 'Reject': false, 'Withdraw': false, 'Activate': false, - 'Undo Approval': false + 'Undo Approval': false, + 'Post Interest As On': false }; /** diff --git a/src/app/savings/savings-account-view/savings-account-view.component.ts b/src/app/savings/savings-account-view/savings-account-view.component.ts index b16e89c07..2acce70b4 100644 --- a/src/app/savings/savings-account-view/savings-account-view.component.ts +++ b/src/app/savings/savings-account-view/savings-account-view.component.ts @@ -103,6 +103,7 @@ export class SavingsAccountViewComponent implements OnInit { case 'Withdraw': case 'Activate': case 'Undo Approval': + case 'Post Interest As On': this.router.navigate([`actions/${name}`], { relativeTo: this.route }); break; case 'Modify Application': diff --git a/src/app/savings/savings.module.ts b/src/app/savings/savings.module.ts index 3eb62105b..4066af238 100644 --- a/src/app/savings/savings.module.ts +++ b/src/app/savings/savings.module.ts @@ -30,6 +30,7 @@ import { RejectSavingsAccountComponent } from './saving-account-actions/reject-s import { WithdrawSavingsAccountComponent } from './saving-account-actions/withdraw-savings-account/withdraw-savings-account.component'; import { ActivateSavingsAccountComponent } from './saving-account-actions/activate-savings-account/activate-savings-account.component'; import { UndoApprovalSavingsAccountComponent } from './saving-account-actions/undo-approval-savings-account/undo-approval-savings-account.component'; +import { PostInterestAsOnSavingsAccountComponent } from './saving-account-actions/post-interest-as-on-savings-account/post-interest-as-on-savings-account.component'; /** * Savings Module @@ -64,7 +65,8 @@ import { UndoApprovalSavingsAccountComponent } from './saving-account-actions/un RejectSavingsAccountComponent, WithdrawSavingsAccountComponent, ActivateSavingsAccountComponent, - UndoApprovalSavingsAccountComponent + UndoApprovalSavingsAccountComponent, + PostInterestAsOnSavingsAccountComponent ], providers: [DatePipe] }) diff --git a/src/app/savings/savings.service.ts b/src/app/savings/savings.service.ts index feb92880a..9e2fb7461 100644 --- a/src/app/savings/savings.service.ts +++ b/src/app/savings/savings.service.ts @@ -194,4 +194,15 @@ export class SavingsService { return this.http.post(`/savingsaccounts/${accountId}`, data, { params: httpParams }); } + /** + * @param {string} accountId Savings Account Id + * @param {string} command Command + * @param {any} data Data + * @returns {Observable} Savings data. + */ + executeSavingsAccountTransactionsCommand(accountId: string, command: string, data: any): Observable { + const httpParams = new HttpParams().set('command', command); + return this.http.post(`/savingsaccounts/${accountId}/transactions`, data, { params: httpParams }); + } + }