Moved to Angular 6.0

----

Pending
* Table width for the points column in incentive
* Linting
* keyboard navigation where it was used earlier
* can remove the unused totals calculated serverside in productledger
* spinner and loading bars
* Activate Guard for Employee Function tabs
* Progress for Fingerprint uploads
* deleted reconcile and receipe features as they were not being used
* focus the right control on component load
This commit is contained in:
tanshu
2018-05-25 19:19:00 +05:30
parent b3cb01da02
commit 6be1dd5a3a
1380 changed files with 23914 additions and 18722 deletions

View File

@ -0,0 +1,61 @@
import {DataSource} from '@angular/cdk/collections';
import {MatPaginator, MatSort} from '@angular/material';
import {map} from 'rxjs/operators';
import {merge, Observable, of as observableOf} from 'rxjs';
import {LedgerItem} from './ledger';
export class LedgerDataSource extends DataSource<LedgerItem> {
constructor(private paginator: MatPaginator, private sort: MatSort, public data: LedgerItem[]) {
super();
}
connect(): Observable<LedgerItem[]> {
const dataMutations = [
observableOf(this.data),
this.paginator.page,
this.sort.sortChange
];
// Set the paginators length
this.paginator.length = this.data.length;
return merge(...dataMutations).pipe(map(() => {
return this.getPagedData(this.getSortedData([...this.data]));
}));
}
disconnect() {
}
private getPagedData(data: LedgerItem[]) {
const startIndex = this.paginator.pageIndex * this.paginator.pageSize;
return data.splice(startIndex, this.paginator.pageSize);
}
private getSortedData(data: LedgerItem[]) {
if (!this.sort.active || this.sort.direction === '') {
return data;
}
return data.sort((a, b) => {
const isAsc = this.sort.direction === 'asc';
switch (this.sort.active) {
case 'date':
return compare(a.date, b.date, isAsc);
case 'debit':
return compare(+a.debit, +b.debit, isAsc);
case 'credit':
return compare(+a.credit, +b.credit, isAsc);
default:
return 0;
}
});
}
}
/** Simple sort comparator for example ID/Name columns (for client-side sorting). */
function compare(a, b, isAsc) {
return (a < b ? -1 : 1) * (isAsc ? 1 : -1);
}

View File

@ -0,0 +1,15 @@
import {inject, TestBed} from '@angular/core/testing';
import {LedgerResolver} from './ledger-resolver.service';
describe('LedgerResolver', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [LedgerResolver]
});
});
it('should be created', inject([LedgerResolver], (service: LedgerResolver) => {
expect(service).toBeTruthy();
}));
});

View File

@ -0,0 +1,21 @@
import {Injectable} from '@angular/core';
import {ActivatedRouteSnapshot, Resolve, RouterStateSnapshot} from '@angular/router';
import {Observable} from 'rxjs/internal/Observable';
import {Ledger} from './ledger';
import {LedgerService} from './ledger.service';
@Injectable({
providedIn: 'root'
})
export class LedgerResolver implements Resolve<Ledger> {
constructor(private ser: LedgerService) {
}
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<Ledger> {
const id = route.paramMap.get('id');
const startDate = route.queryParamMap.get('startDate') || null;
const finishDate = route.queryParamMap.get('finishDate') || null;
return this.ser.list(id, startDate, finishDate);
}
}

View File

@ -0,0 +1,13 @@
import {LedgerRoutingModule} from './ledger-routing.module';
describe('LedgerRoutingModule', () => {
let ledgerRoutingModule: LedgerRoutingModule;
beforeEach(() => {
ledgerRoutingModule = new LedgerRoutingModule();
});
it('should create an instance', () => {
expect(ledgerRoutingModule).toBeTruthy();
});
});

View File

