import { Component, OnInit } from '@angular/core'; import { NotificationService } from '../../../_services/notification.service'; import { ReportingService } from '../reporting.service'; import { AuthenticationService } from '../../../_services/authentication.service'; import { LocalService } from '../../../_services/local.service'; import { KGridHelper } from '../../../_helpers/k-grid.class'; import { DataStateChangeEvent, PageChangeEvent } from '@progress/kendo-angular-grid'; import { SortDescriptor, orderBy, process, State } from '@progress/kendo-data-query'; @Component({ selector: 'app-trial-balance-report', templateUrl: './trial-balance-report.component.html' }) export class TrialBalanceReportComponent implements OnInit { public kGrid: KGridHelper = new KGridHelper(); public _trialBalance: any; public ToDate: Date = null; public loading = false; public geting = false; public CrTotal = 0; public DrTotal = 0; public state: State = { skip: 0, take: 5, // Initial filter descriptor filter: { logic: 'and', filters: [] } }; constructor(public _notificationService: NotificationService, public _reportingServices: ReportingService, public _authenticationService: AuthenticationService, private _localService: LocalService) { } ngOnInit() { this.initializeProps(); } getTrailBalance() { this.loading = true; this.geting = true; this._reportingServices.getTrialBalance({ ToDate: new Date(this.ToDate) }).subscribe((res: any) => { console.log(res); this.kGrid.data = []; this.kGrid.data = this.parseList(res.TrialBalanceItems); this.kGrid.totalRecords = res.TrialBalanceItems.length; this.kGrid.gridView = { data: this.kGrid.data, total: this.kGrid.totalRecords }; this.kGrid.loading = false; console.log(this.kGrid.gridView); this._trialBalance = this.parseList(res); this.loading = false; this.geting = false; }, (err) => { }); } parseList(list) { // list.forEach(element => { // console.log(`${element.Description} -- ${element.DrAmount} -- ${element.CrAmount}`); // if (this.bePositive(element.DrAmount) > 0) { // this.DrTotal += this.bePositive(element.DrAmount); // } // if (this.bePositive(element.CrAmount) > 0) { // this.CrTotal += this.bePositive(element.CrAmount); // } // }); return list; } public ClearFilter() { this.kGrid.fromDate = null; this.kGrid.toDate = null; } private initializeProps() { this.kGrid.loading = false; this.kGrid.pageSize = 20; this.kGrid.pageSizes = [20, 50, 100]; } public dataStateChange(state: DataStateChangeEvent): void { debugger; this.state = state; this.kGrid.gridView = process(this.kGrid.data, this.state); } public sortChange(sort: SortDescriptor[]): void { if (sort[0].field == 'asd') { return; } this.kGrid.sort = sort; this.sortData(); } private sortData() { this.kGrid.gridView = { data: orderBy(this.kGrid.data, this.kGrid.sort), total: this.kGrid.totalRecords }; } public pageChange(event: PageChangeEvent): void { this.kGrid.skip = event.skip; this.getTrailBalance(); } private handleError(err: any) { this.kGrid.loading = false; if (err.status == 403) { this._authenticationService.logout(); } } public changePagesize(value: any) { this.kGrid.pageSize = +value; this.kGrid.skip = 0; this.getTrailBalance(); } public bePositive(num) { return Math.abs(num); } }