EchoTex_Payroll/HRM.UI/Controllers/LetterRequest/LetterRequestController.cs

788 lines
42 KiB
C#
Raw Normal View History

2024-10-14 10:01:49 +06:00
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using AutoMapper.Configuration;
using Google.Protobuf.WellKnownTypes;
using HRM.BO;
using HRM.DA;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.StaticFiles;
using Microsoft.Extensions.Configuration;
using NPOI.SS.Formula.Functions;
using Org.BouncyCastle.Ocsp;
using static HRM.Report.PayrollDataSet.PayrollDataSet;
using static iTextSharp.text.pdf.AcroFields;
using static NPOI.POIFS.Crypt.Dsig.SignatureInfo;
using IConfiguration = Microsoft.Extensions.Configuration.IConfiguration;
// For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
namespace HRM.UI.Controllers
{
[ApiController]
[Route("api/LetterRequest")]
[Authorize]
public class LetterRequestController : Controller
{
#region Declerations
private readonly ICVService _cvService;
private readonly IHeadCountApprovalRequestService _headCountApprovalRequestService;
private readonly IInternalRecruitmentService _internalRecruitmentService;
private readonly ICandidateService _candidateService;
private readonly IRecruitementProcessService _recruitementProcessService;
private readonly IRecruitmentLettersService _recruitementLettterService;
private readonly ILetterRequestService _letterRequestService;
private readonly IEmployeeService _employeeService;
private readonly IDepartmentService _departmentService;
private readonly IDesignationService _designationService;
private readonly IGradeService _gradeService;
private readonly ICategoryService _categoryService;
private readonly IConfiguration _config;
private readonly IAuthorizedPersonService _authorizedPersonService;
private readonly ICountryService _countryService;
private readonly IOrganizationService _organizationService;
private readonly ISalaryMonthlyService _salaryMonthlyService;
private readonly IPayrollTypeService _payrollTypeService;
private readonly IEmpLifeCycleService _empLifeCycleService;
private readonly IEmployeeGradeSalaryService _empGradeSalaryService;
BusinessTemplateBuilder _templateBuilder = null;
private static string _filePath = @"Documents\LetterTempletes";
//test
//private static string _letterRequestTemplatePath = @"ClientApp\Documents\LetterTempletes\";
//private static string _letterfileGeneratedPath = @"ClientApp\Documents\LetterTempletes\GeneratedLetter\";
//private static string _letterRequestSignaturePath = @"ClientApp\Documents\LetterTempletes\Signatures\";
//private static string _logoPath = @"ClientApp\Documents\LetterTempletes\Signatures\PulsTrading.png";
//private static string _letterRequestfilePath = @"ClientApp\Documents\";
//private static string _letterRequestSignatureSealPath = @"ClientApp\Documents\LetterTempletes\Signatures\TempSignatureFiles\";
//live
private static string _letterRequestTemplatePath = @"Documents\LetterTempletes\";
private static string _letterfileGeneratedPath = @"Documents\LetterTempletes\GeneratedLetter\";
private static string _letterRequestSignaturePath = @"Documents\LetterTempletes\Signatures\";
private static string _logoPath = @"Documents\LetterTempletes\Signatures\PulsTrading.png";
private static string _letterRequestfilePath = @"Documents\";
private static string _letterRequestSignatureSealPath = @"Documents\LetterTempletes\Signatures\TempSignatureFiles\";
#endregion
#region Constructor
public LetterRequestController(IConfiguration config,
ICVService cvService,
IHeadCountApprovalRequestService headCountService,
IInternalRecruitmentService internalRecruitmentService,
IPayrollTypeService pTypeService,
ICandidateService candidateService, IRecruitementProcessService recruitementProcessService
, IRecruitmentLettersService recruitementLettterService, ILetterRequestService letterRequestService, IEmployeeService employeeService,
IDepartmentService departmentService, IDesignationService designationService, ICategoryService categoryService, IGradeService gradeService,
IAuthorizedPersonService authorizedPersonService, ICountryService countryService, IOrganizationService organizationService, ISalaryMonthlyService salaryMonthlyService,
IEmpLifeCycleService empLifeCycleService,IEmployeeGradeSalaryService employeeGradeSalaryService
)
{
_config = config;
_cvService = cvService;
_headCountApprovalRequestService = headCountService;
_internalRecruitmentService = internalRecruitmentService;
_candidateService = candidateService;
this._recruitementProcessService = recruitementProcessService;
this._recruitementLettterService = recruitementLettterService;
this._letterRequestService = letterRequestService;
this._employeeService = employeeService;
this._departmentService = departmentService;
this._designationService = designationService;
this._categoryService = categoryService;
this._gradeService = gradeService;
this._countryService = countryService;
_authorizedPersonService = authorizedPersonService;
_organizationService = organizationService;
this._salaryMonthlyService = salaryMonthlyService;
this._payrollTypeService = pTypeService;
this._empLifeCycleService = empLifeCycleService;
this._empGradeSalaryService = employeeGradeSalaryService;
}
#endregion
[HttpGet]
[Route("getOrganizationByOrganizationType/{type}")]
public ActionResult GetOrganizationByOrganizationType(EnumLetterOrganizationType type)
{
List<Organization> oOrganizations = new List<Organization>();
DataSet ds = new DataSet();
try
{
ds = _letterRequestService.GetOrganizationByOrganizationType(type);
foreach (var row in ds.Tables[0].AsEnumerable())
{
Organization temp = new Organization();
temp.ID = row["ORGANIZATIONID"] == null ? 0 : row.Field<Int32>("ORGANIZATIONID");
temp.Name = row["Name"] == null ? "" : row.Field<string>("Name");
temp.Code = row["Code"] == null ? "" : row.Field<string>("Code");
temp.Address = row["Address"] == null ? "" : row.Field<string>("Address");
temp.AddressLine2 = row["AddressLine2"] == null ? "" : row.Field<string>("AddressLine2");
temp.AddressLine3 = row["AddressLine3"] == null ? "" : row.Field<string>("AddressLine3");
temp.RecipeintDesignation = row["RECIPIENTDESIGNATION"] == null ? "" : row.Field<string>("RECIPIENTDESIGNATION");
temp.CountryId = row["Country"] == DBNull.Value ? 0 : Convert.ToInt32(row["Country"]);
//temp.Nationality = row["Nationality"] == null ? "" : row.Field<string>("Nationality");
//temp.PassportNo = row["PassportNo"] == null ? "" : row.Field<string>("PassportNo");
oOrganizations.Add(temp);
}
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(oOrganizations);
}
[HttpPost]
[Route("saveletterrequest")]
public ActionResult SaveLetterRequest(LetterRequest ob)
{
try
{
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
ob.CreatedBy = currentUser.UserID;
ob.CreatedDate = DateTime.Today;
ob.RequestDate = DateTime.Today;
ob.EmployeeId = (int)currentUser.EmployeeID;
if (!Convert.ToBoolean(ob.IsDisgitalSinature))
{
ob.IsDisgitalSinature = false;
ob.Status = EnumStatus.Inactive;// Inactive == Approved
}
_letterRequestService.Save(ob);
}
catch (Exception e)
{
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
}
return Ok();
}
[HttpGet]
[Route("getLetterRequests")]
public ActionResult getLetterRequests()
{
DataSet ds = new DataSet();
List<LetterRequest> oLetterRequests = new List<LetterRequest>();
try
{
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
ds = _letterRequestService.GetLetterRequests((int)currentUser.EmployeeID);
foreach (var row in ds.Tables[0].AsEnumerable())
{
LetterRequest temp = new LetterRequest();
temp.ID = row["LetterRequestId"] == null ? 0 : row.Field<Int32>("LetterRequestId");
temp.Purpose = (EnumLetterRequestPurpose)int.Parse(row["Purpose"].ToString());
temp.PurposeName = !string.IsNullOrEmpty(row["Purpose"].ToString()) ? ((EnumLetterRequestPurpose)int.Parse(row["Purpose"].ToString())).ToString().Replace("_", " ") : string.Empty;
if (temp.Purpose == EnumLetterRequestPurpose.Employment_Certificate || temp.Purpose == EnumLetterRequestPurpose.Experience_Certificate || temp.Purpose == EnumLetterRequestPurpose.Visa_Request_NOC_Personal || temp.Purpose == EnumLetterRequestPurpose.NOC_For_Immigration)
{
temp.PurposeName = EnumHelper.GetEnumDescription(temp.Purpose);
}
temp.AddressLine1 = !string.IsNullOrEmpty(row["AddressLine1"].ToString()) ? row["AddressLine1"].ToString() : string.Empty;
temp.AddressLine2 = !string.IsNullOrEmpty(row["AddressLine2"].ToString()) ? row["AddressLine2"].ToString() : string.Empty;
temp.AddressLine3 = !string.IsNullOrEmpty(row["AddressLine3"].ToString()) ? row["AddressLine3"].ToString() : string.Empty;
temp.PassportNo = !string.IsNullOrEmpty(row["PassportNo"].ToString()) ? row["PassportNo"].ToString() : string.Empty;
temp.Nationality = !string.IsNullOrEmpty(row["Nationality"].ToString()) ? row["Nationality"].ToString() : string.Empty;
temp.Remarks = !string.IsNullOrEmpty(row["Remarks"].ToString()) ? row["Remarks"].ToString() : string.Empty;
temp.FromDate = !string.IsNullOrEmpty(row["FromDate"].ToString()) ? DateTime.Parse(row["FromDate"].ToString()) : null;
temp.ToDate = !string.IsNullOrEmpty(row["ToDate"].ToString()) ? DateTime.Parse(row["ToDate"].ToString()) : null;
temp.CountryId = row["CountryId"] == DBNull.Value ? 0 : Convert.ToInt32(row["CountryId"]);
temp.CreatedDate = DateTime.Parse(row["CREATIONDATE"].ToString());
temp.ApprovalDate = !string.IsNullOrEmpty(row["APPROVALDATE"].ToString()) ? DateTime.Parse(row["APPROVALDATE"].ToString()) : null;
temp.EmployeeId = row["EmployeeId"] == null ? 0 : row.Field<Int32>("EmployeeId");
temp.EmployeeNo = !string.IsNullOrEmpty(row["EMPLOYEENO"].ToString()) ? row["EMPLOYEENO"].ToString() : string.Empty;
temp.EmployeeName = !string.IsNullOrEmpty(row["EmployeeName"].ToString()) ? row["EmployeeName"].ToString() : string.Empty;
temp.RejectComment = !string.IsNullOrEmpty(row["REJECTCOMMENT"].ToString()) ? row["REJECTCOMMENT"].ToString() : string.Empty;
temp.RequestDate = DateTime.Parse(row["LETTERREQUESTDATE"].ToString());
temp.LastWorkingDate = !string.IsNullOrEmpty(row["LastWorkingDate"].ToString()) ? DateTime.Parse(row["LastWorkingDate"].ToString()) : null;
temp.LetterRequestStatus = (EnumLetterRequestStatus)int.Parse(row["Status"].ToString());
temp.RejectComment = !string.IsNullOrEmpty(row["REJECTCOMMENT"].ToString()) ? row["REJECTCOMMENT"].ToString() : string.Empty;
if ((EnumLetterRequestStatus)int.Parse(row["status"].ToString()) == EnumLetterRequestStatus.Approved)
{
temp.StatusString = "Approved";
}
else if ((EnumLetterRequestStatus)int.Parse(row["WfStatus"].ToString()) == EnumLetterRequestStatus.Rejected)
{
temp.StatusString = "Rejected";
}
else if ((EnumLetterRequestStatus)int.Parse(row["WfStatus"].ToString()) == EnumLetterRequestStatus.Submitted)
{
temp.StatusString = "Submitted";
}
else
{
temp.StatusString = !string.IsNullOrEmpty(row["Status"].ToString()) ? ((EnumLetterRequestStatus)int.Parse(row["Status"].ToString())).ToString() == "Not Approved" ? string.Empty : ((EnumLetterRequestStatus)int.Parse(row["Status"].ToString())).ToString().Replace("_", " ") : string.Empty;
}
temp.TripType = row["TripType"] == DBNull.Value ? EnumLetterRequestTrip.None : (EnumLetterRequestTrip)int.Parse(row["TripType"].ToString());
temp.SignatoryId = row["AuthorizedPersonId"] == DBNull.Value ? 0 : Convert.ToInt32(row["AuthorizedPersonId"]);
temp.OrganizationId = row["OrganizationId"] == DBNull.Value ? 0 : Convert.ToInt32(row["OrganizationId"]);
temp.IsDisgitalSinature = row["IsDisgitalSinature"] == DBNull.Value ? null : Convert.ToBoolean(row["IsDisgitalSinature"]);
temp.IsWFNeeded = row["IsWFNeeded"] == DBNull.Value ? null : Convert.ToBoolean(row["IsWFNeeded"]);
temp.RecipeintDesignation = !string.IsNullOrEmpty(row["RecipeintDesignation"].ToString()) ? row["RecipeintDesignation"].ToString() : string.Empty;
oLetterRequests.Add(temp);
}
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(oLetterRequests);
}
[HttpGet]
[Route("getPendingLetterRequest")]
public ActionResult getPendingLetterRequest()
{
DataSet ds = new DataSet();
List<LetterRequest> oLetterRequests = new List<LetterRequest>();
try
{
ds = _letterRequestService.GetPendingLetterRequestsForApproval();
foreach (var row in ds.Tables[0].AsEnumerable())
{
LetterRequest temp = new LetterRequest();
temp.ID = row["LetterRequestId"] == null ? 0 : row.Field<Int32>("LetterRequestId");
temp.Purpose = (EnumLetterRequestPurpose)int.Parse(row["Purpose"].ToString());
temp.PurposeName = !string.IsNullOrEmpty(row["Purpose"].ToString()) ? ((EnumLetterRequestPurpose)int.Parse(row["Purpose"].ToString())).ToString().Replace("_", " ") : string.Empty;
temp.AddressLine1 = !string.IsNullOrEmpty(row["AddressLine1"].ToString()) ? row["AddressLine1"].ToString() : string.Empty;
temp.AddressLine2 = !string.IsNullOrEmpty(row["AddressLine2"].ToString()) ? row["AddressLine2"].ToString() : string.Empty;
temp.Remarks = !string.IsNullOrEmpty(row["Remarks"].ToString()) ? row["Remarks"].ToString() : string.Empty;
temp.FromDate = !string.IsNullOrEmpty(row["FROMDATE"].ToString()) ? DateTime.Parse(row["FROMDATE"].ToString()) : null;
temp.ToDate = !string.IsNullOrEmpty(row["TODATE"].ToString()) ? DateTime.Parse(row["TODATE"].ToString()) : null;
temp.CreatedDate = DateTime.Parse(row["CREATIONDATE"].ToString());
temp.ApprovalDate = !string.IsNullOrEmpty(row["APPROVALDATE"].ToString()) ? DateTime.Parse(row["APPROVALDATE"].ToString()) : null;
temp.LetterRequestStatus = (EnumLetterRequestStatus)int.Parse(row["Status"].ToString());
//temp.ApprovalNeeded = ;
temp.RejectComment = !string.IsNullOrEmpty(row["REJECTCOMMENT"].ToString()) ? row["REJECTCOMMENT"].ToString() : string.Empty;
temp.RejectComment = !string.IsNullOrEmpty(row["REJECTCOMMENT"].ToString()) ? row["REJECTCOMMENT"].ToString() : string.Empty;
if ((EnumLetterRequestStatus)int.Parse(row["status"].ToString()) == EnumLetterRequestStatus.Approved)
{
temp.StatusString = "Approved";
}
else if ((EnumLetterRequestStatus)int.Parse(row["WfStatus"].ToString()) == EnumLetterRequestStatus.Rejected)
{
temp.StatusString = "Rejected";
}
else if ((EnumLetterRequestStatus)int.Parse(row["WfStatus"].ToString()) == EnumLetterRequestStatus.Submitted)
{
temp.StatusString = "Submitted";
}
else
{
temp.StatusString = !string.IsNullOrEmpty(row["Status"].ToString()) ? ((EnumLetterRequestStatus)int.Parse(row["Status"].ToString())).ToString() == "None" ? string.Empty : ((EnumLetterRequestStatus)int.Parse(row["Status"].ToString())).ToString().Replace("_", " ") : string.Empty;
}
temp.EmployeeId = row["EmployeeId"] == null ? 0 : row.Field<Int32>("EmployeeId");
temp.EmployeeNo = !string.IsNullOrEmpty(row["EMPLOYEENO"].ToString()) ? row["EMPLOYEENO"].ToString() : string.Empty;
temp.EmployeeName = !string.IsNullOrEmpty(row["EmployeeName"].ToString()) ? row["EmployeeName"].ToString() : string.Empty;
temp.RequestDate = DateTime.Parse(row["LETTERREQUESTDATE"].ToString());
temp.SignatoryId = row["AuthorizedPersonId"] == DBNull.Value ? 0 : Convert.ToInt32(row["AuthorizedPersonId"]);
temp.OrganizationId = row["OrganizationId"] == DBNull.Value ? 0 : Convert.ToInt32(row["OrganizationId"]);
temp.IsDisgitalSinature = row["IsDisgitalSinature"] == DBNull.Value ? null : Convert.ToBoolean(row["IsDisgitalSinature"]);
temp.IsWFNeeded = row["IsWFNeeded"] == DBNull.Value ? null : Convert.ToBoolean(row["IsWFNeeded"]);
temp.RecipeintDesignation = !string.IsNullOrEmpty(row["RecipeintDesignation"].ToString()) ? row["RecipeintDesignation"].ToString() : string.Empty;
oLetterRequests.Add(temp);
}
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(oLetterRequests);
}
[HttpGet]
[Route("getRequestedLetterRequestItems/{fromDate}/{toDate}/{empId}")]
public ActionResult GetRequestedLetterRequestItems(DateTime? fromDate, DateTime? toDate, int empId)
{
DataSet ds = new DataSet();
List<LetterRequest> oLetterRequests = new List<LetterRequest>();
try
{
ds = _letterRequestService.GetRequestedLetterRequestItems(fromDate, toDate, empId);
foreach (var row in ds.Tables[0].AsEnumerable())
{
LetterRequest temp = new LetterRequest();
temp.ID = row["LetterRequestId"] == null ? 0 : row.Field<Int32>("LetterRequestId");
temp.Purpose = (EnumLetterRequestPurpose)int.Parse(row["Purpose"].ToString());
temp.PurposeName = !string.IsNullOrEmpty(row["Purpose"].ToString()) ? ((EnumLetterRequestPurpose)int.Parse(row["Purpose"].ToString())).ToString().Replace("_", " ") : string.Empty;
temp.AddressLine1 = !string.IsNullOrEmpty(row["AddressLine1"].ToString()) ? row["AddressLine1"].ToString() : string.Empty;
temp.AddressLine2 = !string.IsNullOrEmpty(row["AddressLine2"].ToString()) ? row["AddressLine2"].ToString() : string.Empty;
temp.Remarks = !string.IsNullOrEmpty(row["Remarks"].ToString()) ? row["Remarks"].ToString() : string.Empty;
temp.FromDate = !string.IsNullOrEmpty(row["FROMDATE"].ToString()) ? DateTime.Parse(row["FROMDATE"].ToString()) : null;
temp.ToDate = !string.IsNullOrEmpty(row["TODATE"].ToString()) ? DateTime.Parse(row["TODATE"].ToString()) : null;
temp.CreatedDate = DateTime.Parse(row["CREATIONDATE"].ToString());
temp.ApprovalDate = !string.IsNullOrEmpty(row["APPROVALDATE"].ToString()) ? DateTime.Parse(row["APPROVALDATE"].ToString()) : null;
temp.LetterRequestStatus = (EnumLetterRequestStatus)int.Parse(row["Status"].ToString());
//temp.ApprovalNeeded = ;
temp.RejectComment = !string.IsNullOrEmpty(row["REJECTCOMMENT"].ToString()) ? row["REJECTCOMMENT"].ToString() : string.Empty;
if ((EnumLetterRequestStatus)int.Parse(row["status"].ToString()) == EnumLetterRequestStatus.Approved)
{
temp.StatusString = "Approved";
}
else if ((EnumLetterRequestStatus)int.Parse(row["WfStatus"].ToString()) == EnumLetterRequestStatus.Rejected)
{
temp.StatusString = "Rejected";
}
else if ((EnumLetterRequestStatus)int.Parse(row["WfStatus"].ToString()) == EnumLetterRequestStatus.Submitted)
{
temp.StatusString = "Submitted";
}
else
{
temp.StatusString = !string.IsNullOrEmpty(row["Status"].ToString()) ? ((EnumLetterRequestStatus)int.Parse(row["Status"].ToString())).ToString() == "None" ? string.Empty : ((EnumLetterRequestStatus)int.Parse(row["Status"].ToString())).ToString().Replace("_", " ") : string.Empty;
}
temp.EmployeeId = row["EmployeeId"] == null ? 0 : row.Field<Int32>("EmployeeId");
temp.EmployeeNo = !string.IsNullOrEmpty(row["EMPLOYEENO"].ToString()) ? row["EMPLOYEENO"].ToString() : string.Empty;
temp.EmployeeName = !string.IsNullOrEmpty(row["EmployeeName"].ToString()) ? row["EmployeeName"].ToString() : string.Empty;
temp.RequestDate = DateTime.Parse(row["LETTERREQUESTDATE"].ToString());
temp.SignatoryId = row["AuthorizedPersonId"] == DBNull.Value ? 0 : Convert.ToInt32(row["AuthorizedPersonId"]);
temp.IsDisgitalSinature = row["IsDisgitalSinature"] == DBNull.Value ? null : Convert.ToBoolean(row["IsDisgitalSinature"]);
temp.IsWFNeeded = row["IsWFNeeded"] == DBNull.Value ? null : Convert.ToBoolean(row["IsWFNeeded"]);
temp.RecipeintDesignation = !string.IsNullOrEmpty(row["RecipeintDesignation"].ToString()) ? row["RecipeintDesignation"].ToString() : string.Empty;
oLetterRequests.Add(temp);
}
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(oLetterRequests);
}
[HttpGet]
[Route("getLetterRequestForApproval/{id}")]
public ActionResult GetLetterRequestForApproval(int id)
{
DataSet ds = new DataSet();
List<LetterRequest> oLetterRequests = new List<LetterRequest>();
try
{
ds = _letterRequestService.GetLetterRequestForApproval(id);
foreach (var row in ds.Tables[0].AsEnumerable())
{
LetterRequest temp = new LetterRequest();
temp.ID = row["LetterRequestId"] == null ? 0 : row.Field<Int32>("LetterRequestId");
temp.Purpose = (EnumLetterRequestPurpose)int.Parse(row["Purpose"].ToString());
temp.PurposeName = !string.IsNullOrEmpty(row["Purpose"].ToString()) ? ((EnumLetterRequestPurpose)int.Parse(row["Purpose"].ToString())).ToString().Replace("_", " ") : string.Empty;
temp.Remarks = !string.IsNullOrEmpty(row["Remarks"].ToString()) ? row["Remarks"].ToString() : string.Empty;
temp.FromDateString = !string.IsNullOrEmpty(row["FROMDATE"].ToString()) ? DateTime.Parse(row["FROMDATE"].ToString()).ToString("dd/MM/yy") : null;
temp.ToDateString = !string.IsNullOrEmpty(row["TODATE"].ToString()) ? DateTime.Parse(row["TODATE"].ToString()).ToString("dd/MM/yy") : null;
temp.CreatedDate = DateTime.Parse(row["CREATIONDATE"].ToString());
temp.SignatoryId = row["AuthorizedPersonId"] == DBNull.Value ? 0 : Convert.ToInt32(row["AuthorizedPersonId"]);
temp.EmployeeId = row["EmployeeId"] == DBNull.Value ? 0 : Convert.ToInt32(row["EmployeeId"]);
temp.EmployeeNo = !string.IsNullOrEmpty(row["EMPLOYEENO"].ToString()) ? row["EMPLOYEENO"].ToString() : string.Empty;
temp.EmployeeName = !string.IsNullOrEmpty(row["EmployeeName"].ToString()) ? row["EmployeeName"].ToString() : string.Empty;
temp.Department = !string.IsNullOrEmpty(row["deptName"].ToString()) ? row["deptName"].ToString() : string.Empty;
temp.Designation = !string.IsNullOrEmpty(row["Designation"].ToString()) ? row["Designation"].ToString() : string.Empty;
temp.Organization = !string.IsNullOrEmpty(row["Organization"].ToString()) ? row["Organization"].ToString() : string.Empty;
temp.OrganizationTypeString = !string.IsNullOrEmpty(row["ORGANIZATIONTYPE"].ToString()) ? ((EnumLetterRequestPurpose)int.Parse(row["ORGANIZATIONTYPE"].ToString())).ToString().Replace("_", " ") : string.Empty;
temp.RequestDateString = DateTime.Parse(row["LETTERREQUESTDATE"].ToString()).ToString("dd/MM/yy");
temp.LastworkingDateString = !string.IsNullOrEmpty(row["LastWorkingDate"].ToString()) ? DateTime.Parse(row["LastWorkingDate"].ToString()).ToString("dd/MM/yy") : null;
oLetterRequests.Add(temp);
}
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(oLetterRequests[0]);
}
[HttpPost]
[Route("approveLetterRequest")]
public ActionResult ApproveLetterRequest(WFMovementTran otran)
{
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
otran.FromEmployeeID = (int)currentUser.EmployeeID;
try
{
_letterRequestService.ApproveLetterRequest(otran);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(true);
}
[HttpPost]
[Route("rejectLetterRequest")]
public ActionResult RejectLetterRequest(WFMovementTran otran)
{
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
otran.FromEmployeeID = (int)currentUser.EmployeeID;
try
{
_letterRequestService.RejectLetterRequest(otran);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(true);
}
[HttpPost]
[Route("get-pdf-file")]
public async Task<IActionResult> GetPDFFile(dynamic data)
{
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
string contentType = "";
HttpResponseMessage response = null;
string aupPath = null;
PayrollType payrollType = null;
try
{
if (data != null)
{
var tempdata = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data));
LetterRequest item = new LetterRequest();
item = (LetterRequest)tempdata["dataItem"].ToObject<LetterRequest>();
Employee emp = new Employee();
emp = _employeeService.Get(item.EmployeeId);
Employee lineManager = null;
emp.Department = new Department();
emp.Designation = new Designation();
emp.Category = new Category();
emp.Grade = new Grade();
AuthorizedPerson aup = null;
List<Country> countries = new List<Country>();
countries = _countryService.Get();
if (emp.DepartmentID != null && emp.DepartmentID > 0)
{
emp.Department = _departmentService.Get((int)emp.DepartmentID);
}
if (emp.DesignationID != null && emp.DesignationID > 0)
{
emp.Designation = _designationService.Get((int)emp.DesignationID);
}
if (emp.CategoryID > 0)
{
emp.Category = _categoryService.Get(emp.CategoryID);
}
if (emp.GradeID != null && emp.GradeID > 0)
{
emp.Grade = _gradeService.Get((int)emp.GradeID);
}
if (item.CountryId != null && item.CountryId > 0)
{
item.CountryToVisit = countries.Where(x => x.ID == item.CountryId).FirstOrDefault().Name;
}
if (item.OrganizationId != null && item.OrganizationId > 0)
{
var org = new Organization();
org = _organizationService.Get((int)item.OrganizationId);
if (org != null)
{
item.Organization = org.Name;
if (string.IsNullOrEmpty(item.RecipeintDesignation))
{
item.RecipeintDesignation = org.RecipeintDesignation == null ? "" : org.RecipeintDesignation;
}
}
}
if (item.Purpose == EnumLetterRequestPurpose.Registration_Letter_With_Notice_Period)
{
if (emp.LineManagerID != null && emp.LineManagerID > 0)
{
lineManager = new Employee();
var department = new Department();
var designation = new Designation();
lineManager = _employeeService.Get((int)emp.LineManagerID);
emp.LineManager = lineManager != null ? lineManager.Name : string.Empty;
if (lineManager.DepartmentID != null && lineManager.DepartmentID > 0)
{
department = _departmentService.Get((int)lineManager.DepartmentID);
if (department != null)
emp.LineManagerDept = department.Name;
}
if (lineManager.DesignationID != null && lineManager.DesignationID > 0)
{
designation = _designationService.Get((int)lineManager.DesignationID);
if (department != null)
emp.LineManagerDeg = designation.Name;
}
emp.LMGender = lineManager.Gender;
emp.LineManagerEmail = lineManager.EmailAddress;
}
}
if (item.Purpose == EnumLetterRequestPurpose.Salary_Certificate)
{
if(emp.ForeignExPat== true)
{
item.Currency = "EUR";
}
else
{
item.Currency = "BDT";
}
//List<EmpLifeCycle> empLifeCycleList = _empLifeCycleService.GetEmpID(emp.ID);
//if (empLifeCycleList != null && empLifeCycleList.Count > 0)
//{
// var empLifeCycle = empLifeCycleList.Where(x => x.EffectDate <= DateTime.Now)?.ToList()?.FirstOrDefault();
// if (empLifeCycle != null)
// {
// if (empLifeCycle.GrossSalary != null)
// item.GrossSalary = (double)empLifeCycle.GrossSalary;
// else
// item.GrossSalary = 0;
// }
//}
//current gross salary
var empGradeSalary = _empGradeSalaryService.GetBasicOnDateBAT(emp.ID,DateTime.Now);
if (empGradeSalary != null)
{
double PFContribution = 0;
item.GrossSalary = empGradeSalary.GrossSalary;
if (!emp.ForeignExPat)
{
PFContribution = Math.Round((empGradeSalary.GrossSalary * 10) / 100, 2);// 10% of gross monthly (PF Contribution)
}
item.PFContribution = PFContribution;
}
payrollType = this._payrollTypeService.Get((int)currentUser.PayrollTypeID);
DataSet oPFLoan = _salaryMonthlyService.GetPFForLetterRequest(emp.ID);
foreach (DataRow odRow in oPFLoan.Tables[0].Rows)
{
string temp= odRow["Description"].ToString().Replace(" ", "").ToLower();
if (temp == "pfloan")
{
double dbl = Convert.ToDouble(odRow["CHANGEDAMOUNT"].ToString());
item.PFLoanDeduction = dbl;
}
}
}
if (item.SignatoryId != null && item.SignatoryId > 0)
{
aup = new AuthorizedPerson();
aup = _authorizedPersonService.Get((int)item.SignatoryId);
item.SignatoryName = aup.Name;
item.SignatoryFileName = aup.FileName;
item.SignatoryDeg = aup.Designation;
item.SignatoryEmail = aup.Email;
item.SignatoryExt = aup.Extension;
item.SignatoryPhone = aup.Phone;
if (item.IsDisgitalSinature != null && item.IsDisgitalSinature == true)
{
Stream memoryImage = new MemoryStream();
byte[] bytes = new byte[16 * 1024];
if (aup.FileName != null)
{
aupPath = System.IO.Path.Combine(System.Environment.CurrentDirectory, _letterRequestSignatureSealPath, aup.FileName);
System.IO.File.WriteAllBytes(aupPath, aup.Signature);
}
}
}
_templateBuilder = new BusinessTemplateBuilder();
_templateBuilder.templateDesktopBasePath = System.IO.Path.Combine(System.Environment.CurrentDirectory, _letterRequestfilePath);
string letterTemplateSignaturePath = System.IO.Path.Combine(System.Environment.CurrentDirectory, _letterRequestSignaturePath);//image path
_templateBuilder.logoPath = System.IO.Path.Combine(System.Environment.CurrentDirectory, _logoPath);
DataSet dsSalary = new DataSet();
// dsSalary = _salaryMonthlyService.GetGrossDeduction(emp.ID, (DateTime)currentUser.NextPayProcessDate);
string filePathAndName = _templateBuilder.CreateLetter(item, emp, _letterfileGeneratedPath, _letterRequestTemplatePath, letterTemplateSignaturePath, ".PDF", dsSalary);
string filePath = string.Empty;
string fileName = Path.GetFileNameWithoutExtension(filePathAndName);
filePath = filePathAndName;
Stream memory = new MemoryStream();
byte[] buffer = new byte[16 * 1024];
contentType = GetFileType(filePath);
buffer = System.IO.File.ReadAllBytes(filePath);
var name = fileName;
if (System.IO.File.Exists(filePath))
{
System.IO.File.Delete(filePath);
}
//if(aupPath != null)
//{
// if (System.IO.File.Exists(aupPath))
// {
// System.IO.File.Delete(aupPath);
// }
//}
return File(buffer, contentType, name);
}
else
{
throw new Exception("No Data found");
}
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
}
[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";
}
[HttpPost]
[Route("saveAuthorizedPerson")]
public ActionResult SaveAuthorizedPerson(AuthorizedPerson ob)
{
try
{
string connectionString = _config.GetSection("dbSettings").GetSection("SqlCommandConnection").Value;
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
ob.CreatedBy = currentUser.UserID;
ob.CreatedDate = DateTime.Today;
ob.ModifiedBy = currentUser.UserID;
ob.ModifiedDate = DateTime.Today;
ob.ConnectionString = connectionString;
if (ob.SignatureFileTobase64 != null)
{
string[] items = ob.SignatureFileTobase64.Split(new char[] { ',', ' ' }, StringSplitOptions.None);
byte[] newBytes = Convert.FromBase64String(items[1]);
ob.Signature = newBytes;
}
_authorizedPersonService.Save(ob);
}
catch (Exception e)
{
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
}
return Ok();
}
[Route("getAllAuthorizedPersons")]
public ActionResult GetAllAuthorizedPersons()
{
List<AuthorizedPerson> oCVs = new List<AuthorizedPerson>();
try
{
oCVs = _authorizedPersonService.Get();
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(oCVs);
}
[HttpPost]
[Route("deleteAuthorizedPerson")]
public ActionResult DeleteAuthorizedPerson(AuthorizedPerson item)
{
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
try
{
_authorizedPersonService.Delete(item.ID);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(true);
}
[Route("getImage/{authPersonId}")]
public ActionResult getImage(int authPersonId)
{
object fileData = null;
try
{
DataTable dtImage = new AuthorizedPersonService().GetImage(authPersonId);
if (dtImage != null && dtImage.Rows.Count > 0)
{
DataRow dRow = (DataRow)dtImage.Rows[0];
byte[] SignatureData = (byte[])dRow["SignatureData"];
fileData = Convert.ToBase64String(SignatureData);
}
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(fileData);
}
}
}