import { Component, ViewChild, Injector, Input, Output, EventEmitter, OnInit, AfterViewInit } from '@angular/core'; import { ModalDirective } from 'ngx-bootstrap'; import { finalize } from 'rxjs/operators'; //import { ClinicsServiceProxy, CreateOrEditClinicDto } from '@shared/service-proxies/service-proxies'; import { ClinicsServiceProxy, CreateOrEditClinicDto, RouteDefinitionsServiceProxy, CreateOrEditRouteDefinitionDto, RouteTypesServiceProxy, RouteScheduleDetailsServiceProxy, RouteScheduleDetailDto, CreateOrEditRouteScheduleDetailDto, CreateOrEditClinicScheduleDto } from '@shared/service-proxies/service-proxies'; import { AddressServiceProxy, CreateAddressInput } from '@shared/service-proxies/service-proxies'; import { EmailServiceProxy, CreateEmailInput } from '@shared/service-proxies/service-proxies'; import { RouteSchedulesServiceProxy, CreateOrEditRouteScheduleDto } from '@shared/service-proxies/service-proxies'; import { AppComponentBase } from '@shared/common/app-component-base'; import * as moment from 'moment-timezone'; import { AddressFormComponent } from '@app/shared/layout/form/address-form.component'; import { AddressFormMainComponent } from '../../../shared/layout/formMain/address-form.component'; declare var KTWizard: any; declare var $: any; declare var KTApp: any; declare let swal: any; @Component({ selector: 'createOrEditClinicModal', templateUrl: './create-or-edit-clinic-modal.component.html' }) export class CreateOrEditClinicModalComponent extends AppComponentBase { @ViewChild('createOrEditModal', { static: true }) modal: ModalDirective; @ViewChild(AddressFormMainComponent, { static: false }) addressForm; @Output() modalSave: EventEmitter = new EventEmitter(); @Output() iconChange = new EventEmitter(); active = false; saving = false; edit = false; change = false; activeTabIndex: number = 0; scheduleInput: CreateOrEditRouteScheduleDetailDto = new CreateOrEditRouteScheduleDetailDto; input: CreateOrEditRouteScheduleDto = new CreateOrEditRouteScheduleDto; clinic: CreateOrEditClinicDto = new CreateOrEditClinicDto(); address: CreateAddressInput = new CreateAddressInput(); schedules: any; routeDefinitions: any; routeTypes: any; designationSelect: any; designation: any; eta: any; etaMonday: any; etaTuesday: any; etaWednesday: any; etaThursday: any; etaFriday: any; etaSaturday: any; etaSunday: any; cutOff: any; cutOffMonday: any; cutOffTuesday: any; cutOffWednesday: any; cutOffThursday: any; cutOffFriday: any; cutOffSaturday: any; cutOffSunday: any; effectivityDate: any; sundayIsAuto: any; mondayIsAuto: any; tuesdayIsAuto: any; wednesdayIsAuto: any; thursdayIsAuto: any; fridayIsAuto: any; saturdayIsAuto: any; //dates: Date; clinicId: any; scheduleId: any; showSchedule: boolean; isSaturday: boolean = false; isSunday: boolean = false; constructor( injector: Injector, private _clinicsServiceProxy: ClinicsServiceProxy, private _routeDefinitionsServiceProxy: RouteDefinitionsServiceProxy, private _routeScheduleDetailsServiceProxy: RouteScheduleDetailsServiceProxy, private _routeSchedulesServiceProxy: RouteSchedulesServiceProxy, private _routeTypesServiceProxy: RouteTypesServiceProxy, private _addressService: AddressServiceProxy, private _emailService: EmailServiceProxy, ) { super(injector); } // public etaOnChange(value: Date): void { // console.log(value); // } show(schedule?: any, routeScheduleId?: any, clinicId?: any): void { let today = new Date(); this.showSchedule = true; let that = this; this.isSaturday = false; this.isSunday = false; $(document).ready(function () { $('#routeDefinition').on('select2:select', function (e) { var data = e.params.data; let selectedRouteDefintion = that.routeDefinitions.find(i => i.routeTemplateId == data.id); //that.routeDefinitions.map(({ routeTemplateName }) => data.id); that.scheduleInput.routeTemplateId = selectedRouteDefintion.routeTemplateId; that.scheduleInput.routeCode = selectedRouteDefintion.routeTemplateName; //alert(selectedRouteDefintion.routeTemplateId +" - " + selectedRouteDefintion.routeTemplateName); that.scheduleInput.routeTypeId = selectedRouteDefintion.routeDefinition.routeTypeId; that.getAllDropDown(); }); $('#routeType').on('select2:select', function (e) { var data = e.params.data; if (data.text.trim() == "Saturday") { that.isSaturday = true; that.saturdayIsAuto = 1; } else { that.isSaturday = false; this.sundayIsAuto = 1; this.saturdayIsAuto = 1; this.fridayIsAuto = 1; this.thursdayIsAuto = 1; this.wednesdayIsAuto = 1; this.tuesdayIsAuto = 1; this.mondayIsAuto = 1; } if (data.text.trim() == "Sunday") { that.isSunday = true; that.sundayIsAuto = 1; } else { that.isSunday = false; this.sundayIsAuto = 1; this.saturdayIsAuto = 1; this.fridayIsAuto = 1; this.thursdayIsAuto = 1; this.wednesdayIsAuto = 1; this.tuesdayIsAuto = 1; this.mondayIsAuto = 1; } }); }); //today = moment(today).tz(localStorage.getItem('timeZoneId')).toDate(); this.clinicId = clinicId; this.scheduleId = routeScheduleId; // this.designationSelect = ([ // { // value: "auto", // text: "Auto" // }, // { // value: "willCall", // text: "Will Call" // } // ]); if (schedule == undefined) { this.scheduleInput.isActive = true; this.scheduleInput.routeScheduleId = routeScheduleId; this.cutOffMonday = today; this.cutOffTuesday = today; this.cutOffWednesday = today; this.cutOffThursday = today; this.cutOffFriday = today; this.cutOffSaturday = today; this.cutOffSunday = today; this.etaMonday = today; this.etaTuesday = today; this.etaWednesday = today; this.etaThursday = today; this.etaFriday = today; this.etaSaturday = today; this.etaSunday = today; this.sundayIsAuto = 1; this.saturdayIsAuto = 1; this.fridayIsAuto = 1; this.thursdayIsAuto = 1; this.wednesdayIsAuto = 1; this.tuesdayIsAuto = 1; this.mondayIsAuto = 1; this.eta = today; this.cutOff = today; this.getAllDropDown(); this.active = true; this.modal.show(); } else { today = moment(schedule.today).tz(localStorage.getItem('timeZoneId')).toDate(); this.scheduleInput = schedule; this.edit = true; this.getAllDropDown(); this.active = true; this.modal.show(); if (schedule.willCall == true) { this.designation = "willCall"; } else if (schedule.automatic == true) { this.designation = "auto"; } //alert(today.toDateString()); let dateCutOff = today.toDateString() + ' ' + schedule.cutOff; let dateEta = today.toDateString() + ' ' + schedule.estimatedTimeOfArrival; let mondayEta = today.toDateString() + ' ' + schedule.mondayETATime; let tuesdayEta = today.toDateString() + ' ' + schedule.tuesdayETATime; let wednesdayEta = today.toDateString() + ' ' + schedule.wednesdayETATime; let thursdayEta = today.toDateString() + ' ' + schedule.thursdayETATime; let fridayEta = today.toDateString() + ' ' + schedule.fridayETATime; let saturdayEta = today.toDateString() + ' ' + schedule.saturdayETATime; let sundayEta = today.toDateString() + ' ' + schedule.sundayETATime; let mondayCutOff = today.toDateString() + ' ' + schedule.mondayCutOffTime; let tuesdayCutOff = today.toDateString() + ' ' + schedule.tuesdayCutOffTime; let wednesdayCutOff = today.toDateString() + ' ' + schedule.wednesdayCutOffTime; let thursdayCutOff = today.toDateString() + ' ' + schedule.thursdayCutOffTime; let fridayCutOff = today.toDateString() + ' ' + schedule.fridayCutOffTime; let saturdayCutOff = today.toDateString() + ' ' + schedule.saturdayCutOffTime; let sundayCutOff = today.toDateString() + ' ' + schedule.sundayCutOffTime; this.eta = dateEta; //moment(today.toDateString() + " " + schedule.estimatedTimeOfArrival).tz(localStorage.getItem('timeZoneId')).toDate(); //moment(schedule.displayEta).tz(localStorage.getItem('timeZoneId')).toDate(); //today.setTime(schedule.estimatedTimeOfArrival); this.etaMonday = moment(mondayEta).toDate(); this.etaTuesday = moment(tuesdayEta).toDate(); this.etaWednesday = moment(wednesdayEta).toDate(); this.etaThursday = moment(thursdayEta).toDate(); this.etaFriday = moment(fridayEta).toDate(); this.etaSaturday = moment(saturdayEta).toDate(); this.etaSunday = moment(sundayEta).toDate(); this.cutOff = dateCutOff; //moment(today.toDateString() + " " + schedule.cutOff); //moment(schedule.displayCutOff).tz(localStorage.getItem('timeZoneId')).toDate(); //schedule.cutOff; this.cutOffMonday = moment(mondayCutOff).toDate(); this.cutOffTuesday = moment(tuesdayCutOff).toDate(); this.cutOffWednesday = moment(wednesdayCutOff).toDate(); this.cutOffThursday = moment(thursdayCutOff).toDate(); this.cutOffFriday = moment(fridayCutOff).toDate(); this.cutOffSaturday = moment(saturdayCutOff).toDate(); this.cutOffSunday = moment(sundayCutOff).toDate(); this.effectivityDate = schedule.effectivityDate.toDate(); this.sundayIsAuto = schedule.sundayIsAuto; this.saturdayIsAuto = schedule.saturdayIsAuto; this.fridayIsAuto = schedule.fridayIsAuto; this.thursdayIsAuto = schedule.thursdayIsAuto; this.wednesdayIsAuto = schedule.wednesdayIsAuto; this.tuesdayIsAuto = schedule.tuesdayIsAuto; this.mondayIsAuto = schedule.mondayIsAuto; if(schedule.routeTypeName == "Saturday"){ this.isSaturday = true; } else { this.isSaturday = false; } if(schedule.routeTypeName == "Sunday"){ this.isSunday = true; } else { this.isSunday = false; } } } ngAfterViewInit() { } ngOnInit() { let maxcount = 2000; let that = this; this._routeDefinitionsServiceProxy.getAll( undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, maxcount ).subscribe(result => { that.routeDefinitions = result.items; }); } ngOnChanges() { } save(): void { //this.scheduleInput.routeCode = (document.getElementById('routeDefinition')).value; //$("#routeDefinition option:selected").text(); //(document.getElementById('routeDefinition')).value; this.scheduleInput.routeTypeId = Number((document.getElementById('routeType')).value); // this.designation = (document.getElementById('designations')).value; // if (this.designation == 'willCall') { // this.scheduleInput.willCall = true; // this.scheduleInput.automatic = false; // } // else if (this.designation == 'auto') { // this.scheduleInput.automatic = true; // this.scheduleInput.willCall = false; // } //this.scheduleInput.etaTime = moment(this.eta).format("HH:mm:ss.SSS"); //this.scheduleInput.cutOffTime = moment(this.cutOff).format("HH:mm:ss.SSS"); this.scheduleInput.effectivityDate = moment(this.effectivityDate).tz(localStorage.getItem('timeZoneId')); this.scheduleInput.locationId = Number(localStorage.getItem('operatingLocationId')); if (this.scheduleId == undefined) { this.input.clinicId = this.clinicId; this.scheduleInput.createRouteSchedule = this.input; } if (this.scheduleInput.dateEtaLocked != null || this.scheduleInput.dateEtaLocked != undefined) { this.scheduleInput.dateEtaLocked = moment.utc(this.scheduleInput.dateEtaLocked); } if (this.scheduleInput.oorRate == null) { this.scheduleInput.oorRate = 0; } if (this.scheduleInput.serviceTime == null) { this.scheduleInput.oorRate = 0; } //var isoDate = new Date(this.eta).toISOString(); var etaMoment = moment(this.eta).tz(localStorage.getItem('timeZoneId')); var mondayEtaMoment = moment(this.etaMonday).tz(localStorage.getItem('timeZoneId')); var tuesdayEtaMoment = moment(this.etaTuesday).tz(localStorage.getItem('timeZoneId')); var wednesdayEtaMoment = moment(this.etaWednesday).tz(localStorage.getItem('timeZoneId')); var thursdayEtaMoment = moment(this.etaThursday).tz(localStorage.getItem('timeZoneId')); var fridayEtaMoment = moment(this.etaFriday).tz(localStorage.getItem('timeZoneId')); var saturdayEtaMoment = moment(this.etaSaturday).tz(localStorage.getItem('timeZoneId')); var sundayEtaMoment = moment(this.etaSunday).tz(localStorage.getItem('timeZoneId')); var cutOffMoment = moment(this.cutOff).tz(localStorage.getItem('timeZoneId')); var mondayCutOffMoment = moment(this.cutOffMonday).tz(localStorage.getItem('timeZoneId')); var tuesdayCutOffMoment = moment(this.cutOffTuesday).tz(localStorage.getItem('timeZoneId')); var wednesdayCutOffMoment = moment(this.cutOffWednesday).tz(localStorage.getItem('timeZoneId')); var thursdayCutOffMoment = moment(this.cutOffThursday).tz(localStorage.getItem('timeZoneId')); var fridayCutOffMoment = moment(this.cutOffFriday).tz(localStorage.getItem('timeZoneId')); var saturdayCutOffMoment = moment(this.cutOffSaturday).tz(localStorage.getItem('timeZoneId')); var sundayCutOffMoment = moment(this.cutOffSunday).tz(localStorage.getItem('timeZoneId')); this.scheduleInput.estimatedTimeOfArrival = etaMoment; this.scheduleInput.etaTime = new Date(etaMoment.format()).toLocaleTimeString('en-US', { hour12: true, hour: "numeric", minute: "numeric", second: "numeric" }) as any; this.scheduleInput.cutOff = new Date(cutOffMoment.format()).toLocaleTimeString('en-US', { hour12: true, hour: "numeric", minute: "numeric", second: "numeric" }) as any; this.scheduleInput.mondayETATime = new Date(mondayEtaMoment.format()).toLocaleTimeString('en-US', { hour12: true, hour: "numeric", minute: "numeric", second: "numeric" }) as any; this.scheduleInput.tuesdayETATime = new Date(tuesdayEtaMoment.format()).toLocaleTimeString('en-US', { hour12: true, hour: "numeric", minute: "numeric", second: "numeric" }) as any; this.scheduleInput.wednesdayETATime = new Date(wednesdayEtaMoment.format()).toLocaleTimeString('en-US', { hour12: true, hour: "numeric", minute: "numeric", second: "numeric" }) as any; this.scheduleInput.thursdayETATime = new Date(thursdayEtaMoment.format()).toLocaleTimeString('en-US', { hour12: true, hour: "numeric", minute: "numeric", second: "numeric" }) as any; this.scheduleInput.fridayETATime = new Date(fridayEtaMoment.format()).toLocaleTimeString('en-US', { hour12: true, hour: "numeric", minute: "numeric", second: "numeric" }) as any; this.scheduleInput.saturdayETATime = new Date(saturdayEtaMoment.format()).toLocaleTimeString('en-US', { hour12: true, hour: "numeric", minute: "numeric", second: "numeric" }) as any; // if(this.etaSunday != null) { this.scheduleInput.sundayETATime = new Date(sundayEtaMoment.format()).toLocaleTimeString('en-US', { hour12: true, hour: "numeric", minute: "numeric", second: "numeric" }) as any; // console.log('pasok'); // } // else{ // this.scheduleInput.sundayETATime = null; // } this.scheduleInput.cutOffTime = new Date(cutOffMoment.format()).toLocaleTimeString('en-US', { hour12: true, hour: "numeric", minute: "numeric", second: "numeric" }) as any; this.scheduleInput.mondayCutOffTime = new Date(mondayCutOffMoment.format()).toLocaleTimeString('en-US', { hour12: true, hour: "numeric", minute: "numeric", second: "numeric" }) as any; this.scheduleInput.tuesdayCutOffTime = new Date(tuesdayCutOffMoment.format()).toLocaleTimeString('en-US', { hour12: true, hour: "numeric", minute: "numeric", second: "numeric" }) as any; this.scheduleInput.wednesdayCutOffTime = new Date(wednesdayCutOffMoment.format()).toLocaleTimeString('en-US', { hour12: true, hour: "numeric", minute: "numeric", second: "numeric" }) as any; this.scheduleInput.thursdayCutOffTime = new Date(thursdayCutOffMoment.format()).toLocaleTimeString('en-US', { hour12: true, hour: "numeric", minute: "numeric", second: "numeric" }) as any; this.scheduleInput.fridayCutOffTime = new Date(fridayCutOffMoment.format()).toLocaleTimeString('en-US', { hour12: true, hour: "numeric", minute: "numeric", second: "numeric" }) as any; this.scheduleInput.saturdayCutOffTime = new Date(saturdayCutOffMoment.format()).toLocaleTimeString('en-US', { hour12: true, hour: "numeric", minute: "numeric", second: "numeric" }) as any; this.scheduleInput.sundayCutOffTime = new Date(sundayCutOffMoment.format()).toLocaleTimeString('en-US', { hour12: true, hour: "numeric", minute: "numeric", second: "numeric" }) as any; if (this.sundayIsAuto == "null") { this.sundayIsAuto = null; } if (this.saturdayIsAuto == "null") { this.saturdayIsAuto = null; } if (this.fridayIsAuto == "null") { this.fridayIsAuto = null; } if (this.thursdayIsAuto == "null") { this.thursdayIsAuto = null; } if (this.wednesdayIsAuto == "null") { this.wednesdayIsAuto = null; } if (this.tuesdayIsAuto == "null") { this.tuesdayIsAuto = null; } if (this.mondayIsAuto == "null") { this.mondayIsAuto = null; } if(this.isSunday == true){ this.mondayIsAuto = null; this.tuesdayIsAuto = null; this.wednesdayIsAuto = null; this.thursdayIsAuto = null; this.fridayIsAuto = null; this.saturdayIsAuto = null; } if(this.isSaturday == true){ this.mondayIsAuto = null; this.tuesdayIsAuto = null; this.wednesdayIsAuto = null; this.thursdayIsAuto = null; this.fridayIsAuto = null; this.sundayIsAuto = null; } this.scheduleInput.sundayIsAuto = this.sundayIsAuto; this.scheduleInput.saturdayIsAuto = this.saturdayIsAuto; this.scheduleInput.fridayIsAuto = this.fridayIsAuto; this.scheduleInput.thursdayIsAuto = this.thursdayIsAuto; this.scheduleInput.wednesdayIsAuto = this.wednesdayIsAuto; this.scheduleInput.tuesdayIsAuto = this.tuesdayIsAuto; this.scheduleInput.mondayIsAuto = this.mondayIsAuto; this._routeScheduleDetailsServiceProxy.createOrEdit(this.scheduleInput) .pipe(finalize(() => { this.saving = false; })) .subscribe(() => { this.notify.info(this.l('SavedSuccessfully')); this.modalSave.emit(null); this.close(); }); } close(): void { this.eta = null; this.showSchedule = false; this.effectivityDate = null; this.etaSunday = null; this.cutOffSunday = null; this.etaMonday = null; this.cutOffMonday = null; this.etaTuesday = null; this.cutOffTuesday = null; this.etaWednesday = null; this.cutOffWednesday = null; this.etaThursday = null; this.cutOffThursday = null; this.etaFriday = null; this.cutOffFriday = null; this.etaSaturday = null; this.cutOffSaturday = null; this.cutOff = null; this.scheduleInput = new CreateOrEditRouteScheduleDetailDto; this.edit = false; //this.scheduleInput = null; this.active = false; this.modalSave.emit(null); this.modal.hide(); //this.scheduleInput.routeCode = null; //this.scheduleInput.routeTypeId = null; } getAllDropDown() { let maxcount = 1000; let that = this; jQuery(document).ready(function () { $('.kt-select2').select2(); $('.select2-container').css('width', '100%'); }); this._routeDefinitionsServiceProxy.getAllRouteTypeForLookupTable( undefined, undefined, undefined, maxcount ).subscribe(result => { that.routeTypes = result.items; }); } }