feat: edit, delete and enable/disable GL Account

Chart of Accounts:
  * Edit GL Account Component
  * Delete GL Account
  * Enable/Disable GL Account
This commit is contained in:
Abhay Chawla
2018-08-04 22:09:54 +05:30
parent 1707c2742c
commit 1390540474
9 changed files with 237 additions and 7 deletions
@@ -5,10 +5,10 @@
<button mat-raised-button color="primary" [routerLink]="['/accounting/chart-of-accounts/gl-accounts/view', glAccount.id, 'edit']">
<mat-icon>edit</mat-icon>&nbsp;&nbsp;Edit
</button>
<button mat-raised-button color="warn" *ngIf="!glAccount.disabled">
<button mat-raised-button color="warn" *ngIf="!glAccount.disabled" (click)="changeGlAccountState()">
<mat-icon>lock</mat-icon>&nbsp;&nbsp;Disable
</button>
<button mat-raised-button color="accent" *ngIf="glAccount.disabled">
<button mat-raised-button color="accent" *ngIf="glAccount.disabled" (click)="changeGlAccountState()">
<mat-icon>lock_open</mat-icon>&nbsp;&nbsp;Enable
</button>
<button mat-raised-button color="warn" (click)="deleteGlAccount()">
@@ -1,5 +1,9 @@
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { ActivatedRoute, Router } from '@angular/router';
import { MatDialog } from '@angular/material';
import { DeleteDialogComponent } from '../../../shared/delete-dialog/delete-dialog.component';
import { AccountingService } from '../../accounting.service';
@Component({
selector: 'mifosx-view-gl-account',
@@ -10,7 +14,10 @@ export class ViewGlAccountComponent implements OnInit {
glAccount: any;
constructor(private route: ActivatedRoute) {
constructor(private route: ActivatedRoute,
private accountingService: AccountingService,
private router: Router,
public dialog: MatDialog) {
this.route.data.subscribe((data: { glAccount: any }) => {
this.glAccount = data.glAccount;
});
@@ -19,4 +26,26 @@ export class ViewGlAccountComponent implements OnInit {
ngOnInit() {
}
deleteGlAccount() {
// TODO: (Validation) gl account cannot be deleted if it has transactions logged against it
const deleteGlAccountDialogRef = this.dialog.open(DeleteDialogComponent, {
data: { deleteContext: `gl account ${this.glAccount.id}` }
});
deleteGlAccountDialogRef.afterClosed().subscribe((response: any) => {
if (response.delete) {
this.accountingService.deleteGlAccount(this.glAccount.id)
.subscribe(() => {
this.router.navigate(['/accounting/chart-of-accounts']);
});
}
});
}
changeGlAccountState() {
this.accountingService.updateGlAccount(this.glAccount.id, { disabled: !this.glAccount.disabled })
.subscribe((response: any) => {
this.glAccount.disabled = response.changes.disabled;
});
}
}