import { Component, Injector, ViewEncapsulation, ViewChild } from '@angular/core'; import { ActivatedRoute, Router } from '@angular/router'; import { ClientConnectionsServiceProxy, ClientConnectionDto, ClientAccountsServiceProxy, ClientAccountDto, OrderSourcesServiceProxy, OrderSourceDto } from '@shared/service-proxies/service-proxies'; import { NotifyService } from '@abp/notify/notify.service'; import { AppComponentBase } from '@shared/common/app-component-base'; import { TokenAuthServiceProxy } from '@shared/service-proxies/service-proxies'; import { appModuleAnimation } from '@shared/animations/routerTransition'; import { Table } from 'primeng/components/table/table'; import { Paginator } from 'primeng/components/paginator/paginator'; import { LazyLoadEvent } from 'primeng/components/common/lazyloadevent'; import { FileDownloadService } from '@shared/utils/file-download.service'; import { EntityTypeHistoryModalComponent } from '@app/shared/common/entityHistory/entity-type-history-modal.component'; import * as _ from 'lodash'; import * as moment from 'moment'; import { CreateOrEditClientAccountModalComponent } from './create-or-edit-client-account-modal.component'; import { DownloadOrdersModalComponent } from './download-orders-modal.component'; @Component({ templateUrl: './client-account.component.html', encapsulation: ViewEncapsulation.None, animations: [appModuleAnimation()] }) export class ClientAccountsComponent extends AppComponentBase { @ViewChild('createOrEditClientAccountModal', { static: true }) createOrEditClientAccountModal: CreateOrEditClientAccountModalComponent; @ViewChild('downloadOrdersModalComponent', { static: true }) downloadOrdersModalComponent: DownloadOrdersModalComponent; // @ViewChild('viewClientConnectionModalComponent', { static: true }) viewClientConnectionModal: ViewClientConnectionModalComponent; @ViewChild('entityTypeHistoryModal', { static: true }) entityTypeHistoryModal: EntityTypeHistoryModalComponent; @ViewChild('dataTable', { static: true }) dataTable: Table; @ViewChild('paginator', { static: true }) paginator: Paginator; advancedFiltersAreShown = false; filterText = ''; accountNumber= ''; orderSourceId : number; connectionId : number; _entityTypeFullName = 'SprintTek.Shipping.Integration.ClientAccount'; entityHistoryEnabled = false; connections: ClientConnectionDto[]; orderSources: OrderSourceDto[]; constructor( injector: Injector, private _clientConnectionsServiceProxy: ClientConnectionsServiceProxy, private _clientAccountServiceProxy: ClientAccountsServiceProxy, private _orderSourcesServiceProxy: OrderSourcesServiceProxy, private _router: Router ) { super(injector); } ngOnInit(): void { this.entityHistoryEnabled = this.setIsEntityHistoryEnabled(); $('.kt-select2').select2(); this.getConnections(); this.getOrderSources(); } private setIsEntityHistoryEnabled(): boolean { let customSettings = (abp as any).custom; return customSettings.EntityHistory && customSettings.EntityHistory.isEnabled && _.filter(customSettings.EntityHistory.enabledEntities, entityType => entityType === this._entityTypeFullName).length === 1; } getClientAccounts(event?: LazyLoadEvent) { this.orderSourceId = $('#OrderSource').val()==null || $('#OrderSource').val()=="null" ? undefined : Number($('#OrderSource').val()); this.connectionId = $('#Connection').val()==null || $('#Connection').val()=="null" ? undefined : Number($('#Connection').val()); if (this.primengTableHelper.shouldResetPaging(event)) { this.paginator.changePage(0); return; } this.spinnerService.show(); this._clientAccountServiceProxy.getAll( this.filterText, this.accountNumber, this.orderSourceId, this.connectionId, this.primengTableHelper.getSorting(this.dataTable), this.primengTableHelper.getSkipCount(this.paginator, event), this.primengTableHelper.getMaxResultCount(this.paginator, event) ).subscribe(result => { this.primengTableHelper.totalRecordsCount = result.totalCount; this.primengTableHelper.records = result.items; this.spinnerService.hide(); }); } reloadPage(): void { this.paginator.changePage(this.paginator.getPage()); } createClientAccount(): void { this.createOrEditClientAccountModal.show(); } showHistory(clientAccount: ClientAccountDto): void { this.entityTypeHistoryModal.show({ entityId: clientAccount.id.toString(), entityTypeFullName: this._entityTypeFullName, entityTypeDescription: '' }); } deleteClientAccount(clientAccount: ClientAccountDto): void { this.message.confirm( '', '', (isConfirmed) => { if (isConfirmed) { this._clientAccountServiceProxy.delete(clientAccount.id) .subscribe(() => { this.reloadPage(); this.notify.success(this.l('SuccessfullyDeleted')); }); } } ); } exportToExcel(): void { this._clientAccountServiceProxy.getClientConnectionsToExcel( this.filterText, this.accountNumber, this.orderSourceId, this.connectionId, ) .subscribe(result => { if(result!=undefined){ if(result.fileUrl!=undefined){ this._router.navigate([]).then(result1 => { window.open(result.fileUrl, '_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(); } }else{ this.spinnerService.hide(); } }); } openOrderSource(url: any, id?: number){ if(id != null){ var myurl = `${url}/${id}`; }else{ var myurl = `${url}`; } this._router.navigateByUrl(myurl); } downloadOrders(connectionId: number){ this.downloadOrdersModalComponent.show(connectionId); } getConnections(){ this.spinnerService.show(); this._clientConnectionsServiceProxy.getConnections().subscribe(o =>{ this.connections = o; this.spinnerService.hide(); }); } getOrderSources(){ this.spinnerService.show(); this._orderSourcesServiceProxy.getOrderSources().subscribe(o =>{ this.orderSources = o; this.spinnerService.hide(); }); } }