import { Component, Injector, OnInit, ViewChild, ViewEncapsulation, Input, ViewContainerRef } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; import { AppConsts } from '@shared/AppConsts'; import { appModuleAnimation } from '@shared/animations/routerTransition'; import { AppComponentBase } from '@shared/common/app-component-base'; import { RouteListDto, RouteServiceProxy, ControllerKpiCountServiceProxy, ControllerKpiCountListDto } from '@shared/service-proxies/service-proxies'; import * as moment from 'moment'; import { LazyLoadEvent } from 'primeng/components/common/lazyloadevent'; import { Paginator } from 'primeng/components/paginator/paginator'; import { Table } from 'primeng/components/table/table'; import { HttpClient } from '@angular/common/http'; import { finalize } from 'rxjs/operators'; import { Subscription } from 'rxjs'; import { ControllerRoutesService } from '@app/sprintship/controller/routes/croutes.service'; import { format, parse } from 'path'; import { TimerService } from '@app/sprintship/core-components/timer/timer.service'; import { Console } from 'console'; @Component({ selector: 'kpi-box', templateUrl: './kpi-box.component.html', encapsulation: ViewEncapsulation.None, styleUrls: ['./kpi-box.component.less'], animations: [appModuleAnimation()] }) export class KPIBoxComponent extends AppComponentBase implements OnInit { hide: boolean; isLoading: boolean; @Input('statistics') statistics: { total_vehicles: number, total_packages: number }; @Input('total_packages') total_packages: number; @Input('total_vehicles') total_vehicles: number; @Input() filters: { locationFilter: number; statusFilter: number; typeFilter: number; startDate: Date; endDate: Date; routeIds: Array; completed: boolean, }; searchFilters: { route: string, vehicleName: string, driverName: string, showCompletion: boolean, routeIds: Array, orderType: Array, deviceType: string, completed: boolean, } = {}; todaysDate = moment().format('MM/DD/YYYY'); subscription: Subscription; currentKPI: boolean; active: string; kpiRes = new ControllerKpiCountListDto(); active_vehicles = false; active_stops = false; active_unassignedstops = false; active_remainingPickups = false; active_remainingDeliveries = false; active_totalIncidents = false; active_pickedUp = false; active_delivered = false; active_lateRoutes = false; constructor( injector: Injector, private _routeService: RouteServiceProxy, private _cRoutesService: ControllerRoutesService, private _timerService: TimerService, private _cKpiCountService: ControllerKpiCountServiceProxy, private viewContainerRef: ViewContainerRef, ) { super(injector); var that = this; this.subscription = _timerService.tmrMediator.subscribe(details => { }); this.currentKPI = false; this.active = 'NONE'; this.kpiRes.competionRate = "0.00%"; this.kpiRes.delivered = 0; this.kpiRes.deliveredIds = undefined; this.kpiRes.totalVehicle = 0; this.kpiRes.totalVehicleIds = undefined; this.kpiRes.totalStops = 0; this.kpiRes.totalStopsIds = undefined; this.kpiRes.unassignedStops = 0; this.kpiRes.unassignedStopsIds = undefined; this.kpiRes.remainingPickup = 0; this.kpiRes.remainingPickupIds = undefined; this.kpiRes.remainingDeliveries = 0; this.kpiRes.remainingDeliveriesIds = undefined; this.kpiRes.orderIncidents = 0; this.kpiRes.orderIncidentsIds = undefined; this.kpiRes.pickedUp = 0; this.kpiRes.pickedUpIds = undefined; this.kpiRes.lateRoutes = 0; this.kpiRes.lateRouteIds = undefined; } ngOnInit(): void { } getFilters() { if (localStorage.getItem('searchFilter') == null) { this.searchFilters.route = ''; this.searchFilters.driverName = ''; this.searchFilters.showCompletion = false; this.searchFilters.vehicleName = ''; } else { this.searchFilters = JSON.parse(localStorage.getItem('searchFilter')); } } getKpiCount(): void { this.isLoading = true; this.getFilters(); let locationFilter = this.filters.locationFilter; let timeId = localStorage.getItem('timeZoneId'); moment.tz.setDefault(timeId); if (!isNaN(Date.parse(localStorage.getItem('loadDate')))) { if (localStorage.getItem('loadDate').search('-') > 0) { var str = localStorage.getItem('loadDate').split('-'); var str1 = str[1] + '/' + str[2] + '/' + str[0]; localStorage.setItem('loadDate', str1); } } this._cKpiCountService.getRefreshTime(locationFilter) .subscribe(result => { this.getParentComponent().lastRefresh = sessionStorage.setItem('last-refresh', result); }); // this._cKpiCountService.getKPICount( // undefined, // locationFilter, // moment.tz(localStorage.getItem('loadDate'), timeId), // moment.tz(localStorage.getItem('loadDate'), timeId).endOf('day'), // this.searchFilters.showCompletion, // undefined, // undefined, // undefined // ).subscribe( // result => { // this.isLoading = false; // this.kpiRes = result; // if(result != null){ // this.getParentComponent().getLateRoutes(result.lateRouteIds); // } // }); this.isLoading = false; } getParentComponent() { return this.viewContainerRef['_data'].componentView.component.viewContainerRef['_view'].component } remainingPickUp() { if ($('.filter-right-generic-remaining').hasClass('active')) { $('.filter-right-generic').removeClass('active'); this.getParentComponent().staticTabs.tabs[0].active = true; this.getParentComponent().filters.orderStatusCode = "NONE"; this.getParentComponent().loadOrderListComponent('NONE'); } else { $('.filter-right-generic').removeClass('active'); $('.filter-right-generic-remaining').addClass('active'); this.getParentComponent().staticTabs.tabs[1].active = true; this.getParentComponent().filters.orderStatusCode = "REMAINING_PICKUP"; this.getParentComponent().loadOrderListComponent('KPI_REMAINING_STOPS'); } } remainingDeliveries() { // $('.filter-right-generic').removeClass('active'); // $('.filter-right-generic-rdeliveries').addClass('active'); // this.getParentComponent().staticTabs.tabs[2].active = true; // this.getParentComponent().filters.orderStatusCode = "REMAINING_DELIVERIES"; // this.getParentComponent().loadOrderPackagesListComponent(); if ($('.filter-right-generic-rdeliveries').hasClass('active')) { $('.filter-right-generic').removeClass('active'); this.getParentComponent().staticTabs.tabs[0].active = true; this.getParentComponent().filters.orderStatusCode = "NONE"; this.getParentComponent().loadOrderListComponent('NONE'); } else { $('.filter-right-generic').removeClass('active'); $('.filter-right-generic-rdeliveries').addClass('active'); this.getParentComponent().staticTabs.tabs[1].active = true; this.getParentComponent().filters.orderStatusCode = "REMAINING_DELIVERIES"; this.getParentComponent().loadOrderListComponent('KPI_REMAINING_DELIVERIES'); } } pickedUp() { // this.getParentComponent().staticTabs.tabs[2].active = true; // this.getParentComponent().filters.orderStatusCode = "PICKED_UP"; // this.getParentComponent().loadOrderPackagesListComponent(); if ($('.filter-right-generic-pickedup').hasClass('active')) { $('.filter-right-generic').removeClass('active'); this.getParentComponent().staticTabs.tabs[0].active = true; this.getParentComponent().filters.orderStatusCode = "NONE"; this.getParentComponent().loadOrderListComponent('NONE'); } else { $('.filter-right-generic').removeClass('active'); $('.filter-right-generic-pickedup').addClass('active'); this.getParentComponent().staticTabs.tabs[1].active = true; this.getParentComponent().filters.orderStatusCode = "PICKED_UP"; this.getParentComponent().loadOrderListComponent('KPI_PICKED_UP'); } } delivered() { if ($('.filter-right-generic-delivered').hasClass('active')) { $('.filter-right-generic').removeClass('active'); this.getParentComponent().staticTabs.tabs[0].active = true; this.getParentComponent().filters.orderStatusCode = "NONE"; this.getParentComponent().loadOrderListComponent('NONE'); } else { $('.filter-right-generic').removeClass('active'); $('.filter-right-generic-delivered').addClass('active'); this.getParentComponent().staticTabs.tabs[1].active = true; this.getParentComponent().filters.orderStatusCode = "DELIVERED"; this.getParentComponent().loadOrderListComponent('KPI_DELIVERED'); } // this.getParentComponent().staticTabs.tabs[2].active = true; // this.getParentComponent().filters.orderStatusCode = "DELIVERED"; // this.getParentComponent().loadOrderPackagesListComponent(); } filterDriver() { if ($('.filter-right-generic-vehicle').hasClass('active')) { $('.filter-right-generic').removeClass('active'); this.getParentComponent().staticTabs.tabs[0].active = true; } else { $('.filter-right-generic').removeClass('active'); $('.filter-right-generic-vehicle').addClass('active'); this.getParentComponent().staticTabs.tabs[3].active = true; } } unassingedStops() { if ($('.filter-right-generic-unassigned').hasClass('active')) { $('.filter-right-generic').removeClass('active'); this.getParentComponent().staticTabs.tabs[0].active = true; this.getParentComponent().filters.orderStatusCode = "NONE"; this.getParentComponent().loadOrderListComponent('NONE'); } else { $('.filter-right-generic').removeClass('active'); $('.filter-right-generic-unassigned').addClass('active'); this.getParentComponent().staticTabs.tabs[1].active = true; this.getParentComponent().filters.orderStatusCode = "UNASSIGNED"; this.getParentComponent().loadOrderListComponent('KPI_UNASSIGNED'); } } packageWithIssue() { if ($('.filter-right-generic-issues').hasClass('active')) { $('.filter-right-generic').removeClass('active'); this.getParentComponent().staticTabs.tabs[0].active = true; this.getParentComponent().filters.orderStatusCode = "NONE"; this.getParentComponent().loadOrderListComponent('NONE'); } else { $('.filter-right-generic').removeClass('active'); $('.filter-right-generic-issues').addClass('active'); this.getParentComponent().staticTabs.tabs[1].active = true; this.getParentComponent().filters.orderStatusCode = "ISSUE"; this.getParentComponent().loadOrderListComponent('KPI_DELIVERY_ISSUE'); } // this.getParentComponent().staticTabs.tabs[2].active = true; // this.getParentComponent().filters.orderStatusCode = "PACKAGE_ISSUES"; // this.getParentComponent().loadOrderPackagesListComponent(); } filterKPI(boxType: string): void { $('.filter-right-generic').removeClass('active'); console.log(boxType); console.log(this.kpiRes.lateRoutes); switch (boxType) { case 'VEHICLES': this.active_stops = false; this.active_unassignedstops = false; this.active_remainingPickups = false; this.active_remainingDeliveries = false; this.active_totalIncidents = false; this.active_pickedUp = false; this.active_delivered = false; this.active_lateRoutes = false; if (this.kpiRes.totalVehicle > 0) { if (this.active_vehicles == false) { $('.filter-right-generic-vehicle').addClass('active'); this.getParentComponent().filters.vehicleIds = this.kpiRes.totalVehicleIds; this.getParentComponent().loadVehicleListComponent(); this.active_vehicles = true; this.getParentComponent().staticTabs.tabs[3].active = true; } else { this.active_vehicles = false; this.getParentComponent().filters.vehicleIds = []; this.getParentComponent().filterRoutes(); this.getParentComponent().staticTabs.tabs[3].active = false; this.getParentComponent().staticTabs.tabs[0].active = true; } } break; case 'STOPS': this.active_vehicles = false; this.active_unassignedstops = false; this.active_remainingPickups = false; this.active_remainingDeliveries = false; this.active_totalIncidents = false; this.active_pickedUp = false; this.active_delivered = false; this.active_lateRoutes = false; if (this.kpiRes.totalStops > 0) { if (this.active_stops == false) { $('.filter-right-generic-stops').addClass('active'); this.getParentComponent().filters.orderIds = this.kpiRes.totalStopsIds; this.getParentComponent().loadOrderListComponent(); this.active_stops = true; this.getParentComponent().staticTabs.tabs[1].active = true; } else { this.active_stops = false; this.getParentComponent().filters.orderIds = undefined; this.getParentComponent().staticTabs.tabs[0].active = true; this.getParentComponent().filterRoutes(); } } break; case 'UNASSIGNED_STOPS': this.active_vehicles = false; this.active_stops = false; this.active_remainingPickups = false; this.active_remainingDeliveries = false; this.active_totalIncidents = false; this.active_pickedUp = false; this.active_delivered = false; this.active_lateRoutes = false; // this.getParentComponent().staticTabs.tabs[0].active = true; if (this.kpiRes.totalStops > 0) { if (this.active_unassignedstops == false) { $('.filter-right-generic-unassigned').addClass('active'); this.getParentComponent().filters.orderIds = this.kpiRes.unassignedStopsIds; this.active_unassignedstops = true; this.getParentComponent().staticTabs.tabs[1].active = true; this.getParentComponent().loadOrderListComponent(); } else { this.active_unassignedstops = false; this.getParentComponent().filters.orderIds = undefined; this.getParentComponent().filterRoutes(); this.getParentComponent().staticTabs.tabs[0].active = true; } } break; case 'LATE_ROUTES': this.active_vehicles = false; this.active_stops = false; this.active_unassignedstops = false; this.active_remainingDeliveries = false; this.active_totalIncidents = false; this.active_pickedUp = false; this.active_delivered = false; this.active_remainingPickups == false; // this.getParentComponent().staticTabs.tabs[0].active = true; if (this.kpiRes.lateRoutes > 0) { if (this.active_lateRoutes == false) { $('.filter-right-generic-lateroutes').addClass('active'); this.getParentComponent().filters.routeIds = this.kpiRes.lateRouteIds; this.getParentComponent().filterRoutes(); this.active_lateRoutes = true; this.getParentComponent().staticTabs.tabs[0].active = true; } else { this.active_lateRoutes = false; this.getParentComponent().filters.routeIds = undefined; this.getParentComponent().filterRoutes(); this.getParentComponent().staticTabs.tabs[0].active = true; } } break; case 'REMAINING_PICKUP': this.active_vehicles = false; this.active_stops = false; this.active_unassignedstops = false; this.active_remainingDeliveries = false; this.active_totalIncidents = false; this.active_pickedUp = false; this.active_delivered = false; this.active_lateRoutes == false // this.getParentComponent().staticTabs.tabs[0].active = true; if (this.kpiRes.remainingPickup > 0) { if (this.active_remainingPickups == false) { $('.filter-right-generic-remaining').addClass('active'); this.getParentComponent().filters.orderIds = this.kpiRes.remainingPickupIds; this.getParentComponent().loadOrderListComponent(); this.active_remainingPickups = true; this.getParentComponent().staticTabs.tabs[1].active = true; } else { this.active_remainingPickups = false; this.getParentComponent().filters.orderIds = undefined; this.getParentComponent().filterRoutes(); this.getParentComponent().staticTabs.tabs[0].active = true; } } break; case 'REMAINING_DELIVERIES': this.active_vehicles = false; this.active_stops = false; this.active_unassignedstops = false; this.active_remainingPickups = false; this.active_totalIncidents = false; this.active_pickedUp = false; this.active_delivered = false; this.active_lateRoutes == false // this.getParentComponent().staticTabs.tabs[0].active = true; if (this.kpiRes.remainingDeliveries > 0) { if (this.active_remainingDeliveries == false) { $('.filter-right-generic-rdeliveries').addClass('active'); this.getParentComponent().filters.orderIds = this.kpiRes.remainingDeliveriesIds; this.getParentComponent().loadOrderListComponent(); this.active_remainingDeliveries = true; this.getParentComponent().staticTabs.tabs[1].active = true; } else { this.active_remainingDeliveries = false; this.getParentComponent().filters.orderIds = undefined; this.getParentComponent().filterRoutes(); this.getParentComponent().staticTabs.tabs[0].active = true; } } break; case 'ORDER_INCIDENTS': this.active_vehicles = false; this.active_stops = false; this.active_unassignedstops = false; this.active_remainingPickups = false; this.active_remainingDeliveries = false; this.active_pickedUp = false; this.active_delivered = false; this.active_lateRoutes == false // this.getParentComponent().staticTabs.tabs[0].active = true; if (this.kpiRes.orderIncidents > 0) { if (this.active_totalIncidents == false) { $('.filter-right-generic-issues').addClass('active'); this.getParentComponent().filters.orderIds = this.kpiRes.orderIncidentsIds; this.getParentComponent().loadOrderListComponent(); this.active_totalIncidents = true; this.getParentComponent().staticTabs.tabs[1].active = true; } else { this.active_totalIncidents = false; this.getParentComponent().filters.orderIds = undefined; this.getParentComponent().filterRoutes(); this.getParentComponent().staticTabs.tabs[0].active = true; } } break; case 'PICKED_UP': this.active_vehicles = false; this.active_stops = false; this.active_unassignedstops = false; this.active_remainingPickups = false; this.active_remainingDeliveries = false; this.active_totalIncidents = false; this.active_delivered = false; this.active_lateRoutes == false // this.getParentComponent().staticTabs.tabs[0].active = true; if (this.kpiRes.pickedUp > 0) { if (this.active_pickedUp == false) { $('.filter-right-generic-pickedup').addClass('active'); this.getParentComponent().filters.orderIds = this.kpiRes.pickedUpIds; this.getParentComponent().loadOrderListComponent(); this.active_pickedUp = true; this.getParentComponent().staticTabs.tabs[1].active = true; } else { this.active_pickedUp = false; this.getParentComponent().filters.orderIds = undefined; this.getParentComponent().filterRoutes(); this.getParentComponent().staticTabs.tabs[0].active = true; } } break; case 'DELIVERED': this.active_vehicles = false; this.active_stops = false; this.active_unassignedstops = false; this.active_remainingPickups = false; this.active_remainingDeliveries = false; this.active_totalIncidents = false; this.active_pickedUp = false; this.active_lateRoutes == false // this.getParentComponent().staticTabs.tabs[0].active = true; if (this.kpiRes.delivered > 0) { if (this.active_delivered == false) { $('.filter-right-generic-delivered').addClass('active'); this.getParentComponent().filters.orderIds = this.kpiRes.deliveredIds; this.getParentComponent().loadOrderListComponent(); this.active_delivered = true; this.getParentComponent().staticTabs.tabs[1].active = true; } else { this.active_delivered = false; this.getParentComponent().filters.orderIds = undefined; this.getParentComponent().filterRoutes(); this.getParentComponent().staticTabs.tabs[0].active = true; } } break; } } getStatisticsStandard(data: any) { this.kpiRes.competionRate = data.total_completionRate; this.kpiRes.delivered = data.total_delivered; this.kpiRes.deliveredIds = data.total_delivered_ids; this.kpiRes.totalVehicle = data.total_vehicle; this.kpiRes.totalVehicleIds = data.total_vehicle_ids; this.kpiRes.totalStops = data.total_stops; this.kpiRes.totalStopsIds = data.total_stops_ids; this.kpiRes.unassignedStops = data.total_unassignedstops; this.kpiRes.unassignedStopsIds = data.total_unassignedstops_ids; this.kpiRes.remainingPickup = data.total_remaningPickup; this.kpiRes.remainingPickupIds = data.total_remaningPickup_ids; this.kpiRes.remainingDeliveries = data.total_remaningDeliveries; this.kpiRes.remainingDeliveriesIds = data.total_remaningDeliveries_ids; this.kpiRes.orderIncidents = data.total_incidents; this.kpiRes.orderIncidentsIds = data.total_incidents_ids; this.kpiRes.pickedUp = data.total_pickedUp; this.kpiRes.pickedUpIds = data.total_pickedUp_ids; this.kpiRes.lateRoutes = data.total_lateRoutes; this.kpiRes.lateRouteIds = data.total_lateRoutes_ids; } }