import { Component, Injector, ViewChild, ViewEncapsulation, Input, Output, EventEmitter, OnInit, AfterViewInit } from '@angular/core'; import { ActivatedRoute, Router } from '@angular/router'; import { appModuleAnimation } from '@shared/animations/routerTransition'; import { AppConsts } from '@shared/AppConsts'; import { AppComponentBase } from '@shared/common/app-component-base'; import { ClinicsServiceProxy, CreateOrEditClinicDto, RouteDefinitionsServiceProxy, CreateOrEditRouteDefinitionDto, RouteTypesServiceProxy, RouteScheduleDetailsServiceProxy, RouteScheduleDetailDto, CreateOrEditRouteScheduleDetailDto, CreateOrEditClinicScheduleDto, LockedEtaScheduleInput} from '@shared/service-proxies/service-proxies'; import { AddressServiceProxy, CreateAddressInput } from '@shared/service-proxies/service-proxies'; import { EmailServiceProxy, CreateEmailInput, AddressTypeServiceProxy, PostalCodeServiceProxy, } from '@shared/service-proxies/service-proxies'; import { RouteSchedulesServiceProxy, CreateOrEditRouteScheduleDto } from '@shared/service-proxies/service-proxies'; import { LazyLoadEvent } from 'primeng/components/common/lazyloadevent'; import { CreateOrEditClinicModalComponent } from './create-or-edit-clinic-modal.component'; import {FormGroup, FormControl} from '@angular/forms'; import { finalize } from 'rxjs/operators'; import * as moment from 'moment'; import * as _ from 'lodash'; import {Location} from '@angular/common'; import { ClinicScheduleFlyOutComponent } from '@app/shared/layout/flyout/clinic-schedule/clinic-schedule-flyout.component'; declare var KTWizard: any; declare var $: any; declare var KTApp: any; declare let swal: any; @Component({ templateUrl: './clinic-schedule.component.html', styleUrls: ['./clinic-schedule.component.less'], encapsulation: ViewEncapsulation.None, animations: [appModuleAnimation()], }) export class ClinicScheduleComponent extends AppComponentBase { @Input('selectedCountry') selectedCountry: string; @Input('selectedCity') selectedCity: string; @Input('selectedState') selectedState: string; @Input('postalCodeId') selectedPostalCodeId: number; @Input('postalCodeValue') selectedPostalCodeValue: string; @ViewChild('createOrEditClinicModal', { static: true }) createOrEditClinicModal: CreateOrEditClinicModalComponent; @ViewChild('clinicScheduleFlyOutComponent', { static: false }) clinicScheduleFlyOutComponent: ClinicScheduleFlyOutComponent; active = false; saving = false; id: any; newSchedule = false; //routeScheduleDetail: CreateOrEditRouteScheduleDetailDto = new CreateOrEditRouteScheduleDetailDto(); scheduleContainer: any[] = []; clinic: CreateOrEditClinicDto = new CreateOrEditClinicDto(); address: CreateAddressInput = new CreateAddressInput(); postalInfo: any; routeTypes: any; routeDefinitions: any; designation: any; schedules: any; newSched: any = {}; routeScheduleId: any; constructor( injector: Injector, private _clinicsServiceProxy: ClinicsServiceProxy, private _addressService: AddressServiceProxy, private _emailService: EmailServiceProxy, private _postalCodeService: PostalCodeServiceProxy, private _addressTypeService: AddressTypeServiceProxy, private _routeDefinitionsServiceProxy: RouteDefinitionsServiceProxy, private _routeScheduleDetailsServiceProxy: RouteScheduleDetailsServiceProxy, private _routeSchedulesServiceProxy: RouteSchedulesServiceProxy, private _location:Location, private _router: Router, private route: ActivatedRoute, ) { super(injector); } dynamicArray: Array = []; newDynamicArray: Array = []; newDynamic: any = {}; date: Date; eta: Array = []; cutOff: Array = []; effectivityDate: Array = []; oorRate: Array = []; savedDesignation: Array = []; i: any; savedSchedules: any = []; newSavedSchedules: Array = []; designationSelect: any; scheduleId: any; clinicId: any; lockedEtaInput: LockedEtaScheduleInput = new LockedEtaScheduleInput(); ngOnInit() { //this.paginator.changePage(0); //this.primengTableHelper.showLoadingIndicator(); this.route.paramMap.subscribe(params => { this.id = params.get("id") }) this.showSchedule(); } goBack(){ this._location.back(); } createClinicSchedule(): void { this.createOrEditClinicModal.show(undefined, this.scheduleId, this.clinic.id); } showSchedule() { this.active = true; this._clinicsServiceProxy.getClinicForEdit(this.id).subscribe(result => { //console.log(result); //this.spinnerService.show(); this.clinic = result.clinic; this.address = result.clinic.address; if(this.address.postalCodeId != 0) { this._postalCodeService.getPostalCodeEdit(this.address.postalCodeId).subscribe(resultPostalCode => { //this.spinnerService.show(); this.selectedCountry = resultPostalCode.country; this.selectedState = resultPostalCode.state; this.selectedCity = resultPostalCode.city; this.selectedPostalCodeValue = resultPostalCode.value; }); } }); var that = this; this._clinicsServiceProxy.getClinicSchedule(this.id).subscribe(result => { this.schedules = result.items; //console.log(this.schedules[0]['estimatedTimeOfArrival']); //this.schedules.estimatedTimeOfArrival = result.items.estimatedTimeOfArrival.toDate(); if(result.items.length == 0) { that._routeSchedulesServiceProxy.getAll( that.clinic.id, undefined, undefined, undefined, undefined, undefined ).subscribe(resultSched => { that.routeScheduleId = resultSched.items; if(resultSched.items.length == 0) { that.newSchedule = true; //routeScheduleDetail.routeScheduleId = undefined; that.scheduleId = undefined; } else { that.newSchedule = false; //routeScheduleDetail.routeScheduleId = that.routeScheduleId[0]['routeSchedule']['id']; that.scheduleId = that.routeScheduleId[0]['routeSchedule']['id']; } }); //routeScheduleDetail.routeScheduleId = undefined; //this.newDynamic = {routeCode: "", routeType: "",eta:"", cutOff:"", effectivityDate:"", designation:"auto",oor:"6.18",routeScheduleId:this.schedules[0]['routeScheduleId']}; } else { result.items.forEach(function (value) { that.scheduleId = value.routeScheduleId; }); } //this.spinnerService.hide(); }); } deleteRouteScheduleDetail(routeScheduleDetail: RouteScheduleDetailDto): void { this.message.confirm( '', (isConfirmed) => { if (isConfirmed) { this._routeScheduleDetailsServiceProxy.delete(routeScheduleDetail.id) .subscribe(() => { this.reloadPage(); this.notify.success(this.l('SuccessfullyDeleted')); }); } } ); } reloadPage(): void { this.showSchedule(); } showFlyOut() : void { this.clinicScheduleFlyOutComponent.showFlyout(this.clinic); } lockEta(id: number, value: boolean) { this.lockedEtaInput.id = id; this.lockedEtaInput.etaLocked = value; //console.log(this.lockedEtaInput); this.message.confirm( '', (isConfirmed) => { if (isConfirmed) { this._routeScheduleDetailsServiceProxy.lockedEtaSchedule(this.lockedEtaInput) .pipe(finalize(() => { this.saving = false;})) .subscribe(() => { this.notify.info(this.l('SavedSuccessfully')); this.reloadPage(); }); } } ); } }