import { Component, ViewChild, Injector, Output, EventEmitter, Input, OnInit} from '@angular/core'; import { ModalDirective } from 'ngx-bootstrap'; import { finalize } from 'rxjs/operators'; import { PostalCodesServiceProxy, GetAllRouteStopsInput, OrderStatusTypeServiceProxy, OrderStatusServiceProxy, OrderStatusDto, CreateOrderStatusInput, ControllerOrderPackagesListServiceProxy, TimingServiceProxy, OrderStatusDescriptionListDto, RouteStopsServiceProxy, GetRouteStopForViewDto, NameValueDto } from '@shared/service-proxies/service-proxies'; import { AppComponentBase } from '@shared/common/app-component-base'; import {CalendarModule} from 'primeng/calendar'; import * as moment from 'moment'; import { CommonLookupModalComponent } from '@app/shared/common/lookup/common-lookup-modal.component'; declare var $: any; @Component({ selector: 'addOrderStatusModal', templateUrl: './add-order-status-modal.component.html', styleUrls: ['./add-order-status-modal.component.less'] }) export class AddOrderStatusModalComponent extends AppComponentBase implements OnInit { @ViewChild('routeStopList', {static: true}) routeStopList: CommonLookupModalComponent; @ViewChild('createOrEditModal', { static: true }) modal: ModalDirective; @Input() orderId:number; @Output() modalSave: EventEmitter = new EventEmitter(); @Output() statusEvent: EventEmitter = new EventEmitter(); @Input() myFunction:Function active = false; saving = false; orderStatusTypes: any; routeStop : string; orderStatusDefinitions: OrderStatusDescriptionListDto[]; showStop : boolean = true; lat: any; long: any; value:Date orderStatusNote:string orderStatusLongitude: any orderStatusLatitude : any orderStatusTime:any currentDate:any DateObject = Date; showSearchOnStart : boolean; // currentDate = moment().format("MM/DD/YYYY h:mm a") currentDateConvert: any; statusBoolean=false; dateTime : Date _ukLocale: any stops : GetRouteStopForViewDto[]; orderStatus: CreateOrderStatusInput = new CreateOrderStatusInput(); constructor( injector: Injector, private _orderStatusAppService : OrderStatusServiceProxy, private _timingAppService : TimingServiceProxy, private _orderStatusTypeAppService : OrderStatusTypeServiceProxy, private _orderPackageListAppService : ControllerOrderPackagesListServiceProxy, private _routeStop : RouteStopsServiceProxy, private _routeStopsService: RouteStopsServiceProxy, ) { super(injector); } // orderStatusUpdate(get: boolean){ // this.statusEvent.emit(get) // } ngOnInit(){ this._ukLocale = abp.features.isEnabled('App.DateFormatFeature.UKLocale'); } routeStopModalInit(){ this.routeStopList.configure({ title: this.l('Select stop'), dataSource: (skipCount: number, maxResultCount: number, filter: string, tenantId?: number, locationId?:number) => { let input = new GetAllRouteStopsInput(); input.filter = filter; input.maxResultCount = maxResultCount; input.skipCount = skipCount; return this._routeStopsService.showPagedRouteStop(input); } }); } selectRouteStop(item){ let that = this; if(this.showSearchOnStart) { this._routeStopsService.getRouteStopByContactId(item.value) .subscribe(result => { if(result.routeStop != undefined){ that.routeStop = result.contactName + ' - ' + result.contactAddress; that.lat = result.lat; that.long = result.long; that.showSearchOnStart = false; } }); } else { } } clearRouteStop(): void{ this.showSearchOnStart = true; this.routeStop = ''; this.lat = ''; this.long = ''; } onShown(): void{ $('.kt-select2').select2(); this.showSearchOnStart = true; this.routeStop = ''; // this.orderTypeChange(); // let that = this; // $("#Stops").on('change', function(e) { // let selectedId = $("#Stops").val(); // let stop = that.stops.filter(c => c.routeStop.id == selectedId)[0]; // if(typeof(stop) != 'undefined') { // that.lat = stop.lat; // that.long = stop.long; // } // }); } getRouteStop(routeStop : any){ this.routeStopList.show(); this.routeStopList.filterText = routeStop; } // orderTypeChange() { // let that = this; // $("#OrderStatusType").on('change',function(e){ // that.lat = ''; // that.long = ''; // $("#Stops").val('').change(); // let orderStatusId = $("#OrderStatusType").val(); // let parentId = that.orderStatusDefinitions.filter(c => c.orderStatusTypeId == orderStatusId)[0].parentId; // if(parentId) { // let parent = that.orderStatusDefinitions.filter(c => c.id == parentId)[0]; // if(parent.name.toUpperCase() == "REDELIVERY") // { // $('#StopDiv').show(); // return; // } // } // else if(that.orderStatusDefinitions.filter(c => c.orderStatusTypeId == orderStatusId)[0].name.toUpperCase() == "REDELIVERY") // { // $('#StopDiv').show(); // return; // } // $('#StopDiv').hide(); // }); // $('#StopDiv').hide(); // } show(): void { var that= this this.lat = ''; this.long = ''; this.dateTime = new Date(); this._ukLocale = abp.features.isEnabled('App.DateFormatFeature.UKLocale'); // this.getStop(); this.routeStopModalInit(); this.getOrderStatusType(); // console.log(dateTime) this._timingAppService.convertToTimezone(moment(this.dateTime),localStorage.getItem('timeZone')) .pipe().subscribe(result => { if(this._ukLocale && result){ this.orderStatusTime = result.format("DD/MM/YYYY h:mm a") // console.log(this.orderStatusTime) } else{ this.orderStatusTime = result.format("MM/DD/YYYY h:mm a") } // this.currentDate = result.format("MM/DD/YYYY h:mm a") //console.log(this.orderStatusTime) }) this.active = true; this.modal.show(); this.orderStatus.note = null // this.orderStatus.orderStatusTypeId = null this.orderStatusLongitude = null this.orderStatusLatitude=null // this.currentDateConvert = this.currentDate // this.orderStatusTime=this.currentDate // this._timingAppService.convertToTimezone(this.currentDateConvert, localStorage.getItem('timeZone')) // .pipe(finalize(() => this.spinnerService.hide())).subscribe(result => { // console.log(result) // // this.orderStatusTime=result // }); // console.log(that.currentDate) // this._timingAppService.convertToTimezone(moment(), "UTC") // .pipe() // .subscribe(result => { // console.log(result) // }); // console.log("this is the input id"+this.orderId) // console.log(moment().local()) } // getOrderStatusType(): void{ // this._orderPackageListAppService.getOrderStatusTypeList() // .pipe(finalize(() => this.spinnerService.hide())).subscribe(result => { // this.orderStatusTypes=result.items; // }); // } getOrderStatusType(): void{ this._orderPackageListAppService.getOrderDescriptionList() .pipe(finalize(() => this.spinnerService.hide())).subscribe(result => { this.orderStatusDefinitions=result.items; }); } save(e): void { this.saving = true; let header = document.querySelector('.kt-header'); this._timingAppService.convertToTimezone(moment(this.dateTime), "UTC") .pipe() .subscribe(result => { this.orderStatus.time = result this.orderStatus.orderStatusTypeId=Number((document.getElementById('OrderStatusType')).value); // this.orderStatus.note=String((document.getElementById('OrderStatusNote')).value); this.orderStatus.latitude= Number(this.lat).valueOf() //Number((document.getElementById('OrderStatusLatitude')).value); this.orderStatus.longitude= Number(this.long).valueOf() //Number((document.getElementById('OrderStatusLongitude')).value); this.orderStatus.orderId = this.orderId; this.orderStatus.bgColor = getComputedStyle(header).backgroundColor; console.log(this.orderStatus); this._orderPackageListAppService.createOrderPackageOrderStatus(this.orderStatus) .pipe(finalize(() => { this.saving = false;})) .subscribe(() => { this.notify.info(this.l('SavedSuccessfully')); this.close(); this.modalSave.emit(null); // this.myFunction(); // this.orderStatusUpdate(true) }); }); } close(): void { this.active = false; this.modal.hide(); this.routeStop = ''; } // getStop(id : any){ // this._routeStop.getRouteStopForDropDown().subscribe(result => { // this.stops = result.items // }); // }; }