import { Component, EventEmitter, Injector, ViewChild, Output, Input } from '@angular/core'; import { AppComponentBase } from '@shared/common/app-component-base'; import { WillCallServiceServiceProxy, Route4MeServiceProxy, GetClinicResultDto, GetRouteByClinicResultDto, CreateCallinInput, CreateOptimizeInputDto } from '@shared/service-proxies/service-proxies'; import { ModalDirective } from 'ngx-bootstrap'; import { PrimengTableHelper } from 'shared/helpers/PrimengTableHelper'; import { finalize, catchError } from 'rxjs/operators'; import * as jquery from 'jquery'; import * as moment from 'moment-timezone'; import { throwError } from 'rxjs'; @Component({ templateUrl: './clinic_callin_modal.component.html', selector: 'clinicCallInModal', styleUrls: ['./clinic_callin_modal.component.less'], providers : [WillCallServiceServiceProxy, Route4MeServiceProxy] }) export class ClinicCallInModalComponent extends AppComponentBase { @ViewChild('clinicCallInModal', {static: false}) modal: ModalDirective; @Output() modalSave: EventEmitter = new EventEmitter(); active = false; hide: boolean = false; txtFilter: any; clinics: GetClinicResultDto[]; CreateCallinInput = new CreateCallinInput(); OptimizeInput = new CreateOptimizeInputDto(); clinicId:number; routeCode:string; routeId:number; hide_callin: boolean = true; currently_selected: string; eta_selected: string; load_date: Date; cut_off: string; routeSchedDetailId:number; @Input('inputs') inputs: { locationId: number; loadDate: any; } = {}; constructor( injector: Injector, private _callIn : WillCallServiceServiceProxy, private _route4me : Route4MeServiceProxy ) { super(injector); } ngOnInit(){ this.currently_selected = 'NONE'; //this.hide_callin = false; moment.tz.setDefault(localStorage.getItem('timeZoneId')); moment().tz(localStorage.getItem('timeZoneId')).format(); } searchForClinic(): void { this._callIn.getClinicForCallback(this.txtFilter,undefined) .subscribe(result => { this.clinics = result; }); } show(clinicId?: number) { let timeId = localStorage.getItem('timeZoneId'); this._callIn.getClinicForCallBackWithId(undefined,clinicId) .subscribe(result=>{ this.txtFilter = result[0] this.clinicId = this.txtFilter.id this.active = true; this.modal.show(); // this._callIn.getClinicRoutesSchedule(this.txtFilter.id, undefined, moment.tz(localStorage.getItem('loadDate'), timeId), parseInt(localStorage.getItem('operatingLocationId')), undefined, undefined) // .subscribe(result => // { // var fresult = JSON.parse(JSON.stringify(result)); // var key; // for(key in fresult) // { // fresult[key].cutOff = moment(fresult[key].dateTimeCutOff).tz(localStorage.getItem('timeZoneId')).format('hh:mm A'); // fresult[key].etaOriginal = moment(fresult[key].eta).tz(localStorage.getItem('timeZoneId')).format('hh:mm A'); // } // this.routes = fresult; // if(Object.keys(fresult).length > 0) // { // var that = this; // that.currently_selected = fresult[0].routeCode; // that.eta_selected = moment(fresult[0].eta).tz(localStorage.getItem('timeZoneId')).format('hh:mm A'); // that.cut_off = moment(fresult[0].dateTimeCutOff).tz(localStorage.getItem('timeZoneId')).format('hh:mm A'); // that.routeSchedDetailId = fresult[0].id; // } // else{ // this.currently_selected = 'NONE'; // } // } // ); }); } getRoutes(event) : void { let timeId = localStorage.getItem('timeZoneId'); this.clinicId = event.id; // this._callIn.getClinicRoutesSchedule(this.clinicId, undefined,moment.tz(localStorage.getItem('loadDate'), timeId), parseInt(localStorage.getItem('operatingLocationId')), undefined, undefined) // .subscribe(result => // { // var fresult = JSON.parse(JSON.stringify(result)); // var key; // for(key in fresult) // { // fresult[key].cutOff = moment(fresult[key].dateTimeCutOff).tz(localStorage.getItem('timeZoneId')).format('hh:mm A'); // fresult[key].etaOriginal = moment(fresult[key].eta).tz(localStorage.getItem('timeZoneId')).format('hh:mm A'); // } // this.routes = fresult; // if(Object.keys(fresult).length > 0) // { // var that = this; // that.currently_selected = fresult[0].routeCode; // that.eta_selected = moment(fresult[0].eta).tz(localStorage.getItem('timeZoneId')).format('hh:mm A'); // that.cut_off = moment(fresult[0].dateTimeCutOff).tz(localStorage.getItem('timeZoneId')).format('hh:mm A'); // that.routeSchedDetailId = fresult[0].id; // } // else{ // this.currently_selected = 'NONE'; // } // } // ); } clinicChange(routeCode: string,routeSchedDetailId: number, routeKey : string, eta: string, cutOff: string) { this.currently_selected = routeCode; this.routeSchedDetailId = routeSchedDetailId; this.eta_selected = eta; this.cut_off = cutOff; //alert(routeCode) $("input[type='radio']").click(function() { $("label").removeClass("activeRouteCode"); if ($(this).is(":checked")) { $(this).parent().addClass("activeRouteCode"); } }); } // show() { // this.active = true; // this.modal.show(); // } save(): void { this.spinnerService.show(); let timeId = localStorage.getItem('timeZoneId'); this.CreateCallinInput.clinicId = this.clinicId; this.CreateCallinInput.routeScheduleDetailId = this.routeSchedDetailId; this.CreateCallinInput.requestorName = (document.getElementById('txtRequestorName')).value; this.CreateCallinInput.specialInstructions = (document.getElementById('notes')).value; this._callIn.createCallIn(this.CreateCallinInput) .pipe( catchError((err) => { this.spinnerService.hide(); return throwError(err); }) ) .subscribe((result) => { this.spinnerService.hide(); this.notify.info(this.l('SavedSuccessfully')); this.close(); }); } saveNew(): void { this.spinnerService.show(); var that = this; let timeId = localStorage.getItem('timeZoneId'); this.CreateCallinInput.clinicId = this.clinicId; this.CreateCallinInput.routeScheduleDetailId = this.routeSchedDetailId; this.CreateCallinInput.requestorName = (document.getElementById('txtRequestorName')).value; this.CreateCallinInput.specialInstructions = (document.getElementById('notes')).value; this._callIn.createCallIn(this.CreateCallinInput) .pipe( catchError((err) => { this.spinnerService.hide(); return throwError(err); }) ) .subscribe((result) => { $('#clinicList').val(''); $('#txtRequestorName').val(''); // that.routes = []; $('#notes').val(''); $('#clinicList').focus(); that.txtFilter = ''; this.spinnerService.hide(); this.notify.info(this.l('SavedSuccessfully')); }); } onShown(): void { $('.kt-select2').select2(); } close(): void { this.active = false; this.modal.hide(); } }