import { Component, Injector, OnInit, ViewChild, ViewEncapsulation, ElementRef, AfterViewInit, Renderer, Input } 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, GenerateRouteInputDto, AddressAddressTypeLookupTableDto, ProfileServiceProxy, CurrentUserProfileEditDto, LocationNameDto, ControllerKpiCountServiceProxy, ControllerRouteDetailServiceProxy, PreferencesServiceProxy, UserPreferencesServiceProxy, CreateOrEditPreferenceDto, CreateOrEditUserPreferenceDto, UserPreferenceInput, GetLocationLockDto, ControllerPrintRouteSheetServiceProxy } 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 { ControllerShowHideComponent } from '@app/sprintship/controller/core-components/controller-show-hide-modal.component.ts'; import { CreateRouteControllerModalComponent } from '@app/sprintship/controller/modals/create-routes-controller-modal.component'; 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 { 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'; declare var $: any; declare var jquery: any; @Component({ selector: 'controller-main', templateUrl: 'croutes.component.html', encapsulation: ViewEncapsulation.None, styleUrls: ['./croutes.component.less', './dropdown.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(KPIBoxComponent, { static: false }) tKpiComponents: KPIBoxComponent; @ViewChild(ControllerOrderPackagesComponent, { static: false }) tOrderPackages: ControllerOrderPackagesComponent; @ViewChild(ControllerOrderIncidentsComponent, { static: false }) tOrderIncidents: ControllerOrderIncidentsComponent; /***** 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('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; 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, 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 } = {}; search_string: string; txtFilter: string; allowed_dispatch: string = 'ALLOWED'; statusLocatorComponent: boolean = false; locationName: 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; @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; lockOrUnlockLocation: boolean; lockOrUnlockLocationDetails: GetLocationLockDto = new GetLocationLockDto(); constructor( injector: Injector, private _controllerRouteService: ControllerRouteServiceProxy, private _locationServiceProxy: LocationServiceProxy, private _cRoutesService: ControllerRoutesService, private elem: ElementRef, private router: Router, private _authService: AppAuthService, private _controllerRouteDetailService: ControllerRouteDetailServiceProxy, private _preferencesService: PreferencesServiceProxy, private _userPreferencesService: UserPreferencesServiceProxy, private _controllerPrintRouteDetails: ControllerPrintRouteSheetServiceProxy, ) { super(injector); } _construct() { this.kpiClick = false; this.noLocation = false; this.lastRefresh = 'N/A'; 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 = this.currentRoutes.toString().split('/'); this.currentRoutes = this.currentRoutes[this.currentRoutes.length - 1]; this.todaysDate = moment(Date.now()).format('MM/DD/YYYY'); if (localStorage.getItem('loadDate') == null) { this.todaysDate = moment(Date.now()).format('MM/DD/YYYY'); localStorage.setItem('loadDate', this.todaysDate); } } 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'; } 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._construct(); let timeId = localStorage.getItem('timeZoneId'); moment.tz.setDefault(timeId); let that = this; this.firstload = true; this.tabdisable = false; this.getFilter(); this.getLocationsOnLoad().then(function (result) { if (result !== null) { that.getUserServerSettingsPromise().then(function (rs) { }); } else { that.noLocation = true; } that.groupGridBy = localStorage.getItem('groupGridBy'); }); } 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; } getLocationsOnLoad() { let that = this; return new Promise(function (resolve, reject) { that.spinnerService.show(); that._locationServiceProxy.getLocationNames(undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined) .subscribe(result => { if (result == null) { $("#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); } if (localStorage.getItem('timeZone') == null) { localStorage.setItem('timeZone', that.locations['0'].timezone); } else { if (that.locations.length === 0) { that.locationName = 'NONE'; } } $("#locationSelectInput").val(result["0"].id); 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); }); } }); } getUserServerSettingsPromise() { let that = this; return new Promise(function (resolve, reject) { var locationId = localStorage.getItem('operatingLocationId') == null ? that.locations[0].id.toString() : localStorage.getItem('operatingLocationId'); var loadDate = localStorage.getItem('loadDate') == null ? that.todaysDate : localStorage.getItem('loadDate') that._userPreferencesService.getCurrentuserPreference().subscribe(result => { if (result == null) { that.userPreferenceInput.locationValue = locationId; that.userPreferenceInput.loadDateValue = loadDate; that._userPreferencesService.createOrEditUserPreference(that.userPreferenceInput); } else { for (var data in result) { if (result[data].userPreference.preferences.code == "operatingLocationId") { 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") { 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 (!that.haveLocation) { that.insertServerSettings('operatingLocationId', locationId); that.filters.locationFilter = parseInt(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') { that.dispatchDetailsComponent.populateTable(); } else if (this.groupGridBy === 'Route-Type') { that.dispatchDetailsGroupComponent.populateTable(); } } filterStops(data: any) { this.orderIds = data; this.orderPackageListComponent = true; this.tOrderPackages.filterData = this.filters.orderIds; this.tOrderPackages.filters.unassignedStopsFilter = true; this.loadOrderPackagesListComponent('KPI_BOX'); } filterRoutes() { let key; if (this.groupGridBy === 'None') { 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') { for (key in this.locations) { if (this.locations[key].id == this.filters.locationFilter) { $(".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') { that.dispatchDetailsComponent.populateTable(); } else if (this.groupGridBy === 'Route-Type') { 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') { that.dispatchDetailsComponent.populateTable(); } else if (this.groupGridBy === 'Route-Type') { that.dispatchDetailsGroupComponent.populateTable(); } break; default: if (this.groupGridBy === 'None') { that.dispatchDetailsComponent.populateTable(); } else if (this.groupGridBy === 'Route-Type') { that.dispatchDetailsGroupComponent.populateTable(); } break; } break; case 'Orders': that.tOrderComponents.getOrder(); break; case 'Packages': that.filterType = 'NONE'; that.tOrderPackages.getOrderPackages(); break; case 'Vehicles': that.vehicleTab.getVehicleList(); break; case 'Drivers': that.driverTab.getDriverList(); break; case 'Incidents': that.tOrderIncidents.getOrderIncident(); break; default: if (this.groupGridBy === 'None') { that.dispatchDetailsComponent.populateTable(); } else if (this.groupGridBy === 'Route-Type') { that.dispatchDetailsGroupComponent.populateTable(); } break; } } } 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.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 (filterType == 'NONE') { this.tOrderPackages.filters.unassignedStopsFilter = false this.tOrderPackages.filters.willCallFilter = false this.tOrderPackages.filters.orderStatusCode = undefined this.tOrderPackages.getOrderPackages(); } else if (filterType == 'UNASSIGNED_ORDERS') { this.tOrderPackages.filters.willCallFilter = false this.tOrderPackages.filters.orderStatusCode = undefined this.tOrderPackages.getOrderPackages(); } else if (filterType == 'COMPLETED_STOPS') { this.tOrderPackages.filters.unassignedStopsFilter = false this.tOrderPackages.filters.willCallFilter = false this.tOrderPackages.getOrderPackages(); } else if (filterType == 'COMPLETED_CALLIN') { this.tOrderPackages.filters.unassignedStopsFilter = false this.tOrderPackages.filters.orderStatusCode = undefined this.tOrderPackages.getOrderPackages(); } else { this.tOrderPackages.getOrderPackages(); } } loadOrderIncidentListComponent() { let that = this; this.orderIncidentListComponent = true; this.tOrderIncidents.getOrderIncident(undefined); } loadOrderListComponent(filterType: string) { let that = this; this.orderListComponent = true; if (filterType == 'NONE') { this.tOrderComponents.filters.unassignedStopsFilter = false this.tOrderComponents.filters.willCallFilter = false this.tOrderComponents.filters.orderStatusCode = undefined; this.tOrderComponents.orderIds = this.filters.orderIds; this.tOrderComponents.getOrder(); } else if (filterType == 'KPI_REMAINING_STOPS') { this.tOrderComponents.filters.orderKPIFilter = "KPI_REMAINING_STOPS"; this.tOrderComponents.getOrder(); } else if (filterType == 'KPI_REMAINING_DELIVERIES') { this.tOrderComponents.filters.orderKPIFilter = "KPI_REMAINING_DELIVERIES"; this.tOrderComponents.getOrder(); } else if (filterType == 'KPI_PICKED_UP') { this.tOrderComponents.filters.orderKPIFilter = "KPI_PICKED_UP"; this.tOrderComponents.getOrder(); } else if (filterType == 'KPI_DELIVERED') { this.tOrderComponents.filters.orderKPIFilter = "KPI_DELIVERED"; this.tOrderComponents.getOrder(); } else if (filterType == 'KPI_UNASSIGNED') { this.tOrderComponents.filters.orderKPIFilter = "KPI_UNASSIGNED"; this.tOrderComponents.getOrder(); } else if (filterType == 'KPI_DELIVERY_ISSUE') { this.tOrderComponents.filters.orderKPIFilter = "KPI_DELIVERY_ISSUE"; this.tOrderComponents.getOrder(); } else if (filterType == 'UNASSIGNED_ORDERS') { this.tOrderComponents.filters.willCallFilter = false this.tOrderComponents.filters.orderStatusCode = undefined this.tOrderComponents.getOrder(); } else if (filterType == 'COMPLETED_STOPS') { this.tOrderComponents.filters.unassignedStopsFilter = false this.tOrderComponents.filters.willCallFilter = false this.tOrderComponents.getOrder(); } else if (filterType == 'COMPLETED_CALLIN') { this.tOrderComponents.filters.unassignedStopsFilter = false this.tOrderComponents.filters.orderStatusCode = undefined this.tOrderComponents.getOrder(); } else { this.tOrderComponents.orderIds = this.filters.orderIds; this.tOrderComponents.unassignedWillCalls = this.KPIfilters.unassignedWillCalls; this.tOrderComponents.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.hubConnection.on('BackgroundMessage:' + abp.session.tenantId + ':generateRoutes', (message) => { if (message.match(/Route created/) || message.match(/Order created/)) { this.generateRoutesTracking.logMessage(message, true); } else { this.generateRoutesTracking.logMessage(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.filterRoutes(); if (this.edition === 'LABORATORY') { this.kpiLabComponent.clearFilter(); } } setCompleted() { this.searchFilters.showCompletion = this.completed; this.setFilter(); this.refresh(undefined); } async generateRoute() { let badge = document.querySelector('#badge'); badge.classList.add('pulsate'); this.generateRoutesTracking.clearMessages(); let timeId = localStorage.getItem('timeZoneId'); let params = new GenerateRouteInputDto({ loadDateEnd: moment.tz(localStorage.getItem('loadDate'), timeId), loadDateStart: moment.tz(localStorage.getItem('loadDate'), timeId), locationId: this.filters.locationFilter, action: "RUN", jobId: "" }); let runResult = await this._controllerRouteService.generateRouteManual(params).toPromise(); if (runResult.success) { //this.generateRoutesTracking.complete(); //this.filterRoutes(); 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.generateRoutesTracking.complete(); observable.unsubscribe(); this.filterRoutes(); badge.classList.remove('pulsate'); } }); }); } } } showFlyOut(): void { if (this.noLocation === false) { this.controllerHeaderFlyoutComponent.showFlyout(this.locations, this.userProfile, this.edition); } } PrintRouteSheet() { 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 Route Sheet')); } }); // window.open('/app/sprintship/route-sheet-print', '_blank'); // 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-sheet-print', '_blank'); // } } 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.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 route schedule in this location')); } }); } // data: { files: File } // test(event): void { // this.importListener(); // this.importRouteScheduleTracking.clearMessages(); // this.importRouteScheduleTracking.modal.show(); // const formData: FormData = new FormData(); // const file = data.files[0]; // formData.append('file', file, file.name); // formData.append('key','workbook'); // formData.append('loadDate', moment().tz(localStorage.getItem('timeZoneId')).format()); // // formData.append('entity','addresses','addresses'); // this._httpClient // .post(this.uploadUrl, formData) // .subscribe(response => { // if (response.success) { // this.notify.success(this.l('ImportStart')); // } else if (response.error != null) { // this.notify.error(this.l('ImportFailed')); // } // }); // } // onUploadExcelError(): void { // this.notify.error(this.l('ImportFailed')); // } getLocationLock(): void { let locId = parseInt(localStorage.getItem('operatingLocationId')); if (locId != null) { this._locationServiceProxy.getLocationForLock(locId).subscribe(result => { this.lockOrUnlockLocation = result.lock; this.lockOrUnlockLocationDetails = result; }) } } unlockLocation(): void { let locId = localStorage.getItem('operatingLocationId'); this.unlockModal.show(locId); } lockLocation(): void { this.lockModal.show(this.lockOrUnlockLocationDetails); } getRouteAndDriver(data : any){ this.controllerHeaderFlyoutComponent.filterRouteData = data; } }