import { Component, ViewChild, Injector, Output, EventEmitter} 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'; 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; @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; 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(); 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 { 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()); this.eta = moment(today.toDateString() + " " + schedule.estimatedTimeOfArrival).toDate(); //today.setTime(schedule.estimatedTimeOfArrival); this.cutOff = moment(today.toDateString() + " " + schedule.cutOff).toDate() //schedule.cutOff; this.effectivityDate = schedule.effectivityDate.toDate(); console.log(this.scheduleInput); } } ngAfterViewInit() { //this.address = this.addressForm.address; } save(): void { this.saving = true; this.scheduleInput.routeCode = (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.utc(this.eta.toLocaleString()).format("HH:mm:ss.SSS"); this.scheduleInput.cutOffTime = moment.utc(this.cutOff.toLocaleString()).format("HH:mm:ss.SSS"); this.scheduleInput.effectivityDate = this.effectivityDate; if(this.scheduleId == undefined) { this.input.clinicId = this.clinicId; this.scheduleInput.createRouteSchedule = this.input; } 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; console.log(that.routeTypes); }); } }