@ -0,0 +1,49 @@
import {NgModule} from '@angular/core';
import {CommonModule} from '@angular/common';
import {RouterModule, Routes} from '@angular/router';
import {LedgerResolver} from './ledger-resolver.service';
import {AuthGuard} from '../auth/auth-guard.service';
import {LedgerComponent} from './ledger.component';
const ledgerRoutes: Routes = [
{
path: 'Ledger',
component: LedgerComponent,
canActivate: [AuthGuard],
data: {
permission: 'Ledger'
},
resolve: {
info: LedgerResolver
},
runGuardsAndResolvers: 'always'
},
{
path: 'Ledger/:id',
component: LedgerComponent,
canActivate: [AuthGuard],
data: {
permission: 'Ledger'
},
resolve: {
info: LedgerResolver
},
runGuardsAndResolvers: 'always'
}
];
@NgModule({
imports: [
CommonModule,
RouterModule.forChild(ledgerRoutes)
],
exports: [
RouterModule
],
providers: [
LedgerResolver
]
})
export class LedgerRoutingModule {
}

View File

@ -0,0 +1,12 @@
.right {
display: flex;
justify-content: flex-end;
}
.selected{
background: #fff3cd
}
.unposted{
background: #f8d7da
}

View File

@ -0,0 +1,102 @@
<mat-card>
<mat-card-title-group>
<mat-card-title>Ledger</mat-card-title>
<button mat-button mat-icon-button *ngIf="dataSource.data.length" (click)="exportCsv()">
<mat-icon>save_alt</mat-icon>
</button>
</mat-card-title-group>
<mat-card-content>
<form [formGroup]="form" fxLayout="column">
<div fxLayout="row" fxLayout.lt-md="column" fxLayoutGap="20px" fxLayoutGap.lt-md="0px"
fxLayoutAlign="space-around start">
<mat-form-field fxFlex>
<input matInput [matDatepicker]="startDate" (focus)="startDate.open()" placeholder="Start Date"
formControlName="startDate" autocomplete="off">
<mat-datepicker-toggle matSuffix [for]="startDate"></mat-datepicker-toggle>
<mat-datepicker #startDate></mat-datepicker>
</mat-form-field>
<mat-form-field fxFlex>
<input matInput [matDatepicker]="finishDate" (focus)="finishDate.open()" placeholder="Finish Date"
formControlName="finishDate" autocomplete="off">
<mat-datepicker-toggle matSuffix [for]="finishDate"></mat-datepicker-toggle>
<mat-datepicker #finishDate></mat-datepicker>
</mat-form-field>
</div>
<div fxLayout="row" fxLayout.lt-md="column" fxLayoutGap="20px" fxLayoutGap.lt-md="0px"
fxLayoutAlign="space-around start">
<mat-form-field fxFlex="80">
<input type="text" matInput #accountElement placeholder="Account" [matAutocomplete]="auto"
formControlName="account" autocomplete="off">
<mat-autocomplete #auto="matAutocomplete" autoActiveFirstOption [displayWith]="displayFn"
(optionSelected)="selected($event)">
<mat-option *ngFor="let account of accounts | async" [value]="account">{{account.name}}</mat-option>
</mat-autocomplete>
</mat-form-field>
<button fxFlex="20" mat-raised-button color="primary" (click)="show()">Show</button>
</div>
</form>
<mat-table #table [dataSource]="dataSource" matSort aria-label="Elements">
<!-- Date Column -->
<ng-container matColumnDef="date">
<mat-header-cell *matHeaderCellDef mat-sort-header>Date</mat-header-cell>
<mat-cell *matCellDef="let row">{{row.date}}</mat-cell>
<mat-footer-cell *matFooterCellDef></mat-footer-cell>
</ng-container>
<!-- Particulars Column -->
<ng-container matColumnDef="particulars">
<mat-header-cell *matHeaderCellDef mat-sort-header>Particulars</mat-header-cell>
<mat-cell *matCellDef="let row"><a [href]="row.url">{{row.name}}</a></mat-cell>
<mat-footer-cell *matFooterCellDef>Closing Balance</mat-footer-cell>
</ng-container>
<!-- Type Column -->
<ng-container matColumnDef="type">
<mat-header-cell *matHeaderCellDef mat-sort-header>Type</mat-header-cell>
<mat-cell *matCellDef="let row">{{row.type}}</mat-cell>
<mat-footer-cell *matFooterCellDef>Closing Balance</mat-footer-cell>
</ng-container>
<!-- Narration Column -->
<ng-container matColumnDef="narration">
<mat-header-cell *matHeaderCellDef mat-sort-header>Narration</mat-header-cell>
<mat-cell *matCellDef="let row">{{row.narration}}</mat-cell>
<mat-footer-cell *matFooterCellDef></mat-footer-cell>
</ng-container>
<!-- Debit Column -->
<ng-container matColumnDef="debit">
<mat-header-cell *matHeaderCellDef mat-sort-header class="right">Debit</mat-header-cell>
<mat-cell *matCellDef="let row" class="right">{{row.debit | currency:'INR' | clear}}</mat-cell>
<mat-footer-cell *matFooterCellDef class="right">{{debit | currency:'INR'}}</mat-footer-cell>
</ng-container>
<!-- Credit Column -->
<ng-container matColumnDef="credit">
<mat-header-cell *matHeaderCellDef mat-sort-header class="right">Credit</mat-header-cell>
<mat-cell *matCellDef="let row" class="right">{{row.credit | currency:'INR' | clear}}</mat-cell>
<mat-footer-cell *matFooterCellDef class="right">{{credit | currency:'INR'}}</mat-footer-cell>
</ng-container>
<!-- Running Column -->
<ng-container matColumnDef="running">
<mat-header-cell *matHeaderCellDef mat-sort-header class="right">Running</mat-header-cell>
<mat-cell *matCellDef="let row" class="right">{{row.running | currency:'INR' | accounting}}</mat-cell>
<mat-footer-cell *matFooterCellDef class="right">{{running | currency:'INR' | accounting}}</mat-footer-cell>
</ng-container>
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
<mat-row *matRowDef="let row; columns: displayedColumns;" [ngClass]="getRowClass(row.id, row.posted)"
(click)="selectRow(row.id)"></mat-row>
<mat-footer-row *matFooterRowDef="displayedColumns"></mat-footer-row>
</mat-table>
<mat-paginator #paginator
[length]="dataSource.data.length"
[pageIndex]="0"
[pageSize]="50"
[pageSizeOptions]="[25, 50, 100, 250, 300, 5000]">
</mat-paginator>
</mat-card-content>
</mat-card>

