import { Component, ViewChild, Injector, Output, EventEmitter, Input, ViewContainerRef} from '@angular/core'; import { ModalDirective } from 'ngx-bootstrap'; import { finalize } from 'rxjs/operators'; import { PostalCodesServiceProxy, CreateOrEditPostalCodeDto, OrderStatusTypeServiceProxy, OrderStatusServiceProxy, OrderStatusDto, CreateOrderStatusInput, ControllerOrderPackagesListServiceProxy, AddBatchOrderStatusInput, NameValueDto, GetAllRouteStopsInput, RouteServiceProxy, RouteStopsServiceProxy, TimingServiceProxy, OrderStatusDescriptionListDto } 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 { ControllerOrderPackageDetailComponent } from '../order-packages/order-packages-detail.component'; import { ViewOrderStatusComponent } from './view-order-status.component' import { CommonLookupModalComponent } from '@app/shared/common/lookup/common-lookup-modal.component'; declare var $: any; @Component({ selector: 'addBatchOrderStatusModal', templateUrl: './add-order-status-modal.component.html', styleUrls: ['./add-order-status-modal.component.less'] }) export class AddBatchOrderStatusModalComponent extends AppComponentBase { @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 value:Date orderStatusNote:string orderStatusLongitude: any orderStatusLatitude : any orderStatusTime:any orderIds: []; DateObject = Date currentDate = moment().format("MM/DD/YYYY HH:mm"); orderArray:Array = []; batchOrders:any statusBoolean=false; routeStop : string; lat: any; long: any; showSearchOnStart : boolean; _ukLocale: any; dateTime : Date; orderStatusDefinitions: OrderStatusDescriptionListDto[]; orderStatus: CreateOrderStatusInput = new CreateOrderStatusInput(); constructor( injector: Injector, private _orderStatusAppService : OrderStatusServiceProxy, private _orderStatusTypeAppService : OrderStatusTypeServiceProxy, private _orderPackageListAppService : ControllerOrderPackagesListServiceProxy, private _routeStopsAppService: RouteStopsServiceProxy, private viewContainerRef: ViewContainerRef, private _timingAppService: TimingServiceProxy ) { super(injector); } // orderStatusUpdate(get: boolean){ // this.statusEvent.emit(get) // } ngOnInit(){ this.routeStopModalInit(); } getParentComponent() { return this.viewContainerRef[ '_data' ].componentView.component.viewContainerRef[ '_view' ].component } 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._routeStopsAppService.showPagedRouteStop(input); } }); } passedData($event){ this.orderIds = $event; } onShown(): void{ this.showSearchOnStart = true; $('.kt-select2').select2(); } show(): void { if(this.orderIds === undefined || this.orderIds.length == 0) { this.message.error('No orders selected'); } else { this.getOrderStatusType(); this.active = true; this.modal.show(); this.orderStatus.note = null this.dateTime = new Date(); this._ukLocale = abp.features.isEnabled('App.DateFormatFeature.UKLocale'); 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"); } else{ this.orderStatusTime = result.format("MM/DD/YYYY h:mm a"); } }) this.orderStatusLongitude = null; this.orderStatusLatitude = null; } } getOrderStatusType(): void{ this._orderPackageListAppService.getOrderDescriptionList() .pipe(finalize(() => this.spinnerService.hide())).subscribe(result => { this.orderStatusDefinitions=result.items; }); } save(): void { this.saving = true; if(moment.utc(this.orderStatusTime) != moment.utc(this.currentDate)){ this.orderStatus.time = moment.utc(this.orderStatusTime) } else{ this.orderStatus.time = moment.utc(this.currentDate); } console.log(this.orderStatus.time) this.orderStatus.orderStatusTypeId=Number((document.getElementById('OrderStatusType')).value); // this.orderStatus.note=String((document.getElementById('OrderStatusNote')).value); this.orderStatus.latitude = Number(this.lat).valueOf(); this.orderStatus.longitude = Number(this.long).valueOf(); //this.orderStatus.orderId = this.orderIds; this.orderArray = []; for(let index = 0; index { this.saving = false;})) .subscribe(() => { this.modalSave.emit(null); console.log(this.getParentComponent()); //this.getParentComponent() this.notify.info(this.l('SavedSuccessfully')); this.close(); }); } close(): void { this.active = false; this.modal.hide(); } // selectRouteStop(item:NameValueDto):void{ // //console.log(item) // } selectRouteStop(item){ let that = this; if(this.showSearchOnStart) { this._routeStopsAppService.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; } }); } } getRouteStop(routeStop : any){ this.routeStopList.show(); this.routeStopList.filterText = routeStop; } clearRouteStop(): void{ this.showSearchOnStart = true; this.routeStop = ''; this.lat = ''; this.long = ''; } }