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 { THIS_EXPR } from '@angular/compiler/src/output/output_ast'; import { Subject, Subscription } from 'rxjs'; import { debounceTime } from 'rxjs/operators'; import { CoustomerServices } from '../../coustomer/coustome-services'; import { LocalService } from '../../../_services/local.service'; @Component({ selector: 'app-emp-current-assigning-report', templateUrl: './emp-current-assigning-report.component.html', }) export class EmpCurrentAssigningReportComponent implements OnInit { public kGrid: KGridHelper = new KGridHelper(); public searchEvent = new Subject(); public searchSubcription: Subscription = null; public openDilog = false; public geting = false; public selectedContrect: any; public contrectList: any[] = []; constructor(public _notificationService: NotificationService, public _reportingServices: ReportingService, private _coustomerServices: CoustomerServices, 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(); this.handleSearchEvents(); } private initializeProps() { this.kGrid.loading = false; this.kGrid.pageSize = 20; this.kGrid.pageSizes = [20, 50, 100]; } public getEmployeelist() { let cid = 0; if (this.selectedContrect != null) { cid = this.selectedContrect.Id; } // this.geting = true; this.kGrid.loading = true; this._reportingServices.getEmployeCurrentAssigning(this.kGrid.skip, this.kGrid.pageSize, this.kGrid.searchQuery, this.kGrid.hfId, this.kGrid.geoLvlCode, this.kGrid.hfType, cid, new Date()).subscribe( (response: any) => { this.kGrid.data = []; this.kGrid.data = this.parseDate(response.DtlList); 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; this.geting = false; console.log(this.kGrid.gridView); }, err => this.handleError(err) ); } public TotalCr = 0; public TotalDr = 0; public TotalBalance = 0; parseDate(list) { this.TotalCr = 0; this.TotalDr = 0; this.TotalBalance = 0; for (let i = 0; i < list.length; i++) { if (list[i].StartDate) { list[i].StartDate = new Date(list[i].StartDate); } if (list[i].EndDate) { list[i].EndDate = new Date(list[i].EndDate); } if (list[i].Balance > 0) { this.TotalCr += list[i].Balance; } else { this.TotalDr += list[i].Balance; } this.TotalBalance += list[i].Balance; } console.log(this.TotalBalance); return list; } 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(); } } onBinClick(aid: number) { alert(aid); } public changePagesize(value: any) { this.kGrid.pageSize = +value; this.kGrid.skip = 0; this.getEmployeelist(); } public columns: string[] = [ 'FK_Employee', 'Name', 'FK_Contrect', 'Acc_Titel', 'StartDate', 'EndDate', 'Title' ]; public columnsLabel: string[] = [ 'Id', 'Employee Name', 'Contract Id', 'Customer', 'StartDate', 'EndDate', 'Contract Titel' ]; public close(status) { if (this.hiddenColumns.length > 0) 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); } } public getContrectList(x: string) { this._coustomerServices.getContrectListDDL(x, 'Customer').subscribe((res: any) => { if (res) { debugger; this.contrectList = res; } }, err => { this._notificationService.notify('danger', err.msg); }) } public handleSearchEvents() { this.searchSubcription = this.searchEvent.pipe( debounceTime(400)).subscribe((x: any) => { console.log(x); if (x) { debugger; if (x.filter == 'Customer') { this.getContrectList(x.event); } } }); } }