import { Component, Injector, OnInit, ViewChild, ViewEncapsulation, Input, OnChanges, 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 } 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 * as status_icon from './status_icon.json'; import { ControllerRoutesService } from '@app/sprintship/controller/routes/croutes.service'; import { ControllerHeaderFlyoutComponent } from '@app/shared/layout/flyout/controller-header/controller-header-flyout.component'; @Component({ selector: 'kpi-laboratory', templateUrl: './kpi-laboratory.component.html', encapsulation: ViewEncapsulation.None, styleUrls: ['./kpi-laboratory.component.less'], animations: [appModuleAnimation()], providers: [ControllerRoutesService] }) export class KpiLaboratoryComponent extends AppComponentBase implements OnInit { hide : boolean; @ViewChild('controllerHeaderFlyoutComponent', { static: false }) controllerHeaderFlyoutComponent: ControllerHeaderFlyoutComponent; @Input('statistics') statistics: { total_routes: number, total_stops: number }; status_value: any; completed_stops: number; total_stops: number; completed_routes: number; total_routes: number; completed_callins: number; total_callins: number; total_incidents: number; unassigned_routes: number; unassigned_stops: number; assigned_not_check_in: number; total_unassigned_willcalls: number; late_past_20: number; late_past_30: number; unassigned_routes_ids: any; not_check_in_routes_ids: any; completed_route_ids: any; unassigned_stop_ids: any; completed_stops_id: any; completed_call_in_stops_ids: any; unassigned_willcallIds: any; incidentIds: any; late20_route_ids: any; late30_route_ids: any; active_unassigned: boolean; active_notcheckin: boolean; active_completedroutes: boolean; active_late20: boolean; active_late30: boolean; active_unassignedwillcalls: boolean; active_completedStops: boolean; active_completedWillCalls: boolean; active_incidents: boolean; constructor( injector: Injector, private _routeService: RouteServiceProxy, private _cRoutesService: ControllerRoutesService, private viewContainerRef: ViewContainerRef ) { super(injector); this.total_routes = 0; this.total_stops = 0; this.total_callins = 0; this.completed_routes = 0; this.completed_stops = 0; this.completed_callins = 0; this.total_incidents = 0; this.unassigned_routes = 0; this.unassigned_stops = 0; this.assigned_not_check_in = 0; this.late_past_20 = 0; this.late_past_30 = 0; this.total_unassigned_willcalls = 0; this.unassigned_willcallIds = []; this.unassigned_routes_ids = []; this.not_check_in_routes_ids = []; this.completed_route_ids = []; this.unassigned_stop_ids = []; this.completed_stops_id = []; this.completed_call_in_stops_ids = []; this.late20_route_ids = []; this.late30_route_ids = []; this.incidentIds = []; this.active_unassigned = false; this.active_notcheckin = false; this.active_completedroutes = false; this.active_late20 = false; this.active_late30 = false; this.active_unassignedwillcalls = false; this.active_completedStops = false; this.active_completedWillCalls = false; this.active_incidents = false; } ngOnInit(): void { } onShown(): void { } getParentComponent() { return this.viewContainerRef['_data'].componentView.component.viewContainerRef['_view'].component } getStatistics(result: any): void { this.total_routes = result.total_routes; this.total_stops = result.total_stops; this.total_callins = result.total_callins; this.completed_routes = result.total_completed_routes; this.completed_stops = result.completed_stops; this.completed_callins = result.completed_callins; this.unassigned_routes = result.total_unassigned_routes; this.unassigned_stops = result.total_unassigned_stops; this.assigned_not_check_in = result.total_not_checkin; this.late_past_20 = result.total_twenty_minutes; this.late_past_30 = result.total_thirty_minutes; this.unassigned_routes_ids = result.unassigned_routes_ids; this.not_check_in_routes_ids = result.not_check_in_routes_ids; this.completed_route_ids = result.completed_route_ids; this.unassigned_stop_ids = result.unassigned_stop_ids; this.completed_stops_id = result.completed_stop_ids; this.completed_call_in_stops_ids = result.completed_willcalls_ids; this.late20_route_ids = result.late20_route_ids; this.late30_route_ids = result.late30_route_ids; this.total_unassigned_willcalls = result.total_unassigned_willcalls; this.unassigned_willcallIds = result.unassigned_willcall_ids; this.incidentIds = result.incident; } ngOnChanges(): void { } clearFilter(): void { $('.filter-right').removeClass('active'); this.getParentComponent().filters.routeIds = []; this.active_unassigned = false; this.active_completedroutes = false; this.active_notcheckin = false; // this.getParentComponent().filterRoutes(); } filterKPI(boxType: string, obj: any): void { this.getParentComponent().filters.orderType = []; this.getParentComponent().filters.managerIds =[]; this.getParentComponent().filters.routeTypeIds = []; // localStorage.removeItem('selectedRouteTypeIds'); // localStorage.removeItem('selectedManagerIds'); $('.filter-right').removeClass('active'); this.getParentComponent().kpiClick = false; switch (boxType) { case 'UNASSIGNED_ROUTES': this.active_completedroutes = false; this.active_notcheckin = false; this.active_late20 = false; this.active_late30 = false; this.active_unassignedwillcalls = false; this.active_completedStops = false; this.active_completedWillCalls = false; this.active_incidents = false; this.getParentComponent().staticTabs.tabs[0].active = true; if(this.unassigned_routes > 0) { if(this.active_unassigned == false) { $('.filter-right-routes-unassigned').addClass('active'); this.getParentComponent().filters.routeIds = this.unassigned_routes_ids; this.getParentComponent().filterRoutes(); this.active_unassigned = true; } else { this.active_unassigned = false; this.getParentComponent().filters.routeIds = []; this.getParentComponent().filterRoutes(); } this.getParentComponent().staticTabs.tabs[0].active = true; } break; case 'UNASSIGNED_WILLCALL': this.active_completedroutes = false; this.active_notcheckin = false; this.active_late20 = false; this.active_late30 = false; this.active_completedStops = false; this.active_completedWillCalls = false; this.active_incidents = false; this.active_unassigned = false; this.getParentComponent().staticTabs.tabs[0].active = false; if(this.total_unassigned_willcalls > 0) { if(this.active_unassignedwillcalls == false) { $('.filter-right-routes-unassigned-willcalls').addClass('active'); this.getParentComponent().filters.orderIds = this.unassigned_willcallIds; this.getParentComponent().loadOrderListComponent(); this.active_unassignedwillcalls = true; } else { this.active_unassignedwillcalls = false; this.getParentComponent().filters.orderIds = undefined; this.getParentComponent().loadOrderListComponent(); } this.getParentComponent().staticTabs.tabs[1].active = true; } break; case 'COMPLETED_STOPS': this.active_completedroutes = false; this.active_notcheckin = false; this.active_late20 = false; this.active_late30 = false; this.active_unassignedwillcalls = false; this.active_completedWillCalls = false; this.active_incidents = false; this.active_unassigned = false; this.getParentComponent().staticTabs.tabs[0].active = false; if(this.total_stops > 0) { if(this.active_completedStops == false) { $('.filter-right-completed-stops').addClass('active'); this.getParentComponent().filters.orderIds = this.completed_stops_id; this.getParentComponent().loadOrderListComponent(); this.active_completedStops = true; } else { this.active_completedStops = false; this.getParentComponent().filters.orderIds = undefined; this.getParentComponent().loadOrderListComponent(); } this.getParentComponent().staticTabs.tabs[1].active = true; } break; case 'NOT_CHECK_IN': this.active_completedroutes = false; this.active_late20 = false; this.active_late30 = false; this.active_unassignedwillcalls = false; this.active_completedWillCalls = false; this.active_incidents = false; this.active_unassigned = false; this.active_completedStops = false; this.getParentComponent().staticTabs.tabs[0].active = true; if(this.assigned_not_check_in > 0) { if(this.active_notcheckin == false) { $('.filter-right-routes-notcheckin').addClass('active'); this.getParentComponent().filters.routeIds = this.not_check_in_routes_ids; this.getParentComponent().filterRoutes(); this.active_notcheckin = true; } else { this.getParentComponent().filters.routeIds = []; this.getParentComponent().filterRoutes(); this.active_notcheckin = false; } } break; case 'LATE_20': this.active_completedroutes = false; this.active_late30 = false; this.active_unassignedwillcalls = false; this.active_completedWillCalls = false; this.active_incidents = false; this.active_unassigned = false; this.active_completedStops = false; this.active_notcheckin = false; this.getParentComponent().staticTabs.tabs[0].active = true; if(this.late_past_20 > 0) { if(this.active_late20 == false) { $('.filter-right-routes-late20').addClass('active'); this.getParentComponent().filters.routeIds = this.late20_route_ids; this.getParentComponent().filterRoutes(); this.active_late20 = true; } else { this.getParentComponent().filters.routeIds = []; this.getParentComponent().filterRoutes(); this.active_late20 = false; } } break; case 'LATE_30': this.active_completedroutes = false; this.active_late20 = false; this.active_unassignedwillcalls = false; this.active_completedWillCalls = false; this.active_incidents = false; this.active_unassigned = false; this.active_completedStops = false; this.active_notcheckin = false; this.getParentComponent().staticTabs.tabs[0].active = true; if(this.late_past_30 > 0) { if(this.active_late30 == false) { $('.filter-right-routes-late30').addClass('active'); this.getParentComponent().filters.routeIds = this.late30_route_ids; this.getParentComponent().filterRoutes(); this.active_late30 = true; } else { this.getParentComponent().filters.routeIds = []; this.getParentComponent().filterRoutes(); this.active_late30 = false; } } break; case 'COMPLETED_ROUTES': this.active_late20 = false; this.active_late30 = false; this.active_unassignedwillcalls = false; this.active_completedWillCalls = false; this.active_incidents = false; this.active_unassigned = false; this.active_completedStops = false; this.active_notcheckin = false; this.getParentComponent().staticTabs.tabs[0].active = true; if(this.completed_routes > 0) { if(this.active_completedroutes == false) { $('.filter-right-routes-completed').addClass('active'); this.getParentComponent().filters.routeIds = this.completed_route_ids; this.getParentComponent().filters.completed = true; this.getParentComponent().filterRoutes(); this.active_completedroutes = true; } else { this.getParentComponent().filters.routeIds = []; this.getParentComponent().filters.completed = false; this.getParentComponent().filterRoutes(); this.active_completedroutes = false; } } break; case 'UNASSIGNED_ORDERS': // let data = this.unassigned_stop_ids; // this.getParentComponent().staticTabs.tabs[2].active = true; // this.getParentComponent().filters.orderIds = data; // this.getParentComponent().filterStops(data); if(this.getParentComponent().staticTabs.tabs[2].active == true){ this.getParentComponent().tOrderPackages.filters.unassignedStopsFilter = true this.getParentComponent().loadOrderPackagesListComponent('UNASSIGNED_ORDERS'); } else if(this.getParentComponent().staticTabs.tabs[1].active == true){ this.getParentComponent().tOrderComponents.filters.unassignedStopsFilter = true this.getParentComponent().loadOrderListComponent('UNASSIGNED_ORDERS'); } break; // case 'COMPLETED_STOPS': // // this.getParentComponent().staticTabs.tabs[2].active = true; // if(this.getParentComponent().staticTabs.tabs[2].active == true){ // this.getParentComponent().tOrderPackages.filters.orderStatusCode = 'DELIVERED' // this.getParentComponent().loadOrderPackagesListComponent('COMPLETED_STOPS'); // } // else if(this.getParentComponent().staticTabs.tabs[1].active == true){ // this.getParentComponent().tOrderComponents.filters.orderStatusCode = 'DELIVERED' // this.getParentComponent().loadOrderListComponent('COMPLETED_STOPS'); // } // // let dataCs = this.completed_stops_id; // // this.getParentComponent().staticTabs.tabs[2].active = true; // // this.getParentComponent().filters.orderIds = dataCs; // // this.getParentComponent().filterStops(dataCs); // break; case 'COMPLETED_CALLIN': this.active_completedroutes = false; this.active_notcheckin = false; this.active_late20 = false; this.active_late30 = false; this.active_unassignedwillcalls = false; this.active_incidents = false; this.active_unassigned = false; this.getParentComponent().staticTabs.tabs[0].active = false; if(this.total_stops > 0) { if(this.active_completedWillCalls == false) { $('.filter-right-willcall-completed').addClass('active'); this.getParentComponent().filters.orderIds = this.completed_call_in_stops_ids; this.getParentComponent().loadOrderListComponent(); this.active_completedWillCalls = true; } else { this.active_completedWillCalls = false; this.getParentComponent().filters.orderIds = undefined; this.getParentComponent().loadOrderListComponent(); } this.getParentComponent().staticTabs.tabs[1].active = true; } break; case 'INCIDENT': this.active_completedroutes = false; this.active_notcheckin = false; this.active_late20 = false; this.active_late30 = false; this.active_unassignedwillcalls = false; this.active_unassigned = false; this.active_completedWillCalls = false this.getParentComponent().staticTabs.tabs[0].active = false; if(this.total_stops > 0) { if(this.active_incidents == false) { $('.filter-right-incident').addClass('active'); this.getParentComponent().filters.orderIds = this.incidentIds; this.getParentComponent().loadOrderListComponent(); this.active_incidents = true; } else { this.active_incidents = false; this.getParentComponent().filters.orderIds = undefined; this.getParentComponent().loadOrderListComponent(); } this.getParentComponent().staticTabs.tabs[1].active = true; } break; // if(this.getParentComponent().staticTabs.tabs[2].active == true){ // this.getParentComponent().tOrderPackages.filters.willCallFilter = true // this.getParentComponent().loadOrderPackagesListComponent('COMPLETED_CALLIN'); // } // else if(this.getParentComponent().staticTabs.tabs[1].active == true){ // this.getParentComponent().tOrderComponents.filters.willCallFilter = true // this.getParentComponent().loadOrderListComponent('COMPLETED_CALLIN'); // } // break; default: this.getParentComponent().staticTabs.tabs[0].active = true; this.getParentComponent().filters.routeIds = []; this.getParentComponent().filterRoutes(); break; } this.getParentComponent().kpiClick = false; } }