EchoTex_Payroll/HRM.UI/ClientApp/src/app/final-settlement/Employee-Asset-Assignment/employee-asset-assignment.component.ts

249 lines
8.7 KiB
TypeScript
Raw Normal View History

2024-10-14 10:01:49 +06:00
import { Component, OnInit } from '@angular/core';
import { FormGroup, FormControl, FormBuilder, Validators } from '@angular/forms';
import { HrEmployee } from '../../_models/HREmployee/hrEmployee';
import { SearchEmployee } from '../../_models/Employee/searchEmployee';
import { DynamicPicker, EnumDynamicpickerType } from '../../picker/dynamic-picker/Dynamic-Picker';
import { OrganogramBasic } from '../../_models/Payroll/organogramBasic';
import { EmployeeServices } from '../../_services/employee/employee.service';
import { DataTransferService } from '../../data.transfer.service';
import { UntilityHandlerService } from '../../utility.hanldler.service';
import { HRMNotificationService } from '../../app.notification.service';
import { BasicService } from '../../_services/Basic/basic.service';
import { Router } from '@angular/router';
import { OrganogramService } from '../../_services/payroll/organogram.service';
import { loadingPanelService } from '../../hrm-loding panel/loding.panel.service';
import { Observable } from 'rxjs';
import { TreeNode } from 'primeng/api';
import { UITreeNode } from 'primeng/tree';
import { ApiService } from '../../app.api.service';
import { Asset, AssetSerial, AssetSerialTran } from '../../_models/ExitClearance/existClearance';
import { ExitClearanceService } from '../../_services/payroll/exitClearance.service';
import { ReportServices } from 'src/app/_services/reports/report.service';
import { EnumExtension, EnumPURequestType, EnumReplacementDueTo, enumwfStatus, EnumAssetStatus, EnumAssetTranType, EnumAssetReceiverType } from '../../_models/enums';
@Component({
selector: 'app-employee-asset-assignment',
templateUrl: './employee-asset-assignment.component.html',
styleUrls: ['./employee-asset-assignment.component.css'],
styles: [`
.disableDiv{
pointer-events:none;
}
`]
})
export class EmployeeAssetAssignmentComponent implements OnInit {
public setStatus: EnumAssetStatus;
dropDownType: any;
dropDown: string;
showModal: boolean
IsNew: boolean;
title = '';
PDFTitle = '';
data: TreeNode[];
_fromValidator: FormGroup;
locationPicker: DynamicPicker;
assetSerialList: AssetSerial[] = [];
assignmentDate: Date;
employeeId: number = 0;
departmentId: number = 0;
locationId: number = 0;
assetSerialTranList: AssetSerialTran[] = [];
assetReceiverList: any = EnumExtension.getNamesAndValues(EnumAssetReceiverType);
assignType: EnumAssetReceiverType;
isEmployeeActive: boolean = true;
isDepartmentActive: boolean = true;
isLocationActive: boolean = true;
reportType: any;
showPopUp = false;
src: any;
constructor(public organogramService: OrganogramService,
public datatransferservice: DataTransferService,
public utilityHandlerService: UntilityHandlerService,
public notificationService: HRMNotificationService,
public loadingPanelService: loadingPanelService,
public reportService: ReportServices,
public exitClearanceService: ExitClearanceService,
public basicService: BasicService, public router: Router, public apiService: ApiService) {
this.loadingPanelService.ShowLoadingPanel = false;
this.apiService.selectedMenuName = "My Recived Asset";
this.getAssets();
}
_ogranograms: OrganogramBasic[];
selectedEmployee: SearchEmployee;
organogram: OrganogramBasic;
selectedNode: number[];
selectedorgNode: TreeNode;
orgViewNodes: OrganogramBasic[];
selectedOrgNode: OrganogramBasic;
departmentPicker: DynamicPicker;
expandedKeys: number[];
assetList: Asset[] = [];
ngOnInit() {
this.assignmentDate = new Date();
this.setStatus = EnumAssetStatus.Free;
this.departmentPicker = new DynamicPicker(EnumDynamicpickerType.Department, false);
this.locationPicker = new DynamicPicker(EnumDynamicpickerType.Location, true);
this.createAssetForm();
this.search();
}
public getAssets() {
this.loadingPanelService.ShowLoadingPanel = true;
this.exitClearanceService.getAllAssets().subscribe(
(x) => {
this.assetList = x;
},
(x) => {
this.loadingPanelService.ShowLoadingPanel = false;
this.notificationService.showError(x);
},
() => {
this.loadingPanelService.ShowLoadingPanel = false;
});
}
public GetSelectedSerial(event: any) {
this.assetSerialList = event;
this.assetSerialList.forEach(x => {
x.assetName = this.assetList.find(y => y.id == x.assetId).name;
})
//console.log(event);
}
public GetSelectedEmployee(childData) {
if (childData != undefined) {
var emp: SearchEmployee = childData;
//console.log(childData);
this.employeeId = emp.employeeID;
}
}
public createAssetForm() {
this._fromValidator = new FormBuilder().group({
//assignmentDate: ['', Validators.required],
//assignType: ['', Validators.required]
});
}
public valueChange(value: any): void {
//console.log("valueChange", value);
if (this.assignType == EnumAssetReceiverType.Employee) {
this.isDepartmentActive = true;
this.isEmployeeActive = false;
this.isLocationActive = true;
this.departmentPicker.selectedID = undefined;
this.locationPicker.selectedIDs = undefined;
}
if (this.assignType == EnumAssetReceiverType.Department) {
this.isDepartmentActive = false;
this.isEmployeeActive = true;
this.isLocationActive = true;
this.employeeId = 0;
this.locationPicker.selectedIDs = undefined;
}
if (this.assignType == EnumAssetReceiverType.Location) {
this.isDepartmentActive = true;
this.isEmployeeActive = true;
this.isLocationActive = false;
this.departmentPicker.selectedID = undefined;
this.employeeId = 0;
}
}
closeForm(): void {
this.showPopUp = false;
}
onPreview(item: AssetSerial) {
const data = {
itemid: item.id,
reportid: this.reportType,
employeeid: item.assetReceiverId
};
this.PDFTitle = 'Asset Acknowledgement';
this.title = 'Asset Acknowledgement';
this.loadingPanelService.ShowLoadingPanel = true;
this.reportService.getAssetAcknowledgementData(data).subscribe(
(resp: any) => {
// console.log(resp)
this.src = URL.createObjectURL(this.b64toBlob(resp, 'data:application/pdf;base64', 1024));
this.showPopUp = true;
},
(err) => {
//console.log(err);
this.notificationService.showError(err.error);
this.loadingPanelService.ShowLoadingPanel = false;
},
() => {
this.loadingPanelService.ShowLoadingPanel = false;
// this.loadGrid();
}
);
}
b64toBlob(b64Data, contentType, sliceSize) {
const byteCharacters = atob(b64Data);
const byteArrays = [];
for (let offset = 0; offset < byteCharacters.length; offset += sliceSize) {
const slice = byteCharacters.slice(offset, offset + sliceSize);
const byteNumbers = new Array(slice.length);
for (let i = 0; i < slice.length; i++) {
byteNumbers[i] = slice.charCodeAt(i);
}
const byteArray = new Uint8Array(byteNumbers);
byteArrays.push(byteArray);
}
const blob = new Blob(byteArrays, { type: contentType });
return blob;
}
search() {
debugger;
if (this._fromValidator.invalid) {
return;
}
let receiverid = 0;
this.assetSerialList = [];
this.loadingPanelService.ShowLoadingPanel = true;
this.exitClearanceService.getEmployeeReceivedAssetSerial()
.subscribe(
(x) => { this.assetSerialList = x; },
(err) => {
this.loadingPanelService.ShowLoadingPanel = false;
this.notificationService.showError(err.error);
},
() => {
this.loadingPanelService.ShowLoadingPanel = false;
//if (this.assetSerialList != null && this.assetSerialList.length > 0) {
// this.assetSerialList.forEach(x => {
// x.assetName = this.assetList.find(c => c.id == x.assetId).name;
// })
//}
});
}
}