import { Component, ViewChild, Injector, Output, EventEmitter} from '@angular/core'; import { ModalDirective } from 'ngx-bootstrap'; import { finalize } from 'rxjs/operators'; import { ClientAccountsServiceProxy, ClientConnectionDto, ClientConnectionsServiceProxy, CreateOrEditClientAccountDto, CreateOrEditClientConnectionDto, DownloadOrdersInput, GetClientConnectionForViewDto, OrderSourceDto, OrderSourcesServiceProxy, PagedResultDtoOfGetClientConnectionForViewDto } from '@shared/service-proxies/service-proxies'; import { AppComponentBase } from '@shared/common/app-component-base'; import * as moment from 'moment'; import { AbpSessionService } from 'abp-ng2-module/dist/src/session/abp-session.service'; @Component({ selector: 'downloadOrdersModalComponent', templateUrl: './download-orders-modal.component.html' }) export class DownloadOrdersModalComponent extends AppComponentBase { @ViewChild('createOrEditModal', { static: true }) modal: ModalDirective; @Output() modalSave: EventEmitter = new EventEmitter(); active = false; saving = false; clientAccount: CreateOrEditClientAccountDto = new CreateOrEditClientAccountDto; downloadInput: DownloadOrdersInput = new DownloadOrdersInput; connections: ClientConnectionDto[]; orderSources: OrderSourceDto[]; result: any; public dateRange: moment.Moment[] = [moment().startOf('day'), moment().endOf('day')]; accountId: number; recordsPerPage: number; constructor( private _clientAccountServiceProxy: ClientAccountsServiceProxy, private _abpSessionService: AbpSessionService, injector: Injector, ) { super(injector); } ngOnInit(){ } show(accountId: number): void { this.accountId = accountId; this.dateRange = [moment().startOf('day'), moment().endOf('day')]; this.recordsPerPage = undefined; this.modal.show(); } close(): void { this.active = false; this.modal.hide(); } save(){ this.saving = true; let timeId = localStorage.getItem('timeZoneId'); var str = $("#DateRange").val().toString(); var _str = str.split('-'); this.downloadInput.startDate = moment.tz(_str[0].trim(), timeId); this.downloadInput.endDate = moment.tz(_str[1].trim(), timeId); this.downloadInput.recordPerPage = this.recordsPerPage; this.downloadInput.accountId = this.accountId; this.downloadInput.tenantId = this._abpSessionService.tenantId; var date1 = new Date(_str[0].trim()); var date2 = new Date(_str[1].trim()); var Time = date2.getTime() - date1.getTime(); var Days = Time / (1000 * 3600 * 24); if(this.recordsPerPage > 500){ this.saving = false; this.message.warn('','The maximum number of orders that can be downloaded in a batch is 500.'); }else if(Days > 7){ this.saving = false; this.message.warn('','DateRange is more than 7 Days. Please correct Selected FromDate and ToDate.'); } else{ // console.log(this.downloadInput); this._clientAccountServiceProxy.downloadOrders(this.downloadInput).subscribe(o => { this.saving = false; this.notify.info(this.l('Downloading Orders')); this.modal.hide(); }); } } }