import { Component, OnInit } from '@angular/core'; import { State, SortDescriptor, orderBy, process } from '@progress/kendo-data-query'; import { DataStateChangeEvent, PageChangeEvent } from '@progress/kendo-angular-grid'; import { Subject, Subscription } from 'rxjs'; import { debounceTime } from 'rxjs/operators'; import { KGridHelper } from '../../../../_helpers/k-grid.class'; import { NotificationService } from '../../../../_services/notification.service'; import { ReportingService } from '../../reporting.service'; import { StoreService } from '../../../store/store.services'; import { AuthenticationService } from '../../../../_services/authentication.service'; import { CoustomerServices } from '../../../coustomer/coustome-services'; import { LocalService } from '../../../../_services/local.service'; @Component({ selector: 'app-contrectwise', templateUrl: './contrectwise.component.html', }) export class ContrectwiseComponent implements OnInit { public kGrid: KGridHelper = new KGridHelper(); public empList: any[] = []; public selectedEmp: any; public searchEvent = new Subject(); public searchSubcription: Subscription = null; public openDilog = false; public geting = false; public totalPayable = 0; public totalpaid = 0; constructor(public _notificationService: NotificationService, public _reportingServices: ReportingService, private _coustomerServices: CoustomerServices, public _storeService: StoreService, public _authenticationService: AuthenticationService, private _localService: LocalService) { } public state: State = { skip: 0, take: 5, // Initial filter descriptor filter: { logic: 'and', filters: [] } }; ngOnInit() { this.initializeProps(); this.handleSearchEvents(); } private initializeProps() { this.kGrid.loading = false; this.kGrid.pageSize = 20; this.kGrid.pageSizes = [20, 50, 100]; } public getEmployeelist() { this.kGrid.loading = true; this.geting = true; this._reportingServices.getCashContrectWiseReceving(this.kGrid.skip, this.kGrid.pageSize, this.kGrid.searchQuery, this.kGrid.hfId, this.kGrid.geoLvlCode, this.selectedEmp.Id).subscribe( (response: any) => { 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); this.geting = false; }, 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); if (list[i].CashReturn) this.totalpaid += list[i].CashReturn; if (list[i].CashInHand) this.totalPayable += list[i].CashInHand; } 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[] = [ "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); } } public getContrectList(x: string) { this._coustomerServices.getContrectListDDL(x, 'Customer').subscribe((res: any) => { if (res) { debugger; this.empList = 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 == "emp") { this.getContrectList(x.event); } } }); } }