feat: edit and delete financial activity mapping

Add edit financial activity component and delete dialog component.
This commit is contained in:
abhay_1806
2018-07-28 20:18:01 +05:30
committed by Abhay Chawla
parent 8ebfd61aa3
commit ff8e878e9a
15 changed files with 279 additions and 38 deletions
@@ -0,0 +1,40 @@
<div class="container">
<mat-card>
<form [formGroup]="financialActivityMappingForm" (ngSubmit)="submit()">
<mat-card-content>
<div fxLayout="column">
<mat-form-field>
<mat-select placeholder="Financial Activity" required formControlName="financialActivityId">
<mat-option *ngFor="let financialActivity of financialActivityData" [value]="financialActivity.id">
{{ financialActivity.name }}
</mat-option>
</mat-select>
</mat-form-field>
<mat-form-field>
<mat-select placeholder="Account" required formControlName="glAccountId">
<mat-option *ngFor="let glAccount of glAccountData" [value]="glAccount.id">
{{ glAccount.name + ' (' + glAccount.glCode + ')' }}
</mat-option>
</mat-select>
</mat-form-field>
</div>
</mat-card-content>
<mat-card-actions fxLayout="row" fxLayout.xs="column" fxLayoutAlign="center" fxLayoutGap="5px">
<button type="button" mat-raised-button [routerLink]="['/accounting/financial-activity-mappings/view', financialActivityAccountId]">Cancel</button>
<button mat-raised-button color="primary">Submit</button>
</mat-card-actions>
</form>
</mat-card>
</div>
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { EditFinancialActivityMappingComponent } from './edit-financial-activity-mapping.component';
describe('EditFinancialActivityMappingComponent', () => {
let component: EditFinancialActivityMappingComponent;
let fixture: ComponentFixture<EditFinancialActivityMappingComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ EditFinancialActivityMappingComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(EditFinancialActivityMappingComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,73 @@
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-financial-activity-mapping',
templateUrl: './edit-financial-activity-mapping.component.html',
styleUrls: ['./edit-financial-activity-mapping.component.scss']
})
export class EditFinancialActivityMappingComponent implements OnInit {
financialActivityMappingForm: FormGroup;
glAccountOptions: any;
glAccountData: any;
financialActivityAccountId: any;
financialActivityData: any;
constructor(private route: ActivatedRoute,
private formBuider: FormBuilder,
private accountingService: AccountingService,
private router: Router) { }
ngOnInit() {
this.financialActivityAccountId = this.route.snapshot.paramMap.get('id');
this.createFinancialActivityMappingForm();
this.setGLAccountData();
this.getFinancialActivityAccount();
}
createFinancialActivityMappingForm() {
this.financialActivityMappingForm = this.formBuider.group({
'financialActivityId': ['', Validators.required],
'glAccountId': ['', Validators.required]
});
}
getFinancialActivityAccount() {
this.accountingService.getFinancialActivityAccount(this.financialActivityAccountId, true)
.subscribe((financialActivityAccountData: any) => {
this.glAccountOptions = financialActivityAccountData.glAccountOptions;
this.financialActivityData = financialActivityAccountData.financialActivityOptions;
this.financialActivityMappingForm.get('financialActivityId').setValue(financialActivityAccountData.financialActivityData.id);
this.financialActivityMappingForm.get('glAccountId').setValue(financialActivityAccountData.glAccountData.id);
});
}
setGLAccountData() {
this.financialActivityMappingForm.get('financialActivityId').valueChanges.subscribe(financialActivityId => {
switch (financialActivityId) {
case 100:
case 101:
case 102:
case 103: this.glAccountData = this.glAccountOptions.assetAccountOptions;
break;
case 200:
case 201: this.glAccountData = this.glAccountOptions.liabilityAccountOptions;
break;
case 300: this.glAccountData = this.glAccountOptions.equityAccountOptions;
break;
}
});
}
submit() {
this.accountingService.updateFinancialActivityAccount(this.financialActivityAccountId, this.financialActivityMappingForm.value)
.subscribe((response: any) => {
this.router.navigate(['/accounting/financial-activity-mappings/view', response.resourceId]);
});
}
}