diff --git a/src/app/savings/savings-account-view/custom-dialogs/toggle-withhold-tax-dialog/toggle-withhold-tax-dialog.component.html b/src/app/savings/savings-account-view/custom-dialogs/toggle-withhold-tax-dialog/toggle-withhold-tax-dialog.component.html
new file mode 100644
index 000000000..5f58d474d
--- /dev/null
+++ b/src/app/savings/savings-account-view/custom-dialogs/toggle-withhold-tax-dialog/toggle-withhold-tax-dialog.component.html
@@ -0,0 +1,8 @@
+
{{ data.isEnable ? 'Enable' : 'Disable' }} Withhold Tax
+
+
Are you sure you want to {{ data.isEnable ? 'enable' : 'disable' }} withhold tax for this account ?
+
+
+
+
+
diff --git a/src/app/savings/savings-account-view/custom-dialogs/toggle-withhold-tax-dialog/toggle-withhold-tax-dialog.component.scss b/src/app/savings/savings-account-view/custom-dialogs/toggle-withhold-tax-dialog/toggle-withhold-tax-dialog.component.scss
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/app/savings/savings-account-view/custom-dialogs/toggle-withhold-tax-dialog/toggle-withhold-tax-dialog.component.spec.ts b/src/app/savings/savings-account-view/custom-dialogs/toggle-withhold-tax-dialog/toggle-withhold-tax-dialog.component.spec.ts
new file mode 100644
index 000000000..f0214dca7
--- /dev/null
+++ b/src/app/savings/savings-account-view/custom-dialogs/toggle-withhold-tax-dialog/toggle-withhold-tax-dialog.component.spec.ts
@@ -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;
+
+ beforeEach(async(() => {
+ TestBed.configureTestingModule({
+ declarations: [ ToggleWithholdTaxDialogComponent ]
+ })
+ .compileComponents();
+ }));
+
+ beforeEach(() => {
+ fixture = TestBed.createComponent(ToggleWithholdTaxDialogComponent);
+ component = fixture.componentInstance;
+ fixture.detectChanges();
+ });
+
+ it('should create', () => {
+ expect(component).toBeTruthy();
+ });
+});
diff --git a/src/app/savings/savings-account-view/custom-dialogs/toggle-withhold-tax-dialog/toggle-withhold-tax-dialog.component.ts b/src/app/savings/savings-account-view/custom-dialogs/toggle-withhold-tax-dialog/toggle-withhold-tax-dialog.component.ts
new file mode 100644
index 000000000..11aee1734
--- /dev/null
+++ b/src/app/savings/savings-account-view/custom-dialogs/toggle-withhold-tax-dialog/toggle-withhold-tax-dialog.component.ts
@@ -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,
+ @Inject(MAT_DIALOG_DATA) public data: any) { }
+
+}
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 e54d74210..62f971b0e 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
@@ -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();
+ });
+ }
+ });
}
}
diff --git a/src/app/savings/savings.module.ts b/src/app/savings/savings.module.ts
index 11e53f9b9..127cf2db6 100644
--- a/src/app/savings/savings.module.ts
+++ b/src/app/savings/savings.module.ts
@@ -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]
diff --git a/src/app/savings/savings.service.ts b/src/app/savings/savings.service.ts
index eaa6838c8..420ac7675 100644
--- a/src/app/savings/savings.service.ts
+++ b/src/app/savings/savings.service.ts
@@ -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} Savings data.
+ */
+ executeSavingsAccountUpdateCommand(accountId: string, command: string, data: any): Observable {
+ 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