msword, profile letter

This commit is contained in:
mashfiq 2025-01-16 16:18:21 +06:00
parent dc29f2f17c
commit accd302ef4
6 changed files with 220 additions and 31 deletions

View File

@ -21,6 +21,7 @@ using Microsoft.Extensions.Configuration;
using NPOI.SS.Formula.Functions;
using System.Collections;
using Microsoft.AspNetCore.Http;
using NPOI.HPSF;
namespace HRM.Report
{
@ -3448,7 +3449,7 @@ namespace HRM.Report
{
try
{
string pdfFilePath = string.Empty;
PayrollType payrollType = new PayrollTypeService().Get(payrollTypeID);
string[] sBody = { };
string sFilePath = string.Empty;
@ -3457,7 +3458,7 @@ namespace HRM.Report
// Commented for testing in development phase
//LetterTemplte letterTemplte = new LetterTemplteService().Get(oLetterTemplate.ID);
//PhotoPath oPhotoPath = new PhotoPathService().Get(ID.FromInteger(1));
PhotoPath oPhotoPath = new PhotoPathService().Get(1);
//PhotoPath oPhotoPath = new PhotoPathService().Get(1);
#region Expandable Objects
@ -3629,14 +3630,41 @@ namespace HRM.Report
file.ReplaceWords(sFilePath, table);
file.CloseWordApplication();
pdfFilePath = System.IO.Path.ChangeExtension(sFilePath, ".pdf");
ConvertDocToPdf(sFilePath, pdfFilePath);
}
return sFilePath;
return pdfFilePath;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
public void ConvertDocToPdf(string wordFilePath, string pdfFilePath)
{
Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.Application();
Microsoft.Office.Interop.Word.Document wordDocument = null;
try
{
// Open the Word document
wordDocument = wordApp.Documents.Open(wordFilePath);
// Save as PDF
wordDocument.SaveAs(pdfFilePath, Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatPDF);
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
finally
{
// Clean up
wordDocument?.Close();
System.Runtime.InteropServices.Marshal.ReleaseComObject(wordDocument);
wordApp.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(wordApp);
}
}
}
}

View File

@ -296,6 +296,18 @@
<None Remove="RDLC\UpCommingEmp.rdlc" />
</ItemGroup>
<ItemGroup>
<COMReference Include="Microsoft.Office.Interop.Word">
<WrapperTool>tlbimp</WrapperTool>
<VersionMinor>7</VersionMinor>
<VersionMajor>8</VersionMajor>
<Guid>00020905-0000-0000-c000-000000000046</Guid>
<Lcid>0</Lcid>
<Isolated>false</Isolated>
<EmbedInteropTypes>true</EmbedInteropTypes>
</COMReference>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Attendence\RDLC\DailyAbsent.rdlc" />
<EmbeddedResource Include="Attendence\RDLC\DailyAbsentEcho.rdlc" />

View File

@ -133,4 +133,7 @@ export class ReportServices {
getProfileReportData(param: any): Observable<HttpEvent<any>> {
return this.apiService.httpPost<any>('/Report/getProfileReportData/', param);
}
getGeneratedProfileReportData(param: any) {
return this.apiService.httpDownloadFile('/Report/getGeneratedProfileReport/', param);
}
}

View File

@ -47,8 +47,8 @@
</div>
<div class="p-col-12" align="right">
<button kendoButton icon="file-pdf" [primary]="true" (click)="preview('PDF')">Preview</button>
<button kendoButton icon="file-excel" [primary]="true" style="margin-left:5px;"
(click)="preview('EXCEL')">Export</button>
<button kendoButton icon="download" [primary]="true" style="margin-left:5px;"
(click)="preview('Download')">Download</button>
</div>
</fieldset>
</div>

View File

@ -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 = <HTMLIFrameElement>(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 = <HTMLIFrameElement>(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 = <HTMLIFrameElement>(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 {

View File

@ -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>();
int personID = 0;
int employeeID = 0;
if (items["personID"] != null)
personID = (int)items["personID"].ToObject<int>();
if (items["employeeID"] != null)
employeeID = (int)items["employeeID"].ToObject<int>();
string reportType = (string)items["reportType"].ToObject<string>();
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>();
string fileName = originalFileName;
string contentType;
new FileExtensionContentTypeProvider().TryGetContentType(fileName, out contentType);
return contentType ?? "application/octet-stream";
}
}
}