import { Component, Injector, OnInit, ViewChild, ViewEncapsulation, Input, TemplateRef, Output, EventEmitter, ChangeDetectorRef } from '@angular/core'; import { ActivatedRoute, Router } from '@angular/router'; import { AppConsts } from '@shared/AppConsts'; import { appModuleAnimation } from '@shared/animations/routerTransition'; import { AppComponentBase } from '@shared/common/app-component-base'; import { ControllerRouteDetailServiceProxy, UpdateRouteInput,VehicleInput,UpdateRouteByStopInput, RouteServiceProxy, NameValueDto,ShippingPackageServiceProxy,CreateOptimizeInputDto, DriverListInput, Route4MeServiceProxy, RouteOptimizationServiceProxy, OptimizeRouteInput, GoogleDirectionOptimizationServiceProxy, OptimizeByRouteIdInput, ControllerGetDriverListDto, UpdateEtaInput, GetEditCountDetails,UpdateRouteId } from '@shared/service-proxies/service-proxies'; import { RouteDetailModal } from './route-detail-modal.component'; import { MovePendingOrder } from './move-order-modal.component'; import { CreateIncidentsModal } from './create-incidents-modal.component'; import { EditCountNotes } from './edit-count-notes.component'; import { AppSessionService } from '@shared/common/session/app-session.service'; import * as moment from 'moment'; import { Table } from "primeng/table"; import { LazyLoadEvent } from "primeng/primeng"; import { Paginator } from 'primeng/components/paginator/paginator'; import { HttpClient } from '@angular/common/http'; import { finalize } from 'rxjs/operators'; import * as _ from 'lodash'; import { MessageService } from 'primeng/api'; import * as signalR from '@aspnet/signalr'; import {Location} from '@angular/common'; import { LabRouteDetailComponent } from './lab-route-detail.component'; import { FBXRouteDetailComponent } from './fbx-route-detail.component'; import { CommonLookupModalComponent } from '@app/shared/common/lookup/common-lookup-modal.component'; import { AssignStopModalComponent } from '@app/shared/common/lookup/assignStop-modal.component'; import { EntityTypeHistoryModalComponent } from '@app/shared/common/entityHistory/entity-type-history-modal.component'; import {BreadcrumbModule} from 'primeng/breadcrumb'; import {MenuItem} from 'primeng/api'; import { HFRouteDetailComponent } from './hf-route-detail.component'; import { AppLocalizationService } from '@app/shared/common/localization/app-localization.service'; declare var $: any; declare var jquery: any; @Component({ templateUrl: 'route-detail.component.html', encapsulation: ViewEncapsulation.None, styleUrls: ['./route-detail.component.less'], animations: [appModuleAnimation()], selector: 'routeDetailComponent', providers: [MessageService] }) export class RouteDetailComponent extends AppComponentBase implements OnInit { saving = false; routeId: number = null; details: boolean = false; _isLab: boolean = false; _isFbx: boolean = false; routeCode: string; vehicleName: string; loadDate: string; locationName: string; reload: any; editNotes: string = ""; editCountDetails: GetEditCountDetails = new GetEditCountDetails(); route: UpdateRouteInput = new UpdateRouteInput(); routeDetailTenant:string = 'STANDARD'; totalItems: any; packages: Array<{id: number, name: string}> = new Array(); OptimizeInput = new CreateOptimizeInputDto(); tableDetails:any; driverListInput:any; data:any; stopInput:any; userId: any; routeName: any; updateOnly = false; updateRouteId: number = 0; updateLocationId: number = 0; updateRouteTemplateId: number = 0; editCount: boolean = false; routeBuilder: boolean = false; loadDateString: string; @ViewChild('driversList', {static: true}) driversList: CommonLookupModalComponent; @ViewChild('stopList', {static: true}) stopList: AssignStopModalComponent; @ViewChild('routeDetailModal', { static: true }) routeDetailModal: RouteDetailModal; @ViewChild('movePendingOrderModal', { static: true }) movePendingOrderModal: MovePendingOrder; @ViewChild('createIncidentsModal', { static: true }) createIncidentsModal: CreateIncidentsModal; @ViewChild('editCountNotes', { static: true }) editCountNotesModal: EditCountNotes; @ViewChild('labRouteDetail' , { static: false}) public labRouteDetail: LabRouteDetailComponent; @ViewChild('hfRouteDetail' , { static: false}) public hfRouteDetail: HFRouteDetailComponent; @ViewChild('fbxRouteDetail' , { static: false}) public fbxRouteDetail: FBXRouteDetailComponent; // @Input() hfRouteDetails: TemplateRef; @Input() labRouteDetails: any; @ViewChild("dataTable", { static: true }) dataTable: Table @ViewChild("paginator", { static: true }) paginator: Paginator @Output() reloadTable: EventEmitter = new EventEmitter(); @ViewChild('entityTypeHistoryModal', { static: true }) entityTypeHistoryModal: EntityTypeHistoryModalComponent; _entityTypeFullName = 'SprintTek.Shipping.Routes.Route'; entityHistoryEnabled = false; labRouteRefresh: Function; localRouteIds = []; optimizer: boolean = false; locationId:any; toll: boolean = false; highways: boolean = false;; ferries: boolean = false; indoor: boolean = false;; // locations: LocationListDto[] = []; items: MenuItem[]; handOffChecker: boolean; constructor( injector: Injector, private id: ActivatedRoute, private _controllerRouteDetails: ControllerRouteDetailServiceProxy, private _controllerRoutePackages: ShippingPackageServiceProxy, private _controllerRoute: RouteServiceProxy, private _appSessionService: AppSessionService, private messageService: MessageService, private _location:Location, private _route4me : Route4MeServiceProxy, private router: Router, private optimization: RouteOptimizationServiceProxy, private _googleOptimization: GoogleDirectionOptimizationServiceProxy, private _changeDetector: ChangeDetectorRef, private _appLocalizationService: AppLocalizationService, // private _routeService: RouteServiceProxy ) { super(injector); this._isLab = abp.features.isEnabled('App.ControllerRouteManagementFeature.RouteDetailsManagementFeature'); // this._isFbx = abp.features.isEnabled('App.FBXFeature'); if(this._isLab){ this.routeDetailTenant = 'LAB'; } // if(this._isFbx){ // this.routeDetailTenant = 'FBX'; // } this.id.paramMap.subscribe(params => { this.routeId = Number(params.get('id')); }); } ngOnInit(): void { this.routeBuilder = abp.features.isEnabled('App.RouteBuilder'); this.setIsEntityHistoryEnabled(); this.routeName = localStorage.getItem('RouteName'); //this.primengTableHelper.showLoadingIndicator(); // this.getDetails(); // const connection = new signalR.HubConnectionBuilder() // .configureLogging(signalR.LogLevel.Information) // .withUrl("http://localhost:65302/location") // .build(); // connection.start().then(function () { // console.log('Connecteddfsdfsdf!'); // }).catch(function (err) { // return console.error(err.toString()); // }); // connection.on("GetLocation", (latitude: string,longitude: string) => { // this.messageService.add({ severity: 'success', summary: 'Success Message', detail: 'Notificiation' }); // }); this.locationId = parseInt(localStorage.getItem('operatingLocationId')); this.driversList.configure({ title: this.l('Assign Driver'), type:'assignDriver', dataSource: (skipCount: number, maxResultCount: number, filter: string, tenantId?: number, locationId?:number) => { let input = new DriverListInput(); input.filter = filter; input.maxResultCount = maxResultCount; input.skipCount = skipCount; input.tenantId = tenantId; input.locationId = parseInt(localStorage.getItem('operatingLocationId')); return this._controllerRouteDetails.assignDriversList(input); } }); this.stopList.configure({ title: this.l('Select Delivery Address'), dataSource: (skipCount: number, maxResultCount: number, filter: string, tenantId?: number, locationId?:number) => { // let input = any; // input.filter = filter; // input.maxResultCount = maxResultCount; // input.skipCount = skipCount; // input.tenantId = tenantId; // input.locationId = parseInt(localStorage.getItem('operatingLocationId')); return this._controllerRouteDetails.getAllStopsList(tenantId,parseInt(localStorage.getItem('operatingLocationId')),maxResultCount,skipCount,filter); } }); this._changeDetector.detectChanges(); } ngAfterViewChecked() { } openBuilder() { this.router.navigate([]).then(result => { window.open('/app/sprintship/route-builder/' + this.routeId, '_blank'); }); } private setIsEntityHistoryEnabled(): void { let customSettings = (abp as any).custom; this.entityHistoryEnabled = customSettings.EntityHistory && customSettings.EntityHistory.isEnabled && _.filter(customSettings.EntityHistory.enabledEntities, entityType => entityType === this._entityTypeFullName).length === 1; } showHistory(role: UpdateRouteInput): void { this.entityTypeHistoryModal.show({ entityId: role.id.toString(), entityTypeFullName: this._entityTypeFullName, entityTypeDescription: "Route - " +this.routeName }); } ngAfterViewInit() { $('.kt-select2').select2(); $('.selectpicker').selectpicker(); this.getDetails(); } getDetails() { this.items = []; this._controllerRouteDetails.getControllerRouteDetailHeader(this.routeId) .subscribe(result => { // this.routeCode = result.routeTemplate.name; // this.route.vehicleId = result.vehicleId; // this.route.completion = result.completion; // this.route.departure = result.departure; // this.route.loadDate = result.loadDate; // this.route.locked = result.locked; // this.route.routeTemplateId = result.routeTemplateId; // this.route.locationId = result.locationId; // this.route.id = this.routeId; // this.locationName = result.location.name; // this.userId = result.vehicle==undefined ? 0 : result.vehicle.user==undefined ? 0 : result.vehicle.userId // if (result.vehicle) { // this.vehicleName = result.vehicle.user.name + " " + result.vehicle.user.surname; // } this.data = result; // this.loadDate = localStorage.getItem('loadDate'); // this.labRouteDetails = result.routeTemplate.name; if(result!=null){ this.checkOptimizer(result.locationId); // if(result!=null){ // for(var data in result.parentRouteList){ // var url = AppConsts.appBaseUrl + '/app/sprintship/controller-routes-details/' +result.parentRouteList[data].routeId; // this.items.push({label: result.parentRouteList[data].routeCode, url: url }) // } // } this.routeName = result.parentRouteList[result.parentRouteList.length -1].routeCode; this.loadDateString =result.loadDateString; this.vehicleName = result.driver; this.route.locationId = result.locationId; this.locationName = result.location.name; this.editNotes = result.notes ? result.notes: ""; this.routeCode = result.routeTemplate.name; this.labRouteDetail.locationName = this.locationName; localStorage.setItem('RouteName', this.routeName); } }); if(this._isLab){ this._controllerRouteDetails.getEditCountDetails(this.routeId) .subscribe(result => { this.editCountDetails = result; }) } } checkOptimizer(locationId){ if(!this._isLab){ this._googleOptimization.getRuleByLocation(locationId,undefined,undefined) .subscribe(res=>{ if(res != null && res != undefined){ this.optimizer = true this.toll = res[0].tolls; this.highways = res[0].highways; this.ferries = res[0].ferries; this.indoor = res[0].indoor; } }); }else{ this.updateOnly = true; } } updateETAOnly(locationId, routeTemplateId, routeId){ this.message.confirm( 'Are you sure you want to update the ETA of this route?', '', (isConfirmed) => { if (isConfirmed) { this.spinnerService.show(); let input = new UpdateEtaInput(); input.locationId = locationId; input.routeId = routeId; input.routeTemplateId = routeTemplateId this.optimization.updateEta(input).subscribe(r=>{ let x = new OptimizeRouteInput({routeId : routeId}); this.optimization.reSortByEtaLab(x).subscribe(result=>{ this.refreshPage(); this.notify.info(this.l('SavedSuccessfully')); }); }); } } ); } refreshPage(){ this.getDetails(); if(this._isLab){ localStorage.setItem('checkHandOffRoute', this.labRouteDetail.handOffChecker); // this.labRouteDetail.getLabPackages(); this.labRouteDetail.getLabContainers(); this.labRouteDetail.getRouteDetails(); this.editCount = false; } else if(this._isFbx) { this.fbxRouteDetail.getRouteDetails(); } else{ this.hfRouteDetail.getRouteDetails(); this.hfRouteDetail.getOrderListKpi(); } } updateRoute() { this.route.id = this.routeId; this.route.vehicleId = this.data.vehicleId; this._controllerRoute.updateRoute(this.route) .pipe(finalize(() => this.saving = false)) .subscribe(() => { this.refreshPage(); this.notify.info(this.l('SavedSuccessfully')); }); } setDeparture() { if (!this.route.locked) { if (this.route.departure) { this.route.departure = null; } else { this.route.departure = moment.utc(moment(new Date()).format('YYYY-MM-DD h:m a')); } this.updateRoute(); } else { this.notify.info(this.l('Unlocked Loadlist First')); } } setCompletion() { this.spinnerService.show(); if (!this.route.locked) { if (this.route.completion == null) { let input = new UpdateRouteByStopInput() input.contactId = undefined, input.routeId = this.routeId, input.loadDate = moment.utc(new Date()); this._controllerRouteDetails.updateRouteByStop(input).subscribe(result => { this.notify.info(this.l('SavedSuccessfully')); this.spinnerService.hide() this.getDetails(); this.refreshPage(); }); } else { let input = new UpdateRouteByStopInput() input.contactId = undefined; input.routeId = this.routeId; input.routeComplete = true; input.loadDate = moment.utc(new Date()); this._controllerRouteDetails.updateRouteByStop(input).subscribe(result => { this.notify.info(this.l('SavedSuccessfully')); this.spinnerService.hide(); this.refreshPage(); }); } } else { this.notify.info(this.l('Unlocked Loadlist First')); this.spinnerService.hide(); } } optimizeRoute(routeID){ // this.spinnerService.show(); // let input = new OptimizeByRouteIdInput(); // input.routeId = routeID; // this._googleOptimization.optimizeByRouteId(input).subscribe((result) => { // this.notify.info(this.l('Route has been re-optimized')); // this.refreshPage(); // }); this.spinnerService.show(); let input = new OptimizeByRouteIdInput(); input.routeId = this.routeId; this.optimization.standardOptimization(input) .subscribe(r=>{ this.getDetails(); this.refreshPage(); this.spinnerService.hide(); this.notify.info(this.l('SavedSuccessfully')); }); } loadTable($event) { this.reload = $event; } goBack() { this._location.back(); } onShown() { } removeStops() { this.message.confirm( '', '', (isConfirmed) => { if (isConfirmed) { if(this._isLab){ this.labRouteDetail.removeStop(); } if(this._isFbx){ this.fbxRouteDetail.removeStop(); } } } ); } printRouteSheet(){ if(localStorage.getItem('routeIds')==null){ this.localRouteIds = []; this.localRouteIds.push(this.routeId) localStorage.setItem('routeIds', JSON.stringify(this.localRouteIds)); }else{ localStorage.removeItem('routeIds'); this.localRouteIds = []; this.localRouteIds.push(this.routeId) localStorage.setItem('routeIds', JSON.stringify(this.localRouteIds)); } if(this.routeDetailTenant == 'LAB'){ window.open('/app/sprintship/print-route-sheet', '_blank'); }else{ window.open('/app/sprintship/route-print', '_blank'); } } assignDriverModal(record:any):void{ this.driversList.tenantId = record.id; this.driversList.show(); } updateRouteByVehicle(item:NameValueDto):void{ this.spinnerService.show(); let input = new VehicleInput(); input.driverId = parseInt(item.value); input.routeId = this.routeId; this._controllerRouteDetails.updateRouteByVehicleId(input).subscribe(result=>{ this.refreshPage(); }); } newIncident():void{ window.open('app/sprintship/create-incidents', '_blank'); } markAsDeliveredModal(record:any):void{ this.spinnerService.show() if(this.route.completion == null){ // this.stopList.tenantId = record.id; this.stopList.show(); this.getDetails(); } else{ let input = new UpdateRouteByStopInput() input.contactId = undefined, input.routeId = this.routeId, input.routeComplete = true, input.loadDate = undefined this._controllerRouteDetails.updateRouteByStop(input).subscribe(result=>{ this.notify.info(this.l('UnmarkDelivered')); this.spinnerService.hide() this.getDetails(); this.refreshPage(); }); } } updateRouteByStop(item:NameValueDto):void{ this.spinnerService.show() let input = new UpdateRouteByStopInput(); input.contactId = parseInt(item.value); input.routeId = this.routeId; input.loadDate = moment($('input[name=completionDate]').val()); this._controllerRouteDetails.updateRouteByStop(input).subscribe(result=>{ this.notify.info(this.l('MarkDelivered')); this.spinnerService.hide() this.getDetails(); this.refreshPage(); }); } openMap(userId, routeId) { if(userId == null){ userId = 0; } // window.open('/app/sprintship/locator/'+routeId+'/'+this.filters); this.router.navigate([]).then(result => { window.open('/app/sprintship/locator/' + userId + '/' + routeId, '_blank'); }); } showEditCount(){ let ids = this.labRouteDetail.sprintIdsList; if(ids != null){ this.labRouteDetail.countOrder(); this.labRouteDetail._isEditShow = false; this.editCount = false; //this.refreshPage(); // let count = this.labRouteDetail.resultCountOrder; // if(count == 0){ // this.refreshPage(); // this.message.info("There are no package count in this order/s","Unable to Edit Count"); // } } else{ this.labRouteDetail._isEditShow = true; this.editCount = true; } //this.labRouteDetail.editCount(); //this.editCount = this.labRouteDetail._isEditShow; } cancel(){ this.labRouteDetail.cancelEditCount(); this.editCount = this.labRouteDetail._isEditShow; // this.labRouteDetail.cancelEditCount(); // this.editCount = this.labRouteDetail._isEditShow; this.refreshPage(); } saveModal(notes: string,isView:boolean){ let ids = this.labRouteDetail.sprintIdsList; var cntIds = ids ? ids.length : '0'; if(cntIds != 0 && !isView){ this.editCountNotesModal.show(notes, isView); } else if(isView){ this.editCountNotesModal.show(notes, isView); } else{ this.message.info(this._appLocalizationService.l('EditCountNothingToUpdate'),this._appLocalizationService.l('EditCount')); } } save(notes: any){ this.spinnerService.show(); this.labRouteDetail.saveEditCount(notes).subscribe(result=>{ this.editCount = false; this.editCountDetails = result; this.editNotes = result.notes; }); } createOrUpdate(url: any, id?: number){ if(id != null){ var myurl = `${url}/${id}`; }else{ var myurl = `${url}`; } this.router.navigateByUrl(myurl); } }