import { Component, Injector, OnInit, ViewEncapsulation, ViewChild } from '@angular/core'; import { AppComponentBase } from '@shared/common/app-component-base'; import { appModuleAnimation } from '@shared/animations/routerTransition'; import * as moment from 'moment-timezone'; import { StatisticsServiceProxy, SLADto, SLAInput, LocationServiceProxy, SLAOrdersInput, ControllerKpiCountServiceProxy } from '@shared/service-proxies/service-proxies'; import { StatisticsModalComponent } from '@app/shared/common/lookup/statistics-modal.component'; import { TabsetComponent } from 'ngx-bootstrap'; import { database } from 'firebase'; @Component({ selector: 'app-statistics', templateUrl: './statistics-component.html', styleUrls: ['./statistics-component.less'], encapsulation: ViewEncapsulation.None, animations: [appModuleAnimation()] }) export class StatisticsComponent extends AppComponentBase { @ViewChild('StatisticsModalComponent', { static: true }) SLAModalComponent: StatisticsModalComponent; @ViewChild('SLATab', { static: false }) SLATab: TabsetComponent; slaDate: Date; dateContainer: any = []; dateData: any = {}; dataFields: any = [{ name: "Total packages set for delivery", id: 1 }, { name: "Packages not picked up", id: 2 }, { name: "Packages tendered", id: 3 }, { name: "Packages in transit", id: 4 }, { name: "Packages delivered", id: 5 }, { name: "Delivered on time", id: 6 }, { name: "Delivered late", id: 7 }, { name: "Latest delivery time", id: 8 }, { name: "Packages not delivered", id: 9 }, { name: "Percentage on time", id: 10 }, { name: "Packages with delivery issue", id: 11 }, { name: "Set for redelivery", id: 12 } ]; totalPackagesSetForDelivery: any = []; totalPackagesNotPickedUp: any = []; totalPackagesIntransit: any = []; totalPackagesDelivered: any = []; totalPackagesDeliveredOnTime: any = []; totalPackagesDeliveredLate: any = []; totalPackagesTendered: any = []; packagesNotDelivered: any = []; packagesWDeliveryIssue: any = []; packagesSetForRedelivery: any = []; latestDeliveryTime: any = []; percentageOnTime: any = []; getLocationNames: any = []; allLocation: boolean = true; locationId: number; loaderCtr: number = 0; lastRefresh: string; constructor( injector: Injector, private _slaService: StatisticsServiceProxy, private _locationServiceProxy: LocationServiceProxy, private _dispatch: ControllerKpiCountServiceProxy ) { super(injector); } ngOnInit() { this.loaderCtr++; this.spinnerService.show(); if (localStorage.getItem('SLADate') == null) { localStorage.setItem('SLADate', moment(Date.now()).format('MM/DD/YYYY')); this.slaDate = new Date(localStorage.getItem('SLADate')); } else { this.slaDate = new Date(localStorage.getItem('SLADate')); } let input = new SLAInput(); input.allLocation = this.allLocation; input.locationId = this.locationId; input.startDate = moment.tz(localStorage.getItem('SLADate'), localStorage.getItem('timeZoneId')); this.generateDate(); this.TotalPackagesSetForDelivery(input); this.TotalPackagesNotPickedUp(input); this.TotalPackagesIntransit(input); this.TotalPackagesDelivered(input); this.TotalPackagesDeliveredOnTime(input); this.TotalPackagesDeliveredLate(input); this.TotalPackagesTendered(input); this.PackagesNotDelivered(input); this.PackagesWDeliveryIssue(input); this.PackagesSetForRedelivery(input); this.LatestDeliveryTime(input); this.PercentageOnTime(input); this.Locations(); this.loaderCtr = this.loaderCtr - 1; this._dispatch.getRefreshTime(undefined).subscribe(result => { localStorage.setItem('statsLastRefresh', result); this.lastRefresh = result; if (this.loaderCtr == 0) { this.spinnerService.hide(); } }); if (localStorage.getItem('statsLastRefresh') != undefined) { this.lastRefresh = localStorage.getItem('statsLastRefresh'); } // this.SLATab.tabs[0].active = true; } statsRefresh() { // this._dispatch.getRefreshTime(undefined).subscribe(result =>{ // localStorage.setItem('statsLastRefresh', result); // this.lastRefresh = result; // }); this.ngOnInit(); } AllLocations() { this.loaderCtr++; this.spinnerService.show(); this.allLocation = true; let input = new SLAInput(); input.allLocation = this.allLocation; input.locationId = this.locationId; input.startDate = moment.tz(localStorage.getItem('SLADate'), localStorage.getItem('timeZoneId')); this.generateDate(); // this.TotalPackagesSetForDelivery(input); // this.TotalPackagesNotPickedUp(input); // this.TotalPackagesIntransit(input); // this.TotalPackagesDelivered(input); // this.TotalPackagesDeliveredOnTime(input); // this.TotalPackagesDeliveredLate(input); // this.TotalPackagesTendered(input); // this.PackagesNotDelivered(input); // this.PackagesWDeliveryIssue(input); // this.PackagesSetForRedelivery(input); // this.LatestDeliveryTime(input); // this.PercentageOnTime(input); this.SLAData(input); this.loaderCtr = this.loaderCtr - 1; } SelectedLocation(data: any) { this.loaderCtr++; this.spinnerService.show(); this.allLocation = false; this.locationId = data; let input = new SLAInput(); input.allLocation = this.allLocation; input.locationId = this.locationId; input.startDate = moment.tz(localStorage.getItem('SLADate'), localStorage.getItem('timeZoneId')); this.generateDate(); // this.TotalPackagesSetForDelivery(input); // this.TotalPackagesNotPickedUp(input); // this.TotalPackagesIntransit(input); // this.TotalPackagesDelivered(input); // this.TotalPackagesDeliveredOnTime(input); // this.TotalPackagesDeliveredLate(input); // this.TotalPackagesTendered(input); // this.PackagesNotDelivered(input); // this.PackagesWDeliveryIssue(input); // this.PackagesSetForRedelivery(input); // this.LatestDeliveryTime(input); // this.PercentageOnTime(input); this.SLAData(input); this.loaderCtr = this.loaderCtr - 1; if (this.loaderCtr == 0) { this.spinnerService.hide(); } } onValueChange(value: Date): void { this.loaderCtr++; this.spinnerService.show(); let input = new SLAInput(); input.allLocation = this.allLocation; input.locationId = this.locationId; //set date localStorage.setItem('SLADate', moment.tz(value.toDateString(), localStorage.getItem('timeZoneId')).format('MM/DD/YYYY')); input.startDate = moment.tz(localStorage.getItem('SLADate'), localStorage.getItem('timeZoneId')); this.slaDate = value; this.generateDate(); // this.TotalPackagesSetForDelivery(input); // this.TotalPackagesNotPickedUp(input); // this.TotalPackagesIntransit(input); // this.TotalPackagesDelivered(input); // this.TotalPackagesDeliveredOnTime(input); // this.TotalPackagesDeliveredLate(input); // this.TotalPackagesTendered(input); // this.PackagesNotDelivered(input); // this.PackagesWDeliveryIssue(input); // this.PackagesSetForRedelivery(input); // this.LatestDeliveryTime(input); // this.PercentageOnTime(input); this.SLAData(input); this.loaderCtr = this.loaderCtr - 1; if (this.loaderCtr == 0) { this.spinnerService.hide(); } this._dispatch.getRefreshTime(undefined).subscribe(result => { localStorage.setItem('statsLastRefresh', result); this.lastRefresh = result; if (this.loaderCtr == 0) { this.spinnerService.hide(); } }); this.SLATab.tabs[0].active = true; } generateDate() { this.dateContainer = []; if (localStorage.getItem('SLADate') !== null) { for (let index = 0; index < 7; index++) { var end = moment(localStorage.getItem('SLADate'), "MM/DD/YYYY").add(index, 'days'); this.dateData.date = end.format("MM/DD/YYYY"); this.dateData.day = end.day(); this.dateContainer.push({ loadDate: end, slaDate: end.format("MM/DD/YYYY"), month: end.format("MMM"), dateInt: end.format("D"), date: end.format("dddd"), day: end.day() }); } } } SLAData(data: SLAInput) { this.loaderCtr++; data.allLocation = this.allLocation; data.locationId = this.locationId; data.startDate = moment.tz(localStorage.getItem('SLADate'), localStorage.getItem('timeZoneId')); this._slaService.totalPackagesSetForDelivery(data).subscribe(result => { this.totalPackagesSetForDelivery = result; this._slaService.totalPackagesNotPickedUp(data).subscribe(result => { this.totalPackagesNotPickedUp = result; this._slaService.totalPackagesIntransit(data).subscribe(result => { this.totalPackagesIntransit = result; this._slaService.totalPackagesDelivered(data).subscribe(result => { this.totalPackagesDelivered = result; this._slaService.totalPackagesDeliveredOnTime(data).subscribe(result => { this.totalPackagesDeliveredOnTime = result; this._slaService.totalPackagesDeliveredLate(data).subscribe(result => { this.totalPackagesDeliveredLate = result; this._slaService.totalPackagesTendered(data).subscribe(result => { this.totalPackagesTendered = result; this._slaService.packagesNotDelivered(data).subscribe(result => { this.packagesNotDelivered = result; this._slaService.packagesWDeliveryIssue(data).subscribe(result => { this.packagesWDeliveryIssue = result; this._slaService.totalPackagesSetForDelivery(data).subscribe(result => { this.totalPackagesSetForDelivery = result; this._slaService.totalPackagesNotPickedUp(data).subscribe(result => { this.totalPackagesNotPickedUp = result; this._slaService.totalPackagesIntransit(data).subscribe(result => { this.totalPackagesIntransit = result; this.loaderCtr = this.loaderCtr - 1; if (this.loaderCtr == 0) { this.spinnerService.hide(); } }); // this.loaderCtr = this.loaderCtr - 1; // if (this.loaderCtr == 0) { // this.spinnerService.hide(); // } }); // this.loaderCtr = this.loaderCtr - 1; // if (this.loaderCtr == 0) { // this.spinnerService.hide(); // } }); // this.loaderCtr = this.loaderCtr - 1; // if (this.loaderCtr == 0) { // this.spinnerService.hide(); // } }); // this.loaderCtr = this.loaderCtr - 1; // if (this.loaderCtr == 0) { // this.spinnerService.hide(); // } }); // this.loaderCtr = this.loaderCtr - 1; // if (this.loaderCtr == 0) { // this.spinnerService.hide(); // } }); // this.loaderCtr = this.loaderCtr - 1; // if (this.loaderCtr == 0) { // this.spinnerService.hide(); // } }); // this.loaderCtr = this.loaderCtr - 1; // if (this.loaderCtr == 0) { // this.spinnerService.hide(); // } }); // this.loaderCtr = this.loaderCtr - 1; // if (this.loaderCtr == 0) { // this.spinnerService.hide(); // } }); // this.loaderCtr = this.loaderCtr - 1; // if (this.loaderCtr == 0) { // this.spinnerService.hide(); // } }); // this.loaderCtr = this.loaderCtr - 1; // if (this.loaderCtr == 0) { // this.spinnerService.hide(); // } }); // this.loaderCtr = this.loaderCtr - 1; // if (this.loaderCtr == 0) { // this.spinnerService.hide(); // } }); } TotalPackagesSetForDelivery(data: SLAInput) { this.loaderCtr++; data.allLocation = this.allLocation; data.locationId = this.locationId; data.startDate = moment.tz(localStorage.getItem('SLADate'), localStorage.getItem('timeZoneId')); this._slaService.totalPackagesSetForDelivery(data).subscribe(result => { this.totalPackagesSetForDelivery = result; this.loaderCtr = this.loaderCtr - 1; if (this.loaderCtr == 0) { this.spinnerService.hide(); } }); } TotalPackagesNotPickedUp(data: SLAInput) { this.loaderCtr++; data.allLocation = this.allLocation; data.locationId = this.locationId; data.startDate = moment.tz(localStorage.getItem('SLADate'), localStorage.getItem('timeZoneId')); this._slaService.totalPackagesNotPickedUp(data).subscribe(result => { this.totalPackagesNotPickedUp = result; this.loaderCtr = this.loaderCtr - 1; if (this.loaderCtr == 0) { this.spinnerService.hide(); } }); } TotalPackagesIntransit(data: SLAInput) { this.loaderCtr++; data.allLocation = this.allLocation; data.locationId = this.locationId; data.startDate = moment.tz(localStorage.getItem('SLADate'), localStorage.getItem('timeZoneId')); this._slaService.totalPackagesIntransit(data).subscribe(result => { this.totalPackagesIntransit = result; this.loaderCtr = this.loaderCtr - 1; if (this.loaderCtr == 0) { this.spinnerService.hide(); } }); } TotalPackagesDelivered(data: SLAInput) { this.loaderCtr++; data.allLocation = this.allLocation; data.locationId = this.locationId; data.startDate = moment.tz(localStorage.getItem('SLADate'), localStorage.getItem('timeZoneId')); this._slaService.totalPackagesDelivered(data).subscribe(result => { this.totalPackagesDelivered = result; this.loaderCtr = this.loaderCtr - 1; if (this.loaderCtr == 0) { this.spinnerService.hide(); } }); } TotalPackagesDeliveredOnTime(data: SLAInput) { this.loaderCtr++; data.allLocation = this.allLocation; data.locationId = this.locationId; data.startDate = moment.tz(localStorage.getItem('SLADate'), localStorage.getItem('timeZoneId')); this._slaService.totalPackagesDeliveredOnTime(data).subscribe(result => { this.totalPackagesDeliveredOnTime = result; this.loaderCtr = this.loaderCtr - 1; if (this.loaderCtr == 0) { this.spinnerService.hide(); } }); } TotalPackagesDeliveredLate(data: SLAInput) { this.loaderCtr++; data.allLocation = this.allLocation; data.locationId = this.locationId; data.startDate = moment.tz(localStorage.getItem('SLADate'), localStorage.getItem('timeZoneId')); this._slaService.totalPackagesDeliveredLate(data).subscribe(result => { this.totalPackagesDeliveredLate = result; this.loaderCtr = this.loaderCtr - 1; if (this.loaderCtr == 0) { this.spinnerService.hide(); } }); } TotalPackagesTendered(data: SLAInput) { this.loaderCtr++; data.allLocation = this.allLocation; data.locationId = this.locationId; data.startDate = moment.tz(localStorage.getItem('SLADate'), localStorage.getItem('timeZoneId')); this._slaService.totalPackagesTendered(data).subscribe(result => { this.totalPackagesTendered = result; this.loaderCtr = this.loaderCtr - 1; if (this.loaderCtr == 0) { this.spinnerService.hide(); } }); } PackagesNotDelivered(data: SLAInput) { this.loaderCtr++; data.allLocation = this.allLocation; data.locationId = this.locationId; data.startDate = moment.tz(localStorage.getItem('SLADate'), localStorage.getItem('timeZoneId')); this._slaService.packagesNotDelivered(data).subscribe(result => { this.packagesNotDelivered = result; this.loaderCtr = this.loaderCtr - 1; if (this.loaderCtr == 0) { this.spinnerService.hide(); } }); } PackagesWDeliveryIssue(data: SLAInput) { this.loaderCtr++; data.allLocation = this.allLocation; data.locationId = this.locationId; data.startDate = moment.tz(localStorage.getItem('SLADate'), localStorage.getItem('timeZoneId')); this._slaService.packagesWDeliveryIssue(data).subscribe(result => { this.packagesWDeliveryIssue = result; this.loaderCtr = this.loaderCtr - 1; if (this.loaderCtr == 0) { this.spinnerService.hide(); } }); } PackagesSetForRedelivery(data: SLAInput) { this.loaderCtr++; data.allLocation = this.allLocation; data.locationId = this.locationId; data.startDate = moment.tz(localStorage.getItem('SLADate'), localStorage.getItem('timeZoneId')); this._slaService.packagesSetForRedelivery(data).subscribe(result => { this.packagesSetForRedelivery = result; this.loaderCtr = this.loaderCtr - 1; if (this.loaderCtr == 0) { this.spinnerService.hide(); } }); } LatestDeliveryTime(data: SLAInput) { this.loaderCtr++; data.allLocation = this.allLocation; data.locationId = this.locationId; data.startDate = moment.tz(localStorage.getItem('SLADate'), localStorage.getItem('timeZoneId')); this._slaService.latestDeliveryTime(data).subscribe(result => { this.latestDeliveryTime = result; this.loaderCtr = this.loaderCtr - 1; if (this.loaderCtr == 0) { this.spinnerService.hide(); } }); } PercentageOnTime(data: SLAInput) { this.loaderCtr++; data.allLocation = this.allLocation; data.locationId = this.locationId; data.startDate = moment.tz(localStorage.getItem('SLADate'), localStorage.getItem('timeZoneId')); this._slaService.percentageOnTime(data).subscribe(result => { this.percentageOnTime = result; this.loaderCtr = this.loaderCtr - 1; if (this.loaderCtr == 0) { this.spinnerService.hide(); } }); } Locations() { this.loaderCtr++; this._locationServiceProxy.getLocationNames(undefined, undefined, undefined, undefined, undefined, undefined).subscribe(result => { this.getLocationNames = result; this.loaderCtr = this.loaderCtr - 1; if (this.loaderCtr == 0) { this.spinnerService.hide(); } }); } OrdersNotPickedUp(data: any, date: string, day: string) { this.SLAModalComponent.configure({ title: this.l('Packages not picked up'), subtitle: this.l(date + ' - ' + day), dataSource: (skipCount: number, maxResultCount: number, filter: string, tenantId?: number) => { let input = new SLAOrdersInput(); input.filter = filter; input.maxResultCount = maxResultCount; input.skipCount = skipCount; input.allLocation = this.allLocation; input.locationId = this.locationId; input.loadDate = data; return this._slaService.ordersNotPickedUp(input); } }); this.SLAModalComponent.show(); } OrdersIntransit(data: any, date: string, day: string) { this.SLAModalComponent.configure({ title: this.l('Packages in transit'), subtitle: this.l(date + ' - ' + day), dataSource: (skipCount: number, maxResultCount: number, filter: string, tenantId?: number) => { let input = new SLAOrdersInput(); input.filter = filter; input.maxResultCount = maxResultCount; input.skipCount = skipCount; input.allLocation = this.allLocation; input.locationId = this.locationId; input.loadDate = data; return this._slaService.ordersIntransit(input); } }); this.SLAModalComponent.show(); } OrdersLate(data: any, date: string, day: string) { this.SLAModalComponent.configure({ title: this.l('Delivered late'), subtitle: this.l(date + ' - ' + day), dataSource: (skipCount: number, maxResultCount: number, filter: string, tenantId?: number) => { let input = new SLAOrdersInput(); input.filter = filter; input.maxResultCount = maxResultCount; input.skipCount = skipCount; input.allLocation = this.allLocation; input.locationId = this.locationId; input.loadDate = data; return this._slaService.ordersLate(input); } }); this.SLAModalComponent.show(); } OrdersNotDelivered(data: any, date: string, day: string) { this.SLAModalComponent.configure({ title: this.l('Packages not delivered'), subtitle: this.l(date + ' - ' + day), dataSource: (skipCount: number, maxResultCount: number, filter: string, tenantId?: number) => { let input = new SLAOrdersInput(); input.filter = filter; input.maxResultCount = maxResultCount; input.skipCount = skipCount; input.allLocation = this.allLocation; input.locationId = this.locationId; input.loadDate = data; return this._slaService.ordersNotDelivered(input); } }); this.SLAModalComponent.show(); } TotalOrdersNotPickedUp() { this.SLAModalComponent.configure({ title: this.l('Total packages not picked up'), dataSource: (skipCount: number, maxResultCount: number, filter: string, tenantId?: number) => { let input = new SLAOrdersInput(); input.filter = filter; input.maxResultCount = maxResultCount; input.skipCount = skipCount; input.allLocation = this.allLocation; input.locationId = this.locationId; input.loadDate = moment.tz(localStorage.getItem('SLADate'), localStorage.getItem('timeZoneId'));; return this._slaService.totalOrdersNotPickedUp(input); } }); this.SLAModalComponent.show(); } TotalOrdersIntransit() { this.SLAModalComponent.configure({ title: this.l('Total packages in transit'), dataSource: (skipCount: number, maxResultCount: number, filter: string, tenantId?: number) => { let input = new SLAOrdersInput(); input.filter = filter; input.maxResultCount = maxResultCount; input.skipCount = skipCount; input.allLocation = this.allLocation; input.locationId = this.locationId; input.loadDate = moment.tz(localStorage.getItem('SLADate'), localStorage.getItem('timeZoneId'));; return this._slaService.totalOrdersIntransit(input); } }); this.SLAModalComponent.show(); } TotalOrdersLate() { this.SLAModalComponent.configure({ title: this.l('Total packages delivered late'), dataSource: (skipCount: number, maxResultCount: number, filter: string, tenantId?: number) => { let input = new SLAOrdersInput(); input.filter = filter; input.maxResultCount = maxResultCount; input.skipCount = skipCount; input.allLocation = this.allLocation; input.locationId = this.locationId; input.loadDate = moment.tz(localStorage.getItem('SLADate'), localStorage.getItem('timeZoneId'));; return this._slaService.totalOrdersLate(input); } }); this.SLAModalComponent.show(); } TotalOrdersNotDelivered() { this.SLAModalComponent.configure({ title: this.l('Total packages not delivered'), dataSource: (skipCount: number, maxResultCount: number, filter: string, tenantId?: number) => { let input = new SLAOrdersInput(); input.filter = filter; input.maxResultCount = maxResultCount; input.skipCount = skipCount; input.allLocation = this.allLocation; input.locationId = this.locationId; input.loadDate = moment.tz(localStorage.getItem('SLADate'), localStorage.getItem('timeZoneId'));; return this._slaService.totalOrdersNotDelivered(input); } }); this.SLAModalComponent.show(); } }