import { Component, OnInit, ViewEncapsulation } from '@angular/core'; import { Router } from '@angular/router'; import { DashboardService } from './dashboard.service'; import { NotificationService } from '../../_services/notification.service'; import { LocalService } from '../../_services/local.service'; import { RootService } from '../../_services/root.service'; import { AuthenticationService } from '../../_services/authentication.service'; import { SeriesVisualArgs } from '@progress/kendo-angular-charts'; import { transform } from '@progress/kendo-drawing/dist/npm/geometry'; import { Path, Group } from '@progress/kendo-drawing'; import { KGridHelper } from '../../_helpers/k-grid.class'; import { PageChangeEvent } from '@progress/kendo-angular-grid'; import { SortDescriptor, orderBy } from '@progress/kendo-data-query'; import { EmployeeServices } from '../employee/employee-services'; @Component({ templateUrl: 'dashboard.component.html' }) export class DashboardComponent implements OnInit { public TopInStock: any[] = []; public mName: any[] = []; public qty: any[] = []; public mNameE: any[] = []; public qtyE: any[] = []; public ExpMed: any[] = []; public TopExpMed: any[] = []; public G1loading = false; public G2loading = false; public employeeGrid: KGridHelper = new KGridHelper(); public dashboardVM: DasboardCountViewModel; public data: any[] = [{ kind: 'Bikes', share: 0 }, { kind: 'Sim', share: 0 }, { kind: 'Mobiles', share: 0 }, { kind: 'Helmet', share: 0 }, { kind: 'Other', share: 0 }]; public labelContent(e: any): string { return e.category; } constructor(private router: Router, public _authService: AuthenticationService, public _employeeServices: EmployeeServices, public _authenticationService: AuthenticationService, public _notificationService: NotificationService, public _localService: LocalService, private _rootService: RootService, private _dashboardService: DashboardService) { } ngOnInit(): void { // this.G1loading = true; // this.G2loading = true; // this.getTopInStock(); // this.getExpMed(); // this.getTopExpMed(); this.dashboardVM = new DasboardCountViewModel(); this.dashInit(); this.initializeProps(); this.getEmployeelist(); } private _employeesList:any = []; public getEmployeelist() { this.employeeGrid.loading = true; this._employeeServices.GetEmployeeListforDashboard().subscribe( (response: any) => { this._employeesList = response.DtlList; this.employeeGrid.data = []; this.employeeGrid.data = response.DtlList; this.employeeGrid.totalRecords = response.TotalCount; this.employeeGrid.gridView = { data: this.employeeGrid.data, total: this.employeeGrid.totalRecords }; this.employeeGrid.loading = false; console.log(this.employeeGrid.gridView); }, err => this.handleError(err) ); } dashInit() { this._dashboardService.getCountsForDashboard().subscribe((res: any) => { this.dashboardVM = res; console.log(res); }, (err) => { console.log(err); }); } public cashFlowData = [{ period: 'Beginning\\nBalance', amount: 0 }, { period: 'Jan', amount: 0 }, { period: 'Feb', amount: 0 }, { period: 'Mar', amount: -0 }, { period: 'Q1', summary: 'runningTotal' }, { period: 'Apr', amount: -0 }, { period: 'May', amount: -0 }, { period: 'Jun', amount: 0 }, { period: 'Q2', summary: 'runningTotal' }, { period: 'Ending\\nBalance', summary: 'total' }]; public pointColor(point: any): string { var summary = point.dataItem.summary; if (summary) { return summary == 'total' ? '#555' : 'gray'; } if (point.value > 0) { return 'green'; } else { return 'red'; } } public seriesData: any[] = [ 0 ]; getTopInStock() { this._dashboardService.getTopInStock().subscribe( (responce: any) => { console.log(responce); if (responce) { this.G1loading = false; this.TopInStock = responce.res; this.mName = responce.mName as string[]; this.qty = responce.qty as number[]; } }, err => { } ); } getExpMed() { this._dashboardService.getExpMed().subscribe( (res: any) => { this.ExpMed = res; }, err => { } ); } getTopExpMed() { this._dashboardService.getTopExpMed().subscribe( (res: any) => { this.G2loading = false; this.TopExpMed = res.res; this.mNameE = res.mName as string[]; this.qtyE = res.qty as number[]; }, err => { } ); } public filterText = ''; onEmployeeNameSearch() { let filteredEmployees = []; if (this.filterText !== '') { filteredEmployees = this._employeesList.filter(x => x.Account.toLowerCase().includes(this.filterText.toLowerCase())); } else { filteredEmployees = this._employeesList; } this.employeeGrid.data = []; this.employeeGrid.data = filteredEmployees; this.employeeGrid.totalRecords = filteredEmployees.length; this.employeeGrid.gridView = { data: this.employeeGrid.data, total: this.employeeGrid.totalRecords }; } private initializeProps() { this.employeeGrid.loading = false; this.employeeGrid.pageSize = 5; this.employeeGrid.pageSizes = [5, 20, 50, 100]; } public sortChange(sort: SortDescriptor[]): void { if (sort[0].field == 'asd') { return; } this.employeeGrid.sort = sort; this.sortData(); } private sortData() { this.employeeGrid.gridView = { data: orderBy(this.employeeGrid.data, this.employeeGrid.sort), total: this.employeeGrid.totalRecords }; } public pageChange(event: PageChangeEvent): void { this.employeeGrid.skip = event.skip; this.getEmployeelist(); } private handleError(err: any) { this.employeeGrid.loading = false; if (err.status == 403) { // this._authenticationService.logout(); } } public changePagesize(value: any) { this.employeeGrid.pageSize = +value; this.employeeGrid.skip = 0; this.getEmployeelist(); } } export class DasboardCountViewModel { public ExpiringBike: number; public ExpiringEmployeeDocuments: number; public ExpiringContract: number; public IssuedCheques: number; public Inventry: number; public Sales: number; public Purchase: number; public AssignedInventory: number; public ReceiveableAdvanceAmount: number; public VisaExpenseAmount: number; public VisaReceiveAmount: number; public TodayBookAmount: number; public CashReceiveableAmount: number; public SimExpenseAmount: number; public TFExpenseAmount: number; public GeneralExpenseAmount: number; public BikeInventory: number; public RentedBike: number; public SimInventory: number; public BikeAssigned: number; public Customers: number; public SimAssigned: number; public Employe: number; public AssignedEmploye: number; }