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, PagedResultDtoOfGetOrganizationUnitOrderNotificationForViewDto, NameValueDto, PagedResultDtoOfNameValueDto, GetControllerRouteLoadDateInputPage, GetLocationNamesInputPage, LocationServiceProxy } from '@shared/service-proxies/service-proxies'; import { PrimengTableHelper } from 'shared/helpers/PrimengTableHelper'; import { finalize } from 'rxjs/operators'; import { Paginator } from 'primeng/components/paginator/paginator'; import { Table } from "primeng/table"; import * as jquery from 'jquery'; import * as moment from 'moment-timezone'; import { ActivatedRoute, Router } from '@angular/router'; import { CommonLookupModalComponent } from '@app/shared/common/lookup/common-lookup-modal.component'; // import * as DualListbox from 'dual-listbox'; @Component({ templateUrl: './move-order-routebuilder.component.html', selector: 'MovePendingOrderRouteBuilder' }) export class MovePendingOrderRouteBuilder extends AppComponentBase { @ViewChild('movePendingOrderModal', { static: false }) modal: ModalDirective; @Output() refresh: 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() locationId: number; @Input() orderList: Array; @Input() routeDate: string; @Input() routeId: number; // @Input() updateTable:Function locationFilter: PagedResultDtoOfNameValueDto = new PagedResultDtoOfNameValueDto(); toAddLocation: NameValueDto; reload: boolean = false; active = false; saving = false; loadDate: any; location:any; timeId: any; orderId:any; orderIds: Array = new Array; routeList: ListResultDtoOfControllerGetAllAvailabelRouteDto = new ListResultDtoOfControllerGetAllAvailabelRouteDto(); moveInput: ControllerMoveOrderInput = new ControllerMoveOrderInput(); _isLab: any; _ukLocale: boolean; todaysDate: string; sample: any movefilteredLocation: any; selectedLocation: any; loadDateString: string; locationName: string; routeName: string; newRouteId: number; constructor( injector: Injector, private _controllerRouteDetails: ControllerRouteDetailServiceProxy, private _controllerOrderService: OrderServiceProxy, private router: Router, private _timingService: TimingServiceProxy, private id: ActivatedRoute, private _locationAppService: LocationServiceProxy ) { super(injector); 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('routeid')); }); 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; // 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(); // } input.loadDateStart = moment.tz(localStorage.getItem('moveOrderLoadDate'), this.timeId); input.loadDateEnd = moment.tz(localStorage.getItem('moveOrderLoadDate'), this.timeId).endOf('day'); input.operatingLocationId = this.locationId; return this._controllerRouteDetails.assignAvailableRoute(input); } }); } show(builderList?: any, routeId?: number, locationId? :any) { this.orderIds = [] let e = this; let dateString = "" this.orderId = undefined; var lang = abp.localization.currentLanguage.name; var str1 = ""; this.location = (locationId == null ? undefined : parseInt(localStorage.getItem('operatingLocationId'))); if (localStorage.getItem('moveOrderLoadDate') == null) { this.todaysDate = moment(Date.now()).format('MM/DD/YYYY'); localStorage.setItem('moveOrderLoadDate', this.todaysDate); } // this.loadDate = moment.tz(localStorage.getItem('loadDate'), this.timeId).toDate(); this._controllerRouteDetails.getAvailableRoute(moment.tz(localStorage.getItem('moveOrderLoadDate'), this.timeId), moment.tz(localStorage.getItem('moveOrderLoadDate'), this.timeId).endOf('day'), localStorage.getItem('timeZone'), this.location, this.routeId, undefined) .subscribe(result => { this.routeList = result; }); this.active = true; this.modal.show(); if (builderList != null) { builderList.forEach(x => { this.orderIds.push(x.orderId); }); } } reloadList(){ // if(this._ukLocale) // { // this.loadDate = new Date(this.loadDate).toLocaleDateString('en-GB'); // } // else{ // this.loadDate = new Date(this.loadDate).toLocaleDateString('en-US'); // } // this.loadDate = new Date(new Date(Date.now()).toLocaleDateString(moment.locale())); var lang = abp.localization.currentLanguage.name; var str1 = ""; 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 = ""; // this.loadDate = moment(this.loadDate).toDate() // this._controllerRouteDetails.getAvailableRoute(moment.tz(localStorage.getItem('moveOrderLoadDate'), this.timeId), // moment.tz(localStorage.getItem('moveOrderLoadDate'), this.timeId).endOf('day'), // localStorage.getItem('timeZone'), this.location, this.routeId,undefined) // .subscribe(result => { // this.routeList = result; // }); } onShown(): void { let e = this; 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(); } acceptOrderId($event) { this.orderIds = $event; } applyMove() { if (this.orderIds != null) { // this.moveOrders(Number((document.getElementById('selectedRouteId')).value), this.orderIds, this.routeId); this.moveOrders(this.newRouteId, this.orderIds, this.routeId); this.notify.info(this.l('SavedSuccessfully')); this.close(); } else { this.notify.info(this.l('Select orders to move')); } } applyMoveGo(){ if (this.orderIds != null) { this.moveOrders(this.newRouteId, this.orderIds, this.routeId); this.notify.info(this.l('SavedSuccessfully')); this.routeName = ""; this.close(); this.router.navigateByUrl("app/sprintship/route-builder/"+this.newRouteId); } else { this.newRouteId = undefined; this.routeName = ""; 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; this.moveInput.id = ids; this._controllerOrderService.moveOrder(this.moveInput) .pipe(finalize(() => this.saving = false)) .subscribe(() => { this.newRouteId = undefined; this.routeName = ""; this.refresh.emit(); }); } close(): void { this.active = false; 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(); } }