From 6c80e86c0c5b71b9b3e95d2293a0432fd558b68c Mon Sep 17 00:00:00 2001 From: Abhay Chawla Date: Sat, 4 Aug 2018 21:57:50 +0530 Subject: [PATCH] feat(closing-entries): edit and delete closure Add edit closure component and ability to delete an accounting closure to backdate a transaction. --- .../accounting/accounting-routing.module.ts | 15 ++++- src/app/accounting/accounting.module.ts | 4 +- src/app/accounting/accounting.service.ts | 8 +++ .../create-closure.component.ts | 2 +- .../edit-closure/edit-closure.component.html | 42 ++++++++++++ .../edit-closure/edit-closure.component.scss | 3 + .../edit-closure.component.spec.ts | 25 ++++++++ .../edit-closure/edit-closure.component.ts | 64 +++++++++++++++++++ .../view-closure/view-closure.component.html | 3 + .../view-closure/view-closure.component.ts | 22 ++++++- 10 files changed, 182 insertions(+), 6 deletions(-) create mode 100644 src/app/accounting/closing-entries/edit-closure/edit-closure.component.html create mode 100644 src/app/accounting/closing-entries/edit-closure/edit-closure.component.scss create mode 100644 src/app/accounting/closing-entries/edit-closure/edit-closure.component.spec.ts create mode 100644 src/app/accounting/closing-entries/edit-closure/edit-closure.component.ts diff --git a/src/app/accounting/accounting-routing.module.ts b/src/app/accounting/accounting-routing.module.ts index 9085722e1..bea24b9cd 100644 --- a/src/app/accounting/accounting-routing.module.ts +++ b/src/app/accounting/accounting-routing.module.ts @@ -24,6 +24,7 @@ import { EditGlAccountComponent } from './chart-of-accounts/edit-gl-account/edit import { ClosingEntriesComponent } from './closing-entries/closing-entries.component'; import { CreateClosureComponent } from './closing-entries/create-closure/create-closure.component'; import { ViewClosureComponent } from './closing-entries/view-closure/view-closure.component'; +import { EditClosureComponent } from './closing-entries/edit-closure/edit-closure.component'; const routes: Routes = [ Route.withShell([ @@ -146,8 +147,18 @@ const routes: Routes = [ }, { path: 'view/:id', - component: ViewClosureComponent, - data: { title: extract('View Accounting Closure'), routeParamBreadcrumb: 'id' } + data: { title: extract('View Accounting Closure'), routeParamBreadcrumb: 'id' }, + children: [ + { + path: '', + component: ViewClosureComponent + }, + { + path: 'edit', + component: EditClosureComponent, + data: { title: extract('Edit Accounting Closure'), breadcrumb: 'Edit', routeParamBreadcrumb: false } + } + ] } ] } diff --git a/src/app/accounting/accounting.module.ts b/src/app/accounting/accounting.module.ts index 6279c5e93..d201d0f2f 100644 --- a/src/app/accounting/accounting.module.ts +++ b/src/app/accounting/accounting.module.ts @@ -23,6 +23,7 @@ import { EditGlAccountComponent } from './chart-of-accounts/edit-gl-account/edit import { ClosingEntriesComponent } from './closing-entries/closing-entries.component'; import { CreateClosureComponent } from './closing-entries/create-closure/create-closure.component'; import { ViewClosureComponent } from './closing-entries/view-closure/view-closure.component'; +import { EditClosureComponent } from './closing-entries/edit-closure/edit-closure.component'; @NgModule({ imports: [ @@ -50,7 +51,8 @@ import { ViewClosureComponent } from './closing-entries/view-closure/view-closur EditGlAccountComponent, ClosingEntriesComponent, CreateClosureComponent, - ViewClosureComponent + ViewClosureComponent, + EditClosureComponent ], entryComponents: [ RevertTransactionComponent, diff --git a/src/app/accounting/accounting.service.ts b/src/app/accounting/accounting.service.ts index 2a9ac90b0..28f802aa0 100644 --- a/src/app/accounting/accounting.service.ts +++ b/src/app/accounting/accounting.service.ts @@ -133,4 +133,12 @@ export class AccountingService { return this.http.get(`/glclosures/${accountingClosureId}`); } + deleteAccountingClosure(accountingClosureId: number) { + return this.http.delete(`/glclosures/${accountingClosureId}`); + } + + updateAccountingClosure(accountingClosureId: number, accountingClosure: any) { + return this.http.put(`/glclosures/${accountingClosureId}`, accountingClosure); + } + } diff --git a/src/app/accounting/closing-entries/create-closure/create-closure.component.ts b/src/app/accounting/closing-entries/create-closure/create-closure.component.ts index 6b5127707..334403f55 100644 --- a/src/app/accounting/closing-entries/create-closure/create-closure.component.ts +++ b/src/app/accounting/closing-entries/create-closure/create-closure.component.ts @@ -11,7 +11,7 @@ import { AccountingService } from '../../accounting.service'; }) export class CreateClosureComponent implements OnInit { - // TODO: Validations, Hints + // TODO: Validations, Hints minDate = new Date(2000, 0, 1); maxDate = new Date(); diff --git a/src/app/accounting/closing-entries/edit-closure/edit-closure.component.html b/src/app/accounting/closing-entries/edit-closure/edit-closure.component.html new file mode 100644 index 000000000..237d8021a --- /dev/null +++ b/src/app/accounting/closing-entries/edit-closure/edit-closure.component.html @@ -0,0 +1,42 @@ +
+ + + +
+ + + +
+ + + + + {{ office.name }} + + + + + + + + + + + + + + +
+ +
+ + + + + + +
+ +
+ +
diff --git a/src/app/accounting/closing-entries/edit-closure/edit-closure.component.scss b/src/app/accounting/closing-entries/edit-closure/edit-closure.component.scss new file mode 100644 index 000000000..d774f68da --- /dev/null +++ b/src/app/accounting/closing-entries/edit-closure/edit-closure.component.scss @@ -0,0 +1,3 @@ +.container { + max-width: 37rem; +} diff --git a/src/app/accounting/closing-entries/edit-closure/edit-closure.component.spec.ts b/src/app/accounting/closing-entries/edit-closure/edit-closure.component.spec.ts new file mode 100644 index 000000000..1bc389aa0 --- /dev/null +++ b/src/app/accounting/closing-entries/edit-closure/edit-closure.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { EditClosureComponent } from './edit-closure.component'; + +describe('EditClosureComponent', () => { + let component: EditClosureComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ EditClosureComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(EditClosureComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/accounting/closing-entries/edit-closure/edit-closure.component.ts b/src/app/accounting/closing-entries/edit-closure/edit-closure.component.ts new file mode 100644 index 000000000..7bcdc0ce6 --- /dev/null +++ b/src/app/accounting/closing-entries/edit-closure/edit-closure.component.ts @@ -0,0 +1,64 @@ +import { Component, OnInit } from '@angular/core'; +import { FormBuilder, FormGroup, Validators } from '@angular/forms'; +import { Router, ActivatedRoute } from '@angular/router'; + +import { AccountingService } from '../../accounting.service'; + +@Component({ + selector: 'mifosx-edit-closure', + templateUrl: './edit-closure.component.html', + styleUrls: ['./edit-closure.component.scss'] +}) +export class EditClosureComponent implements OnInit { + + // TODO: Update once language and date settings are setup + + accountingClosureForm: FormGroup; + accountingClosureId: number; + accountingClosure: any; + officeData: any; + + constructor(private formBuilder: FormBuilder, + private accountingService: AccountingService, + private router: Router, + private route: ActivatedRoute) { } + + ngOnInit() { + this.accountingClosureId = Number(this.route.snapshot.paramMap.get('id')); + this.createAccountingClosureForm(); + this.getAccountingClosure(); + this.getOffices(); + } + + getAccountingClosure() { + this.accountingService.getAccountingClosure(this.accountingClosureId) + .subscribe((accountingClosure: any) => { + this.accountingClosure = accountingClosure; + this.accountingClosureForm.get('officeId').setValue(this.accountingClosure.officeId); + this.accountingClosureForm.get('closingDate').setValue(new Date()); + this.accountingClosureForm.get('comments').setValue(this.accountingClosure.comments); + }); + } + + createAccountingClosureForm() { + this.accountingClosureForm = this.formBuilder.group({ + 'officeId': [{ value: '', disabled: true }, Validators.required], + 'closingDate': [{ value: '', disabled: true }, Validators.required], + 'comments': [''] + }); + } + + getOffices() { + this.accountingService.getOffices().subscribe(officeData => { + this.officeData = officeData; + }); + } + + submit() { + this.accountingService.updateAccountingClosure(this.accountingClosureId, { comments: this.accountingClosureForm.value.comments }) + .subscribe((response: any) => { + this.router.navigate(['/accounting/closing-entries/view', response.resourceId]); + }); + } + +} diff --git a/src/app/accounting/closing-entries/view-closure/view-closure.component.html b/src/app/accounting/closing-entries/view-closure/view-closure.component.html index d8fb23f1b..a07df34cd 100644 --- a/src/app/accounting/closing-entries/view-closure/view-closure.component.html +++ b/src/app/accounting/closing-entries/view-closure/view-closure.component.html @@ -1,4 +1,7 @@
+ diff --git a/src/app/accounting/closing-entries/view-closure/view-closure.component.ts b/src/app/accounting/closing-entries/view-closure/view-closure.component.ts index 081f1dab4..6895397bc 100644 --- a/src/app/accounting/closing-entries/view-closure/view-closure.component.ts +++ b/src/app/accounting/closing-entries/view-closure/view-closure.component.ts @@ -1,7 +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 { AccountingService } from '../../accounting.service'; +import { DeleteDialogComponent } from '../../../shared/delete-dialog/delete-dialog.component'; @Component({ selector: 'mifosx-view-closure', @@ -14,7 +16,9 @@ export class ViewClosureComponent implements OnInit { accountingClosure: any; constructor(private accountingService: AccountingService, - private route: ActivatedRoute) { } + private route: ActivatedRoute, + private router: Router, + public dialog: MatDialog) { } ngOnInit() { this.accountingClosureId = Number(this.route.snapshot.paramMap.get('id')); @@ -28,4 +32,18 @@ export class ViewClosureComponent implements OnInit { }); } + deleteAccountingClosure() { + const deleteAccountingClosureDialogRef = this.dialog.open(DeleteDialogComponent, { + data: { deleteContext: `accounting closure ${this.accountingClosureId}` } + }); + deleteAccountingClosureDialogRef.afterClosed().subscribe((response: any) => { + if (response.delete) { + this.accountingService.deleteAccountingClosure(this.accountingClosureId) + .subscribe(() => { + this.router.navigate(['/accounting/closing-entries']); + }); + } + }); + } + }