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 } from '@shared/service-proxies/service-proxies'; import { FileDownloadService } from '@shared/utils/file-download.service'; @Component({ selector: 'report-package-per-postal-code', templateUrl: 'report-package-per-postal-code.component.html', // styleUrls: ['./route-sheet-laboratory.css'], encapsulation: ViewEncapsulation.None, animations: [appModuleAnimation()], providers: [ReportPackageByZipCodeServiceProxy] }) export class ReportPackagePerPostalCodeComponent 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; constructor( injector: Injector, private id: ActivatedRoute, private _locationServiceProxy: LocationServiceProxy, private _reportPackagePerPostal: ReportPackageByZipCodeServiceProxy, 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.getLocationTableOnly(undefined, undefined, undefined, undefined, undefined, undefined) .subscribe(result => { this.locations = result; }); } filter(){ this.spinnerService.show(); console.log($('#hiddenStartDate').val()); this.listOfDates = this.getDates($('#hiddenStartDate').val(), $('#hiddenEndDate').val()); // var locationdId = parseInt(localStorage.getItem('operatingLocationId')); var locationdId = parseInt($("#locationSelectInput").val()); this._reportPackagePerPostal.getReportPackageWithZipCode(moment.tz($('#hiddenStartDate').val(), this.timeId), moment.tz($('#hiddenEndDate').val(), this.timeId),locationdId) .subscribe(result => { this.primengTableHelper.records = result; this.primengTableHelper.totalRecordsCount = result.length; this.spinnerService.hide(); }) } getDates(startDate, stopDate) { var dateArray = []; var currentDate = moment.tz(startDate, this.timeId); var stopDates = moment.tz(stopDate, this.timeId); console.log(currentDate.format("YYYY-MM-DD") +" " +stopDates.format("YYYY-MM-DD")); while (currentDate <= stopDates) { dateArray.push( moment.utc(currentDate).format('YYYY-MM-DD') ) currentDate = moment.utc(currentDate).add(1, 'days'); } return dateArray; } // getDates(startDate, stopDate) { // var dateArray = []; // var currentDate = moment.utc(startDate); // var stopDates = moment.utc(stopDate); // while (currentDate <= stopDates) { // dateArray.push( moment.utc(currentDate).format('YYYY-MM-DD') ) // currentDate = moment.utc(currentDate).add(1, 'days'); // } // return dateArray; // } exportToExcel(): void { this.spinnerService.show(); // var locationdId = parseInt(localStorage.getItem('operatingLocationId')); var locationdId = parseInt($("#locationSelectInput").val()); this._reportPackagePerPostal.getReportPackagePerZipCodeToExcel(moment.tz($('#hiddenStartDate').val(), this.timeId), moment.tz($('#hiddenEndDate').val(), this.timeId),locationdId) .subscribe(result => { this._fileDownloadService.downloadTempFile(result); this.spinnerService.hide(); }); } }