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
@@ -1,7 +1,7 @@
<div class="container">
<mat-card>
<form [formGroup]="financialActivityMappingForm" (ngSubmit)="submit()">
<mat-card-content>
@@ -9,19 +9,27 @@
<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>
</mat-select>
<mat-error *ngIf="financialActivityMappingForm.controls.financialActivityId.hasError('required')">
Financial Activity is <strong>required</strong>
</mat-error>
</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>
</mat-select>
<mat-error *ngIf="financialActivityMappingForm.controls.glAccountId.hasError('required')">
Account is <strong>required</strong>
</mat-error>
</mat-form-field>
</div>
@@ -29,8 +37,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']">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.valid">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 } from '@angular/router';
import { Router, ActivatedRoute } from '@angular/router';
/** Custom Services */
import { AccountingService } from '../../accounting.service';
/**
* Create financial activity mapping component.
*/
@Component({
selector: 'mifosx-create-financial-activity-mapping',
templateUrl: './create-financial-activity-mapping.component.html',
@@ -11,56 +16,79 @@ import { AccountingService } from '../../accounting.service';
})
export class CreateFinancialActivityMappingComponent implements OnInit {
/** Financial activity mapping form. */
financialActivityMappingForm: FormGroup;
/** GL Account options. */
glAccountOptions: any;
/** GL Account data. */
glAccountData: any;
/** Financial activity data. */
financialActivityData: any;
constructor(private formBuider: FormBuilder,
/**
* Retrieves the gl account options and financial activity 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 formBuilder: FormBuilder,
private accountingService: AccountingService,
private router: Router) { }
ngOnInit() {
this.createFinancialActivityMappingForm();
this.getFinancialActivityAccountsTemplate();
this.setGLAccountData();
private route: ActivatedRoute,
private router: Router) {
this.route.data.subscribe((data: { financialActivityAccountsTemplate: any }) => {
this.glAccountOptions = data.financialActivityAccountsTemplate.glAccountOptions;
this.financialActivityData = data.financialActivityAccountsTemplate.financialActivityOptions;
});
}
/**
* Creates the financial activity mapping form and sets the gl account data.
*/
ngOnInit() {
this.createFinancialActivityMappingForm();
this.setGlAccountData();
}
/**
* Creates the financial activity mapping form.
*/
createFinancialActivityMappingForm() {
this.financialActivityMappingForm = this.formBuider.group({
this.financialActivityMappingForm = this.formBuilder.group({
'financialActivityId': ['', Validators.required],
'glAccountId': ['', Validators.required]
});
}
getFinancialActivityAccountsTemplate() {
this.accountingService.getFinancialActivityAccountsTemplate().subscribe((financialActivityAccountData: any) => {
this.glAccountOptions = financialActivityAccountData.glAccountOptions;
this.financialActivityData = financialActivityAccountData.financialActivityOptions;
});
}
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;
}
});
/**
* 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;
}
});
}
/**
* Submits the financial activity mapping form and creates financial activity account,
* if successful redirects to view created account.
*/
submit() {
this.accountingService.createFinancialActivityAccount(this.financialActivityMappingForm.value)
.subscribe((response: any) => {
this.router.navigate(['/accounting/financial-activity-mappings/view', response.resourceId]);
this.router.navigate(['../view', response.resourceId], { relativeTo: this.route });
});
}
@@ -0,0 +1,30 @@
/** Angular Imports */
import { Injectable } from '@angular/core';
import { Resolve } from '@angular/router';
/** rxjs Imports */
import { Observable } from 'rxjs';
/** Custom Services */
import { AccountingService } from '../../accounting.service';
/**
* Financial activity mappings template data resolver.
*/
@Injectable()
export class FinancialActivityMappingsTemplateResolver implements Resolve<Object> {
/**
* @param {AccountingService} accountingService Accounting service.
*/
constructor(private accountingService: AccountingService) {}
/**
* Returns the financial activity mappings template data.
* @returns {Observable<any>}
*/
resolve(): Observable<any> {
return this.accountingService.getFinancialActivityAccountsTemplate();
}
}