import { Component, OnInit } from '@angular/core'; import { RootService } from '../../../_services/root.service'; import { StockReportingService } from '../stock-reporting.service'; import { AuthenticationService } from '../../../_services/authentication.service'; import { debugOutputAstAsTypeScript } from '@angular/compiler'; import { LocalService } from '../../../_services/local.service'; @Component({ selector: 'app-report-manager', templateUrl: './report-manager.component.html', styles: [` `] }) export class ReportManagerComponent implements OnInit { public currentUser: any; public DDTH: any[] = []; public DColumns: any[] = []; public data: any[] = []; public Division: any[] = []; public SelectedDivision: any[] = []; public District: any[] = []; public SelectedDistrict: any[] = []; public Tehsil: any[] = []; public SelectedTehsil: any[] = []; public HF: any[] = []; public SelectedHF: any[] = []; public HFType: any[] = []; public SelectedHFType: any[] = []; public ShowFiltrer: boolean = true; public isLoading: boolean = false; public isDownloading: boolean = false; public isDownloadingPDF: boolean = false; public Group = [ { label: 'Division', value: { Display: 'Division', value: 'DivisionName' } }, { label: 'District', value: { Display: 'District', value: 'DistrictName' } }, { label: 'Tehsil', value: { Display: 'Tehsil', value: 'TehsilName' } }, { label: 'Health Facility Type', value: { Display: 'Health Facility Type', value: 'HFTypeName' } }, { label: 'Health Facility', value: { Display: 'Health Facility', value: 'FullName' } }, { label: 'Medicine', value: { Display: 'Medicine', value: 'bm.Name' } }, ]; constructor(private _rootService: RootService, private _vpService: StockReportingService, private _authenticationService: AuthenticationService, private _localService: LocalService) { } ngOnInit() { this.currentUser = this._authenticationService.getUser(); debugger; this.loadDivision(); this.loadDistrict(); this.loadTehsil(); this.loadHFType(); this.checkRole(); } public isNumber(val) { debugger; return typeof val === 'number'; } public checkRole() { debugger; if(this.currentUser.RoleName == 'HF') { this.Group.forEach(element => { this.DDTH.push(element.value); }); } if(this.currentUser.RoleName == 'CEO') { } } public loadDivision() { this.Division = []; this._rootService.getDivisions(this._authenticationService.getUserHfmisCode()) .subscribe((x: any[]) => { if (x) { if (x.length == 1) { this.SelectedDivision.push(x[0].Name); } console.log(this.Group); x.forEach(element => { this.Division.push({ label: element.Name, value: element.Name }); }); } }); } public loadDistrict() { this.District = []; this._rootService.getDistricts(this._authenticationService.getUserHfmisCode()) .subscribe((x: any[]) => { if (x) { if (x.length == 1) { this.SelectedDistrict.push(x[0].Name); } x.forEach(element => { this.District.push({ label: element.Name, value: element.Name }); }); } }); } public loadTehsil() { this.Tehsil = []; this._rootService.getTehsils(this._authenticationService.getUserHfmisCode()) .subscribe((x: any[]) => { if (x) { if (x.length == 1) { this.SelectedTehsil.push(x[0].Name); } x.forEach(element => { this.Tehsil.push({ label: element.Name, value: element.Name }); }); } }); } public loadHFType() { this.HFType = []; this._rootService.getHFTypes() .subscribe((x: any) => { if (x) { if (x.length == 1) { /* if(this.currentUser.HfmisCode.length == 19){ console.log('hi'); } */ this.SelectedHFType.push(x[0].Name); } x.forEach(element => { this.HFType.push({ label: element.Name, value: element.Name }); }); } }); } GetFilterdHF(){ this.HF= []; console.log(this.SelectedTehsil); this._rootService.getMultipelHF(this.SelectedTehsil).subscribe( (x : any[])=>{ if (x) { if (x.length == 1) { this.SelectedHF.push(x[0].Name); } x.forEach(element => { this.HF.push({ label: element.Name, value: element.Name }); }); } },err=>{ }) } public clear() { this.DDTH = []; this.DColumns = []; this.SelectedDistrict = []; this.SelectedDivision = []; this.SelectedTehsil = []; this.SelectedHFType = []; this.resetData(); } public resetData() { this.data = []; } public getData() { this.isLoading = true; let filters = { Divisions: this.SelectedDivision, Districts: this.SelectedDistrict, Tehsils: this.SelectedTehsil, HFTypes: this.SelectedHFType , HFs:this.SelectedHF }; this._vpService.getStockPosition_HfWiseData(this.DDTH, filters) .subscribe((x: any) => { debugger; this.isLoading = false; this.data = x.res; this.DColumns = x.dim; this.ShowFiltrer = false; }); } public download() { this.isDownloading = true; let filters = { Divisions: this.SelectedDivision, Districts: this.SelectedDistrict, Tehsils: this.SelectedTehsil, HFTypes: this.SelectedHFType }; this._vpService.downloadStockPosition_HfWiseData(this.DDTH, filters) .subscribe((x: any) => { debugger; this.isDownloading = false; var blob = new Blob([x.body], { type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" }); this.saveAs(blob, "VacancyData.xls"); }); } saveAs(blob, fileName) { if (window.navigator.msSaveOrOpenBlob) { // For IE: navigator.msSaveBlob(blob, fileName); } else { // For other browsers: var link = document.createElement('a'); link.href = window.URL.createObjectURL(blob); link.download = fileName; link.click(); window.URL.revokeObjectURL(link.href); } } public switchStatus() { this.ShowFiltrer = !this.ShowFiltrer; } print() { let html = document.getElementById('printOld').innerHTML; var mywindow = window.open('', 'PRINT', 'height=600,width=900'); if (mywindow) { mywindow.document.write(` Application`); mywindow.document.write(''); mywindow.document.write(html); mywindow.document.write(''); mywindow.document.close(); // necessary for IE >= 10 mywindow.focus(); // necessary for IE >= 10 mywindow.print(); mywindow.close(); } } }