diff --git a/src/app/accounting/accounting-routing.module.ts b/src/app/accounting/accounting-routing.module.ts index 88e80b51d..7182ae191 100644 --- a/src/app/accounting/accounting-routing.module.ts +++ b/src/app/accounting/accounting-routing.module.ts @@ -18,6 +18,7 @@ import { ChartOfAccountsResolver } from './chart-of-accounts/chart-of-accounts.r import { CreateGlAccountComponent } from './chart-of-accounts/create-gl-account/create-gl-account.component'; import { ViewGlAccountComponent } from './chart-of-accounts/view-gl-account/view-gl-account.component'; import { ViewGlAccountResolver } from './chart-of-accounts/view-gl-account/view-gl-account.resolver'; +import { EditGlAccountComponent } from './chart-of-accounts/edit-gl-account/edit-gl-account.component'; const routes: Routes = [ Route.withShell([ @@ -103,11 +104,22 @@ const routes: Routes = [ }, { path: 'gl-accounts/view/:id', - component: ViewGlAccountComponent, data: { title: extract('View GL Account'), routeResolveBreadcrumb: ['glAccount', 'name'] }, resolve: { glAccount: ViewGlAccountResolver - } + }, + runGuardsAndResolvers: 'always', + children: [ + { + path: '', + component: ViewGlAccountComponent + }, + { + path: 'edit', + component: EditGlAccountComponent, + data: { title: extract('Edit GL Account'), breadcrumb: 'Edit', routeResolveBreadcrumb: false } + } + ] } ] } diff --git a/src/app/accounting/accounting.module.ts b/src/app/accounting/accounting.module.ts index 02dfa618e..23bcbca2c 100644 --- a/src/app/accounting/accounting.module.ts +++ b/src/app/accounting/accounting.module.ts @@ -18,6 +18,7 @@ import { EditFinancialActivityMappingComponent } from './financial-activity-mapp import { ChartOfAccountsComponent } from './chart-of-accounts/chart-of-accounts.component'; import { CreateGlAccountComponent } from './chart-of-accounts/create-gl-account/create-gl-account.component'; import { ViewGlAccountComponent } from './chart-of-accounts/view-gl-account/view-gl-account.component'; +import { EditGlAccountComponent } from './chart-of-accounts/edit-gl-account/edit-gl-account.component'; @NgModule({ imports: [ @@ -41,7 +42,8 @@ import { ViewGlAccountComponent } from './chart-of-accounts/view-gl-account/view EditFinancialActivityMappingComponent, ChartOfAccountsComponent, CreateGlAccountComponent, - ViewGlAccountComponent + ViewGlAccountComponent, + EditGlAccountComponent ], entryComponents: [ RevertTransactionComponent, diff --git a/src/app/accounting/accounting.service.ts b/src/app/accounting/accounting.service.ts index b8f03ed07..b2b4d5e46 100644 --- a/src/app/accounting/accounting.service.ts +++ b/src/app/accounting/accounting.service.ts @@ -113,4 +113,12 @@ export class AccountingService { return this.http.get(`/glaccounts/${glAccountId}`, { params: httpParams }); } + updateGlAccount(glAccountId: number, glAccount: any) { + return this.http.put(`/glaccounts/${glAccountId}`, glAccount); + } + + deleteGlAccount(glAccountId: number) { + return this.http.delete(`/glaccounts/${glAccountId}`); + } + } diff --git a/src/app/accounting/chart-of-accounts/edit-gl-account/edit-gl-account.component.html b/src/app/accounting/chart-of-accounts/edit-gl-account/edit-gl-account.component.html new file mode 100644 index 000000000..c7de4a3ef --- /dev/null +++ b/src/app/accounting/chart-of-accounts/edit-gl-account/edit-gl-account.component.html @@ -0,0 +1,74 @@ +
+ + + +
+ + + +
+ + + + + {{ accountType.value }} + + + + + + + + + + + + {{ accountUsage.value }} + + + + + + + + + + + + {{ parent.name }} + + + + + + + + {{ tag.name }} + + + + +
+ + Manual Entries Allowed + +
+ + + + + +
+ +
+ + + + + + +
+ +
+ +
diff --git a/src/app/accounting/chart-of-accounts/edit-gl-account/edit-gl-account.component.scss b/src/app/accounting/chart-of-accounts/edit-gl-account/edit-gl-account.component.scss new file mode 100644 index 000000000..e69de29bb diff --git a/src/app/accounting/chart-of-accounts/edit-gl-account/edit-gl-account.component.spec.ts b/src/app/accounting/chart-of-accounts/edit-gl-account/edit-gl-account.component.spec.ts new file mode 100644 index 000000000..29379a7ab --- /dev/null +++ b/src/app/accounting/chart-of-accounts/edit-gl-account/edit-gl-account.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { EditGlAccountComponent } from './edit-gl-account.component'; + +describe('EditGlAccountComponent', () => { + let component: EditGlAccountComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ EditGlAccountComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(EditGlAccountComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/accounting/chart-of-accounts/edit-gl-account/edit-gl-account.component.ts b/src/app/accounting/chart-of-accounts/edit-gl-account/edit-gl-account.component.ts new file mode 100644 index 000000000..52173add0 --- /dev/null +++ b/src/app/accounting/chart-of-accounts/edit-gl-account/edit-gl-account.component.ts @@ -0,0 +1,80 @@ +import { Component, OnInit } from '@angular/core'; +import { ActivatedRoute, Router } from '@angular/router'; +import { FormGroup, FormBuilder, Validators } from '@angular/forms'; + +import { AccountingService } from '../../accounting.service'; + +@Component({ + selector: 'mifosx-edit-gl-account', + templateUrl: './edit-gl-account.component.html', + styleUrls: ['./edit-gl-account.component.scss'] +}) +export class EditGlAccountComponent implements OnInit { + + glAccountForm: FormGroup; + glAccount: any; + accountTypeData: any; + accountUsageData: any; + parentData: any; + tagData: any; + + constructor(private route: ActivatedRoute, + private formBuilder: FormBuilder, + private accountingService: AccountingService, + private router: Router) { + this.route.data.subscribe((data: { glAccount: any }) => { + this.glAccount = data.glAccount; + }); + } + + ngOnInit() { + this.createGlAccountForm(); + this.setGLAccountForm(); + } + + createGlAccountForm() { + this.glAccountForm = this.formBuilder.group({ + 'type': ['', Validators.required], + 'name': [this.glAccount.name, Validators.required], + 'usage': [this.glAccount.usage.id, Validators.required], + 'glCode': [this.glAccount.glCode, Validators.required], + 'parentId': [this.glAccount.parentId], + 'tagId': [this.glAccount.tagId.id], + 'manualEntriesAllowed': [this.glAccount.manualEntriesAllowed, Validators.required], + 'description': [this.glAccount.description] + }); + } + + setGLAccountForm() { + this.accountTypeData = this.glAccount.accountTypeOptions; + this.accountUsageData = this.glAccount.usageOptions; + this.glAccountForm.get('type').valueChanges.subscribe(accountTypeId => { + switch (accountTypeId) { + case 1: this.parentData = this.glAccount.assetHeaderAccountOptions; + this.tagData = this.glAccount.allowedAssetsTagOptions; + break; + case 2: this.parentData = this.glAccount.liabilityHeaderAccountOptions; + this.tagData = this.glAccount.allowedLiabilitiesTagOptions; + break; + case 3: this.parentData = this.glAccount.equityHeaderAccountOptions; + this.tagData = this.glAccount.allowedEquityTagOptions; + break; + case 4: this.parentData = this.glAccount.incomeHeaderAccountOptions; + this.tagData = this.glAccount.allowedIncomeTagOptions; + break; + case 5: this.parentData = this.glAccount.expenseHeaderAccountOptions; + this.tagData = this.glAccount.allowedExpensesTagOptions; + break; + } + }); + this.glAccountForm.get('type').setValue(this.glAccount.type.id); + } + + submit() { + this.accountingService.updateGlAccount(this.glAccount.id, this.glAccountForm.value) + .subscribe((response: any) => { + this.router.navigate(['/accounting/chart-of-accounts/gl-accounts/view', response.resourceId]); + }); + } + +} diff --git a/src/app/accounting/chart-of-accounts/view-gl-account/view-gl-account.component.html b/src/app/accounting/chart-of-accounts/view-gl-account/view-gl-account.component.html index 2bfb67e1c..84b7f98d3 100644 --- a/src/app/accounting/chart-of-accounts/view-gl-account/view-gl-account.component.html +++ b/src/app/accounting/chart-of-accounts/view-gl-account/view-gl-account.component.html @@ -5,10 +5,10 @@ - -