feat; savings account actions (enable/disable-withhold-tax) (#945)

Fixes: #944
This commit is contained in:
Karan Takalkar
2020-06-29 01:09:36 +05:30
committed by GitHub
parent d800f05ae3
commit be0e7032a7
7 changed files with 120 additions and 9 deletions
@@ -0,0 +1,8 @@
<h1 mat-dialog-title>{{ data.isEnable ? 'Enable' : 'Disable' }} Withhold Tax</h1>
<div mat-dialog-content>
<p>Are you sure you want to {{ data.isEnable ? 'enable' : 'disable' }} withhold tax for this account ?</p>
</div>
<mat-dialog-actions align="end">
<button mat-raised-button mat-dialog-close>Cancel</button>
<button mat-raised-button color="{{ data.isEnable ? 'accent' : 'warn' }}" [mat-dialog-close]="{ confirm: true }">Confirm</button>
</mat-dialog-actions>
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ToggleWithholdTaxDialogComponent } from './toggle-withhold-tax-dialog.component';
describe('ToggleWithholdTaxDialogComponent', () => {
let component: ToggleWithholdTaxDialogComponent;
let fixture: ComponentFixture<ToggleWithholdTaxDialogComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ ToggleWithholdTaxDialogComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(ToggleWithholdTaxDialogComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,22 @@
/** Angular Imports */
import { Component, Inject } from '@angular/core';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';
/**
* Toggle withhold tax dialog dialog component.
*/
@Component({
selector: 'mifosx-toggle-withhold-tax-dialog',
templateUrl: './toggle-withhold-tax-dialog.component.html',
styleUrls: ['./toggle-withhold-tax-dialog.component.scss']
})
export class ToggleWithholdTaxDialogComponent {
/**
* @param {MatDialogRef} dialogRef Component reference to dialog.
* @param {any} data.
*/
constructor(public dialogRef: MatDialogRef<ToggleWithholdTaxDialogComponent>,
@Inject(MAT_DIALOG_DATA) public data: any) { }
}
@@ -7,6 +7,7 @@ import { MatDialog } from '@angular/material';
import { DeleteDialogComponent } from 'app/shared/delete-dialog/delete-dialog.component';
import { CalculateInterestDialogComponent } from './custom-dialogs/calculate-interest-dialog/calculate-interest-dialog.component';
import { PostInterestDialogComponent } from './custom-dialogs/post-interest-dialog/post-interest-dialog.component';
import { ToggleWithholdTaxDialogComponent } from './custom-dialogs/toggle-withhold-tax-dialog/toggle-withhold-tax-dialog.component';
/** Custom Buttons Configuration */
import { SavingsButtonsConfiguration } from './savings-buttons.config';
@@ -98,6 +99,18 @@ export class SavingsAccountViewComponent implements OnInit {
}
}
/**
* Refetches data fot the component
* TODO: Replace by a custom reload component instead of hard-coded back-routing.
*/
reload() {
const clientId = this.savingsAccountData.clientId;
const url: string = this.router.url;
this.router.navigateByUrl(`/clients/${clientId}/savingsaccounts`, {skipLocationChange: true})
.then(() => this.router.navigate([url]));
}
/**
* Performs action button/option action.
* @param {string} name action name.
@@ -132,6 +145,12 @@ export class SavingsAccountViewComponent implements OnInit {
case 'Post Interest':
this.postInterest();
break;
case 'Enable Withhold Tax':
this.enableWithHoldTax();
break;
case 'Disable Withhold Tax':
this.disableWithHoldTax();
break;
}
}
@@ -180,14 +199,37 @@ export class SavingsAccountViewComponent implements OnInit {
}
/**
* Refetches data fot the component
* TODO: Replace by a custom reload component instead of hard-coded back-routing.
* Enables withhold tax for savings account.
*/
private reload() {
const clientId = this.savingsAccountData.clientId;
const url: string = this.router.url;
this.router.navigateByUrl(`/clients/${clientId}/savingsaccounts`, {skipLocationChange: true})
.then(() => this.router.navigate([url]));
private enableWithHoldTax() {
const deleteSavingsAccountDialogRef = this.dialog.open(ToggleWithholdTaxDialogComponent, {
data: { isEnable: true }
});
deleteSavingsAccountDialogRef.afterClosed().subscribe((response: any) => {
if (response.confirm) {
this.savingsService.executeSavingsAccountUpdateCommand(this.savingsAccountData.id, 'updateWithHoldTax', { withHoldTax: true})
.subscribe(() => {
this.reload();
});
}
});
}
/**
* Disables withhold tac for savings account
*/
private disableWithHoldTax() {
const disableWithHoldTaxDialogRef = this.dialog.open(ToggleWithholdTaxDialogComponent, {
data: { isEnable: false }
});
disableWithHoldTaxDialogRef.afterClosed().subscribe((response: any) => {
if (response.confirm) {
this.savingsService.executeSavingsAccountUpdateCommand(this.savingsAccountData.id, 'updateWithHoldTax', { withHoldTax: false})
.subscribe(() => {
this.reload();
});
}
});
}
}
+5 -2
View File
@@ -41,6 +41,7 @@ import { InactivateChargeDialogComponent } from './savings-account-view/custom-d
import { WithdrawByClientSavingsAccountComponent } from './saving-account-actions/withdraw-by-client-savings-account/withdraw-by-client-savings-account.component';
import { AddChargeSavingsAccountComponent } from './saving-account-actions/add-charge-savings-account/add-charge-savings-account.component';
import { CloseSavingsAccountComponent } from './saving-account-actions/close-savings-account/close-savings-account.component';
import { ToggleWithholdTaxDialogComponent } from './savings-account-view/custom-dialogs/toggle-withhold-tax-dialog/toggle-withhold-tax-dialog.component';
/**
@@ -87,14 +88,16 @@ import { CloseSavingsAccountComponent } from './saving-account-actions/close-sav
InactivateChargeDialogComponent,
WithdrawByClientSavingsAccountComponent,
AddChargeSavingsAccountComponent,
CloseSavingsAccountComponent
CloseSavingsAccountComponent,
ToggleWithholdTaxDialogComponent
],
entryComponents: [
CalculateInterestDialogComponent,
PostInterestDialogComponent,
UndoTransactionDialogComponent,
WaiveChargeDialogComponent,
InactivateChargeDialogComponent
InactivateChargeDialogComponent,
ToggleWithholdTaxDialogComponent
],
providers: [DatePipe]
+11
View File
@@ -184,6 +184,17 @@ 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<any>} Savings data.
*/
executeSavingsAccountUpdateCommand(accountId: string, command: string, data: any): Observable<any> {
const httpParams = new HttpParams().set('command', command);
return this.http.put(`/savingsaccounts/${accountId}`, data, { params: httpParams });
}
/**
* @param {string} accountId Savings Account Id
* @param {string} transactionId Transaction Id