import { Component, Injector, ViewEncapsulation, ViewChild, NgModule } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; import { ClinicsServiceProxy, ClinicDto, WillCallServiceServiceProxy, OrderStatusTypeServiceProxy, ControllerOrderPackagesListServiceProxy, OrderTypesServiceProxy, CreateGoBackOrder, ShippingPackageListDto } 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 { CreateOrEditClinicModalComponent } from './create-or-edit-clinic-modal.component'; import { ViewClinicModalComponent } from './view-clinic-modal.component'; 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-timezone'; import { Router } from '@angular/router'; import { HttpClient } from '@angular/common/http'; import { AppConsts } from '@shared/AppConsts'; import { ImportRouteScheduleTracking } from './route-schedule-import-tracking'; import * as signalR from '@aspnet/signalr'; import { AttachmentComponent } from './attachment.component'; import { Location } from '@angular/common'; import { finalize, catchError } from 'rxjs/operators'; import { throwError } from 'rxjs'; declare var KTWizard: any; declare var $: any; declare var KTApp: any; declare let swal: any; @Component({ templateUrl: './clinic-history.component.html', styleUrls: ['./clinic-history.component.less'], encapsulation: ViewEncapsulation.None, animations: [appModuleAnimation()], }) export class ClinicHistoryComponent extends AppComponentBase { @ViewChild('dataTable', { static: true }) dataTable: Table; @ViewChild('paginator', { static: true }) paginator: Paginator; @ViewChild('attachmentComponent', { static: true }) attachmentComponent: AttachmentComponent; id: any; clinicData: ClinicDto = new ClinicDto(); filterText: string; goBackHistory: number; user: string; status: number = null; datefrom = null; dateTo = null; orderStatusDefinitions: any; dateRange: any; orderType: any; orderT: number = null; packageListOption: any; totalp: Array = new Array(); advancedFiltersAreShown = false; orderId: number; driver: string; constructor( injector: Injector, private _clinicHistory: WillCallServiceServiceProxy, private route: ActivatedRoute, private router: Router, private _location: Location, private _orderPackageListAppService : ControllerOrderPackagesListServiceProxy, private _orderTypesServiceProxy: OrderTypesServiceProxy, private _fileDownloadService: FileDownloadService, private _willcallService: WillCallServiceServiceProxy, ) { super(injector); } ngOnInit() { this.goBackHistory = window.history.length; $('.kt-select2').select2(); this.route.paramMap.subscribe(params => { this.id = params.get("id") }) this._orderPackageListAppService.getOrderDescriptionList() .pipe().subscribe(result => { this.orderStatusDefinitions=result.items; }); this._willcallService.getPackageListOptions() .pipe().subscribe(result => { this.packageListOption = result; }); this._orderTypesServiceProxy.getAll( undefined, undefined, undefined, 1, undefined, undefined, undefined, 1000 ).subscribe(result => { this.orderType = result.items; }); } getHistory(event?: LazyLoadEvent) { if(this.advancedFiltersAreShown == true){ this.status = Number((document.getElementById('OrderStatusType')).value); this.orderT = Number((document.getElementById('OrderType')).value); if(this.dateRange != undefined){ this.datefrom = this.dateRange[0]; this.dateTo = this.dateRange[1]; } }else{ this.user = undefined; this.status = 0; this.datefrom = undefined; this.dateTo = undefined; this.orderT = 0; } if (this.primengTableHelper.shouldResetPaging(event)) { this.paginator.changePage(0); return; } this.spinnerService.show(); this._clinicHistory.getHistory( this.id, this.filterText, this.user, this.status, this.datefrom, this.dateTo, this.orderT, this.primengTableHelper.getSorting(this.dataTable), this.primengTableHelper.getSkipCount(this.paginator, event), this.primengTableHelper.getMaxResultCount(this.paginator, event) ).subscribe(result => { result.orders.items.forEach(item => { this.totalp[item.id] = 0; item.historyPackageList.forEach(d => { this.totalp[item.id] += d.quantity; }); }); this.primengTableHelper.totalRecordsCount = result.orders.totalCount; this.primengTableHelper.records = result.orders.items; this.clinicData = result.clinic; this.primengTableHelper.hideLoadingIndicator(); this.spinnerService.hide(); }); } orderAttachments(id:number){ this.attachmentComponent.show(id); } navOrder(id){ this.router.navigate(['/app/sprintship/controller-order-details/', id]); } goBack() { if(this.goBackHistory > 1){ this._location.back(); } } exportToExcel(): void { this._clinicHistory.getClinicHistoryToExcel( this.id, this.filterText, this.user, this.status, this.datefrom, this.dateTo, this.orderT, ) .subscribe(result => { if(result!=undefined){ if(result.fileUrl!=undefined){ this.router.navigate([]).then(result1 => { window.open(result.fileUrl, '_blank'); }); this.spinnerService.hide(); }else{ this.spinnerService.hide(); } }else{ this.message.warn('', "No data to export"); this.spinnerService.hide(); } }); } createIncidents(url: any, id?: number){ this._willcallService.getRouteCodeDriver( id ).pipe( catchError((err) => { return throwError(err); }) ).subscribe(result => { this.driver = result; if(this.driver != null){ if(id != null){ var myurl = `${url}/${id}`; }else{ var myurl = `${url}`; } //window.open(myurl, "_blank") this.router.navigateByUrl(myurl); } }); } viewIncident(url: any){ var myurl = `${url}`; this.router.navigateByUrl(myurl); } goBackOrder(clinicId: number, orderId: number): void { this.orderId = orderId; this.spinnerService.show(); this._willcallService.getGoBackDetails(clinicId, orderId) .pipe( catchError((err) => { this.spinnerService.hide(); return throwError(err); }) ) .subscribe( result=>{ let create = new CreateGoBackOrder({ orderId: this.orderId, eta: result.originalEta }) this.spinnerService.hide(); this.message.confirm( 'Call Back Schedule: ' + result.routeCode + ' - ' + result.eta, result.clinicName, (isConfirmed) => { if (isConfirmed) { this.spinnerService.show(); this._willcallService.createGoBackOrder(create) .subscribe(() => { this.spinnerService.hide(); this.notify.success(this.l('Successfully')); }); } } ); }) // this.message.confirm( // '', // '', // (isConfirmed) => { // if (isConfirmed) { // this._clinicsServiceProxy.delete(clinic.id) // .subscribe(() => { // this.reloadPage(); // this.notify.success(this.l('SuccessfullyDeleted')); // }); // } // } // ); } gotoIncidentReport(incidentNumber : number){ window.open('/app/sprintship/update-incidents/' + incidentNumber, '_blank'); } }