feat: savings account charges actions (edit/delete) (#952)

Fixes: #951
This commit is contained in:
Karan Takalkar
2020-06-29 20:22:27 +05:30
committed by GitHub
parent 102d936479
commit 99fd6ad38c
5 changed files with 169 additions and 15 deletions
@@ -69,11 +69,11 @@
<td mat-cell *matCellDef="let charge">
<span *ngIf="savingsAccountData.status.value === 'Submitted and pending approval'">
<button class="account-action-button" mat-raised-button color="primary" matTooltip="Edit Charge"
*mifosxHasPermission="'UPDATE_SAVINGSACCOUNTCHARGE'">
*mifosxHasPermission="'UPDATE_SAVINGSACCOUNTCHARGE'" (click)="routeEdit($event); editCharge(charge)">
<i class="fa fa-pencil"></i>
</button>
<button class="account-action-button" mat-raised-button color="warn" matTooltip="Delete Charge"
*mifosxHasPermission="'DELETE_SAVINGSACCOUNTCHARGE'">
*mifosxHasPermission="'DELETE_SAVINGSACCOUNTCHARGE'" (click)="routeEdit($event); deleteCharge(charge.id)">
<i class="fa fa-trash"></i>
</button>
</span>
@@ -11,6 +11,7 @@ import { SavingsService } from 'app/savings/savings.service';
import { FormDialogComponent } from 'app/shared/form-dialog/form-dialog.component';
import { WaiveChargeDialogComponent } from '../custom-dialogs/waive-charge-dialog/waive-charge-dialog.component';
import { InactivateChargeDialogComponent } from '../custom-dialogs/inactivate-charge-dialog/inactivate-charge-dialog.component';
import { DeleteDialogComponent } from 'app/shared/delete-dialog/delete-dialog.component';
/** Custom Models */
import { FormfieldBase } from 'app/shared/form-dialog/formfield/model/formfield-base';
@@ -170,6 +171,61 @@ export class ChargesTabComponent implements OnInit {
});
}
/**
* Edits the charge
* @param {any} charge Charge
*/
editCharge(charge: any) {
const formfields: FormfieldBase[] = [
new InputBase({
controlName: 'amount',
label: 'Amount',
value: charge.amount || charge.amountOrPercentage,
type: 'number',
required: true
})
];
const data = {
title: `Edit Charge ${charge.id}`,
layout: { addButtonText: 'Confirm' },
formfields: formfields
};
const editChargeDialogRef = this.dialog.open(FormDialogComponent, { data });
editChargeDialogRef.afterClosed().subscribe((response: any) => {
if (response.data) {
const locale = 'en';
const dateFormat = 'dd MMMM yyyy';
const dataObject = {
...response.data.value,
dateFormat,
locale
};
this.savingsService.editSavingsAccountCharge(this.savingsAccountData.id, dataObject, charge.id)
.subscribe(() => {
this.reload();
});
}
});
}
/**
* Deletes the charge
* @param {any} chargeId Charge Id
*/
deleteCharge(chargeId: any) {
const deleteChargeDialogRef = this.dialog.open(DeleteDialogComponent, {
data: { deleteContext: `charge id:${chargeId}` }
});
deleteChargeDialogRef.afterClosed().subscribe((response: any) => {
if (response.delete) {
this.savingsService.deleteSavingsAccountCharge(this.savingsAccountData.id, chargeId)
.subscribe(() => {
this.reload();
});
}
});
}
/**
* Checks if charge is recurring.
* @param {any} charge Charge