import { Component, EventEmitter, Injector, ViewChild, Output, Input } from '@angular/core'; import { AppComponentBase } from '@shared/common/app-component-base'; import { ModalDirective } from 'ngx-bootstrap'; import { ControllerRouteDetailServiceProxy, OrderServiceProxy, ControllerMoveOrderInput, ListResultDtoOfControllerGetAllAvailabelRouteDto, TimingServiceProxy, LocationServiceProxy, NameValueDto, PagedResultDtoOfNameValueDto, GetLocationNamesInputPage, GetControllerRouteLoadDateInputPage } from '@shared/service-proxies/service-proxies'; import { PrimengTableHelper } from 'shared/helpers/PrimengTableHelper'; import { HFRouteDetailComponent } from './hf-route-detail.component'; import { finalize } from 'rxjs/operators'; import { Paginator } from 'primeng/components/paginator/paginator'; import { Table } from "primeng/table"; import * as moment from 'moment-timezone'; import { ActivatedRoute } from '@angular/router'; import { CommonLookupModalComponent } from '@app/shared/common/lookup/common-lookup-modal.component'; declare var $: any; // import * as DualListbox from 'dual-listbox'; @Component({ templateUrl: './move-order-modal.component.html', selector: 'MovePendingOrder' }) export class MovePendingOrder extends AppComponentBase { @ViewChild('movePendingOrderModal', { static: false }) modal: ModalDirective; @Output() reloadTable: EventEmitter = new EventEmitter(); @Output() reloadTablePackages: EventEmitter = new EventEmitter(); @Input('selectedRouteId') selectedRouteId: number; @ViewChild("paginator", { static: true }) paginator: Paginator; @ViewChild("dataTable", { static: true }) dataTable: Table; @ViewChild('locationList', { static: true }) locationList: CommonLookupModalComponent; @ViewChild('routesList', { static: true }) routesList: CommonLookupModalComponent; @Input() refreshRouteMove: Function @Input() refreshRouteBatchMove: Function // @Input() updateTable:Function locationFilter: PagedResultDtoOfNameValueDto = new PagedResultDtoOfNameValueDto(); toAddLocation: NameValueDto; reload: boolean = false; active = false; saving = false; loadDate: Date; location:any; timeId: any; orderId:any; orderIds: Array = new Array; routeId: any; routeDate: any routeList: ListResultDtoOfControllerGetAllAvailabelRouteDto = new ListResultDtoOfControllerGetAllAvailabelRouteDto(); moveInput: ControllerMoveOrderInput = new ControllerMoveOrderInput(); _isLab: any; _ukLocale: boolean; sample: any movefilteredLocation: any; selectedLocation: any; locationId: any; todaysDate: string; loadDateString: string; locationName: string; routeName: string; newRouteId: number; locationData: any; constructor( injector: Injector, private _controllerRouteDetails: ControllerRouteDetailServiceProxy, private _controllerOrderService: OrderServiceProxy, private _timingService: TimingServiceProxy, private id: ActivatedRoute, private _locationAppService: LocationServiceProxy ) { super(injector); this.locationId = localStorage.getItem('operatingLocationId') == null ? 0 :parseInt(localStorage.getItem('operatingLocationId')); this._isLab = abp.features.isEnabled('App.RouteDetails'); this.todaysDate = moment(Date.now()).format('MM/DD/YYYY'); if (localStorage.getItem('moveOrderLoadDate') == null) { this.todaysDate = moment(Date.now()).format('MM/DD/YYYY'); localStorage.setItem('moveOrderLoadDate', this.todaysDate); } } ngOnInit() { this._ukLocale = abp.features.isEnabled('App.DateFormatFeature.UKLocale'); this.timeId = localStorage.getItem('timeZoneId'); // moment.tz.setDefault(this.timeId); this.id.paramMap.subscribe(params => { this.routeId = Number(params.get('id')); }); this.filterLocation(); $('.kt-select2').select2(); let that = this; that.locationId = localStorage.getItem('operatingLocationId') == null ? 0 :parseInt(localStorage.getItem('operatingLocationId')); if (localStorage.getItem('moveOrderLoadDate') == null) { $(".RouteDate").val(moment(this.todaysDate).format('MM/DD/YYYY')); this.loadDate = moment(Date.now()).toDate(); }else { if(localStorage.getItem('moveOrderLoadDate').search('-') > 0) { var str = localStorage.getItem('moveOrderLoadDate').split('-'); var str1 = str[1] + '/' + str[2] + '/' + str[0]; localStorage.setItem('moveOrderLoadDate',str1); } $(".RouteDate").val(localStorage.getItem('moveOrderLoadDate')); this.loadDate = moment.tz(localStorage.getItem('moveOrderLoadDate'), this.timeId).toDate() } this.locationList.configure({ title: this.l('Select Location'), dataSource: (skipCount: number, maxResultCount: number, filter: string, tenantId?: number, locationId?: number) => { let input = new GetLocationNamesInputPage(); input.filter = filter; input.maxResultCount = maxResultCount; input.skipCount = skipCount; return this._locationAppService.assignLocationList(input); } }); this.routesList.configure({ title: this.l('Select Route'), dataSource: (skipCount: number, maxResultCount: number, filter: string, tenantId?: number, locationId?: number) => { let input = new GetControllerRouteLoadDateInputPage(); input.filter = filter; input.maxResultCount = maxResultCount; input.skipCount = skipCount; input.routeId = this.routeId; input.loadDateStart = moment.tz(localStorage.getItem('moveOrderLoadDate'), that.timeId); input.loadDateEnd = moment.tz(localStorage.getItem('moveOrderLoadDate'), that.timeId).endOf('day'); input.operatingLocationId = this.locationId; return this._controllerRouteDetails.assignAvailableRoute(input); } }); // this.loadDateString = } filterLocation(): void { this._locationAppService.getLocationNames( undefined, undefined, undefined, undefined, undefined, undefined ).subscribe(result => { this.movefilteredLocation = result; }); } show(orderId?: number, routeId?: number, locationId? :any) { let that = this; let dateString = ""; that.locationId = localStorage.getItem('operatingLocationId') == null ? 0 : parseInt(localStorage.getItem('operatingLocationId')); this.location = localStorage.getItem('operatingLocationId') == null ? $("#selectedLocation").val() : parseInt(localStorage.getItem('operatingLocationId')); if (localStorage.getItem('moveOrderLoadDate') == null) { this.todaysDate = moment(Date.now()).format('MM/DD/YYYY'); localStorage.setItem('moveOrderLoadDate', this.todaysDate); } that.orderId = orderId == null ? undefined : orderId; that.active = true; that.modal.show(); if (orderId != null) { that.orderIds = []; that.orderIds.push(orderId); } let input = new GetLocationNamesInputPage(); input.filter = ""; input.maxResultCount = 10; input.skipCount = 0; input.id = that.locationId; this._locationAppService.assignLocationList(input).subscribe(result => { if(result.totalCount!=0){ this.locationName = result.items[0].name; this.locationId = parseInt(this.locationData[0].value); } }); } reloadList(){ var lang = abp.localization.currentLanguage.name; if(lang=="en-GB"){ var str = $('.RouteDate').val().toString().split('/'); var str1 = str[1] + '/' + str[0] + '/' + str[2]; localStorage.setItem('moveOrderLoadDate', str1); }else{ var str = $('.RouteDate').val().toString().split('/'); var str1 = str[0] + '/' + str[1] + '/' + str[2]; localStorage.setItem('moveOrderLoadDate', str1); } this.newRouteId = undefined; this.routeName = ""; // let timeId = localStorage.getItem('timeZoneId'); // this.locationId = localStorage.getItem('operatingLocationId') == null ? 0 : parseInt(localStorage.getItem('operatingLocationId')); // this.location = localStorage.getItem('operatingLocationId') == null ? $("#selectedLocation").val() : parseInt(localStorage.getItem('operatingLocationId')); // this.location = $("#selectedLocation").val(); // this._controllerRouteDetails.getAvailableRoute(moment.tz(localStorage.getItem('moveOrderLoadDate'), this.timeId), // moment.tz(localStorage.getItem('moveOrderLoadDate'), this.timeId).endOf('day'), // localStorage.getItem('timeZone'), this.location, undefined, this.orderId) // .subscribe(result => { // this.routeList = result; // }); } onShown(): void { let that = this; if(this._isLab){ if (localStorage.getItem('moveOrderLoadDate') == null) { $(".RouteDate").val(moment(that.todaysDate).format('MM/DD/YYYY')); that.loadDate = moment(Date.now()).toDate(); }else { if(localStorage.getItem('moveOrderLoadDate').search('-') > 0) { var str = localStorage.getItem('moveOrderLoadDate').split('-'); var str1 = str[1] + '/' + str[2] + '/' + str[0]; localStorage.setItem('moveOrderLoadDate',str1); } $(".RouteDate").val(localStorage.getItem('moveOrderLoadDate')); that.loadDate = moment.tz(localStorage.getItem('moveOrderLoadDate'), that.timeId).toDate() } } else{ //for todays date upon show if (localStorage.getItem('moveOrderLoadDate') == null) { $(".RouteDate").val(moment(that.todaysDate).format('MM/DD/YYYY')); that.loadDate = moment(Date.now()).toDate(); }else { if(localStorage.getItem('moveOrderLoadDate').search('-') > 0) { var str = localStorage.getItem('moveOrderLoadDate').split('-'); var str1 = str[1] + '/' + str[2] + '/' + str[0]; localStorage.setItem('moveOrderLoadDate',str1); } // $(".RouteDate").val(localStorage.getItem('moveOrderLoadDate')); that.loadDate = moment(Date.now()).toDate(); localStorage.setItem('moveOrderLoadDate', this.todaysDate); // that.loadDate = moment.tz(localStorage.getItem('moveOrderLoadDate'), that.timeId).toDate() } } $('.kt-select2').select2(); $("#selectedLocation").on('change',function(e){ // that.reloadList(); }); this.locationId = localStorage.getItem('operatingLocationId') == null ? 0 : parseInt(localStorage.getItem('operatingLocationId')); this.location = localStorage.getItem('operatingLocationId') == null ? $("#selectedLocation").val() : parseInt(localStorage.getItem('operatingLocationId')); } acceptOrderId($event) { this.orderIds = $event; } applyMove() { if (this.orderIds != null) { this.moveOrders(this.newRouteId, this.orderIds, this.routeId); this.routeName = ""; this.routeId = null; this.notify.info(this.l('SavedSuccessfully')); this.close(); } else { this.routeName = ""; this.routeId = null; this.notify.info(this.l('Select orders to move')); } } moveOrders(routeId: number, ids: any, originRouteId: number) { this.spinnerService.show(); this.moveInput.selectedRouteId = routeId; this.moveInput.originRouteId = originRouteId==0 || originRouteId==undefined ? undefined : originRouteId; this.moveInput.id = ids; this._controllerOrderService.moveOrder(this.moveInput) .pipe(finalize(() => this.saving = false)) .subscribe(() => { this.moveInput.id.forEach(element => { this.reloadTablePackages.emit(null); }); this.reloadTable.emit(null); this.spinnerService.hide(); }, error =>{ this.spinnerService.hide(); }); } onChange(deviceValue) { } close(): void { this.active = false; this.routeName = ""; this.routeId = null; this.modal.hide(); } assignLocation(): void { this.locationList.show(); } selectLocation(item: NameValueDto): void { this.locationId = parseInt(item.value); this.locationName = item.name; } assignRoute(): void { this.routesList.show(); } selectRoute(item: NameValueDto): void { this.newRouteId = parseInt(item.value); this.routeName = item.name; // this.applyMove(); } }