import { Component, ViewChild, Injector, Output, EventEmitter } from '@angular/core'; import { ModalDirective } from 'ngx-bootstrap'; import { GetExportMappingForViewDto, ExportMappingDto , ExportType, DataType, ExportMappingsServiceProxy, LocationServiceProxy, OrderTypesServiceProxy, GetExportEDIResult} from '@shared/service-proxies/service-proxies'; import { AppComponentBase } from '@shared/common/app-component-base'; import { FileDownloadService } from '@shared/utils/file-download.service'; import * as moment from 'moment'; import { Router } from '@angular/router'; import { catchError } from 'rxjs/operators'; @Component({ selector: 'exportOrderEdiModal', templateUrl: './export-order-edi.component.html' }) export class ExportOrderEDIModalComponent extends AppComponentBase { @ViewChild('createOrEditModal', { static: true }) modal: ModalDirective; @Output() modalSave: EventEmitter = new EventEmitter(); active = false; saving = false; trackingId:string=""; filteredLocation: any; filteredOrderTypes: any; locationId: number; orderTypeId: number; public dateRange: moment.Moment[] = [moment().startOf('day'), moment().endOf('day')]; timeId: any; loadDateStart: string; loadDateEnd: string; constructor( injector: Injector, private _ExportMappingsServiceProxy: ExportMappingsServiceProxy, private _fileDownloadService: FileDownloadService, private _locationAppService: LocationServiceProxy, private _orderTypeService: OrderTypesServiceProxy, private router: Router, ) { super(injector); } show(): void { this.active = true; this.filterLocation(); this.filterOrderTypes(); this.trackingId=""; this.modal.show(); } onShown(): void{ $('.kt-select2').select2(); } close(): void { this.active = false; this.modal.hide(); } exportOrderToEdi(): void { this.spinnerService.show(); this.timeId = localStorage.getItem('timeZoneId'); this.locationId = !this.trackingId ? Number((document.getElementById('locationSelectInput')).value) ? Number((document.getElementById('locationSelectInput')).value) : undefined : undefined; this.orderTypeId = !this.trackingId ? Number((document.getElementById('orderType')).value) ? Number((document.getElementById('orderType')).value) : undefined : undefined; console.log($("#DateRange").val()); if($("#DateRange").val()!=undefined){ var res = $("#DateRange").val().toString().split(" - ", 3); var dateSplit = res[0].split("/"); var dateSplit1 = res[1].split("/"); this.loadDateStart = dateSplit[2] + '-' + dateSplit[0] + '-' + dateSplit[1]; this.loadDateEnd = dateSplit1[2] + '-' + dateSplit1[0] + '-' + dateSplit1[1] }else{ this.loadDateStart = ""; this.loadDateEnd = ""; } this._ExportMappingsServiceProxy.getOrderExportFile( this.trackingId = !this.trackingId? undefined : this.trackingId, this.loadDateStart, this.loadDateEnd, this.locationId, this.orderTypeId) .pipe(catchError((err, caught): any => { this.spinnerService.hide(); })).subscribe((result: GetExportEDIResult) =>{ if(result!=undefined){ if(result.blobUrl!=undefined){ this.router.navigate([]).then(result1 => { window.open(result.blobUrl, '_blank'); }); // this.message.success('','EDI was sent successfully to your email'); // this._fileDownloadService.downloadTempFile(result); this.spinnerService.hide(); }else{ this.message.warn('', result.message); this.spinnerService.hide(); } } }); } filterLocation(): void { this._locationAppService.getLocationNames( undefined, undefined, undefined, undefined, undefined, undefined ).subscribe(result => { this.filteredLocation = result; }); } filterOrderTypes(): void { this._orderTypeService.getOrderTypes().subscribe(result => { this.filteredOrderTypes = result; }); } }