CEL_Payroll/Payroll.BO/Tax/TaxParameter.cs
2024-09-17 14:30:13 +06:00

728 lines
22 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ease.CoreV35;
using Ease.CoreV35.Model;
using Ease.CoreV35.Caching;
using System.Data.Linq.Mapping;
using System.Data;
namespace Payroll.BO
{
#region TaxParameter
[Serializable]
public class TaxParameter : AuditTrailBase
{
#region Cache Store
private static Cache _cache = new Cache(typeof(TaxParameter));
#endregion
#region Constructor
public TaxParameter()
{
_fiscalYear = string.Empty;
_assessmentYear = string.Empty;
_maxInvestPercent = 0;
_maxHRPercent = 0;
_maxHRAmount = 0;
_maxMedicalAmount = 0;
_maxConvAmount = 0;
_maxMedicalPercent = 0;
_maxCPFPercent = 0;
_maxInvExempPercent = 0;
_maxInvAmount = 0;
_minTaxAmount = 0;
_pfIntProjection = 0;
_maxAge = 0;
//_isMonthlyExamtion = false;
_TaxParameterSlabs = null;
_InvestmentActiveMonth = DateTime.MinValue;
}
#endregion
#region Properties
#region fiscalYear : string
private string _fiscalYear;
public string FiscalYear
{
get { return _fiscalYear; }
set
{
base.OnPropertyChange<string>("fiscalYear", _fiscalYear, value);
_fiscalYear = value;
}
}
public DateTime FiscalyearDatefrom
{
get
{
return new DateTime(Convert.ToInt32(_fiscalYear.Substring(0, 4)), 7, 1);
}
}
public DateTime FiscalyearDateTo
{
get
{
return new DateTime(Convert.ToInt32(_fiscalYear.Substring(5, 4)), 6, 30);
}
}
#endregion
#region assessmentYear : string
private string _assessmentYear;
public string AssessmentYear
{
get { return _assessmentYear; }
set
{
base.OnPropertyChange<string>("assessmentYear", _assessmentYear, value);
_assessmentYear = value;
}
}
#endregion
#region maxInvestPercent : double
private double _maxInvestPercent;
public double MaxInvestPercent
{
get { return _maxInvestPercent; }
set
{
base.OnPropertyChange<double>("maxInvestPercent", _maxInvestPercent, value);
_maxInvestPercent = value;
}
}
#endregion
#region maxHRPercent : double
private double _maxHRPercent;
public double MaxHRPercent
{
get { return _maxHRPercent; }
set
{
base.OnPropertyChange<double>("maxHRPercent", _maxHRPercent, value);
_maxHRPercent = value;
}
}
#endregion
#region maxHRAmount : double
private double _maxHRAmount;
public double MaxHRAmount
{
get { return _maxHRAmount; }
set
{
base.OnPropertyChange<double>("maxHRAmount", _maxHRAmount, value);
_maxHRAmount = value;
}
}
#endregion
#region maxMedicalPercent : double
private double _maxMedicalPercent;
public double MaxMedicalPercent
{
get { return _maxMedicalPercent; }
set
{
base.OnPropertyChange<double>("maxMedicalPercent", _maxMedicalPercent, value);
_maxMedicalPercent = value;
}
}
#endregion
#region MaxMedicalAmount : double
private double _maxMedicalAmount;
public double MaxMedicalAmount
{
get { return _maxMedicalAmount; }
set
{
base.OnPropertyChange<double>("maxMedicalAmount", _maxMedicalAmount, value);
_maxMedicalAmount = value;
}
}
#endregion
#region maxConvAmount : double
private double _maxConvAmount;
public double MaxConvAmount
{
get { return _maxConvAmount; }
set
{
base.OnPropertyChange<double>("maxConvAmount", _maxConvAmount, value);
_maxConvAmount = value;
}
}
#endregion
#region maxCPFPercent : double
private double _maxCPFPercent;
public double MaxCPFPercent
{
get { return _maxCPFPercent; }
set
{
base.OnPropertyChange<double>("maxCPFPercent", _maxCPFPercent, value);
_maxCPFPercent = value;
}
}
#endregion
#region maxInvExempPercent : double
private double _maxInvExempPercent;
public double MaxInvExempPercent
{
get { return _maxInvExempPercent; }
set
{
base.OnPropertyChange<double>("maxInvExempPercent", _maxInvExempPercent, value);
_maxInvExempPercent = value;
}
}
#endregion
#region maxInvAmount : double
private double _maxInvAmount;
public double MaxInvAmount
{
get { return _maxInvAmount; }
set
{
base.OnPropertyChange<double>("maxInvAmount", _maxInvAmount, value);
_maxInvAmount = value;
}
}
#endregion
#region minTaxAmount : double
private double _minTaxAmount;
public double MinTaxAmount
{
get { return _minTaxAmount; }
set
{
base.OnPropertyChange<double>("minTaxAmount", _minTaxAmount, value);
_minTaxAmount = value;
}
}
#endregion
#region pfIntProjection : double
private double _pfIntProjection;
public double PfIntProjection
{
get { return _pfIntProjection; }
set
{
base.OnPropertyChange<double>("pfIntProjection", _pfIntProjection, value);
_pfIntProjection = value;
}
}
#endregion
#region maxAge : double
private double _maxAge;
public double MaxAge
{
get { return _maxAge; }
set
{
base.OnPropertyChange<double>("maxAge", _maxAge, value);
_maxAge = value;
}
}
#endregion
#region InvestmentActiveMonth : DateTime
private DateTime? _InvestmentActiveMonth;
public DateTime? InvestmentActiveMonth
{
get { return _InvestmentActiveMonth; }
set
{
base.OnPropertyChange<DateTime>("InvestmentActiveMonth", _InvestmentActiveMonth, value);
_InvestmentActiveMonth = value;
}
}
#endregion
//#region isMonthlyExamtion : bool
//private bool _isMonthlyExamtion;
//public bool IsMonthlyExamtion
//{
// get { return _isMonthlyExamtion; }
// set
// {
// base.OnPropertyChange<bool>("isMonthlyExamtion", _isMonthlyExamtion, value);
// _isMonthlyExamtion = value;
// }
//}
//#endregion
#region TaxParameterSlab : TaxParameterSlab
private ObjectsTemplate<TaxParameterSlab> _TaxParameterSlabs = null;
public ObjectsTemplate<TaxParameterSlab> TaxParameterSlabs
{
get
{
if (_TaxParameterSlabs == null && !this.ID.IsUnassigned && this.ID.Integer > 0)
{
_TaxParameterSlabs = TaxParameter.GetSlabsByParamID(this.ID);
}
return this._TaxParameterSlabs;
}
set
{
_TaxParameterSlabs = value;
}
}
#endregion
#region Service Factory ITaxParameterService : ITaxParameterService
internal static ITaxParameterService Service
{
get { return Services.Factory.CreateService<ITaxParameterService>(typeof(ITaxParameterService)); }
}
#endregion
#endregion
#region Functions
public static TaxParameter Get(ID nID)
{
TaxParameter oTaxParameter = null;
#region Cache Header
oTaxParameter = (TaxParameter)_cache["Get", nID];
if (oTaxParameter != null)
return oTaxParameter;
#endregion
oTaxParameter = TaxParameter.Service.Get(nID);
#region Cache Footer
_cache.Add(oTaxParameter, "Get", nID);
#endregion
return oTaxParameter;
}
//Tax Parameter From Old Table
public static TaxParameter GetOldTaxParameter(ID nID)
{
TaxParameter oTaxParameter = null;
#region Cache Header
oTaxParameter = (TaxParameter)_cache["GetOldTaxParameter", nID];
if (oTaxParameter != null)
return oTaxParameter;
#endregion
oTaxParameter = TaxParameter.Service.GetOldTaxParameter(nID);
#region Cache Footer
_cache.Add(oTaxParameter, "GetOldTaxParameter", nID);
#endregion
return oTaxParameter;
}
public static TaxParameter Get(string assessmentYear)
{
TaxParameter oTaxParameter = null;
oTaxParameter = TaxParameter.Service.Get(assessmentYear);
return oTaxParameter;
}
public double GetSlabTotal()
{
double amount = 0;
foreach (TaxParameterSlab item in _TaxParameterSlabs)
{
amount = amount + item.IncomeAmount;
}
return amount;
}
public static ObjectsTemplate<TaxParameter> Get()
{
#region Cache Header
ObjectsTemplate<TaxParameter> taxParameters = _cache["Get"] as ObjectsTemplate<TaxParameter>;
if (taxParameters != null)
return taxParameters;
#endregion
try
{
taxParameters = Service.Get();
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(taxParameters, "Get");
#endregion
return taxParameters;
}
public static ObjectsTemplate<TaxParameter> Get(bool IsCurrentFY)
{
#region Cache Header
ObjectsTemplate<TaxParameter> taxParameters = _cache["Get", IsCurrentFY] as ObjectsTemplate<TaxParameter>;
if (taxParameters != null)
return taxParameters;
#endregion
try
{
taxParameters = Service.Get(IsCurrentFY, Payroll.BO.SystemInformation.CurrentSysInfo.PayrollTypeID.Integer);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(taxParameters, "Get", IsCurrentFY);
#endregion
return taxParameters;
}
//Tax Card From Old Table
public static DataTable GetOldTaxCard(bool IsCurrentFY)
{
DataTable dtTaxCard = new DataTable();
try
{
dtTaxCard = Service.GetOldTaxCard(IsCurrentFY, Payroll.BO.SystemInformation.CurrentSysInfo.PayrollTypeID.Integer);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
return dtTaxCard;
}
public static DataTable GetFiscalYearFromOldTable()
{
DataTable dtFiscalYears = new DataTable();
try
{
dtFiscalYears = Service.GetFiscalYearFromOldTable(SystemInformation.CurrentSysInfo.PayrollTypeID);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
return dtFiscalYears;
}
public static ObjectsTemplate<TaxParameterSlab> GetTaxSlabs(ID nTaxParamID, EnumTaxSlabType TaxType)
{
#region Cache Header
ObjectsTemplate<TaxParameterSlab> taxParamSlabs = _cache["GetTaxSlabs", nTaxParamID, TaxType] as ObjectsTemplate<TaxParameterSlab>;
if (taxParamSlabs != null)
return taxParamSlabs;
#endregion
try
{
taxParamSlabs = Service.GetTaxSlabs(nTaxParamID, TaxType);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(taxParamSlabs, "GetTaxSlabs", nTaxParamID, TaxType);
#endregion
return taxParamSlabs;
}
public static DataSet GetTSByParamAndType(ID nTaxParamID, EnumTaxSlabType TaxType)
{
DataSet taxParamSlabs = null;
try
{
taxParamSlabs = Service.GetTSByParamAndType(nTaxParamID, TaxType);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
return taxParamSlabs;
}
public static ObjectsTemplate<TaxParameterSlab> GetEmployeeSlab(TaxParameter parameter, Employee employee)
{
foreach (TaxParameterSlab item in parameter.TaxParameterSlabs)
{
item.SlabTaxAmount = 0;
item.SlabTaxableAmount = 0;
}
ObjectsTemplate<TaxParameterSlab> employeeSlab = null;
EnumTaxSlabType SlabType = EnumTaxSlabType.Male;
if (employee.PersonType == EnumPersonType.Disable)
SlabType = EnumTaxSlabType.Disable;
else if (employee.PersonType == EnumPersonType.Freedom_Fighter)
SlabType = EnumTaxSlabType.Freedom_Fighter;
else
{
if (employee.Gender == EnumGender.Female)
SlabType = EnumTaxSlabType.Female;
else
{
SlabType = EnumTaxSlabType.Male;
//int NoOfMonth = Ease.CoreV35.Utility.Global.DateFunctions.DateDiff("m",
// employee.BirthDate, SystemInformation.CurrentSysInfo.TaxYearEndDate);
//int NoOfYear = NoOfMonth / 12;
//if (NoOfYear >= parameter.MaxAge) SlabType = EnumTaxSlabType.Age;
}
}
employeeSlab = new ObjectsTemplate<TaxParameterSlab>();
foreach (TaxParameterSlab item in parameter.TaxParameterSlabs)
{
if (item.ParamType == SlabType)
employeeSlab.Add(item);
}
return employeeSlab;
}
public static ObjectsTemplate<TaxParameterSlab> CalculateTaxOnSlab(TaxParameter parameter, Employee emp, double taxableIncome)
{
ObjectsTemplate<TaxParameterSlab> empTaxSlabs = TaxParameter.GetEmployeeSlab(parameter, emp);
if (empTaxSlabs == null || empTaxSlabs.Count == 0) throw new ServiceException("Employee Tax Slabs not found; Employee No:" + emp.EmployeeNo);
int index = 0;
//if (emp.ForeignExPat &&
// Ease.CoreV35.Utility.Global.DateFunctions.DateDiff("m", emp.JoiningDate, SystemInformation.CurrentSysInfo.NextPayProcessDate) > 6)
//{
// empTaxSlabs[empTaxSlabs.Count - 1].SlabTaxAmount = empTaxSlabs[empTaxSlabs.Count].TaxPercent * (taxableIncome / 100);
// return empTaxSlabs;
//}
while (taxableIncome != 0)
{
TaxParameterSlab slab = empTaxSlabs[index];
if (taxableIncome > slab.IncomeAmount && index != empTaxSlabs.Count - 1)
{
slab.SlabTaxAmount = GlobalFunctions.Round((slab.IncomeAmount * slab.TaxPercent) / 100);
slab.SlabTaxableAmount = slab.IncomeAmount;
taxableIncome = taxableIncome - slab.IncomeAmount;
}
else
{
slab.SlabTaxableAmount = taxableIncome;
slab.SlabTaxAmount = GlobalFunctions.Round(((taxableIncome * slab.TaxPercent) / 100));
taxableIncome = 0;
}
index = index + 1;
}
return empTaxSlabs;
}
//Calculate Tax On Slab From Old Table
public static ObjectsTemplate<TaxParameterSlab> GetEmployeeOldSlab(TaxParameter parameter, DataRow employee)
{
foreach (TaxParameterSlab item in parameter.TaxParameterSlabs)
{
item.SlabTaxAmount = 0;
item.SlabTaxableAmount = 0;
}
ObjectsTemplate<TaxParameterSlab> employeeSlab = null;
EnumTaxSlabType SlabType = EnumTaxSlabType.Male;
//Need to consult with Mr. Ashek vai
//if (employee.PersonType == EnumPersonType.Disable)
// SlabType = EnumTaxSlabType.Disable;
//else if (employee.PersonType == EnumPersonType.Freedom_Fighter)
// SlabType = EnumTaxSlabType.Freedom_Fighter;
//else
//{
if ((EnumGender)Convert.ToInt16(employee["Gender"].ToString()) == EnumGender.Female)
SlabType = EnumTaxSlabType.Female;
else
{
int NoOfMonth = Ease.CoreV35.Utility.Global.DateFunctions.DateDiff("m", Convert.ToDateTime(employee["BirthDate"]), SystemInformation.CurrentSysInfo.TaxYearEndDate);
int NoOfYear = NoOfMonth / 12;
if (NoOfYear >= parameter.MaxAge) SlabType = EnumTaxSlabType.Age;
}
//}
employeeSlab = new ObjectsTemplate<TaxParameterSlab>();
foreach (TaxParameterSlab item in parameter.TaxParameterSlabs)
{
if (item.ParamType == SlabType)
employeeSlab.Add(item);
}
return employeeSlab;
}
public static ObjectsTemplate<TaxParameterSlab> CalculateOldTaxOnSlab(TaxParameter parameter, DataRow emp, double taxableIncome)
{
ObjectsTemplate<TaxParameterSlab> empTaxSlabs = TaxParameter.GetEmployeeOldSlab(parameter, emp);
if (empTaxSlabs == null || empTaxSlabs.Count == 0) throw new ServiceException("Employee Tax Slabs not found; Employee No:" + emp["EmployeeNo"]);
int index = 0;
//if (emp.ForeignExPat &&
// Ease.CoreV35.Utility.Global.DateFunctions.DateDiff("m", emp.JoiningDate, SystemInformation.CurrentSysInfo.NextPayProcessDate) > 6)
//{
// empTaxSlabs[empTaxSlabs.Count - 1].SlabTaxAmount = empTaxSlabs[empTaxSlabs.Count].TaxPercent * (taxableIncome / 100);
// return empTaxSlabs;
//}
while (taxableIncome != 0)
{
TaxParameterSlab slab = empTaxSlabs[index];
if (taxableIncome > slab.IncomeAmount && index != empTaxSlabs.Count - 1)
{
slab.SlabTaxAmount = GlobalFunctions.Round((slab.IncomeAmount * slab.TaxPercent) / 100);
slab.SlabTaxableAmount = slab.IncomeAmount;
taxableIncome = taxableIncome - slab.IncomeAmount;
}
else
{
slab.SlabTaxableAmount = taxableIncome;
slab.SlabTaxAmount = GlobalFunctions.Round(((taxableIncome * slab.TaxPercent) / 100));
taxableIncome = 0;
}
index = index + 1;
}
return empTaxSlabs;
}
public static ObjectsTemplate<TaxParameterSlab> GetSlabsByParamID(ID nTaxParamID)
{
#region Cache Header
ObjectsTemplate<TaxParameterSlab> taxParamSlabs = _cache["GetSlabsByParamID", nTaxParamID] as ObjectsTemplate<TaxParameterSlab>;
if (taxParamSlabs != null)
return taxParamSlabs;
#endregion
try
{
taxParamSlabs = Service.GetSlabsByParamID(nTaxParamID);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(taxParamSlabs, "GetSlabsByParamID", nTaxParamID);
#endregion
return taxParamSlabs;
}
public ID Save()
{
this.SetAuditTrailProperties();
return TaxParameter.Service.Save(this);
}
public ID SaveCopy()
{
this.SetAuditTrailProperties();
return TaxParameter.Service.SaveCopy(this);
}
public void Delete()
{
TaxParameter.Service.Delete(ID, Payroll.BO.SystemInformation.CurrentSysInfo.PayrollTypeID.Integer);
}
#endregion
}
#endregion
#region ITaxParameter Service
public interface ITaxParameterService
{
TaxParameter Get(ID id);
TaxParameter GetOldTaxParameter(ID id);
TaxParameter Get(string assessmentYear);
ObjectsTemplate<TaxParameter> Get();
ObjectsTemplate<TaxParameter> Get(bool IsForCurrentYear, int payrollTypeID);
DataTable GetOldTaxCard(bool IsForCurrentYear, int payrollTypeID);
ObjectsTemplate<TaxParameterSlab> GetTaxSlabs(ID taxParameterID, EnumTaxSlabType TaxType);
DataSet GetTSByParamAndType(ID taxParameterID, EnumTaxSlabType TaxType);
ObjectsTemplate<TaxParameterSlab> GetSlabsByParamID(ID taxParameterID);
DataTable GetFiscalYearFromOldTable(ID payrollTypeID);
ID Save(TaxParameter item);
ID SaveCopy(TaxParameter item);
void Delete(ID id, int payrollTypeID);
}
#endregion
}