import { Component, OnInit } from '@angular/core'; import { KGridHelper } from '../../../_helpers/k-grid.class'; import { NotificationService } from '../../../_services/notification.service'; import { ReportingService } from '../reporting.service'; import { AuthenticationService } from '../../../_services/authentication.service'; import { State, SortDescriptor, orderBy, process } from '@progress/kendo-data-query'; import { DataStateChangeEvent, PageChangeEvent } from '@progress/kendo-angular-grid'; import { AccountService } from '../../accounts/accounts-services'; import { LocalService } from '../../../_services/local.service'; @Component({ selector: 'app-daybook-report', templateUrl: './daybook-report.component.html', }) export class DaybookReportComponent implements OnInit { public kGrid: KGridHelper = new KGridHelper(); public openDilog = false; constructor(public _notificationService: NotificationService, public _reportingServices: ReportingService, public _accountService: AccountService, public _authenticationService: AuthenticationService, private _localService: LocalService) { } public state: State = { skip: 0, take: 5, // Initial filter descriptor filter: { logic: 'and', filters: [] } }; ngOnInit() { this.initializeProps(); this.getEmployeelist(); } public getEmployeelist() { // this.kGrid.loading = true; // let td = null; // let fd = null; // if (this.kGrid.toDate != null) { // td = this.kGrid.toDate.toDateString(); // } // if (this.kGrid.fromDate != null) { // fd = this.kGrid.fromDate.toDateString(); // } // this._reportingServices.getDayBookReport(this.kGrid.skip, this.kGrid.pageSize, this.kGrid.searchQuery, td, fd) // .subscribe((response: any) => { // console.log(response); // this.kGrid.data = []; // this.kGrid.data = this.parseDate(response.DtlList); // console.log(this.kGrid.data); // this.kGrid.totalRecords = response.TotalCount; // this.kGrid.gridView = process(this.kGrid.data, this.state); // this.kGrid.gridView = { data: this.kGrid.data, total: this.kGrid.totalRecords }; // this.kGrid.loading = false; // console.log(this.kGrid.gridView); // }, (err) => this.handleError(err) // ); this.getAccountsList(); } public getAccountsList() { this.kGrid.loading = true; let td = null; let fd = null; if (this.kGrid.toDate != null) { td = this.kGrid.toDate.toDateString(); } if (this.kGrid.fromDate != null) { fd = this.kGrid.fromDate.toDateString(); } this._accountService.getDayBookList(this.kGrid.skip, this.kGrid.pageSize, this.kGrid.searchQuery, this.kGrid.hfId, this.kGrid.geoLvlCode, this.kGrid.hfType, this.kGrid.stockId, fd, td).subscribe( (response: any) => { this.kGrid.data = []; this.kGrid.data = this.parseDate(response.DtlList); this.kGrid.totalRecords = response.TotalCount; this.kGrid.gridView = { data: this.kGrid.data, total: this.kGrid.totalRecords }; this.kGrid.loading = false; console.log(this.kGrid.gridView); }, err => this.handleError(err) ); } parseDate(list) { for (let i = 0; i < list.length; i++) { if (list[i].CreationDate) { list[i].CreationDate = new Date(list[i].CreationDate); } } 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.getEmployeelist(); } 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.getEmployeelist(); } onBinClick(aid: number) { alert(aid); } public columns: string[] = [ "Title", "Name", "StartDate", "EndDate", "NoOfsolutions", "ShiftHour", "ContrectReate" ]; public columnsLabel: string[] = [ "Title", "Coustomer", "Start Date", "End Date", "Solutions", "Shift Hour", "Contrect Rate" ]; public close(status) { this.getEmployeelist(); this.openDilog = false; } public hiddenColumns: string[] = []; public isHidden(columnName: string): boolean { var c = this.columns[this.columnsLabel.indexOf(columnName)] return this.hiddenColumns.indexOf(c) > -1; } public isHiddenGrid(columnName: string): boolean { return this.hiddenColumns.indexOf(columnName) > -1; } public isDisabled(columnName: string): boolean { var c = this.columns[this.columnsLabel.indexOf(columnName)] return this.columns.length - this.hiddenColumns.length === 1 && !this.isHidden(columnName); } public hideColumn(columnName: string): void { var c = this.columns[this.columnsLabel.indexOf(columnName)] const hiddenColumns = this.hiddenColumns; if (!this.isHidden(columnName)) { hiddenColumns.push(c); } else { hiddenColumns.splice(hiddenColumns.indexOf(c), 1); } } }