import { Component, EventEmitter, Injector, ViewChild, Output, Input } from '@angular/core'; import { AppComponentBase } from '@shared/common/app-component-base'; import { WillCallServiceServiceProxy, GetClinicResultDto, GetRouteByClinicResultDto, CreateCallbackInput } from '@shared/service-proxies/service-proxies'; import { ModalDirective } from 'ngx-bootstrap'; import { DropdownModule } from 'primeng/dropdown'; import { AutoCompleteModule } from 'primeng/autocomplete'; import { PrimengTableHelper } from 'shared/helpers/PrimengTableHelper'; import { finalize } from 'rxjs/operators'; import * as jquery from 'jquery'; import * as moment from 'moment'; import { FormControl } from '@angular/forms'; import { Time } from '@angular/common'; @Component({ templateUrl: './call_back_modal.component.html', selector: 'callBackModal', styleUrls: ['./calls_modal.component.less'], providers : [WillCallServiceServiceProxy] }) export class CallBackModalComponent extends AppComponentBase { @ViewChild('callBackModal', {static: false}) modal: ModalDirective; @Output() modalSave: EventEmitter = new EventEmitter(); active = false; clinics: GetClinicResultDto[]; // routes: GetRouteByETAResultDto[]; callback = new CreateCallbackInput(); routeId: any; routeCode: string; clinicList : boolean = false; txtFilter: any; clinicId: number; mytime: Date = new Date(); minTime: Date = new Date(); maxTime: Date = new Date(); cutOffValidation: boolean; etaValidation: boolean; routeValidation: boolean; cutOff: any; eta: any; sample: any saving:boolean; @Input('inputs') inputs: { locationId: number; loadDate: any; } = {}; constructor( injector: Injector, private _callBack : WillCallServiceServiceProxy ) { super(injector); } ngOnInit(){ let timeId = localStorage.getItem('timeZoneId'); moment.tz.setDefault(timeId); } ngAfterViewInit(){ } show(clinicId?: number) { //let timeId = localStorage.getItem('timeZoneId'); // this.routes=[]; let timeId = localStorage.getItem('timeZoneId'); this.cutOffValidation=null; this.etaValidation = null this.routeValidation= null; let that = this; this.minTime.setHours(this.mytime.getHours()) this.minTime.setMinutes(this.mytime.getMinutes()) this.maxTime.setHours(23) this.maxTime.setMinutes(59) this._callBack.getClinicForCallBackWithId(undefined,clinicId) .subscribe(result=>{ this.txtFilter = result[0] this.clinicId = this.txtFilter.id console.log("Clinic Id" + this.clinicId) // console.log(moment.utc(localStorage.getItem('loadDate'))) this.active = true; // this._callBack.getRoutesByETA(this.txtFilter.id, undefined, moment.tz(localStorage.getItem('loadDate'), timeId), parseInt(localStorage.getItem('operatingLocationId')), true, undefined) // .subscribe(routesresult => { // this.routes = routesresult // if(this.routes.length == 0){ // this.routeValidation = false; // } // // console.log(this.routes) // }); this.modal.show(); }); } getRoutes(event) : void { let timeId = localStorage.getItem('timeZoneId'); this.clinicId = event.id // this._callBack.getRoutesByETA(event.id,undefined, moment.tz(localStorage.getItem('loadDate'), timeId), parseInt(localStorage.getItem('operatingLocationId')), true, undefined) // .subscribe(result => { // // console.log("Clinic Id"+event.id) // this.routes = result // if(this.routes.length == 0){ // this.routeValidation = false; // } // // console.log('routes on get routes') // }); // console.log(moment.utc(localStorage.getItem('loadDate'))) // console.log(event.id) // this._callBack.getRouteByClinic(event.id, moment.utc(localStorage.getItem('loadDate'))) // .subscribe(result => // { // this.routes = result // console.log(this.routes) // } // ); } save(): void { this.saving = true; let timeId = localStorage.getItem('timeZoneId'); // this.spinnerService.show(); //let timeId = localStorage.getItem('timeZoneId'); this.callback.clinicId = this.clinicId // this.routeId =$("#selectOption").val(); // this.callback.routeId = this.routeId this.callback.routeCode = this.routeCode // this.callback.etaDateTime = moment.utc(this.mytime) this.callback.routeDate = moment.tz(localStorage.getItem('loadDate'), timeId) console.log(" Hello" + parseInt(localStorage.getItem('operatingLocationId'))) this.callback.locationId = parseInt(localStorage.getItem('operatingLocationId')); // console.log(this.mytime) // console.log(this.routeId) this._callBack.createCallback(this.callback) .subscribe(result=> { this.spinnerService.hide(); this.notify.info(this.l('SavedSuccessfully')); this.active = false; this.modal.hide(); }); this.saving = false; } saveAndNew(): void{ let that = this; let timeId = localStorage.getItem('timeZoneId'); // this.spinnerService.show(); this.callback.clinicId = this.clinicId // this.routeId =$("#selectOption").val(); // this.callback.routeId = this.routeId this.callback.routeCode = this.routeCode // this.callback.etaDateTime = moment.utc(this.mytime) this.callback.routeDate = moment.tz(localStorage.getItem('loadDate'), timeId) // console.log(this.mytime) // console.log(this.routeId) this._callBack.createCallback(this.callback) .subscribe(result=> { this.spinnerService.hide(); $('#clinicNames').val(''); // that.routes = []; $('#clinicNames').focus(); that.txtFilter = ''; this.notify.info(this.l('SavedSuccessfully')); }); } onShown(): void { $('.kt-select2').select2(); let that = this; $('#selectOption').on("select2:select", function(e) { that.routeCode =$("#selectOption").val().toString(); that.routeCutoffValidation() console.log(that.routeCode) }); } searchForClinic(event) { this._callBack.getClinicForCallback(this.txtFilter,undefined) .subscribe(result => { this.clinics = result; } ); } close(): void { this.active = false; this.modal.hide(); } selectOption(id: number): void{ console.log(id); console.log(this.routeId); } routeCutoffValidation(){ let timeId = localStorage.getItem('timeZoneId'); this.spinnerService.show(); this._callBack.getRouteCutOffValidation(this.clinicId,moment.tz(localStorage.getItem('loadDate'), timeId),this.routeCode,parseInt(localStorage.getItem('operatingLocationId'))) .subscribe(result => { // console.log(this.toTime(result.cutOffTime)) this.cutOffValidation = result.cutOffValidation; this.etaValidation = result.etaValidation; // console.log("cutoff" + this.cutOffValidation) // console.log("eta" + this.etaValidation) // console.log("cutoff" + this.cutOff) // console.log("eta" + this.eta); this.cutOff = this.toTime(result.cutOffTime); this.eta= this.toTime(result.driverEta); }); this.spinnerService.hide(); } toTime(timeString){ var timeTokens = timeString.split(':'); return new Date(1970,0,1, timeTokens[0], timeTokens[1], timeTokens[2]); } }