310 lines
11 KiB
C#
310 lines
11 KiB
C#
|
using Ease.Core.Model;
|
|||
|
using Ease.Core.DataAccess;
|
|||
|
using HRM.BO;
|
|||
|
using Ease.Core.Utility;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Data;
|
|||
|
using Ease.Core;
|
|||
|
using Payroll.Service;
|
|||
|
using System;
|
|||
|
using Org.BouncyCastle.Bcpg.OpenPgp;
|
|||
|
|
|||
|
namespace HRM.DA
|
|||
|
{
|
|||
|
public class TaxInvestmentService : ServiceTemplate, ITaxInvestmentService
|
|||
|
{
|
|||
|
public TaxInvestmentService()
|
|||
|
{
|
|||
|
}
|
|||
|
|
|||
|
private void MapObject(TaxInvestment oTaxInvestment, DataReader oReader)
|
|||
|
{
|
|||
|
base.SetObjectID(oTaxInvestment, oReader.GetInt32("TypeID").Value);
|
|||
|
oTaxInvestment.Code = oReader.GetString("typeCode");
|
|||
|
oTaxInvestment.Name = oReader.GetString("typeName");
|
|||
|
oTaxInvestment.Sequence = oReader.GetInt32("SequenceNo").Value;
|
|||
|
oTaxInvestment.Status = (EnumStatus)oReader.GetInt32("Status").Value;
|
|||
|
oTaxInvestment.CreatedBy = oReader.GetInt32("CreatedBy", 0);
|
|||
|
oTaxInvestment.CreatedDate = oReader.GetDateTime("CreationDate").Value;
|
|||
|
oTaxInvestment.ModifiedBy = oReader.GetInt32("ModifiedBy", 0);
|
|||
|
oTaxInvestment.ModifiedDate = oReader.GetDateTime("ModifiedDate");
|
|||
|
oTaxInvestment.MaxLimit = oReader.GetDouble("MaxLimit", 0);
|
|||
|
|
|||
|
this.SetObjectState(oTaxInvestment, Ease.Core.ObjectState.Saved);
|
|||
|
}
|
|||
|
|
|||
|
protected override T CreateObject<T>(DataReader oReader)
|
|||
|
{
|
|||
|
TaxInvestment oTaxInvestment = new TaxInvestment();
|
|||
|
MapObject(oTaxInvestment, oReader);
|
|||
|
return oTaxInvestment as T;
|
|||
|
}
|
|||
|
|
|||
|
#region Service implementation
|
|||
|
|
|||
|
public TaxInvestment Get(int id)
|
|||
|
{
|
|||
|
TaxInvestment oTaxInvestment = null;
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
DataReader oreader = new DataReader(TaxInvestmentDA.Get(tc, id));
|
|||
|
if (oreader.Read())
|
|||
|
{
|
|||
|
oTaxInvestment = this.CreateObject<TaxInvestment>(oreader);
|
|||
|
}
|
|||
|
|
|||
|
oreader.Close();
|
|||
|
tc.End();
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
#region Handle Exception
|
|||
|
|
|||
|
if (tc != null)
|
|||
|
tc.HandleError();
|
|||
|
ExceptionLog.Write(e);
|
|||
|
throw new ServiceException(e.Message, e);
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
|
|||
|
return oTaxInvestment;
|
|||
|
}
|
|||
|
|
|||
|
public List<TaxInvestment> Get(EnumStatus status)
|
|||
|
{
|
|||
|
List<TaxInvestment> taxInvestments = new List<TaxInvestment>();
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
|
|||
|
DataReader dr = new DataReader(TaxInvestmentDA.Get(tc, status));
|
|||
|
taxInvestments = this.CreateObjects<TaxInvestment>(dr);
|
|||
|
dr.Close();
|
|||
|
|
|||
|
tc.End();
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
#region Handle Exception
|
|||
|
|
|||
|
if (tc != null)
|
|||
|
tc.HandleError();
|
|||
|
ExceptionLog.Write(e);
|
|||
|
|
|||
|
throw new ServiceException(e.Message, e);
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
|
|||
|
return taxInvestments;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
public DataTable GetInfoForAdmin(int taxParamId, int entryFrom, int taxEffect)
|
|||
|
{
|
|||
|
DataTable dt = new DataTable();
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
|
|||
|
dt = TaxInvestmentDA.GetInfoForAdmin(tc, taxParamId, entryFrom, taxEffect);
|
|||
|
|
|||
|
tc.End();
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
#region Handle Exception
|
|||
|
|
|||
|
if (tc != null)
|
|||
|
tc.HandleError();
|
|||
|
ExceptionLog.Write(e);
|
|||
|
|
|||
|
throw new ServiceException(e.Message, e);
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
|
|||
|
return dt;
|
|||
|
}
|
|||
|
|
|||
|
public DataTable GetInvestmentDetailAdmin(int taxParamId)
|
|||
|
{
|
|||
|
DataTable dt = new DataTable();
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
|
|||
|
dt = TaxInvestmentDA.GetInvestmentDetailAdmin(tc, taxParamId);
|
|||
|
|
|||
|
tc.End();
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
#region Handle Exception
|
|||
|
|
|||
|
if (tc != null)
|
|||
|
tc.HandleError();
|
|||
|
ExceptionLog.Write(e);
|
|||
|
|
|||
|
throw new ServiceException(e.Message, e);
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
|
|||
|
return dt;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
public int Save(TaxInvestment oTaxInvestment)
|
|||
|
{
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin(true);
|
|||
|
if (oTaxInvestment.IsNew)
|
|||
|
{
|
|||
|
int id = tc.GenerateID("INVTYPE", "TypeID");
|
|||
|
base.SetObjectID(oTaxInvestment, (id));
|
|||
|
|
|||
|
int seqNo = tc.GenerateID("INVTYPE", "SequenceNo");
|
|||
|
oTaxInvestment.Sequence = seqNo;
|
|||
|
TaxInvestmentDA.Insert(tc, oTaxInvestment);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
TaxInvestmentDA.Update(tc, oTaxInvestment);
|
|||
|
}
|
|||
|
|
|||
|
tc.End();
|
|||
|
return oTaxInvestment.ID;
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
#region Handle Exception
|
|||
|
|
|||
|
if (tc != null)
|
|||
|
tc.HandleError();
|
|||
|
ExceptionLog.Write(e);
|
|||
|
throw new ServiceException(e.Message, e);
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public void Delete(int id)
|
|||
|
{
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin(true);
|
|||
|
TaxInvestmentDA.DeleteInvestment(tc, id);
|
|||
|
tc.End();
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
#region Handle Exception
|
|||
|
|
|||
|
if (tc != null)
|
|||
|
tc.HandleError();
|
|||
|
ExceptionLog.Write(e);
|
|||
|
throw new ServiceException(e.Message, e);
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
public List<(string, string)> CalculateRebateTax(int employeeId, int taxParamId)
|
|||
|
{
|
|||
|
var tupleList = new List<(string, string)>();
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
TaxParameter taxParameter = new TaxParameterService().Get(taxParamId);
|
|||
|
List<IncomeTax> incometaxes =
|
|||
|
new IncomeTaxService().Get(new IncomeTaxService().GetEnumForSalaryIT(employeeId), employeeId,
|
|||
|
taxParamId);
|
|||
|
IncomeTax taxRebate = new IncomeTaxService().Get(incometaxes, employeeId,
|
|||
|
EnumIncomeTaxItemGroup.Investment_Allowed, (int)EnumIncomeTaxItemGroup.Investment_Allowed);
|
|||
|
IncomeTax pf = new IncomeTaxService().Get(incometaxes, employeeId,
|
|||
|
EnumIncomeTaxItemGroup.Company_Contri_PF, (int)EnumIncomeTaxItemGroup.Company_Contri_PF);
|
|||
|
IncomeTax actualInvestment = new IncomeTaxService().Get(incometaxes, employeeId,
|
|||
|
EnumIncomeTaxItemGroup.Investment_Actual, (int)EnumIncomeTaxItemGroup.Investment_Actual);
|
|||
|
//ObjectsTemplate<IncomeTax> currentYearTax = IncomeTax.Get(SessionManager.CurrentEmployee.ID, EnumIncomeTaxDataFrom.ProcessTempData);
|
|||
|
//IncomeTax annualIncome = IncomeTax.Get(currentYearTax, SessionManager.CurrentEmployee.ID, EnumIncomeTaxItemGroup.Investment_Actual, (int)EnumIncomeTaxItemGroup.Investment_Actual);
|
|||
|
bool investmentwithoutPF =
|
|||
|
ConfigurationManager.GetBoolValue("incometax", "investmentwithoutpf", EnumConfigurationType.Logic);
|
|||
|
|
|||
|
double investment = 0;
|
|||
|
double otherAmount = 0;
|
|||
|
double otherInvestment = 0;
|
|||
|
|
|||
|
IncomeTax investmentCapdo;
|
|||
|
if (!investmentwithoutPF)
|
|||
|
{
|
|||
|
investmentCapdo = new IncomeTaxService().Get(incometaxes, employeeId,
|
|||
|
EnumIncomeTaxItemGroup.Annual_Income,
|
|||
|
(int)EnumIncomeTaxItemGroup.Annual_Income);
|
|||
|
if (investmentCapdo != null)
|
|||
|
investment = (investmentCapdo.TotalAmount * taxParameter.MaxInvestPercent) / 100;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
investmentCapdo = new IncomeTaxService().Get(incometaxes, employeeId,
|
|||
|
EnumIncomeTaxItemGroup.Annual_Salary_Income,
|
|||
|
(int)EnumIncomeTaxItemGroup.Annual_Salary_Income);
|
|||
|
if (investmentCapdo != null)
|
|||
|
investment = (investmentCapdo.TotalAmount * taxParameter.MaxInvestPercent) / 100;
|
|||
|
}
|
|||
|
|
|||
|
if (actualInvestment == null && taxRebate !=null)
|
|||
|
{
|
|||
|
otherAmount = taxRebate.TotalAmount - (pf != null ? pf.TotalAmount * 2 : 0.0);
|
|||
|
if (otherAmount < 0) otherAmount = 0;
|
|||
|
otherInvestment = otherAmount;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
otherAmount = actualInvestment.TotalAmount;
|
|||
|
otherInvestment = otherAmount;
|
|||
|
}
|
|||
|
|
|||
|
tupleList = new List<(string, string)>
|
|||
|
{
|
|||
|
("Annual Income", investmentCapdo == null ? "0.0" : GlobalFunctions.TakaFormat(investmentCapdo.TotalAmount)),
|
|||
|
($"{taxParameter.MaxInvestPercent} % of annual taxable income (a)", GlobalFunctions.TakaFormat(investment)),
|
|||
|
("Maximum investment allowed (a)", GlobalFunctions.TakaFormat(taxParameter.MaxInvAmount)),
|
|||
|
("Lower One (a)", GlobalFunctions.TakaFormat(taxRebate.TotalAmount)),
|
|||
|
("PF contribution by Employee (b)", GlobalFunctions.TakaFormat(pf != null ? pf.TotalAmount : 0.0)),
|
|||
|
("PF contribution by Company (c)", GlobalFunctions.TakaFormat(pf != null ? pf.TotalAmount : 0.0)),
|
|||
|
("Other investment to be made by the employee (d=a-b-c)", GlobalFunctions.TakaFormat(otherInvestment))
|
|||
|
};
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
#region Handle Exception
|
|||
|
|
|||
|
if (tc != null)
|
|||
|
tc.HandleError();
|
|||
|
ExceptionLog.Write(e);
|
|||
|
throw new ServiceException(e.Message, e);
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
|
|||
|
return tupleList;
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|