('/Report/getProfileReportData/', param);
}
+ getGeneratedProfileReportData(param: any) {
+ return this.apiService.httpDownloadFile('/Report/getGeneratedProfileReport/', param);
+ }
}
diff --git a/HRM.UI/ClientApp/src/app/reports/employee-profile-reports/employee-profile-reports.component.html b/HRM.UI/ClientApp/src/app/reports/employee-profile-reports/employee-profile-reports.component.html
index c62ccb2..80054c8 100644
--- a/HRM.UI/ClientApp/src/app/reports/employee-profile-reports/employee-profile-reports.component.html
+++ b/HRM.UI/ClientApp/src/app/reports/employee-profile-reports/employee-profile-reports.component.html
@@ -47,8 +47,8 @@
-
+
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 91963a3..6cbe30c 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
@@ -45,6 +45,7 @@ import { encodeBase64 } from '@progress/kendo-file-saver';
import { AuthorizedPerson } from 'src/app/adhoc-feature/authorized-persons/authorizedPerson';
import { Employee } from 'src/app/_models/Employee/employee';
import { HrEmployee } from 'src/app/_models/HREmployee/hrEmployee';
+import { HttpClient } from '@angular/common/http';
@Component({
selector: 'app-employee-profile-reports',
@@ -97,42 +98,73 @@ export class EmployeeProfileReportsComponent implements OnInit {
preview(reportType: string) {
debugger;
const data = {
- reportID: this.selectedreportType['value'],
- personID: this.authorizedPerson.id,
- employeeID: this.selectedEmployee.employeeID,
- reportType: reportType
+ reportID: this.selectedreportType['value'],
+ personID: this.authorizedPerson.id,
+ employeeID: this.selectedEmployee.employeeID,
+ reportType: reportType == 'Download' ? 'PDF' : reportType
};
+ switch(this.selectedreportType['value']){
+ case EnumProfileReportType.Print_CV:
+ this.PDFTitle = EnumExtension.getName(EnumProfileReportType, EnumProfileReportType.Print_CV);
+ break;
+ case EnumProfileReportType.Appointment_Letter_Officer:
+ this.PDFTitle = EnumExtension.getName(EnumProfileReportType, EnumProfileReportType.Appointment_Letter_Officer);
+ break;
+ case EnumProfileReportType.Appointment_Letter_Staff:
+ this.PDFTitle = EnumExtension.getName(EnumProfileReportType, EnumProfileReportType.Appointment_Letter_Staff);
+ break;
+ case EnumProfileReportType.Appointment_Letter_Worker:
+ this.PDFTitle = EnumExtension.getName(EnumProfileReportType, EnumProfileReportType.Appointment_Letter_Worker);
+ break;
+ }
this.loadingPanel.ShowLoadingPanel = true;
if (reportType === 'PDF')
- this.showPopUp = true;
- this.reportService.getProfileReportData(data).subscribe(
+ this.showPopUp = true;
+ if (this.selectedreportType['value'] == EnumProfileReportType.Print_CV || this.selectedreportType['value'] == EnumProfileReportType.Appointment_Letter_Officer) {
+ this.reportService.getProfileReportData(data).subscribe(
(resp: any) => {
- if (reportType === 'PDF') {
+ if (reportType === 'PDF') {
- this.src = URL.createObjectURL(this.b64toBlob(resp, 'application/pdf', 1024));
- var element = (document.getElementById("pdf-viewer-report"));
- element.src = this.src;
- } else if (reportType === 'EXCEL') {
- this.downloadFile(resp);
- }
+ this.src = URL.createObjectURL(this.b64toBlob(resp, 'application/pdf', 1024));
+ var element = (document.getElementById("pdf-viewer-report"));
+ element.src = this.src;
+ } else if (reportType === 'Download') {
+ this.downloadFile(resp);
+ }
+ this.loadingPanel.ShowLoadingPanel = false;
},
(err) => {
- this.closeForm();
- console.log(err);
- this.notificationService.showError(err.error);
- this.loadingPanel.ShowLoadingPanel = false;
- },
- () => {
-
- this.loadingPanel.ShowLoadingPanel = false;
- // this.loadGrid();
+ this.closeForm();
+ console.log(err);
+ this.notificationService.showError(err.error);
+ this.loadingPanel.ShowLoadingPanel = false;
}
- );
+ );
+ }
+ else {
+ this.reportService.getGeneratedProfileReportData(data).subscribe(fileData => {
+ 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;
+ },
+ (error) => {
+ this.closeForm();
+ this.notificationService.showError(error.error);
+ });
+ }
}
downloadFile(blobContent) {
- let blob = new Blob([this.b64toBlob(blobContent, 'application/data:application/vnd.ms-excel', 1024)], {});
- saveAs(blob, this.PDFTitle + '.xls');
+ // let blob = new Blob([this.b64toBlob(blobContent, 'application/data:application/vnd.ms-excel', 1024)], {});
+ // saveAs(blob, this.PDFTitle + '.xls');
+ let blob = new Blob([this.b64toBlob(blobContent, 'application/pdf', 1024)], {});
+ saveAs(blob, this.PDFTitle + '.pdf');
}
b64toBlob(b64Data, contentType, sliceSize) {
const byteCharacters = atob(b64Data);
@@ -183,6 +215,7 @@ export class EmployeeProfileReportsComponent implements OnInit {
// }
// );
}
+
}
export enum EnumProfileReportType {
diff --git a/HRM.UI/Controllers/Report/ReportController.cs b/HRM.UI/Controllers/Report/ReportController.cs
index 2711a5a..9afabc5 100644
--- a/HRM.UI/Controllers/Report/ReportController.cs
+++ b/HRM.UI/Controllers/Report/ReportController.cs
@@ -20,6 +20,7 @@ using NPOI.SS.Formula.Functions;
using HRM.BO.Report;
using HRM.Report.PayrollDataSet;
using Newtonsoft.Json;
+using Microsoft.AspNetCore.StaticFiles;
namespace HRM.UI.Controllers.Report
{
@@ -1740,7 +1741,21 @@ 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", "Worker.doc");
+ 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);
@@ -1765,5 +1780,103 @@ namespace HRM.UI.Controllers.Report
return Ok(bytes);
}
+
+ [HttpPost("getGeneratedProfileReport")]
+ public ActionResult getGeneratedProfileReportData(dynamic data)
+ {
+ CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
+ var items = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data));
+ EnumProfileReportType reportid = (EnumProfileReportType)items["reportID"].ToObject();
+ int personID = 0;
+ int employeeID = 0;
+
+ if (items["personID"] != null)
+ personID = (int)items["personID"].ToObject();
+ if (items["employeeID"] != null)
+ employeeID = (int)items["employeeID"].ToObject();
+
+ string reportType = (string)items["reportType"].ToObject();
+
+ int payrollTypeId = currentUser.PayrollTypeID.GetValueOrDefault();
+ byte[] bytes = null;
+
+ LetterTemplte ltemplate = new LetterTemplte();
+
+ try
+ {
+
+ 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);
+
+ 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;
+
+ }
+ }
+ catch (Exception e)
+ {
+ return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
+ }
+
+ return Ok(bytes);
+ }
+
+ [HttpPost]
+ [Route("get-file-type")]
+ [AllowAnonymous]
+ [IgnoreAntiforgeryToken]
+ [ProducesResponseType(StatusCodes.Status200OK)]
+ public string GetFileType(string originalFileName)
+ {
+ //var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data));
+ //string fileName = (string)item["fileName"].ToObject();
+ string fileName = originalFileName;
+ string contentType;
+ new FileExtensionContentTypeProvider().TryGetContentType(fileName, out contentType);
+ return contentType ?? "application/octet-stream";
+ }
}
}