import { Component, OnInit, ViewChild, SimpleChanges } from '@angular/core'; import { PayslipService } from '../service/payslip.service' import { TranslatorService } from 'src/app/hmg-common/services/translator/translator.service'; import { CommonService } from 'src/app/hmg-common/services/common/common.service'; import { MenuResponse } from 'src/app/hmg-common/services/menu/models/menu-response'; import { SharedDataService } from 'src/app/hmg-common/services/shared-data-service/shared-data.service'; import { DeductionRequest } from '../model/deductionReq'; import { IonInfiniteScroll, IonSlides } from '@ionic/angular'; import { AuthenticationService } from "src/app/hmg-common/services/authentication/authentication.service"; import { AuthenticatedUser } from "src/app/hmg-common/services/authentication/models/authenticated-user"; import { UIChart } from 'primeng/components/chart/chart'; @Component({ selector: 'app-home', templateUrl: './home.component.html', styleUrls: ['./home.component.scss'], }) export class HomeComponent implements OnInit { selEmp: string; respID: number; selMenu: MenuResponse; GetPayslipList: any = ''; GetSummaryOfPaymentList: any = ''; GetPaymentInformationList: any = ''; showPaySlip: any = []; ActionContextID: any; public static ACTION_CONTEXT_ID = "passActionContectID"; GetEarningsList: any = ''; GetDeductionsList: any = ''; earingTotal: any; deductionTotal: any; firstPayslip: any; defultSelected: any; IsReachEnd: any; private deductionReq: DeductionRequest; doinfiniteDedReq: any; doinfinitEarReq: any; personalInfo: any; setImage: any; imageSrc: any = "../assets/imgs/profile.png"; slideView: any; sliderOne: any; payslipIndex: any; data: any; public direction: string; @ViewChild('slides') slides: IonSlides; @ViewChild('slideWithNav') slideWithNav: IonSlides; @ViewChild('chart') chart: UIChart; slideOptsOne = { initialSlide: 0, slidesPerView: 1, autoplay: true }; @ViewChild(IonInfiniteScroll) infiniteScroll: IonInfiniteScroll; public options = { cutoutPercentage: 85, tooltips: { enabled: false }, legend: { display: false } }; gaugeType = "full"; // gaugeValue = 11.200; // gaugeLabel = ""; constructor( public payslipService: PayslipService, public ts: TranslatorService, public common: CommonService, public sharedData: SharedDataService, public authService: AuthenticationService, public cs: CommonService, ) { this.direction = TranslatorService.getCurrentDirection(); } ngOnInit() { this.direction = TranslatorService.getCurrentLanguageName() // this.selEmp = this.common.sharedService.getSharedData( // MenuResponse.SHARED_SEL_EMP, // false // ); // if(this.selEmp){}else{ // this.authService.loadAuthenticatedUser().subscribe((user: AuthenticatedUser) => { // if (user) { // this.selEmp = user.ASSIGNMENT_NUMBER; // } // }); // } // console.log(" this.selEmp" + this.selEmp); // this.respID = this.common.sharedService.getSharedData( // MenuResponse.SHARED_SEL_RESP_ID, // false // ); // if(this.respID){}else{ // this.respID=-999; // } // console.log(" this.respID" + this.respID); // this.selMenu = new MenuResponse(); // this.selMenu = this.common.sharedService.getSharedData( // MenuResponse.SHARED_DATA, // false // ); // console.log(" this.selMenu" + this.selMenu); this.getPayslip(); // this.getProfile(); } ngOnChanges(changes: SimpleChanges): void { if (changes.inputData.currentValue) { // update this.data here // then chart is getting updated setTimeout(() => { this.chart.reinit(); }, 100); } } slideNext(object, slideView) { if (this.payslipIndex != 0) { this.payslipIndex = this.payslipIndex - 1; this.showInfo(); } } slidePrev(object, slideView) { if (this.payslipIndex < this.GetPayslipList.length - 1) { // console.log(this.payslipIndex); this.payslipIndex = this.payslipIndex + 1; this.showInfo(); } } // getProfile() { // this.authService // .loadAuthenticatedUser() // .subscribe((user: AuthenticatedUser) => { // if (user) { // this.personalInfo = user; // if(this.cs.getUpdateImage().status){ // // this.imageSrc = this.sanitizer.bypassSecurityTrustUrl("data:Image/*;base64,"+this.cs.getUpdateImage().img); // this.imageSrc = "data:image/png;base64,"+this.cs.getUpdateImage().img; // // alert("this.imageSrc"+ this.imageSrc); // }else{ // this.imageSrc = user.EMPLOYEE_IMAGE // ? "data:image/png;base64," + user.EMPLOYEE_IMAGE // : this.imageSrc; // console.log("2-"+user); // } // } // else { // console.log("3-"+user); // } // }); // } getPayslip() { // this.selEmp ="13777"; console.log("this.selEmp????????" + this.selEmp) this.respID = -999; const request = { P_SELECTED_EMPLOYEE_NUMBER: this.selEmp,//'125346',//this.selEmp, P_MENU_TYPE: "E",// 'E',//this.selMenu.List_Menu.MENU_TYPE, P_SELECTED_RESP_ID: this.respID//"-999" //this.respID, // P_PAGE_NUM: this.P_PAGE_NUM, // P_PAGE_LIMIT: this.P_PAGE_LIMIT }; this.payslipService.getPayslip(request, () => { }, this.ts.trPK('general', 'retry')).subscribe((result) => { this.handleRespondGetPayslipResult(result); } ); } handleRespondGetPayslipResult(result) { if (result.GetPayslipList != null) { this.GetPayslipList = result.GetPayslipList; this.firstPayslip = this.GetPayslipList[0] this.defultSelected = this.firstPayslip.PAYSLIP_CHOICE } this.showPaySlip = this.GetPayslipList[0]; this.payslipIndex = 0; this.getAllPayslipData(this.GetPayslipList[0].ACTION_CONTEXT_ID); } showInfo() { //console.log(event.detail.value); //const index = parseInt(event.detail.value); this.showPaySlip = this.GetPayslipList[this.payslipIndex]; this.ActionContextID = this.GetPayslipList[this.payslipIndex].ACTION_CONTEXT_ID; this.getAllPayslipData(this.ActionContextID); } getAllPayslipData(ActionContextID) { this.common.sharedService.setSharedData(ActionContextID, HomeComponent.ACTION_CONTEXT_ID); this.getSummeryOfPayment(ActionContextID); this.getPaymentInfo(ActionContextID); this.getDeduction(ActionContextID); this.getEarings(ActionContextID); } getSummeryOfPayment(ActionContextID) { const request = { P_ACTION_CONTEXT_ID: ActionContextID, }; this.payslipService.getSummeryOFPayment(request, () => { }, this.ts.trPK('general', 'retry')).subscribe((result) => { this.handleSummeryOfPaymentResult(result); } ); } handleSummeryOfPaymentResult(result) { if (result.GetSummaryOfPaymentList != null) { this.GetSummaryOfPaymentList = result.GetSummaryOfPaymentList[0]; this.earingTotal = this.GetSummaryOfPaymentList.TOTAL_EARNINGS_AMOUNT; this.deductionTotal = this.GetSummaryOfPaymentList.TOTAL_DEDUCTIONS_AMOUNT; this.data = { labels: ['earingTotal', 'deductionTotal'], datasets: [ { data: [this.earingTotal, this.deductionTotal], backgroundColor: [ '#BE332F', '#BE332F',], borderWidth: 2 } ] }; } } getPaymentInfo(ActionContextID) { const request = { P_ACTION_CONTEXT_ID: ActionContextID, }; this.payslipService.getPaymentInfo(request, () => { }, this.ts.trPK('general', 'retry')).subscribe((result) => { this.handleGetPaymentInfoResult(result); } ); } handleGetPaymentInfoResult(result) { if (result.GetPaymentInformationList != null) { this.GetPaymentInformationList = result.GetPaymentInformationList; } } openEarings() { this.common.openEarningsPage(); } openDeductions() { this.common.openDeductionsPage(); } getEarings(ActionContextID) { console.log("getEarings"); // this.deductionReq.P_ACTION_CONTEXT_ID=ActionContextID; // this.deductionReq.P_PAGE_NUM=1; // this.deductionReq.P_PAGE_LIMIT=100; const request = { P_ACTION_CONTEXT_ID: ActionContextID, P_PAGE_NUM: 1, P_PAGE_LIMIT: 100 } this.doinfinitEarReq = request; this.payslipService.getEarings(request, () => { }, this.ts.trPK('general', 'retry')).subscribe((result) => { this.handleGetEaringsResult(result); } ); } handleGetEaringsResult(result) { if (result.GetEarningsList != null) { this.GetEarningsList = result.GetEarningsList; } } getDeduction(ActionContextID) { console.log("getDeduction"); const request = { P_ACTION_CONTEXT_ID: ActionContextID, P_PAGE_NUM: 1, P_PAGE_LIMIT: 100 } // this.deductionReq.P_ACTION_CONTEXT_ID=ActionContextID; // this.deductionReq.P_PAGE_NUM=1; // this.deductionReq.P_PAGE_LIMIT=100; this.doinfiniteDedReq = request; this.payslipService.getDeduction(request, () => { }, this.ts.trPK('general', 'retry')).subscribe((result) => { this.handleGetDeductionResult(result); } ); } handleGetDeductionResult(result) { if (result.GetDeductionsList != null) { this.GetDeductionsList = result.GetDeductionsList; } } doInfiniteDeduction(infiniteScroll) { //this.pageNum= this.pageNum + 1; if (!this.IsReachEnd) { this.payslipService.getDeduction(this.doinfiniteDedReq).subscribe( (result: any) => { if (this.common.validResponse(result)) { this.doinfiniteDedReq.P_PAGE_NUM++; if (this.common.hasData(result.GetDeductionsList)) { result.GetDeductionsList.forEach(element => { if (element.ROW_NUM == element.NO_OF_ROWS) { this.IsReachEnd = true; } else { this.IsReachEnd = false; } this.GetDeductionsList.push(element); }); } // if list length >0 else { this.IsReachEnd = true; } } // if response == 1 //this.pageNum++; this.infiniteScroll.complete(); } ); } else { if (this.infiniteScroll) this.infiniteScroll.complete(); } } //end infiniteScroll doInfiniteEarning(infiniteScroll) { //this.pageNum= this.pageNum + 1; if (!this.IsReachEnd) { this.payslipService.getEarings(this.doinfinitEarReq).subscribe( (result: any) => { if (this.common.validResponse(result)) { this.doinfinitEarReq.P_PAGE_NUM++; if (this.common.hasData(result.GetEarningsList)) { result.GetEarningsList.forEach(element => { if (element.ROW_NUM == element.NO_OF_ROWS) { this.IsReachEnd = true; } else { this.IsReachEnd = false; } this.GetEarningsList.push(element); }); } // if list length >0 else { this.IsReachEnd = true; } } // if response == 1 //this.pageNum++; this.infiniteScroll.complete(); } ); } else { if (this.infiniteScroll) this.infiniteScroll.complete(); } } }