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; 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; cutOff: any; effectivityDate: any; //dates: Date; clinicId: any; scheduleId: any; constructor( injector: Injector, private _clinicsServiceProxy: ClinicsServiceProxy, private _routeDefinitionsServiceProxy: RouteDefinitionsServiceProxy, private _routeScheduleDetailsServiceProxy: RouteScheduleDetailsServiceProxy, private _routeSchedulesServiceProxy: RouteSchedulesServiceProxy, private _addressService: AddressServiceProxy, private _emailService: EmailServiceProxy, ) { super(injector); } show(schedule?: any, routeScheduleId?: any, clinicId?: any): void { let today = new Date(); //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.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; 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.cutOff = dateCutOff; //moment(today.toDateString() + " " + schedule.cutOff); //moment(schedule.displayCutOff).tz(localStorage.getItem('timeZoneId')).toDate(); //schedule.cutOff; this.effectivityDate = schedule.effectivityDate.toDate(); console.log(today.toDateString()); console.log(schedule.cutOff); console.log(dateCutOff); console.log(this.cutOff); } } ngAfterViewInit() { //this.address = this.addressForm.address; } ngOnInit() { } ngOnChanges(){ } save(): void { //this.saving = true; 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 = this.effectivityDate; 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 cutOffMoment = moment(this.cutOff).tz(localStorage.getItem('timeZoneId')); this.scheduleInput.etaTime = new Date(etaMoment.format()).toLocaleTimeString('en-US', { hour12: false, hour: "numeric", minute: "numeric", second: "numeric" }); this.scheduleInput.cutOffTime = new Date(cutOffMoment.format()).toLocaleTimeString('en-US', { hour12: false, hour: "numeric", minute: "numeric", second: "numeric" }); //this.scheduleInput.estimatedTimeOfArrival = moment(etaMoment.toDate().toDateString() + " " + this.scheduleInput.etaTime); //this.scheduleInput.cutOff = moment(cutOffMoment.toDate().toDateString() + " " + this.scheduleInput.cutOffTime); 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.effectivityDate = 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.getAll( undefined, undefined, undefined, undefined, undefined, maxcount ).subscribe(result => { that.routeDefinitions = result.items; }); this._routeDefinitionsServiceProxy.getAllRouteTypeForLookupTable( undefined, undefined, undefined, maxcount ).subscribe(result => { that.routeTypes = result.items; }); } }