View File

@ -0,0 +1,25 @@
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
import {LedgerComponent} from './ledger.component';
describe('LedgerComponent', () => {
let component: LedgerComponent;
let fixture: ComponentFixture<LedgerComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [LedgerComponent]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(LedgerComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -0,0 +1,157 @@
import {AfterViewInit, Component, ElementRef, OnInit, ViewChild} from '@angular/core';
import {FormBuilder, FormGroup} from '@angular/forms';
import {MatAutocompleteSelectedEvent, MatPaginator, MatSort} from '@angular/material';
import {ActivatedRoute, Router} from '@angular/router';
import {Observable, of as observableOf} from 'rxjs';
import {debounceTime, distinctUntilChanged, map, startWith, switchMap} from 'rxjs/operators';
import * as moment from 'moment';
import {LedgerDataSource} from './ledger-datasource';
import {Ledger} from './ledger';
import {Account} from '../account/account';
import {LedgerService} from './ledger.service';
import {AccountService} from '../account/account.service';
@Component({
selector: 'app-ledger',
templateUrl: './ledger.component.html',
styleUrls: ['./ledger.component.css']
})
export class LedgerComponent implements OnInit, AfterViewInit {
@ViewChild('accountElement') accountElement: ElementRef;
@ViewChild(MatPaginator) paginator: MatPaginator;
@ViewChild(MatSort) sort: MatSort;
dataSource: LedgerDataSource;
form: FormGroup;
info: Ledger;
selectedRowId: string;
debit: number;
credit: number;
running: number;
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
displayedColumns = ['date', 'particulars', 'type', 'narration', 'debit', 'credit', 'running'];
accounts: Observable<Account[]>;
constructor(
private route: ActivatedRoute,
private router: Router,
private fb: FormBuilder,
private ser: LedgerService,
private accountSer: AccountService
) {
this.createForm();
this.accounts = this.form.get('account').valueChanges
.pipe(
startWith(null),
map(x => (x !== null && x.length >= 1) ? x : null),
debounceTime(150),
distinctUntilChanged(),
switchMap(x => (x === null) ? observableOf([]) : this.accountSer.autocomplete(x))
);
}
ngOnInit() {
this.route.data
.subscribe((data: { info: Ledger }) => {
this.info = data.info;
this.calculateTotals();
this.form.setValue({
account: this.info.account,
startDate: moment(this.info.startDate, 'DD-MMM-YYYY').toDate(),
finishDate: moment(this.info.finishDate, 'DD-MMM-YYYY').toDate()
});
this.dataSource = new LedgerDataSource(this.paginator, this.sort, this.info.body);
});
}
ngAfterViewInit() {
setTimeout(() => {
this.accountElement.nativeElement.focus();
}, 0);
}
displayFn(account?: Account): string | undefined {
return account ? account.name : undefined;
}
calculateTotals() {
this.debit = 0;
this.credit = 0;
this.running = 0;
this.info.body.forEach((item) => {
if (item.type !== 'Opening Balance') {
this.debit += item.debit;
this.credit += item.credit;
if (item.posted) {
this.running += item.debit - item.credit;
}
} else {
this.running += item.debit - item.credit;
}
item.running = this.running;
});
}
selected(event: MatAutocompleteSelectedEvent): void {
this.info.account = event.option.value;
}
selectRow(id: string): void {
this.selectedRowId = id;
}
getRowClass(id: string, posted: boolean): string {
if (this.selectedRowId === id) {
return 'selected';
} else if (!posted) {
return 'unposted';
} else {
return '';
}
}
show() {
const info = this.getInfo();
this.router.navigate(['Ledger', info.account.id], {
queryParams: {
startDate: info.startDate,
finishDate: info.finishDate
}
});
}
createForm() {
this.form = this.fb.group({
startDate: '',
finishDate: '',
account: ''
});
}
getInfo(): Ledger {
const formModel = this.form.value;
return {
account: formModel.account,
startDate: moment(formModel.startDate).format('DD-MMM-YYYY'),
finishDate: moment(formModel.finishDate).format('DD-MMM-YYYY')
};
}
exportCsv() {
const data: string[] = ['Date , Name , Type , Narration , Debit , Credit , Running , Posted'];
data.push(
...this.dataSource.data.map(x => x.date + ', ' + x.name + ', ' + x.type + ', ' +
x.narration + ', ' + x.debit + ', ' + x.credit + ', ' + x.running + ', ' + x.posted)
);
const csvData = new Blob([data.join('\n')], {type: 'text/csv;charset=utf-8;'});
const link = document.createElement('a');
link.href = window.URL.createObjectURL(csvData);
link.setAttribute('download', 'ledger.csv');
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
}

View File

@ -0,0 +1,13 @@
import {LedgerModule} from './ledger.module';
describe('LedgerModule', () => {
let ledgerModule: LedgerModule;
beforeEach(() => {
ledgerModule = new LedgerModule();
});
it('should create an instance', () => {
expect(ledgerModule).toBeTruthy();
});
});

View File

@ -0,0 +1,75 @@
import {NgModule} from '@angular/core';
import {CommonModule} from '@angular/common';
import {
DateAdapter,
MAT_DATE_FORMATS,
MAT_DATE_LOCALE,
MatAutocompleteModule,
MatButtonModule,
MatCardModule,
MatCheckboxModule,
MatDatepickerModule,
MatFormFieldModule,
MatIconModule,
MatInputModule,
MatNativeDateModule,
MatPaginatorModule,
MatProgressSpinnerModule,
MatSortModule,
MatTableModule
} from '@angular/material';
import {SharedModule} from '../shared/shared.module';
import {ReactiveFormsModule} from '@angular/forms';
import {CdkTableModule} from '@angular/cdk/table';
import {LedgerRoutingModule} from './ledger-routing.module';
import {LedgerComponent} from './ledger.component';
import {MomentDateAdapter} from '@angular/material-moment-adapter';
import {A11yModule} from '@angular/cdk/a11y';
import {FlexLayoutModule, FlexModule} from '@angular/flex-layout';
export const MY_FORMATS = {
parse: {
dateInput: 'DD-MMM-YYYY',
},
display: {
dateInput: 'DD-MMM-YYYY',
monthYearLabel: 'MMM YYYY',
dateA11yLabel: 'DD-MMM-YYYY',
monthYearA11yLabel: 'MMM YYYY',
},
};
@NgModule({
imports: [
A11yModule,
CommonModule,
CdkTableModule,
FlexModule,
FlexLayoutModule,
MatAutocompleteModule,
MatButtonModule,
MatCardModule,
MatCheckboxModule,
MatDatepickerModule,
MatFormFieldModule,
MatIconModule,
MatInputModule,
MatNativeDateModule,
MatPaginatorModule,
MatProgressSpinnerModule,
MatSortModule,
MatTableModule,
ReactiveFormsModule,
SharedModule,
LedgerRoutingModule
],
declarations: [
LedgerComponent
],
providers: [
{provide: DateAdapter, useClass: MomentDateAdapter, deps: [MAT_DATE_LOCALE]},
{provide: MAT_DATE_FORMATS, useValue: MY_FORMATS},
]
})
export class LedgerModule {
}

View File

@ -0,0 +1,15 @@
import {inject, TestBed} from '@angular/core/testing';
import {LedgerService} from './ledger.service';
describe('LedgerService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [LedgerService]
});
});
it('should be created', inject([LedgerService], (service: LedgerService) => {
expect(service).toBeTruthy();
}));
});

