import { Component, Injector, OnInit, ViewChild, ViewEncapsulation, EventEmitter, Output, Input } from '@angular/core'; import { ActivatedRoute, Router } from '@angular/router'; import { appModuleAnimation } from '@shared/animations/routerTransition'; import { AppComponentBase } from '@shared/common/app-component-base'; declare var $: any; declare var jquery: any; import * as moment from 'moment-timezone'; import { LocationServiceProxy, ReportPackageByZipCodeServiceProxy, MileageReimbursementServiceProxy } from '@shared/service-proxies/service-proxies'; import { FileDownloadService } from '@shared/utils/file-download.service'; import { LazyLoadEvent } from 'primeng/api'; import { Table } from 'primeng/table'; import { Paginator } from 'primeng/primeng'; @Component({ selector: 'mileage-reimbursement', templateUrl: 'mileage-reimbursement.component.html', encapsulation: ViewEncapsulation.None, animations: [appModuleAnimation()], providers: [MileageReimbursementServiceProxy] }) export class MileageReimbursementComponent extends AppComponentBase implements OnInit { locations: any; timeId = localStorage.getItem('timeZoneId'); // public dateRange: moment.Moment[] = [moment().startOf('day'), moment().endOf('day')]; packagesByPostalCode:any; dateRange: Date; listOfDates = []; startDate: Date; endDate: Date; sortingColumns:string = null; @ViewChild('dataTable', { static: true }) dataTable: Table; @ViewChild('paginator', { static: true }) paginator: Paginator; constructor( injector: Injector, private id: ActivatedRoute, private _locationServiceProxy: LocationServiceProxy, private _mileageReimbursementServiceProxy: MileageReimbursementServiceProxy, private _fileDownloadService: FileDownloadService, ) { super(injector); } ngOnInit() { $('.kt-select2').select2(); this.getLocation(); $('#kt_daterangepicker_2').daterangepicker({ buttonClasses: ' btn', applyClass: 'btn-primary', cancelClass: 'btn-secondary' }, function(start, end, label) { $('#kt_daterangepicker_2 .form-control').val( start.format('YYYY-MM-DD') + ' / ' + end.format('YYYY-MM-DD')); $('#hiddenStartDate').val(start.format('YYYY-MM-DD')); $('#hiddenEndDate').val(end.format('YYYY-MM-DD')); }); } ngAfterViewInit() { } getLocation() { this._locationServiceProxy.getLocationNames(undefined, undefined, undefined, undefined, undefined, undefined) .subscribe(result => { this.locations = result; console.log(this.locations); }); } getMileageReimbursement(event?: LazyLoadEvent) { if (this.primengTableHelper.shouldResetPaging(event)) { this.paginator.changePage(0); return; } this.spinnerService.show(); this.listOfDates = this.getDates($('#hiddenStartDate').val(), $('#hiddenEndDate').val()); var locationdId = parseInt($("#locationSelectInput").val()); if(this.listOfDates.length!=0){ this._mileageReimbursementServiceProxy.getMileageReimbursement(moment.tz($('#hiddenStartDate').val(), this.timeId), moment.tz($('#hiddenEndDate').val(), this.timeId),locationdId, this.primengTableHelper.getSorting(this.dataTable), this.primengTableHelper.getSkipCount(this.paginator, event), this.primengTableHelper.getMaxResultCount(this.paginator, event) ) .subscribe(result => { this.primengTableHelper.records = result; this.primengTableHelper.totalRecordsCount = result.length; this.sortingColumns = this.primengTableHelper.getSorting(this.dataTable), this.spinnerService.hide(); }) }else{ this.notify.error(this.l('Please Select Date')); this.spinnerService.hide(); } } getDates(startDate, stopDate) { var dateArray = []; var currentDate = moment.tz(startDate, this.timeId); var stopDates = moment.tz(stopDate, this.timeId); while (currentDate <= stopDates) { dateArray.push( moment.utc(currentDate).format('YYYY-MM-DD') ) currentDate = moment.utc(currentDate).add(1, 'days'); } return dateArray; } exportToExcel(event?: LazyLoadEvent): void { this.spinnerService.show(); this.listOfDates = this.getDates($('#hiddenStartDate').val(), $('#hiddenEndDate').val()); var locationdId = parseInt($("#locationSelectInput").val()); if(this.listOfDates.length!=0){ this._mileageReimbursementServiceProxy.getMileageReimbursementToExcel(moment.tz($('#hiddenStartDate').val(), this.timeId), moment.tz($('#hiddenEndDate').val(), this.timeId),locationdId, this.sortingColumns, undefined, undefined ) .subscribe(result => { this._fileDownloadService.downloadTempFile(result); this.spinnerService.hide(); }) }else{ this.notify.error(this.l('Please Select Date')); this.spinnerService.hide(); } } }