2026-11-03 13:06:00 +06:00
using HRM.BO ;
using HRM.BO.Configuration ;
using HRM.DA ;
using HRM.DA.Service.Tax ;
using HRM.Report ;
//using Microsoft.AspNetCore.Razor.Language.Intermediate;
using Microsoft.AspNetCore.Authorization ;
using Microsoft.AspNetCore.Http ;
using Microsoft.AspNetCore.Mvc ;
using Microsoft.Extensions.Configuration ;
using Microsoft.Extensions.Options ;
using NPOI.SS.Formula.Functions ;
using System ;
using System.Collections.Generic ;
using System.Data ;
using System.IO ;
using System.IO.Compression ;
using System.Linq ;
using System.Text ;
using System.Threading.Tasks ;
using DataSet = System . Data . DataSet ;
using IConfiguration = Microsoft . Extensions . Configuration . IConfiguration ;
namespace HRM.UI.Controllers.Payroll
{
[Route("api/Tax")]
[ApiController]
[Authorize]
public class IncomeTaxController : ControllerBase
{
private readonly IAdvanceIncomeTaxService _advanceIncomeTaxService ;
private readonly IEmployeeTaxInvestmentService _employeeTaxInvestmentService ;
private readonly IIncomeTaxService _incomeTaxService ;
private readonly IITEmpHeadService _itEmpHeadService ;
private readonly IMinTaxExceptionService _minTaxExceptionService ;
private readonly ITaxAdjustmentService _taxAdjustmentService ;
private readonly ITaxChallanService _taxChallanService ;
private readonly ITaxHeadAssignmentService _taxHeadAssignmentService ;
private readonly ITaxInvestmentService _taxInvestmentService ;
private readonly ITaxMergeMasterService _taxMergeMasterService ;
private readonly ITaxParameterService _taxParameterService ;
private readonly ITaxReturnService _taxReturnService ;
private readonly IEmpTaxAitService _empTaxAitService ;
private readonly IPayrollTypeService _payrollTypeService ;
private readonly IConfiguration _config ;
private readonly IOptions < EmailSettings > _emailSettings ;
private readonly IEmployeeService _employeeService ;
private readonly IEmployeeTaxExcecptionService _employeeExceptionService ;
private readonly IEmailDispatchService _emailDispatchService ;
public IncomeTaxController ( IAdvanceIncomeTaxService advanceIncomeTaxService ,
IEmployeeTaxInvestmentService employeeTaxInvestmentService ,
IIncomeTaxService incomeTaxService ,
IITEmpHeadService itEmpHeadService ,
IMinTaxExceptionService minTaxExceptionService ,
ITaxAdjustmentService taxAdjustmentService ,
ITaxChallanService taxChallanService ,
ITaxHeadAssignmentService taxHeadAssignmentService ,
ITaxInvestmentService taxInvestmentService ,
ITaxMergeMasterService taxMergeMasterService ,
ITaxParameterService taxParameterService ,
ITaxReturnService taxReturnService ,
IEmpTaxAitService empTaxAitService ,
IPayrollTypeService payrollTypeService , IConfiguration config , IOptions < EmailSettings > emailSettings , IEmployeeService employeeService , IEmployeeTaxExcecptionService employeeExceptionService ,
IEmailDispatchService emailDispatchService )
{
this . _emailDispatchService = emailDispatchService ;
this . _advanceIncomeTaxService = advanceIncomeTaxService ;
this . _employeeTaxInvestmentService = employeeTaxInvestmentService ;
this . _incomeTaxService = incomeTaxService ;
this . _itEmpHeadService = itEmpHeadService ;
this . _minTaxExceptionService = minTaxExceptionService ;
this . _taxAdjustmentService = taxAdjustmentService ;
this . _taxChallanService = taxChallanService ;
this . _taxHeadAssignmentService = taxHeadAssignmentService ;
this . _taxInvestmentService = taxInvestmentService ;
this . _taxMergeMasterService = taxMergeMasterService ;
this . _taxParameterService = taxParameterService ;
this . _taxReturnService = taxReturnService ;
this . _empTaxAitService = empTaxAitService ;
_payrollTypeService = payrollTypeService ;
this . _config = config ;
this . _emailSettings = emailSettings ;
this . _employeeService = employeeService ;
this . _employeeExceptionService = employeeExceptionService ;
}
[HttpGet("getAdvanceIncomeTaxById/{id}")]
public ActionResult GetAdvanceIncomeTaxById ( int id )
{
AdvanceIncomeTax incomeTax = new AdvanceIncomeTax ( ) ;
try
{
incomeTax = _advanceIncomeTaxService . Get ( id ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( incomeTax ) ;
}
[HttpGet("getAllAdvanceIncomeTax")]
public ActionResult GetAllAdvanceIncomeTax ( )
{
List < AdvanceIncomeTax > incomeTaxs = new List < AdvanceIncomeTax > ( ) ;
try
{
incomeTaxs = _advanceIncomeTaxService . Get ( ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( incomeTaxs ) ;
}
[HttpPost]
[Route("saveAdvanceIncomeTax")]
public ActionResult SaveAdvanceIncomeTax ( AdvanceIncomeTax advanceIncomeTax )
{
try
{
_advanceIncomeTaxService . Save ( advanceIncomeTax ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( advanceIncomeTax ) ;
}
[HttpPost]
[Route("deleteAdvanceIncomeTax")]
public ActionResult DeleteAdvanceIncomeTax ( int id )
{
try
{
_advanceIncomeTaxService . Delete ( id ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( ) ;
}
// EmployeeTaxInvestment
[HttpGet("getEmployeeTaxInvestmentById/{id}")]
public ActionResult GetEmployeeTaxInvestmentById ( int id )
{
EmployeeTaxInvestment employeeTaxInvestment = new EmployeeTaxInvestment ( ) ;
try
{
employeeTaxInvestment = _employeeTaxInvestmentService . Get ( id ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( employeeTaxInvestment ) ;
}
[HttpGet("getAllEmployeeTaxInvestment")]
public ActionResult GetAllEmployeeTaxInvestment ( )
{
List < EmployeeTaxInvestment > employeeTaxInvestments = new List < EmployeeTaxInvestment > ( ) ;
try
{
employeeTaxInvestments = _employeeTaxInvestmentService . Get ( ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( employeeTaxInvestments ) ;
}
[HttpGet("getAllUsersInfo")]
public ActionResult GetAllUsersInfo ( )
{
List < EmployeeTaxInvestment > employeeTaxInvestments = null ;
try
{
employeeTaxInvestments = _employeeTaxInvestmentService . GetAllUsersInfo ( ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( employeeTaxInvestments ) ;
}
[HttpGet("getAmount/{taxParamId}/{employeeId}")]
public ActionResult GetAmount ( int taxParamId , int employeeId )
{
Double result ;
try
{
result = _employeeTaxInvestmentService . GetAmount ( taxParamId , employeeId ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( result ) ;
}
[HttpGet("getSingleEmpsInfo/{empid}/{taxparamid}")]
public ActionResult GetSingleEmpsInfo ( int empid , int taxparamid )
{
List < EmployeeTaxInvestment > employeeTaxInvestments = new List < EmployeeTaxInvestment > ( ) ;
try
{
employeeTaxInvestments = _employeeTaxInvestmentService . GetSingleEmpsInfo ( empid , taxparamid ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( employeeTaxInvestments ) ;
}
[HttpPost]
[Route("saveEmployeeTaxInvestment")]
public ActionResult SaveEmployeeTaxInvestment ( EmployeeTaxInvestment taxInvestment )
{
int id = 0 ;
string connectionString = _config . GetSection ( "dbSettings" ) . GetSection ( "SqlCommandConnection" ) . Value ;
try
{
if ( taxInvestment . IsNew & & taxInvestment . EntryFrom = = EnumTaxInvestment . ESS )
{
TaxParameter taxParam = _taxParameterService . Get ( taxInvestment . TaxparameterId ) ;
if ( taxParam ! = null & & taxParam . IsAllowInvestmentForESS = = true
& & taxParam . InvestmentSubmitDeadline ! = null & & DateTime . Today > taxParam . InvestmentSubmitDeadline . Value . Date )
{
throw new Exception ( "Investment submission deadline (" + taxParam . InvestmentSubmitDeadline . Value . ToString ( "dd MMM yyyy" ) + ") has passed. You can no longer submit new investment." ) ;
}
}
if ( taxInvestment . TaxAttachment ! = null )
{
if ( taxInvestment . TaxAttachment . ID < = 0 & & taxInvestment . TaxAttachment . PreviousFileTobase64 ! = null )
{
string [ ] items = taxInvestment . TaxAttachment . PreviousFileTobase64 . Split ( new char [ ] { ',' , ' ' } , StringSplitOptions . None ) ;
byte [ ] newBytes = Convert . FromBase64String ( items [ 1 ] ) ;
taxInvestment . TaxAttachment . FileAsByteArray = newBytes ;
taxInvestment . TaxAttachment . ConnectionString = connectionString ;
}
}
id = _employeeTaxInvestmentService . Save ( taxInvestment ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( id ) ;
}
//[HttpPost]
//[Route("saveEmployeeTaxInvestmentList")]
//public ActionResult SaveEmployeeTaxInvestmentList(List<EmployeeTaxInvestment> employeeTaxInvestments)
//{
// try
// {
// _employeeTaxInvestmentService.Save(employeeTaxInvestments);
// }
// catch (Exception e)
// {
// return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
// }
// return Ok();
//}
[HttpPost]
[Route("deleteEmployeeTaxInvestment")]
public ActionResult DeleteEmployeeTaxInvestment ( EmployeeTaxInvestment item )
{
try
{
_employeeTaxInvestmentService . Delete ( item . ID ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( ) ;
}
// IncomeTax
[HttpGet("getPrvYearTax/{taxParameterId}/{groupCode}/{itemId}")]
public ActionResult GetPrvYearTax ( int taxParameterId , EnumIncomeTaxItemGroup groupCode , int itemId )
{
List < IncomeTax > incomeTaxes = new List < IncomeTax > ( ) ;
try
{
incomeTaxes = _incomeTaxService . GetPrvYear ( taxParameterId , groupCode , itemId ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( incomeTaxes ) ;
}
[HttpGet("getPrvYearTaxByPayrollId/{taxParameterId}")]
public ActionResult GetPrvYearTaxByPayrollId ( int taxParameterId )
{
CurrentUser currentUser = CurrentUser . GetCurrentUser ( HttpContext . User ) ;
int payrollTypeId = currentUser . PayrollTypeID . GetValueOrDefault ( ) ;
List < IncomeTax > incomeTaxes = new List < IncomeTax > ( ) ;
try
{
incomeTaxes = _incomeTaxService . GetPrvYear ( taxParameterId , payrollTypeId ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( incomeTaxes ) ;
}
[HttpGet("getTaxByEmployeeIdAndDataForm/{employeeId}/{dataFrom}")]
public ActionResult GetTaxByEmployeeIdAndDataForm ( int employeeId , int dataFrom )
{
List < IncomeTax > incomeTaxes = new List < IncomeTax > ( ) ;
EnumIncomeTaxDataFrom frm = ( EnumIncomeTaxDataFrom ) dataFrom ;
try
{
incomeTaxes = _incomeTaxService . Get ( employeeId , frm ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( incomeTaxes ) ;
}
[HttpGet("getTaxByDataFormAndPayrollTypeId/{dataFrom}")]
public ActionResult GetTaxByDataFormAndPayrollTypeId ( EnumIncomeTaxDataFrom dataForm )
{
CurrentUser currentUser = CurrentUser . GetCurrentUser ( HttpContext . User ) ;
int payrollTypeId = currentUser . PayrollTypeID . GetValueOrDefault ( ) ;
List < IncomeTax > incomeTaxes = new List < IncomeTax > ( ) ;
try
{
incomeTaxes = _incomeTaxService . Get ( dataForm , payrollTypeId ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( incomeTaxes ) ;
}
[HttpGet("getTaxByDataFormAndEmpIdsAndPayrollTypeId/{dataFrom}/{empIds}")]
public ActionResult GetTaxByDataFormAndEmpIdsAndPayrollTypeId ( EnumIncomeTaxDataFrom dataForm , string empIds )
{
CurrentUser currentUser = CurrentUser . GetCurrentUser ( HttpContext . User ) ;
int payrollTypeId = currentUser . PayrollTypeID . GetValueOrDefault ( ) ;
List < IncomeTax > incomeTaxes = new List < IncomeTax > ( ) ;
try
{
incomeTaxes = _incomeTaxService . Get ( dataForm , empIds , payrollTypeId , null ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( incomeTaxes ) ;
}
[HttpGet("getTaxByDataFormAndEmpIdAndTaxParamId/{dataFrom}/{empId}/{taxParamId}")]
public ActionResult GetTaxByDataFormAndEmpIdAndTaxParamId ( int dataFrom , int empId ,
int taxParamId )
{
List < IncomeTax > incomeTaxes = new List < IncomeTax > ( ) ;
try
{
CurrentUser currentUser = CurrentUser . GetCurrentUser ( HttpContext . User ) ;
if ( currentUser . TaxParamID ! = taxParamId )
{
dataFrom = 1 ;
}
incomeTaxes = _incomeTaxService . Get ( ( EnumIncomeTaxDataFrom ) dataFrom , empId , taxParamId ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( incomeTaxes ) ;
}
[HttpGet("getTax/{dataFrom}/{empId}/{groupCode}/{itemId}")]
public ActionResult GetTax ( EnumIncomeTaxDataFrom dataForm , int empId , EnumIncomeTaxItemGroup groupCode ,
int itemId )
{
IncomeTax incomeTax = new IncomeTax ( ) ;
try
{
incomeTax = _incomeTaxService . Get ( dataForm , empId , groupCode , itemId ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( incomeTax ) ;
}
[HttpGet("getTaxByYear/{taxParamId}/{dataFrom}")]
public ActionResult GetTaxByYear ( int taxParamId , EnumIncomeTaxDataFrom dataForm )
{
CurrentUser currentUser = CurrentUser . GetCurrentUser ( HttpContext . User ) ;
int payrollTypeId = currentUser . PayrollTypeID . GetValueOrDefault ( ) ;
List < IncomeTax > incomeTaxes = new List < IncomeTax > ( ) ;
try
{
incomeTaxes = _incomeTaxService . GetByYear ( taxParamId , dataForm , payrollTypeId ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( incomeTaxes ) ;
}
[HttpPost]
[Route("updateOt")]
public ActionResult UpdateOt ( List < OTProcess > otProcess )
{
try
{
_incomeTaxService . UpdateOT ( otProcess ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( ) ;
}
[HttpPost]
[Route("saveIncomeTax")]
public ActionResult SaveIncomeTaxTemp ( IncomeTax incomeTax )
{
int id = 0 ;
try
{
id = _incomeTaxService . Save ( incomeTax , incomeTax . DataTo ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( id ) ;
}
[HttpPost]
[Route("doYearEndReProcessTax")]
public ActionResult DoYearEndReProcessTax ( dynamic request )
{
CurrentUser currentUser = CurrentUser . GetCurrentUser ( HttpContext . User ) ;
int payrollTypeId = currentUser . PayrollTypeID . GetValueOrDefault ( ) ;
try
{
_incomeTaxService . DoYearEndReProcess ( request , payrollTypeId ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( ) ;
}
//[HttpPost]
//[Route("doTaxYearEnd")]
//public ActionResult DoTaxYearEnd(List<IncomeTax> incomeTaxes)
//{
// CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
// int payrollTypeId = currentUser.PayrollTypeID.GetValueOrDefault();
// try
// {
// _incomeTaxService.DoTaxYearEnd(incomeTaxes, payrollTypeId);
// }
// catch (Exception e)
// {
// return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
// }
// return Ok();
//}
[HttpPost]
[Route("DoTaxYearEnd")]
public ActionResult DoTaxYearEnd ( dynamic item )
{
CurrentUser currentUser = CurrentUser . GetCurrentUser ( HttpContext . User ) ;
try
{
_incomeTaxService . DoTaxYearEnd ( ( int ) currentUser . PayrollTypeID ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( ) ;
}
[HttpPost]
[Route("CompareIncomedataview")]
public ActionResult CompareIncomedataview ( List < IncomeTax > taxes )
{
CurrentUser currentUser = CurrentUser . GetCurrentUser ( HttpContext . User ) ;
var employeeIds = taxes . Select ( t = > t . EmployeeID ) . Distinct ( ) . ToList ( ) ;
var descriptions = taxes . Select ( t = > t . Description ) . Distinct ( ) . ToList ( ) ;
string inempstring = string . Join ( "," , employeeIds ) ;
if ( inempstring = = "" ) throw new Exception ( "there is no data found" ) ;
List < SearchEmployee > searhemp = new SearchEmployeeService ( ) . GetByEmpIDIn ( inempstring ) ;
// Step 2: Create DataTable and columns
DataTable pivotTable = new DataTable ( ) ;
pivotTable . Columns . Add ( "employeeid" , typeof ( int ) ) ;
pivotTable . Columns . Add ( "employeeno" , typeof ( string ) ) ;
pivotTable . Columns . Add ( "name" , typeof ( string ) ) ;
foreach ( var desc in descriptions )
{
pivotTable . Columns . Add ( "tax-" + desc , typeof ( double ) ) ;
pivotTable . Columns . Add ( "sal-" + desc , typeof ( double ) ) ;
pivotTable . Columns . Add ( "dif-" + desc , typeof ( double ) ) ;
}
// Step 3: Fill rows
foreach ( var empId in employeeIds )
{
DataRow row = pivotTable . NewRow ( ) ;
row [ "employeeid" ] = Convert . ToInt32 ( empId ) ;
row [ "employeeno" ] = searhemp . FirstOrDefault ( e = > e . EmployeeID = = empId ) ? . EmployeeNo ;
row [ "name" ] = searhemp . FirstOrDefault ( e = > e . EmployeeID = = empId ) ? . Name ;
foreach ( var desc in descriptions )
{
var tax = taxes . FirstOrDefault ( t = > t . EmployeeID = = empId & & t . Description = = desc ) ;
row [ "tax-" + desc ] = tax ! = null ? tax . ThisMonthAmount : 0.0 ;
row [ "sal-" + desc ] = tax ! = null ? tax . PreviousAmount : 0.0 ;
row [ "dif-" + desc ] = tax ! = null ? Math . Round ( tax . ThisMonthAmount - tax . PreviousAmount ) : 0.0 ;
}
pivotTable . Rows . Add ( row ) ;
}
return Ok ( pivotTable ) ;
}
[HttpPost]
[Route("updateTaxForcorrection")]
public ActionResult updateTaxForcorrection ( List < IncomeTax > taxes )
{
CurrentUser currentUser = CurrentUser . GetCurrentUser ( HttpContext . User ) ;
PayrollType payrollType = new PayrollTypeService ( ) . Get ( ( int ) currentUser . PayrollTypeID ) ;
int taxParamID = taxes [ 0 ] . TaxParameterID ;
EnumIncomeTaxDataFrom souce = EnumIncomeTaxDataFrom . ProcessTempData ;
if ( taxParamID ! = payrollType . TaxParamID )
{
souce = EnumIncomeTaxDataFrom . ProcessedData ;
}
try
{
_incomeTaxService . updateTaxForcorrection ( taxes , souce , ( int ) taxParamID ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( ) ;
}
[HttpPost]
[Route("CompareIncome")]
public ActionResult CompareIncome ( dynamic recalData )
{
CurrentUser currentUser = CurrentUser . GetCurrentUser ( HttpContext . User ) ;
var items = Newtonsoft . Json . JsonConvert . DeserializeObject ( Convert . ToString ( recalData ) ) ;
int index = 0 ;
List < SearchEmployee > searhemp = new List < SearchEmployee > ( ) ;
string empid = "" ;
int taxparamid = 0 ;
bool liveemp = false ;
bool disconemp = false ;
foreach ( var item in items )
{
if ( index = = 0 )
{
taxparamid = ( int ) item [ "paramId" ] . ToObject < int > ( ) ;
liveemp = ( bool ) item [ "liveemp" ] . ToObject < bool > ( ) ;
disconemp = ( bool ) item [ "disconemp" ] . ToObject < bool > ( ) ;
}
// empid = empid + (string)item["empid"].ToObject<string>() + ",";
}
if ( empid . Length > 0 )
{
empid = empid . Substring ( 0 , empid . Length - 1 ) ;
}
List < IncomeTax > taxItems = new List < IncomeTax > ( ) ;
try
{
taxItems = new TaxCalculator ( ) . compareIncome ( ( int ) currentUser . PayrollTypeID ,
null , taxparamid , liveemp , disconemp ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( taxItems ) ;
}
[HttpPost]
[Route("TaxRecalculate")]
public ActionResult TaxRecalculate ( dynamic recalData )
{
CurrentUser currentUser = CurrentUser . GetCurrentUser ( HttpContext . User ) ;
var items = Newtonsoft . Json . JsonConvert . DeserializeObject ( Convert . ToString ( recalData ) ) ;
int index = 0 ;
List < SearchEmployee > searhemp = new List < SearchEmployee > ( ) ;
string empid = "" ;
int taxparamid = 0 ;
EnumIncomeTaxDataFrom dataFrom = EnumIncomeTaxDataFrom . ProcessTempData ;
foreach ( var item in items )
{
if ( index = = 0 )
{
taxparamid = ( int ) item [ "taxParamID" ] . ToObject < int > ( ) ;
dataFrom = ( EnumIncomeTaxDataFrom ) item [ "taxParamID" ] . ToObject < int > ( ) ;
}
empid = empid + ( string ) item [ "empid" ] . ToObject < string > ( ) + "," ;
}
if ( empid . Length > 0 )
{
empid = empid . Substring ( 0 , empid . Length - 1 ) ;
}
List < IncomeTax > taxItems = new List < IncomeTax > ( ) ;
try
{
List < Employee > employees = new EmployeeService ( ) . GetByEmpIDs ( empid , ( int ) currentUser . PayrollTypeID ) ;
taxItems = new TaxCalculator ( ) . TaxReconsiliation ( ( int ) currentUser . PayrollTypeID , employees , taxparamid ,
dataFrom ) ;
this . _incomeTaxService . Save ( taxItems , dataFrom ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( true ) ;
}
[HttpPost]
[Route("saveTaxList")]
public ActionResult SaveTaxList ( List < IncomeTax > incomeTaxes , EnumIncomeTaxDataFrom saveTo )
{
try
{
_incomeTaxService . Save ( incomeTaxes , saveTo ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( ) ;
}
[HttpPost]
[Route("deleteTax")]
public ActionResult DeleteTax ( IncomeTax item )
{
try
{
_incomeTaxService . Delete ( item . EmployeeID , item . DataTo , item . ItemGroup , item . ItemID ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( ) ;
}
[HttpPost]
[Route("deleteYearlyDataTax")]
public ActionResult DeleteYearlyDataTax ( int taxParamID , EnumIncomeTaxDataFrom deleteFrom , int empId ,
EnumIncomeTaxItemGroup itemGroup , int itemId )
{
try
{
_incomeTaxService . DeleteYearlyData ( taxParamID , deleteFrom , empId , itemGroup , itemId ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( ) ;
}
[HttpPost]
[Route("doTaxTempReProcessTax")]
public ActionResult DoTaxTempReProcessTax ( List < IncomeTax > incomeTaxes , int taxParameterId ,
EnumIncomeTaxDataFrom saveTo )
{
CurrentUser currentUser = CurrentUser . GetCurrentUser ( HttpContext . User ) ;
int payrollTypeId = currentUser . PayrollTypeID . GetValueOrDefault ( ) ;
try
{
_incomeTaxService . DoTaxTempReProcess ( incomeTaxes , taxParameterId , saveTo , payrollTypeId ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( ) ;
}
[HttpGet]
[Route("hasTaxDataInSalaryTemp/{employeeID}")]
public ActionResult HasDataInTempTax ( int employeeId , int TaxParamID )
{
bool status = false ;
try
{
status = _incomeTaxService . hasTaxDataInSalaryTemp ( employeeId ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( status ) ;
}
[HttpGet]
[Route("getcurrentYeardataSource/{employeeID}")]
public ActionResult getcurrentYeardataSource ( int employeeId )
{
EnumIncomeTaxDataFrom status = EnumIncomeTaxDataFrom . ProcessTempData ;
try
{
status = _incomeTaxService . currentYeardataSource ( employeeId ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( status ) ;
}
[HttpPost]
[Route("TaxCalculationbySalary")]
public ActionResult TaxCalculationbySalary ( SalaryMonthly salaries )
{
List < IncomeTax > incomeTaxes = new List < IncomeTax > ( ) ;
CurrentUser currentUser = CurrentUser . GetCurrentUser ( HttpContext . User ) ;
int payrollTypeId = currentUser . PayrollTypeID . GetValueOrDefault ( ) ;
try
{
// TaxParameter otaxParam = new ITaxParameterService().
incomeTaxes = _incomeTaxService . calculateTaxFromSalary ( salaries ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( incomeTaxes ) ;
}
// ITEmpHead
[HttpGet("getITEmpHead/{id}")]
public ActionResult GetITEmpHead ( int id )
{
ITEmpHead itEmpHead = new ITEmpHead ( ) ;
try
{
itEmpHead = _itEmpHeadService . Get ( id ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( itEmpHead ) ;
}
[HttpGet("getITEmpHeadWithTaxParam/{taxParamId}")]
public ActionResult GetITEmpHeadWithTaxParam ( int taxParamId )
{
List < ITEmpHead > itEmpHeads = new List < ITEmpHead > ( ) ;
try
{
itEmpHeads = _itEmpHeadService . GetWithTaxParam ( taxParamId ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( itEmpHeads ) ;
}
[HttpPost]
[Route("saveITEmpHead")]
public ActionResult SaveITEmpHead ( ITEmpHead itEmpHead )
{
CurrentUser ouser = CurrentUser . GetCurrentUser ( HttpContext . User ) ;
if ( itEmpHead . IsNew )
{
itEmpHead . CreatedBy = ouser . UserID ;
itEmpHead . CreatedDate = DateTime . Today ;
}
else
{
itEmpHead . ModifiedBy = ouser . UserID ;
itEmpHead . ModifiedDate = DateTime . Today ;
}
try
{
_itEmpHeadService . Save ( itEmpHead ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( ) ;
}
[HttpPost]
[Route("saveITEmpHead2")]
public ActionResult SaveITEmpHead2 ( ITEmpHead itEmpHead )
{
try
{
_itEmpHeadService . Save2 ( itEmpHead ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( ) ;
}
[HttpPost]
[Route("deleteITEmpHead")]
public ActionResult DeleteITEmpHead ( ITEmpHead itEmpHead )
{
try
{
_itEmpHeadService . Delete ( itEmpHead ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( ) ;
}
// MinTaxException
[HttpGet("getAllMinTaxException")]
public ActionResult GetAllMinTaxException ( )
{
List < MinTaxException > minTaxExceptions = new List < MinTaxException > ( ) ;
try
{
minTaxExceptions = _minTaxExceptionService . Get ( ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( minTaxExceptions ) ;
}
[HttpGet("getMinTaxExceptionByEmpId/{empId}")]
public ActionResult GetMinTaxExceptionByEmpId ( int empId )
{
MinTaxException minTaxException = new MinTaxException ( ) ;
try
{
minTaxException = _minTaxExceptionService . Get ( empId ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( minTaxException ) ;
}
[HttpPost]
[Route("saveMinTaxException")]
public ActionResult SaveMinTaxException ( List < MinTaxException > minTaxExceptions )
{
try
{
_minTaxExceptionService . Save ( minTaxExceptions ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( ) ;
}
[HttpPost]
[Route("deleteMinTaxException")]
public ActionResult DeleteMinTaxException ( int id )
{
try
{
_minTaxExceptionService . Delete ( id ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( ) ;
}
// TaxAdjustment
[HttpGet("getTaxAdjustment/{id}")]
public ActionResult GetTaxAdjustment ( int id )
{
TaxAdjustment taxAdjustment = new TaxAdjustment ( ) ;
try
{
taxAdjustment = _taxAdjustmentService . Get ( id ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( taxAdjustment ) ;
}
[HttpGet("getAllTaxAdjustment")]
public ActionResult GetAllTaxAdjustment ( )
{
List < TaxAdjustment > taxAdjustments = new List < TaxAdjustment > ( ) ;
try
{
taxAdjustments = _taxAdjustmentService . Get ( ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( taxAdjustments ) ;
}
[HttpGet("getAllTaxAdjustmentByEnumStatus/{status}")]
public ActionResult GetAllTaxAdjustmentByEnumStatus ( EnumStatus status )
{
List < TaxAdjustment > taxAdjustments = new List < TaxAdjustment > ( ) ;
try
{
taxAdjustments = _taxAdjustmentService . Get ( status ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( taxAdjustments ) ;
}
[HttpPost]
[Route("saveTaxAdjustment")]
public ActionResult SaveTaxAdjustment ( TaxAdjustment taxAdjustment )
{
try
{
_taxAdjustmentService . Save ( taxAdjustment ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( taxAdjustment ) ;
}
[HttpPost]
[Route("deleteTaxAdjustment")]
public ActionResult DeleteTaxAdjustment ( int id )
{
try
{
_taxAdjustmentService . Delete ( id ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( ) ;
}
// TaxChallan
[HttpGet("getTaxChallanById/{id}")]
public ActionResult GetTaxChallanById ( int id )
{
TaxChallan taxChallan = new TaxChallan ( ) ;
try
{
taxChallan = _taxChallanService . Get ( id ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( taxChallan ) ;
}
[HttpGet("getAllTaxChallan")]
public ActionResult GetAllTaxChallan ( )
{
List < TaxChallan > taxChallans = new List < TaxChallan > ( ) ;
try
{
taxChallans = _taxChallanService . Get ( ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( taxChallans ) ;
}
[HttpGet("GetGroupChallans/{taxparamid}")]
public ActionResult GetGroupChallans ( int taxparamid )
{
DataTable taxChallans = null ;
try
{
taxChallans = _taxChallanService . GetGroupChallans ( taxparamid ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( taxChallans ) ;
}
[HttpGet("getByTaxParamId/{taxParamId}")]
public ActionResult GetByTaxParamId ( int taxParamId )
{
List < TaxChallan > taxChallans = new List < TaxChallan > ( ) ;
try
{
taxChallans = _taxChallanService . GetByTaxParamId ( taxParamId ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( taxChallans ) ;
}
[HttpGet("getTaxChallanByEmpIdAndTaxParamId/{empId}/{taxParamId}")]
public ActionResult GetTaxChallanByEmpIdAndTaxParamId ( int empId , int taxParamId )
{
List < TaxChallan > taxChallans = new List < TaxChallan > ( ) ;
try
{
taxChallans = _taxChallanService . Get ( empId , taxParamId ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( taxChallans ) ;
}
[HttpPost]
[Route("saveTaxChallan")]
public ActionResult SaveTaxChallan ( TaxChallan taxChallan )
{
CurrentUser currentUser = CurrentUser . GetCurrentUser ( HttpContext . User ) ;
taxChallan . PayrolltypeID = currentUser . PayrollTypeID . GetValueOrDefault ( ) ;
taxChallan . CreatedBy = currentUser . UserID ;
taxChallan . ModifiedBy = currentUser . UserID ;
try
{
if ( taxChallan . ID = = 0 )
{
List < TaxChallan > GetAllTaxChallan = _taxChallanService . Get ( ) ;
TaxChallan SearchTaxChallan = GetAllTaxChallan . Find ( x = > x . SalaryMonthly . Date = = taxChallan . SalaryMonthly . Date & & x . IsBonusAmount = = taxChallan . IsBonusAmount & & x . PayrolltypeID = = taxChallan . PayrolltypeID ) ;
if ( SearchTaxChallan ! = null )
{
return BadRequest ( "This salary month already exists" ) ;
}
}
_taxChallanService . Save ( taxChallan ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( taxChallan ) ;
}
[HttpPost]
[Route("deleteTaxChallan")]
public ActionResult DeleteTaxChallanById ( TaxChallan item )
{
try
{
_taxChallanService . Delete ( item . ID ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( ) ;
}
[HttpPost]
[Route("deleteAllByTaxParamId")]
public ActionResult DeleteAllByTaxParamId ( int taxParamId )
{
try
{
_taxChallanService . DeleteAllByTaxparamID ( taxParamId ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( ) ;
}
// TaxHeadAssignment
[HttpGet("getTaxHeadAssignmentById/{id}")]
public ActionResult GetTaxHeadAssignmentById ( int id )
{
TaxHeadAssignment taxHeadAssignment = new TaxHeadAssignment ( ) ;
try
{
taxHeadAssignment = _taxHeadAssignmentService . Get ( id ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( taxHeadAssignment ) ;
}
[HttpGet("getAllTaxHeadAssignment")]
public ActionResult GetAllTaxHeadAssignment ( )
{
List < TaxHeadAssignment > taxHeadAssignments = new List < TaxHeadAssignment > ( ) ;
try
{
taxHeadAssignments = _taxHeadAssignmentService . Get ( ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( taxHeadAssignments ) ;
}
[HttpPost]
[Route("saveTaxHeadAssignment")]
public ActionResult SaveTaxHeadAssignment ( TaxHeadAssignment taxHeadAssignment )
{
try
{
_taxHeadAssignmentService . Save ( taxHeadAssignment ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( ) ;
}
[HttpPost]
[Route("deleteTaxHeadAssignment")]
public ActionResult DeleteTaxHeadAssignment ( int id )
{
try
{
_taxHeadAssignmentService . Delete ( id ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( ) ;
}
// TaxInvestment
[HttpGet("getTaxInvestmentById/{id}")]
public ActionResult GetTaxInvestmentById ( int id )
{
TaxInvestment taxInvestment = new TaxInvestment ( ) ;
try
{
taxInvestment = _taxInvestmentService . Get ( id ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( taxInvestment ) ;
}
[HttpGet("getTaxInvestmentByStatus/{status}")]
public ActionResult GetTaxInvestmentByStatus ( EnumStatus status )
{
List < TaxInvestment > taxInvestments = new List < TaxInvestment > ( ) ;
try
{
taxInvestments = _taxInvestmentService . Get ( status ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( taxInvestments ) ;
}
[HttpGet("getInfoForAdmin/{taxParamId}/{entryFrom}/{taxEffect}")]
public ActionResult getInfoForAdmin ( int taxParamId , int entryFrom , int taxEffect )
{
DataTable dt = null ;
try
{
dt = _taxInvestmentService . GetInfoForAdmin ( taxParamId , entryFrom , taxEffect ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( dt ) ;
}
//need to work
//[HttpGet("getInvestmentDetailAdmin/{taxParamId}")]
//public ActionResult getInvestmentDetailAdmin(int taxParamId)
//{
// DataTable dt = null;
// try
// {
// dt = _taxInvestmentService.GetInvestmentDetailAdmin(taxParamId);
// }
// catch (Exception e)
// {
// return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
// }
// return Ok(dt);
//}
[HttpGet("getInvestmentDetailAdmin/{taxParamId}")]
public ActionResult getInvestmentDetailAdmin ( int taxParamId )
{
DataTable dataTable = new DataTable ( ) ;
try
{
CurrentUser currentUser = CurrentUser . GetCurrentUser ( HttpContext . User ) ;
List < EmployeeTaxInvestment > emptaxInv = new EmployeeTaxInvestmentService ( ) . GetEmpByTaxparam ( taxParamId ) ;
List < TaxInvestment > taxInvs = new TaxInvestmentService ( ) . Get ( EnumStatus . Active ) ;
List < IncomeTax > incomeTaxItems = new IncomeTaxService ( ) . Get ( EnumIncomeTaxDataFrom . ProcessTempData , ( int ) currentUser . PayrollTypeID ) ;
List < IncomeTax > investmentAllowedItems = incomeTaxItems . Where ( x = > x . ItemGroup = = EnumIncomeTaxItemGroup . Investment_Allowed ) . ToList ( ) ;
List < IncomeTax > pfInvestmentItems = incomeTaxItems . Where ( x = > x . ItemGroup = = EnumIncomeTaxItemGroup . Company_Contri_PF ) . ToList ( ) ;
dataTable . Columns . Add ( "Employee-ID" ) ;
dataTable . Columns . Add ( "Employee-Name" ) ;
foreach ( TaxInvestment item in taxInvs )
{
dataTable . Columns . Add ( item . Name ) ;
dataTable . Columns . Add ( item . Name + "-Limit" ) ;
}
dataTable . Columns . Add ( "Total-Invest" ) ;
dataTable . Columns . Add ( "Total-Invest-Consider" ) ;
dataTable . Columns . Add ( "Investment-Allowed" ) ;
dataTable . Columns . Add ( "PF-Investment" ) ;
dataTable . Columns . Add ( "Other-Investment" ) ;
dataTable . Columns . Add ( "Investment-To-Do" ) ;
List < EmployeeTaxInvestment > items = emptaxInv . GroupBy ( u = > u . EmployeeID ) . Select ( g = > g . First ( ) ) . ToList ( ) ;
//var employeeIds = items.Select(emp => emp.EmployeeID).ToList();
foreach ( var item in items )
{
DataRow row = dataTable . Rows . Add ( ) ;
var empItems = emptaxInv . FindAll ( x = > x . EmployeeID = = item . EmployeeID ) ;
row [ "Employee-ID" ] = empItems [ 0 ] . EmployeeNo ;
row [ "Employee-Name" ] = empItems [ 0 ] . EmployeeName ;
double investSum = 0 ;
double investConsiderSum = 0 ;
double investmentAllowedTotal = 0 ;
double pfInvestmentTotal = 0 ;
double investmentToDo = 0 ;
foreach ( var inv in taxInvs )
{
var empItem = empItems . FindAll ( x = > x . TypeID = = inv . ID & & x . submitStatus = = EnumTaxInvestmentStatus . Approve ) ;
if ( empItem . Count ! = 0 )
{
row [ inv . Name ] = empItem . Sum ( x = > x . Amount ) ;
investSum = investSum + ( int ) empItem . Sum ( x = > x . Amount ) ;
double limitAMount = EmployeeTaxInvestment . GetAmount ( item . EmployeeID , empItem , taxInvs ) ;
row [ inv . Name + "-Limit" ] = limitAMount ;
investConsiderSum = investConsiderSum + limitAMount ;
}
}
row [ "Total-Invest" ] = investSum ;
row [ "Total-Invest-Consider" ] = investConsiderSum ;
if ( investmentAllowedItems . Where ( x = > x . EmployeeID = = item . EmployeeID ) . ToList ( ) . Count > 0 )
{
investmentAllowedTotal = investmentAllowedItems . FirstOrDefault ( x = > x . EmployeeID = = item . EmployeeID ) . TotalAmount ;
investmentAllowedTotal = GlobalFunctions . Round ( investmentAllowedTotal , 2 ) ;
row [ "Investment-Allowed" ] = investmentAllowedTotal . ToString ( "0.00" ) ;
}
if ( pfInvestmentItems . Where ( x = > x . EmployeeID = = item . EmployeeID ) . ToList ( ) . Count > 0 )
{
pfInvestmentTotal = 2 * ( pfInvestmentItems . FirstOrDefault ( x = > x . EmployeeID = = item . EmployeeID ) . TotalAmount ) ;
pfInvestmentTotal = GlobalFunctions . Round ( pfInvestmentTotal , 2 ) ;
row [ "PF-Investment" ] = pfInvestmentTotal . ToString ( "0.00" ) ;
}
row [ "Other-Investment" ] = GlobalFunctions . Round ( ( investmentAllowedTotal - pfInvestmentTotal ) ) ;
investmentToDo = GlobalFunctions . Round ( ( investmentAllowedTotal - pfInvestmentTotal ) - investConsiderSum ) ;
row [ "Investment-To-Do" ] = investmentToDo > 0 ? investmentToDo : 0 ;
}
//dt = _taxInvestmentService.GetInvestmentDetailAdmin(taxParamId);
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( dataTable ) ;
}
[HttpGet("getSummaryview/{taxParamId}")]
public ActionResult getSummaryview ( int taxParamId )
{
DataTable dt = null ;
try
{
dt = _employeeTaxInvestmentService . getSummaryView ( taxParamId ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( dt ) ;
}
[HttpPost]
[Route("saveTaxInvestment")]
public ActionResult SaveTaxInvestment ( TaxInvestment taxInvestment )
{
try
{
_taxInvestmentService . Save ( taxInvestment ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( ) ;
}
[HttpPost]
[Route("deleteTaxInvestment")]
public ActionResult DeleteTaxInvestment ( dynamic data )
{
var item = Newtonsoft . Json . JsonConvert . DeserializeObject ( Convert . ToString ( data ) ) ;
int id = item [ "id" ] . ToObject < int > ( ) ;
try
{
_taxInvestmentService . Delete ( id ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( ) ;
}
[HttpPost]
[Route("ApproveEmployeeTaxInvestment")]
public ActionResult ApproveEmployeeTaxInvestment ( List < EmployeeTaxInvestment > items )
{
CurrentUser currentUser = CurrentUser . GetCurrentUser ( HttpContext . User ) ;
foreach ( var item in items )
{
item . ModifiedBy = currentUser . UserID ;
item . ModifiedDate = DateTime . Today ;
item . submitStatus = EnumTaxInvestmentStatus . Approve ;
}
try
{
_employeeTaxInvestmentService . Approve ( items ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( ) ;
}
[HttpPost]
[Route("RejectEmployeeTaxInvestment")]
public ActionResult RejectEmployeeTaxInvestment ( List < EmployeeTaxInvestment > items )
{
CurrentUser currentUser = CurrentUser . GetCurrentUser ( HttpContext . User ) ;
foreach ( var item in items )
{
item . ModifiedBy = currentUser . UserID ;
item . ModifiedDate = DateTime . Today ;
item . submitStatus = EnumTaxInvestmentStatus . Reject ;
}
try
{
_employeeTaxInvestmentService . Reject ( items ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( ) ;
}
// TaxMergeMaster
[HttpGet("getTaxMergeMasterById/{id}")]
public ActionResult GetTaxMergeMasterById ( int id )
{
CurrentUser currentUser = CurrentUser . GetCurrentUser ( HttpContext . User ) ;
int payrollTypeId = currentUser . PayrollTypeID . GetValueOrDefault ( ) ;
TaxMergeMaster taxMergeMaster = new TaxMergeMaster ( ) ;
try
{
taxMergeMaster = _taxMergeMasterService . Get ( id , payrollTypeId ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( taxMergeMaster ) ;
}
[HttpGet("getTaxMergeMaster/{taxMergeType}/{itemID}")]
public ActionResult GetTaxMergeMaster ( EnumTaxMergeType taxMergeType , int itemID )
{
CurrentUser currentUser = CurrentUser . GetCurrentUser ( HttpContext . User ) ;
int payrollTypeId = currentUser . PayrollTypeID . GetValueOrDefault ( ) ;
TaxMergeMaster taxMergeMaster = new TaxMergeMaster ( ) ;
try
{
taxMergeMaster = _taxMergeMasterService . Get ( payrollTypeId , ( int ) currentUser . TaxParamID , taxMergeType , itemID ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( taxMergeMaster ) ;
}
[HttpGet("getTaxMergeMasterByTaxParameterId/{taxParameterId}")]
public ActionResult GetTaxMergeMasterByTaxParameterId ( int taxParameterId )
{
CurrentUser currentUser = CurrentUser . GetCurrentUser ( HttpContext . User ) ;
int payrollTypeId = currentUser . PayrollTypeID . GetValueOrDefault ( ) ;
List < TaxMergeMaster > taxMergeMasters = new List < TaxMergeMaster > ( ) ;
try
{
taxMergeMasters = _taxMergeMasterService . GetbyTaxParameter ( taxParameterId , payrollTypeId ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( taxMergeMasters ) ;
}
[HttpPost]
[Route("saveTaxMergeMaster")]
public ActionResult SaveTaxMergeMaster ( TaxMergeMaster taxMergeMaster )
{
CurrentUser ouser = CurrentUser . GetCurrentUser ( HttpContext . User ) ;
int mergeID = 0 ;
try
{
taxMergeMaster . PayrollTypeID = ( int ) ouser . PayrollTypeID ;
if ( taxMergeMaster . IsNew = = true )
{
taxMergeMaster . CreatedBy = ouser . UserID ;
taxMergeMaster . CreatedDate = DateTime . Today ;
}
else
{
taxMergeMaster . ModifiedBy = ouser . UserID ;
taxMergeMaster . ModifiedDate = DateTime . Today ;
}
mergeID = _taxMergeMasterService . Save ( taxMergeMaster ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( mergeID ) ;
}
[HttpPost]
[Route("deleteTaxMergeMaster")]
public ActionResult DeleteTaxMergeMaster ( TaxMergeMaster taxMergeMaster )
{
try
{
_taxMergeMasterService . Delete ( taxMergeMaster . ID ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( ) ;
}
// TaxParameter
[HttpGet("getTaxParameter/{id}")]
public ActionResult GetTaxParameter ( int id )
{
TaxParameter taxParameter = new TaxParameter ( ) ;
try
{
taxParameter = _taxParameterService . Get ( id ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( taxParameter ) ;
}
[HttpGet("getTaxParameterWithSignature/{id}")]
public ActionResult getTaxParameterWithSignature ( int id )
{
TaxParameter taxParameter = new TaxParameter ( ) ;
try
{
taxParameter = _taxParameterService . GetTaxParameterWithSignature ( id ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( taxParameter ) ;
}
[HttpGet("getCurrentTaxParameter")]
public ActionResult GetCurrentTaxParameter ( )
{
CurrentUser currentUser = CurrentUser . GetCurrentUser ( HttpContext . User ) ;
int taxParamId = currentUser . TaxParamID . GetValueOrDefault ( ) ;
TaxParameter taxParameter = new TaxParameter ( ) ;
try
{
taxParameter = _taxParameterService . Get ( taxParamId ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( taxParameter ) ;
}
[HttpGet("getPreviousTaxParameter")]
public ActionResult GetPreviousTaxParameter ( )
{
CurrentUser currentUser = CurrentUser . GetCurrentUser ( HttpContext . User ) ;
int taxParamId = currentUser . TaxParamID . GetValueOrDefault ( ) ;
TaxParameter taxParameter = new TaxParameter ( ) ;
TaxParameter prevTaxParameter = new TaxParameter ( ) ;
try
{
taxParameter = _taxParameterService . Get ( taxParamId ) ;
string fiscalYear = $"{taxParameter.FiscalyearDatefrom.Year - 1}-{taxParameter.FiscalyearDatefrom.Year}" ;
prevTaxParameter = _taxParameterService . GetByFiscalYear ( fiscalYear , taxParameter . PayrollTypeID ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( prevTaxParameter ) ;
}
[HttpGet("getTaxParameterByAssessmentYear/{assessmentYear}")]
public ActionResult GetTaxParameterByAssessmentYear ( string assessmentYear )
{
TaxParameter taxParameter = new TaxParameter ( ) ;
try
{
taxParameter = _taxParameterService . Get ( assessmentYear ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( taxParameter ) ;
}
[HttpGet("getAllTaxParameter")]
public ActionResult GetAllTaxParameter ( )
{
CurrentUser currentUser = CurrentUser . GetCurrentUser ( HttpContext . User ) ;
int payrollTypeId = currentUser . PayrollTypeID . GetValueOrDefault ( ) ;
List < TaxParameter > taxParameters = new List < TaxParameter > ( ) ;
try
{
taxParameters = _taxParameterService . GetbyPayrolltype ( payrollTypeId ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( taxParameters ) ;
}
[HttpGet("getTexAdjustmentParameter")]
public ActionResult getTexAdjustmentParameter ( )
{
CurrentUser currentUser = CurrentUser . GetCurrentUser ( HttpContext . User ) ;
int payrollTypeId = currentUser . PayrollTypeID . GetValueOrDefault ( ) ;
List < TaxAdjustment > taxParameters = new List < TaxAdjustment > ( ) ;
try
{
taxParameters = _taxAdjustmentService . Get ( ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( taxParameters ) ;
}
[HttpGet("getAllTaxParameterForCurrentYear/{isForCurrentYear}")]
public ActionResult GetAllTaxParameterForCurrentYear ( bool isForCurrentYear )
{
CurrentUser currentUser = CurrentUser . GetCurrentUser ( HttpContext . User ) ;
int payrollTypeId = currentUser . PayrollTypeID . GetValueOrDefault ( ) ;
List < TaxParameter > taxParameters = new List < TaxParameter > ( ) ;
try
{
taxParameters = _taxParameterService . Get ( isForCurrentYear , payrollTypeId ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( taxParameters ) ;
}
[HttpGet("getTaxSlabsByTaxParameterIdAndTaxType/{taxParameterId}/{taxType}")]
public ActionResult GetTaxSlabsByTaxParameterIdAndTaxType ( int taxParameterId , EnumTaxSlabType taxType )
{
List < TaxParameterSlab > taxParameterSlabs = new List < TaxParameterSlab > ( ) ;
try
{
taxParameterSlabs = _taxParameterService . GetTaxSlabs ( taxParameterId , taxType ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( taxParameterSlabs ) ;
}
[HttpGet("getTaxSlabsByTaxParameterId/{taxParameterId}")]
public ActionResult GetTaxSlabsByTaxParameterId ( int taxParameterId )
{
List < TaxParameterSlab > taxParameterSlabs = new List < TaxParameterSlab > ( ) ;
try
{
taxParameterSlabs = _taxParameterService . GetSlabsByParamID ( taxParameterId ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( taxParameterSlabs ) ;
}
[HttpPost]
[Route("saveTaxParameter")]
public ActionResult SaveTaxParameter ( TaxParameter otaxParameter )
{
CurrentUser currentUser = CurrentUser . GetCurrentUser ( HttpContext . User ) ;
int payrollTypeId = currentUser . PayrollTypeID . GetValueOrDefault ( ) ;
try
{
otaxParameter . PayrollTypeID = payrollTypeId ;
if ( otaxParameter . IsNew = = true )
{
otaxParameter . CreatedBy = currentUser . UserID ;
otaxParameter . CreatedDate = DateTime . Today ;
}
else
{
otaxParameter . ModifiedBy = currentUser . UserID ;
otaxParameter . ModifiedDate = DateTime . Today ;
}
_taxParameterService . Save ( otaxParameter , payrollTypeId ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( ) ;
}
[HttpPost]
[Route("SetCurrentYearTax")]
public ActionResult SetCurrentYearTax ( TaxParameter otaxParameter )
{
CurrentUser currentUser = CurrentUser . GetCurrentUser ( HttpContext . User ) ;
int payrollTypeId = currentUser . PayrollTypeID . GetValueOrDefault ( ) ;
try
{
_taxParameterService . SetCurrentYearTax ( otaxParameter . ID , payrollTypeId ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( ) ;
}
[HttpPost]
[Route("deleteTaxParameter")]
public ActionResult DeleteTaxParameter ( int id )
{
CurrentUser currentUser = CurrentUser . GetCurrentUser ( HttpContext . User ) ;
int payrollTypeId = currentUser . PayrollTypeID . GetValueOrDefault ( ) ;
try
{
_taxParameterService . Delete ( id , payrollTypeId ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( ) ;
}
[HttpPost]
[Route("saveTaxReturn")]
public ActionResult SaveTaxReturn ( TaxReturn item )
{
int id = 0 ;
try
{
CurrentUser currentUser = CurrentUser . GetCurrentUser ( HttpContext . User ) ;
if ( item . IsNew & & currentUser . UserType = = EnumUserType . Employee )
{
TaxParameter taxParam = _taxParameterService . Get ( item . TaxParamID ) ;
if ( taxParam ! = null & & taxParam . IsAllowTaxReturnForESS = = true
& & taxParam . TaxReturnSubmitDeadline ! = null & & DateTime . Today > taxParam . TaxReturnSubmitDeadline . Value . Date )
{
throw new Exception ( "Tax return submission deadline (" + taxParam . TaxReturnSubmitDeadline . Value . ToString ( "dd MMM yyyy" ) + ") has passed. You can no longer submit new tax acknowledgement." ) ;
}
}
id = _taxReturnService . Save ( item ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( id ) ;
}
[HttpGet("getTaxReturnByTaxParamId/{taxParamId}")]
public ActionResult GetTaxReturnByTaxParamId ( int taxParamId )
{
DataSet ds = new DataSet ( ) ;
try
{
ds = _taxReturnService . GetByTaxParamId ( taxParamId ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( ds . Tables [ 0 ] ) ;
}
[HttpGet("getTaxReturnByTaxParamIdandReturnStatus/{taxParamId}/{returnStatus}")]
public ActionResult getTaxReturnByTaxParamIdandReturnStatus ( int taxParamId , EnumReturnStatus returnStatus )
{
DataSet ds = new DataSet ( ) ;
try
{
ds = _taxReturnService . GetByTaxParamId ( taxParamId , returnStatus ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( ds . Tables [ 0 ] ) ;
}
[HttpGet("UpdateTaxReturnStatus/{taxreturnID}/{returnStatus}/{rejectReason}")]
public ActionResult UpdateTaxReturnStatus ( int taxreturnID , EnumReturnStatus returnStatus , string rejectReason )
{
CurrentUser currentUser = CurrentUser . GetCurrentUser ( HttpContext . User ) ;
TaxReturn oTaxReturn = new TaxReturn ( ) ;
int id = 0 ;
try
{
oTaxReturn = _taxReturnService . Get ( taxreturnID ) ;
if ( oTaxReturn ! = null )
{
oTaxReturn . ReturnStatus = returnStatus ;
oTaxReturn . ModifiedBy = ( int ) currentUser . UserID ;
oTaxReturn . ModifiedDate = DateTime . Now ;
oTaxReturn . AcknowledgedBy = ( int ) currentUser . UserID ;
oTaxReturn . AcknowledgedDate = DateTime . Now ;
if ( oTaxReturn . ReturnStatus = = EnumReturnStatus . Rejected )
{
oTaxReturn . Reason = rejectReason ;
}
id = _taxReturnService . UpdateTaxReturnStatus ( oTaxReturn ) ;
}
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( ) ;
}
[HttpGet("getTaxReturnByEmpIdTaxParamId/{empId}/{taxParamId}")]
public ActionResult GetTaxReturnByEmpIdTaxParamId ( int empId , int taxParamId )
{
TaxReturn item = new TaxReturn ( ) ;
try
{
item = _taxReturnService . Get ( empId , taxParamId ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( item ) ;
}
[HttpGet("getTaxReturnByEmpId/{empId}")]
public ActionResult GetTaxReturnByEmpId ( int empId )
{
DataSet ds = new DataSet ( ) ;
try
{
ds = _taxReturnService . GetTaxReturnByEmpId ( empId ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( ds . Tables [ 0 ] ) ;
}
[HttpGet("getTaxFile/{empId}/{referenceId}/{type}")]
public ActionResult GetTaxFile ( int empId , int referenceId , EnumTaxAttachmentType type )
{
TaxReturnAttachment attachment = new TaxReturnAttachment ( ) ;
try
{
attachment = _taxReturnService . GetFile ( empId , referenceId , type ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( attachment ) ;
}
[HttpGet("GetAllFileByReferenceIds/{referenceIds}")]
public ActionResult GetAllFileByReferenceIds ( string referenceIds )
{
List < TaxReturnAttachment > allAttachment = new List < TaxReturnAttachment > ( ) ;
try
{
allAttachment = _taxReturnService . GetAllFileByReferenceIds ( referenceIds ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( allAttachment ) ;
}
[HttpPost("uploadTaxFile")]
2026-11-08 11:31:05 +06:00
//[AllowAnonymous]
2026-11-03 13:06:00 +06:00
public ActionResult UploadEmpFile ( )
{
TaxReturnAttachment item = new TaxReturnAttachment ( ) ;
string base64String = "" ;
try
{
var fdata = Request . Form . Files [ "empFile" ] ;
//Upload Image
item . EmployeeID = Convert . ToInt32 ( Request . Form [ "empId" ] ) ;
item . ReferenceID = Convert . ToInt32 ( Request . Form [ "referenceId" ] ) ;
item . FileType = ( EnumTaxAttachmentType ) Convert . ToInt32 ( Request . Form [ "fileType" ] ) ;
using ( var ms = new MemoryStream ( ) )
{
fdata . CopyTo ( ms ) ;
item . FileData = ms . ToArray ( ) ;
item . FileName = item . FileType . ToString ( ) + $"-{item.ReferenceID}{Path.GetExtension(fdata.FileName)}" ;
byte [ ] textAsBytes = ms . ToArray ( ) ;
this . _taxReturnService . UploadFile ( item ) ;
base64String = Convert . ToBase64String ( textAsBytes ) ;
}
}
catch ( Exception ex )
{
return StatusCode ( StatusCodes . Status500InternalServerError , ex . Message ) ;
}
return Ok ( base64String ) ;
}
[HttpPost("SaveTaxInvestment")]
[AllowAnonymous]
public ActionResult SaveTaxInvestment ( EmployeeTaxInvestment item )
{
string connectionString = _config . GetSection ( "dbSettings" ) . GetSection ( "SqlCommandConnection" ) . Value ;
string base64String = "" ;
try
{
if ( item . TaxAttachment ! = null )
{
if ( item . TaxAttachment . ID < = 0 & & item . TaxAttachment . PreviousFileTobase64 ! = null )
{
string [ ] items = item . TaxAttachment . PreviousFileTobase64 . Split ( new char [ ] { ',' , ' ' } , StringSplitOptions . None ) ;
byte [ ] newBytes = Convert . FromBase64String ( items [ 1 ] ) ;
item . TaxAttachment . FileAsByteArray = newBytes ;
//item.TaxAttachment.FileType = (EnumTaxAttachment)Convert.ToInt32(EnumTaxAttachment.Investment);
//TaxAttachmentDA.Insert(item.TaxAttachment, connectionString);
}
}
}
catch ( Exception ex )
{
return StatusCode ( StatusCodes . Status500InternalServerError , ex . Message ) ;
}
return Ok ( base64String ) ;
}
// EmpTaxAit
[HttpGet("getTaxAitById/{id}")]
public ActionResult GetTaxAitById ( int id )
{
EmpTaxAit item = new EmpTaxAit ( ) ;
try
{
item = _empTaxAitService . Get ( id ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( item ) ;
}
[HttpGet("getTaxAitAll")]
public ActionResult GetTaxAitAll ( )
{
List < EmpTaxAit > items = new List < EmpTaxAit > ( ) ;
try
{
items = _empTaxAitService . GetAll ( ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( items ) ;
}
[HttpGet("getTaxAitByEmpId/{empId}")]
public ActionResult GetTaxAitByEmpId ( int empId )
{
List < EmpTaxAit > items = new List < EmpTaxAit > ( ) ;
try
{
items = _empTaxAitService . GetByEmpId ( empId ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( items ) ;
}
[HttpGet("getTaxAitByEffectForAdmin/{taxParamId}/{entryFrom}/{taxEffect}/{taxEffectB}")]
public ActionResult getTaxAitByEffectForAdmin ( int taxParamId , int entryFrom , int taxEffect , EnumTaxAITInvestment taxEffectB )
{
List < EmpTaxAit > items = new List < EmpTaxAit > ( ) ;
EmpTaxAitService service = new EmpTaxAitService ( ) ;
try
{
items = service . GetByTaxParamIdEffectForAdmin ( taxParamId , entryFrom , taxEffectB ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( items ) ;
}
[HttpGet("getTaxAitForAdmin/{taxParamId}/{entryFrom}/{taxEffect}")]
public ActionResult GetTaxAitForAdmin ( int taxParamId , int entryFrom , int taxEffect )
{
List < EmpTaxAit > items = new List < EmpTaxAit > ( ) ;
try
{
items = _empTaxAitService . GetByTaxParamIdForAdmin ( taxParamId , entryFrom , taxEffect ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( items ) ;
}
[HttpGet("getTaxAitByTaxParamIdAndEmpId/{taxParamId}/{empId}")]
public ActionResult GetTaxAitByTaxParamIdAndEmpId ( int taxParamId , int empId )
{
List < EmpTaxAit > items = new List < EmpTaxAit > ( ) ;
try
{
items = _empTaxAitService . GetByTaxParamIdAndEmpId ( taxParamId , empId ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( items ) ;
}
[HttpPost("saveTaxAit")]
public ActionResult SaveTaxAit ( EmpTaxAit item )
{
string connectionString = _config . GetSection ( "dbSettings" ) . GetSection ( "SqlCommandConnection" ) . Value ;
int id ;
CurrentUser currentUser = CurrentUser . GetCurrentUser ( HttpContext . User ) ;
bool isNew = item . IsNew ;
try
{
if ( item . IsNew = = true )
{
if ( item . EntryFrom = = EnumTaxInvestment . ESS )
{
TaxParameter taxParam = _taxParameterService . Get ( item . TaxParamId ) ;
if ( taxParam ! = null & & taxParam . IsAllowAITForESS = = true
& & taxParam . AITSubmitDeadline ! = null & & DateTime . Today > taxParam . AITSubmitDeadline . Value . Date )
{
throw new Exception ( "AIT submission deadline (" + taxParam . AITSubmitDeadline . Value . ToString ( "dd MMM yyyy" ) + ") has passed. You can no longer submit new AIT." ) ;
}
}
item . CreatedBy = currentUser . UserID ;
item . CreatedDate = DateTime . Today ;
//if (item.AitAttachment != null)
//{
// if (item.AitAttachment.ID <= 0 && item.AitAttachment.PreviousFileTobase64 != null)
// {
// string[] items = item.AitAttachment.PreviousFileTobase64.Split(new char[] { ',', ' ' }, StringSplitOptions.None);
// byte[] newBytes = Convert.FromBase64String(items[1]);
// item.AitAttachment.FileAsByteArray = newBytes;
// item.AitAttachment.ConnectionString = connectionString;
// }
//}
if ( item . AitAttachments ! = null & & item . AitAttachments . Count > 0 )
{
foreach ( var attachment in item . AitAttachments )
{
if ( attachment . ID < = 0 & &
! string . IsNullOrWhiteSpace ( attachment . PreviousFileTobase64 ) )
{
string base64 = attachment . PreviousFileTobase64 ;
// Remove data URL prefix:
// data:application/pdf;base64,JVBERi0x...
if ( base64 . Contains ( "," ) )
{
base64 = base64 . Substring ( base64 . IndexOf ( ',' ) + 1 ) ;
}
attachment . FileAsByteArray = Convert . FromBase64String ( base64 ) ;
attachment . ConnectionString = connectionString ;
}
}
}
}
else
{
PayrollType payrollType = _payrollTypeService . Get ( ( int ) currentUser . PayrollTypeID ) ;
bool isSalaryProcessed = new IncomeTaxService ( ) . hasTaxDataInSalaryTemp ( item . EmployeeId ) ;
if ( isSalaryProcessed & & item . TaxEffectDone = = EnumTaxAITInvestment . Approve )
{
throw new Exception ( "Can not approve AIT data as salary already processed !" ) ;
}
item . ModifiedBy = currentUser . UserID ;
item . ModifiedDate = DateTime . Today ;
if ( item . TaxEffectDone = = EnumTaxAITInvestment . Reject )
{
item . ActionDate = DateTime . Now ;
}
}
id = _empTaxAitService . Save ( item ) ;
if ( id ! = 0 & & isNew = = false )
{
Employee emp = new Employee ( ) ;
EmployeeService employeeService = new EmployeeService ( ) ;
emp = employeeService . Get ( item . EmployeeId ) ;
string email = emp . EmailAddress ;
string name = emp . Name ;
string status = null ;
if ( item . TaxEffectDone = = EnumTaxAITInvestment . Approve )
{
status = "Approve" ;
}
else
{
status = "Reject" ;
}
if ( emp . EmailAddress ! = "" )
{
var builder = new ConfigurationBuilder ( ) . SetBasePath ( Directory . GetCurrentDirectory ( ) ) . AddJsonFile ( "appsettings.json" ) ;
IConfiguration Configuration = builder . Build ( ) ;
string LiveLink = Configuration . GetSection ( "AppSettings" ) [ "LiveLink" ] ;
EmailSettings emailSettings = _emailSettings . Value ;
MailSender mailSender = new MailSender ( ) ;
mailSender . AddTo ( emp . EmailAddress ) ;
mailSender . Subject = "Advance Income Tax Admin Approval" ;
mailSender . Body = $ @ "<p>Dear {name},</p>
< p > Your Advance Income Tax has been { status } . < / p >
< p > Please click on this link : { LiveLink } to access Luminous Self - service for details . < / p >
< p > Thank you . < / p > ";
mailSender . ThreadSendMail ( emailSettings ) ;
}
}
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( id ) ;
}
[HttpGet("getAllEmployeeTaxParameter")]
public ActionResult getAllEmployeeTaxParameter ( )
{
List < Employee > employees = new List < Employee > ( ) ;
EmployeeService empService = new EmployeeService ( ) ;
try
{
// employees = empService.GetEmpTaxAit();
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( employees ) ;
}
[HttpPost("deleteTaxAit")]
public ActionResult DeleteTaxAit ( EmpTaxAit item )
{
try
{
_empTaxAitService . Delete ( item . ID ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( ) ;
}
[HttpPost]
[Route("getAitAttachment")]
public ActionResult getAitAttachment ( dynamic data )
{
var item = Newtonsoft . Json . JsonConvert . DeserializeObject ( Convert . ToString ( data ) ) ;
int employeeID = item [ "employeeID" ] . ToObject < int > ( ) ;
EnumTaxAttachment fileType = ( EnumTaxAttachment ) item [ "fileType" ] ;
List < AitAttachment > taxAttachments = new List < AitAttachment > ( ) ;
EmpTaxAitService service = new EmpTaxAitService ( ) ;
try
{
taxAttachments = service . GetTaxAttachment ( employeeID , fileType ) ;
}
catch ( Exception ex )
{
return StatusCode ( StatusCodes . Status500InternalServerError , ex . Message ) ;
}
return Ok ( taxAttachments ) ;
}
[HttpPost]
[Route("getAitAttachmentBYID")]
public ActionResult getAitAttachmentBYID ( dynamic data )
{
var item = Newtonsoft . Json . JsonConvert . DeserializeObject ( Convert . ToString ( data ) ) ;
int ID = item [ "ID" ] . ToObject < int > ( ) ;
int employeeID = item [ "employeeID" ] . ToObject < int > ( ) ;
EnumTaxAttachment fileType = ( EnumTaxAttachment ) item [ "fileType" ] ;
AitAttachment taxAttachments = new AitAttachment ( ) ;
EmpTaxAitService service = new EmpTaxAitService ( ) ;
try
{
taxAttachments = service . GetTaxAttachmentByID ( ID , employeeID , fileType ) ;
}
catch ( Exception ex )
{
return StatusCode ( StatusCodes . Status500InternalServerError , ex . Message ) ;
}
return Ok ( taxAttachments ) ;
}
[HttpGet("calculateRebate")]
public ActionResult CalculateRebate ( )
{
CurrentUser currentUser = CurrentUser . GetCurrentUser ( HttpContext . User ) ;
int employeeId = currentUser . EmployeeID . GetValueOrDefault ( ) ;
var ans = new Object ( ) ;
try
{
PayrollType payrollType = _payrollTypeService . Get ( ( int ) currentUser . PayrollTypeID ) ;
ans = _taxInvestmentService . CalculateRebateTax ( employeeId , ( int ) payrollType . TaxParamID ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( ans ) ;
}
[HttpGet("getTaxAttachment/{referenceId}/{type}")]
public ActionResult GetTaxAttachment ( int referenceId , EnumTaxAttachment type )
{
TaxAttachment attachment = new TaxAttachment ( ) ;
try
{
attachment = _employeeTaxInvestmentService . GetFile ( referenceId , type ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( attachment ) ;
}
[HttpGet("getEmployeeData")]
public ActionResult getEmployeeData ( )
{
List < Employee > EmployeeInfoes = new List < Employee > ( ) ;
try
{
EmployeeInfoes = _employeeService . GetAllEmps ( ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( EmployeeInfoes ) ;
}
[HttpGet("GetEmployeeDataUsingExceptionType/{ExceptionType}")]
public ActionResult GetEmployeeDataUsingExceptionType ( string ExceptionType )
{
List < EmployeeTaxException > dt = new List < EmployeeTaxException > ( ) ;
try
{
dt = _employeeExceptionService . GetEmployeeDataUsingExceptionType ( ExceptionType ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( dt ) ;
}
[HttpGet("GetEmployeeDataUsingPersonType/{ExceptionType}")]
public ActionResult GetEmployeeDataUsingPersonType ( int ExceptionType )
{
List < EmployeeTaxException > dt = new List < EmployeeTaxException > ( ) ;
try
{
dt = _employeeExceptionService . GetEmployeeDataUsingPersonType ( ExceptionType ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( dt ) ;
}
[HttpGet("GetEmployeeDataUsingTaxCircle/{TaxCircleType}")]
public ActionResult GetEmployeeDataUsingTaxCircle ( int TaxCircleType )
{
List < EmployeeTaxException > dt = new List < EmployeeTaxException > ( ) ;
try
{
dt = _employeeExceptionService . GetEmployeeDataUsingTaxCircle ( TaxCircleType ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( dt ) ;
}
[HttpPost]
[Route("UpdateEmployeeByPersonType")]
public ActionResult UpdateEmployeeByPersonType ( List < EmployeeTaxException > EmployeeInfo )
{
try
{
_employeeExceptionService . UpdateEmployeeByPersonType ( EmployeeInfo ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( ) ;
}
[HttpPost]
[Route("UpdateEmployeeByTaxCircle")]
public ActionResult UpdateEmployeeByTaxCircle ( List < EmployeeTaxException > EmployeeInfo )
{
try
{
_employeeExceptionService . UpdateEmployeeByTaxCircle ( EmployeeInfo ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( ) ;
}
[HttpPost]
[Route("GeneratePerquisite")]
public ActionResult GeneratePerquisite ( dynamic data )
{
CurrentUser currentUser = CurrentUser . GetCurrentUser ( HttpContext . User ) ;
var item = Newtonsoft . Json . JsonConvert . DeserializeObject ( Convert . ToString ( data ) ) ;
DateTime fromDate = ( DateTime ) item [ "fromDate" ] . ToObject < DateTime > ( ) ;
DateTime toDate = ( DateTime ) item [ "toDate" ] . ToObject < DateTime > ( ) ;
double exemtedAmount = ( double ) item [ "exemtedAmount" ] . ToObject < double > ( ) ;
double percentage = ( double ) item [ "percentage" ] . ToObject < double > ( ) ;
string sEmpIDs = ( string ) item [ "empIDs" ] . ToObject < string > ( ) ;
int payrolltypeID = currentUser . PayrollTypeID ? ? 0 ;
DataSet oEmpBasicInfos = new DataSet ( ) ;
try
{
var response = new RptIncomeTax ( ) . GenerateTaxperquisite ( fromDate , toDate , exemtedAmount , percentage , sEmpIDs , payrolltypeID ) ;
return Ok ( response ) ;
}
catch ( Exception ex )
{
return StatusCode ( StatusCodes . Status500InternalServerError , ex . Message ) ;
}
}
[HttpGet("GetDistinctTaxItems/{taxParamId}")]
public IActionResult GetDistinctTaxItems ( int taxParamId )
{
CurrentUser currentUser = CurrentUser . GetCurrentUser ( HttpContext . User ) ;
int taxparameterid = 0 ;
if ( currentUser . TaxParamID ! = taxparameterid )
{
taxparameterid = taxParamId ;
}
int newid = 0 ;
var dt = _incomeTaxService . GetDistinctTaxItems ( taxparameterid , ( int ) currentUser . PayrollTypeID ) ;
var result = dt . AsEnumerable ( ) . Select ( row = > new
{
newid = newid + 1 ,
id = newid ,
mergeinto = false ,
mergeditem = false ,
itemgroup = row [ "ITEMCODE" ] ,
itemId = row [ "ITEMID" ] ,
side = row [ "SIDE" ] ,
position = row [ "POSITION" ] ,
description = row [ "DESCRIPTION" ]
} ) . ToList ( ) ;
return Ok ( result ) ;
}
[HttpPost]
[Route("UpdatePosition")]
public IActionResult UpdatePosition ( IncomeTax tax )
{
try
{
CurrentUser currentUser = CurrentUser . GetCurrentUser ( HttpContext . User ) ;
if ( ( int ) currentUser . TaxParamID = = tax . TaxParameterID ) tax . TaxParameterID = 0 ; // as writen query for current year
_incomeTaxService . UpdatePosition ( tax , ( int ) currentUser . PayrollTypeID ) ;
}
catch ( Exception ex )
{
return StatusCode ( StatusCodes . Status500InternalServerError , ex . Message ) ;
}
return Ok ( ) ;
}
[HttpPost]
[Route("RenameTaxItem")]
public async Task < IActionResult > RenameTaxItem (
IncomeTax taxhead )
{
CurrentUser currentUser = CurrentUser . GetCurrentUser ( HttpContext . User ) ;
try
{
this . _incomeTaxService . RenameHead ( taxhead , ( int ) currentUser . PayrollTypeID ) ;
}
catch ( Exception ex )
{
return StatusCode ( StatusCodes . Status500InternalServerError , ex . Message ) ;
}
return Ok ( true ) ;
}
[HttpPost]
[Route("MergeHeads")]
public async Task < IActionResult > MergeHeads (
List < IncomeTax > taxheads )
{
CurrentUser currentUser = CurrentUser . GetCurrentUser ( HttpContext . User ) ;
try
{
this . _incomeTaxService . MergeHeads ( taxheads , ( int ) currentUser . PayrollTypeID ) ;
}
catch ( Exception ex )
{
return StatusCode ( StatusCodes . Status500InternalServerError , ex . Message ) ;
}
return Ok ( true ) ;
}
[HttpGet("getIncomeTaxableMonth/{employeeid}/{taxParameterID}")]
public ActionResult getIncomeTaxableMonth ( int employeeid , int taxParameterID )
{
DataTable oDataTable = new DataTable ( ) ;
try
{
oDataTable = new AdvanceIncomeTaxService ( ) . getIncomeTaxableMonth ( employeeid , taxParameterID ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( oDataTable ) ;
}
[HttpGet("getAITAttachmentsByRefIDs/{referenceIds}")]
public ActionResult GetAITAttachmentsByRefIDs ( string referenceIds )
{
List < AitAttachment > allAttachment = new List < AitAttachment > ( ) ;
try
{
allAttachment = _empTaxAitService . GetAITAttachmentsByRefIDs ( referenceIds ) ;
}
catch ( Exception e )
{
return StatusCode ( StatusCodes . Status500InternalServerError , e . Message ) ;
}
return Ok ( allAttachment ) ;
}
#region Tax Card - mail and download
/// <summary>
/// Mails the tax card of one fiscal year to many employees.
///
/// Same contract as the payslip batch: every selected employee gets a
/// row in MasterEmailLogDetails, including the ones with no address,
/// and a failure on one employee never stops the rest. Returns as soon
/// as the batch is written; the caller follows it through
/// api/emailLog/getLog/{id} and replays failures from
/// api/emailLog/retryFailed/{id}.
/// </summary>
[HttpPost]
[Route("sendTaxCardForMultiple")]
public ActionResult SendTaxCardForMultiple ( dynamic data )
{
CurrentUser currentUser = CurrentUser . GetCurrentUser ( HttpContext . User ) ;
if ( currentUser = = null | | currentUser . PayrollTypeID = = null )
{
return Unauthorized ( new { message = "A signed-in payroll user is required to send tax cards." } ) ;
}
try
{
var item = Newtonsoft . Json . JsonConvert . DeserializeObject ( Convert . ToString ( data ) ) ;
var employees = Newtonsoft . Json . JsonConvert . DeserializeObject ( Convert . ToString ( data . list ) ) ;
int taxParameterID = ( int ) item [ "itemid" ] . ToObject < int > ( ) ;
string subject = ReadOptionalText ( item , "emailSubject" ) ;
string body = ReadOptionalText ( item , "emailBody" ) ;
if ( taxParameterID < = 0 )
{
return BadRequest ( new { message = "Select a fiscal year." } ) ;
}
int payrollTypeID = ( int ) currentUser . PayrollTypeID ;
int systemTaxParamID = currentUser . TaxParamID . GetValueOrDefault ( ) ;
DateTime nextPayProcessDate = currentUser . NextPayProcessDate . GetValueOrDefault ( ) ;
TaxParameter taxParameter = _taxParameterService . Get ( taxParameterID ) ;
string fiscalYear = taxParameter = = null ? string . Empty : taxParameter . FiscalYear ;
// Declared up front rather than inline: `employees` is dynamic,
// so the call is dispatched at runtime and a lambda argument
// would have no type to bind to.
Func < string , string > bodyBuilder = ( name ) = > BuildTaxCardBody ( name , body , fiscalYear ) ;
List < EmailRecipient > recipients = BuildRecipients ( employees , subject , bodyBuilder , taxParameterID ) ;
if ( recipients . Count = = 0 )
{
return BadRequest ( new { message = "No employee was selected." } ) ;
}
EmailDispatchRequest request = new EmailDispatchRequest ( ) ;
request . EmailType = EnumEmailType . TaxCard ;
request . Description = "Tax Card - " + ( string . IsNullOrEmpty ( fiscalYear )
? taxParameterID . ToString ( )
: fiscalYear ) ;
request . PayrollTypeID = payrollTypeID ;
request . ParameterJson = Newtonsoft . Json . JsonConvert . SerializeObject ( new
{
taxParameterId = taxParameterID ,
fiscalYear = fiscalYear ,
payrollTypeId = payrollTypeID
} ) ;
request . UserID = currentUser . UserID ;
request . Recipients = recipients ;
// HRM.DA cannot reference HRM.Report, so the document is built
// here and handed to the dispatcher - the same plug-in point the
// payslip batch uses.
request . AttachmentResolver = ( EmailRecipient recipient ) = >
BuildTaxCardAttachment ( recipient . EmployeeID . GetValueOrDefault ( ) , recipient . EmployeeNo ,
taxParameterID , systemTaxParamID , nextPayProcessDate , payrollTypeID , fiscalYear ) ;
int masterEmailLogID = _emailDispatchService . CreateBatch ( request ) ;
EmailSettings emailSettings = _emailSettings . Value ;
IEmailDispatchService dispatchService = _emailDispatchService ;
EmailLogBackgroundRunner . Run ( ( ) = >
dispatchService . ProcessBatch ( masterEmailLogID , request , emailSettings ) ) ;
return Ok ( new
{
masterEmailLogID = masterEmailLogID ,
totalCount = recipients . Count ,
message = "Sending started for " + recipients . Count + " employee(s)."
} ) ;
}
catch ( Exception ex )
{
return StatusCode ( StatusCodes . Status500InternalServerError , ex . Message ) ;
}
}
/// <summary>
/// Mails a plain message - no attachment - to many employees, logged the
/// same way as every other batch so the failures can still be replayed.
/// </summary>
[HttpPost]
[Route("sendEmailForMultiple")]
public ActionResult SendEmailForMultiple ( dynamic data )
{
CurrentUser currentUser = CurrentUser . GetCurrentUser ( HttpContext . User ) ;
if ( currentUser = = null | | currentUser . PayrollTypeID = = null )
{
return Unauthorized ( new { message = "A signed-in payroll user is required to send mail." } ) ;
}
try
{
var item = Newtonsoft . Json . JsonConvert . DeserializeObject ( Convert . ToString ( data ) ) ;
var employees = Newtonsoft . Json . JsonConvert . DeserializeObject ( Convert . ToString ( data . list ) ) ;
string subject = ReadOptionalText ( item , "emailSubject" ) ;
string body = ReadOptionalText ( item , "emailBody" ) ;
if ( string . IsNullOrWhiteSpace ( subject ) )
{
return BadRequest ( new { message = "Email subject is required." } ) ;
}
Func < string , string > bodyBuilder = ( name ) = > BuildPlainBody ( name , body ) ;
List < EmailRecipient > recipients = BuildRecipients ( employees , subject , bodyBuilder , null ) ;
if ( recipients . Count = = 0 )
{
return BadRequest ( new { message = "No employee was selected." } ) ;
}
EmailDispatchRequest request = new EmailDispatchRequest ( ) ;
request . EmailType = EnumEmailType . GeneralMail ;
request . Description = subject . Length > 200 ? subject . Substring ( 0 , 200 ) : subject ;
request . PayrollTypeID = ( int ) currentUser . PayrollTypeID ;
request . UserID = currentUser . UserID ;
request . Recipients = recipients ;
// Nothing to attach, so nothing to preserve either.
request . PreserveAttachment = false ;
int masterEmailLogID = _emailDispatchService . CreateBatch ( request ) ;
EmailSettings emailSettings = _emailSettings . Value ;
IEmailDispatchService dispatchService = _emailDispatchService ;
EmailLogBackgroundRunner . Run ( ( ) = >
dispatchService . ProcessBatch ( masterEmailLogID , request , emailSettings ) ) ;
return Ok ( new
{
masterEmailLogID = masterEmailLogID ,
totalCount = recipients . Count ,
message = "Sending started for " + recipients . Count + " employee(s)."
} ) ;
}
catch ( Exception ex )
{
return StatusCode ( StatusCodes . Status500InternalServerError , ex . Message ) ;
}
}
/// <summary>
/// Zips the tax cards of the selected employees and returns the archive.
///
/// Built entirely in memory: nothing is written to the web root, so two
/// operators downloading the same fiscal year cannot overwrite or delete
/// each other's files, and an interrupted run leaves nothing behind.
/// An employee whose card cannot be produced is skipped rather than
/// failing the whole download; the response header X-Skipped-Employees
/// carries their employee numbers.
/// </summary>
[HttpPost]
[Route("DownloadTaxCardForMultiple")]
public ActionResult DownloadTaxCardForMultiple ( dynamic data )
{
CurrentUser currentUser = CurrentUser . GetCurrentUser ( HttpContext . User ) ;
if ( currentUser = = null | | currentUser . PayrollTypeID = = null )
{
return Unauthorized ( new { message = "A signed-in payroll user is required to download tax cards." } ) ;
}
try
{
var item = Newtonsoft . Json . JsonConvert . DeserializeObject ( Convert . ToString ( data ) ) ;
var employees = Newtonsoft . Json . JsonConvert . DeserializeObject ( Convert . ToString ( data . list ) ) ;
int taxParameterID = ( int ) item [ "itemid" ] . ToObject < int > ( ) ;
if ( taxParameterID < = 0 )
{
return BadRequest ( new { message = "Select a fiscal year." } ) ;
}
int payrollTypeID = ( int ) currentUser . PayrollTypeID ;
int systemTaxParamID = currentUser . TaxParamID . GetValueOrDefault ( ) ;
DateTime nextPayProcessDate = currentUser . NextPayProcessDate . GetValueOrDefault ( ) ;
TaxParameter taxParameter = _taxParameterService . Get ( taxParameterID ) ;
string fiscalYear = taxParameter = = null ? string . Empty : taxParameter . FiscalYear ;
List < string > skipped = new List < string > ( ) ;
int added = 0 ;
using ( MemoryStream memoryStream = new MemoryStream ( ) )
{
using ( ZipArchive archive = new ZipArchive ( memoryStream , ZipArchiveMode . Create , true ) )
{
foreach ( var employee in employees )
{
int employeeID = Convert . ToInt32 ( employee . employeeID ) ;
string employeeNo = Convert . ToString ( employee . employeeNo ) ;
EmailAttachmentInfo card ;
try
{
card = BuildTaxCardAttachment ( employeeID , employeeNo , taxParameterID ,
systemTaxParamID , nextPayProcessDate , payrollTypeID , fiscalYear ) ;
}
catch ( Exception )
{
skipped . Add ( employeeNo ) ;
continue ;
}
if ( card = = null | | card . Data = = null | | card . Data . Length = = 0 )
{
skipped . Add ( employeeNo ) ;
continue ;
}
ZipArchiveEntry zipEntry = archive . CreateEntry ( card . FileName ) ;
using ( Stream entryStream = zipEntry . Open ( ) )
{
entryStream . Write ( card . Data , 0 , card . Data . Length ) ;
}
added + + ;
}
}
if ( added = = 0 )
{
return BadRequest ( new
{
message = "No tax card could be produced for the selected employee(s) in "
+ ( string . IsNullOrEmpty ( fiscalYear ) ? "this fiscal year" : fiscalYear ) + "."
} ) ;
}
if ( skipped . Count > 0 )
{
Response . Headers . Append ( "X-Skipped-Employees" , string . Join ( "," , skipped ) ) ;
Response . Headers . Append ( "Access-Control-Expose-Headers" , "X-Skipped-Employees" ) ;
}
string zipName = "TaxCard_" + SafeFileNamePart ( fiscalYear ) + "_" + payrollTypeID + ".zip" ;
return File ( memoryStream . ToArray ( ) , "application/zip" , zipName ) ;
}
}
catch ( Exception ex )
{
return StatusCode ( StatusCodes . Status500InternalServerError , ex . Message ) ;
}
}
#endregion
#region Tax Certificate - mail and download
/// <summary>
/// Mails the tax certificate of one fiscal year to many employees.
///
/// Same contract as the payslip and tax card batches: every selected
/// employee gets a row in MasterEmailLogDetails, the ones with no
/// address are logged as Skipped, and one employee's failure never
/// stops the rest.
/// </summary>
[HttpPost]
[Route("sendTaxCertificateForMultiple")]
public ActionResult SendTaxCertificateForMultiple ( dynamic data )
{
CurrentUser currentUser = CurrentUser . GetCurrentUser ( HttpContext . User ) ;
if ( currentUser = = null | | currentUser . PayrollTypeID = = null )
{
return Unauthorized ( new { message = "A signed-in payroll user is required to send tax certificates." } ) ;
}
try
{
var item = Newtonsoft . Json . JsonConvert . DeserializeObject ( Convert . ToString ( data ) ) ;
var employees = Newtonsoft . Json . JsonConvert . DeserializeObject ( Convert . ToString ( data . list ) ) ;
int taxParameterID = ( int ) item [ "itemid" ] . ToObject < int > ( ) ;
string subject = ReadOptionalText ( item , "emailSubject" ) ;
string body = ReadOptionalText ( item , "emailBody" ) ;
if ( taxParameterID < = 0 )
{
return BadRequest ( new { message = "Select a fiscal year." } ) ;
}
int payrollTypeID = ( int ) currentUser . PayrollTypeID ;
int systemTaxParamID = currentUser . TaxParamID . GetValueOrDefault ( ) ;
// Which of the two certificate layouts this installation uses.
// Read once per batch, not once per employee - it is a
// system-wide switch, and re-reading it would be one extra
// query per recipient.
bool empWiseChallan = IsEmpWiseChallan ( ) ;
TaxParameter taxParameter = _taxParameterService . Get ( taxParameterID ) ;
string fiscalYear = taxParameter = = null ? string . Empty : taxParameter . FiscalYear ;
Func < string , string > bodyBuilder = ( name ) = > BuildTaxCertificateBody ( name , body , fiscalYear ) ;
List < EmailRecipient > recipients = BuildRecipients ( employees , subject , bodyBuilder , taxParameterID ) ;
if ( recipients . Count = = 0 )
{
return BadRequest ( new { message = "No employee was selected." } ) ;
}
EmailDispatchRequest request = new EmailDispatchRequest ( ) ;
request . EmailType = EnumEmailType . TaxCertificate ;
request . Description = "Tax Certificate - " + ( string . IsNullOrEmpty ( fiscalYear )
? taxParameterID . ToString ( )
: fiscalYear ) ;
request . PayrollTypeID = payrollTypeID ;
request . ParameterJson = Newtonsoft . Json . JsonConvert . SerializeObject ( new
{
taxParameterId = taxParameterID ,
fiscalYear = fiscalYear ,
payrollTypeId = payrollTypeID ,
empWiseChallan = empWiseChallan
} ) ;
request . UserID = currentUser . UserID ;
request . Recipients = recipients ;
request . AttachmentResolver = ( EmailRecipient recipient ) = >
BuildTaxCertificateAttachment ( recipient . EmployeeID . GetValueOrDefault ( ) , recipient . EmployeeNo ,
taxParameterID , systemTaxParamID , payrollTypeID , fiscalYear , empWiseChallan ) ;
int masterEmailLogID = _emailDispatchService . CreateBatch ( request ) ;
EmailSettings emailSettings = _emailSettings . Value ;
IEmailDispatchService dispatchService = _emailDispatchService ;
EmailLogBackgroundRunner . Run ( ( ) = >
dispatchService . ProcessBatch ( masterEmailLogID , request , emailSettings ) ) ;
return Ok ( new
{
masterEmailLogID = masterEmailLogID ,
totalCount = recipients . Count ,
message = "Sending started for " + recipients . Count + " employee(s)."
} ) ;
}
catch ( Exception ex )
{
return StatusCode ( StatusCodes . Status500InternalServerError , ex . Message ) ;
}
}
/// <summary>
/// Zips the tax certificates of the selected employees. Built in memory
/// for the same reasons as the tax card download - no temp folder to
/// collide over or leave behind.
/// </summary>
[HttpPost]
[Route("DownloadTaxCertificateForMultiple")]
public ActionResult DownloadTaxCertificateForMultiple ( dynamic data )
{
CurrentUser currentUser = CurrentUser . GetCurrentUser ( HttpContext . User ) ;
if ( currentUser = = null | | currentUser . PayrollTypeID = = null )
{
return Unauthorized ( new
{
message = "A signed-in payroll user is required to download tax certificates."
} ) ;
}
try
{
var item = Newtonsoft . Json . JsonConvert . DeserializeObject ( Convert . ToString ( data ) ) ;
var employees = Newtonsoft . Json . JsonConvert . DeserializeObject ( Convert . ToString ( data . list ) ) ;
int taxParameterID = ( int ) item [ "itemid" ] . ToObject < int > ( ) ;
if ( taxParameterID < = 0 )
{
return BadRequest ( new { message = "Select a fiscal year." } ) ;
}
int payrollTypeID = ( int ) currentUser . PayrollTypeID ;
int systemTaxParamID = currentUser . TaxParamID . GetValueOrDefault ( ) ;
bool empWiseChallan = IsEmpWiseChallan ( ) ;
TaxParameter taxParameter = _taxParameterService . Get ( taxParameterID ) ;
string fiscalYear = taxParameter = = null ? string . Empty : taxParameter . FiscalYear ;
List < string > skipped = new List < string > ( ) ;
int added = 0 ;
using ( MemoryStream memoryStream = new MemoryStream ( ) )
{
using ( ZipArchive archive = new ZipArchive ( memoryStream , ZipArchiveMode . Create , true ) )
{
foreach ( var employee in employees )
{
int employeeID = Convert . ToInt32 ( employee . employeeID ) ;
string employeeNo = Convert . ToString ( employee . employeeNo ) ;
EmailAttachmentInfo certificate ;
try
{
certificate = BuildTaxCertificateAttachment ( employeeID , employeeNo , taxParameterID ,
systemTaxParamID , payrollTypeID , fiscalYear , empWiseChallan ) ;
}
catch ( Exception )
{
skipped . Add ( employeeNo ) ;
continue ;
}
if ( certificate = = null | | certificate . Data = = null | | certificate . Data . Length = = 0 )
{
skipped . Add ( employeeNo ) ;
continue ;
}
ZipArchiveEntry zipEntry = archive . CreateEntry ( certificate . FileName ) ;
using ( Stream entryStream = zipEntry . Open ( ) )
{
entryStream . Write ( certificate . Data , 0 , certificate . Data . Length ) ;
}
added + + ;
}
}
if ( added = = 0 )
{
return BadRequest ( new
{
message = "No tax certificate could be produced for the selected employee(s) in "
+ ( string . IsNullOrEmpty ( fiscalYear ) ? "this fiscal year" : fiscalYear ) + "."
} ) ;
}
if ( skipped . Count > 0 )
{
Response . Headers . Append ( "X-Skipped-Employees" , string . Join ( "," , skipped ) ) ;
Response . Headers . Append ( "Access-Control-Expose-Headers" , "X-Skipped-Employees" ) ;
}
string zipName = "TaxCertificate_" + SafeFileNamePart ( fiscalYear ) + "_" + payrollTypeID + ".zip" ;
return File ( memoryStream . ToArray ( ) , "application/zip" , zipName ) ;
}
}
catch ( Exception ex )
{
return StatusCode ( StatusCodes . Status500InternalServerError , ex . Message ) ;
}
}
#endregion
#region Tax Certificate helpers
/// <summary>
/// Produces one employee's tax certificate, picking the same layout the
/// ESS Tax Certificate screen would: ReportController's
/// EnumReportType.TaxCertificate branches on the "empwisechallan" logic
/// setting, and so does this.
/// </summary>
private EmailAttachmentInfo BuildTaxCertificateAttachment ( int employeeID , string employeeNo ,
int taxParameterID , int systemTaxParamID , int payrollTypeID , string fiscalYear , bool empWiseChallan )
{
RptIncomeTax rptIncomeTax = new RptIncomeTax ( ) ;
byte [ ] bytes = empWiseChallan
? rptIncomeTax . ShowTaxCertificateEmpWiseChallan ( employeeID . ToString ( ) , taxParameterID ,
payrollTypeID , systemTaxParamID , "PDF" )
: rptIncomeTax . ShowTaxCertificate ( employeeID . ToString ( ) , taxParameterID ,
payrollTypeID , systemTaxParamID , "PDF" ) ;
if ( bytes = = null | | bytes . Length = = 0 )
{
throw new Exception ( "No tax certificate data found for "
+ ( string . IsNullOrEmpty ( fiscalYear ) ? "the selected fiscal year" : fiscalYear )
+ "." ) ;
}
string fileName = "TaxCertificate_" + SafeFileNamePart ( employeeNo ) + "_"
+ SafeFileNamePart ( fiscalYear ) + ".pdf" ;
return new EmailAttachmentInfo ( fileName , bytes ) ;
}
/// <summary>Whether this installation issues employee-wise challan certificates.</summary>
private static bool IsEmpWiseChallan ( )
{
return new SystemConfigarationService ( ) . GetconfigBooleanValue ( EnumConfigurationType . Logic ,
"incometax" , "empwisechallan" ) ;
}
private static string BuildTaxCertificateBody ( string employeeName , string operatorBody , string fiscalYear )
{
string message = string . IsNullOrWhiteSpace ( operatorBody )
? string . Empty
: "<p>" + operatorBody . Trim ( ) + "</p>" ;
string period = string . IsNullOrWhiteSpace ( fiscalYear )
? "the selected fiscal year"
: "fiscal year " + fiscalYear ;
return $ @ "<p>Dear {employeeName},</p>
{ message }
< p > Please find attached your tax certificate for { period } . < / p >
< p > If you have any questions or notice any discrepancies , feel free to reach out to the HR department . < / p >
< p > Best regards , < br / > Payroll Department < / p > ";
}
#endregion
#region Tax Card helpers
/// <summary>
/// Produces one employee's tax card. Throws when there is nothing to
/// produce, so the dispatcher records the reason against that employee
/// instead of mailing an empty attachment.
/// </summary>
private EmailAttachmentInfo BuildTaxCardAttachment ( int employeeID , string employeeNo , int taxParameterID ,
int systemTaxParamID , DateTime nextPayProcessDate , int payrollTypeID , string fiscalYear )
{
byte [ ] bytes = new RptIncomeTax ( ) . ShowMultipleTaxCard ( employeeID . ToString ( ) , true , taxParameterID ,
systemTaxParamID , nextPayProcessDate , payrollTypeID , "PDF" ) ;
if ( bytes = = null | | bytes . Length = = 0 )
{
throw new Exception ( "No tax card data found for "
+ ( string . IsNullOrEmpty ( fiscalYear ) ? "the selected fiscal year" : fiscalYear )
+ "." ) ;
}
string fileName = "TaxCard_" + SafeFileNamePart ( employeeNo ) + "_"
+ SafeFileNamePart ( fiscalYear ) + ".pdf" ;
return new EmailAttachmentInfo ( fileName , bytes ) ;
}
/// <summary>
/// Maps the posted employee list onto dispatcher recipients. Employees
/// with no address are kept in the list on purpose - the dispatcher logs
/// them as Skipped, which is what makes "who did not get it" complete.
/// </summary>
private static List < EmailRecipient > BuildRecipients ( dynamic employees , string subject ,
Func < string , string > bodyBuilder , int? referenceID )
{
List < EmailRecipient > recipients = new List < EmailRecipient > ( ) ;
foreach ( var employee in employees )
{
EmailRecipient recipient = new EmailRecipient ( ) ;
recipient . EmployeeID = Convert . ToInt32 ( employee . employeeID ) ;
recipient . EmployeeNo = Convert . ToString ( employee . employeeNo ) ;
recipient . EmployeeName = Convert . ToString ( employee . name ) ;
recipient . MailTo = employee . employeeEmail = = null
? string . Empty
: Convert . ToString ( employee . employeeEmail ) ;
recipient . Subject = subject ;
recipient . Body = bodyBuilder ( recipient . EmployeeName ) ;
recipient . ReferenceID = referenceID ;
recipients . Add ( recipient ) ;
}
return recipients ;
}
private static string BuildTaxCardBody ( string employeeName , string operatorBody , string fiscalYear )
{
string message = string . IsNullOrWhiteSpace ( operatorBody )
? string . Empty
: "<p>" + operatorBody . Trim ( ) + "</p>" ;
string period = string . IsNullOrWhiteSpace ( fiscalYear )
? "the selected fiscal year"
: "fiscal year " + fiscalYear ;
return $ @ "<p>Dear {employeeName},</p>
{ message }
< p > Please find attached your tax card for { period } . < / p >
< p > If you have any questions or notice any discrepancies , feel free to reach out to the HR department . < / p >
< p > Best regards , < br / > Payroll Department < / p > ";
}
private static string BuildPlainBody ( string employeeName , string operatorBody )
{
string message = string . IsNullOrWhiteSpace ( operatorBody )
? string . Empty
: "<p>" + operatorBody . Trim ( ) + "</p>" ;
return $ @ "<p>Dear {employeeName},</p>
{ message }
< p > Best regards , < br / > Payroll Department < / p > ";
}
/// <summary>Reads an optional string field without throwing when it is absent.</summary>
private static string ReadOptionalText ( dynamic item , string fieldName )
{
var field = item [ fieldName ] ;
return field = = null ? string . Empty : ( string ) field . ToObject < string > ( ) ;
}
/// <summary>Keeps a value safe to use inside a file name.</summary>
private static string SafeFileNamePart ( string value )
{
if ( string . IsNullOrWhiteSpace ( value ) )
{
return "NA" ;
}
StringBuilder sb = new StringBuilder ( value . Length ) ;
foreach ( char c in value . Trim ( ) )
{
sb . Append ( Array . IndexOf ( Path . GetInvalidFileNameChars ( ) , c ) > = 0 | | c = = ' ' ? '_' : c ) ;
}
return sb . ToString ( ) ;
}
#endregion
}
}