View File

@ -0,0 +1,38 @@
import {Injectable} from '@angular/core';
import {catchError} from 'rxjs/operators';
import {Observable} from 'rxjs/internal/Observable';
import {HttpClient, HttpHeaders, HttpParams} from '@angular/common/http';
import {Ledger} from './ledger';
import {ErrorLoggerService} from '../core/error-logger.service';
const httpOptions = {
headers: new HttpHeaders({'Content-Type': 'application/json'})
};
const url = '/api/Ledger';
const serviceName = 'LedgerService';
@Injectable({
providedIn: 'root'
})
export class LedgerService {
constructor(private http: HttpClient, private log: ErrorLoggerService) {
}
list(date: string, startDate: string, finishDate): Observable<Ledger> {
const listUrl = (date === null) ? url : `${url}/${date}`;
const options = {params: new HttpParams()};
if (startDate !== null) {
options.params = options.params.set('s', startDate);
}
if (finishDate !== null) {
options.params = options.params.set('f', finishDate);
}
return <Observable<Ledger>>this.http.get<Ledger>(listUrl, options)
.pipe(
catchError(this.log.handleError(serviceName, 'list'))
);
}
}

View File

@ -0,0 +1,21 @@
import {Account} from '../account/account';
export class LedgerItem {
date: string;
id: string;
name: string;
type: string;
narration: string;
debit: number;
credit: number;
running: number;
posted: boolean;
url: string;
}
export class Ledger {
startDate: string;
finishDate: string;
account: Account;
body?: LedgerItem[];
}