refractor: accounting module (#300)

* Refractor components.
* Add resolvers.
* Add relative router links.
* Replace mat-icons by font-awesome icons.
* Add comments.

Fixes: #298
This commit is contained in:
Abhay Chawla
2018-08-19 22:49:48 +05:30
committed by GitHub
parent 598f239251
commit 6e552d72eb
114 changed files with 3760 additions and 1432 deletions
@@ -9,7 +9,8 @@
<div fxLayout="column">
<mat-form-field>
<mat-select placeholder="Financial Activity" required formControlName="financialActivityId">
<mat-label>Financial Activity</mat-label>
<mat-select required formControlName="financialActivityId">
<mat-option *ngFor="let financialActivity of financialActivityData" [value]="financialActivity.id">
{{ financialActivity.name }}
</mat-option>
@@ -17,7 +18,8 @@
</mat-form-field>
<mat-form-field>
<mat-select placeholder="Account" required formControlName="glAccountId">
<mat-label>Account</mat-label>
<mat-select required formControlName="glAccountId">
<mat-option *ngFor="let glAccount of glAccountData" [value]="glAccount.id">
{{ glAccount.name + ' (' + glAccount.glCode + ')' }}
</mat-option>
@@ -29,8 +31,8 @@
</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>
<button type="button" mat-raised-button [routerLink]="['../']">Cancel</button>
<button mat-raised-button color="primary" [disabled]="financialActivityMappingForm.pristine">Submit</button>
</mat-card-actions>
</form>
@@ -1,9 +1,14 @@
/** Angular Imports */
import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { Router, ActivatedRoute } from '@angular/router';
/** Custom Services */
import { AccountingService } from '../../accounting.service';
/**
* Edit financial activity mapping component.
*/
@Component({
selector: 'mifosx-edit-financial-activity-mapping',
templateUrl: './edit-financial-activity-mapping.component.html',
@@ -11,24 +16,54 @@ import { AccountingService } from '../../accounting.service';
})
export class EditFinancialActivityMappingComponent implements OnInit {
/** Financial activity mapping form. */
financialActivityMappingForm: FormGroup;
/** GL Account options. */
glAccountOptions: any;
/** GL Account data. */
glAccountData: any;
financialActivityAccountId: any;
/** Financial activity data. */
financialActivityData: any;
/** Financial activity account ID. */
financialActivityAccountId: string;
/** Financial activity ID. */
financialActivityId: number;
/** GL Account ID. */
glAccountId: number;
constructor(private route: ActivatedRoute,
private formBuider: FormBuilder,
/**
* Retrieves the gl account options, financial activity and financial activity account data from `resolve`.
* @param {FormBuilder} formBuilder Form Builder.
* @param {AccountingService} accountingService Accounting Service.
* @param {ActivatedRoute} route Activated Route.
* @param {Router} router Router for navigation.
*/
constructor(private formBuider: FormBuilder,
private accountingService: AccountingService,
private router: Router) { }
ngOnInit() {
this.financialActivityAccountId = this.route.snapshot.paramMap.get('id');
this.createFinancialActivityMappingForm();
this.setGLAccountData();
this.getFinancialActivityAccount();
private route: ActivatedRoute,
private router: Router) {
this.route.data.subscribe((data: { financialActivityAccountAndTemplate: any }) => {
this.financialActivityAccountId = data.financialActivityAccountAndTemplate.id;
this.financialActivityId = data.financialActivityAccountAndTemplate.financialActivityData.id;
this.glAccountId = data.financialActivityAccountAndTemplate.glAccountData.id;
this.glAccountOptions = data.financialActivityAccountAndTemplate.glAccountOptions;
this.financialActivityData = data.financialActivityAccountAndTemplate.financialActivityOptions;
});
}
/**
* Creates and sets the financial activity mapping form and sets the gl account data.
*/
ngOnInit() {
this.createFinancialActivityMappingForm();
this.setGLAccountData();
this.financialActivityMappingForm.get('financialActivityId').setValue(this.financialActivityId);
this.financialActivityMappingForm.get('glAccountId').setValue(this.glAccountId);
}
/**
* Creates the financial activity mapping form.
*/
createFinancialActivityMappingForm() {
this.financialActivityMappingForm = this.formBuider.group({
'financialActivityId': ['', Validators.required],
@@ -36,37 +71,35 @@ export class EditFinancialActivityMappingComponent implements OnInit {
});
}
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);
/**
* Sets the gl account data on the basis of selected financial activity.
*/
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;
}
});
}
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;
}
});
}
/**
* Submits the financial activity mapping form and updates financial activity account,
* if successful redirects to view updated account.
*/
submit() {
this.accountingService.updateFinancialActivityAccount(this.financialActivityAccountId, this.financialActivityMappingForm.value)
.subscribe((response: any) => {
this.router.navigate(['/accounting/financial-activity-mappings/view', response.resourceId]);
this.router.navigate(['../../', response.resourceId], { relativeTo: this.route });
});
}
@@ -0,0 +1,31 @@
/** Angular Imports */
import { Injectable } from '@angular/core';
import { Resolve, ActivatedRouteSnapshot } from '@angular/router';
/** rxjs Imports */
import { Observable } from 'rxjs';
/** Custom Services */
import { AccountingService } from '../../accounting.service';
/**
* Financial activity mapping and template data resolver.
*/
@Injectable()
export class FinancialActivityMappingAndTemplateResolver implements Resolve<Object> {
/**
* @param {AccountingService} accountingService Accounting service.
*/
constructor(private accountingService: AccountingService) {}
/**
* Returns the financial activity mapping and template data.
* @returns {Observable<any>}
*/
resolve(route: ActivatedRouteSnapshot): Observable<any> {
const financialActivityAccountId = route.paramMap.get('id');
return this.accountingService.getFinancialActivityAccount(financialActivityAccountId, true);
}
}