import { Component, ViewChild, Injector, Output, EventEmitter, Input, OnInit } from '@angular/core'; import { ModalDirective, TabsetComponent } from 'ngx-bootstrap'; import { finalize, isEmpty } from 'rxjs/operators'; import { RouteDefinitionsServiceProxy, CreateOrEditRouteDefinitionDto, RouteTypesServiceProxy, RouteDefinitionRouteTypeLookupTableDto, ContactServiceProxy, OrganizationUnitDto, OrderNotificationsServiceProxy, OrganizationUnitServiceProxy, ContactListDto, LocationServiceProxy, LocationListDto, RouteTemplateTypeServiceProxy, RouteTemplateTypeListDto, UserServiceProxy, RoleServiceProxy, DriversServiceProxy, UserListRoleDto, UserListDto, RouteStopsServiceProxy, RouteStopDto, GetRouteStopForViewDto, GetManagerListDto, WillCallServiceServiceProxy, GetDriverListDto, OrderIncidentsServiceProxy, LocationNameDto, GetUnassignedDrivers, GetDriverList, RouteTemplateServiceProxy, GetAllRouteStopsInput, RouteNotificationRecipientDto, StopTypeCode } from '@shared/service-proxies/service-proxies'; import { AppComponentBase } from '@shared/common/app-component-base'; import * as moment from 'moment'; import { RouteDefinitionRouteTypeLookupTableModalComponent } from './routeDefinition-routeType-lookup-table-modal.component'; import { AppSessionService } from '@shared/common/session/app-session.service'; import { CommonLookupModalComponent } from '@app/shared/common/lookup/common-lookup-modal.component'; import { truncate } from 'fs'; import { NullVisitor } from '@angular/compiler/src/render3/r3_ast'; declare var KTWizard: any; declare var $: any; declare var KTApp: any; @Component({ selector: 'createOrEditRouteDefinitionModal', templateUrl: './create-or-edit-routeDefinition-modal.component.html', styleUrls: ['./create-or-edit-routeDefinition-modal.component.less'] }) export class CreateOrEditRouteDefinitionModalComponent extends AppComponentBase implements OnInit{ @ViewChild('routeStartList', {static: true}) routeStartList: CommonLookupModalComponent; @ViewChild('routeStopList', {static: true}) routeStopList: CommonLookupModalComponent; @ViewChild('meetPointList', {static: true}) meetPointList: CommonLookupModalComponent; @ViewChild('driverList', {static: true}) driverList: CommonLookupModalComponent; @ViewChild('managerList', {static: true}) managerList: CommonLookupModalComponent; @ViewChild('routeDefTab', { static: false }) staticTabs: TabsetComponent; @ViewChild('createOrEditModal', { static: true }) modal: ModalDirective; @ViewChild('routeDefinitionRouteTypeLookupTableModal', { static: true }) routeDefinitionRouteTypeLookupTableModal: RouteDefinitionRouteTypeLookupTableModalComponent; @Output() modalSave: EventEmitter = new EventEmitter(); maxcount = 1000; active = false; saving = false; activeTabIndex: number = 0; routeDefinition: CreateOrEditRouteDefinitionDto = new CreateOrEditRouteDefinitionDto(); locations: LocationNameDto[] = []; templateTypes: RouteTemplateTypeListDto[] = []; users: GetDriverList[] = []; contacts: ContactListDto[] = []; routeTypes: any; routeStops: GetRouteStopForViewDto[] = []; isEnabledLaboratory : boolean routeTemplateId : any; routeTypeRouteTypeCode = ''; routeTemplateName = ''; currentDateTime: Date; eta: any; cutOff: any; activeStatus: boolean; drivers: Array; contact_drivers: Array; selectedDrivers: Array; managerId: number; getManagerListDto: GetManagerListDto[]; appSession: AppSessionService; managers: any; allOrganizationUnits: OrganizationUnitDto[]; supervisors: RouteNotificationRecipientDto[] = []; activeTab: boolean = false; addSupervisors: any; allUsers: UserListDto[]; delete: any; isEmail: boolean; isSMS: boolean; supervisorList: Array = []; startTime: any; endTime: any; txtRouteStopFilter : string; txtMeetPointFilter : string; txtRouteStartFilter : string; routeStopId : number; routeStartId : number; meetPointId : number; searchRouteStop : boolean; searchMeetPoint : boolean; showSearchOnStop : boolean; showSearchOnMeetpoint : boolean showSearchOnStart : boolean; mondayDriverFilter tuesdayDriverFilter wednesdayDriverFilter thursdayDriverFilter fridayDriverFilter saturdayDriverFilter sundayDriverFilter sundayManagerFilter mondayManagerFilter tuesdayManagerFilter wednesdayManagerFilter thursdayManagerFilter fridayManagerFilter saturdayManagerFilter sundaySupervisorFilter mondaySupervisorFilter tuesdaySupervisorFilter wednesdaySupervisorFilter thursdaySupervisorFilter fridaySupervisorFilter saturdaySupervisorFilter searchDay : string; userField : string; isRunning: boolean; isRunningRouteFeature:boolean = false; hasRouteStop: boolean = false; startTimeTypeCheck:boolean = false; startTimeType = 0; startTimeMins = 0; endTimeTypeCheck:boolean = false; endTimeType = 0; endTimeMins = 0; constructor( injector: Injector, private _routeDefinitionsServiceProxy: RouteDefinitionsServiceProxy, private _routeTemplateServiceProxy: RouteTemplateServiceProxy, private _contactServiceProxy: ContactServiceProxy, private _driverService: DriversServiceProxy, private _routeStopsService: RouteStopsServiceProxy, private _locationServiceProxy: LocationServiceProxy, private _routeTemplateTypeServiceProxy: RouteTemplateTypeServiceProxy, private _routeTypesServiceProxy: RouteTypesServiceProxy, private _willCallService: WillCallServiceServiceProxy, private _orderIncidentAppService: OrderIncidentsServiceProxy, private _orderNotificationsServiceProxy: OrderNotificationsServiceProxy, private _organizationUnitService: OrganizationUnitServiceProxy ) { super(injector); } ngOnInit(): void { this.routeStopsModalInit(); this.driverListModalInit(); this.isRunningRouteFeature = abp.features.isEnabled('App.RunningRoute'); } routeStopsModalInit() { this.routeStartList.configure({ title: this.l('Select stop'), dataSource: (skipCount: number, maxResultCount: number, filter: string, tenantId?: number, locationId?:number) => { let input = new GetAllRouteStopsInput(); input.filter = filter; input.maxResultCount = maxResultCount; input.skipCount = skipCount; input.stopType = StopTypeCode.StartPoint; return this._routeStopsService.showPagedRouteStop(input); } }); this.routeStopList.configure({ title: this.l('Select stop'), dataSource: (skipCount: number, maxResultCount: number, filter: string, tenantId?: number, locationId?:number) => { let input = new GetAllRouteStopsInput(); input.filter = filter; input.maxResultCount = maxResultCount; input.skipCount = skipCount; input.stopType = StopTypeCode.EndPoint; return this._routeStopsService.showPagedRouteStop(input); } }); this.meetPointList.configure({ title: this.l('Select stop'), dataSource: (skipCount: number, maxResultCount: number, filter: string, tenantId?: number, locationId?:number) => { let input = new GetAllRouteStopsInput(); input.filter = filter; input.maxResultCount = maxResultCount; input.skipCount = skipCount; input.stopType = StopTypeCode.MeetPoint; return this._routeStopsService.showPagedRouteStop(input); } }); } driverListModalInit(){ this.driverList.configure({ title: this.l('Select driver'), dataSource: (skipCount: number, maxResultCount: number, filter: string, tenantId?: number, locationId?:number) => { let input = {filter,maxResultCount,skipCount}; input.filter = filter; input.maxResultCount = maxResultCount; input.skipCount = skipCount; return this._driverService.getPagedDriverList( input.filter,undefined,input.skipCount,input.maxResultCount); } }); } managerListModalInit(){ this.managerList.configure({ title: this.l('Select ') + this.userField, dataSource: (skipCount: number, maxResultCount: number, filter: string, tenantId?: number, locationId?:number) => { let input = {filter,maxResultCount,skipCount}; input.filter = filter; input.maxResultCount = maxResultCount; input.skipCount = skipCount; return this._orderIncidentAppService.getPagedManagerList(input.filter, 0, undefined, input.skipCount, input.maxResultCount); } }); } show(routeDefinitionId?: number): void { this.isEnabledLaboratory = abp.features.isEnabled('App.ControllerRouteManagementFeature.RouteDetailsManagementFeature'); let day = []; this.activeStatus = true this.supervisors = []; this.allOrganizationUnits = []; this.allUsers = []; this.supervisorList = []; this.txtRouteStartFilter = ''; this.txtRouteStopFilter = ''; this.routeStopId = null; this.routeStartId = null; this.startTime = new Date(moment().format('YYYY-MM-DD') + ' ' + '"00:00:00'); this.endTime = new Date(moment().format('YYYY-MM-DD') + ' ' + '"00:00:00' ); $('.organization-unit').select2(); $('.user').select2(); this.showSearchOnStop = true; this.showSearchOnStart = true; this.showSearchOnMeetpoint = true; this._orderNotificationsServiceProxy.getAllUserForTableDropdown().subscribe(result => { this.allUsers = result; }); this._orderNotificationsServiceProxy.getAllOrgUnitsForTableDropdown().subscribe(result => { this.allOrganizationUnits = result; }); if (!routeDefinitionId) { this.routeDefinition = new CreateOrEditRouteDefinitionDto(); this.getAllDropDown(); this.routeDefinition.id = routeDefinitionId; this.routeTypeRouteTypeCode = ''; this.routeTemplateName = ''; this.eta = ''; this.initDriverFields(); this.initManagerFields() this.endTimeTypeCheck = true; this.startTimeTypeCheck = true; this.endTimeMins = 0; this.startTimeMins = 0; // // this.activeTabIndex = 0; this.active = true; this.modal.show(); } else { this._routeDefinitionsServiceProxy.getRouteDefinitionForEdit(routeDefinitionId).subscribe(result => { this.getAllDropDown(); this.routeTemplateId = result.routeDefinition.routeTemplateId; this.routeDefinition = result.routeDefinition; this.routeTypeRouteTypeCode = result.routeTypeRouteTypeCode; //this.routeDefinition.routeCode = result.routeTypeRouteTypeCode; this.routeDefinition.routeCode = result.routeTemplateName; //this.routeDefinition.eta = this.routeDefinition.eta; this.startTimeMins = result.routeDefinition.startTimeMins; if(result.routeDefinition.startTimeType == undefined || result.routeDefinition.startTimeType == 0){ this.startTimeTypeCheck = true; }else{ this.startTimeTypeCheck = false; } this.endTimeMins = result.routeDefinition.endTimeMins; if(result.routeDefinition.endTimeType == undefined || result.routeDefinition.endTimeType == 0){ this.endTimeTypeCheck = true; }else{ this.endTimeTypeCheck = false; } this.startTime = new Date(moment().format('YYYY-MM-DD') + ' ' + result.routeDefinition.startTime); this.endTime = new Date(moment().format('YYYY-MM-DD') + ' ' + result.routeDefinition.endTime ); this.isRunning = result.routeDefinition.isRunning; this.eta = result.routeDefinition.eta.toDate(); this.cutOff = result.routeDefinition.cutOff.toDate(); //moment(moment(this.currentDateTime + ' ' + result.routeDefinition.cutOff).toDate(); //this.routeDefinition.eta = this.eta; this.routeDefinition.cutOff = this.cutOff; if (this.routeDefinition.inactive == true) { this.activeStatus = false; } else { this.activeStatus = true; } if(result.routeDefinition.routeNotificationRecipients != undefined) { this.supervisors = result.routeDefinition.routeNotificationRecipients; let s = this; setTimeout(() => { $('.organization-unit').on('select2:select', function (e) { s.updateUnits($(e.currentTarget).attr('id'), $(e.currentTarget).val()); }); $('.user').on('select2:select', function (e) { s.updateUsers($(e.currentTarget).attr('id'), $(e.currentTarget).val()); }); }, 100); } if(result.routeDefinition.routeStartContactId != null && result.routeDefinition.routeStartContactId != 0){ this._routeStopsService.getRouteStop(result.routeDefinition.routeStartContactId) .subscribe(res => { if(res.routeStop != undefined){ this.showSearchOnStart = false; this.txtRouteStartFilter = res.routeStop.company + ' - ' + res.contactAddress; this.routeStartId = result.routeDefinition.routeStartContactId; } else { this.routeStartId = null; } }); } if(result.routeDefinition.defaultContactId != null && result.routeDefinition.defaultContactId != 0) { this._routeStopsService.getRouteStop(result.routeDefinition.defaultContactId) .subscribe(res => { if(res.routeStop != undefined){ this.showSearchOnStop = false; this.txtRouteStopFilter = res.routeStop.company + ' - ' + res.contactAddress; this.routeStopId = result.routeDefinition.defaultContactId; this.hasRouteStop = (res.routeStop.id <= 0) ? false: true; } else { this.routeStopId = null; } }); } if(result.routeDefinition.meetpointContactId != null && result.routeDefinition.meetpointContactId != 0) { this._routeStopsService.getRouteStop(result.routeDefinition.meetpointContactId) .subscribe(res => { if(res.routeStop != undefined){ this.showSearchOnMeetpoint = false; this.txtMeetPointFilter = res.routeStop.company + ' - ' + res.contactAddress; this.meetPointId = result.routeDefinition.meetpointContactId; //this.hasRouteStop = (res.routeStop.id <= 0) ? false: true; } else { this.meetPointId = null; } }); } //this.routeStartId = result.routeDefinition.routeStartContactId; //this.routeStopId = result.routeDefinition.defaultContactId; this.initDriverFields() this.initManagerFields() this.activeTabIndex = 0; this.active = true; this.modal.show(); }); } } getRouteStop(routeStopFilter : any) { this.searchRouteStop = true; this.routeStopList.show(); this.routeStopList.filterText = routeStopFilter; } getRouteStart(routeStartFilter : any) { this.searchRouteStop = false; this.routeStartList.show(); this.routeStartList.filterText = routeStartFilter; } getMeetPoint(meetPointFilter : any) { this.searchMeetPoint = true; this.meetPointList.show(); this.meetPointList.filterText = meetPointFilter; } selectRouteStop(item) { var resultId = item.value; var name = item.name if (this.searchMeetPoint) { this.meetPointId = resultId; this.txtMeetPointFilter = name; this.searchMeetPoint = false; this.showSearchOnMeetpoint = false; } else { if(this.searchRouteStop){ this.routeStopId = resultId; this.txtRouteStopFilter = name; this.searchRouteStop = false; this.showSearchOnStop = false; } else { this.routeStartId = resultId; this.txtRouteStartFilter = name; this.showSearchOnStart = false; } } } onShown(){ this.toggleRouteStartAndStop() } toggleRouteStartAndStop(){ let toggleStartActive = (bool) => { return this.routeStartActiveToggle(bool) } $('#routeStartOption').on('select2:select', function (e) { if($('#routeStartOption').val() == '0'){ toggleStartActive(false) } else{ toggleStartActive(true) } }); let toggleStopActive = (bool) => { return this.routeStopActiveToggle(bool) } $('#routeStopOption').on('select2:select', function (e) { if($('#routeStopOption').val() == '0'){ toggleStopActive(false) } else{ toggleStopActive(true) } }); } clearRouteStop(){ this.txtRouteStopFilter = ''; this.routeStopId = null; this.showSearchOnStop = true; } clearRouteStart(){ this.txtRouteStartFilter = ''; this.routeStartId = null; this.showSearchOnStart = true; } clearMeetPoint(){ this.txtMeetPointFilter = ''; this.meetPointId = null; this.showSearchOnMeetpoint = true; } save(): void { let drivers = []; this.saving = true; //this.currentDateTime = moment(moment().toISOString()).toDate(); this.routeDefinition.locationId = Number((document.getElementById('txtLocation')).value); // this.routeDefinition.defaultContactId = Number((document.getElementById('routeStop')).value); this.routeDefinition.defaultContactId = this.routeStopId == null? null : this.routeStopId ; this.routeDefinition.meetpointContactId = this.meetPointId == null ? null : this.meetPointId; this.routeDefinition.hasRouteStop = this.hasRouteStop; // this.routeDefinition.routeStartContactId = Number((document.getElementById('routeStart')).value); this.routeDefinition.routeStartContactId = this.routeStartId == null? null : this.routeStartId ; this.routeDefinition.managerId = Number((document.getElementById('selectedManager')).value) == 0 ? null : Number((document.getElementById('selectedManager')).value); this.routeDefinition.assignedById = this.appSession.userId; if(this.endTime.toString() == 'Invalid Date'){ let nd = new Date(0,0,0,0,0,0); this.routeDefinition.endTime = nd.toLocaleTimeString('en-US', { hour12: true, hour: "numeric", minute: "numeric", second: "numeric" }) as any; }else{ this.routeDefinition.endTime = new Date(this.endTime).toLocaleTimeString('en-US', { hour12: true, hour: "numeric", minute: "numeric", second: "numeric" }) as any; } if(this.startTime.toString() == 'Invalid Date'){ let nd = new Date(0,0,0,0,0,0); this.routeDefinition.startTime = nd.toLocaleTimeString('en-US', { hour12: true, hour: "numeric", minute: "numeric", second: "numeric" }) as any; }else{ this.routeDefinition.startTime = new Date(this.startTime).toLocaleTimeString('en-US', { hour12: true, hour: "numeric", minute: "numeric", second: "numeric" }) as any; } this.routeDefinition.defaultUserId = this.routeDefinition.sundayDriverId != null && this.routeDefinition.sundayDriverId != 0 ? this.routeDefinition.sundayDriverId : this.routeDefinition.mondayDriverId != null && this.routeDefinition.mondayDriverId != 0 ? this.routeDefinition.mondayDriverId : this.routeDefinition.tuesdayDriverId != null && this.routeDefinition.tuesdayDriverId != 0 ? this.routeDefinition.tuesdayDriverId : this.routeDefinition.wednesdayDriverId != null && this.routeDefinition.wednesdayDriverId != 0 ? this.routeDefinition.wednesdayDriverId : this.routeDefinition.thursdayDriverId != null && this.routeDefinition.thursdayDriverId != 0 ? this.routeDefinition.thursdayDriverId : this.routeDefinition.fridayDriverId != null && this.routeDefinition.fridayDriverId != 0 ? this.routeDefinition.fridayDriverId : this.routeDefinition.saturdayDriverId != null && this.routeDefinition.saturdayDriverId != 0 ? this.routeDefinition.saturdayDriverId : null; this.routeDefinition.routeTemplateTypeId = 1; if(this.isEnabledLaboratory){ this.routeDefinition.routeTypeId = Number((document.getElementById('routeType')).value); } //this.eta = moment(moment(this.routeDefinition.eta).toISOString()).toDate(); //this.routeDefinition.eta = moment.utc(moment(this.currentDateTime).format('YYYY-MM-DD') + ' ' + moment(this.eta).format('HH:mm:ss')); this.routeDefinition.eta = this.eta; //alert(moment(moment(this.currentDateTime).format('YYYY-MM-DD') + ' ' + moment(this.eta).format('HH:mm:ss'))); // let cutOffS = moment(moment(this.routeDefinition.cutOff).format('HH:mm:ss')); this.routeDefinition.cutOff = this.routeDefinition.cutOff; //console.log(this.supervisors); if(this.supervisors.length != 0) { //this.routeDefinition.supervisors = this.supervisors; for (var i = 0; i < this.supervisors.length; i++) { let a = new RouteNotificationRecipientDto({ isEmail: this.supervisors[i].isEmail, tenantId: null, isActive: this.supervisors[i].isActive, emailAddress: this.supervisors[i].emailAddress, code: this.supervisors[i].code, organizationUnitId: this.supervisors[i].organizationUnitId, userId: this.supervisors[i].userId, routeTemplateId: this.supervisors[i].routeTemplateId, id: this.supervisors[i].id, isSMS:this.supervisors[i].isSMS }); this.supervisorList.push(a); } this.routeDefinition.routeNotificationRecipients = this.supervisorList; } //console.log(this.routeDefinition); if (this.activeStatus == true) { this.routeDefinition.inactive = false; } else { this.routeDefinition.inactive = true; } this.routeDefinition.isRunning = this.isRunning; this.routeDefinition.startTimeMins = this.startTimeMins; if(this.startTimeTypeCheck){ this.routeDefinition.startTimeType = 0; }else{ this.routeDefinition.startTimeType = 1; } this.routeDefinition.endTimeMins = this.endTimeMins; if(this.endTimeTypeCheck){ this.routeDefinition.endTimeType = 0; }else{ this.routeDefinition.endTimeType = 1; } if(this.routeDefinition.routeTypeId === 0) { this.saving = false; (document.getElementById('routeTypeDiv')).style.color="#fd397a"; } else if(this.routeDefinition.routeStartContactId === 0 && this.routeDefinition.routeStartInactive == false) { this.saving = false; (document.getElementById('routeStartDiv')).style.color="#FF3300"; } else if(this.routeDefinition.defaultContactId === 0) { this.saving = false; (document.getElementById('routeStopDiv')).style.color="#FF3300"; } else if(this.routeDefinition.locationId === 0) { this.saving = false; (document.getElementById('locationDiv')).style.color="#FF3300"; } else { this._routeDefinitionsServiceProxy.createOrEdit(this.routeDefinition) .pipe(finalize(() => { this.saving = false; })) .subscribe(() => { this.notify.info(this.l('SavedSuccessfully')); this.close(); this.modalSave.emit(null); }); } } openSelectRouteTypeModal() { this.routeDefinitionRouteTypeLookupTableModal.id = this.routeDefinition.routeTypeId; this.routeDefinitionRouteTypeLookupTableModal.displayName = this.routeTypeRouteTypeCode; this.routeDefinitionRouteTypeLookupTableModal.show(); } setRouteTypeIdNull() { this.routeDefinition.routeTypeId = null; this.routeTypeRouteTypeCode = ''; } setRouteTemplateIdNull() { this.routeDefinition.routeTemplateId = null; this.routeTemplateName = ''; } getNewRouteTypeId() { this.routeDefinition.routeTypeId = this.routeDefinitionRouteTypeLookupTableModal.id; this.routeTypeRouteTypeCode = this.routeDefinitionRouteTypeLookupTableModal.displayName; } getAllDropDown() { let s = this; jQuery(document).ready(function () { $('.kt-select2').select2(); $('.select2-container').css('width', '100%'); $('#routeType').on('select2:select', function (e) { s.setRouteType(this.value); }); $('.route-driver').on('select2:select', function (e) { for (let index = 0; index < $('.route-driver').length; index++) { if ($('.route-driver').eq(index).val() == '') { $('.route-driver').eq(index).val(this.value); } } $('.route-driver').trigger('change'); }); }); this.filterRouteManager(); let maxcount = 1000; // let that = this; // this._contactServiceProxy.getContactAddress().subscribe(result => { // this.contacts = result.items; // }); // this._routeStopsService.getRouteStopForDropDown().subscribe(result => { // this.routeStops = result.items; // }); this.getManagers(); this._locationServiceProxy.getLocationNames(undefined, undefined, undefined, undefined, undefined, undefined) .subscribe(result => { this.locations = result; }); this._routeDefinitionsServiceProxy.getAllRouteTypeForLookupTable( undefined, 0, undefined, undefined, maxcount ).subscribe(result => { this.routeTypes = result.items; }); } ngAfterViewInit(): void { $('.kt-select2').select2(); $('.organization-unit').select2(); $('.user').select2(); } updateEmail(id, data): void { this.supervisors[id].isEmail = data; } updateSMS(id, data): void { this.supervisors[id].isSMS = data; } deleteRecipient(id: number): void { this.delete = this.supervisors[id]; this._routeDefinitionsServiceProxy.deleteSupervisor(this.delete.id) .subscribe(() => { this.notify.success(this.l('SuccessfullyDeleted')); }); this.supervisors.splice(id, 1); } updateUnits(id, data): void { this.supervisors[id].organizationUnitId = data; setTimeout(() => { $('.organization-unit').select2(); $('.user').select2(); }, 100); } updateUsers(id, data): void { this.supervisors[id].userId = data; setTimeout(() => { $('.organization-unit').select2(); $('.user').select2(); }, 100); } updateRecipientType(id, data): void { let s = this; this.supervisors[id].code = data; setTimeout(() => { $('.organization-unit').select2(); $('.user').select2(); $('.organization-unit').on('select2:select', function (e) { s.updateUnits($(e.currentTarget).attr('id'), $(e.currentTarget).val()); }); $('.user').on('select2:select', function (e) { s.updateUsers($(e.currentTarget).attr('id'), $(e.currentTarget).val()); }); }, 100); } addRecipient(): void { let s = this; this.addSupervisors = []; this.addSupervisors.isEmail = false; this.addSupervisors.isSMS = false; this.addSupervisors.isActive = false; this.addSupervisors.organizationUnitId = null; this.addSupervisors.emailAddress = ""; this.addSupervisors.code = ""; this.addSupervisors.userId = null; this.addSupervisors.routeTemplateId = null; this.supervisors.push(this.addSupervisors); //console.log(this.supervisors); //this.supervisors = this.addSupervisors; setTimeout(() => { $('.organization-unit').select2(); $('.user').select2(); }, 10); } routeStartActiveToggle(status){ if(status == true){ this.routeDefinition.routeStartInactive = true; } if(status == false){ this.routeDefinition.routeStartInactive = false; } } routeStopActiveToggle(status){ if(status == true){ this.routeDefinition.routeStopInactive = true; } if(status == false){ this.routeDefinition.routeStopInactive = false; } } setRouteType(e) { this._routeTypesServiceProxy.getAll( undefined, undefined, undefined, undefined, undefined, undefined, undefined, 1000).subscribe(data => { data.items.forEach(value => { if (value.routeType.id == e) { this.routeTypeRouteTypeCode = value.routeType.routeTypeCode; jQuery(document).ready(function () { $('.kt-select2').select2(); $('.select2-container').css('width', '100%'); }); } }); }); } editDriver() { this.activeTabIndex = 1; } getManagers(){ this._orderIncidentAppService.getManagers().subscribe(result => { this.managers = result; }) } close(): void { this.active = false; this.modal.hide(); } filterRouteManager(): void { this._routeDefinitionsServiceProxy.getManagerList().subscribe(result => { this.getManagerListDto = result; }); } validateForm(id): void{ this.routeDefinition.locationId = Number((document.getElementById('txtLocation')).value); this.routeDefinition.routeTypeId = this.isEnabledLaboratory ? Number((document.getElementById('routeType')).value) : null; // this.routeDefinition.defaultContactId = Number((document.getElementById('routeStop')).value); // this.routeDefinition.routeStartContactId = Number((document.getElementById('routeStart')).value); this.routeDefinition.defaultContactId = this.routeStopId == null? null : this.routeStopId; this.routeDefinition.routeStartContactId = this.routeStartId == null? null : this.routeStartId ; /*if(this.eta == undefined) { this.saving = false; (document.getElementById('etaDiv')).style.color="#fd397a"; this.staticTabs.tabs[1].active = false; this.staticTabs.tabs[2].active = false; this.staticTabs.tabs[3].active = false; this.message.warn('','Please fill in all required fields in Route Details Tab'); }else{ (document.getElementById('etaDiv')).style.color="#646c9a"; } if(this.routeDefinition.cutOff == undefined) { this.saving = false; (document.getElementById('cutOffDiv')).style.color="#fd397a"; this.staticTabs.tabs[1].active = false; this.staticTabs.tabs[2].active = false; this.staticTabs.tabs[3].active = false; this.message.warn('','Please fill in all required fields in Route Details Tab'); }else{ (document.getElementById('cutOffDiv')).style.color="#646c9a"; }*/ if(this.routeDefinition.routeCode == undefined || this.routeDefinition.routeCode == "") { this.saving = false; (document.getElementById('routeCodeDiv')).style.color="#fd397a"; this.staticTabs.tabs[0].active = true; this.staticTabs.tabs[1].active = false; this.staticTabs.tabs[2].active = false; this.staticTabs.tabs[3].active = false; this.staticTabs.tabs[4].active = false; this.staticTabs.tabs[5].active = false; this.message.warn('','Please fill in all required fields in Route Details Tab'); }else{ (document.getElementById('routeCodeDiv')).style.color="#646c9a"; } if(this.routeDefinition.routeTypeId === 0) { this.saving = false; if (this.isEnabledLaboratory) { (document.getElementById('routeTypeDiv')).style.color="#fd397a"; } this.staticTabs.tabs[1].active = false; this.staticTabs.tabs[2].active = false; this.staticTabs.tabs[3].active = false; this.staticTabs.tabs[4].active = false; this.message.warn('','Please fill in all required fields in Route Details Tab'); return; }else{ if (this.isEnabledLaboratory) { (document.getElementById('routeTypeDiv')).style.color="#646c9a"; } } // else{ // (document.getElementById('routeStartDiv')).style.color="#646c9a"; // } if (id == 2) { if(this.routeDefinition.locationId === 0) { this.saving = false; (document.getElementById('locationDiv')).style.color="#FF3300"; this.staticTabs.tabs[0].active = false; this.staticTabs.tabs[2].active = false; this.staticTabs.tabs[3].active = false; this.staticTabs.tabs[4].active = false; this.message.warn('','Please fill in all required fields in Locations Tab'); } else{ (document.getElementById('locationDiv')).style.color="#646c9a"; } } if(id == 3) { if(!this.routeDefinition.routeStartInactive && (this.routeDefinition.routeStartContactId == undefined || this.routeDefinition.routeStartContactId === 0)) { this.saving = false; (document.getElementById('routeStartDiv')).style.color="#FF3300"; this.staticTabs.tabs[0].active = false; this.staticTabs.tabs[2].active = false; this.staticTabs.tabs[3].active = false; this.staticTabs.tabs[4].active = false; this.message.warn('','Please fill in all required fields in Stops Tab'); } if(!this.routeDefinition.routeStopInactive && (this.routeDefinition.defaultContactId === 0 || this.routeDefinition.defaultContactId == undefined)) { //this.routeDefinition.routeStopInactive? false : this.routeStopId == null || this.routeStopId == 0? true : false this.saving = false; (document.getElementById('routeStopDiv')).style.color="#FF3300"; this.staticTabs.tabs[0].active = false; this.staticTabs.tabs[2].active = false; this.staticTabs.tabs[3].active = false; this.staticTabs.tabs[4].active = false; this.message.warn('','Please fill in all required fields in Stops Tab'); } // else{ // (document.getElementById('routeStopDiv')).style.color="#646c9a"; // } } /*if(this.routeDefinition.locationId !== 0 && this.routeDefinition.defaultContactId !== 0 && this.routeDefinition.routeTypeId !== 0 && (this.routeDefinition.routeCode == undefined || this.routeDefinition.routeCode == "")&& this.eta == undefined && this.routeDefinition.cutOff == undefined) { this.staticTabs.tabs[0].active = false; if(id==1){ this.staticTabs.tabs[1].active = true; } else if(id==2) { this.staticTabs.tabs[2].active = true; } else if(id==3) { this.staticTabs.tabs[3].active = true; } else{ this.staticTabs.tabs[4].active = true; } }*/ if( this.routeDefinition.routeTypeId !== 0 && (this.routeDefinition.routeCode == undefined || this.routeDefinition.routeCode == "")&& this.eta == undefined && this.routeDefinition.cutOff == undefined) { this.staticTabs.tabs[0].active = false; if(id==1){ this.staticTabs.tabs[1].active = true; } else if(id==2) { this.staticTabs.tabs[2].active = true; } else if(id==3) { this.staticTabs.tabs[3].active = true; } else if(id==4) { this.staticTabs.tabs[4].active = true; } else{ this.staticTabs.tabs[5].active = true; } } } searchDriver(day : string){ this.searchDay = day; let filterText = ''; switch (this.searchDay){ case 'monday': filterText = this.mondayDriverFilter; break; case 'tuesday': filterText = this.tuesdayDriverFilter; break; case 'wednesday': filterText = this.wednesdayDriverFilter; break; case 'thursday': filterText = this.thursdayDriverFilter; break; case 'friday': filterText = this.fridayDriverFilter; break; case 'saturday': filterText = this.saturdayDriverFilter; break; case 'sunday': filterText = this.sundayDriverFilter; break; } this.driverList.show(); this.driverList.filterText = filterText; } searchManager(day : string, field : string){ let filterText = ''; this.searchDay = day; this.userField = field; this.managerListModalInit(); if(field == 'manager'){ switch (this.searchDay){ case 'monday': filterText = this.mondayManagerFilter; break; case 'tuesday': filterText = this.tuesdayManagerFilter; break; case 'wednesday': filterText = this.wednesdayManagerFilter; break; case 'thursday': filterText = this.thursdayManagerFilter; break; case 'friday': filterText = this.fridayManagerFilter; break; case 'saturday': filterText = this.saturdayManagerFilter; break; case 'sunday': filterText = this.sundayManagerFilter; break; } } if(field == 'supervisor'){ switch (this.searchDay){ case 'monday': filterText = this.mondaySupervisorFilter; break; case 'tuesday': filterText = this.tuesdaySupervisorFilter; break; case 'wednesday': filterText = this.wednesdaySupervisorFilter; break; case 'thursday': filterText = this.thursdaySupervisorFilter; break; case 'friday': filterText = this.fridaySupervisorFilter; break; case 'saturday': filterText = this.saturdaySupervisorFilter; break; case 'sunday': filterText = this.sundaySupervisorFilter; break; } } this.managerList.show(); this.managerList.filterText = filterText; } setDriver(item){ var resultId = item.value var name = item.name switch (this.searchDay){ case 'monday': this.routeDefinition.mondayDriverId = resultId; this.mondayDriverFilter = name; break; case 'tuesday': this.routeDefinition.tuesdayDriverId = resultId; this.tuesdayDriverFilter = name; break; case 'wednesday': this.routeDefinition.wednesdayDriverId = resultId; this.wednesdayDriverFilter = name; break; case 'thursday': this.routeDefinition.thursdayDriverId = resultId; this.thursdayDriverFilter = name; break; case 'friday': this.routeDefinition.fridayDriverId = resultId; this.fridayDriverFilter = name; break; case 'saturday': this.routeDefinition.saturdayDriverId = resultId; this.saturdayDriverFilter = name; break; case 'sunday': this.routeDefinition.sundayDriverId = resultId; this.sundayDriverFilter = name; break; } } setManager(item){ var resultId = item.value var name = item.name if(this.userField == 'manager'){ switch (this.searchDay){ case 'monday': this.routeDefinition.mondayManagerId = resultId; this.mondayManagerFilter = name; break; case 'tuesday': this.routeDefinition.tuesdayManagerId = resultId; this.tuesdayManagerFilter = name; break; case 'wednesday': this.routeDefinition.wednesdayManagerId = resultId; this.wednesdayManagerFilter = name; break; case 'thursday': this.routeDefinition.thursdayManagerId = resultId; this.thursdayManagerFilter = name; break; case 'friday': this.routeDefinition.fridayManagerId = resultId; this.fridayManagerFilter = name; break; case 'saturday': this.routeDefinition.saturdayManagerId = resultId; this.saturdayManagerFilter = name; break; case 'sunday': this.routeDefinition.sundayManagerId = resultId; this.sundayManagerFilter = name; break; } } else if(this.userField == 'supervisor'){ switch (this.searchDay){ case 'monday': this.routeDefinition.mondaySupervisorId = resultId; this.mondaySupervisorFilter = name; break; case 'tuesday': this.routeDefinition.tuesdaySupervisorId = resultId; this.tuesdaySupervisorFilter = name; break; case 'wednesday': this.routeDefinition.wednesdaySupervisorId = resultId; this.wednesdaySupervisorFilter = name; break; case 'thursday': this.routeDefinition.thursdaySupervisorId = resultId; this.thursdaySupervisorFilter = name; break; case 'friday': this.routeDefinition.fridaySupervisorId = resultId; this.fridaySupervisorFilter = name; break; case 'saturday': this.routeDefinition.saturdaySupervisorId = resultId; this.saturdaySupervisorFilter = name; break; case 'sunday': this.routeDefinition.sundaySupervisorId = resultId; this.sundaySupervisorFilter = name; break; } } } clearManager(day : string, field : string){ if(field == 'manager'){ switch (day){ case 'monday': this.routeDefinition.mondayManagerId = null; this.mondayManagerFilter = ''; break; case 'tuesday': this.routeDefinition.tuesdayManagerId = null; this.tuesdayManagerFilter = ''; break; case 'wednesday': this.routeDefinition.wednesdayManagerId = null; this.wednesdayManagerFilter = ''; break; case 'thursday': this.routeDefinition.thursdayManagerId = null; this.thursdayManagerFilter = ''; break; case 'friday': this.routeDefinition.fridayManagerId = null; this.fridayManagerFilter = ''; break; case 'saturday': this.routeDefinition.saturdayManagerId = null; this.saturdayManagerFilter = ''; break; case 'sunday': this.routeDefinition.sundayManagerId = null; this.sundayManagerFilter = ''; break; } } else if(field == 'supervisor'){ switch (day){ case 'monday': this.routeDefinition.mondaySupervisorId = null; this.mondaySupervisorFilter = ''; break; case 'tuesday': this.routeDefinition.tuesdaySupervisorId = null; this.tuesdaySupervisorFilter = ''; break; case 'wednesday': this.routeDefinition.wednesdaySupervisorId = null; this.wednesdaySupervisorFilter = ''; break; case 'thursday': this.routeDefinition.thursdaySupervisorId = null; this.thursdaySupervisorFilter = ''; break; case 'friday': this.routeDefinition.fridaySupervisorId = null; this.fridaySupervisorFilter = ''; break; case 'saturday': this.routeDefinition.saturdaySupervisorId = null; this.saturdaySupervisorFilter = ''; break; case 'sunday': this.routeDefinition.sundaySupervisorId = null; this.sundaySupervisorFilter = ''; break; } } } clearDriver(day){ switch (day){ case 'monday': this.routeDefinition.mondayDriverId = null; this.mondayDriverFilter = ''; break; case 'tuesday': this.routeDefinition.tuesdayDriverId = null; this.tuesdayDriverFilter = ''; break; case 'wednesday': this.routeDefinition.wednesdayDriverId = null; this.wednesdayDriverFilter = ''; break; case 'thursday': this.routeDefinition.thursdayDriverId = null; this.thursdayDriverFilter = ''; break; case 'friday': this.routeDefinition.fridayDriverId = null; this.fridayDriverFilter = ''; break; case 'saturday': this.routeDefinition.saturdayDriverId = null; this.saturdayDriverFilter = ''; break; case 'sunday': this.routeDefinition.sundayDriverId = null; this.sundayDriverFilter = ''; break; } } initDriverFields(){ this._driverService.getDriverList().subscribe((result) => { this.users = result; this.sundayDriverFilter = this.routeDefinition.sundayDriverId != null && this.routeDefinition.sundayDriverId != 0? this.users.filter(c => c.id == this.routeDefinition.sundayDriverId)[0].fullName : ''; this.mondayDriverFilter = this.routeDefinition.mondayDriverId != null && this.routeDefinition.mondayDriverId != 0? this.users.filter(c => c.id == this.routeDefinition.mondayDriverId)[0].fullName : ''; this.tuesdayDriverFilter = this.routeDefinition.tuesdayDriverId != null && this.routeDefinition.tuesdayDriverId != 0? this.users.filter(c => c.id == this.routeDefinition.tuesdayDriverId)[0].fullName : ''; this.wednesdayDriverFilter = this.routeDefinition.wednesdayDriverId != null && this.routeDefinition.wednesdayDriverId != 0? this.users.filter(c => c.id == this.routeDefinition.wednesdayDriverId)[0].fullName : ''; this.thursdayDriverFilter = this.routeDefinition.thursdayDriverId != null && this.routeDefinition.thursdayDriverId != 0? this.users.filter(c => c.id == this.routeDefinition.thursdayDriverId)[0].fullName : ''; this.fridayDriverFilter = this.routeDefinition.fridayDriverId != null && this.routeDefinition.fridayDriverId != 0? this.users.filter(c => c.id == this.routeDefinition.fridayDriverId)[0].fullName : ''; this.saturdayDriverFilter = this.routeDefinition.saturdayDriverId != null && this.routeDefinition.saturdayDriverId != 0? this.users.filter(c => c.id == this.routeDefinition.saturdayDriverId)[0].fullName : ''; }); } initManagerFields(){ this._orderIncidentAppService.getManagers().subscribe(result => { this.managers = result; this.sundayManagerFilter = this.routeDefinition.sundayManagerId != null && this.routeDefinition.sundayManagerId != 0? this.managers.filter(c => c.managerId == this.routeDefinition.sundayManagerId)[0].managerFullName : ''; this.mondayManagerFilter = this.routeDefinition.mondayManagerId != null && this.routeDefinition.mondayManagerId != 0? this.managers.filter(c => c.managerId == this.routeDefinition.mondayManagerId)[0].managerFullName : ''; this.tuesdayManagerFilter = this.routeDefinition.tuesdayManagerId != null && this.routeDefinition.tuesdayManagerId != 0? this.managers.filter(c => c.managerId == this.routeDefinition.tuesdayManagerId)[0].managerFullName : ''; this.wednesdayManagerFilter = this.routeDefinition.wednesdayManagerId != null && this.routeDefinition.wednesdayManagerId != 0? this.managers.filter(c => c.managerId == this.routeDefinition.wednesdayManagerId)[0].managerFullName : ''; this.thursdayManagerFilter = this.routeDefinition.thursdayManagerId != null && this.routeDefinition.thursdayManagerId != 0? this.managers.filter(c => c.managerId == this.routeDefinition.thursdayManagerId)[0].managerFullName : ''; this.fridayManagerFilter = this.routeDefinition.fridayManagerId != null && this.routeDefinition.fridayManagerId != 0? this.managers.filter(c => c.managerId == this.routeDefinition.fridayManagerId)[0].managerFullName : ''; this.saturdayManagerFilter = this.routeDefinition.saturdayManagerId != null && this.routeDefinition.saturdayManagerId != 0? this.managers.filter(c => c.managerId == this.routeDefinition.saturdayManagerId)[0].managerFullName : ''; this.sundaySupervisorFilter = this.routeDefinition.sundaySupervisorId != null && this.routeDefinition.sundaySupervisorId != 0? this.managers.filter(c => c.managerId == this.routeDefinition.sundaySupervisorId)[0].managerFullName : ''; this.mondaySupervisorFilter = this.routeDefinition.mondaySupervisorId != null && this.routeDefinition.mondaySupervisorId != 0? this.managers.filter(c => c.managerId == this.routeDefinition.mondaySupervisorId)[0].managerFullName : ''; this.tuesdaySupervisorFilter = this.routeDefinition.tuesdaySupervisorId != null && this.routeDefinition.tuesdaySupervisorId != 0? this.managers.filter(c => c.managerId == this.routeDefinition.tuesdaySupervisorId)[0].managerFullName : ''; this.wednesdaySupervisorFilter = this.routeDefinition.wednesdaySupervisorId != null && this.routeDefinition.wednesdaySupervisorId != 0? this.managers.filter(c => c.managerId == this.routeDefinition.wednesdaySupervisorId)[0].managerFullName : ''; this.thursdaySupervisorFilter = this.routeDefinition.thursdaySupervisorId != null && this.routeDefinition.thursdaySupervisorId != 0? this.managers.filter(c => c.managerId == this.routeDefinition.thursdaySupervisorId)[0].managerFullName : ''; this.fridaySupervisorFilter = this.routeDefinition.fridaySupervisorId != null && this.routeDefinition.fridaySupervisorId != 0? this.managers.filter(c => c.managerId == this.routeDefinition.fridaySupervisorId)[0].managerFullName : ''; this.saturdaySupervisorFilter = this.routeDefinition.saturdaySupervisorId != null && this.routeDefinition.saturdaySupervisorId != 0? this.managers.filter(c => c.managerId == this.routeDefinition.saturdaySupervisorId)[0].managerFullName : ''; }) } }