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:
+31
@@ -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';
|
||||
|
||||
/**
|
||||
* Provisioning entry entries data resolver.
|
||||
*/
|
||||
@Injectable()
|
||||
export class ProvisioningEntryEntriesResolver implements Resolve<Object> {
|
||||
|
||||
/**
|
||||
* @param {AccountingService} accountingService Accounting service.
|
||||
*/
|
||||
constructor(private accountingService: AccountingService) {}
|
||||
|
||||
/**
|
||||
* Returns the provisioning entry entries data.
|
||||
* @returns {Observable<any>}
|
||||
*/
|
||||
resolve(route: ActivatedRouteSnapshot): Observable<any> {
|
||||
const provisioningEntryId = route.paramMap.get('id');
|
||||
return this.accountingService.getProvisioningEntryEntries(provisioningEntryId);
|
||||
}
|
||||
|
||||
}
|
||||
+31
@@ -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';
|
||||
|
||||
/**
|
||||
* Provisioning entry data resolver.
|
||||
*/
|
||||
@Injectable()
|
||||
export class ProvisioningEntryResolver implements Resolve<Object> {
|
||||
|
||||
/**
|
||||
* @param {AccountingService} accountingService Accounting service.
|
||||
*/
|
||||
constructor(private accountingService: AccountingService) {}
|
||||
|
||||
/**
|
||||
* Returns the provisioning entry data.
|
||||
* @returns {Observable<any>}
|
||||
*/
|
||||
resolve(route: ActivatedRouteSnapshot): Observable<any> {
|
||||
const provisioningEntryId = route.paramMap.get('id');
|
||||
return this.accountingService.getProvisioningEntry(provisioningEntryId);
|
||||
}
|
||||
|
||||
}
|
||||
+9
-5
@@ -2,7 +2,8 @@
|
||||
|
||||
<div class="m-b-20" fxLayout="row" fxLayoutAlign="end" fxLayoutGap="20px">
|
||||
<button mat-raised-button color="primary" (click)="createProvisioningJournalEntries()" [disabled]="provisioningEntry.journalEntry">
|
||||
<mat-icon>add</mat-icon> Create Journal Entries
|
||||
<fa-icon icon="plus"></fa-icon>
|
||||
Create Journal Entries
|
||||
</button>
|
||||
</div>
|
||||
|
||||
@@ -48,15 +49,18 @@
|
||||
<div class="container m-t-20" fxLayout="row wrap" fxLayoutGap="2%" fxLayout.lt-md="column">
|
||||
|
||||
<mat-form-field fxFlex="31%">
|
||||
<input matInput placeholder="Office Name" [formControl]="officeName" [matAutocomplete]="officeNameAutocomplete">
|
||||
<mat-label>Office Name</mat-label>
|
||||
<input matInput [formControl]="officeName" [matAutocomplete]="officeNameAutocomplete">
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field fxFlex="31%">
|
||||
<input matInput placeholder="Loan Product" [formControl]="loanProduct" [matAutocomplete]="loanProductAutocomplete">
|
||||
<mat-label>Loan Product</mat-label>
|
||||
<input matInput [formControl]="loanProduct" [matAutocomplete]="loanProductAutocomplete">
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field fxFlex="31%">
|
||||
<input matInput placeholder="Provisioning Category" [formControl]="provisioningCategory" [matAutocomplete]="provisioningCategoryAutocomplete">
|
||||
<mat-label>Provisioning Category</mat-label>
|
||||
<input matInput [formControl]="provisioningCategory" [matAutocomplete]="provisioningCategoryAutocomplete">
|
||||
</mat-form-field>
|
||||
|
||||
</div>
|
||||
@@ -122,7 +126,7 @@
|
||||
</ng-container>
|
||||
|
||||
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
|
||||
<tr mat-row *matRowDef="let row; columns: displayedColumns;" [routerLink]="['/accounting/provisioning-entries/view', row.id]"></tr>
|
||||
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
|
||||
|
||||
</table>
|
||||
|
||||
|
||||
+3
-3
@@ -6,9 +6,9 @@ table {
|
||||
div {
|
||||
margin: 1rem 0;
|
||||
word-wrap: break-word;
|
||||
}
|
||||
|
||||
.header {
|
||||
font-weight: 500;
|
||||
&.header {
|
||||
font-weight: 500;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+156
-81
@@ -1,12 +1,18 @@
|
||||
/** Angular Imports */
|
||||
import { Component, OnInit, ViewChild, AfterViewInit } from '@angular/core';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { FormControl } from '@angular/forms';
|
||||
import { MatPaginator, MatSort, MatTableDataSource } from '@angular/material';
|
||||
|
||||
/** rxjs Imports */
|
||||
import { startWith, map, debounceTime, distinctUntilChanged, tap } from 'rxjs/operators';
|
||||
|
||||
/** Custom Services */
|
||||
import { AccountingService } from '../../accounting.service';
|
||||
|
||||
/**
|
||||
* View provisioning entry component.
|
||||
*/
|
||||
@Component({
|
||||
selector: 'mifosx-view-provisioning-entry',
|
||||
templateUrl: './view-provisioning-entry.component.html',
|
||||
@@ -14,41 +20,87 @@ import { AccountingService } from '../../accounting.service';
|
||||
})
|
||||
export class ViewProvisioningEntryComponent implements OnInit, AfterViewInit {
|
||||
|
||||
/** Provisioning entry id. */
|
||||
provisioningEntryId: string;
|
||||
/** Provisioning entry. */
|
||||
provisioningEntry: any;
|
||||
|
||||
/** Provisioning entry entries. */
|
||||
provisioningEntryEntries: any;
|
||||
/** Office name filter form control. */
|
||||
officeName = new FormControl();
|
||||
/** Office data. */
|
||||
officeData: any;
|
||||
/** Filtered office data for autocomplete. */
|
||||
filteredOfficeData: any;
|
||||
/** Loan product filter form control. */
|
||||
loanProduct = new FormControl();
|
||||
/** Loan product data. */
|
||||
loanProductData: any;
|
||||
/** Filtered loan product data for autocomplete. */
|
||||
filteredLoanProductData: any;
|
||||
/** Provisioning category filter form control. */
|
||||
provisioningCategory = new FormControl();
|
||||
/** Provisioning category data. */
|
||||
provisioningCategoryData: any;
|
||||
/** Filtered provisioning category data for autocomplete. */
|
||||
filteredProvisioningCategoryData: any;
|
||||
/** Columns to be displayed in provisioning entry entries table. */
|
||||
displayedColumns: string[] = ['officeName', 'productName', 'currencyCode', 'categoryName', 'amountreserved', 'liabilityAccountName', 'expenseAccountName'];
|
||||
dataSource: any;
|
||||
filterValue: any = { officeName: '', productName: '', categoryName: '' };
|
||||
/** Data source for provisioning entry entries table. */
|
||||
dataSource: MatTableDataSource<any>;
|
||||
/** Provisioning entry entries filter. */
|
||||
filterValue: any = {
|
||||
officeName: '',
|
||||
productName: '',
|
||||
categoryName: ''
|
||||
};
|
||||
|
||||
/** Paginator for provisioning entry entries table. */
|
||||
@ViewChild(MatPaginator) paginator: MatPaginator;
|
||||
/** Sorter for provisioning entry entries table. */
|
||||
@ViewChild(MatSort) sort: MatSort;
|
||||
|
||||
officeName = new FormControl();
|
||||
officeData: any;
|
||||
filteredOfficeData: any;
|
||||
|
||||
loanProduct = new FormControl();
|
||||
loanProductData: any;
|
||||
filteredLoanProductData: any;
|
||||
|
||||
provisioningCategory = new FormControl();
|
||||
provisioningCategoryData: any;
|
||||
filteredProvisioningCategoryData: any;
|
||||
|
||||
constructor(private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
private accountingService: AccountingService) { }
|
||||
|
||||
ngOnInit() {
|
||||
this.provisioningEntryId = this.route.snapshot.paramMap.get('id');
|
||||
this.getProvisioningEntry();
|
||||
this.getProvisioningEntryEntries();
|
||||
this.getOffices();
|
||||
this.getLoanProducts();
|
||||
this.getProvisioningCategories();
|
||||
/**
|
||||
* Retrieves the provisioning entry, provisioning entry entries, offices,
|
||||
* loan products, provisioning categories data from `resolve`.
|
||||
* @param {AccountingService} accountingService Accounting Service.
|
||||
* @param {ActivatedRoute} route Activated Route.
|
||||
* @param {Router} router Router for navigation.
|
||||
*/
|
||||
constructor(private accountingService: AccountingService,
|
||||
private route: ActivatedRoute,
|
||||
private router: Router) {
|
||||
this.route.data.subscribe((data: {
|
||||
provisioningEntry: any,
|
||||
provisioningEntryEntries: any,
|
||||
offices: any,
|
||||
loanProducts: any,
|
||||
provisiningCategories: any
|
||||
}) => {
|
||||
this.provisioningEntryId = data.provisioningEntry.id;
|
||||
this.provisioningEntry = data.provisioningEntry;
|
||||
this.provisioningEntryEntries = data.provisioningEntryEntries;
|
||||
this.officeData = data.offices;
|
||||
this.loanProductData = data.loanProducts;
|
||||
this.provisioningCategoryData = data.provisiningCategories;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets filtered offices, loan products and provisioning categories for autocomplete
|
||||
* and provisioning entry entries table.
|
||||
*/
|
||||
ngOnInit() {
|
||||
this.setProvisioningEntryEntries();
|
||||
this.setFilteredOffices();
|
||||
this.setFilteredLoanProducts();
|
||||
this.setFilteredProvisioningCategories();
|
||||
}
|
||||
|
||||
/**
|
||||
* Subscribes to all search filters:
|
||||
* Office Name, Loan Product, Provisioning categories.
|
||||
*/
|
||||
ngAfterViewInit() {
|
||||
this.officeName.valueChanges
|
||||
.pipe(
|
||||
@@ -84,86 +136,109 @@ export class ViewProvisioningEntryComponent implements OnInit, AfterViewInit {
|
||||
.subscribe();
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter predicate for provisioning entry entries table data.
|
||||
* @param {any} data Table data.
|
||||
* @param {any} filterValue Values to filter data by.
|
||||
*/
|
||||
filterPredicate(data: any, filterValue: any) {
|
||||
return data.officeName.toLowerCase().indexOf(filterValue['officeName']) !== -1
|
||||
&& data.productName.toLowerCase().indexOf(filterValue['productName']) !== -1
|
||||
&& data.categoryName.toLowerCase().indexOf(filterValue['categoryName']) !== -1;
|
||||
}
|
||||
|
||||
applyFilter(filterValue: string, property: string) {
|
||||
/**
|
||||
* Initializes the data source, paginator, sorter and filter predicate for
|
||||
* provisioning entry entries table.
|
||||
*/
|
||||
setProvisioningEntryEntries() {
|
||||
this.dataSource = new MatTableDataSource(this.provisioningEntryEntries.pageItems);
|
||||
this.dataSource.paginator = this.paginator;
|
||||
this.dataSource.sort = this.sort;
|
||||
this.dataSource.filterPredicate = this.filterPredicate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters data in provisioning entry entries table based on passed value.
|
||||
* @param {string} filterValue Value to filter data.
|
||||
* @param {string} property Property to filter data.
|
||||
*/
|
||||
applyFilter(filterValue: string, property: string) {
|
||||
this.filterValue[property] = filterValue;
|
||||
this.dataSource.filter = this.filterValue;
|
||||
}
|
||||
|
||||
getProvisioningEntry() {
|
||||
this.accountingService.getProvisioningEntry(this.provisioningEntryId)
|
||||
.subscribe((provisioningEntry: any) => {
|
||||
this.provisioningEntry = provisioningEntry;
|
||||
});
|
||||
/**
|
||||
* Sets filtered offices for autocomplete.
|
||||
*/
|
||||
setFilteredOffices() {
|
||||
this.filteredOfficeData = this.officeName.valueChanges
|
||||
.pipe(
|
||||
startWith(''),
|
||||
map((office: any) => typeof office === 'string' ? office : office.name),
|
||||
map((officeName: string) => officeName ? this.filterOfficeAutocompleteData(officeName) : this.officeData)
|
||||
);
|
||||
}
|
||||
|
||||
getProvisioningEntryEntries() {
|
||||
this.accountingService.getProvisioningEntryEntries(this.provisioningEntryId)
|
||||
.subscribe((provisioningEntryEntries: any) => {
|
||||
this.dataSource = new MatTableDataSource(provisioningEntryEntries.pageItems);
|
||||
this.dataSource.paginator = this.paginator;
|
||||
this.dataSource.sort = this.sort;
|
||||
this.dataSource.filterPredicate = this.filterPredicate;
|
||||
});
|
||||
/**
|
||||
* Sets filtered loan products for autocomplete.
|
||||
*/
|
||||
setFilteredLoanProducts() {
|
||||
this.filteredLoanProductData = this.loanProduct.valueChanges
|
||||
.pipe(
|
||||
startWith(''),
|
||||
map((loanProduct: any) => typeof loanProduct === 'string' ? loanProduct : loanProduct.name),
|
||||
map((loanProductName: string) => loanProductName ? this.filterLoanProductAutocompleteData(loanProductName) : this.loanProductData)
|
||||
);
|
||||
}
|
||||
|
||||
getOffices() {
|
||||
this.accountingService.getOffices().subscribe(officeData => {
|
||||
this.officeData = officeData;
|
||||
this.filteredOfficeData = this.officeName.valueChanges
|
||||
.pipe(
|
||||
startWith(''),
|
||||
map((office: any) => typeof office === 'string' ? office : office.name),
|
||||
map((officeName: string) => officeName ? this.filterOfficeAutocompleteData(this.officeData, officeName) : this.officeData)
|
||||
);
|
||||
});
|
||||
/**
|
||||
* Sets filtered provisioning categories for autocomplete.
|
||||
*/
|
||||
setFilteredProvisioningCategories() {
|
||||
this.filteredProvisioningCategoryData = this.provisioningCategory.valueChanges
|
||||
.pipe(
|
||||
startWith(''),
|
||||
map((provisioningCategory: any) => typeof provisioningCategory === 'string' ? provisioningCategory : provisioningCategory.categoryName),
|
||||
map((provisioningCategoryName: string) => provisioningCategoryName ? this.filterProvisioningCategoryAutocompleteData(provisioningCategoryName) : this.provisioningCategoryData)
|
||||
);
|
||||
}
|
||||
|
||||
getLoanProducts() {
|
||||
this.accountingService.getLoanProducts().subscribe(loanProductData => {
|
||||
this.loanProductData = loanProductData;
|
||||
this.filteredLoanProductData = this.loanProduct.valueChanges
|
||||
.pipe(
|
||||
startWith(''),
|
||||
map((loanProduct: any) => typeof loanProduct === 'string' ? loanProduct : loanProduct.name),
|
||||
map((loanProductName: string) => loanProductName ? this.filterLoanProductAutocompleteData(this.loanProductData, loanProductName) : this.loanProductData)
|
||||
);
|
||||
});
|
||||
/**
|
||||
* Filters offices.
|
||||
* @param {string} officeName Office name to filter office by.
|
||||
* @returns {any} Filtered offices.
|
||||
*/
|
||||
private filterOfficeAutocompleteData(officeName: string): any {
|
||||
return this.officeData.filter((office: any) => office.name.toLowerCase().includes(officeName.toLowerCase()));
|
||||
}
|
||||
|
||||
getProvisioningCategories() {
|
||||
this.accountingService.getProvisioningCategories().subscribe(provisioningCategoryData => {
|
||||
this.provisioningCategoryData = provisioningCategoryData;
|
||||
this.filteredProvisioningCategoryData = this.provisioningCategory.valueChanges
|
||||
.pipe(
|
||||
startWith(''),
|
||||
map((provisioningCategory: any) => typeof provisioningCategory === 'string' ? provisioningCategory : provisioningCategory.categoryName),
|
||||
map((provisioningCategoryName: string) => provisioningCategoryName ? this.filterProvisioningCategoryAutocompleteData(this.provisioningCategoryData, provisioningCategoryName) : this.provisioningCategoryData)
|
||||
);
|
||||
});
|
||||
/**
|
||||
* Filters loan products.
|
||||
* @param {string} loanProductName Loan product name to filter loan products by.
|
||||
* @returns {any} Filtered loan products.
|
||||
*/
|
||||
private filterLoanProductAutocompleteData(loanProductName: string): any {
|
||||
return this.loanProductData.filter((loanProduct: any) => loanProduct.name.toLowerCase().includes(loanProductName.toLocaleLowerCase()));
|
||||
}
|
||||
|
||||
private filterOfficeAutocompleteData(officeData: any, officeName: string): any {
|
||||
return officeData.filter((office: any) => office.name.toLowerCase().includes(officeName.toLowerCase()));
|
||||
}
|
||||
|
||||
private filterLoanProductAutocompleteData(loanProductData: any, loanProductName: string): any {
|
||||
return loanProductData.filter((loanProduct: any) => loanProduct.name.toLowerCase().includes(loanProductName.toLocaleLowerCase()));
|
||||
}
|
||||
|
||||
private filterProvisioningCategoryAutocompleteData(provisioningCategoryData: any, provisioningCategoryName: string): any {
|
||||
return provisioningCategoryData.filter((provisioningCategory: any) => provisioningCategory.categoryName.toLowerCase().includes(provisioningCategoryName.toLocaleLowerCase()));
|
||||
/**
|
||||
* Filters provisioning categories.
|
||||
* @param {string} provisioningCategoryName Provisioning category name to filter provisioning categories by.
|
||||
* @returns {any} Filtered provisioning categories.
|
||||
*/
|
||||
private filterProvisioningCategoryAutocompleteData(provisioningCategoryName: string): any {
|
||||
return this.provisioningCategoryData.filter((provisioningCategory: any) => provisioningCategory.categoryName.toLowerCase().includes(provisioningCategoryName.toLocaleLowerCase()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates provisioning journal entries
|
||||
* and redirects to created entries.
|
||||
*/
|
||||
createProvisioningJournalEntries() {
|
||||
this.accountingService.createProvisioningJournalEntries(this.provisioningEntryId)
|
||||
.subscribe((response: any) => {
|
||||
this.router.navigate(['/accounting/provisioning-entries/journal-entries/view', response.resourceId]);
|
||||
this.router.navigate(['../../journal-entries/view', response.resourceId], { relativeTo: this.route });
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user