HRM-10/HRM.UI/ClientApp/src/app/adhoc-feature/claim-preview-by-admin-list/claim-preview-by-admin-list.component.ts
2026-11-23 11:49:34 +06:00

454 lines
17 KiB
TypeScript

import { ClaimItemApproveByLineManagerComponent } from './../claim-item-approve-by-line-manager/claim-item-approve-by-line-manager.component';
import { Component, OnInit, ChangeDetectionStrategy } from '@angular/core';
import { FormControl, FormGroup } from '@angular/forms';
import { DataTransferService, PickerDataTransferService } from '../../data.transfer.service';
import { WFMovementTran } from '../../_models/Work-Flow/wFMovementTran';
import { WorkflowService } from '../../_services/workflow/workflow.service';
import { WFFlowHistory } from '../../_models/Work-Flow/wFMovementNext';
import { ClaimService } from '../../_services/claim/claim.service';
import { ClaimRequisition, ClaimRequisitionAttachment, ClaimRequisitionItem, ClaimDisbursementReport } from '../../claim/claimRequisistion';
import { HRMNotificationService } from '../../app.notification.service';
import { ApiService } from '../../app.api.service';
import { EnumClaimRequsitionStatus, enumwfStatus, EnumClaimPaymentType, EnumExtension, EnumClaimWFStatus } from '../../_models/enums';
import { Router } from '@angular/router';
import { loadingPanelService } from '../../hrm-loding panel/loding.panel.service';
import { SearchEmployee } from '../../_models/Employee/searchEmployee';
import { ExcelExportComponent, ExcelExportData } from '@progress/kendo-angular-excel-export';
import { DataResult, GroupDescriptor, process, State } from '@progress/kendo-data-query';
import { DataStateChangeEvent, GridDataResult, SelectableSettings } from '@progress/kendo-angular-grid';
import { CommonModule } from '@angular/common';
import { LoadingPanelComponent } from 'src/app/hrm-loding panel/loading-panel.component';
import { ButtonModule } from '@progress/kendo-angular-buttons';
import { DropDownListModule } from '@progress/kendo-angular-dropdowns';
import { ReactiveFormsModule } from '@angular/forms';
import { FormsModule } from '@angular/forms';
import { ExcelExportModule } from '@progress/kendo-angular-excel-export';
import { KENDO_GRID } from '@progress/kendo-angular-grid';
import { DatePickerModule } from '@progress/kendo-angular-dateinputs';
import { EmployeePickerComponent } from 'src/app/picker/employee-picker.component';
import { ClaimPaymentAllComponent } from './claim-payment/claim-payment-all.component';
@Component({
selector: 'app-claim-preview-by-admin-list',
templateUrl: './claim-preview-by-admin-list.component.html',
styleUrls: ['./claim-preview-by-admin-list.component.css']
,changeDetection: ChangeDetectionStrategy.Eager,
standalone: false,
})
export class ClaimPreviewByAdminListComponent implements OnInit {
_fromValidator: FormGroup;
selectedEmployee: SearchEmployee;
paymentForm: FormGroup;
fromDate: Date;
toDate: Date;
employeeNo: string;
selectedEmployees: SearchEmployee[] = [];
taggedSelection: number[] = [];
employeeName: string;
_wfTran: WFMovementTran;
_wfTrans: WFMovementTran[] = [];
claimRequisitionId: number;
tranid: number;
claimRequisitionList: ClaimRequisition[] = [];
claimRequisition: ClaimRequisition;
claimAproveForm: FormGroup;
claimRembursementForm: FormGroup;
showNew: boolean = false;
// The Claim All Payment dialog ran cancelAllPayment() on every close (p-dialog's onHide), also
// when the screen closes it from code; kept as it was.
private _showNewAllPayment = false;
get showNewAllPayment(): boolean { return this._showNewAllPayment; }
set showNewAllPayment(value: boolean) {
const wasOpen = this._showNewAllPayment;
this._showNewAllPayment = value;
if (wasOpen && !value) {
this.cancelAllPayment();
}
}
showNewPayment: boolean = false;
userType: string = "admin";
claimRequisitionIds: number[] = [];
empIdList: number[] = [];
empIds = '';
claimTypeDropDown: any = EnumExtension.getNamesAndValues(EnumClaimPaymentType);
paymentStatusList: any = EnumExtension.getNamesAndValues(EnumClaimPaymentType);
claimTypeDropDownGrid: any;
approveStatusList: any = EnumExtension.getNamesAndValues(EnumClaimWFStatus);
approveStatusListNew: ApproveStatusList[] = [];
paymentStatus:any;
approveStatus:any
claimDisbursementReportList: ClaimDisbursementReport[] = [];
gridView: GridDataResult;
public selectableSettings: SelectableSettings;
selectedAmount: number = 0;
public gridState: State = {
skip: 0,
take: 10
};
constructor(
public dataTransferService: DataTransferService,
public workflowService: WorkflowService,
public claimService: ClaimService,
public notification: HRMNotificationService,
public apiService: ApiService,
public loadingService: loadingPanelService,
public router: Router) {
this.paymentForm = new FormGroup({});
this.allData = this.allData.bind(this);
this.setSelectableSettings();
}
setSelectableSettings(): void {
this.selectableSettings = {
checkboxOnly: true,
mode: 'multiple', // this.mode
};
}
ngOnInit() {
this.apiService.selectedMenuName = 'Admin Claim Status';
this.loadApprovedNewList();
this.claimTypeDropDownGrid = this.claimTypeDropDownGrid = this.claimTypeDropDown.filter(x => x.value !== 0 || x.value !== 3);;
this.fromDate = new Date();
this.toDate = new Date();
this.claimAproveForm = new FormGroup({});
this.claimRembursementForm = new FormGroup({});
this._fromValidator = new FormGroup({
remarks: new FormControl(),
txtFromDate: new FormControl(),
txtToDate: new FormControl(),
employeeNo: new FormControl(),
employeeName: new FormControl(),
approveType: new FormControl(),
paymentStatus: new FormControl(),
paymentType: new FormControl()
});
this.claimRequisition = new ClaimRequisition();
this._wfTran = new WFMovementTran();
}
public loadApprovedNewList() {
this.approveStatusList.forEach(x => {
let appvelist = new ApproveStatusList();
if (x.value === 1) {
appvelist.name = 'Submitted';
appvelist.value = x.value;
this.approveStatusListNew.push(appvelist);
}
if (x.value === 2) {
appvelist.name = 'Approved';
appvelist.value = x.value;
this.approveStatusListNew.push(appvelist);
}
if (x.value === 3) {
appvelist.name = 'Rejected';
appvelist.value = x.value;
this.approveStatusListNew.push(appvelist);
}
if (x.value === 4) {
appvelist.name = 'Approved with Paid';
appvelist.value = x.value;
this.approveStatusListNew.push(appvelist);
}
//appvelist.name = 'Submitted';
//appvelist.value = 1;
//this.approveStatusListNew.push(appvelist);
//appvelist.name = 'Approved';
//appvelist.value = 2;
//this.approveStatusListNew.push(appvelist);
//appvelist.name = 'Rejected';
//appvelist.value = 3;
//this.approveStatusListNew.push(appvelist);
//appvelist.name = 'Approved with Paid';
//appvelist.value = 4;
//this.approveStatusListNew.push(appvelist);
})
}
public getTran(objectId: number){
let wfTypeID = 4; //claim module
let wfruleID = 0; //claim module
this.loadingService.ShowLoadingPanel = true;
this.workflowService.getWfTranByObjectId(objectId, wfTypeID, wfruleID).subscribe(
(resp: any) => {
this._wfTran = resp;
},
(err: any) => {
this.loadingService.ShowLoadingPanel = false;
this.notification.showError(err);
},
() => {
this.loadingService.ShowLoadingPanel = false;
this.showNew = true;
}
);
}
new(dataItem: ClaimRequisition) {
this.getTran(dataItem.id);
}
search() {
this.loadData();
}
rembursementPayment(dataItem: ClaimRequisition) {
this.showNewPayment=true
}
addNew() {
this.router.navigate(['/ess/claim/claim-apply-by-employee']);
this.dataTransferService.setData(undefined);
}
onSubmitAllPaymnent() {
this.showNewAllPayment = false;
}
public allData(): ExcelExportData {
let result: ExcelExportData = {
data: process(this.claimDisbursementReportList, {
group: [],
sort: []
}).data,
group: [],
};
//let employeeIds = (this.selectedEmployee != undefined || this.selectedEmployee != null) ? this.selectedEmployee.employeeID.toString() : null;
//let fromDate = (this.fromDate == undefined || this.fromDate == null) ? null : this.fromDate;
//let toDate = (this.toDate == undefined || this.toDate == null) ? null : this.toDate;
//this.loadingService.ShowLoadingPanel = true;
//this.claimService.getClaimDisbursementByReport(fromDate, toDate, employeeIds).subscribe(
// (resp) => {
// this.claimDisbursementReportList = resp;
// },
// (x) => {
// console.log(x);
// this.loadingService.ShowLoadingPanel = false;
// },
// () => {
// this.loadingService.ShowLoadingPanel = false;
// result.data = this.claimDisbursementReportList;
// },
//);
return result;
}
public dataStateChange(state: DataStateChangeEvent): void {
this.gridState = state;
this.gridView = process(this.claimRequisitionList, this.gridState);
}
totalSelectedAmount() {
this.selectedAmount = 0;
if (this.taggedSelection != undefined) {
this.taggedSelection.forEach(x => {
console.log(x);
var item = this.claimRequisitionList.find(y => y.id == x);
this.selectedAmount = this.selectedAmount + item.claimAmount;
})
}
}
public exportAsExcelFile(json: any[], excelFileName: string): void {
}
private saveAsExcelFile(buffer: any, fileName: string): void {
//const data: Blob = new Blob([buffer], {
// type: EXCEL_TYPE
//});
//FileSaver.saveAs(data, fileName + '_export_' + new Date().getHours() + ':' + new Date().getMinutes() + ':' + new Date().getSeconds() + EXCEL_EXTENSION);
}
loadData() {
this.claimRequisitionList = [];
this.gridState.skip = 0;
this.gridState.take = 10;
this.taggedSelection = [];
;
let employeeIds = (this.empIds == undefined || this.empIds == null || this.empIds.length == 0) ? null : this.empIds;
let fromDate = (this.fromDate == undefined || this.fromDate == null) ? null : this.fromDate;
let toDate = (this.toDate == undefined || this.toDate == null) ? null : this.toDate;
let data = {
empIds: employeeIds,
fromDate: fromDate,
toDate: toDate,
paymentStatus: this.paymentStatus,
approveStatus: this.approveStatus
}
console.log(data);
this.loadingService.ShowLoadingPanel = true;
//this.claimService.getClaimReqsByEmployeeIds(fromDate, toDate, employeeIds).subscribe(
// (resp) => {
// this.claimRequisitionList = resp;
// },
// (x) => {
// console.log(x);
// this.loadingService.ShowLoadingPanel = false;
// },
// () => {
// this.loadingService.ShowLoadingPanel = false;
// },
//);
this.claimService.getClaimReqsByEmployeeIds1(data).subscribe(
(resp) => {
this.claimRequisitionList = resp;
},
(x) => {
console.log(x);
this.loadingService.ShowLoadingPanel = false;
},
() => {
//console.log(this.claimRequisitionList);
if (this.claimRequisitionList !== null && this.claimRequisitionList.length > 0) {
this.claimRequisitionList.forEach(x => {
if (x.paymentType === EnumClaimPaymentType.None || x.paymentType === EnumClaimPaymentType.Unpaid)
x.paymentType = null;
})
}
this.loadingService.ShowLoadingPanel = false;
this.loadGrid();
},
);
}
allPayment() {
//console.log(this.taggedSelection);
this.showNewAllPayment = true;
this.dataTransferService.setData(this.taggedSelection);
}
public loadGrid(): void {
this.gridView = {
data: this.claimRequisitionList.slice(this.gridState.skip, this.gridState.skip + this.gridState.take),
total: this.claimRequisitionList.length
};
}
public doExcelExport(components: ExcelExportComponent[]): void {
//let employeeIds = (this.selectedEmployee != undefined || this.selectedEmployee != null) ? this.selectedEmployee.employeeID.toString() : null;
let employeeIds = (this.empIds == undefined || this.empIds == null || this.empIds.length == 0) ? null : this.empIds;
let fromDate = (this.fromDate == undefined || this.fromDate == null) ? null : this.fromDate;
let toDate = (this.toDate == undefined || this.toDate == null) ? null : this.toDate;
let data = {
empIds: employeeIds,
fromDate: fromDate,
toDate: toDate,
wfstatus: this.approveStatus,
paymentstatus: this.paymentStatus,
approveStatus: this.approveStatus
}
this.loadingService.ShowLoadingPanel = true;
this.claimService.getClaimDisbursementByReport1(data).subscribe(
(resp) => {
this.claimDisbursementReportList = resp;
//console.log(this.claimDisbursementReportList);
},
(x) => {
console.log(x);
this.loadingService.ShowLoadingPanel = false;
},
() => {
this.loadingService.ShowLoadingPanel = false;
//console.log(components[0]);
components[0].data = this.claimDisbursementReportList;
//console.log(components[0])
var options = components[0].workbookOptions();
if (components.length > 1) {
for (var x = 1; x < components.length; x++) {
options.sheets[x] = components[x].workbookOptions().sheets[0];
}
}
components[0].save(options);
},
);
}
public GetSelectedEmployee(childData) {
;
this.selectedEmployees = childData;
this.empIds = undefined;
this.empIdList = [];
this.selectedEmployees.forEach(x => {
if (x !== undefined) {
let y = this.empIdList.find(c => c === x.employeeID);
if (y === undefined) {
this.empIdList.push(x.employeeID);
}
}
});
if (this.empIdList !== undefined )
this.empIds = this.empIdList.join(",");
}
saveHandler(dataItem: any) {
if (dataItem === true) {
this.showNew = false;
//console.log(dataItem);
//var idex = this.claimRequisitionList.find(x => x.claimRequisitionId == dataItem.tranID
// && x.wfMovementTranID == dataItem.objectID)
//this.claimRequisitionList.splice(idex, 1);
this._wfTran = new WFMovementTran();
}
if (dataItem === false) {
this.showNew = false;
}
}
savePayment(dataItem: ClaimRequisition) {
//console.log(dataItem);
this.loadingService.ShowLoadingPanel = true;
this.claimService.updateclaimrequisition(dataItem).subscribe(
(resp: any) => {
},
(x: any) => {
console.log(x);
this.notification.showError(x.error);
this.loadingService.ShowLoadingPanel = false;
},
() => {
this.notification.showSuccess('Claim payment saved succesfully!');
this.loadingService.ShowLoadingPanel = false;
this.loadData();
}
);
}
saveHandlerAllPayment(dataItem: any) {
if (dataItem === true) {
this.showNewAllPayment = false;
}
if (dataItem === false) {
this.showNewAllPayment = false;
}
this.dataTransferService.setData(undefined);
this.loadData();
}
cancelAllPayment() {
this.showNewAllPayment = false;
this.loadData();
}
}
export class ApproveStatusList{
name: string;
value: number;
}