feat: add payment types component (#521)

Fixes: #163
This commit is contained in:
punwai
2019-12-24 12:04:46 +03:00
committed by Abhay Chawla
parent 34e1f4da36
commit dc61cba5d6
9 changed files with 260 additions and 3 deletions
@@ -17,6 +17,7 @@ import { CurrenciesComponent } from './currencies/currencies.component';
import { SmsCampaignsComponent } from './sms-campaigns/sms-campaigns.component';
import { AdhocQueryComponent } from './adhoc-query/adhoc-query.component';
import { TellersComponent } from './tellers/tellers.component';
import { PaymentTypesComponent } from './payment-types/payment-types.component';
/** Custom Resolvers */
import { LoanProvisioningCriteriaResolver } from './loan-provisioning-criteria/loan-provisioning-criteria.resolver';
@@ -26,6 +27,7 @@ import { CurrenciesResolver } from './currencies/currencies.resolver';
import { SmsCampaignsResolver } from './sms-campaigns/sms-campaigns.resolver';
import { AdhocQueriesResolver } from './adhoc-query/adhoc-queries.resolver';
import { TellersResolver } from './tellers/tellers.resolver';
import { PaymentTypesResolver } from './payment-types/payment-types.resolver';
/** Organization Routes */
const routes: Routes = [
@@ -98,6 +100,14 @@ const routes: Routes = [
resolve: {
tellers: TellersResolver
}
},
{
path: 'payment-types',
component: PaymentTypesComponent,
data: { title: extract('Payment Types'), breadcrumb: 'Payment Types' },
resolve: {
paymentTypes: PaymentTypesResolver
}
}
]
}
@@ -119,7 +129,8 @@ const routes: Routes = [
CurrenciesResolver,
SmsCampaignsResolver,
AdhocQueriesResolver,
TellersResolver
TellersResolver,
PaymentTypesResolver
]
})
export class OrganizationRoutingModule { }
@@ -121,7 +121,7 @@
<p matLine>Define working days and configure behaviour of payments due on holidays</p>
</mat-list-item>
<mat-list-item>
<mat-list-item [routerLink]="['payment-types']">
<mat-icon matListIcon>
<fa-icon icon="dollar-sign" size="sm"></fa-icon>
</mat-icon>
+3 -1
View File
@@ -15,6 +15,7 @@ import { CurrenciesComponent } from './currencies/currencies.component';
import { SmsCampaignsComponent } from './sms-campaigns/sms-campaigns.component';
import { AdhocQueryComponent } from './adhoc-query/adhoc-query.component';
import { TellersComponent } from './tellers/tellers.component';
import { PaymentTypesComponent } from './payment-types/payment-types.component';
/**
* Organization Module
@@ -35,7 +36,8 @@ import { TellersComponent } from './tellers/tellers.component';
CurrenciesComponent,
SmsCampaignsComponent,
AdhocQueryComponent,
TellersComponent
TellersComponent,
PaymentTypesComponent
]
})
export class OrganizationModule { }
@@ -67,4 +67,19 @@ export class OrganizationService {
return this.http.get('/tellers');
}
/**
* @returns {Observable<any>} Payment Types data
*/
getPaymentTypes(): Observable<any> {
return this.http.get('/paymenttypes');
}
/**
* @param {string} paymentTypeId Payment type ID of payment type to be deleted.
* @returns {Observable<any>}
*/
deletePaymentType(paymentTypeId: string): Observable<any> {
return this.http.delete(`/paymenttypes/${paymentTypeId}`);
}
}
@@ -0,0 +1,69 @@
<div class="container m-b-20" fxLayout="row" fxLayoutAlign="end" fxLayoutGap="20px">
<button mat-raised-button color="primary">
<fa-icon icon="plus"></fa-icon>&nbsp;&nbsp;
Add Payment Type
</button>
</div>
<div class="container">
<div fxLayout="row" fxLayoutGap="20px">
<mat-form-field fxFlex>
<mat-label>Filter</mat-label>
<input matInput (keyup)="applyFilter($event.target.value)">
</mat-form-field>
</div>
<div class="mat-elevation-z8">
<table mat-table [dataSource]="dataSource" matSort>
<ng-container matColumnDef="name">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Name </th>
<td mat-cell *matCellDef="let paymentType"> {{ paymentType.name }} </td>
</ng-container>
<ng-container matColumnDef="description">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Description </th>
<td mat-cell *matCellDef="let paymentType"> {{ paymentType.description }} </td>
</ng-container>
<ng-container matColumnDef="isCashPayment">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Cash Payment </th>
<td mat-cell *matCellDef="let paymentType">
<div [className]="paymentType.isCashPayment === true ? 'true' : 'false'">
<fa-icon *ngIf="paymentType.isCashPayment" icon="check-circle" size="lg" matTooltip="Yes" matTooltipPosition="right"></fa-icon>
<fa-icon *ngIf="!paymentType.isCashPayment" icon="times-circle" size="lg" matTooltip="No" matTooltipPosition="right"></fa-icon>
</div>
</td>
</ng-container>
<ng-container matColumnDef="position">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Position </th>
<td mat-cell *matCellDef="let paymentType"> {{ paymentType.position }} </td>
</ng-container>
<ng-container matColumnDef="actions">
<th mat-header-cell *matHeaderCellDef> Actions </th>
<td mat-cell *matCellDef="let paymentType">
<button mat-button color="primary">
<fa-icon icon="edit"></fa-icon>&nbsp;&nbsp;Edit
</button>
<button mat-button (click)="deletePaymentType(paymentType.id)" color="warn">
<fa-icon icon="trash"></fa-icon>&nbsp;&nbsp;Delete
</button>
</td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
</table>
<mat-paginator [pageSizeOptions]="[10, 25, 50, 100]" showFirstLastButtons></mat-paginator>
</div>
</div>
@@ -0,0 +1,11 @@
table {
width: 100%;
}
.true {
color: #32cd32;
}
.false {
color: #f44366;
}
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { PaymentTypesComponent } from './payment-types.component';
describe('PaymentTypesComponent', () => {
let component: PaymentTypesComponent;
let fixture: ComponentFixture<PaymentTypesComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ PaymentTypesComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(PaymentTypesComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,94 @@
/** Angular Imports */
import { Component, OnInit, ViewChild } from '@angular/core';
import { MatTableDataSource, MatPaginator, MatSort, MatDialog } from '@angular/material';
import { ActivatedRoute } from '@angular/router';
/** rxjs Imports */
import { of } from 'rxjs';
/** Custom Services */
import { OrganizationService } from '../organization.service';
/** Custom Components */
import { DeleteDialogComponent } from '../../shared/delete-dialog/delete-dialog.component';
/**
* Payment Types component.
*/
@Component({
selector: 'mifosx-payment-types',
templateUrl: './payment-types.component.html',
styleUrls: ['./payment-types.component.scss']
})
export class PaymentTypesComponent implements OnInit {
/** Payment Types data. */
paymentTypesData: any;
/** Columns to be displayed in payment types table. */
displayedColumns: string[] = ['name', 'description', 'isCashPayment', 'position', 'actions'];
/** Data source for payment types table. */
dataSource: MatTableDataSource<any>;
/** Paginator for payment types table. */
@ViewChild(MatPaginator) paginator: MatPaginator;
/** Sorter for payment types table. */
@ViewChild(MatSort) sort: MatSort;
/**
* Retrieves the payment types data from `resolve`.
* @param {OrganizationService} organizationService Organization Service.
* @param {ActivatedRoute} route Activated Route.
* @param {MatDialog} dialog Dialog reference.
*/
constructor(private organizationService: OrganizationService,
private route: ActivatedRoute,
private dialog: MatDialog) {
this.route.data.subscribe(( data: { paymentTypes: any }) => {
this.paymentTypesData = data.paymentTypes;
});
}
/**
* Filters data in payment types table based on passed value.
* @param {string} filterValue Value to filter data.
*/
applyFilter(filterValue: string) {
this.dataSource.filter = filterValue.trim().toLowerCase();
}
/**
* Sets the payment types table.
*/
ngOnInit() {
this.setPaymentTypes();
}
/**
* Initializes the data source, paginator and sorter for payment types table.
*/
setPaymentTypes() {
this.dataSource = new MatTableDataSource(this.paymentTypesData);
this.dataSource.paginator = this.paginator;
this.dataSource.sort = this.sort;
}
/**
* Deletes the payment type
* @param {string} paymentTypeId Payment Type ID of payment type to be deleted.
*/
deletePaymentType(paymentTypeId: string) {
const deletePaymentTypeDialogRef = this.dialog.open(DeleteDialogComponent, {
data: { deleteContext: `payment type ${paymentTypeId}` }
});
deletePaymentTypeDialogRef.afterClosed().subscribe((response: any) => {
if (response.delete) {
this.organizationService.deletePaymentType(paymentTypeId)
.subscribe(() => {
this.paymentTypesData = this.paymentTypesData.filter((paymentType: any) => paymentType.id !== paymentTypeId);
this.setPaymentTypes();
});
}
});
}
}
@@ -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 { OrganizationService } from '../organization.service';
/**
* Payment Types data resolver.
*/
@Injectable()
export class PaymentTypesResolver implements Resolve<Object> {
/**
* @param {OrganizationService} organizationService Organization service.
*/
constructor(private organizationService: OrganizationService) {}
/**
* Returns the payment types data.
* @returns {Observable<any>}
*/
resolve(): Observable<any> {
return this.organizationService.getPaymentTypes();
}
}