1259 lines
46 KiB
C#
1259 lines
46 KiB
C#
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using HRM.BO;
|
|
using System.Data;
|
|
using HRM.BO.Configuration;
|
|
using Microsoft.Extensions.Options;
|
|
using HRM.Report;
|
|
using System.IO;
|
|
using System.Net.Mail;
|
|
using HRM.DA;
|
|
|
|
namespace HRM.UI.Controllers.Payroll
|
|
{
|
|
[Route("api/salary")]
|
|
[ApiController]
|
|
public class SalaryController : ControllerBase
|
|
{
|
|
private readonly ISalaryMonthlyService _salaryMonthlyService;
|
|
private readonly ISalaryProcessService _salaryProcessService;
|
|
private readonly IEmployeeService _employeeService;
|
|
private readonly IEmployeeGradeSalaryService _empGradeSalaries;
|
|
private readonly IOptions<EmailSettings> _emailSettings;
|
|
private readonly IPayrollComponentListService _payrollComponentListService;
|
|
public SalaryController(ISalaryMonthlyService salaryMonthlyService,
|
|
ISalaryProcessService salaryProcessService, IPayrollComponentListService payrollComponentListService,
|
|
IEmployeeService empService, IEmployeeGradeSalaryService empGradeSalaries, IOptions<EmailSettings> emailSettings)
|
|
{
|
|
this._salaryMonthlyService = salaryMonthlyService;
|
|
this._salaryProcessService = salaryProcessService;
|
|
this._employeeService = empService;
|
|
this._empGradeSalaries = empGradeSalaries;
|
|
this._emailSettings = emailSettings;
|
|
this._payrollComponentListService = payrollComponentListService;
|
|
}
|
|
|
|
// Salary Monthly
|
|
[HttpGet("getSalaryMonthlyById/{id}")]
|
|
public ActionResult GetSalaryMonthlyById(int id)
|
|
{
|
|
SalaryMonthly salaryMonthly = new SalaryMonthly();
|
|
try
|
|
{
|
|
salaryMonthly = _salaryMonthlyService.Get(id);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
}
|
|
|
|
return Ok(salaryMonthly);
|
|
}
|
|
|
|
[HttpGet("ConstantItemsForSalary")]
|
|
public ActionResult ConstantItemsForSalary()
|
|
{
|
|
List<PayrollComponentList> componenentList = new List<PayrollComponentList>();
|
|
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
|
int payrollTypeId = currentUser.PayrollTypeID.GetValueOrDefault();
|
|
|
|
try
|
|
{
|
|
componenentList = _payrollComponentListService.ConstantItemsForSalary(payrollTypeId);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
}
|
|
|
|
return Ok(componenentList);
|
|
}
|
|
|
|
[HttpGet("getLastPaidSalaryMonth/{empId}")]
|
|
public ActionResult GetLastPaidSalaryMonth(int empId)
|
|
{
|
|
DateTime dt = new DateTime();
|
|
try
|
|
{
|
|
dt = _salaryMonthlyService.GetLastPaidSalaryMonth(empId).GetValueOrDefault();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
}
|
|
|
|
return Ok(dt);
|
|
}
|
|
|
|
[HttpPost]
|
|
[Route("updateSalaryMonthly")]
|
|
public ActionResult UpdateSalaryMonthly(SalaryMonthly salaryMonthly)
|
|
{
|
|
try
|
|
{
|
|
_salaryMonthlyService.Update(salaryMonthly);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
}
|
|
|
|
return Ok();
|
|
}
|
|
|
|
[HttpPost]
|
|
[Route("UpdateDetail")]
|
|
public ActionResult UpdateDetail(List<SalaryMonthlyDetail> salaryMonthlyDetails)
|
|
{
|
|
List<IncomeTax> incomeTaxes = new List<IncomeTax>();
|
|
try
|
|
{
|
|
_salaryMonthlyService.UpdateDetail(salaryMonthlyDetails, incomeTaxes);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
}
|
|
|
|
return Ok();
|
|
}
|
|
|
|
//[HttpPost]
|
|
//[Route("saveSalaryMonthly")]
|
|
//public ActionResult SaveSalaryMonthly(SalaryProcess process)
|
|
//{
|
|
// List<SalaryMonthly> items = new List<SalaryMonthly>();
|
|
// try
|
|
// {
|
|
// _salaryMonthlyService.Save(process, items);
|
|
// }
|
|
// catch (Exception e)
|
|
// {
|
|
// return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
// }
|
|
|
|
// return Ok();
|
|
//}
|
|
|
|
[HttpPost]
|
|
[Route("deleteSalaryMonthly")]
|
|
public ActionResult DeleteSalaryMonthly(int id)
|
|
{
|
|
try
|
|
{
|
|
_salaryMonthlyService.Delete(id);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
}
|
|
|
|
return Ok();
|
|
}
|
|
|
|
[HttpGet("getSumOnRange/{employeeId}/{fromDate}/{toDate}/{groupCode}/{itemCode}/{itemId}")]
|
|
public ActionResult GetSumOnRange(int employeeId, DateTime fromDate, DateTime toDate, EnumSalaryGroup groupCode,
|
|
EnumSalaryItemCode itemCode, int itemId)
|
|
{
|
|
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
|
int payrollTypeId = currentUser.PayrollTypeID.GetValueOrDefault();
|
|
Double result;
|
|
try
|
|
{
|
|
result = _salaryMonthlyService.GetSumOnRange(employeeId, fromDate, toDate, groupCode, itemCode, itemId,
|
|
payrollTypeId);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
}
|
|
|
|
return Ok(result);
|
|
}
|
|
|
|
[HttpGet("getSumOnRangeOnRound/{employeeId}/{fromDate}/{toDate}/{groupCode}/{itemCode}/{itemId}")]
|
|
public ActionResult GetSumOnRangeOnRound(int employeeId, DateTime fromDate, DateTime toDate,
|
|
EnumSalaryGroup groupCode, EnumSalaryItemCode itemCode, int itemId)
|
|
{
|
|
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
|
int payrollTypeId = currentUser.PayrollTypeID.GetValueOrDefault();
|
|
Double result;
|
|
try
|
|
{
|
|
result = _salaryMonthlyService.GetSumOnRangeOnRound(employeeId, fromDate, toDate, groupCode, itemCode,
|
|
itemId, payrollTypeId);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
}
|
|
|
|
return Ok(result);
|
|
}
|
|
|
|
[HttpGet("getSalaryMonthlyByEmpId/{empId}/{dateTime}")]
|
|
public ActionResult GetSalaryMonthlyByEmpId(int empId, DateTime dateTime)
|
|
{
|
|
SalaryMonthly salaryMonthly = new SalaryMonthly();
|
|
try
|
|
{
|
|
salaryMonthly = _salaryMonthlyService.Get(empId, dateTime);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
}
|
|
|
|
return Ok(salaryMonthly);
|
|
}
|
|
|
|
[HttpGet("getSalaryMonthlyList/{empId}/{salaryMonth}")]
|
|
public ActionResult GetSalaryMonthlyList(DateTime salaryMonth)
|
|
{
|
|
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
|
int payrollTypeId = currentUser.PayrollTypeID.GetValueOrDefault();
|
|
List<SalaryMonthly> salaryMonthlyList = new List<SalaryMonthly>();
|
|
try
|
|
{
|
|
salaryMonthlyList = _salaryMonthlyService.Get(salaryMonth, payrollTypeId);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
}
|
|
|
|
return Ok(salaryMonthlyList);
|
|
}
|
|
|
|
[HttpGet("getForJV/{salaryMonth}")]
|
|
public ActionResult GetForJV(DateTime salaryMonth)
|
|
{
|
|
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
|
int payrollTypeId = currentUser.PayrollTypeID.GetValueOrDefault();
|
|
List<SalaryMonthly> salaryMonthlyList = new List<SalaryMonthly>();
|
|
try
|
|
{
|
|
salaryMonthlyList = _salaryMonthlyService.GetForJV(salaryMonth, payrollTypeId);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
}
|
|
|
|
return Ok(salaryMonthlyList);
|
|
}
|
|
|
|
[HttpGet("getSalaryMonthlyListByEmpId/{empId}/{salaryMonth}")]
|
|
public ActionResult GetSalaryMonthlyListByEmpId(string empId, DateTime salaryMonth)
|
|
{
|
|
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
|
int payrollTypeId = currentUser.PayrollTypeID.GetValueOrDefault();
|
|
List<SalaryMonthly> salaryMonthlyList = new List<SalaryMonthly>();
|
|
try
|
|
{
|
|
salaryMonthlyList = _salaryMonthlyService.Get(empId, salaryMonth, payrollTypeId);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
}
|
|
|
|
return Ok(salaryMonthlyList);
|
|
}
|
|
|
|
[HttpGet("getForWTP/{empId}/{salaryMonth}")]
|
|
public ActionResult GetForWTP(string empId, DateTime salaryMonth)
|
|
{
|
|
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
|
int payrollTypeId = currentUser.PayrollTypeID.GetValueOrDefault();
|
|
List<SalaryMonthly> salaryMonthlyList = new List<SalaryMonthly>();
|
|
try
|
|
{
|
|
salaryMonthlyList = _salaryMonthlyService.GetForWTP(empId, salaryMonth, payrollTypeId);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
}
|
|
|
|
return Ok(salaryMonthlyList);
|
|
}
|
|
|
|
[HttpGet("getForCC/{salaryMonthId}")]
|
|
public ActionResult GetForCC(int salaryMonthId)
|
|
{
|
|
List<SalaryEmpCostCenter> salaryEmpCostCenters = new List<SalaryEmpCostCenter>();
|
|
try
|
|
{
|
|
salaryEmpCostCenters = _salaryMonthlyService.GetForCC(salaryMonthId);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
}
|
|
|
|
return Ok(salaryEmpCostCenters);
|
|
}
|
|
|
|
[HttpGet("getCostCenterList/{salaryMonth}")]
|
|
public ActionResult GetCostCenterList(DateTime salaryMonth)
|
|
{
|
|
List<SalaryEmpCostCenter> salaryEmpCostCenters = new List<SalaryEmpCostCenter>();
|
|
try
|
|
{
|
|
salaryEmpCostCenters = _salaryMonthlyService.GetCostCenter(salaryMonth);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
}
|
|
|
|
return Ok(salaryEmpCostCenters);
|
|
}
|
|
|
|
[HttpGet("getUnAuthorizeAmountOnDateRange/{employeeId}/{fromDate}/{toDate}/{groupCode}")]
|
|
public ActionResult GetUnAuthorizeAmountOnDateRange(int employeeId, DateTime fromDate, DateTime toDate,
|
|
EnumSalaryGroup groupCode)
|
|
{
|
|
Double result;
|
|
try
|
|
{
|
|
result = _salaryMonthlyService.GetUnAuthorizeAmountOnDateRange(employeeId, fromDate, toDate, groupCode);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
}
|
|
|
|
return Ok(result);
|
|
}
|
|
|
|
[HttpGet("isSalaryProcessed/{employeeId}/{salaryMonth}")]
|
|
public ActionResult IsSalaryProcessed(int employeeId, DateTime salaryMonth)
|
|
{
|
|
bool ans;
|
|
try
|
|
{
|
|
ans = _salaryMonthlyService.IsSalaryProcessed(employeeId, salaryMonth);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
}
|
|
|
|
return Ok(ans);
|
|
}
|
|
|
|
[HttpGet("isSalaryProcessedWeb/{salaryMonth}")]
|
|
public ActionResult IsSalaryProcessedWeb(DateTime salaryMonth)
|
|
{
|
|
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
|
int payrollTypeId = currentUser.PayrollTypeID.GetValueOrDefault();
|
|
bool ans;
|
|
try
|
|
{
|
|
ans = _salaryMonthlyService.IsSalaryProcessedWeb(salaryMonth, payrollTypeId);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
}
|
|
|
|
return Ok(ans);
|
|
}
|
|
|
|
[HttpGet("isPermanentEmp/{employeeId}/{salaryMonth}")]
|
|
public ActionResult IsPermanentEmp(int employeeId, DateTime salaryMonth)
|
|
{
|
|
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
|
int payrollTypeId = currentUser.PayrollTypeID.GetValueOrDefault();
|
|
bool ans;
|
|
try
|
|
{
|
|
ans = _salaryMonthlyService.IsPermanentEmp(employeeId, salaryMonth, payrollTypeId);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
}
|
|
|
|
return Ok(ans);
|
|
}
|
|
|
|
[HttpGet("isSalaryProcessedAndFinalized/{employeeId}/{salaryMonth}/{isProcessed}/{isFinalized}")]
|
|
public ActionResult IsSalaryProcessedAndFinalized(int employeeId, DateTime salaryMonth, bool isProcessed,
|
|
bool isFinalized)
|
|
{
|
|
try
|
|
{
|
|
_salaryMonthlyService.IsSalaryProcessedAndFinalized(employeeId, salaryMonth, ref isProcessed,
|
|
ref isFinalized);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
}
|
|
|
|
return Ok();
|
|
}
|
|
|
|
[HttpGet("getUnAuthorizeDays/{employeeId}/{salaryMonth}")]
|
|
public ActionResult GetUnAuthorizeDays(int employeeId, DateTime salaryMonth)
|
|
{
|
|
int ans;
|
|
try
|
|
{
|
|
ans = _salaryMonthlyService.GetUnAuthorizeDays(employeeId, salaryMonth);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
}
|
|
|
|
return Ok(ans);
|
|
}
|
|
|
|
[HttpGet("getSalaryDetailList/{salaryMonthlyId}")]
|
|
public ActionResult GetSalaryDetailList(int salaryMonthlyId)
|
|
{
|
|
List<SalaryMonthlyDetail> salaryMonthlyDetails = new List<SalaryMonthlyDetail>();
|
|
try
|
|
{
|
|
salaryMonthlyDetails = _salaryMonthlyService.GetSalaryDetail(salaryMonthlyId);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
}
|
|
|
|
return Ok(salaryMonthlyDetails);
|
|
}
|
|
|
|
[HttpGet("getSalaryDetailListBySalaryMonthlyIds/{salaryMonthlyIds}")]
|
|
public ActionResult GetSalaryDetailListBySalaryMonthlyIds(string salaryMonthlyIds)
|
|
{
|
|
List<SalaryMonthlyDetail> salaryMonthlyDetails = new List<SalaryMonthlyDetail>();
|
|
try
|
|
{
|
|
salaryMonthlyDetails = _salaryMonthlyService.GetSalaryDetail(salaryMonthlyIds);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
}
|
|
|
|
return Ok(salaryMonthlyDetails);
|
|
}
|
|
|
|
[HttpGet("getTotalEmp/{salaryProcessId}")]
|
|
public ActionResult GetTotalEmp(int salaryProcessId)
|
|
{
|
|
int ans;
|
|
try
|
|
{
|
|
ans = _salaryMonthlyService.GetTotalEmp(salaryProcessId);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
}
|
|
|
|
return Ok(ans);
|
|
}
|
|
|
|
[HttpGet("getAmountOnDateDiff/{employeeId}/{fromDate}/{toDate}/{groupCode}/{itemCode}/{itemId}")]
|
|
public ActionResult GetAmountOnDateDiff(int employeeId, DateTime fromDate, DateTime toDate,
|
|
EnumSalaryGroup groupCode, EnumSalaryItemCode itemCode, int itemId)
|
|
{
|
|
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
|
int payrollTypeId = currentUser.PayrollTypeID.GetValueOrDefault();
|
|
Double result;
|
|
try
|
|
{
|
|
result = _salaryMonthlyService.GetAmountOnDateDiff(employeeId, fromDate, toDate, groupCode, itemCode,
|
|
itemId, payrollTypeId);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
}
|
|
|
|
return Ok(result);
|
|
}
|
|
|
|
[HttpGet("getThisMonthBasicOnDateDiff/{employeeId}/{fromDate}/{toDate}/{groupCode}/{itemCode}/{itemId}")]
|
|
public ActionResult GetThisMonthBasicOnDateDiff(int employeeId, DateTime fromDate, DateTime toDate,
|
|
EnumSalaryGroup groupCode, EnumSalaryItemCode itemCode, int itemId)
|
|
{
|
|
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
|
int payrollTypeId = currentUser.PayrollTypeID.GetValueOrDefault();
|
|
Double result;
|
|
try
|
|
{
|
|
result = _salaryMonthlyService.GetThisMonthBasicOnDateDiff(employeeId, fromDate, toDate, groupCode,
|
|
itemCode, itemId, payrollTypeId);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
}
|
|
|
|
return Ok(result);
|
|
}
|
|
|
|
[HttpGet("getAmountOnDateDiffForOverTime/{employeeId}/{fromDate}/{toDate}/{groupCode}/{itemCode}/{itemId}")]
|
|
public ActionResult GetAmountOnDateDiffForOverTime(int employeeId, DateTime fromDate, DateTime toDate,
|
|
EnumSalaryGroup groupCode, EnumSalaryItemCode itemCode, int itemId)
|
|
{
|
|
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
|
int payrollTypeId = currentUser.PayrollTypeID.GetValueOrDefault();
|
|
Double result;
|
|
try
|
|
{
|
|
result = _salaryMonthlyService.GetAmountOnDateDiffForOverTime(employeeId, fromDate, toDate, groupCode,
|
|
itemCode, itemId, payrollTypeId);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
}
|
|
|
|
return Ok(result);
|
|
}
|
|
|
|
[HttpGet("getAmountOnDateDiffForAll/{employeeId}/{fromDate}/{toDate}")]
|
|
public ActionResult GetAmountOnDateDiffForAll(int employeeId, DateTime fromDate, DateTime toDate)
|
|
{
|
|
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
|
int payrollTypeId = currentUser.PayrollTypeID.GetValueOrDefault();
|
|
Double result;
|
|
try
|
|
{
|
|
result = _salaryMonthlyService.GetAmountOnDateDiffForAll(employeeId, fromDate, toDate, payrollTypeId);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
}
|
|
|
|
return Ok(result);
|
|
}
|
|
|
|
[HttpGet("getPrvTaxAmount/{dataForm}/{employeeId}/{fromDate}/{toDate}")]
|
|
public ActionResult GetPrvTaxAmount(EnumIncomeTaxDataFrom dataFrom, int employeeId, DateTime fromDate,
|
|
DateTime toDate)
|
|
{
|
|
Double result;
|
|
try
|
|
{
|
|
result = _salaryMonthlyService.GetPrvTaxAmount(dataFrom, employeeId, fromDate, toDate);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
}
|
|
|
|
return Ok(result);
|
|
}
|
|
|
|
[HttpGet("getByDateRange/{startDate}/{endDate}")]
|
|
public ActionResult GetByDateRange(DateTime startDate, DateTime endDate)
|
|
{
|
|
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
|
int payrollTypeId = currentUser.PayrollTypeID.GetValueOrDefault();
|
|
List<SalaryMonthly> salaryMonthlies = new List<SalaryMonthly>();
|
|
try
|
|
{
|
|
salaryMonthlies = _salaryMonthlyService.GetByDateRange(startDate, endDate, payrollTypeId);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
}
|
|
|
|
return Ok(salaryMonthlies);
|
|
}
|
|
|
|
[HttpGet("getByDateRangeByEmpId/{empId}/{startDate}/{endDate}")]
|
|
public ActionResult GetByDateRangeByEmpId(int empId, DateTime startDate, DateTime endDate)
|
|
{
|
|
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
|
int payrollTypeId = currentUser.PayrollTypeID.GetValueOrDefault();
|
|
List<SalaryMonthly> salaryMonthlies = new List<SalaryMonthly>();
|
|
try
|
|
{
|
|
salaryMonthlies = _salaryMonthlyService.GetByDateRange(empId, startDate, endDate, payrollTypeId);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
}
|
|
|
|
return Ok(salaryMonthlies);
|
|
}
|
|
|
|
[HttpGet("getHead/{index}/{salaryMonth}")]
|
|
public ActionResult GetHead(int index, DateTime salaryMonth)
|
|
{
|
|
List<SalaryMonthlyDetail> salaryMonthlyDetails = new List<SalaryMonthlyDetail>();
|
|
try
|
|
{
|
|
salaryMonthlyDetails = _salaryMonthlyService.GetHead(index, salaryMonth);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
}
|
|
|
|
return Ok(salaryMonthlyDetails);
|
|
}
|
|
|
|
[HttpGet("getSalaryMonthlyByDateRange/{empId}/{fromDate}/{toDate}")]
|
|
public ActionResult GetSalaryMonthlyByDateRange(string empId, DateTime fromDate, DateTime toDate)
|
|
{
|
|
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
|
int payrollTypeId = currentUser.PayrollTypeID.GetValueOrDefault();
|
|
List<SalaryMonthly> salaryMonthlies = new List<SalaryMonthly>();
|
|
try
|
|
{
|
|
salaryMonthlies = _salaryMonthlyService.Get(empId, fromDate, toDate, payrollTypeId);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
}
|
|
|
|
return Ok(salaryMonthlies);
|
|
}
|
|
|
|
[HttpGet("getByProcessID/{processId}")]
|
|
public ActionResult GetByProcessID(int processId)
|
|
{
|
|
List<SalaryMonthly> salaryMonthlies = new List<SalaryMonthly>();
|
|
try
|
|
{
|
|
salaryMonthlies = _salaryMonthlyService.GetByProcessID(processId);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
}
|
|
|
|
return Ok(salaryMonthlies);
|
|
}
|
|
|
|
[HttpGet("isSalaryProcessedAndFinalizedByDateRange/{dateTime}/{isProcessed}/{isFinalized}")]
|
|
public ActionResult IsSalaryProcessedAndFinalizedByDateRange(DateTime dateTime, bool isProcessed,
|
|
bool isFinalized)
|
|
{
|
|
try
|
|
{
|
|
_salaryMonthlyService.IsSalaryProcessedAndFinalized(dateTime, ref isProcessed, ref isFinalized);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
}
|
|
|
|
return Ok();
|
|
}
|
|
|
|
[HttpGet("GetUnApprovedSalaries")]
|
|
public ActionResult GetUnApprovedSalaries()
|
|
{
|
|
List<SalaryProcess> salaryProcess = new List<SalaryProcess>();
|
|
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
|
try
|
|
{
|
|
salaryProcess = _salaryProcessService.GetUnApprovedSalaries((DateTime)currentUser.NextPayProcessDate, (int)currentUser.PayrollTypeID);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
}
|
|
|
|
return Ok(salaryProcess);
|
|
}
|
|
|
|
|
|
|
|
[HttpPost("Updatepayment")]
|
|
public ActionResult Updatepayment(dynamic data)//Hello World Chapal Bhai
|
|
{
|
|
var items = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data));
|
|
DateTime paymentDate = DateTime.Today;
|
|
if (items["paymentDate"] != null)
|
|
paymentDate = (DateTime)items["paymentDate"].ToObject<DateTime>();
|
|
int salarymonthlyid = items["salarymonthlyid"].ToObject<int>();
|
|
string chequeNo = items["chequeno"].ToObject<string>();
|
|
string remarks = items["remarks"].ToObject<string>();
|
|
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
|
//DataTable olist = null;
|
|
|
|
try
|
|
{
|
|
_salaryMonthlyService.Updatepayment(paymentDate, salarymonthlyid, chequeNo, remarks, currentUser.UserID);
|
|
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
}
|
|
|
|
return Ok();
|
|
}
|
|
[HttpPost("GetWithheldData")]
|
|
public ActionResult GetWithheldData(dynamic data)
|
|
{
|
|
var items = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data));
|
|
DateTime salarymonth = DateTime.Today;
|
|
if (items["salaryMonth"] != null)
|
|
salarymonth = (DateTime)items["salaryMonth"].ToObject<DateTime>();
|
|
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
|
DataTable olist = null;
|
|
|
|
try
|
|
{
|
|
olist = _salaryMonthlyService.GetWithheldData(GlobalFunctions.LastDateOfMonth(salarymonth), (int)currentUser.PayrollTypeID);
|
|
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
}
|
|
|
|
return Ok(olist);
|
|
}
|
|
|
|
|
|
// SalaryProcess
|
|
//[HttpGet("getSalaryProcessById/{id}")]
|
|
//public ActionResult GetSalaryProcessById(int id)
|
|
//{
|
|
// SalaryProcess salaryProcess = new SalaryProcess();
|
|
// try
|
|
// {
|
|
// salaryProcess = _salaryProcessService.Get(id);
|
|
// }
|
|
// catch (Exception e)
|
|
// {
|
|
// return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
// }
|
|
|
|
// return Ok(salaryProcess);
|
|
//}
|
|
|
|
//[HttpGet("getSalaryProcessWithPayrollType")]
|
|
//public ActionResult GetSalaryProcessWithPayrollType()
|
|
//{
|
|
// CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
|
// int payrollTypeId = currentUser.PayrollTypeID.GetValueOrDefault();
|
|
// List<SalaryProcess> salaryProcesses = new List<SalaryProcess>();
|
|
// try
|
|
// {
|
|
// salaryProcesses = _salaryProcessService.GetWithPayrollType(payrollTypeId);
|
|
// }
|
|
// catch (Exception e)
|
|
// {
|
|
// return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
// }
|
|
|
|
// return Ok(salaryProcesses);
|
|
//}
|
|
|
|
//[HttpGet("getAllSalaryProcess")]
|
|
//public ActionResult GetAllSalaryProcess()
|
|
//{
|
|
// List<SalaryProcess> salaryProcesses = new List<SalaryProcess>();
|
|
// try
|
|
// {
|
|
// salaryProcesses = _salaryProcessService.GetSP();
|
|
// }
|
|
// catch (Exception e)
|
|
// {
|
|
// return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
// }
|
|
|
|
// return Ok(salaryProcesses);
|
|
//}
|
|
|
|
[HttpGet("getSalaryProcessBySMonth/{month}")]
|
|
public ActionResult GetSalaryProcessBySMonth(DateTime month)
|
|
{
|
|
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
|
int payrollTypeId = currentUser.PayrollTypeID.GetValueOrDefault();
|
|
bool ans;
|
|
try
|
|
{
|
|
ans = _salaryProcessService.GetBySMonth(month, payrollTypeId);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
}
|
|
|
|
return Ok(ans);
|
|
}
|
|
|
|
[HttpPost]
|
|
[Route("saveSalaryProcess")]
|
|
public ActionResult SaveSalaryProcess(SalaryProcess process)
|
|
{
|
|
try
|
|
{
|
|
_salaryProcessService.Save(process);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
}
|
|
|
|
return Ok();
|
|
}
|
|
|
|
[HttpPost]
|
|
[Route("ApproveSalary")]
|
|
public ActionResult ApproveSalary(dynamic processItems)
|
|
{
|
|
// string remarks = (string)processItems["remarks"].ToObject<string>();
|
|
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
|
try
|
|
{
|
|
_salaryProcessService.ApproveSalary((DateTime)currentUser.NextPayProcessDate, (int)currentUser.PayrollTypeID);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
}
|
|
|
|
return Ok(true);
|
|
}
|
|
|
|
|
|
[HttpPost]
|
|
[Route("deleteSalaryProcessById")]
|
|
public ActionResult DeleteSalaryProcessById(int id)
|
|
{
|
|
try
|
|
{
|
|
_salaryProcessService.Delete(id);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
}
|
|
|
|
return Ok();
|
|
}
|
|
|
|
[HttpPost]
|
|
[Route("SalaryProcess")]
|
|
public ActionResult SalaryProcess(dynamic processItems)
|
|
{
|
|
SalaryProcess oporcess = new SalaryProcess();
|
|
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
|
|
|
var items = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(processItems));
|
|
int index = 0;
|
|
//List<Employee> employees = this._employeeService.GetByEmpIDs
|
|
List<SearchEmployee> searhemp = new List<SearchEmployee>();
|
|
string empid = "";
|
|
foreach (var item in items)
|
|
{
|
|
if (index == 0)
|
|
{
|
|
oporcess.PayrollTypeID = (int)currentUser.PayrollTypeID;
|
|
oporcess.CreatedBy = currentUser.UserID;
|
|
oporcess.CreatedDate = DateTime.Today;
|
|
oporcess.SalaryMonth = (DateTime)currentUser.NextPayProcessDate;
|
|
if (item["euroRate"] != null)
|
|
{
|
|
oporcess.EuroRate = (double)item["euroRate"].ToObject<double>();
|
|
}
|
|
if (item["remarks"] != null)
|
|
oporcess.Remarks = (string)item["remarks"].ToObject<string>();
|
|
oporcess.PaymentDate = (DateTime)item["paymentDate"].ToObject<DateTime>();
|
|
oporcess.ProcessCode = oporcess.SalaryMonth.ToString("ddmmyy") + DateTime.Today.ToString("hh:mm");
|
|
oporcess.ProcessDate = DateTime.Today;
|
|
}
|
|
empid = empid + (string)item["empid"].ToObject<string>() + ",";
|
|
}
|
|
if (empid.Length > 0)
|
|
{
|
|
empid = empid.Substring(0, empid.Length - 1);
|
|
}
|
|
List<SalaryProcessStatus> errorOrSucess = new List<SalaryProcessStatus>();
|
|
try
|
|
{
|
|
List<Employee> employees = this._employeeService.GetByEmpIDs(empid, (int)currentUser.PayrollTypeID);
|
|
|
|
|
|
errorOrSucess = _salaryProcessService.SalaryProcess(oporcess, employees);
|
|
if (errorOrSucess.Count == 0) errorOrSucess = null;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
}
|
|
|
|
return Ok(errorOrSucess);
|
|
}
|
|
|
|
|
|
[HttpPost]
|
|
[Route("undoSalaryProcessById")]
|
|
public ActionResult UndoSalaryProcessById(SalaryProcess item)
|
|
{
|
|
try
|
|
{
|
|
_salaryProcessService.UndoSalary(item.ID);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
}
|
|
|
|
return Ok();
|
|
}
|
|
|
|
|
|
|
|
[HttpPost]
|
|
[Route("undoMonthlySalaryProcessByEmpId")]
|
|
public ActionResult UndoMonthlySalaryProcessByEmpId(List<SearchEmployee> emps)
|
|
{
|
|
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
|
|
|
try
|
|
{
|
|
_salaryProcessService.UndoMonthlySalaryByEmpIDs(SearchEmployee.getEmpID(emps), (DateTime)currentUser.NextPayProcessDate);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
}
|
|
|
|
return Ok();
|
|
}
|
|
|
|
[HttpPost]
|
|
[Route("updateSalaryProcess")]
|
|
public ActionResult UpdateSalaryProcess(SalaryProcess process)
|
|
{
|
|
try
|
|
{
|
|
_salaryProcessService.Update(process);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
}
|
|
|
|
return Ok();
|
|
}
|
|
|
|
[HttpPost]
|
|
[Route("salaryProcessApprove")]
|
|
public ActionResult SalaryProcessApprove(SalaryProcess process)
|
|
{
|
|
try
|
|
{
|
|
_salaryProcessService.SPApprove(process);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
}
|
|
|
|
return Ok();
|
|
}
|
|
|
|
[HttpPost("salaryValidation")]
|
|
public ActionResult salaryValidation(List<SearchEmployee> emps)
|
|
{
|
|
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
|
int payrollTypeId = currentUser.PayrollTypeID.GetValueOrDefault();
|
|
List<SalaryProcess> salaryProcesses = new List<SalaryProcess>();
|
|
List<SalaryProcessStatus> errorList = new List<SalaryProcessStatus>();
|
|
try
|
|
{
|
|
DataSet GradeSalary = this._empGradeSalaries.GetmultipleTilldatedemp(payrollTypeId);
|
|
if (GradeSalary.Tables[0].Rows.Count > 0)
|
|
{
|
|
string smsg = string.Empty;
|
|
int nCount = 0;
|
|
foreach (DataRow oRow in GradeSalary.Tables[0].Rows)
|
|
{
|
|
nCount = nCount + 1;
|
|
var emp = emps.FirstOrDefault(x => x.EmployeeID == Convert.ToInt32(oRow["EmployeeId"]));
|
|
if (emp != null)
|
|
{
|
|
errorList.Add(new SalaryProcessStatus(emp.EmployeeNo, emp.Name,
|
|
"Salary Entry Error, please see the Life-cycle-salary information"));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
}
|
|
if (errorList.Count == 0) errorList = null;
|
|
return Ok(errorList);
|
|
}
|
|
|
|
|
|
[HttpGet("getSalaryProcessByMonthAndPayrollTypeId/{month}")]
|
|
public ActionResult GetSalaryProcessByMonthAndPayrollTypeId(DateTime month)
|
|
{
|
|
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
|
int payrollTypeId = currentUser.PayrollTypeID.GetValueOrDefault();
|
|
List<SalaryProcess> salaryProcesses = new List<SalaryProcess>();
|
|
try
|
|
{
|
|
salaryProcesses = _salaryProcessService.Get(month, payrollTypeId);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
}
|
|
|
|
return Ok(salaryProcesses);
|
|
}
|
|
|
|
[HttpPost]
|
|
[Route("salaryProcessMonthEnd")]
|
|
public ActionResult SalaryProcessMonthEnd(dynamic MonthEnddata)
|
|
{
|
|
//var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data));
|
|
//int userid = (int)item["userid"].ToObject<int>();
|
|
|
|
var items = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(MonthEnddata));
|
|
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
|
DateTime paymentDate = DateTime.Today; //(DateTime)items[0].ToObject<DateTime>();
|
|
|
|
try
|
|
{
|
|
_salaryProcessService.MonthEnd(currentUser.UserID, (DateTime)currentUser.NextPayProcessDate, (int)currentUser.PayrollTypeID, paymentDate);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
}
|
|
|
|
return Ok();
|
|
}
|
|
|
|
[HttpGet("getAllSalaryProcessByNextPayProcessDate/{nextPayProcessDate}")]
|
|
public ActionResult GetAllSalaryProcessByNextPayProcessDate(DateTime nextPayProcessDate)
|
|
{
|
|
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
|
int payrollTypeId = currentUser.PayrollTypeID.GetValueOrDefault();
|
|
List<SalaryProcess> salaryProcesses = new List<SalaryProcess>();
|
|
try
|
|
{
|
|
salaryProcesses = _salaryProcessService.GetAllProcess(payrollTypeId, nextPayProcessDate);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
}
|
|
|
|
return Ok(salaryProcesses);
|
|
}
|
|
|
|
[HttpGet("GetNetAmountofCurrentMonth")]
|
|
public ActionResult GetNetAmountofCurrentMonth()
|
|
{
|
|
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
|
DataTable ot = new DataTable();
|
|
try
|
|
{
|
|
ot = this._salaryMonthlyService.GetNetAmount((DateTime)currentUser.NextPayProcessDate, (int)currentUser.PayrollTypeID);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
}
|
|
|
|
return Ok(ot);
|
|
}
|
|
|
|
[HttpPost]
|
|
[Route("sendEmailForMultiple")]
|
|
public ActionResult SendEmailForMultiple(dynamic data)
|
|
{
|
|
EmailSettings emailSettings = _emailSettings.Value;
|
|
var employees = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data.list));
|
|
var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data));
|
|
string subject = (string)item["emailSubject"].ToObject<string>();
|
|
string body = (string)item["emailBody"].ToObject<string>();
|
|
try
|
|
{
|
|
foreach (var employee in employees)
|
|
{
|
|
MailSender mailSender = new MailSender();
|
|
mailSender.AddTo(employee.employeeEmail.ToString());
|
|
mailSender.Subject = subject;
|
|
mailSender.Body = "<p>" + body + "</p>";
|
|
mailSender.SendMail(emailSettings);
|
|
System.Threading.Thread.Sleep(500);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
|
|
}
|
|
|
|
return Ok();
|
|
}
|
|
|
|
[HttpPost]
|
|
[Route("sendPayslipForMultiple")]
|
|
public ActionResult sendPayslipForMultiple(dynamic data)
|
|
{
|
|
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
|
byte[] bytes = null;
|
|
HRM.Report.PayrollDataSet.PayrollDataSet.PayslipDataTable tempdata = new HRM.Report.PayrollDataSet.PayrollDataSet.PayslipDataTable();
|
|
DateTime fromDate = DateTime.Today.AddMonths(-1);
|
|
EmailSettings emailSettings = _emailSettings.Value;
|
|
var employees = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data.list));
|
|
var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data));
|
|
string subject = "Payslip Published";//(string)item["emailSubject"].ToObject<string>();
|
|
//string body = (string)item["emailBody"].ToObject<string>();
|
|
string sEmpIDs = (string)item["empIds"].ToObject<string>();
|
|
try
|
|
{
|
|
|
|
bool isForESS = false;
|
|
//if (sEmpIDs.Length == 0)
|
|
//{
|
|
// isForESS = true;
|
|
// sEmpIDs = employeeId.ToString();
|
|
//}
|
|
new PaySlip().PayslipMail((int)currentUser.PayrollTypeID, fromDate, sEmpIDs, isForESS, emailSettings);
|
|
|
|
|
|
//foreach (var employee in employees)
|
|
//{
|
|
//MailSender mailSender = new MailSender();
|
|
//mailSender.AddTo(employee.employeeEmail.ToString());
|
|
//mailSender.Subject = subject;
|
|
//Attachment att = new Attachment(new MemoryStream(bytes), "Payslip.pdf");
|
|
|
|
//mailSender.Body = "<p>" + "" + "</p>";
|
|
//mailSender.SendMail(emailSettings,att);
|
|
//System.Threading.Thread.Sleep(500);
|
|
|
|
// DataTable PayslipDatatemp = PayslipData.AsEnumerable().Where(x => x["EmployeeID"].ToString() == employee.employeeid).CopyToDataTable();
|
|
|
|
//loanDT.TableName = "PayrollDataSet_LoanData";
|
|
//PayslipData.TableName = "PayrollDataSet_Payslip";
|
|
//oFDST.Tables.Add(PayslipData);
|
|
//oFDST.Tables.Add(loanDT);
|
|
//return reportProcessor.GetPayslipReport(null, oFDST, payrollTypeID);
|
|
|
|
//MailSender mailSender = new MailSender();
|
|
//mailSender.AddTo(employee.employeeEmail.ToString());
|
|
//mailSender.Subject = subject;
|
|
//Attachment att = new Attachment(new MemoryStream(bytes), "Payslip.pdf");
|
|
|
|
//mailSender.Body = "<p>" + "" + "</p>";
|
|
//mailSender.SendMail(emailSettings, att);
|
|
//System.Threading.Thread.Sleep(500);
|
|
|
|
//}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
|
|
}
|
|
|
|
return Ok();
|
|
}
|
|
|
|
[HttpGet("getBasicSalaryOfEmployee/{id}")]
|
|
public ActionResult getBasicSalaryOfEmployee(int id)
|
|
{
|
|
string currentBasic;
|
|
try
|
|
{
|
|
currentBasic = new EmployeeService().GetBasicSalary(id);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
}
|
|
|
|
return Ok(currentBasic);
|
|
}
|
|
|
|
[HttpPost]
|
|
[Route("DownloadPayslipForMultiple")]
|
|
public ActionResult DownloadPayslipForMultiple(dynamic data)
|
|
{
|
|
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
|
byte[] bytes = null;
|
|
DateTime fromDate = DateTime.Today.AddMonths(-1);
|
|
var employees = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data.list));
|
|
try
|
|
{
|
|
bool isForESS = false;
|
|
|
|
foreach (var employee in employees)
|
|
{
|
|
//create bytes for pdf
|
|
bytes = new PaySlip().DownloadPayslip((int)currentUser.PayrollTypeID, fromDate, employee.employeeID.ToString(), isForESS);
|
|
//save pdf in folder
|
|
SavePdf(bytes, "Payslip_" + DateTime.Today.Year + "_" + DateTime.Today.Month, employee.employeeNo.ToString());
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
|
|
}
|
|
|
|
return Ok("Success");
|
|
}
|
|
|
|
[HttpPost("upload-pdf")]
|
|
public IActionResult SavePdf(byte[] pdfBytes, string folderName, string employeeNo)
|
|
{
|
|
// Get the user's Desktop folder path
|
|
var desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
|
|
|
|
// Define the folder path on the Desktop
|
|
var folderPath = Path.Combine(desktopPath, folderName);
|
|
|
|
// Check if the folder exists, if not, create it
|
|
if (!Directory.Exists(folderPath))
|
|
{
|
|
Directory.CreateDirectory(folderPath);
|
|
}
|
|
|
|
// Define the file name and path where the PDF will be saved
|
|
//var fileNameFormat = $"Payslip_empno_2024_09.pdf";
|
|
var fileName = "Payslip_" + employeeNo + "_" + DateTime.Today.Year + "_" + DateTime.Today.Month + ".pdf";
|
|
var filePath = Path.Combine(folderPath, fileName);
|
|
|
|
try
|
|
{
|
|
// Save the byte array as a PDF file
|
|
System.IO.File.WriteAllBytes(filePath, pdfBytes);
|
|
|
|
// Return success response
|
|
return Ok(new { message = "PDF saved successfully on Desktop!" });
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
// Handle exceptions and return error message
|
|
return BadRequest(new { message = "Error saving PDF", error = ex.Message });
|
|
}
|
|
}
|
|
}
|
|
|
|
} |