import { Component, Injector, OnInit, ViewChild, ViewEncapsulation, ElementRef, AfterViewInit, Renderer, Input, EventEmitter } from '@angular/core'; import { ActivatedRoute, Route, Router } from '@angular/router'; import { AppConsts } from '@shared/AppConsts'; import { CommonModule, Location } from '@angular/common'; import { AppAuthService } from '@app/shared/common/auth/app-auth.service'; import { appModuleAnimation } from '@shared/animations/routerTransition'; import { AppComponentBase } from '@shared/common/app-component-base'; import { RouteListDto, RouteServiceProxy, LocationListDto, LocationServiceProxy, ControllerRouteServiceProxy, GenerateInputDto, AddressAddressTypeLookupTableDto, ProfileServiceProxy, CurrentUserProfileEditDto, LocationNameDto, ControllerKpiCountServiceProxy, ControllerRouteDetailServiceProxy, PreferencesServiceProxy, UserPreferencesServiceProxy, CreateOrEditPreferenceDto, CreateOrEditUserPreferenceDto, UserPreferenceInput, GetLocationLockDto, ShippingPackageServiceProxy, ControllerPrintRouteSheetServiceProxy, RouteDefinitionListInput, NameValueDto, CreateNewRouteInput, OrderTypesServiceProxy, ContainersServiceProxy } 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 _ from 'lodash'; import { TabsetComponent } from 'ngx-bootstrap'; /**** STANDARD ****/ import { DispatchDetailsComponents } from '@app/sprintship/controller/dispatch/dispatch-details.component'; import { DispatchDetailsGroupComponents } from '@app/sprintship/controller/dispatch/dispatch-details.group.component'; /**** SHARED COMPONENTS ****/ import { TimerComponent } from '@app/sprintship/core-components/timer/timer.component'; import { ControllerRoutesService } from '@app/sprintship/controller/routes/croutes.service'; import { DriverListTabComponent } from '@app/sprintship/controller/drivers/driver-list.component'; import { KPIBoxComponent } from '@app/sprintship/controller/kpi-box/kpi-box.component'; import { KpiLaboratoryComponent } from '@app/sprintship/controller/kpi-box/kpi-laboratory/kpi-laboratory.component'; import { VehicleListTabComponent } from '@app/sprintship/controller/vehicles/vehicle-list.component'; import { AppSessionService } from '@shared/common/session/app-session.service'; import { GenerateRoutesTrackingComponent } from './generate-routes-tracking.component'; import { interval, Subscription } from 'rxjs'; import { map } from 'rxjs/operators' import * as signalR from '@aspnet/signalr'; import { OrderListTabComponent } from '../orders/order-list.component'; import * as controller_table_settings from '@app/sprintship/controller/core-components/controller-table-settings.json'; import { OrderPackagesComponent } from '@app/sprintship/order-management/order-package-rad/orderPackages.component'; import { ControllerOrderPackagesComponent } from '../order-packages/order-packages-list.component'; import { TimerService } from '@app/sprintship/core-components/timer/timer.service'; import { CallBackModalComponent } from '@app/sprintship/controller/modals/call_back_modal.component'; import { CallInModalComponent } from '@app/sprintship/controller/modals/call_in_modal.component'; import { ControllerOrderIncidentsComponent } from '../order-incident/order-incident-list.component'; import { ControllerHeaderFlyoutComponent } from '@app/shared/layout/flyout/controller-header/controller-header-flyout.component'; import { NoDataComponent } from '@app/sprintship/controller/routes/nodata.component' import { RouteDetailModal } from '@app/sprintship/controller/route-detail/route-detail-modal.component'; import { XmlHttpRequestHelper } from '@shared/helpers/XmlHttpRequestHelper'; // import { CallBackModalComponent } from '@app/sprintship/controller/modals/call_back_modal.component'; // import { CallInModalComponent } from '@app/sprintship/controller/modals/call_in_modal.component'; import { FileDownloadService } from '@shared/utils/file-download.service'; import { ImportRouteScheduleTracking } from '@app/main/laboratory/clinics/route-schedule-import-tracking'; import { FileUpload } from 'primeng/fileupload'; import { result } from 'lodash'; import { UnlockModalComponent } from '@app/sprintship/controller/modals/unlock-modal.component'; import { LockModalComponent } from '@app/sprintship/controller/modals/lock-modal.component'; import { ProgressBarService } from '@app/shared/layout/progressbar/progressbar.service'; import { CommonLookupModalComponent } from '@app/shared/common/lookup/common-lookup-modal.component'; import { CreateNewRouteModalComponent } from './create-route-modal.component'; import { OrderGroupListTabComponent } from '../orders/order-list-group.component'; import { ControllerOrderPackagesGroupComponent } from '../order-packages/order-packages-group.component'; import { ControllerOrderIncidentsGroupComponent } from '../order-incident/order-incident-list-group.component'; import { Output } from '@angular/core'; import { ValueTransformer } from '@angular/compiler/src/util'; declare var $: any; declare var jquery: any; @Component({ selector: 'controller-main', templateUrl: 'croutes.component.html', encapsulation: ViewEncapsulation.None, styleUrls: ['./croutes.component.less'], animations: [appModuleAnimation()], providers: [ControllerRoutesService, TimerService] }) export class CRoutesComponent extends AppComponentBase implements OnInit { private hubConnection: signalR.HubConnection private importConnection: signalR.HubConnection /***** PAGES *****/ @ViewChild('routeDetailModal', { static: true }) routeDetailModal: RouteDetailModal; @ViewChild('controllerTab', { static: false }) staticTabs: TabsetComponent; @ViewChild('controllerTab', { read: ElementRef, static: true }) cRef: ElementRef; @ViewChild('controllerHeader', { read: ElementRef, static: true }) cHeader: ElementRef; @ViewChild('timerComponent', { static: false }) timerComponent: TimerComponent; /***** COMPONENTS *****/ @ViewChild(DriverListTabComponent, { static: false }) driverTab: DriverListTabComponent; @ViewChild(VehicleListTabComponent, { static: false }) vehicleTab: VehicleListTabComponent; @ViewChild(OrderListTabComponent, { static: false }) tOrderComponents: OrderListTabComponent; @ViewChild(OrderGroupListTabComponent, { static: false }) tOrderGroupComponents: OrderGroupListTabComponent; @ViewChild(ControllerOrderPackagesGroupComponent, { static: false }) tOrderPackageGroupComponents: ControllerOrderPackagesGroupComponent; @ViewChild(KPIBoxComponent, { static: false }) tKpiComponents: KPIBoxComponent; @ViewChild(ControllerOrderPackagesComponent, { static: false }) tOrderPackages: ControllerOrderPackagesComponent; @ViewChild(ControllerOrderIncidentsComponent, { static: false }) tOrderIncidents: ControllerOrderIncidentsComponent; @ViewChild(ControllerOrderIncidentsGroupComponent, { static: false }) tOrderIncidentsGroup: ControllerOrderIncidentsGroupComponent; /***** MODAL *****/ /***** STANDARD *****/ @ViewChild(DispatchDetailsComponents, { static: false }) dispatchDetailsComponent: DispatchDetailsComponents; @ViewChild(DispatchDetailsGroupComponents, { static: false }) dispatchDetailsGroupComponent: DispatchDetailsGroupComponents; /***** LABORATORY *****/ @ViewChild(KpiLaboratoryComponent, { static: false }) kpiLabComponent: KpiLaboratoryComponent; /***** EXTRAS *****/ @ViewChild('controllerHeaderFlyoutComponent', { static: false }) controllerHeaderFlyoutComponent: ControllerHeaderFlyoutComponent; @ViewChild('noDataComponent', { static: false }) noDataComponent: NoDataComponent; @ViewChild('dr', { static: false }) dr: ElementRef; // @ViewChild('columnChooser', { // static: false // }) columnChooser: ControllerShowHideComponent; @ViewChild('generateRoutesTracking', { static: false }) generateRoutesTracking: GenerateRoutesTrackingComponent; // importing @ViewChild('importRouteScheduleTracking', { static: false }) importRouteScheduleTracking: ImportRouteScheduleTracking; @ViewChild('ExcelFileUpload', { static: true }) excelFileUpload: FileUpload; @ViewChild('unlockModal', { static: true }) unlockModal: UnlockModalComponent; @ViewChild('lockModal', { static: true }) lockModal: LockModalComponent; @Input() LineHaulFilter: boolean; @Output() emitFunctionOfParent: EventEmitter = new EventEmitter(); isEnabledLaboratory: boolean = false; controller_edition_type: string = 'STANDARD'; updateProfile: CurrentUserProfileEditDto = new CurrentUserProfileEditDto; userPreferenceInput: UserPreferenceInput = new UserPreferenceInput; locations: LocationNameDto[] = []; hide: boolean = true; hide_menu: boolean = true; key: number; tblMain: any; todaysDate: string; event: LazyLoadEvent; generateEnable: boolean; timerVar: any; completed: boolean; fRouteName: string; statistics: any; lastRefresh: string; timerInterval: string; KPIfilters: { unassignedWillCalls: any, completeWillCalls: any, completeStops: any, } = {}; filters: { locationFilter: number, locationIds: number[], statusFilter: number, typeFilter: number, startDate: moment.Moment, endDate: moment.Moment, orderStatusCode: string, filterTxt: string, routeId: string, routeName: string, vehicleName: string, driverName: string, completed: boolean, orderType: Array, osName: string, routeIds: Array, orderIds: Array, managerIds: Array, routeTypeIds: Array, unassignedStopsFilter: boolean, orderKPIFilter: string, vehicleIds: Array, isLineHaul: boolean, locationName: string } = {}; search_string: string; txtFilter: string; allowed_dispatch: string = 'ALLOWED'; statusLocatorComponent: boolean = false; locationNames: string; orderPackageListComponent: boolean = false; orderIncidentListComponent: boolean = false; orderListComponent: boolean = false; heightTemp: string; advancedFiltersAreShown: boolean = false; inputs: { locationId: number; loadDate: moment.Moment; } = {}; subscription: Subscription; searchFilters: { route: string, vehicleName: string, driverName: string, showCompletion: boolean, routeIds: Array, orderType: Array, deviceType: string, } = {}; userProfile: { name: string, surname: string, userName: string, emailAddress: string, phoneNumber: string, isPhoneNumberConfirmed: boolean, timezone: string, qrCodeSetupImageUrl: string, isGoogleAuthenticatorEnabled: boolean } = {}; testDate: string; currentRoutes: any; noLocation: boolean; isShowToday: boolean = false; @Input('edition_name') edition: string; localRouteIds = []; orderIds = []; kpiClick: boolean; filterType: string; groupGridBy: string; tabdisable: boolean; firstload: boolean; afterLoad: boolean = false; uploadUrl: string; importRouteScheduleImpoting: boolean = false; inputUserPreferences: CreateOrEditUserPreferenceDto = new CreateOrEditUserPreferenceDto(); inputPreferences: CreateOrEditPreferenceDto = new CreateOrEditPreferenceDto(); haveLoadDate: boolean = false; haveLocation: boolean = false; haveThreshold: boolean = false; lockOrUnlockLocation: boolean; lockOrUnlockLocationDetails: GetLocationLockDto = new GetLocationLockDto(); packages: Array<{ id: number, name: string, color: string }> = new Array(); containers: Array<{ id: number, name: string, color: string }> = new Array(); routeCode: string; @ViewChild('routeList', { static: true }) routeList: CreateNewRouteModalComponent; driverThresholdInLocation: any; filteredOrderType: any; selectedLocationId: number; locationIds: any; locationTabs: any; isMultipleLocation: boolean; tab: string; constructor( injector: Injector, private _controllerRouteService: ControllerRouteServiceProxy, private _locationServiceProxy: LocationServiceProxy, private _routeService: RouteServiceProxy, private _cRoutesService: ControllerRoutesService, private elem: ElementRef, private router: Router, private _authService: AppAuthService, private _controllerRouteDetailService: ControllerRouteDetailServiceProxy, private _preferencesService: PreferencesServiceProxy, private _userPreferencesService: UserPreferencesServiceProxy, private _controllerRoutePackages: ShippingPackageServiceProxy, private _controllerPrintRouteDetails: ControllerPrintRouteSheetServiceProxy, private _orderTypeRepository: OrderTypesServiceProxy, private _progressBar: ProgressBarService, private _controllerRouteContainers: ContainersServiceProxy, private _activatedRoute: ActivatedRoute ) { super(injector); } public _construct() { this.kpiClick = false; this.noLocation = false; this.lastRefresh = 'N/A'; let timeId = localStorage.getItem('timeZoneId'); if (sessionStorage.getItem('last-refresh') != null) { this.lastRefresh = sessionStorage.getItem('last-refresh'); } // this.timerInterval = '900000'; // if (sessionStorage.getItem('timer-interval') == null) { // sessionStorage.setItem('timer-interval', this.timerInterval); // } $('#kpiToggleLink').html('Show KPI'); if (abp.auth.isGranted('Pages.Shipping.Controller') === false) { this.allowed_dispatch = 'NOT_ALLOWED'; this.router.navigate(['/app/sprintship/not-allowed']) } else { this.allowed_dispatch = 'ALLOWED'; this.generateEnable = false; this.isEnabledLaboratory = abp.features.isEnabled('App.ControllerRouteManagementFeature.RouteDetailsManagementFeature'); if (this.isEnabledLaboratory) { this.controller_edition_type = 'LABORATORY'; } this.edition = this.controller_edition_type; // this.currentRoutes = this.router.url; this.currentRoutes = location.pathname; this.currentRoutes = this.currentRoutes.toString().split('/'); this.currentRoutes = this.currentRoutes[this.currentRoutes.length - 1]; this.todaysDate = moment.tz(Date.now(), timeId).format('MM/DD/YYYY'); if (localStorage.getItem('loadDate') == null) { this.todaysDate = moment.tz(Date.now(), timeId).format('MM/DD/YYYY'); localStorage.setItem('loadDate', this.todaysDate); } if (localStorage.getItem('showEmptyRoute') == null) { localStorage.setItem('showEmptyRoute', "false"); } if (localStorage.getItem('showCompleted') == null) { localStorage.setItem('showCompleted', "false"); } } this._cRoutesService.StatisticsObj.subscribe(result => { this.statistics = result; if (this.edition === 'LABORATORY') { this.statistics = result; this.kpiLabComponent.getStatistics(result); } else if (this.edition === 'STANDARD') { this.statistics = result; this.tKpiComponents.getStatisticsStandard(result); } }); var that = this; if (localStorage.getItem('groupGridBy') == null) { localStorage.setItem('groupGridBy', 'None'); } if (this.edition == 'STANDARD') { localStorage.setItem('groupGridBy', 'None'); } this.groupGridBy = localStorage.getItem('groupGridBy'); this.importRouteScheduleImpoting = abp.features.isEnabled('App.OrderImporting'); this.uploadUrl = AppConsts.remoteServiceBaseUrl + '/Import/ImportFromExcel'; this.getPackages(); this.getContainers(); } refreshIntervalTimer() { return null; } enableAll() { $('.controllerSearchFilter').css('visibility', 'visible'); this.tabdisable = false; } disableAll() { $('.controllerSearchFilter').css('visibility', 'hidden'); this.tabdisable = true; } hideKpi(): void { if (this.hide == true) { this.hide = false; $('#kpiToggleIcon').removeClass('fa-eye-slash'); $('#kpiToggleIcon').addClass('fa-eye'); $('#kpiIndicator').html('Show KPI'); } else { this.hide = true; $('#kpiToggleIcon').addClass('fa-eye-slash'); $('#kpiToggleIcon').removeClass('fa-eye'); $('#kpiIndicator').html('Hide KPI'); } } hideKpiDropdown(): void { if (this.hide == true) { this.hide = false; $('#kpiToggleLink').html('Show KPI'); } else { this.hide = true; $('#kpiToggleLink').html('Hide KPI'); } } hideMenu(): void { if (this.hide_menu == true) { $('.dropdown-controller-menu').css('display', 'block'); this.hide_menu = false; } else { $('.dropdown-controller-menu').css('display', 'none'); this.hide_menu = true; } } ngOnInit(): void { // this.LineHaulFilter = (this._activatedRoute.snapshot.queryParams['isLinehaul'] == 'true')? true: false; // this._activatedRoute.paramMap.subscribe(p => { // this.tab = p.get('type') // this.LineHaulFilter = this.tab == 'linehaul' ? true : false; // }); this._construct(); let timeId = localStorage.getItem('timeZoneId'); moment.tz.setDefault(timeId); let that = this; this.firstload = true; this.tabdisable = false; this.getFilter(); this.filterOrderTypes(); this.getLocationsOnLoad().then(function (result) { if (result !== null) { that.getUserServerSettingsPromise().then(function (rs) { }); } else { that.noLocation = true; } that.groupGridBy = localStorage.getItem('groupGridBy'); }); // this.routeList.configure({ // title: this.l('New Route'), // dataSource: (skipCount: number, maxResultCount: number, filter: string, tenantId?: number, locationId?: number) => { // let input = new RouteDefinitionListInput(); // input.filter = filter; // input.maxResultCount = maxResultCount; // input.skipCount = skipCount; // input.tenantId = tenantId; // input.name = filter; // input.locationId = parseInt(localStorage.getItem('operatingLocationId')); // return this._controllerRouteService.pickRouteDefinitionListPaged(input); // } // }); } ngOnDestroy() { if (this.timerVar) { clearInterval(this.timerVar); } } // resetInterval() { // var that = this; // clearInterval(that.timerVar); // that.timerVar = setInterval(function refreshIntervalTimer() { that.dispatchDetailsComponent.populateTable(); }, parseInt(sessionStorage.getItem('timer-interval'))); // } setFilter() { localStorage.setItem('searchFilter', JSON.stringify(this.searchFilters)); } getFilter() { 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')); } localStorage.setItem('searchFilter', JSON.stringify(this.searchFilters)); this.completed = this.searchFilters.showCompletion; this.filters.routeName = this.searchFilters.route; this.filters.driverName = this.searchFilters.driverName; this.filters.vehicleName = this.searchFilters.vehicleName; this.fRouteName = this.searchFilters.route; this.filters.completed = this.searchFilters.showCompletion; this.filters.isLineHaul = this.LineHaulFilter; } getLocationsOnLoad() { let that = this; return new Promise(function (resolve, reject) { that.spinnerService.show(); that._locationServiceProxy.getLocationNames(undefined, undefined, undefined, undefined, undefined, undefined) .subscribe(result => { if (result == null || result.length == 0) { $("#locationSelectInput").val(''); resolve(null); } else { that.locations = result; if (localStorage.getItem('operatingLocationId') == null || localStorage.getItem('operatingLocationId') == undefined || localStorage.getItem('operatingLocationId') == '') { localStorage.setItem('operatingLocationId', that.locations['0'].id.toString()); that.selectedLocationId = that.locations['0'].id; } else { if (localStorage.getItem('operatingLocationId').search(',') > 0) { that.filters.locationIds = localStorage.getItem('operatingLocationId').split(',').map(function (item) { return parseInt(item, 10); }); var selectedTabLocation = localStorage.getItem('selectedTabLocation') == null || localStorage.getItem('selectedTabLocation') == undefined || localStorage.getItem('selectedTabLocation') == '' ? that.filters.locationIds[0] : parseInt(localStorage.getItem('selectedTabLocation')); var selectedLocation = that.filters.locationIds.find(x => x == selectedTabLocation); if (selectedLocation == undefined) { localStorage.removeItem('selectedTabLocation'); selectedTabLocation = that.filters.locationIds[0]; } let arrAny = {}, arrHolder = []; for (var key3 in that.filters.locationIds) { for (var key2 in that.locations) { if (that.filters.locationIds[key3].valueOf() == that.locations[key2].id) { if (selectedTabLocation == that.filters.locationIds[key3].valueOf()) { arrAny = { 'name': that.locations[key2].name, 'id': that.locations[key2].id, 'active': true }; } else { arrAny = { 'name': that.locations[key2].name, 'id': that.locations[key2].id, 'active': false }; } arrHolder.push(arrAny); } } } that.locationTabs = arrHolder; that.isMultipleLocation = true; } else { that.filters.locationIds = []; that.filters.locationIds.push(parseInt(localStorage.getItem('operatingLocationId'))); } } if (localStorage.getItem('timeZone') == null) { localStorage.setItem('timeZone', that.locations['0'].timezone); } else { if (that.locations.length === 0) { that.locationNames = 'NONE'; } } that.txtFilter = null; resolve(result["0"].id); } }); }); } insertServerSettings(preferences: string, value: string) { let that = this; this._preferencesService.getAll(undefined, preferences, undefined, undefined, undefined, undefined).subscribe(resultPref => { if (resultPref.totalCount > 0) { that.inputUserPreferences.userId = abp.session.userId; that.inputUserPreferences.value = value; that.inputUserPreferences.preferenceId = resultPref.items[0].preference.id; that._userPreferencesService.createOrEdit(that.inputUserPreferences).subscribe(resultInsertPref => { }) } else { that.inputPreferences.code = preferences; that.inputPreferences.description = preferences; that._preferencesService.createOrEdit(that.inputPreferences).subscribe(resultInsertPref => { that.insertServerSettings(preferences, value); }); } }); } isNumeric = (val: string): boolean => { return !isNaN(Number(val)); } getUserServerSettingsPromise() { let that = this; return new Promise(function (resolve, reject) { var locationId = localStorage.getItem('operatingLocationId') == null || localStorage.getItem('operatingLocationId') == 'null' ? that.locations[0].id.toString() : !that.isNumeric(localStorage.getItem('operatingLocationId')) ? that.locations[0].id.toString() : localStorage.getItem('operatingLocationId'); var loadDate = localStorage.getItem('loadDate') == null ? that.todaysDate : localStorage.getItem('loadDate') var thresholdValue = localStorage.getItem('THRESHOLD') == null ? undefined : localStorage.getItem('THRESHOLD') that._userPreferencesService.getCurrentuserPreference().subscribe(result => { if (result == null) { that.userPreferenceInput.locationValue = locationId; that.userPreferenceInput.loadDateValue = loadDate; that.userPreferenceInput.thresholdValue = thresholdValue that._userPreferencesService.createOrEditUserPreference(that.userPreferenceInput); } else { for (var data in result) { if (result[data].userPreference.preferences != null) { if (result[data].userPreference.preferences.code == "LOCATIONID") { if (result[data].userPreference.value == 'null' || result[data].userPreference.value == null) { result[data].userPreference.value = that.locations[0].id.toString(); that.userPreferenceInput.locationValue = result[data].userPreference.value; } else { if (!(result[data].userPreference.value.search(',') > 0)) { if (!that.isNumeric(result[data].userPreference.value)) { result[data].userPreference.value = that.locations[0].id.toString(); that.userPreferenceInput.locationValue = result[data].userPreference.value; } } } localStorage.setItem("operatingLocationId", result[data].userPreference.value); that.filters.locationFilter = parseInt(result[data].userPreference.value); that.inputs.locationId = parseInt(result[data].userPreference.value.toString()); $("#locationSelectInput").val(result[data].userPreference.value); that.haveLocation = true; } if (result[data].userPreference.preferences.code == "LOADDATE") { if (result[data].userPreference.value == 'null' || result[data].userPreference.value == null) { result[data].userPreference.value = that.todaysDate; that.userPreferenceInput.loadDateValue = that.todaysDate; } that.userPreferenceInput.loadDateValue = result[data].userPreference.value; localStorage.setItem("loadDate", result[data].userPreference.value); that.controllerHeaderFlyoutComponent.flyoutDate = moment(localStorage.getItem('loadDate')).toDate(); that.filters.startDate = moment(localStorage.getItem('loadDate')); that.filters.endDate = moment(localStorage.getItem('loadDate')); that.haveLoadDate = true; } if (result[data].userPreference.preferences.code == "THRESHOLD") { localStorage.setItem("THRESHOLD", result[data].userPreference.value); that.userPreferenceInput.thresholdValue = result[data].userPreference.value; that.controllerHeaderFlyoutComponent.driverThresholdId = parseInt(result[data].userPreference.value); that.haveThreshold = true; } if (result[data].userPreference.preferences.code == "THRESHOLD") { localStorage.setItem("THRESHOLD", result[data].userPreference.value); that.userPreferenceInput.thresholdValue = result[data].userPreference.value; that.controllerHeaderFlyoutComponent.driverThresholdId = parseInt(result[data].userPreference.value); that.haveThreshold = true; } if (result[data].userPreference.preferences.code == "BOXLIMIT") { localStorage.setItem("BOXLIMIT", result[data].userPreference.value); } } } that._userPreferencesService.createOrEditUserPreference(that.userPreferenceInput).subscribe(result => { }); if (!that.haveLocation) { that.insertServerSettings('LOCATIONID', locationId); that.filters.locationFilter = parseInt(locationId); } if (!that.haveThreshold && thresholdValue != undefined) { //that.insertServerSettings('THRESHOLD', locationId); } if (!that.haveLoadDate) { that.insertServerSettings('LOADDATE', loadDate); that.controllerHeaderFlyoutComponent.flyoutDate = moment(localStorage.getItem('loadDate')).toDate(); that.filters.startDate = moment(localStorage.getItem('loadDate')); that.filters.endDate = moment(localStorage.getItem('loadDate')); } } $('.selLocation').select2(); that.backgroundProcessListener(); that.filters.orderStatusCode = ""; that.filters.routeIds = []; that.filterRoutes(); if (that.edition === 'LABORATORY') { that.kpiLabComponent.clearFilter(); } }); resolve(null); }); } loadRouteComponent() { var that = this; if (this.groupGridBy === 'None' || this.groupGridBy === 'Order-Type') { that.dispatchDetailsComponent.locationTabs = that.locationTabs; that.dispatchDetailsComponent.isMultipleLocation = that.isMultipleLocation; that.dispatchDetailsComponent.isLineHaul = that.LineHaulFilter; that.dispatchDetailsComponent.populateTable(); } else if (this.groupGridBy === 'Route-Type') { that.dispatchDetailsGroupComponent.locationTabs = that.locationTabs; that.dispatchDetailsGroupComponent.isMultipleLocation = that.isMultipleLocation; that.dispatchDetailsGroupComponent.populateTable(); } } filterStops(data: any) { this.orderIds = data; let that = this; this.orderPackageListComponent = true; this.tOrderPackages.filterData = this.filters.orderIds; this.tOrderPackages.filters.unassignedStopsFilter = true; this.loadOrderPackagesListComponent('KPI_BOX'); } filterRoutes() { let key; var lang = abp.localization.currentLanguage.name; let timeId = localStorage.getItem('timeZoneId'); if (isNaN(Date.parse(localStorage.getItem('loadDate')))) { if (lang == "en-GB") { localStorage.setItem('loadDate', moment.tz(Date.now(), timeId).format('MM/DD/YYYY')); $(".controllerDatePicker1").val(moment.tz(Date.now(), timeId).format('DD/MM/YYYY')); } else { localStorage.setItem('loadDate', moment.tz(Date.now(), timeId).format('MM/DD/YYYY')); $(".controllerDatePicker1").val(moment.tz(Date.now(), timeId).format('MM/DD/YYYY')); } this.filters.startDate = moment.tz(Date.now(), timeId); } if (localStorage.getItem('operatingLocationId') == null) { localStorage.setItem('operatingLocationId', this.filters.locationIds.toString()); } else { if (localStorage.getItem('operatingLocationId').search(',') > 0) { this.filters.locationIds = localStorage.getItem('operatingLocationId').split(',').map(function (item) { return parseInt(item, 10); }); let arrAny = {}, arrHolder = []; var selectedTabLocation = localStorage.getItem('selectedTabLocation') == null || localStorage.getItem('selectedTabLocation') == undefined || localStorage.getItem('selectedTabLocation') == '' ? this.filters.locationIds[0] : parseInt(localStorage.getItem('selectedTabLocation')); var selectedLocation = this.filters.locationIds.find(x => x == selectedTabLocation); if (selectedLocation == undefined) { localStorage.removeItem('selectedTabLocation'); selectedTabLocation = this.filters.locationIds[0]; } for (var key3 in this.filters.locationIds) { for (var key2 in this.locations) { if (this.filters.locationIds[key3].valueOf() == this.locations[key2].id) { if (selectedTabLocation == this.filters.locationIds[key3].valueOf()) { arrAny = { 'name': this.locations[key2].name, 'id': this.locations[key2].id, 'active': true }; } else { arrAny = { 'name': this.locations[key2].name, 'id': this.locations[key2].id, 'active': false }; } arrHolder.push(arrAny); } } } this.filters.locationFilter = selectedTabLocation; this.locationTabs = arrHolder; this.isMultipleLocation = true; this.locationNames = "MULTIPLE"; } else { var singleLoc = this.locations.filter(e => e.id == parseInt(localStorage.getItem('operatingLocationId'))); this.locationNames = singleLoc == null || singleLoc == [] ? "" : singleLoc[0].name; this.filters.locationFilter = parseInt(localStorage.getItem('operatingLocationId')); this.isMultipleLocation = false; this.filters.locationIds = []; this.filters.locationIds.push(parseInt(localStorage.getItem('operatingLocationId'))); } } this.getLocationLock(); if (this.groupGridBy === 'None' || this.groupGridBy === 'Order-Type') { this.dispatchDetailsComponent.kpiClick = this.kpiClick; } else if (this.groupGridBy === 'Route-Type') { this.dispatchDetailsGroupComponent.kpiClick = this.kpiClick; } if (this.filters.routeName != undefined) { this.searchFilters.route = this.filters.routeName; this.setFilter(); } else { this.searchFilters.route = ''; this.setFilter(); } if (this.filters.vehicleName != undefined) { this.searchFilters.vehicleName = this.filters.vehicleName; this.setFilter(); } else { this.searchFilters.vehicleName = ''; this.setFilter(); } if (this.filters.driverName != undefined) { this.searchFilters.driverName = this.filters.driverName; this.setFilter() } else { this.searchFilters.driverName = ''; this.setFilter(); } if (this.currentRoutes == 'dispatch' || this.currentRoutes == 'dispatch-linehaul') { for (key in this.locations) { if (this.locations[key].id == this.filters.locationFilter) { /*$(".location").text(this.locations[key].name + " - ");*/ $(".location").text(this.locations[key].name + ""); } } let that = this; let nowDate = moment(this.todaysDate).toDate(); let nowDateMoment = moment(nowDate); let duration = {}; duration['_data'] = { 'days': 0 }; duration = moment.duration(nowDateMoment.diff(this.filters.endDate)); if (typeof duration !== "undefined") { if (duration['_data'].days > 0) { this.generateEnable = true; } else { this.generateEnable = false; } } this.inputs.loadDate = this.filters.endDate; this.inputs.locationId = that.filters.locationFilter; if (this.edition === 'STANDARD') { this.tKpiComponents.getKpiCount(); } this.searchFilters = JSON.parse(localStorage.getItem('searchFilter')); this.completed = this.searchFilters.showCompletion; if (!this.isEnabledLaboratory) { this.filters.completed = this.searchFilters.showCompletion; } switch (this.cRef.nativeElement.querySelector('.nav-tabs .active a span').innerText) { case 'Routes': switch (this.edition) { case 'STANDARD': if (this.groupGridBy === 'None' || this.groupGridBy === 'Order-Type') { that.dispatchDetailsComponent.locationTabs = that.locationTabs; that.dispatchDetailsComponent.isMultipleLocation = that.isMultipleLocation; that.dispatchDetailsComponent.populateTable(); } else if (this.groupGridBy === 'Route-Type') { that.dispatchDetailsGroupComponent.locationTabs = that.locationTabs; that.dispatchDetailsGroupComponent.isMultipleLocation = that.isMultipleLocation; that.dispatchDetailsGroupComponent.populateTable(); } break; case 'LABORATORY': if (this.kpiClick == false) { that._cRoutesService.setStatistics({ 'total_stops': 0, 'total_callins': 0, 'total_routes': 0, 'completed_stops': 0, 'completed_callins': 0, 'total_completed_routes': 0, 'total_unassigned_routes': 0, 'total_unassigned_stops': 0, 'total_not_checkin': 0, 'total_twenty_minutes': 0, 'total_thirty_minutes': 0, 'total_unassigned_willcalls': 0, 'unassigned_routes_ids': [], 'not_check_in_routes_ids': [], 'completed_route_ids': [], 'unassigned_stop_ids': [], 'completed_stops_id': [], 'completed_call_in_stops_ids': [] }); } if (this.groupGridBy === 'None' || this.groupGridBy === 'Order-Type') { that.dispatchDetailsComponent.locationTabs = that.locationTabs; that.dispatchDetailsComponent.isMultipleLocation = that.isMultipleLocation; that.dispatchDetailsComponent.populateTable(); } else if (this.groupGridBy === 'Route-Type') { that.dispatchDetailsGroupComponent.locationTabs = that.locationTabs; that.dispatchDetailsGroupComponent.isMultipleLocation = that.isMultipleLocation; that.dispatchDetailsGroupComponent.populateTable(); } break; default: if (this.groupGridBy === 'None' || this.groupGridBy === 'Order-Type') { that.dispatchDetailsComponent.locationTabs = that.locationTabs; that.dispatchDetailsComponent.isMultipleLocation = that.isMultipleLocation; that.dispatchDetailsComponent.populateTable(); } else if (this.groupGridBy === 'Route-Type') { that.dispatchDetailsGroupComponent.locationTabs = that.locationTabs; that.dispatchDetailsGroupComponent.isMultipleLocation = that.isMultipleLocation; that.dispatchDetailsGroupComponent.populateTable(); } break; } break; case 'Orders': if (this.groupGridBy === 'None' || this.groupGridBy === 'Route-Type') { that.tOrderComponents.getOrder(); } else if (this.groupGridBy === 'Order-Type') { that.tOrderGroupComponents.getOrder(); } break; case 'Packages': that.filterType = 'NONE'; if (this.groupGridBy === 'None' || this.groupGridBy === 'Route-Type') { that.tOrderPackages.getOrderPackages(); } else if (this.groupGridBy === 'Order-Type') { that.tOrderPackageGroupComponents.getOrderPackages(); } break; case 'Vehicles': that.vehicleTab.getVehicleList(); break; case 'Drivers': that.driverTab.getDriverList(); break; case 'Incidents': if (this.groupGridBy === 'None' || this.groupGridBy === 'Route-Type') { that.tOrderIncidents.getOrderIncident(); } else if (this.groupGridBy === 'Order-Type') { that.tOrderIncidentsGroup.getOrderIncident(); } break; default: if (this.groupGridBy === 'None' || this.groupGridBy === 'Order-Type') { that.dispatchDetailsComponent.locationTabs = that.locationTabs; that.dispatchDetailsComponent.isMultipleLocation = that.isMultipleLocation; that.dispatchDetailsComponent.populateTable(); } else if (this.groupGridBy === 'Route-Type') { that.dispatchDetailsGroupComponent.locationTabs = that.locationTabs; that.dispatchDetailsGroupComponent.isMultipleLocation = that.isMultipleLocation; that.dispatchDetailsGroupComponent.populateTable(); } break; } this.controllerHeaderFlyoutComponent.enableButton(); } } TodayFilter() { if (this.noLocation === false) { this.firstload = false; this._controllerRouteService.getBranchTime(undefined, this.filters.locationFilter, undefined, undefined, undefined) .subscribe(result => { let dateLocation; dateLocation = result.split(' '); localStorage.setItem('loadDate', dateLocation[0]); var loadDate = dateLocation[0]; this.filters.startDate = moment(localStorage.getItem('loadDate')); this.filters.endDate = moment(localStorage.getItem('loadDate')); this.controllerHeaderFlyoutComponent.flyoutDate = moment(localStorage.getItem('loadDate')).toDate(); $(".controllerDatePicker1").val(dateLocation[0]); this.userPreferenceInput.loadDateValue = localStorage.getItem('loadDate'); this.userPreferenceInput.locationValue = localStorage.getItem('operatingLocationId'); this._userPreferencesService.createOrEditUserPreference(this.userPreferenceInput).subscribe(res => { this.filterRoutes(); }); localStorage.setItem('loadDate', dateLocation[0]); this.controllerHeaderFlyoutComponent.getRoutes(); this.dispatchDetailsComponent.noResultFound = false; }); } } loadDriverListComponent() { this.driverTab.getDriverList(); } loadVehicleListComponent() { this.vehicleTab.getVehicleList(); } loadOrderPackagesListComponent(filterType: string) { filterType = filterType != null ? filterType : 'NONE' let that = this; this.orderPackageListComponent = true; this.tOrderPackages.filterData = this.filters.orderIds = undefined; this.staticTabs.tabs[2].active = true; if (this.groupGridBy === 'None' || this.groupGridBy === 'Route-Type') { if (filterType == 'NONE') { this.tOrderPackages.filters.unassignedStopsFilter = false this.tOrderPackages.filters.willCallFilter = false this.tOrderPackages.filters.orderStatusCode = undefined this.tOrderPackages.filters.isLineHaul = this.LineHaulFilter; this.tOrderPackages.getOrderPackages(); } else if (filterType == 'UNASSIGNED_ORDERS') { this.tOrderPackages.filters.willCallFilter = false this.tOrderPackages.filters.orderStatusCode = undefined this.tOrderPackages.filters.isLineHaul = this.LineHaulFilter; this.tOrderPackages.getOrderPackages(); } else if (filterType == 'COMPLETED_STOPS') { this.tOrderPackages.filters.unassignedStopsFilter = false this.tOrderPackages.filters.willCallFilter = false, this.tOrderPackages.filters.isLineHaul = this.LineHaulFilter; this.tOrderPackages.getOrderPackages(); } else if (filterType == 'COMPLETED_CALLIN') { this.tOrderPackages.filters.unassignedStopsFilter = false this.tOrderPackages.filters.orderStatusCode = undefined this.tOrderPackages.filters.isLineHaul = this.LineHaulFilter; this.tOrderPackages.getOrderPackages(); } else { this.tOrderPackages.filters.isLineHaul = this.LineHaulFilter; this.tOrderPackages.getOrderPackages(); } } else if (this.groupGridBy === 'Order-Type') { if (filterType == 'NONE') { this.tOrderPackageGroupComponents.filters.unassignedStopsFilter = false this.tOrderPackageGroupComponents.filters.willCallFilter = false this.tOrderPackageGroupComponents.filters.orderStatusCode = undefined this.tOrderPackageGroupComponents.filters.isLineHaul = this.LineHaulFilter; this.tOrderPackageGroupComponents.getOrderPackages(); } else if (filterType == 'UNASSIGNED_ORDERS') { this.tOrderPackageGroupComponents.filters.willCallFilter = false this.tOrderPackageGroupComponents.filters.orderStatusCode = undefined this.tOrderPackageGroupComponents.filters.isLineHaul = this.LineHaulFilter; this.tOrderPackageGroupComponents.getOrderPackages(); } else if (filterType == 'COMPLETED_STOPS') { this.tOrderPackageGroupComponents.filters.unassignedStopsFilter = false this.tOrderPackageGroupComponents.filters.willCallFilter = false this.tOrderPackageGroupComponents.filters.isLineHaul = this.LineHaulFilter; this.tOrderPackageGroupComponents.getOrderPackages(); } else if (filterType == 'COMPLETED_CALLIN') { this.tOrderPackageGroupComponents.filters.unassignedStopsFilter = false this.tOrderPackageGroupComponents.filters.orderStatusCode = undefined this.tOrderPackageGroupComponents.filters.isLineHaul = this.LineHaulFilter; this.tOrderPackageGroupComponents.getOrderPackages(); } else { this.tOrderPackageGroupComponents.filters.isLineHaul = this.LineHaulFilter; this.tOrderPackageGroupComponents.getOrderPackages(); } } } loadOrderIncidentListComponent() { let that = this; this.orderIncidentListComponent = true; if (this.groupGridBy === 'None' || this.groupGridBy === 'Route-Type') { this.tOrderIncidents.filters.isLineHaul = this.LineHaulFilter; this.tOrderIncidents.getOrderIncident(undefined); } else if (this.groupGridBy === 'Order-Type') { this.tOrderIncidentsGroup.filters.isLineHaul = this.LineHaulFilter; this.tOrderIncidentsGroup.getOrderIncident(undefined); } } loadOrderListComponent(filterType: string) { let that = this; this.orderListComponent = true; if (this.groupGridBy === 'None' || this.groupGridBy === 'Route-Type') { if (filterType == 'NONE') { this.tOrderComponents.filters.unassignedStopsFilter = false this.tOrderComponents.filters.willCallFilter = false this.tOrderComponents.filters.orderStatusCode = undefined; this.tOrderComponents.filters.isLineHaul = this.LineHaulFilter; this.tOrderComponents.orderIds = this.filters.orderIds; this.tOrderComponents.getOrder(); } else if (filterType == 'KPI_REMAINING_STOPS') { this.tOrderComponents.filters.orderKPIFilter = "KPI_REMAINING_STOPS"; this.tOrderComponents.filters.isLineHaul = this.LineHaulFilter; this.tOrderComponents.getOrder(); } else if (filterType == 'KPI_REMAINING_DELIVERIES') { this.tOrderComponents.filters.orderKPIFilter = "KPI_REMAINING_DELIVERIES"; this.tOrderComponents.filters.isLineHaul = this.LineHaulFilter; this.tOrderComponents.getOrder(); } else if (filterType == 'KPI_PICKED_UP') { this.tOrderComponents.filters.orderKPIFilter = "KPI_PICKED_UP"; this.tOrderComponents.filters.isLineHaul = this.LineHaulFilter; this.tOrderComponents.getOrder(); } else if (filterType == 'KPI_DELIVERED') { this.tOrderComponents.filters.orderKPIFilter = "KPI_DELIVERED"; this.tOrderComponents.filters.isLineHaul = this.LineHaulFilter; this.tOrderComponents.getOrder(); } else if (filterType == 'KPI_UNASSIGNED') { this.tOrderComponents.filters.orderKPIFilter = "KPI_UNASSIGNED"; this.tOrderComponents.filters.isLineHaul = this.LineHaulFilter; this.tOrderComponents.getOrder(); } else if (filterType == 'KPI_DELIVERY_ISSUE') { this.tOrderComponents.filters.orderKPIFilter = "KPI_DELIVERY_ISSUE"; this.tOrderComponents.filters.isLineHaul = this.LineHaulFilter; this.tOrderComponents.getOrder(); } else if (filterType == 'UNASSIGNED_ORDERS') { this.tOrderComponents.filters.willCallFilter = false this.tOrderComponents.filters.isLineHaul = this.LineHaulFilter; this.tOrderComponents.filters.orderStatusCode = undefined this.tOrderComponents.getOrder(); } else if (filterType == 'COMPLETED_STOPS') { this.tOrderComponents.filters.unassignedStopsFilter = false this.tOrderComponents.filters.isLineHaul = this.LineHaulFilter; this.tOrderComponents.filters.willCallFilter = false this.tOrderComponents.getOrder(); } else if (filterType == 'COMPLETED_CALLIN') { this.tOrderComponents.filters.unassignedStopsFilter = false this.tOrderComponents.filters.isLineHaul = this.LineHaulFilter; this.tOrderComponents.filters.orderStatusCode = undefined this.tOrderComponents.getOrder(); } else { this.tOrderComponents.orderIds = this.filters.orderIds; this.tOrderComponents.unassignedWillCalls = this.KPIfilters.unassignedWillCalls; this.tOrderComponents.filters.isLineHaul = this.LineHaulFilter; this.tOrderComponents.getOrder(); } } else if (this.groupGridBy === 'Order-Type') { if (filterType == 'NONE') { this.tOrderGroupComponents.filters.unassignedStopsFilter = false this.tOrderGroupComponents.filters.willCallFilter = false this.tOrderGroupComponents.filters.orderStatusCode = undefined; this.tOrderGroupComponents.orderIds = this.filters.orderIds; this.tOrderComponents.filters.isLineHaul = this.LineHaulFilter; this.tOrderGroupComponents.getOrder(); } else if (filterType == 'KPI_REMAINING_STOPS') { this.tOrderGroupComponents.filters.orderKPIFilter = "KPI_REMAINING_STOPS"; this.tOrderComponents.filters.isLineHaul = this.LineHaulFilter; this.tOrderGroupComponents.getOrder(); } else if (filterType == 'KPI_REMAINING_DELIVERIES') { this.tOrderGroupComponents.filters.orderKPIFilter = "KPI_REMAINING_DELIVERIES"; this.tOrderComponents.filters.isLineHaul = this.LineHaulFilter; this.tOrderGroupComponents.getOrder(); } else if (filterType == 'KPI_PICKED_UP') { this.tOrderGroupComponents.filters.orderKPIFilter = "KPI_PICKED_UP"; this.tOrderComponents.filters.isLineHaul = this.LineHaulFilter; this.tOrderGroupComponents.getOrder(); } else if (filterType == 'KPI_DELIVERED') { this.tOrderGroupComponents.filters.orderKPIFilter = "KPI_DELIVERED"; this.tOrderComponents.filters.isLineHaul = this.LineHaulFilter; this.tOrderGroupComponents.getOrder(); } else if (filterType == 'KPI_UNASSIGNED') { this.tOrderGroupComponents.filters.orderKPIFilter = "KPI_UNASSIGNED"; this.tOrderComponents.filters.isLineHaul = this.LineHaulFilter; this.tOrderGroupComponents.getOrder(); } else if (filterType == 'KPI_DELIVERY_ISSUE') { this.tOrderGroupComponents.filters.orderKPIFilter = "KPI_DELIVERY_ISSUE"; this.tOrderComponents.filters.isLineHaul = this.LineHaulFilter; this.tOrderGroupComponents.getOrder(); } else if (filterType == 'UNASSIGNED_ORDERS') { this.tOrderGroupComponents.filters.willCallFilter = false this.tOrderComponents.filters.isLineHaul = this.LineHaulFilter; this.tOrderGroupComponents.filters.orderStatusCode = undefined this.tOrderGroupComponents.getOrder(); } else if (filterType == 'COMPLETED_STOPS') { this.tOrderGroupComponents.filters.unassignedStopsFilter = false this.tOrderComponents.filters.isLineHaul = this.LineHaulFilter; this.tOrderGroupComponents.filters.willCallFilter = false this.tOrderGroupComponents.getOrder(); } else if (filterType == 'COMPLETED_CALLIN') { this.tOrderGroupComponents.filters.unassignedStopsFilter = false this.tOrderComponents.filters.isLineHaul = this.LineHaulFilter; this.tOrderGroupComponents.filters.orderStatusCode = undefined this.tOrderGroupComponents.getOrder(); } else { this.tOrderGroupComponents.orderIds = this.filters.orderIds; this.tOrderGroupComponents.unassignedWillCalls = this.KPIfilters.unassignedWillCalls; this.tOrderComponents.filters.isLineHaul = this.LineHaulFilter; this.tOrderGroupComponents.getOrder(); } } } getSelected() { let elements = this.elem.nativeElement.querySelectorAll('.checkboxItem'); } filterRoutesByParameters() { var that = this; this.search_string = this.txtFilter; switch (this.edition) { case 'STANDARD': if (this.groupGridBy === 'None') { this.dispatchDetailsComponent.setFilter(this.txtFilter); } else if (this.groupGridBy === 'Route-Type') { this.dispatchDetailsGroupComponent.setFilter(this.txtFilter); } this._cRoutesService.setStatistics({ "result": "OK", "total_vehicles": "0", "total_packages": "0" }); if (this.groupGridBy === 'None') { that.dispatchDetailsComponent.populateTable(); } else if (this.groupGridBy === 'Route-Type') { that.dispatchDetailsGroupComponent.populateTable(); } break; case 'LABORATORY': this.dispatchDetailsComponent.setFilter(this.txtFilter); this._cRoutesService.setStatistics({ "result": "OK", "total_vehicles": "0", "total_packages": "0" }); if (this.groupGridBy === 'None') { that.dispatchDetailsComponent.populateTable(); } else if (this.groupGridBy === 'Route-Type') { that.dispatchDetailsGroupComponent.populateTable(); } break; default: this.dispatchDetailsComponent.setFilter(this.txtFilter); this._cRoutesService.setStatistics({ "result": "OK", "total_vehicles": "0", "total_packages": "0" }); if (this.groupGridBy === 'None') { that.dispatchDetailsComponent.populateTable(); } else if (this.groupGridBy === 'Route-Type') { that.dispatchDetailsGroupComponent.populateTable(); } break; } } backgroundProcessListener() { this.hubConnection = new signalR.HubConnectionBuilder() .withUrl(AppConsts.remoteServiceBaseUrl + '/signalr-background') .build(); this.hubConnection .start() .then() .catch(err => { console.log('Error while starting connection: ' + err); this.toggle(false); }); this.hubConnection.on('BackgroundMessage:' + abp.session.tenantId + ':generateRoutes', (message) => { if (message.match(/Route created/) || message.match(/Order created/) || message.match(/--End--/)) { this.generateRoutesTracking.logMessage(message, true); } else { this.generateRoutesTracking.logMessage(message); } this.sendMessage(message); }); } importListener() { this.importConnection = new signalR.HubConnectionBuilder() .withUrl(AppConsts.remoteServiceBaseUrl + '/import') .build(); this.importConnection .start() .then(() => console.log('Connection started')) .catch(err => console.log('Error while starting connection: ' + err)); this.importConnection.on('BackgroundMessage', (message) => { if (message.match(/End Importing/)) { this.importRouteScheduleTracking.importing = false; this.importConnection.off; } else { this.importRouteScheduleTracking.logMessage(message); } }); } refresh(event: any) { this.firstload = true; this.filters.routeIds = []; this.getUserServerSettingsPromise(); // this.filterRoutes(); // if (this.edition === 'LABORATORY') { // this.kpiLabComponent.clearFilter(); // } } setCompleted() { this.searchFilters.showCompletion = this.completed; this.setFilter(); this.refresh(undefined); } async generateRoute() { //this.generateRoutesTracking.clearMessages(); let timeId = localStorage.getItem('timeZoneId'); let params = new GenerateInputDto({ locationId: this.filters.locationFilter, loadDateEnd: moment.tz(localStorage.getItem('loadDate'), timeId), loadDateStart: moment.tz(localStorage.getItem('loadDate'), timeId), limit: 100, action: "RUN", jobId: "", timezone: "", isAuto: false, runEstimatedStartTimes: true, runRouteDestinations: true }); this._locationServiceProxy.isHolidayOnLocation(params.loadDateEnd, params.locationId, undefined, undefined) .subscribe(result => { if (result) { this.message.info('Today is a holiday. Route and orders are not allowed to be generated') } else { this.genRoutes(params); } }); } async genRoutes(params: GenerateInputDto) { let runResult = await this._controllerRouteService.generateRouteManual(params).toPromise(); if (runResult.success) { //this.generateRoutesTracking.complete(); //this.filterRoutes(); this.toggle(true); this.notify.info('Route generation is queued. Please wait'); if (runResult.jobId) { //this.generateRoutesTracking.modal.show(); params.jobId = runResult.jobId; params.action = "TRACK"; let observable = interval(1500).subscribe((val) => { this._controllerRouteService.generateRouteManual(params).subscribe(watcher => { if (watcher.result == "DONE") { this.toggle(false); this.notify.success('Route generation is complete'); this.generateRoutesTracking.complete(); observable.unsubscribe(); this.filterRoutes(); this.controllerHeaderFlyoutComponent.enableButton(); this.noDataComponent.enableButton(); } }); }); } } } showFlyOut(): void { if (this.noLocation === false) { this.controllerHeaderFlyoutComponent.showFlyout(this.locations, this.userProfile, this.edition); } } PrintRouteSheet() { this.localRouteIds = JSON.parse(localStorage.getItem('routeIds')); if (this.localRouteIds.length == 0) { this.notify.error(this.l('Please select atleast one route')); } else { window.open('/app/sprintship/print-route-sheet', '_blank'); } // var locationId = localStorage.getItem('operatingLocationId'); // if (locationId==null || locationId=="0") { // this.notify.error(this.l('Please select atleast one location')); // } else { // window.open('/app/sprintship/print-route-sheet', '_blank'); // } // var locationId = parseInt(localStorage.getItem('operatingLocationId')); // let timeId = localStorage.getItem('timeZoneId'); // this.spinnerService.show(); // this.notify.info(this.l('Exporting Route Sheet')); // this._controllerPrintRouteDetails.getRouteSheetToExcel(locationId, moment.tz(localStorage.getItem('loadDate'), timeId)).subscribe(result => { // if (result.fileName!=undefined) { // this.spinnerService.hide(); // this.notify.success(this.l('Exported Successfully')); // window.open(AppConsts.remoteServiceBaseUrl + '/File/DownloadTempFile?fileType=' + result.fileType + '&fileToken=' + result.fileToken + '&fileName=' + result.fileName, '_blank'); // }else{ // this.spinnerService.hide(); // this.notify.error(this.l('No Data for Route Sheet')); // } // }); } PrintRoute() { this.localRouteIds = JSON.parse(localStorage.getItem('routeIds')); if (this.localRouteIds.length == 0) { this.notify.error(this.l('Please select atleast one route')); } else { window.open('/app/sprintship/route-print', '_blank'); } } myProfile() { abp.event.trigger('app.show.mySettingsModal'); } logOut() { this._authService.logout(); } exportRouteSchedules(): void { this.spinnerService.show(); this.notify.info(this.l('Exporting Route Schedule.')); this._controllerRouteDetailService .getRouteScheduleToExcel(parseInt(localStorage.getItem('operatingLocationId'))) .subscribe(result => { if (result != undefined) { if (result.fileUrl != undefined) { this.router.navigate([]).then(result1 => { window.open(result.fileUrl, '_blank'); }); // this.message.success('','EDI was sent successfully to your email'); // this._fileDownloadService.downloadTempFile(result); this.spinnerService.hide(); } else { // this.message.warn('', result.message); this.spinnerService.hide(); } } else { this.spinnerService.hide(); } }); } getLocationLock(): void { // if (localStorage.getItem('operatingLocationId').search(',') > 0) { // this.filters.locationIds = localStorage.getItem('operatingLocationId').split(',').map(function(item) { // return parseInt(item, 10); // }); // }else{ // if(!this.isNumeric(localStorage.getItem('operatingLocationId'))){ // this.filters.locationIds.push(parseInt(localStorage.getItem('operatingLocationId'))); // } // } // this.selectedLocationId = localStorage.getItem('operatingLocationId')!=null? this.filters.locationIds==[] || this.filters.locationIds == null ? // this.locations['0'].id : this.filters.locationIds[0].valueOf() : this.locations['0'].id; let timeId = localStorage.getItem('timeZoneId'); if (this.filters.locationFilter != null) { this._locationServiceProxy.getLocationForLock(this.filters.locationFilter, moment.tz(localStorage.getItem('loadDate'), timeId)).subscribe(result => { this.lockOrUnlockLocation = result.lock; this.lockOrUnlockLocationDetails = result; }) } } unlockLocation(): void { let locId = this.filters.locationFilter; this.unlockModal.show(locId); } lockLocation(): void { this.lockModal.show(this.lockOrUnlockLocationDetails); } getRouteAndDriver(data: any) { this.controllerHeaderFlyoutComponent.filterRouteData = data; } getPackages(): void { if (this.edition === 'LABORATORY') { this._controllerRoutePackages.getShippingPackageListOptions(undefined, undefined, undefined, undefined, undefined, undefined) .subscribe(resultPackages => { resultPackages.forEach(element => { if (element.name !== 'Default') { if (element.isHiddenPackages === '0') { this.packages.push(element); } } }); }); } } getContainers(): void { this.containers.length = 0; this._controllerRouteContainers.getAll().subscribe(result => { result.items.forEach(element => { this.containers.push(element); }); }); } toggle(toggle: boolean) { this._progressBar.toggleProgressBar(toggle); } sendMessage(message: string) { this._progressBar.sendMessage(message); } createNewRoute(item: NameValueDto) { // let input = new CreateNewRouteInput(); // let timeId = localStorage.getItem('timeZoneId'); // input.name = undefined; // input.routeDefinitionId = parseInt(item.value); // input.loadDate = moment.tz(localStorage.getItem('loadDate'), timeId); // input.locationId = parseInt(localStorage.getItem('operatingLocationId')); // this._controllerRouteService.createNewRoute(input).subscribe(result => { // }); } showRouteList(record: any): void { this.routeList.shown(); } filterOrderTypes() { this._orderTypeRepository.getAll(undefined, undefined, undefined, 1, undefined, undefined, undefined, undefined).subscribe(result => { this.filteredOrderType = result.items; }); } getLateRoutes(lateRoutes: any) { this.dispatchDetailsComponent.highlightLateRoutes(lateRoutes); } }