From 558c53d4d328311047722624ad98c409934b63d6 Mon Sep 17 00:00:00 2001 From: mashfiq Date: Thu, 16 Jan 2025 18:23:03 +0600 Subject: [PATCH] Profile generated letter --- HRM.UI/ClientApp/src/app/app.api.service.ts | 2 +- .../employee-profile-reports.component.ts | 53 +++++++++---- HRM.UI/Controllers/Report/ReportController.cs | 77 ++++++------------- 3 files changed, 63 insertions(+), 69 deletions(-) diff --git a/HRM.UI/ClientApp/src/app/app.api.service.ts b/HRM.UI/ClientApp/src/app/app.api.service.ts index fd4f140..34679f7 100644 --- a/HRM.UI/ClientApp/src/app/app.api.service.ts +++ b/HRM.UI/ClientApp/src/app/app.api.service.ts @@ -13,7 +13,7 @@ export class ApiService { public isSSO = false; public versionDeployement = false; - public versionNumber = `V-${GlobalfunctionExtension.generateVersionNumber(new Date(2025, 0, 9))}-`+"01"; + public versionNumber = `V-${GlobalfunctionExtension.generateVersionNumber(new Date(2025, 0, 16))}-`+"01"; public static BASE_URL = ''; public base_url = ''; // public currentLink = ''; diff --git a/HRM.UI/ClientApp/src/app/reports/employee-profile-reports/employee-profile-reports.component.ts b/HRM.UI/ClientApp/src/app/reports/employee-profile-reports/employee-profile-reports.component.ts index 6cbe30c..5e3099d 100644 --- a/HRM.UI/ClientApp/src/app/reports/employee-profile-reports/employee-profile-reports.component.ts +++ b/HRM.UI/ClientApp/src/app/reports/employee-profile-reports/employee-profile-reports.component.ts @@ -97,24 +97,32 @@ export class EmployeeProfileReportsComponent implements OnInit { preview(reportType: string) { debugger; + if (this.selectedEmployee == undefined || this.selectedEmployee == null) { + this.notificationService.showWarning('Please Select and employee!!'); + return; + } + if (this.selectedreportType == undefined || this.selectedreportType['value'] == null) { + this.notificationService.showWarning('Please select a report!!'); + return; + } const data = { reportID: this.selectedreportType['value'], - personID: this.authorizedPerson.id, + personID: this.authorizedPerson != null ? this.authorizedPerson.id : 0, employeeID: this.selectedEmployee.employeeID, reportType: reportType == 'Download' ? 'PDF' : reportType }; - switch(this.selectedreportType['value']){ + switch (this.selectedreportType['value']) { case EnumProfileReportType.Print_CV: - this.PDFTitle = EnumExtension.getName(EnumProfileReportType, EnumProfileReportType.Print_CV); + this.PDFTitle = this.selectedEmployee.employeeNo + '-' + EnumExtension.getName(EnumProfileReportType, EnumProfileReportType.Print_CV); break; case EnumProfileReportType.Appointment_Letter_Officer: - this.PDFTitle = EnumExtension.getName(EnumProfileReportType, EnumProfileReportType.Appointment_Letter_Officer); + this.PDFTitle = this.selectedEmployee.employeeNo + '-' + EnumExtension.getName(EnumProfileReportType, EnumProfileReportType.Appointment_Letter_Officer); break; case EnumProfileReportType.Appointment_Letter_Staff: - this.PDFTitle = EnumExtension.getName(EnumProfileReportType, EnumProfileReportType.Appointment_Letter_Staff); + this.PDFTitle = this.selectedEmployee.employeeNo + '-' + EnumExtension.getName(EnumProfileReportType, EnumProfileReportType.Appointment_Letter_Staff); break; case EnumProfileReportType.Appointment_Letter_Worker: - this.PDFTitle = EnumExtension.getName(EnumProfileReportType, EnumProfileReportType.Appointment_Letter_Worker); + this.PDFTitle = this.selectedEmployee.employeeNo + '-' + EnumExtension.getName(EnumProfileReportType, EnumProfileReportType.Appointment_Letter_Worker); break; } @@ -134,9 +142,9 @@ export class EmployeeProfileReportsComponent implements OnInit { } this.loadingPanel.ShowLoadingPanel = false; }, - (err) => { + (err: any) => { this.closeForm(); - console.log(err); + // console.log(err); this.notificationService.showError(err.error); this.loadingPanel.ShowLoadingPanel = false; } @@ -144,25 +152,29 @@ export class EmployeeProfileReportsComponent implements OnInit { } else { this.reportService.getGeneratedProfileReportData(data).subscribe(fileData => { + + this.loadingPanel.ShowLoadingPanel = false; if (reportType == 'PDF') { var element = (document.getElementById("pdf-viewer-report")); element.src = URL.createObjectURL(new Blob([fileData], { type: 'application/pdf' })); } - this.loadingPanel.ShowLoadingPanel = false; - - // if (reportType == 'download') - // this.downloadBlob(new Blob([fileData], { type: 'application/pdf' }), 'application/pdf', dataItem.employeeNo + "-" + dataItem.name + "_" + dataItem.year.toString() + "_" + 'Promotion Letter'); - // this.loadingPanelService.ShowLoadingPanel = false; + if (reportType == 'Download') + this.downloadBlob(new Blob([fileData], { type: 'application/pdf' }), 'application/pdf', this.PDFTitle); + }, (error) => { this.closeForm(); + console.log(error); this.notificationService.showError(error.error); + this.loadingPanel.ShowLoadingPanel = false; }); } } downloadFile(blobContent) { + //EXCEL // let blob = new Blob([this.b64toBlob(blobContent, 'application/data:application/vnd.ms-excel', 1024)], {}); // saveAs(blob, this.PDFTitle + '.xls'); + //PDF let blob = new Blob([this.b64toBlob(blobContent, 'application/pdf', 1024)], {}); saveAs(blob, this.PDFTitle + '.pdf'); } @@ -186,6 +198,21 @@ export class EmployeeProfileReportsComponent implements OnInit { return blob; } + private downloadBlob(data: any, type: string, fileName: string): void { + const blob: Blob = new Blob([data], { type: type }); + // const fileName: string = this.workOrderBillReceive.UploadAttachment[0].OriginalFileName; + // const fileName: string = fileName; + const objectUrl: string = URL.createObjectURL(blob); + const a: HTMLAnchorElement = document.createElement('a') as HTMLAnchorElement; + + a.href = objectUrl; + a.download = fileName; + document.body.appendChild(a); + a.click(); + + document.body.removeChild(a); + URL.revokeObjectURL(objectUrl); + } public loadAuthorizedPerson() { this.employeeService.getAuthorizedPerson().subscribe( (resp) => { diff --git a/HRM.UI/Controllers/Report/ReportController.cs b/HRM.UI/Controllers/Report/ReportController.cs index 9afabc5..b911a00 100644 --- a/HRM.UI/Controllers/Report/ReportController.cs +++ b/HRM.UI/Controllers/Report/ReportController.cs @@ -1733,40 +1733,8 @@ namespace HRM.UI.Controllers.Report bytes = new rptEmployee().GetAsstOfficeAndAbove(employeeID, payrollTypeId, reportType); break; case EnumProfileReportType.Appointment_Letter_Worker: - ltemplate.SetObjectID(FixedLetterTemplte.Worker_Appointment_Letter); - - ltemplate.ID = 3; - ltemplate.Description = "Letter Template Worker"; - ltemplate.Subject = "Letter Template Worker"; - ltemplate.Type = EnumDocType.Desktop_Letter; - ltemplate.TypeID = (int)EnumDocType.Desktop_Letter; - - string downloadPath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + @"\Downloads"; - string lFileName = "Worker.doc"; - - string sFilePath = new rptEmployee().Generate(ltemplate, employeeID, payrollTypeId, downloadPath, lFileName); - - - byte[] buffer = new byte[16 * 1024]; - buffer = System.IO.File.ReadAllBytes(sFilePath); - string contentType = GetFileType(sFilePath); - var name = System.IO.Path.ChangeExtension(lFileName, ".pdf"); - if (System.IO.File.Exists(sFilePath)) - { - System.IO.File.Delete(sFilePath); - } - return File(buffer, contentType, name); break; case EnumProfileReportType.Appointment_Letter_Staff: - ltemplate.SetObjectID(FixedLetterTemplte.Staff_Appointment_Letter); - - ltemplate.ID = 2; - ltemplate.Description = "Letter Template Staff"; - ltemplate.Subject = "Letter Template Staff"; - ltemplate.Type = EnumDocType.Desktop_Letter; - ltemplate.TypeID = (int)EnumDocType.Desktop_Letter; - - new rptEmployee().Generate(ltemplate, employeeID, payrollTypeId, "C:\\Users\\mashfiq.EASE\\Downloads", "Staff.doc"); break; default: break; @@ -1804,17 +1772,12 @@ namespace HRM.UI.Controllers.Report try { + //string downloadPath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + @"\Downloads"; + string downloadPath = System.Environment.CurrentDirectory + "\\Documents\\LetterTempFolder\\"; + string sFilePath = string.Empty, lFileName = string.Empty; switch (reportid) { - //case EnumProfileReportType.Print_CV: - // bytes = new rptEmployee().GetEmployeeCV(employeeID, payrollTypeId, reportType); - // break; - //case EnumProfileReportType.Employee_Service_Book: - // break; - //case EnumProfileReportType.Appointment_Letter_Officer: - // bytes = new rptEmployee().GetAsstOfficeAndAbove(employeeID, payrollTypeId, reportType); - // break; case EnumProfileReportType.Appointment_Letter_Worker: ltemplate.SetObjectID(FixedLetterTemplte.Worker_Appointment_Letter); @@ -1824,21 +1787,9 @@ namespace HRM.UI.Controllers.Report ltemplate.Type = EnumDocType.Desktop_Letter; ltemplate.TypeID = (int)EnumDocType.Desktop_Letter; - string downloadPath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + @"\Downloads"; - string lFileName = "Worker.doc"; + lFileName = "Worker.doc"; - string sFilePath = new rptEmployee().Generate(ltemplate, employeeID, payrollTypeId, downloadPath, lFileName); - - - byte[] buffer = new byte[16 * 1024]; - buffer = System.IO.File.ReadAllBytes(sFilePath); - string contentType = GetFileType(sFilePath); - var name = System.IO.Path.ChangeExtension(lFileName, ".pdf"); - if (System.IO.File.Exists(sFilePath)) - { - System.IO.File.Delete(sFilePath); - } - return File(buffer, contentType, name); + sFilePath = new rptEmployee().Generate(ltemplate, employeeID, payrollTypeId, downloadPath, lFileName); break; case EnumProfileReportType.Appointment_Letter_Staff: ltemplate.SetObjectID(FixedLetterTemplte.Staff_Appointment_Letter); @@ -1849,12 +1800,28 @@ namespace HRM.UI.Controllers.Report ltemplate.Type = EnumDocType.Desktop_Letter; ltemplate.TypeID = (int)EnumDocType.Desktop_Letter; - new rptEmployee().Generate(ltemplate, employeeID, payrollTypeId, "C:\\Users\\mashfiq.EASE\\Downloads", "Staff.doc"); + lFileName = "Staff.doc"; + + sFilePath = new rptEmployee().Generate(ltemplate, employeeID, payrollTypeId, downloadPath, lFileName); break; default: break; } + + byte[] buffer = new byte[16 * 1024]; + buffer = System.IO.File.ReadAllBytes(sFilePath); + string contentType = GetFileType(sFilePath); + var name = System.IO.Path.ChangeExtension(lFileName, ".pdf"); + if (System.IO.File.Exists(sFilePath)) + { + System.IO.File.Delete(sFilePath); + } + if (System.IO.File.Exists(System.IO.Path.ChangeExtension(sFilePath, ".doc"))) + { + System.IO.File.Delete(System.IO.Path.ChangeExtension(sFilePath, ".doc")); + } + return File(buffer, contentType, name); } catch (Exception e) {