Spaces:
Runtime error
Runtime error
shubhampal
commited on
Commit
•
1ce2a0d
1
Parent(s):
ceb805c
Upload 5 files
Browse files
accounting-rules-template.resolver.ts
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/** Angular Imports */
|
2 |
+
import { Injectable } from '@angular/core';
|
3 |
+
import { Resolve } from '@angular/router';
|
4 |
+
|
5 |
+
/** rxjs Imports */
|
6 |
+
import { Observable } from 'rxjs';
|
7 |
+
|
8 |
+
/** Custom Services */
|
9 |
+
import { AccountingService } from '../accounting.service';
|
10 |
+
|
11 |
+
/**
|
12 |
+
* Accounting rules template data resolver.
|
13 |
+
*/
|
14 |
+
@Injectable()
|
15 |
+
export class AccountingRulesTemplateResolver implements Resolve<Object> {
|
16 |
+
|
17 |
+
/**
|
18 |
+
* @param {AccountingService} accountingService Accounting service.
|
19 |
+
*/
|
20 |
+
constructor(private accountingService: AccountingService) {}
|
21 |
+
|
22 |
+
/**
|
23 |
+
* Returns the accounting rules template data.
|
24 |
+
* @returns {Observable<any>}
|
25 |
+
*/
|
26 |
+
resolve(): Observable<any> {
|
27 |
+
// Calls the getAccountingRulesTemplate method of the AccountingService to fetch the accounting rules template data.
|
28 |
+
return this.accountingService.getAccountingRulesTemplate();
|
29 |
+
}
|
30 |
+
|
31 |
+
}
|
accounting-rules.component.html
ADDED
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<div class="container m-b-20" fxLayout="row" fxLayoutAlign="end" fxLayoutGap="20px">
|
2 |
+
<!-- This button is only visible if the user has the permission to create accounting rules -->
|
3 |
+
<button mat-raised-button color="primary" [routerLink]="['create']" *mifosxHasPermission="'CREATE_ACCOUNTINGRULE'">
|
4 |
+
<!-- Icon and button label -->
|
5 |
+
<fa-icon icon="plus" class="m-r-10"></fa-icon>
|
6 |
+
{{"labels.buttons.Add Rule" | translate}}
|
7 |
+
</button>
|
8 |
+
</div>
|
9 |
+
|
10 |
+
<div class="container">
|
11 |
+
|
12 |
+
<div fxLayout="row">
|
13 |
+
<!-- Search bar for filtering accounting rules -->
|
14 |
+
<mat-form-field fxFlex>
|
15 |
+
<mat-label>{{'labels.inputs.Filter' | translate}}</mat-label>
|
16 |
+
<input matInput (keyup)="applyFilter($event.target.value)">
|
17 |
+
</mat-form-field>
|
18 |
+
</div>
|
19 |
+
|
20 |
+
<div class="mat-elevation-z8">
|
21 |
+
<!-- Table displaying accounting rules -->
|
22 |
+
<table mat-table [dataSource]="dataSource" matSort>
|
23 |
+
<!-- Column definitions for the table -->
|
24 |
+
|
25 |
+
<!-- Name column -->
|
26 |
+
<ng-container matColumnDef="name">
|
27 |
+
<th mat-header-cell *matHeaderCellDef mat-sort-header> {{"labels.inputs.name" | translate}} </th>
|
28 |
+
<td mat-cell *matCellDef="let accountingRule"> {{ accountingRule.name }} </td>
|
29 |
+
</ng-container>
|
30 |
+
|
31 |
+
<!-- Office name column -->
|
32 |
+
<ng-container matColumnDef="officeName">
|
33 |
+
<th mat-header-cell *matHeaderCellDef mat-sort-header> {{"labels.inputs.Office" | translate}} </th>
|
34 |
+
<td mat-cell *matCellDef="let accountingRule"> {{ accountingRule.officeName }} </td>
|
35 |
+
</ng-container>
|
36 |
+
|
37 |
+
<!-- Debit tags column -->
|
38 |
+
<ng-container matColumnDef="debitTags">
|
39 |
+
<th mat-header-cell *matHeaderCellDef mat-sort-header> {{"labels.inputs.Debit Tags" | translate}} </th>
|
40 |
+
<td mat-cell *matCellDef="let accountingRule"> {{ accountingRule.debitTags }} </td>
|
41 |
+
</ng-container>
|
42 |
+
|
43 |
+
<!-- Debit account column -->
|
44 |
+
<ng-container matColumnDef="debitAccount">
|
45 |
+
<th mat-header-cell *matHeaderCellDef mat-sort-header> {{"labels.inputs.Debit Account" | translate}} </th>
|
46 |
+
<td mat-cell *matCellDef="let accountingRule"> {{ accountingRule.debitAccounts ? accountingRule.debitAccounts[0].name : '' }} </td>
|
47 |
+
</ng-container>
|
48 |
+
|
49 |
+
<!-- Credit tags column -->
|
50 |
+
<ng-container matColumnDef="creditTags">
|
51 |
+
<th mat-header-cell *matHeaderCellDef mat-sort-header> {{"labels.inputs.Credit Tags" | translate}} </th>
|
52 |
+
<td mat-cell *matCellDef="let accountingRule"> {{ accountingRule.creditTags }} </td>
|
53 |
+
</ng-container>
|
54 |
+
|
55 |
+
<!-- Credit account column -->
|
56 |
+
<ng-container matColumnDef="creditAccount">
|
57 |
+
<th mat-header-cell *matHeaderCellDef mat-sort-header> {{"labels.inputs.Credit Account" | translate}} </th>
|
58 |
+
<td mat-cell *matCellDef="let accountingRule"> {{ accountingRule.creditAccounts ? accountingRule.creditAccounts[0].name : '' }} </td>
|
59 |
+
</ng-container>
|
60 |
+
|
61 |
+
<!-- Header row for the table -->
|
62 |
+
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
|
63 |
+
<!-- Row definition for each accounting rule -->
|
64 |
+
<tr mat-row *matRowDef="let row; columns: displayedColumns;" [routerLink]="['view', row.id]" class="select-row"></tr>
|
65 |
+
|
66 |
+
</table>
|
67 |
+
|
68 |
+
<!-- Pagination controls for the table -->
|
69 |
+
<mat-paginator [pageSizeOptions]="[10, 25, 50, 100]" showFirstLastButtons></mat-paginator>
|
70 |
+
|
71 |
+
</div>
|
72 |
+
|
73 |
+
</div>
|
accounting-rules.component.spec.ts
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
2 |
+
|
3 |
+
import { AccountingRulesComponent } from './accounting-rules.component';
|
4 |
+
|
5 |
+
// This describes a group of tests for the AccountingRulesComponent
|
6 |
+
describe('AccountingRulesComponent', () => {
|
7 |
+
// Define variables to hold the component and its fixture
|
8 |
+
let component: AccountingRulesComponent;
|
9 |
+
let fixture: ComponentFixture<AccountingRulesComponent>;
|
10 |
+
|
11 |
+
// This setup block runs before each test case
|
12 |
+
beforeEach(async(() => {
|
13 |
+
// Configure the test module with the component declaration
|
14 |
+
TestBed.configureTestingModule({
|
15 |
+
declarations: [ AccountingRulesComponent ]
|
16 |
+
})
|
17 |
+
// Compile the component's template
|
18 |
+
.compileComponents();
|
19 |
+
}));
|
20 |
+
|
21 |
+
// This setup block runs before each test case
|
22 |
+
beforeEach(() => {
|
23 |
+
// Create a new instance of the component
|
24 |
+
fixture = TestBed.createComponent(AccountingRulesComponent);
|
25 |
+
// Get the component instance from the fixture
|
26 |
+
component = fixture.componentInstance;
|
27 |
+
// Detect changes in the component's bindings and template
|
28 |
+
fixture.detectChanges();
|
29 |
+
});
|
30 |
+
|
31 |
+
// This test case checks if the component is created successfully
|
32 |
+
it('should create', () => {
|
33 |
+
// Expect the component to be truthy, meaning it exists
|
34 |
+
expect(component).toBeTruthy();
|
35 |
+
});
|
36 |
+
});
|
accounting-rules.component.ts
ADDED
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/** Angular Imports */
|
2 |
+
import { Component, OnInit, ViewChild } from '@angular/core';
|
3 |
+
import { MatPaginator } from '@angular/material/paginator';
|
4 |
+
import { MatSort } from '@angular/material/sort';
|
5 |
+
import { MatTableDataSource } from '@angular/material/table';
|
6 |
+
import { ActivatedRoute } from '@angular/router';
|
7 |
+
|
8 |
+
/**
|
9 |
+
* Accounting rules component.
|
10 |
+
*/
|
11 |
+
@Component({
|
12 |
+
selector: 'mifosx-accounting-rules',
|
13 |
+
templateUrl: './accounting-rules.component.html',
|
14 |
+
styleUrls: ['./accounting-rules.component.scss']
|
15 |
+
})
|
16 |
+
export class AccountingRulesComponent implements OnInit {
|
17 |
+
|
18 |
+
/** Accounting rule data. */
|
19 |
+
accountingRuleData: any;
|
20 |
+
/** Columns to be displayed in accounting rules table. */
|
21 |
+
displayedColumns: string[] = ['name', 'officeName', 'debitTags', 'debitAccount', 'creditTags', 'creditAccount'];
|
22 |
+
/** Data source for accounting rules table. */
|
23 |
+
dataSource: MatTableDataSource<any>;
|
24 |
+
|
25 |
+
/** Paginator for accounting rules table. */
|
26 |
+
@ViewChild(MatPaginator, { static: true }) paginator: MatPaginator;
|
27 |
+
/** Sorter for accounting rules table. */
|
28 |
+
@ViewChild(MatSort, { static: true }) sort: MatSort;
|
29 |
+
|
30 |
+
/**
|
31 |
+
* Retrieves the accounting rules data from `resolve`.
|
32 |
+
* @param {ActivatedRoute} route Activated Route.
|
33 |
+
*/
|
34 |
+
constructor(private route: ActivatedRoute) {
|
35 |
+
// subscribe to the data from the route
|
36 |
+
this.route.data.subscribe((data: { accountingRules: any }) => {
|
37 |
+
// assign the accounting rules data to the component property
|
38 |
+
this.accountingRuleData = data.accountingRules;
|
39 |
+
});
|
40 |
+
}
|
41 |
+
|
42 |
+
/**
|
43 |
+
* Sets the accounting rules table.
|
44 |
+
*/
|
45 |
+
ngOnInit() {
|
46 |
+
// call the function to set the accounting rules table
|
47 |
+
this.setAccountingRules();
|
48 |
+
}
|
49 |
+
|
50 |
+
/**
|
51 |
+
* Initializes the data source, paginator and sorter for accounting rules table.
|
52 |
+
*/
|
53 |
+
setAccountingRules() {
|
54 |
+
// iterate over each accounting rule
|
55 |
+
this.accountingRuleData.forEach((accountingRule: any) => {
|
56 |
+
// join the debit tags into a comma-separated string if they exist
|
57 |
+
accountingRule.debitTags = accountingRule.debitTags ? accountingRule.debitTags.map((debitTag: any) => debitTag.tag.name).join(', ') : '';
|
58 |
+
// join the credit tags into a comma-separated string if they exist
|
59 |
+
accountingRule.creditTags = accountingRule.creditTags ? accountingRule.creditTags.map((creditTag: any) => creditTag.tag.name).join(', ') : '';
|
60 |
+
});
|
61 |
+
// create a new MatTableDataSource instance and assign the accounting rule data
|
62 |
+
this.dataSource = new MatTableDataSource(this.accountingRuleData);
|
63 |
+
// set the paginator for the data source
|
64 |
+
this.dataSource.paginator = this.paginator;
|
65 |
+
// set the sorting data accessor for the data source
|
66 |
+
this.dataSource.sortingDataAccessor = (accountingRule: any, property: any) => {
|
67 |
+
// return the appropriate value for sorting based on the property
|
68 |
+
switch (property) {
|
69 |
+
case 'debitAccount': return accountingRule.debitAccounts[0].name;
|
70 |
+
case 'creditAccount': return accountingRule.creditAccounts[0].name;
|
71 |
+
default: return accountingRule[property];
|
72 |
+
}
|
73 |
+
};
|
74 |
+
// set the sorter for the data source
|
75 |
+
this.dataSource.sort = this.sort;
|
76 |
+
}
|
77 |
+
|
78 |
+
/**
|
79 |
+
* Filters data in accounting rules table based on passed value.
|
80 |
+
* @param {string} filterValue Value to filter data.
|
81 |
+
*/
|
82 |
+
applyFilter(filterValue: string) {
|
83 |
+
// filter the data source based on the filter value
|
84 |
+
this.dataSource.filter = filterValue.trim().toLowerCase();
|
85 |
+
}
|
86 |
+
|
87 |
+
}
|
accounting-rules.resolver.ts
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/** Angular Imports */
|
2 |
+
import { Injectable } from '@angular/core';
|
3 |
+
import { Resolve } from '@angular/router';
|
4 |
+
|
5 |
+
/** rxjs Imports */
|
6 |
+
import { Observable } from 'rxjs';
|
7 |
+
|
8 |
+
/** Custom Services */
|
9 |
+
import { AccountingService } from '../accounting.service';
|
10 |
+
|
11 |
+
/**
|
12 |
+
* Accounting rules data resolver.
|
13 |
+
*/
|
14 |
+
@Injectable()
|
15 |
+
export class AccountingRulesResolver implements Resolve<Object> {
|
16 |
+
|
17 |
+
/**
|
18 |
+
* @param {AccountingService} accountingService Accounting service.
|
19 |
+
*/
|
20 |
+
constructor(private accountingService: AccountingService) {}
|
21 |
+
|
22 |
+
/**
|
23 |
+
* Returns the accounting rules data.
|
24 |
+
* @returns {Observable<any>}
|
25 |
+
*/
|
26 |
+
resolve(): Observable<any> {
|
27 |
+
// Call the getAccountingRules method of the AccountingService to retrieve the accounting rules data.
|
28 |
+
return this.accountingService.getAccountingRules();
|
29 |
+
}
|
30 |
+
|
31 |
+
}
|