2026-11-03 13:06:00 +06:00
using Ease.Core.DataAccess ;
using Ease.Core.Model ;
using Ease.Core.Utility ;
using HRM.BO ;
using OfficeOpenXml ;
using System ;
using System.Collections.Generic ;
using System.Linq ;
using static iTextSharp . text . pdf . AcroFields ;
namespace HRM.DA
{
public abstract class AbstractTaxCalculator
{
#region Define Class Variable
protected SalaryMonthly _salary ;
private BonusProcess . BonusProcessDetail _bonus ;
protected Employee _employee ;
protected TaxParameter _taxParameter ;
private TaxParameter _PrvYeartaxParameter ;
protected List < TaxParameterSlab > _taxSlabs ;
protected List < IncomeTax > _currentYearTax ;
private List < IncomeTax > _prvYearTotalIncomes ;
protected List < ADParameter > _adParameters ;
protected List < TaxMergeMaster > _mergeItems ;
protected List < ProcessItem > _processItems ;
private List < ITEmpHead > _assignedHeads ;
private List < BonusParameter > _projectionBonusParams ;
protected List < BonusParameter > _ApplicableBonusParams ;
protected List < BonusProcess . BonusProcessDetail > _paidBonuses ;
protected List < BATBGrandFatherTaging > _bATBGrandFatherTagings ;
protected List < AllowanceDeduction > _allowanceDeductions ;
protected List < EmployeeTaxInvestment > _empTaxInvestments = null ;
2026-11-30 10:14:40 +06:00
protected List < TaxInvestment > _investmentTypes = null ;
2026-11-03 13:06:00 +06:00
protected double _projectedMonth ;
protected double _onceoffAmount ;
List < OTProcess > _oTProcesss = null ;
private double _taxontaxamount ;
2026-11-30 10:14:40 +06:00
public bool? _investmentwithoutpf = null ;
2026-11-03 13:06:00 +06:00
public bool? _monthlyexemption = null ;
public bool _isActualInvestment ;
#endregion Define Class Variable
public AbstractTaxCalculator ( )
{
}
public AbstractTaxCalculator ( int taxParameterID , int payrolltypeid )
{
_isActualInvestment = false ;
_salary = null ;
_taxSlabs = null ;
TaxParameter param = new TaxParameterService ( ) . Get ( taxParameterID ) ;
_mergeItems = new TaxMergeMasterService ( ) . GetbyTaxParameter ( param . ID , payrolltypeid ) ;
if ( param ! = null )
_assignedHeads = new ITEmpHeadService ( ) . GetWithTaxParam ( param . ID ) ;
_processItems = new ProcessItemService ( ) . Get ( ) ;
_onceoffAmount = 0 ;
this . payrolltype = new PayrollTypeService ( ) . Get ( payrolltypeid ) ;
}
public AbstractTaxCalculator ( TaxParameter taxparam , PayrollType ptype )
{
_isActualInvestment = false ;
_salary = null ;
_taxSlabs = null ;
2026-11-30 10:14:40 +06:00
TaxParameter param = taxparam ;
2026-11-03 13:06:00 +06:00
_mergeItems = new TaxMergeMasterService ( ) . GetbyTaxParameter ( param . ID , ptype . ID ) ;
this . payrolltype = ptype ;
if ( param ! = null )
_assignedHeads = new ITEmpHeadService ( ) . GetWithTaxParam ( param . ID ) ;
_processItems = new ProcessItemService ( ) . Get ( ) ;
_onceoffAmount = 0 ;
}
public abstract TaxParameter TaxParameter { set ; }
public abstract Employee Employee { set ; }
public abstract SalaryMonthly Salary { set ; }
public abstract List < ADParameter > AdParameters { set ; }
public List < AllowanceDeduction > AllowanceDeductions
{
get
{
return _allowanceDeductions ;
}
set
{
_allowanceDeductions = value ;
}
}
public List < BonusProcess . BonusProcessDetail > PaidBonues
{
get
{
return _paidBonuses ;
}
set
{
_paidBonuses = value ;
}
}
public List < IncomeTax > CurrentYearTax
{
get
{
return _currentYearTax ;
}
set { _currentYearTax = value ; }
}
public BonusProcess . BonusProcessDetail Bonus
{
set
{
_bonus = value ;
}
}
public List < IncomeTax > Calculate ( )
{
List < IncomeTax > returnedItems = new List < IncomeTax > ( ) ;
return returnedItems ;
}
private void EmployeeSlab ( )
{
//TaxParameter.Get
}
public PayrollType payrolltype { get ; set ; }
private void Add ( IncomeTax taxItem )
{
if ( taxItem . Position = = 0 )
{
ProcessItem pitem = _processItems . Find ( delegate ( ProcessItem item )
{ return item . ItemCode = = ( int ) taxItem . ItemGroup ; } ) ;
if ( pitem = = null ) throw new ServiceException ( "Tax process item code not found in the process collection; Item Code:" + taxItem . ItemGroup . ToString ( ) ) ;
taxItem . Position = pitem . Position ;
}
IncomeTax existItem = _currentYearTax . Find ( delegate ( IncomeTax item )
{ return item . ItemGroup = = taxItem . ItemGroup & & item . ItemID = = taxItem . ItemID ; } ) ;
if ( existItem = = null ) _currentYearTax . Add ( taxItem ) ;
else
{
existItem . PreviousAmount = existItem . PreviousAmount + taxItem . PreviousAmount ;
existItem . ThisMonthAmount = existItem . ThisMonthAmount + taxItem . ThisMonthAmount ;
existItem . ProjectedAmount = existItem . ProjectedAmount + taxItem . ProjectedAmount ;
existItem . Position = taxItem . Position ;
existItem . Description = taxItem . Description ;
}
}
protected IncomeTax Add ( EnumIncomeTaxItemGroup group , int itemId ,
string description , double thismonthAmount ,
double projectedamount , EnumIncomeTaxSide side )
{
IncomeTax existItem = _currentYearTax . Find ( delegate ( IncomeTax item )
{ return item . ItemGroup = = group & & item . ItemID = = itemId ; } ) ;
if ( existItem = = null )
{
ProcessItem pitem = _processItems . Find ( delegate ( ProcessItem item )
{ return item . ItemCode = = ( int ) group ; } ) ;
if ( pitem = = null ) throw new ServiceException ( "Tax process item code not found in the process collection; Item Code:" + group . ToString ( ) ) ;
IncomeTax taxItem = new IncomeTax ( ) ;
taxItem . ItemGroup = group ;
taxItem . ItemID = itemId ;
taxItem . Description = ( description = = string . Empty ) ? pitem . UserDescription : description ;
taxItem . Position = pitem . Position ;
taxItem . PreviousAmount = projectedamount ;
taxItem . ThisMonthAmount = thismonthAmount ;
taxItem . ProjectedAmount = projectedamount ;
taxItem . EmployeeID = _employee . ID ;
taxItem . Side = side ;
_currentYearTax . Add ( taxItem ) ;
return taxItem ;
}
else
{
if ( existItem . Position = = 0 )
{
ProcessItem pitem = _processItems . Find ( delegate ( ProcessItem item )
{ return item . ItemCode = = ( int ) group ; } ) ;
if ( pitem = = null ) throw new ServiceException ( "Tax process item code not found in the process collection; Item Code:" + group . ToString ( ) ) ;
existItem . Position = pitem . Position ;
}
existItem . ThisMonthAmount = existItem . ThisMonthAmount + thismonthAmount ;
existItem . ProjectedAmount = existItem . ProjectedAmount + projectedamount ;
existItem . Description = description ;
existItem . Side = side ;
return existItem ;
}
}
protected void CalcualteprojectMonth ( )
{
//_projectedMonth = 12 - Ease.CoreV35.Utility.Global.DateFunctions.DateDiff ("m",
// SystemInformation.CurrentSysInfo.TaxYearEndDate,
// SystemInformation.CurrentSysInfo.NextPayProcessDate);
_projectedMonth = 12 - ( ( ( this . payrolltype . NextPayProcessDate . Year - this . payrolltype . TaxYearEndDate . Year ) * 12 )
+ this . payrolltype . NextPayProcessDate . Month - this . payrolltype . TaxYearEndDate . Month ) ;
if ( _projectedMonth < 0 ) _projectedMonth = 0 ;
//_projectedMonth= Ease.CoreV35.Utility.Global.DateFunctions.DateDiff("m",
// new DateTime(2010, 12, 31), new DateTime(2011, 6, 30));
if ( _employee . EndOfContractDate ! = null & & _employee . EndOfContractDate ! = DateTime . MinValue )
{
if ( _employee . EndOfContractDate < _taxParameter . FiscalyearDateTo )
_projectedMonth = GetProjectionMonth ( ( DateTime ) _employee . EndOfContractDate ) ;
}
}
protected void CalculateOT ( )
{
// find current month OT
if ( _oTProcesss = = null )
_oTProcesss = new OTProcessService ( ) . Get ( this . payrolltype . NextPayProcessDate ) ;
OTProcess op = _oTProcesss . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID ) ;
if ( op = = null ) return ;
IncomeTax otItem = _currentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID
& & x . ItemGroup = = EnumIncomeTaxItemGroup . TimeCard & & x . ItemID = = 2 ) ;
//if (otItem == null) otItem = this.Add(EnumIncomeTaxItemGroup.TimeCard, (int)EnumIncomeTaxItemGroup.TimeCard, string.Empty, 0, 0, EnumIncomeTaxSide.Dec_SalaryIncome);
if ( otItem = = null ) otItem = this . Add ( EnumIncomeTaxItemGroup . TimeCard , ( int ) EnumIncomeTaxItemGroup . TimeCard , "Time Card" , 0 , 0 , EnumIncomeTaxSide . Dec_SalaryIncome ) ;
// update this month amount
otItem . ThisMonthAmount = op . Amount ;
otItem . ProjectedAmount = op . Amount * _projectedMonth ;
}
private double GetProjectionMonth ( DateTime date )
{
double nFraction ;
//If Month is July then no need for Projection
if ( date . Month = = 7 )
nFraction = Convert . ToDouble ( 0 ) ;
else
nFraction = GlobalFunctions . GetFraction ( this . payrolltype . NextPayProcessDate . AddDays ( 1 ) , date ) ;
return nFraction ;
}
private double GetAmountfromSalary ( SalaryMonthlyDetail detail )
{
if ( detail . itemGroupCode = = EnumSalaryGroup . Arrear )
_onceoffAmount = _onceoffAmount + detail . ChangedAmount ;
if ( detail . itemGroupCode = = EnumSalaryGroup . Miscellaneous | | detail . itemGroupCode = = EnumSalaryGroup . OtherItem ) return 0 ;
if ( detail . itemGroupCode = = EnumSalaryGroup . Gross | | detail . itemGroupCode = = EnumSalaryGroup . Arrear )
return detail . ChangedAmount ;
else return - detail . ChangedAmount ;
}
protected IncomeTax GetTaxItem ( EnumTaxMergeType type , int ItemId , string itemName )
{
IncomeTax taxItem = TaxMergeMaster . Extract (
_mergeItems , type , ItemId ) ;
if ( taxItem = = null ) throw new ServiceException ( "Tax setup not found for the Item :" + itemName ) ;
if ( taxItem ! = null )
taxItem . EmployeeID = _employee . ID ;
return taxItem ;
}
protected void InitializeForNextMonth ( )
{
if ( _currentYearTax = = null )
{
_currentYearTax = new List < IncomeTax > ( ) ;
_currentYearTax = new IncomeTaxService ( ) . Get ( _employee . ID , EnumIncomeTaxDataFrom . ProcessTempData ) ;
}
foreach ( IncomeTax item in _currentYearTax )
{
item . PreviousAmount = item . PreviousAmount + item . ThisMonthAmount ;
item . ThisMonthAmount = 0 ;
item . ProjectedAmount = 0 ;
}
}
private SalaryMonthlyDetail CreateSalaryDetail ( string description , EnumSalaryItemCode itemCode , int itemid , int supportid , double amount )
{
SalaryMonthlyDetail odetail = new SalaryMonthlyDetail ( ) ;
odetail . Description = description ;
odetail . itemGroupCode = EnumSalaryGroup . Gross ;
odetail . ItemCode = itemCode ;
odetail . ItemID = itemid ;
odetail . ChangedAmount = amount ;
odetail . SupportID = supportid ;
return odetail ;
}
protected void CalculateOnlyProjection ( )
{
foreach ( IncomeTax item in this . CurrentYearTax )
item . ProjectedAmount = 0 ;
List < ADParameter > adParams = null ;
List < ADParameterEmployee > adParamEmps = null ;
EmployeeGradeSalary oEmpGSalary = new EmployeeGradeSalary ( ) ;
List < TaxRawItem > rawItems = new List < TaxRawItem > ( ) ;
_projectedMonth = _projectedMonth + 1 ;
_salary = new SalaryMonthly ( ) ;
_salary . Details . Add ( this . CreateSalaryDetail ( "Basic Salary" , EnumSalaryItemCode . Basic_Salary , ( int ) EnumSalaryItemCode . Basic_Salary , 0 , _employee . BasicSalary ) ) ;
if ( _adParameters = = null ) _adParameters = new ADParameterService ( ) . Get ( EnumStatus . Regardless , EnumAllowOrDeduct . Allowance , this . payrolltype . ID ) ;
adParams = new ADParameterService ( ) . GetApplicableParameters ( _employee , ( int ) _employee . GradeID , _adParameters ) ;
if ( adParams ! = null )
{
foreach ( ADParameter adParam in adParams )
{
//if (adParam.EntitleType == EnumEntitleType.Grade)
// _salary.Details.Add(this.CreateSalaryDetail(adParam.AllowanceDeduction.Name,
// EnumSalaryItemCode.Allowance, adParam.AllowanceDeduction.ID, adParam.ID, new ADParameterService().GetGradeDefinedAmount(_employee, _employee.BasicSalary,
// _employee.GrossSalary, new EmployeeGradeSalary())));
}
}
adParamEmps = new ADParameterEmployeeService ( ) . GetByEmployee ( _employee . ID , EnumAllowOrDeduct . Allowance , EnumADEmpType . AppliedToIndividual ) ;
if ( adParamEmps ! = null )
{
foreach ( ADParameterEmployee adEmp in adParamEmps )
{
_salary . Details . Add ( this . CreateSalaryDetail ( adEmp . AllowDeduct . Name ,
EnumSalaryItemCode . Allowance , adEmp . AllowDeduct . ID , adEmp . ID , adEmp . MonthlyAmount ) ) ;
}
}
this . IncludePayslipItems ( ) ;
foreach ( IncomeTax item in this . CurrentYearTax )
{
item . PreviousAmount = 0 ;
item . ThisMonthAmount = 0 ;
}
}
protected void CalculateOnlyProjection ( List < ADParameter > oParams )
{
foreach ( IncomeTax item in this . CurrentYearTax )
item . ProjectedAmount = 0 ;
List < ADParameter > adParams = null ;
List < ADParameterEmployee > adParamEmps = null ;
EmployeeGradeSalary oEmpGSalary = new EmployeeGradeSalary ( ) ;
List < TaxRawItem > rawItems = new List < TaxRawItem > ( ) ;
2026-11-30 10:14:40 +06:00
// _projectedMonth = _projectedMonth + 1;
2026-11-03 13:06:00 +06:00
_salary = new SalaryMonthly ( ) ;
_salary . Details . Add ( this . CreateSalaryDetail ( "Basic Salary" , EnumSalaryItemCode . Basic_Salary , ( int ) EnumSalaryItemCode . Basic_Salary , 0 , _employee . BasicSalary ) ) ;
2026-11-30 10:14:40 +06:00
if ( this . _allowanceDeductions = = null )
2026-11-03 13:06:00 +06:00
{
this . _allowanceDeductions = new AllowanceDeductionService ( ) . Get ( EnumStatus . Regardless , this . payrolltype . ID ) ;
}
if ( _adParameters = = null ) _adParameters = oParams ; // ADParameter.Get(EnumStatus.Regardless, EnumAllowOrDeduct.Allowance);
adParams = new ADParameterService ( ) . GetApplicableParameters ( _employee , ( int ) _employee . GradeID , _adParameters ) ;
if ( adParams ! = null )
{
foreach ( ADParameter adParam in adParams )
{
adParam . AllowanceDeduction = this . _allowanceDeductions . FirstOrDefault ( x = > x . ID = = adParam . AllowDeductID ) ;
if ( adParam . EntitleType = = EnumEntitleType . Grade )
_salary . Details . Add ( this . CreateSalaryDetail ( adParam . AllowanceDeduction . Name ,
2026-11-30 10:14:40 +06:00
EnumSalaryItemCode . Allowance , adParam . AllowanceDeduction . ID , adParam . ID ,
2026-11-03 13:06:00 +06:00
new ADParameterService ( ) . GetGradeDefinedAmount ( _employee , _employee . BasicSalary ,
_employee . GrossSalary , new EmployeeGradeSalary ( ) , adParam ) ) ) ;
}
}
adParamEmps = new ADParameterEmployeeService ( ) . GetByEmployee ( _employee . ID , EnumAllowOrDeduct . Allowance , EnumADEmpType . AppliedToIndividual ) ;
if ( adParamEmps ! = null )
{
foreach ( ADParameterEmployee adEmp in adParamEmps )
{
_salary . Details . Add ( this . CreateSalaryDetail ( adEmp . AllowDeduct . Name ,
EnumSalaryItemCode . Allowance , adEmp . AllowDeduct . ID , adEmp . ADParameterID , adEmp . MonthlyAmount ) ) ;
}
}
this . IncludePayslipItems ( ) ;
foreach ( IncomeTax item in this . CurrentYearTax )
{
item . PreviousAmount = 0 ;
item . ThisMonthAmount = 0 ;
}
}
private bool IsExamptedItem ( IncomeTax Item )
{
bool IsExamptedItem = false ;
if ( Item . ItemGroup = = EnumIncomeTaxItemGroup . House_Rent_Allowance )
IsExamptedItem = true ;
else if ( Item . ItemGroup = = EnumIncomeTaxItemGroup . Conveyance_Allowance )
IsExamptedItem = true ;
else if ( Item . ItemGroup = = EnumIncomeTaxItemGroup . Medical_Allowance )
IsExamptedItem = true ;
else if ( Item . ItemGroup = = EnumIncomeTaxItemGroup . LFA_Allowance )
IsExamptedItem = true ;
return IsExamptedItem ;
}
private IncomeTax PayslipAllowanceDeduction ( SalaryMonthlyDetail salaryDetail , EnumTaxMergeType type )
{
EmployeeGradeSalary oEmpGSalary = new EmployeeGradeSalary ( ) ;
IncomeTax item = null ;
ADParameter adparameter = _adParameters . FirstOrDefault ( x = > x . ID = = salaryDetail . SupportID ) ;
if ( adparameter = = null )
throw new ServiceException ( "Allowance/deduction parameter not found for " + salaryDetail . Description ) ;
if ( adparameter . IsTaxable = = false ) return null ;
item = this . GetTaxItem ( type , salaryDetail . ItemID , salaryDetail . Description ) ;
item . ThisMonthAmount = GlobalFunctions . Round ( item . ThisMonthAmount + GetAmountfromSalary ( salaryDetail ) ) ;
if ( adparameter . Periodicity = = EnumPeriodicity . OneOff )
{
//if (User.CurrentUser.LogInPayrollTypeID.Integer == 1)
//{
if ( IsExamptedItem ( item ) = = false )
_onceoffAmount = _onceoffAmount + item . ThisMonthAmount ;
//}
//else
//{
// if (adparameter.IsDependsOnAttendance == true)
// {
// item.ProjectedAmount = GlobalFunctions.Round(item.ThisMonthAmount) * _projectedMonth;
// }
//}
}
else
{
if ( salaryDetail . itemGroupCode = = EnumSalaryGroup . Gross )
{
//if (User.CurrentUser.LogInPayrollTypeID.Integer != 1 && item.ItemGroup == EnumIncomeTaxItemGroup.Conveyance_Allowance)
//{
// double conveyance = adparameter.FlatAmount;
// if (_employee.GrandFather != null) conveyance = adparameter.GFFlatAmount;
// item.ProjectedAmount = conveyance;
// item.ProjectedAmount = 26 * _projectedMonth * conveyance;
//}
//else
{
#region Management Payrol
if ( adparameter . EntitleType = = EnumEntitleType . Grade )
{
2026-11-30 10:14:40 +06:00
if ( ( salaryDetail . IsOnBalancing = = true )
& & salaryDetail . ItemCode = = EnumSalaryItemCode . Allowance & &
salaryDetail . itemGroupCode = = EnumSalaryGroup . Gross )
{
item . ProjectedAmount = salaryDetail . ActualPassegeFreeAmount * _projectedMonth ;
}
else item . ProjectedAmount = GlobalFunctions . Round ( new ADParameterService ( ) . GetGradeDefinedAmount ( _employee , _employee . BasicSalary , _employee . GrossSalary , oEmpGSalary , adparameter ) ) * _projectedMonth ;
//item.ProjectedAmount = GlobalFunctions.Round( new ADParameterService().GetGradeDefinedAmount(_employee, _employee.BasicSalary, _employee.GrossSalary, oEmpGSalary, adparameter)) * _projectedMonth;
2026-11-03 13:06:00 +06:00
}
else
{
DateTime fromDate = GlobalFunctions . FirstDateOfMonth ( this . payrolltype . NextPayProcessDate ) ;
DateTime toDate = this . payrolltype . NextPayProcessDate ;
if ( salaryDetail . SupportID ! = null )
{
ADParameterEmployee oempadp = salaryDetail . ADParamEmployee ;
if ( oempadp = = null )
oempadp = new ADParameterEmployeeService ( ) . Get ( _employee . ID , salaryDetail . ItemID , ( int ) salaryDetail . SupportID , EnumArrearType . NotPresent ) ;
//ADParameterEmployee oempadp = ADParameterEmployee.Get(_employee.ID, ID.FromInteger(salaryDetail.ItemID), salaryDetail.SupportID);
if ( oempadp ! = null )
{
fromDate = GlobalFunctions . FirstDateOfMonth ( this . payrolltype . NextPayProcessDate . AddMonths ( 1 ) ) ;
if ( oempadp . TillDate = = null | | oempadp . TillDate = = DateTime . MinValue )
{
if ( _employee . EndOfContractDate = = null )
toDate = _taxParameter . FiscalyearDateTo ;
else toDate = ( DateTime ) _employee . EndOfContractDate ;
}
else
{
if ( _employee . EndOfContractDate = = null )
toDate = ( DateTime ) oempadp . TillDate ;
else toDate = ( DateTime ) _employee . EndOfContractDate ;
}
double nproject = 0 ;
if ( fromDate > toDate ) nproject = 0 ;
else
{
if ( toDate > _taxParameter . FiscalyearDateTo ) toDate = _taxParameter . FiscalyearDateTo ;
nproject = GlobalFunctions . GetFraction ( fromDate , toDate ) ;
}
item . ProjectedAmount = GlobalFunctions . Round ( oempadp . GetAmount ( _employee . BasicSalary , 0 ) ) * nproject ;
}
else item . ProjectedAmount = GlobalFunctions . Round ( item . ThisMonthAmount ) * _projectedMonth ;
}
else item . ProjectedAmount = GlobalFunctions . Round ( item . ThisMonthAmount ) * _projectedMonth ;
}
#endregion
}
}
}
return item ;
}
protected void IncludePayslipItems ( )
{
foreach ( SalaryMonthlyDetail salaryDetail in _salary . Details )
{
IncomeTax item = null ;
switch ( salaryDetail . ItemCode )
{
case EnumSalaryItemCode . Basic_Salary :
item = GetTaxItem ( EnumTaxMergeType . NONE , ( int ) EnumIncomeTaxItemGroup . Basic_Salary , salaryDetail . Description ) ;
item . ThisMonthAmount = GlobalFunctions . Round ( GetAmountfromSalary ( salaryDetail ) ) ;
if ( salaryDetail . itemGroupCode = = EnumSalaryGroup . Gross ) item . ProjectedAmount = GlobalFunctions . Round ( _employee . BasicSalary ) * _projectedMonth ;
break ;
case EnumSalaryItemCode . Over_Time_Amount :
item = GetTaxItem ( EnumTaxMergeType . OT , salaryDetail . ItemID , salaryDetail . Description ) ;
if ( item = = null ) throw new ServiceException ( "Tax grouping not found for " + salaryDetail . Description ) ;
item . ThisMonthAmount = GlobalFunctions . Round ( GetAmountfromSalary ( salaryDetail ) ) ;
break ;
case EnumSalaryItemCode . Bonus :
//if (salaryDetail.ItemID == (int)EnumBATBBonusType.Management_Festival && PaidBonues != null)
//{
// BonusProcess.BonusProcessDetail obDetail = PaidBonues.FirstOrDefault(x => x.EmployeeID.Integer == _employee.ID.Integer && x.BonusID.Integer == salaryDetail.ItemID && x.IsLFA == true);
// if (obDetail != null) item = GetTaxItem(EnumTaxMergeType.NONE, (int)EnumIncomeTaxItemGroup.LFA_Allowance, salaryDetail.Description);
// else item = GetTaxItem(EnumTaxMergeType.Bonus, salaryDetail.ItemID, salaryDetail.Description);
//}
//else
item = GetTaxItem ( EnumTaxMergeType . Bonus , salaryDetail . ItemID , salaryDetail . Description ) ;
if ( item = = null ) throw new ServiceException ( "Tax grouping not found for " + salaryDetail . Description ) ;
item . ThisMonthAmount = GlobalFunctions . Round ( GetAmountfromSalary ( salaryDetail ) ) ;
break ;
case EnumSalaryItemCode . Allowance :
item = this . PayslipAllowanceDeduction ( salaryDetail , EnumTaxMergeType . Allowance ) ;
if ( item = = null ) continue ;
break ;
case EnumSalaryItemCode . Deduction :
item = this . PayslipAllowanceDeduction ( salaryDetail , EnumTaxMergeType . Deduction ) ;
if ( item = = null ) continue ;
break ;
//case EnumSalaryItemCode.PF_Contribution:
// item = GetTaxItem(EnumTaxMergeType.NONE, (int)EnumIncomeTaxItemGroup.Company_Contri_PF, salaryDetail.Description);
// item.ThisMonthAmount =GlobalFunctions.Round(GetAmountfromSalary(salaryDetail));
// break;
default :
break ;
}
if ( item ! = null ) item . Side = EnumIncomeTaxSide . Inc_SalaryIncome ;
if ( item ! = null ) this . Add ( item ) ;
}
}
protected void CalculateExemptionOnward2023 ( )
{
IncomeTax exempted = _currentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID
& & x . ItemGroup = = EnumIncomeTaxItemGroup . AnnualExemption & & x . ItemID = = ( int ) EnumIncomeTaxItemGroup . AnnualExemption ) ;
if ( exempted = = null ) exempted = this . Add ( EnumIncomeTaxItemGroup . AnnualExemption ,
( int ) EnumIncomeTaxItemGroup . AnnualExemption , string . Empty , 0 , 0 ,
EnumIncomeTaxSide . Dec_AnnualIncome ) ;
if ( _employee . ForeignExPat & & ( _employee . JoiningDate - payrolltype . NextPayProcessDate ) . TotalDays < = 183 )
{
exempted . ThisMonthAmount = 0 ;
exempted . PreviousAmount = 0 ;
exempted . ProjectedAmount = 0 ;
return ;
}
exempted . ProjectedAmount = 0 ;
exempted . TotalAmount = 0 ;
double annualIncome = this . GetAnnualIncome ( ) ;
if ( annualIncome > 0 )
{
exempted . ProjectedAmount = Math . Ceiling ( ( annualIncome / 3 ) * 1 ) ;
if ( exempted . ProjectedAmount > 500000 )
{
exempted . ProjectedAmount = 500000 ;
}
}
exempted . TotalAmount = exempted . ProjectedAmount ;
}
protected void CalculateExamtion ( )
{
this . CalculateExemptionOnward2023 ( ) ;
return ;
#region get Examtion items from processItem
var examtionItems = from pItem in _processItems
where pItem . ItemGroup = = 7
select pItem ;
#endregion
2026-11-30 10:14:40 +06:00
if ( this . _monthlyexemption = = null )
2026-11-03 13:06:00 +06:00
this . _monthlyexemption = new SystemConfigarationService ( ) . GetconfigBooleanValue ( EnumConfigurationType . Logic , "incometax" , "monthlyexemption" ) ;
foreach ( var processItem in examtionItems )
{
double tempAmount = 0 ;
#region House rent allowance
if ( processItem . ItemCode = = ( int ) EnumIncomeTaxItemGroup . Exemption_House_Rent_Allowance )
{
//if (_employee.JoiningDate.Day > 1)
// _employee.JoiningDate = new DateTime(_employee.JoiningDate.Year, _employee.JoiningDate.Month, 1);
2026-11-30 10:14:40 +06:00
IncomeTax basicItem = _currentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID & &
x . ItemGroup = = EnumIncomeTaxItemGroup . Basic_Salary & & x . ItemID = = ( int ) EnumIncomeTaxItemGroup . Basic_Salary ) ;
2026-11-03 13:06:00 +06:00
2026-11-30 10:14:40 +06:00
IncomeTax HRItem = _currentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID & &
2026-11-03 13:06:00 +06:00
x . ItemGroup = = EnumIncomeTaxItemGroup . House_Rent_Allowance & & x . ItemID = = ( int ) EnumIncomeTaxItemGroup . House_Rent_Allowance ) ;
if ( HRItem = = null | | HRItem . TotalAmount = = 0 ) continue ; //throw new ServiceException("House rent allowance not found in the collection while calculating HR Examtion");
//continue; //
2026-11-30 10:14:40 +06:00
IncomeTax HrExption = _currentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID & &
x . ItemGroup = = EnumIncomeTaxItemGroup . Exemption_House_Rent_Allowance & &
x . ItemID = = ( int ) EnumIncomeTaxItemGroup . Exemption_House_Rent_Allowance ) ;
2026-11-03 13:06:00 +06:00
if ( HrExption = = null ) HrExption = this . Add ( EnumIncomeTaxItemGroup . Exemption_House_Rent_Allowance ,
( int ) EnumIncomeTaxItemGroup . Exemption_House_Rent_Allowance , string . Empty , 0 , 0 , EnumIncomeTaxSide . Dec_SalaryIncome ) ;
//if (oCycles != null && oCycles.Count>0)
//{
// EmpLifeCycle cycle = oCycles.Find(x => x.IsContinue==true);
// if (cycle != null)
// _employee.JoiningDate = cycle.EffectDate;
//}
//if (_employee.JoiningDate < new DateTime(_taxParameter.FiscalyearDatefrom.Year, 7, 1))
//{
// monthlyexemption = false;
//}
//else
this . _monthlyexemption = true ;
HrExption . ProjectedAmount = 0 ;
//HrExption.ThisMonthAmount = 0;
//HrExption.PreviousAmount = 0;
//HrExption.TotalAmount = 0;
if ( this . _monthlyexemption = = false )
{
HrExption . ProjectedAmount = 0 ;
HrExption . ThisMonthAmount = 0 ;
HrExption . PreviousAmount = 0 ;
HrExption . TotalAmount = 0 ;
if ( _taxParameter . MaxHRPercent ! = 0 )
{
double hrAmount = ( basicItem . TotalAmount * _taxParameter . MaxHRPercent ) / 100 ;
double maxMonthlyAmount = ( _taxParameter . MaxHRAmount / 12 ) * 12 - _projectedMonth ;
if ( hrAmount > _taxParameter . MaxHRAmount )
HrExption . ProjectedAmount = _taxParameter . MaxHRAmount ;
else HrExption . ProjectedAmount = hrAmount ;
if ( HrExption . TotalAmount > HRItem . TotalAmount | | Math . Abs ( HrExption . TotalAmount - HRItem . TotalAmount ) < 10 )
HrExption . ProjectedAmount = HRItem . TotalAmount -
( HrExption . ThisMonthAmount + HrExption . PreviousAmount ) ;
}
else
{
if ( HRItem . TotalAmount > _taxParameter . MaxHRAmount )
HrExption . ProjectedAmount = _taxParameter . MaxHRAmount ;
else HrExption . ProjectedAmount = HRItem . TotalAmount ;
if ( HrExption . TotalAmount > HRItem . TotalAmount | | Math . Abs ( HrExption . TotalAmount - HRItem . TotalAmount ) < 10 )
HrExption . ProjectedAmount = HRItem . TotalAmount -
( HrExption . ThisMonthAmount + HrExption . PreviousAmount ) ;
}
}
else
{
//#region monthly Examption
//if (HRItem.TotalAmount > _taxParameter.MaxHRAmount)
//{
// tempAmount = _taxParameter.MaxHRAmount - HrExption.PreviousAmount;
// HrExption.ThisMonthAmount = tempAmount / (_projectedMonth + 1);
// HrExption.ProjectedAmount = _taxParameter.MaxHRAmount -
// (HrExption.ThisMonthAmount + HrExption.PreviousAmount);
// if (HrExption.TotalAmount > _taxParameter.MaxHRAmount || Math.Abs(HrExption.TotalAmount - HRItem.TotalAmount) < 10)
// HrExption.ProjectedAmount = HrExption.TotalAmount - _taxParameter.MaxHRAmount;
//}
//else
//{
double def = 0 ;
double nFracAmount = 0 ;
#region This code needed for only this month to calculate previous month
double maxMonthlyAmount = _taxParameter . MaxHRAmount / 12 ;
//if (HrExption.PreviousAmount == 0 && _employee.JoiningDate < new DateTime(_taxParameter.FiscalyearDatefrom.Year, 7, 1))
//{
// if (maxMonthlyAmount * (SystemInformation.CurrentSysInfo.NextPayProcessDate.Month- _taxParameter.FiscalyearDatefrom.Month) > HRItem.PreviousAmount)
// {
// HrExption.PreviousAmount = maxMonthlyAmount * (SystemInformation.CurrentSysInfo.NextPayProcessDate.Month - _taxParameter.FiscalyearDatefrom.Month);
// }
// else HrExption.PreviousAmount = HRItem.PreviousAmount;
//}
DateTime fromDate = _employee . JoiningDate ;
DateTime todate = this . payrolltype . NextPayProcessDate ;
if ( _employee . JoiningDate < _taxParameter . FiscalyearDatefrom ) fromDate = _taxParameter . FiscalyearDatefrom ;
if ( HrExption . PreviousAmount = = 0 ) // that mean sytem started tax calculation middle of the fiscal year
{
if ( HRItem . PreviousAmount > 0 )
{
def = Global . DateFunctions . DateDiff ( "m" , fromDate , GlobalFunctions . LastDateOfMonth ( todate ) ) ;
if ( HRItem . PreviousAmount < maxMonthlyAmount * def )
HrExption . PreviousAmount = HRItem . PreviousAmount ;
else HrExption . PreviousAmount = maxMonthlyAmount * def ;
}
else if ( HRItem . PreviousAmount = = 0 & &
GlobalFunctions . FirstDateOfMonth ( _employee . JoiningDate ) < GlobalFunctions . FirstDateOfMonth ( todate ) ) // New Joiner with Arrear
{
def = Global . DateFunctions . DateDiff ( "m" , fromDate , GlobalFunctions . LastDateOfMonth ( todate ) ) ;
HrExption . PreviousAmount = maxMonthlyAmount * def ;
}
}
//todate = _taxParameter.FiscalyearDateTo;
//if (_taxParameter.FiscalyearDatefrom < _employee.JoiningDate) fromDate = _employee.JoiningDate;
//if (_employee.EndOfContractDate != null && _employee.EndOfContractDate < _taxParameter.FiscalyearDateTo)
// todate = (DateTime)_employee.EndOfContractDate;
//if (fromDate == GlobalFunctions.FirstDateOfMonth(_employee.JoiningDate))
// def = Global.DateFunctions.DateDiff("m", fromDate, GlobalFunctions.LastDateOfMonth(todate)) + 1;
//else
//{
// def = Global.DateFunctions.DateDiff("m", fromDate, GlobalFunctions.LastDateOfMonth(todate));
// TimeSpan ts = GlobalFunctions.LastDateOfMonth(fromDate) - fromDate;
// nFracAmount = (maxMonthlyAmount / (double)DateTime.DaysInMonth(fromDate.Year, fromDate.Month)) * ((double)ts.Days + 1);
//}
// if(_employee.JoiningDate < new DateTime(2018, 2,1))
//HrExption.ProjectedAmount = (maxMonthlyAmount * def) + nFracAmount;
if ( _employee . EndOfContractDate ! = null & & _salary ! = null )
{
if ( _salary . SalaryMonth > GlobalFunctions . FirstDateOfMonth ( ( DateTime ) _employee . EndOfContractDate )
& & _salary . SalaryMonth < = GlobalFunctions . LastDateOfMonth ( ( DateTime ) _employee . EndOfContractDate ) )
{
maxMonthlyAmount = maxMonthlyAmount * GlobalFunctions . GetFractinalOfTillDate ( ( DateTime ) _employee . EndOfContractDate ) ;
}
}
if ( HRItem . ThisMonthAmount < maxMonthlyAmount )
maxMonthlyAmount = HRItem . ThisMonthAmount ;
HrExption . ThisMonthAmount = maxMonthlyAmount ;
double hrAmount = ( basicItem . ProjectedAmount * _taxParameter . MaxHRPercent ) / 100 ;
if ( hrAmount > _taxParameter . MaxHRAmount / 12 * _projectedMonth )
HrExption . ProjectedAmount = _taxParameter . MaxHRAmount / 12 * _projectedMonth ;
else HrExption . ProjectedAmount = hrAmount ;
//if (hrAmount > _taxParameter.MaxHRAmount / 12 * Math.Ceiling(_projectedMonth))
// HrExption.ProjectedAmount = _taxParameter.MaxHRAmount / 12 * Math.Ceiling(_projectedMonth);
//else HrExption.ProjectedAmount = hrAmount;
if ( HrExption . TotalAmount > HRItem . TotalAmount | | Math . Abs ( HrExption . TotalAmount - HRItem . TotalAmount ) < 10 )
HrExption . ProjectedAmount = HRItem . TotalAmount -
( HrExption . ThisMonthAmount + HrExption . PreviousAmount ) ;
if ( HrExption . TotalAmount > _taxParameter . MaxHRAmount )
{
double excess = HrExption . TotalAmount - _taxParameter . MaxHRAmount ;
HrExption . ProjectedAmount = HrExption . ProjectedAmount - excess ;
}
//if (HRItem.ThisMonthAmount < maxMonthlyAmount)
//{
// double nBasic = basicItem.ThisMonthAmount * def;
// nBasic = (nBasic * 50) / 100;
// if (HrExption.PreviousAmount < nBasic)
// HrExption.PreviousAmount = nBasic;
//}
//#endregion
//if (maxMonthlyAmount < HRItem.ThisMonthAmount)
//{
// HrExption.ThisMonthAmount = maxMonthlyAmount;
// HrExption.ProjectedAmount = maxMonthlyAmount * _projectedMonth;
//}
//else
//{
// HrExption.ThisMonthAmount = HRItem.ThisMonthAmount;
// HrExption.ProjectedAmount = HRItem.ThisMonthAmount * _projectedMonth;
// if (_salary != null && _salary.Details.Any(x => x.itemGroupCode == EnumSalaryGroup.UnauthLeave))
// {
// double unhraount = 0;
// SalaryMonthlyDetail odt = _salary.Details.FirstOrDefault(x => x.itemGroupCode == EnumSalaryGroup.Gross
// && x.ItemCode == EnumSalaryItemCode.Allowance && x.ItemID == 1);
// if (odt != null)
// unhraount = odt.ChangedAmount;
// HrExption.ProjectedAmount = (unhraount + HRItem.ThisMonthAmount) * _projectedMonth;
// }
//}
// HrExption.ThisMonthAmount = HRItem.ThisMonthAmount;
//tempAmount = HRItem.TotalAmount - HrExption.PreviousAmount;
//HrExption.ThisMonthAmount = HRItem.ThisMonthAmount;
//HrExption.ProjectedAmount = HRItem.ProjectedAmount;
//if (HrExption.TotalAmount > HRItem.TotalAmount || Math.Abs(HrExption.TotalAmount - HRItem.TotalAmount) < 10)
// HrExption.ProjectedAmount = HRItem.TotalAmount -
// (HrExption.ThisMonthAmount + HrExption.PreviousAmount);
//}
#endregion monthly Examption
}
HrExption . ThisMonthAmount = GlobalFunctions . Round ( HrExption . ThisMonthAmount ) ;
HrExption . ProjectedAmount = GlobalFunctions . Round ( HrExption . ProjectedAmount ) ;
HrExption . TotalAmount = HrExption . ThisMonthAmount + HrExption . PreviousAmount + HrExption . ProjectedAmount ;
//if (_employee.JoiningDate < new DateTime(_taxParameter.FiscalyearDatefrom.Year, 7, 1))
//{
// HrExption.ThisMonthAmount = GlobalFunctions.Round(HrExption.ThisMonthAmount);
// HrExption.ProjectedAmount = GlobalFunctions.Round(HrExption.ProjectedAmount);
// HrExption.TotalAmount = HrExption.ThisMonthAmount + HrExption.PreviousAmount + HrExption.ProjectedAmount;
//}
//else
//{
// HrExption.ThisMonthAmount = 0;
// HrExption.ProjectedAmount = 0;
//}
//DataSet ds = IncomeTax.GetTaxAdj(EnumIncomeTaxItemGroup.Exemption_House_Rent_Allowance, (int)EnumIncomeTaxItemGroup.Exemption_House_Rent_Allowance, _employee.ID);
//if (ds != null && ds.Tables.Count > 0)
//{
// foreach (DataRow dr in ds.Tables[0].Rows)
// {
// HrExption.PreviousAmount = Convert.ToDouble(dr[4].ToString());
// }
//}
//HrExption.TotalAmount = HrExption.PreviousAmount;
}
#endregion House rent allowance
#region Conveyance Allowance Examtion
else if ( processItem . ItemCode = = ( int ) EnumIncomeTaxItemGroup . Exemption_Conveyance_Allowance )
{
2026-11-30 10:14:40 +06:00
IncomeTax CnvItem = _currentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID & &
2026-11-03 13:06:00 +06:00
x . ItemGroup = = EnumIncomeTaxItemGroup . Conveyance_Allowance & & x . ItemID = = ( int ) EnumIncomeTaxItemGroup . Conveyance_Allowance ) ;
if ( CnvItem = = null | | CnvItem . TotalAmount = = 0 ) continue ;
2026-11-30 10:14:40 +06:00
IncomeTax CvExption = _currentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID & &
x . ItemGroup = = EnumIncomeTaxItemGroup . Exemption_Conveyance_Allowance & & x . ItemID = = ( int ) EnumIncomeTaxItemGroup . Exemption_Conveyance_Allowance ) ;
2026-11-03 13:06:00 +06:00
if ( CvExption = = null ) CvExption = this . Add ( EnumIncomeTaxItemGroup . Exemption_Conveyance_Allowance , ( int ) EnumIncomeTaxItemGroup . Exemption_Conveyance_Allowance , string . Empty , 0 , 0 , EnumIncomeTaxSide . Dec_SalaryIncome ) ;
if ( this . _monthlyexemption = = false )
{
CvExption . TotalAmount = 0 ;
CvExption . ProjectedAmount = 0 ;
CvExption . PreviousAmount = 0 ;
CvExption . ThisMonthAmount = 0 ;
if ( CnvItem . TotalAmount > _taxParameter . MaxConvAmount | | Math . Abs ( CnvItem . TotalAmount - _taxParameter . MaxConvAmount ) < 10 )
CvExption . ProjectedAmount = _taxParameter . MaxConvAmount ;
else CvExption . ProjectedAmount = CnvItem . TotalAmount ;
}
else
{
if ( CnvItem . TotalAmount > _taxParameter . MaxConvAmount )
CvExption . ThisMonthAmount = _taxParameter . MaxConvAmount / 12 ;
else CvExption . ThisMonthAmount = CnvItem . ThisMonthAmount ;
if ( CnvItem . TotalAmount > _taxParameter . MaxConvAmount | | Math . Abs ( CnvItem . TotalAmount - _taxParameter . MaxConvAmount ) < 10 )
{
CvExption . ProjectedAmount = _taxParameter . MaxConvAmount - (
CvExption . ThisMonthAmount + CvExption . PreviousAmount ) ;
}
else
{
CvExption . ProjectedAmount = CnvItem . TotalAmount - (
CvExption . ThisMonthAmount + CvExption . PreviousAmount ) ;
}
}
CvExption . Side = EnumIncomeTaxSide . Dec_SalaryIncome ;
CvExption . ThisMonthAmount = GlobalFunctions . Round ( CvExption . ThisMonthAmount ) ;
CvExption . ProjectedAmount = GlobalFunctions . Round ( CvExption . ProjectedAmount ) ;
CvExption . TotalAmount = CvExption . ThisMonthAmount + CvExption . PreviousAmount + CvExption . ProjectedAmount ;
}
#endregion Conveyance Allowance Examtion
#region Other Allowance Examption
else if ( processItem . ItemCode = = ( int ) EnumIncomeTaxItemGroup . Exemption_Medical_Allowance )
{
2026-11-30 10:14:40 +06:00
IncomeTax MedicalItem = _currentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID & &
x . ItemGroup = = EnumIncomeTaxItemGroup . Medical_Allowance & & x . ItemID = = ( int ) EnumIncomeTaxItemGroup . Medical_Allowance ) ;
2026-11-03 13:06:00 +06:00
if ( MedicalItem = = null ) continue ; //throw new ServiceException("Conveyance allowance not found in the collection while calculating HR Examtion");
2026-11-30 10:14:40 +06:00
IncomeTax mdExption = _currentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID & &
2026-11-03 13:06:00 +06:00
x . ItemGroup = = EnumIncomeTaxItemGroup . Exemption_Medical_Allowance & & x . ItemID = = ( int ) EnumIncomeTaxItemGroup . Exemption_Medical_Allowance ) ;
if ( mdExption = = null ) mdExption = this . Add ( EnumIncomeTaxItemGroup . Exemption_Medical_Allowance , ( int ) EnumIncomeTaxItemGroup . Exemption_Medical_Allowance , string . Empty , 0 , 0 , EnumIncomeTaxSide . Dec_SalaryIncome ) ;
2026-11-30 10:14:40 +06:00
IncomeTax basicItem = _currentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID & &
2026-11-03 13:06:00 +06:00
x . ItemGroup = = EnumIncomeTaxItemGroup . Basic_Salary & & x . ItemID = = ( int ) EnumIncomeTaxItemGroup . Basic_Salary ) ;
//Sumon on 24 June 2014
double nMamount = 0 ;
if ( basicItem ! = null ) nMamount = basicItem . TotalAmount *
( double ) ( ( _taxParameter . MaxMedicalPercent ! = 0 ) ? _taxParameter . MaxMedicalPercent / 100 : 0 ) ;
if ( MedicalItem = = null | | MedicalItem . TotalAmount = = 0 )
mdExption . ProjectedAmount = 0.00 ;
else if ( nMamount > _taxParameter . MaxMedicalAmount )
mdExption . ProjectedAmount = MedicalItem . TotalAmount < _taxParameter . MaxMedicalAmount ? MedicalItem . TotalAmount : GlobalFunctions . Round ( _taxParameter . MaxMedicalAmount ) ;
else
mdExption . ProjectedAmount = MedicalItem . TotalAmount > nMamount ? GlobalFunctions . Round ( nMamount ) : MedicalItem . TotalAmount ;
//End
//mdExption.ProjectedAmount =GlobalFunctions.Round(MedicalItem.TotalAmount);
mdExption . TotalAmount = mdExption . ThisMonthAmount + mdExption . PreviousAmount + mdExption . ProjectedAmount ;
mdExption . Side = EnumIncomeTaxSide . Dec_SalaryIncome ;
// this.Add(mdExption);
}
else if ( processItem . ItemCode = = ( int ) EnumIncomeTaxItemGroup . Exemption_LFA_Allowance )
{
2026-11-30 10:14:40 +06:00
IncomeTax LFAItem = _currentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID & &
2026-11-03 13:06:00 +06:00
x . ItemGroup = = EnumIncomeTaxItemGroup . LFA_Allowance & & x . ItemID = = ( int ) EnumIncomeTaxItemGroup . LFA_Allowance ) ;
if ( LFAItem = = null ) continue ; // throw new ServiceException("LFA allowance not found in the collection while calculating HR Examtion");
//continue; //
2026-11-30 10:14:40 +06:00
IncomeTax lfaExption = _currentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID
2026-11-03 13:06:00 +06:00
& & x . ItemGroup = = EnumIncomeTaxItemGroup . Exemption_LFA_Allowance & & x . ItemID = = ( int ) EnumIncomeTaxItemGroup . Exemption_LFA_Allowance ) ;
if ( lfaExption = = null ) lfaExption = this . Add ( EnumIncomeTaxItemGroup . Exemption_LFA_Allowance , ( int ) EnumIncomeTaxItemGroup . Exemption_LFA_Allowance , string . Empty , 0 , 0 , EnumIncomeTaxSide . Dec_SalaryIncome ) ;
lfaExption . ProjectedAmount = GlobalFunctions . Round ( LFAItem . TotalAmount ) ;
lfaExption . TotalAmount = lfaExption . ThisMonthAmount + lfaExption . PreviousAmount + lfaExption . ProjectedAmount ;
lfaExption . Side = EnumIncomeTaxSide . Dec_SalaryIncome ;
// this.Add(mdExption);
}
else if ( processItem . ItemCode = = ( int ) EnumIncomeTaxItemGroup . WPPF_Examption )
{
2026-11-30 10:14:40 +06:00
IncomeTax wppfItem = _currentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID & &
2026-11-03 13:06:00 +06:00
x . ItemGroup = = EnumIncomeTaxItemGroup . WPPF_Allowance & & x . ItemID = = ( int ) EnumIncomeTaxItemGroup . WPPF_Allowance ) ;
if ( wppfItem = = null ) continue ; // throw new ServiceException("LFA allowance not found in the collection while calculating HR Examtion");
//continue; //
2026-11-30 10:14:40 +06:00
IncomeTax wppfExption = _currentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID
2026-11-03 13:06:00 +06:00
& & x . ItemGroup = = EnumIncomeTaxItemGroup . WPPF_Examption & & x . ItemID = = ( int ) EnumIncomeTaxItemGroup . WPPF_Examption ) ;
if ( wppfExption = = null ) wppfExption = this . Add ( EnumIncomeTaxItemGroup . WPPF_Examption , ( int ) EnumIncomeTaxItemGroup . WPPF_Examption , string . Empty , 0 , 0 , EnumIncomeTaxSide . Dec_SalaryIncome ) ;
double exception = wppfItem . TotalAmount ;
if ( wppfItem . TotalAmount > 50000 ) exception = 50000 ;
wppfExption . ProjectedAmount = GlobalFunctions . Round ( exception ) ;
//wppfExption.ThisMonthAmount = 0; // need to remove
//wppfExption.PreviousAmount = 0;// need to remove
wppfExption . TotalAmount = wppfExption . ProjectedAmount ;
wppfExption . Side = EnumIncomeTaxSide . Dec_SalaryIncome ;
}
#endregion Other Allowance Examption
}
}
protected void CalculateCPF ( )
{
if ( _employee . PFMemberType ! = EnumPFMembershipType . Live ) return ;
IncomeTax pfItem = _currentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID & &
x . ItemGroup = = EnumIncomeTaxItemGroup . Company_Contri_PF & & x . ItemID = = ( int ) EnumIncomeTaxItemGroup . Company_Contri_PF ) ;
if ( pfItem = = null ) pfItem = this . Add ( EnumIncomeTaxItemGroup . Company_Contri_PF , ( int ) EnumIncomeTaxItemGroup . Company_Contri_PF , string . Empty , 0 , 0 , EnumIncomeTaxSide . Inc_AnnualIncome ) ;
2026-11-30 10:14:40 +06:00
IncomeTax BasicItem = _currentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID
2026-11-03 13:06:00 +06:00
& & x . ItemGroup = = EnumIncomeTaxItemGroup . Basic_Salary & & x . ItemID = = ( int ) EnumIncomeTaxItemGroup . Basic_Salary ) ;
if ( BasicItem = = null ) return ;
if ( _salary ! = null )
pfItem . ThisMonthAmount = _salary . GetDeductAmount ( EnumSalaryItemCode . PF_Contribution , ( int ) EnumSalaryItemCode . PF_Contribution ) ;
else
{
pfItem . ThisMonthAmount = ( BasicItem . ThisMonthAmount
* this . payrolltype . pFContriCompany ) / 100 ;
}
pfItem . ProjectedAmount = ( BasicItem . ProjectedAmount
* this . payrolltype . pFContriCompany ) / 100 ;
pfItem . ThisMonthAmount = GlobalFunctions . Round ( pfItem . ThisMonthAmount ) ;
pfItem . ProjectedAmount = GlobalFunctions . Round ( pfItem . ProjectedAmount ) ;
}
//protected void CalculateUpdateBonusProjection(double nAmount)
//{
// if (_employee.ForeignExPat == true) return;
// List<FestivalBonusProjection> taxProjections = FestivalBonusProjection.Get(EnumStatus.Active);
// IncomeTax pfItem = IncomeTax.Get(_currentYearTax, _employee.ID, EnumIncomeTaxItemGroup.Bonus, (int)EnumIncomeTaxItemGroup.Bonus);
// if (pfItem == null) pfItem = this.Add(EnumIncomeTaxItemGroup.Bonus, (int)EnumIncomeTaxItemGroup.Bonus, "Festival Bonus", 0, 0, EnumIncomeTaxSide.Inc_SalaryIncome);
// pfItem.ProjectedAmount = nAmount + pfItem.ProjectedAmount;
// if (pfItem.ProjectedAmount <= 0)
// pfItem.ProjectedAmount = 0;
// pfItem.ProjectedAmount = GlobalFunctions.Round(pfItem.ProjectedAmount);
//}
protected void CalculateBonusProjection ( )
{
#region Bonus projetion Management
List < BonusParameter > oparams = null ;
if ( _projectionBonusParams = = null )
{
_projectionBonusParams = new List < BonusParameter > ( ) ;
List < BonusParameter > ops = new BonusParameterService ( ) . Get ( EnumStatus . Active , this . payrolltype . ID ) ;
foreach ( BonusParameter oitem in ops )
if ( oitem . IsProjectInTaxCalculation = = true )
{
_projectionBonusParams . Add ( oitem ) ;
}
}
if ( _projectionBonusParams = = null | | _projectionBonusParams . Count = = 0 ) return ;
2026-11-30 10:14:40 +06:00
oparams = new BonusParameterService ( ) . GetApplicableParameters ( _employee , ( int ) _employee . GradeID , _projectionBonusParams ) ;
2026-11-03 13:06:00 +06:00
if ( oparams = = null ) return ;
_ApplicableBonusParams = oparams ;
foreach ( BonusParameter item in oparams )
{
IncomeTax pfItem = GetTaxItem ( EnumTaxMergeType . Bonus , item . BonusID , item . BonusName ) ;
pfItem . Side = EnumIncomeTaxSide . Inc_SalaryIncome ;
if ( pfItem = = null ) pfItem = this . Add ( EnumIncomeTaxItemGroup . Bonus ,
( int ) EnumIncomeTaxItemGroup . Bonus , item . BonusName , 0 , 0 , EnumIncomeTaxSide . Inc_SalaryIncome ) ;
// pfItem = _currentYearTax.FirstOrDefault(x => x.EmployeeID == _employee.ID &&
//x.ItemGroup == EnumIncomeTaxItemGroup.Bonus && x.ItemID == item.BonusID);
//if (pfItem == null) pfItem = this.Add(EnumIncomeTaxItemGroup.Bonus,
// (int)EnumIncomeTaxItemGroup.Bonus, item.BonusName , 0, 0, EnumIncomeTaxSide.Inc_SalaryIncome);
BonusCalculator ocal = new BonusCalculator ( ) ;
double bonusAmount = pfItem . ProjectedAmount + ocal . CalcluateBonus ( item , _employee , _employee . BasicSalary , _employee . GrossSalary ,
Global . DateFunctions . LastDateOfYear ( payrolltype . NextPayProcessDate ) ) ;
pfItem . ProjectedAmount = 0 ;
//First Project Month
2026-11-30 10:14:40 +06:00
if ( bonusAmount > 0 & & item . firstProjectMonth ! = null & & item . firstProjectMonth > payrolltype . NextPayProcessDate )
2026-11-03 13:06:00 +06:00
{
2026-11-30 10:14:40 +06:00
if ( item . secondProjectMonth ! = null )
2026-11-03 13:06:00 +06:00
pfItem . ProjectedAmount = bonusAmount / 2 ;
else pfItem . ProjectedAmount = bonusAmount ;
}
if ( bonusAmount > 0 & & item . secondProjectMonth ! = null & & item . secondProjectMonth > payrolltype . NextPayProcessDate )
{
pfItem . ProjectedAmount = pfItem . ProjectedAmount + bonusAmount / 2 ;
}
if ( payrolltype . NextPayProcessDate . Month = = 6 ) // Forcely zero on month Jun
pfItem . ProjectedAmount = 0 ;
if ( pfItem . ProjectedAmount < = 0 )
pfItem . ProjectedAmount = 0 ;
pfItem . ProjectedAmount = GlobalFunctions . Round ( pfItem . ProjectedAmount ) ;
this . Add ( pfItem ) ;
}
#endregion
}
protected void CalculateInvestment ( )
{
IncomeTax InvestmentItem = _currentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID & &
x . ItemGroup = = EnumIncomeTaxItemGroup . Tax_Credit_On_Investment & & x . ItemID = = ( int ) EnumIncomeTaxItemGroup . Tax_Credit_On_Investment ) ;
if ( InvestmentItem = = null ) InvestmentItem = this . Add ( EnumIncomeTaxItemGroup . Tax_Credit_On_Investment , ( int ) EnumIncomeTaxItemGroup . Tax_Credit_On_Investment , string . Empty , 0 , 0 , EnumIncomeTaxSide . Dec_GrossTax ) ;
if ( _employee . ForeignExPat = = true ) return ;
if ( this . _investmentwithoutpf = = null )
this . _investmentwithoutpf = new SystemConfigarationService ( ) . GetconfigBooleanValue ( EnumConfigurationType . Logic , "incometax" , "investmentwithoutpf" ) ;
IncomeTax AnnualItem = null ;
double nExemptedAmount = 0 ;
//if (this._investmentwithoutpf==true)
//{
// AnnualItem = _currentYearTax.FirstOrDefault(x => x.EmployeeID == _employee.ID && x.ItemGroup == EnumIncomeTaxItemGroup.Annual_Salary_Income
// && x.ItemID == (int)EnumIncomeTaxItemGroup.Annual_Salary_Income);
// IncomeTax ExemptedItem = _currentYearTax.FirstOrDefault(x => x.EmployeeID == _employee.ID && x.ItemGroup == EnumIncomeTaxItemGroup.AnnualExemption
// && x.ItemID == (int)EnumIncomeTaxItemGroup.AnnualExemption);
// if (ExemptedItem != null)
// {
// nExemptedAmount = ExemptedItem.TotalAmount;
// }
//}
//else
AnnualItem = _currentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID & & x . ItemGroup = = EnumIncomeTaxItemGroup . Annual_Income
& & x . ItemID = = ( int ) EnumIncomeTaxItemGroup . Annual_Income ) ;
double investmentCanBeShown = ( ( ( AnnualItem . TotalAmount - nExemptedAmount ) * _taxParameter . MaxInvestPercent ) / 100 ) ;
if ( investmentCanBeShown > _taxParameter . MaxInvAmount ) investmentCanBeShown = _taxParameter . MaxInvAmount ;
double investAmount = investmentCanBeShown ;
_isActualInvestment = false ;
if ( this . payrolltype . ActualTaxInvestment = = true )
{
_taxParameter . InvestmentActiveMonth = _taxParameter . FiscalyearDatefrom ;
_isActualInvestment = true ;
}
if ( _isActualInvestment = = false & & _taxParameter . InvestmentActiveMonth = = null ) _isActualInvestment = false ;
else
{
DateTime investmonth = new DateTime ( _taxParameter . FiscalyearDatefrom . Year , ( ( DateTime ) _taxParameter . InvestmentActiveMonth ) . Month , 1 ) ;
investmonth = GlobalFunctions . LastDateOfMonth ( investmonth ) ;
if ( investmonth < = this . payrolltype . NextPayProcessDate )
_isActualInvestment = true ;
}
if ( _isActualInvestment = = true ) // payroll type wise Actual investment date is different, so this done in temporary basis
{
2026-11-30 10:14:40 +06:00
IncomeTax ActualInvestment = _currentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID & &
2026-11-03 13:06:00 +06:00
x . ItemGroup = = EnumIncomeTaxItemGroup . Investment_Actual & & x . ItemID = = ( int ) EnumIncomeTaxItemGroup . Investment_Actual ) ;
if ( ActualInvestment = = null )
ActualInvestment = this . Add ( EnumIncomeTaxItemGroup . Investment_Actual , ( int ) EnumIncomeTaxItemGroup . Investment_Actual , string . Empty , 0 , 0 , EnumIncomeTaxSide . Tax_Info_Item ) ;
2026-11-30 10:14:40 +06:00
IncomeTax pfItem = _currentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID & & x . ItemGroup = = EnumIncomeTaxItemGroup . Company_Contri_PF
& & x . ItemID = = ( int ) EnumIncomeTaxItemGroup . Company_Contri_PF ) ;
2026-11-03 13:06:00 +06:00
investAmount = 0 ;
if ( pfItem ! = null )
investAmount = investAmount + ( pfItem . TotalAmount * 2 ) ;
if ( this . _investmentTypes = = null ) this . _investmentTypes = new TaxInvestmentService ( ) . Get ( EnumStatus . Regardless ) ;
if ( this . _empTaxInvestments = = null ) this . _empTaxInvestments = new EmployeeTaxInvestmentService ( ) . GetByTaxParamID ( this . _taxParameter . ID ) ;
double nactualInvt = EmployeeTaxInvestment . GetAmount ( this . _employee . ID , _empTaxInvestments , _investmentTypes ) ;
investAmount = investAmount + nactualInvt ;
ActualInvestment . ProjectedAmount = nactualInvt ;
ActualInvestment . TotalAmount = nactualInvt ;
}
2026-11-30 10:14:40 +06:00
IncomeTax InvestmentAllowed = _currentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID & & x . ItemGroup = = EnumIncomeTaxItemGroup . Investment_Allowed
& & x . ItemID = = ( int ) EnumIncomeTaxItemGroup . Investment_Allowed ) ;
2026-11-03 13:06:00 +06:00
if ( InvestmentAllowed = = null ) InvestmentAllowed = this . Add ( EnumIncomeTaxItemGroup . Investment_Allowed ,
( int ) EnumIncomeTaxItemGroup . Investment_Allowed , string . Empty , 0 , 0 , EnumIncomeTaxSide . Tax_Info_Item ) ;
InvestmentAllowed . ProjectedAmount = GlobalFunctions . Round ( investmentCanBeShown ) ;
InvestmentAllowed . TotalAmount = GlobalFunctions . Round ( investmentCanBeShown ) ;
if ( investAmount > investmentCanBeShown )
investAmount = investmentCanBeShown ;
#region Rebate
double taxCredit = 0 ;
double nTempRebate = ( investAmount * _taxParameter . MaxInvExempPercent ) / 100 ;
if ( nTempRebate > ( AnnualItem . TotalAmount * . 03 ) )
nTempRebate = AnnualItem . TotalAmount * . 03 ;
if ( nTempRebate > 1000000 )
nTempRebate = 1000000 ;
taxCredit = nTempRebate ;
#endregion
InvestmentItem . ProjectedAmount = GlobalFunctions . Round ( taxCredit ) ;
InvestmentItem . TotalAmount = GlobalFunctions . Round ( taxCredit ) ;
}
protected void CmpProvidedHouseAndTransport ( DateTime month )
{
try
{
if ( _assignedHeads = = null ) return ;
2026-11-30 10:14:40 +06:00
List < ITEmpHead > Items = _assignedHeads . FindAll ( x = > x . EmployeeID = = _employee . ID ) ;
2026-11-03 13:06:00 +06:00
if ( Items = = null | | Items . Count = = 0 ) return ;
DateTime fromDate = GlobalFunctions . FirstDateOfMonth ( month ) ;
DateTime toDate = GlobalFunctions . LastDateOfMonth ( month ) ;
bool bvalid = false ;
2026-11-30 10:14:40 +06:00
IncomeTax basicSalaryItem = _currentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID
2026-11-03 13:06:00 +06:00
& & x . ItemGroup = = EnumIncomeTaxItemGroup . Basic_Salary
2026-11-30 10:14:40 +06:00
& & x . ItemID = = ( int ) EnumIncomeTaxItemGroup . Basic_Salary ) ;
2026-11-03 13:06:00 +06:00
if ( basicSalaryItem = = null ) throw new ServiceException ( "Basic salary item not found in the collection on "
+ " calculating Company provided Car/HouseRent of the Employee No:" + _employee . EmployeeNo ) ;
double tempAmount = 0 ;
double carparcent = ( ( double ) 5 / ( double ) 100 ) ;
double hrPercent = ( ( double ) 25 / ( double ) 100 ) ;
foreach ( ITEmpHead item in Items )
{
IncomeTax taxItem ;
bvalid = false ;
if ( item . StartDate < = fromDate & & item . EndDate > = fromDate ) bvalid = true ;
else bvalid = false ;
if ( item . StartDate < = toDate & & item . EndDate > = toDate ) bvalid = true ;
else bvalid = false ;
if ( item . StartDate > = fromDate ) { fromDate = item . StartDate ; }
if ( item . EndDate < = toDate ) { toDate = item . EndDate ; }
if ( bvalid = = false ) continue ;
#region Calculate Car calculation
if ( item . HeadID = = EnumIncomeTaxHead . Car )
{
2026-11-30 10:14:40 +06:00
taxItem = _currentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID
& & x . ItemGroup = = EnumIncomeTaxItemGroup . Cmp_Provided_car
& & x . ItemID = = ( int ) EnumIncomeTaxItemGroup . Cmp_Provided_car ) ;
2026-11-03 13:06:00 +06:00
if ( taxItem = = null ) taxItem = this . Add ( EnumIncomeTaxItemGroup . Cmp_Provided_car ,
( int ) EnumIncomeTaxItemGroup . Cmp_Provided_car , "Company provided car" , 0 , 0 , EnumIncomeTaxSide . Inc_SalaryIncome ) ;
tempAmount = item . HouseRent ;
if ( item . EndDate > = _taxParameter . FiscalyearDateTo ) toDate = _taxParameter . FiscalyearDateTo ;
taxItem . ThisMonthAmount = tempAmount ;
toDate = item . EndDate ;
if ( item . EndDate > _taxParameter . FiscalyearDateTo ) toDate = _taxParameter . FiscalyearDateTo ;
if ( _employee . EndOfContractDate ! = null & & _employee . EndOfContractDate < toDate )
toDate = Convert . ToDateTime ( _employee . EndOfContractDate ) ;
//if (_projectedMonth == 0) tempAmount = basicSalaryItem.ProjectedAmount;
//else tempAmount = basicSalaryItem.ProjectedAmount / _projectedMonth;
if ( toDate = = GlobalFunctions . LastDateOfMonth ( toDate ) )
2026-11-30 10:14:40 +06:00
taxItem . ProjectedAmount = ( tempAmount * ( Global . DateFunctions . DateDiff ( "m" , GlobalFunctions . LastDateOfMonth ( month ) . AddDays ( 1 ) , toDate ) + 1 ) ) ;
2026-11-03 13:06:00 +06:00
else
2026-11-30 10:14:40 +06:00
taxItem . ProjectedAmount = ( tempAmount * GlobalFunctions . GetFraction ( GlobalFunctions . LastDateOfMonth ( month ) . AddDays ( 1 ) , toDate ) ) ;
2026-11-03 13:06:00 +06:00
taxItem . ProjectedAmount = GlobalFunctions . Round ( taxItem . ProjectedAmount ) ;
2026-11-30 10:14:40 +06:00
if ( taxItem . TotalAmount < 120000 )
2026-11-03 13:06:00 +06:00
{
taxItem . ProjectedAmount = 120000 - ( taxItem . PreviousAmount + taxItem . ThisMonthAmount ) ;
}
}
#endregion Calculate Car calculation
#region Calculate House rent calculation
if ( item . HeadID = = EnumIncomeTaxHead . House )
{
2026-11-30 10:14:40 +06:00
taxItem = _currentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID
2026-11-03 13:06:00 +06:00
& & x . ItemGroup = = EnumIncomeTaxItemGroup . Cmp_Provided_House
2026-11-30 10:14:40 +06:00
& & x . ItemID = = ( int ) EnumIncomeTaxItemGroup . Cmp_Provided_House ) ;
2026-11-03 13:06:00 +06:00
if ( taxItem = = null ) taxItem = this . Add ( EnumIncomeTaxItemGroup . Cmp_Provided_House ,
( int ) EnumIncomeTaxItemGroup . Cmp_Provided_House , "Company provided House" , 0 , 0 , EnumIncomeTaxSide . Inc_SalaryIncome ) ;
if ( item . HouseRent = = 0 )
{
if ( _salary = = null )
tempAmount = basicSalaryItem . ThisMonthAmount ;
else
{
2026-11-30 10:14:40 +06:00
SalaryMonthlyDetail detail = _salary . Details . FirstOrDefault ( x = > x . itemGroupCode = = EnumSalaryGroup . Gross
2026-11-03 13:06:00 +06:00
& & x . ItemCode = = EnumSalaryItemCode . Basic_Salary & & x . ItemID = = ( int ) EnumSalaryItemCode . Basic_Salary ) ;
if ( detail = = null ) continue ;
tempAmount = detail . ChangedAmount ;
#region basic salary arrear effect
foreach ( EmployeeGradeSalary gse in _salary . ArrearGradeSalaries )
{
if ( gse . TillDate > item . StartDate )
{
if ( item . StartDate > gse . EffectDate )
tempAmount = tempAmount + gse . BasicSalary *
GlobalFunctions . GetFraction ( item . StartDate , ( DateTime ) gse . TillDate ) ;
else
{
2026-11-30 10:14:40 +06:00
SalaryMonthlyDetail arreardetail = _salary . Details . FirstOrDefault ( x = > x . itemGroupCode = = EnumSalaryGroup . Arrear
2026-11-03 13:06:00 +06:00
& & x . ItemCode = = EnumSalaryItemCode . Basic_Salary & & x . ItemID = = ( int ) EnumSalaryItemCode . Basic_Salary ) ;
if ( arreardetail ! = null )
{
tempAmount = tempAmount + arreardetail . ChangedAmount ;
}
}
}
}
foreach ( EmployeeGradeSalary gse in _salary . ArrearPaidGradeSalaries )
{
if ( gse . TillDate > item . StartDate )
{
if ( item . StartDate > gse . EffectDate )
tempAmount = tempAmount - gse . BasicSalary *
GlobalFunctions . GetFraction ( item . StartDate , ( DateTime ) gse . TillDate ) ;
else
tempAmount = tempAmount - gse . BasicSalary *
GlobalFunctions . GetFraction ( gse . EffectDate , ( DateTime ) gse . TillDate ) ;
}
}
#endregion basic salary arrear effect
}
taxItem . ThisMonthAmount = GlobalFunctions . Round ( tempAmount * hrPercent ) ;
}
else
taxItem . ThisMonthAmount = GlobalFunctions . Round ( GlobalFunctions . GetFraction ( fromDate , toDate ) * item . HouseRent ) ;
//if (item.EndDate <= toDate) continue;
//toDate = item.EndDate;
if ( item . EndDate > = _taxParameter . FiscalyearDateTo ) toDate = _taxParameter . FiscalyearDateTo ;
if ( item . HouseRent = = 0 )
{
if ( _projectedMonth = = 0 )
tempAmount = basicSalaryItem . ProjectedAmount ;
else tempAmount = basicSalaryItem . ProjectedAmount / _projectedMonth ;
if ( toDate = = GlobalFunctions . LastDateOfMonth ( toDate ) )
taxItem . ProjectedAmount = ( tempAmount * ( Global . DateFunctions . DateDiff ( "m" , GlobalFunctions . LastDateOfMonth ( month ) . AddDays ( 1 ) , toDate ) + 1 ) * hrPercent ) ;
else
taxItem . ProjectedAmount = ( tempAmount * GlobalFunctions . GetFraction ( GlobalFunctions . LastDateOfMonth ( month ) . AddDays ( 1 ) , toDate ) ) * hrPercent ;
taxItem . ProjectedAmount = GlobalFunctions . Round ( taxItem . ProjectedAmount ) ;
}
else
{
taxItem . ProjectedAmount = GlobalFunctions . GetFraction (
GlobalFunctions . LastDateOfMonth ( month ) . AddDays ( 1 ) , toDate ) * item . HouseRent ;
taxItem . ProjectedAmount = GlobalFunctions . Round ( taxItem . ProjectedAmount ) ;
}
taxItem . Side = EnumIncomeTaxSide . Inc_SalaryIncome ;
}
#endregion Calculate Car calculation
}
}
catch ( ServiceException ex )
{
throw new ServiceException ( ex . Message ) ;
}
catch ( Exception ex )
{
throw new ServiceException ( ex . Message ) ;
}
}
private double GetTotalSalary ( )
{
double TotGross ;
double TotExemp ;
TotGross = 0 ; TotExemp = 0 ;
foreach ( IncomeTax item in _currentYearTax )
{
if ( item . Side = = EnumIncomeTaxSide . Dec_SalaryIncome )
TotExemp = TotExemp + item . TotalAmount ;
else if ( item . Side = = EnumIncomeTaxSide . Inc_SalaryIncome )
TotGross = TotGross + item . TotalAmount ;
}
return TotGross - TotExemp ;
}
protected double GetAnnualIncome ( )
{
double TotIncome = 0 ;
foreach ( IncomeTax item in _currentYearTax )
{
if ( item . Side = = EnumIncomeTaxSide . Inc_AnnualIncome )
TotIncome = TotIncome + item . TotalAmount ;
else if ( item . Side = = EnumIncomeTaxSide . Dec_AnnualIncome )
TotIncome = TotIncome - item . TotalAmount ;
}
TotIncome = this . GetTotalSalary ( ) + TotIncome ;
return TotIncome ;
}
protected void CalculateTotalIncome ( )
{
2026-11-30 10:14:40 +06:00
IncomeTax salaryIncome = _currentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID & &
2026-11-03 13:06:00 +06:00
x . ItemGroup = = EnumIncomeTaxItemGroup . Annual_Salary_Income & & x . ItemID = = ( int ) EnumIncomeTaxItemGroup . Annual_Salary_Income ) ;
if ( salaryIncome = = null ) salaryIncome = this . Add ( EnumIncomeTaxItemGroup . Annual_Salary_Income ,
( int ) EnumIncomeTaxItemGroup . Annual_Salary_Income , string . Empty , 0 , 0 , EnumIncomeTaxSide . Tax_fixed_Item ) ;
salaryIncome . TotalAmount = 0 ;
salaryIncome . PreviousAmount = 0 ;
salaryIncome . ThisMonthAmount = 0 ;
salaryIncome . ProjectedAmount = 0 ;
foreach ( IncomeTax item in _currentYearTax )
{
if ( item . Side = = EnumIncomeTaxSide . Inc_SalaryIncome )
{
salaryIncome . PreviousAmount = salaryIncome . PreviousAmount + item . PreviousAmount ;
salaryIncome . ThisMonthAmount = salaryIncome . ThisMonthAmount + item . ThisMonthAmount ;
salaryIncome . ProjectedAmount = salaryIncome . ProjectedAmount + item . ProjectedAmount ;
salaryIncome . TotalAmount = salaryIncome . TotalAmount + item . TotalAmount ;
}
else if ( item . Side = = EnumIncomeTaxSide . Dec_SalaryIncome )
{
salaryIncome . PreviousAmount = salaryIncome . PreviousAmount - item . PreviousAmount ;
salaryIncome . ThisMonthAmount = salaryIncome . ThisMonthAmount - item . ThisMonthAmount ;
salaryIncome . ProjectedAmount = salaryIncome . ProjectedAmount - item . ProjectedAmount ;
salaryIncome . TotalAmount = salaryIncome . TotalAmount - item . TotalAmount ;
}
}
salaryIncome . PreviousAmount = GlobalFunctions . Round ( salaryIncome . PreviousAmount ) ;
salaryIncome . ThisMonthAmount = GlobalFunctions . Round ( salaryIncome . ThisMonthAmount ) ;
salaryIncome . ProjectedAmount = GlobalFunctions . Round ( salaryIncome . ProjectedAmount ) ;
2026-11-30 10:14:40 +06:00
IncomeTax annualIncome = _currentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID
2026-11-03 13:06:00 +06:00
& & x . ItemGroup = = EnumIncomeTaxItemGroup . Annual_Income & & x . ItemID = = ( int ) EnumIncomeTaxItemGroup . Annual_Income ) ;
if ( annualIncome = = null ) annualIncome = this . Add ( EnumIncomeTaxItemGroup . Annual_Income ,
( int ) EnumIncomeTaxItemGroup . Annual_Income , string . Empty , 0 , 0 , EnumIncomeTaxSide . Tax_fixed_Item ) ;
annualIncome . TotalAmount = 0 ;
annualIncome . PreviousAmount = 0 ;
annualIncome . ThisMonthAmount = 0 ;
annualIncome . ProjectedAmount = 0 ;
foreach ( IncomeTax item in _currentYearTax )
{
if ( item . Side = = EnumIncomeTaxSide . Inc_AnnualIncome )
{
annualIncome . PreviousAmount = annualIncome . PreviousAmount + item . PreviousAmount ;
annualIncome . ThisMonthAmount = annualIncome . ThisMonthAmount + item . ThisMonthAmount ;
annualIncome . ProjectedAmount = annualIncome . ProjectedAmount + item . ProjectedAmount ;
annualIncome . TotalAmount = annualIncome . TotalAmount + item . TotalAmount ;
}
else if ( item . Side = = EnumIncomeTaxSide . Dec_AnnualIncome )
{
annualIncome . PreviousAmount = annualIncome . PreviousAmount - item . PreviousAmount ;
annualIncome . ThisMonthAmount = annualIncome . ThisMonthAmount - item . ThisMonthAmount ;
annualIncome . ProjectedAmount = annualIncome . ProjectedAmount - item . ProjectedAmount ;
annualIncome . TotalAmount = annualIncome . TotalAmount - item . TotalAmount ;
}
}
annualIncome . PreviousAmount = annualIncome . PreviousAmount + salaryIncome . PreviousAmount ;
annualIncome . ThisMonthAmount = annualIncome . ThisMonthAmount + salaryIncome . ThisMonthAmount ;
annualIncome . ProjectedAmount = annualIncome . ProjectedAmount + salaryIncome . ProjectedAmount ;
annualIncome . TotalAmount = annualIncome . TotalAmount + salaryIncome . TotalAmount ;
annualIncome . PreviousAmount = GlobalFunctions . Round ( annualIncome . PreviousAmount ) ;
annualIncome . ThisMonthAmount = GlobalFunctions . Round ( annualIncome . ThisMonthAmount ) ;
annualIncome . ProjectedAmount = GlobalFunctions . Round ( annualIncome . ProjectedAmount ) ;
}
protected double GetTaxRebate ( )
{
double TotIncome = 0 ;
foreach ( IncomeTax item in _currentYearTax )
{
if ( item . ItemGroup = = EnumIncomeTaxItemGroup . Tax_Gross_Rebate | |
item . ItemGroup = = EnumIncomeTaxItemGroup . Tax_Gross_Refund | |
item . ItemGroup = = EnumIncomeTaxItemGroup . Tax_Gross_OtherRebate | |
2026-11-30 10:14:40 +06:00
item . ItemGroup = = EnumIncomeTaxItemGroup . Tax_Gross_OtherAddable )
2026-11-03 13:06:00 +06:00
{
if ( item . Side = = EnumIncomeTaxSide . Inc_GrossTax )
TotIncome = TotIncome + item . TotalAmount ;
else if ( item . Side = = EnumIncomeTaxSide . Dec_GrossTax )
TotIncome = TotIncome - item . TotalAmount ;
}
}
return TotIncome ;
}
/// <summary>
/// follwing function equal the net tax payable and tax deducted amount. Adjusted amount stores in Tax refund item.
/// </summary>
protected void CalculateYearlyRefund ( )
{
2026-11-30 10:14:40 +06:00
IncomeTax oNetTaxPayable = this . CurrentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID & &
x . ItemGroup = = EnumIncomeTaxItemGroup . Net_Payable & & x . ItemID = = ( int ) EnumIncomeTaxItemGroup . Net_Payable ) ;
IncomeTax oTaxDeducted = this . CurrentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID & &
2026-11-03 13:06:00 +06:00
x . ItemGroup = = EnumIncomeTaxItemGroup . Tax_Deducted & & x . ItemID = = ( int ) EnumIncomeTaxItemGroup . Tax_Deducted ) ;
if ( oNetTaxPayable = = null ) oNetTaxPayable = this . Add ( EnumIncomeTaxItemGroup . Net_Payable ,
( int ) EnumIncomeTaxItemGroup . Net_Payable , string . Empty , 0 , 0 , EnumIncomeTaxSide . Tax_fixed_Item ) ;
if ( oTaxDeducted = = null ) oTaxDeducted = this . Add ( EnumIncomeTaxItemGroup . Tax_Deducted ,
( int ) EnumIncomeTaxItemGroup . Tax_Deducted , string . Empty , 0 , 0 , EnumIncomeTaxSide . Tax_fixed_Item ) ;
if ( ( oNetTaxPayable . TotalAmount - oTaxDeducted . TotalAmount ) ! = 0 )
{
2026-11-30 10:14:40 +06:00
IncomeTax TaxRefund = _currentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID
2026-11-03 13:06:00 +06:00
& & x . ItemGroup = = EnumIncomeTaxItemGroup . Tax_Refund_On_Current_Year & & x . ItemID = = ( int ) EnumIncomeTaxItemGroup . Tax_Refund_On_Current_Year ) ;
if ( TaxRefund = = null ) TaxRefund = this . Add ( EnumIncomeTaxItemGroup . Tax_Refund_On_Current_Year ,
( int ) EnumIncomeTaxItemGroup . Tax_Refund_On_Current_Year , string . Empty , 0 , 0 , EnumIncomeTaxSide . Tax_fixed_Item ) ;
TaxRefund . ThisMonthAmount = 0 ;
TaxRefund . PreviousAmount = 0 ;
TaxRefund . ProjectedAmount = 0 ;
TaxRefund . TotalAmount = 0 ;
TaxRefund . TotalAmount = GlobalFunctions . Round ( oNetTaxPayable . TotalAmount - oTaxDeducted . TotalAmount ) ;
// set equal to Net_Taxable_income to Tax_deducted_current_year amount
// oTaxDeducted.TotalAmount = oNetTaxPayable.TotalAmount;
}
}
protected void CalculateNetPayable ( )
{
2026-11-30 10:14:40 +06:00
IncomeTax GrossTax = _currentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID
2026-11-03 13:06:00 +06:00
& & x . ItemGroup = = EnumIncomeTaxItemGroup . Gross_Tax & & x . ItemID = = ( int ) EnumIncomeTaxItemGroup . Gross_Tax ) ;
if ( GrossTax = = null )
{
this . Add ( GrossTax ) ;
}
this . CalculateGrossTax ( ) ;
2026-11-30 10:14:40 +06:00
IncomeTax netPayable = _currentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID & &
2026-11-03 13:06:00 +06:00
x . ItemGroup = = EnumIncomeTaxItemGroup . Net_Payable & & x . ItemID = = ( int ) EnumIncomeTaxItemGroup . Net_Payable ) ;
if ( netPayable = = null ) netPayable = this . Add ( EnumIncomeTaxItemGroup . Net_Payable ,
( int ) EnumIncomeTaxItemGroup . Net_Payable , string . Empty , 0 , 0 , EnumIncomeTaxSide . Tax_fixed_Item ) ;
netPayable . TotalAmount = 0 ;
netPayable . PreviousAmount = 0 ;
netPayable . ThisMonthAmount = 0 ;
netPayable . ProjectedAmount = 0 ;
if ( GrossTax . TotalAmount > 0 )
{
2026-11-30 10:14:40 +06:00
IncomeTax InvestItem = _currentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID
2026-11-03 13:06:00 +06:00
& & x . ItemGroup = = EnumIncomeTaxItemGroup . Tax_Credit_On_Investment & & x . ItemID = = ( int ) EnumIncomeTaxItemGroup . Tax_Credit_On_Investment ) ;
if ( InvestItem = = null ) this . CalculateInvestment ( ) ;
2026-11-30 10:14:40 +06:00
2026-11-03 13:06:00 +06:00
netPayable . ProjectedAmount = netPayable . ProjectedAmount + GrossTax . TotalAmount - InvestItem . TotalAmount ;
#region Tax Incentive
ProcessItem pitem = _processItems . FirstOrDefault ( x = > x . ItemGroup = = ( int ) EnumIncomeTaxSide . Dec_GrossTax & & x . ItemCode = = ( int ) EnumIncomeTaxItemGroup . Tax_Incentive ) ;
if ( netPayable . ProjectedAmount > 0 & & pitem ! = null )
{
IncomeTax incentive = _currentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID & &
x . ItemGroup = = EnumIncomeTaxItemGroup . Tax_Incentive & & x . ItemID = = ( int ) EnumIncomeTaxItemGroup . Tax_Incentive ) ;
if ( incentive = = null ) incentive = this . Add ( EnumIncomeTaxItemGroup . Tax_Incentive ,
( int ) EnumIncomeTaxItemGroup . Tax_Incentive , "Tax Incentive" , 0 , 0 , EnumIncomeTaxSide . Dec_GrossTax ) ;
incentive . TotalAmount = 0 ;
incentive . PreviousAmount = 0 ;
incentive . ThisMonthAmount = 0 ;
incentive . ProjectedAmount = 0 ;
incentive . ProjectedAmount = GlobalFunctions . Round ( netPayable . ProjectedAmount * 0.05 ) ;
if ( incentive . ProjectedAmount > 25000 )
{
incentive . ProjectedAmount = 25000 ;
}
incentive . TotalAmount = GlobalFunctions . Round ( incentive . ProjectedAmount ) ;
netPayable . ProjectedAmount = netPayable . ProjectedAmount - incentive . TotalAmount ;
2026-11-30 10:14:40 +06:00
}
2026-11-03 13:06:00 +06:00
#endregion
if ( netPayable . ProjectedAmount < _taxParameter . MinTaxAmount )
netPayable . ProjectedAmount = _taxParameter . MinTaxAmount ;
}
netPayable . ProjectedAmount = netPayable . ProjectedAmount + this . GetTaxRebate ( ) ;
// netPayable.ProjectedAmount = netPayable.ProjectedAmount>=5000?GlobalFunctions.Round(netPayable.ProjectedAmount):5000;
netPayable . TotalAmount = GlobalFunctions . Round ( netPayable . ProjectedAmount ) ;
}
protected void CalculateGrossTax ( )
{
2026-11-30 10:14:40 +06:00
IncomeTax GrossTax = _currentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID
2026-11-03 13:06:00 +06:00
& & x . ItemGroup = = EnumIncomeTaxItemGroup . Gross_Tax & & x . ItemID = = ( int ) EnumIncomeTaxItemGroup . Gross_Tax ) ;
if ( GrossTax = = null ) GrossTax = this . Add ( EnumIncomeTaxItemGroup . Gross_Tax ,
( int ) EnumIncomeTaxItemGroup . Gross_Tax , string . Empty , 0 , 0 , EnumIncomeTaxSide . Tax_fixed_Item ) ;
double annualIncome = this . GetAnnualIncome ( ) ;
double yearlyTax = this . GetTaxAmount ( annualIncome ) ;
GrossTax . TotalAmount = 0 ;
GrossTax . PreviousAmount = 0 ;
GrossTax . ThisMonthAmount = 0 ;
GrossTax . ProjectedAmount = GlobalFunctions . Round ( yearlyTax ) ;
GrossTax . TotalAmount = GlobalFunctions . Round ( yearlyTax ) ;
}
protected double CalculateDecutedAmount ( )
{
double nAmount = 0 ;
double nTaxAmount = 0 ;
2026-11-30 10:14:40 +06:00
IncomeTax TaxDeductitem = _currentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID
2026-11-03 13:06:00 +06:00
& & x . ItemGroup = = EnumIncomeTaxItemGroup . Tax_Deducted & & x . ItemID = = ( int ) EnumIncomeTaxItemGroup . Tax_Deducted ) ;
if ( TaxDeductitem ! = null )
{
nAmount = TaxDeductitem . ThisMonthAmount ;
TaxDeductitem . ThisMonthAmount = 0 ;
}
this . CalculateThisMonth ( ) ;
2026-11-30 10:14:40 +06:00
TaxDeductitem = _currentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID & &
2026-11-03 13:06:00 +06:00
x . ItemGroup = = EnumIncomeTaxItemGroup . Tax_Deducted & & x . ItemID = = ( int ) EnumIncomeTaxItemGroup . Tax_Deducted ) ;
if ( TaxDeductitem ! = null )
{
nTaxAmount = TaxDeductitem . ThisMonthAmount - nAmount ;
}
return nTaxAmount ;
}
protected void UndoDecutedAmount ( double nAmount )
{
2026-11-30 10:14:40 +06:00
IncomeTax TaxDeductitem = _currentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID
2026-11-03 13:06:00 +06:00
& & x . ItemGroup = = EnumIncomeTaxItemGroup . Tax_Deducted & & x . ItemID = = ( int ) EnumIncomeTaxItemGroup . Tax_Deducted ) ;
if ( TaxDeductitem ! = null )
TaxDeductitem . ThisMonthAmount = TaxDeductitem . ThisMonthAmount - nAmount ;
//this.CalculateThisMonth();
}
protected double CalculateOnceOfInvestmentAmt ( double IncomeAmount )
{
if ( _employee . ForeignExPat = = true ) return 0 ;
2026-11-30 10:14:40 +06:00
if ( this . _investmentwithoutpf = = null )
2026-11-03 13:06:00 +06:00
this . _investmentwithoutpf = new SystemConfigarationService ( ) . GetconfigBooleanValue ( EnumConfigurationType . Logic , "incometax" , "investmentwithoutpf" ) ;
IncomeTax AnnItem = null ;
2026-11-30 10:14:40 +06:00
AnnItem = _currentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID & & x . ItemGroup = = EnumIncomeTaxItemGroup . Annual_Income
& & x . ItemID = = ( int ) EnumIncomeTaxItemGroup . Annual_Income ) ;
2026-11-03 13:06:00 +06:00
double totalIncome = IncomeAmount ; //AnnItem.TotalAmount - _onceoffAmount;
double investmentCanBeShown = ( ( totalIncome * _taxParameter . MaxInvestPercent ) / 100 ) ;
if ( investmentCanBeShown > _taxParameter . MaxInvAmount ) investmentCanBeShown = _taxParameter . MaxInvAmount ;
double investAmount = investmentCanBeShown ;
_isActualInvestment = false ;
if ( payrolltype . ActualTaxInvestment = = true )
{
_taxParameter . InvestmentActiveMonth = _taxParameter . FiscalyearDatefrom ;
_isActualInvestment = true ;
}
if ( _isActualInvestment = = false & & _taxParameter . InvestmentActiveMonth = = null ) _isActualInvestment = false ;
else
{
DateTime investmonth = new DateTime ( _taxParameter . FiscalyearDatefrom . Year , ( ( DateTime ) _taxParameter . InvestmentActiveMonth ) . Month , 1 ) ;
investmonth = GlobalFunctions . LastDateOfMonth ( investmonth ) ;
if ( investmonth < = payrolltype . NextPayProcessDate )
_isActualInvestment = true ;
}
if ( _isActualInvestment = = true )
{
2026-11-30 10:14:40 +06:00
IncomeTax ActualInvestment = _currentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID & &
2026-11-03 13:06:00 +06:00
x . ItemGroup = = EnumIncomeTaxItemGroup . Investment_Actual & & x . ItemID = = ( int ) EnumIncomeTaxItemGroup . Investment_Actual ) ;
if ( ActualInvestment = = null )
ActualInvestment = this . Add ( EnumIncomeTaxItemGroup . Investment_Actual , ( int ) EnumIncomeTaxItemGroup . Investment_Actual , string . Empty , 0 , 0 , EnumIncomeTaxSide . Tax_Info_Item ) ;
2026-11-30 10:14:40 +06:00
IncomeTax pfItem = _currentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID & & x . ItemGroup = = EnumIncomeTaxItemGroup . Company_Contri_PF
& & x . ItemID = = ( int ) EnumIncomeTaxItemGroup . Company_Contri_PF ) ;
2026-11-03 13:06:00 +06:00
investAmount = 0 ;
if ( pfItem ! = null )
investAmount = investAmount + ( pfItem . TotalAmount * 2 ) ;
//EmployeeTaxInvestment etax = new EmployeeTaxInvestment();
//double nactualInvt = new EmployeeTaxInvestmentService().GetAmount(_taxParameter.ID, _employee.ID);
if ( this . _investmentTypes = = null ) this . _investmentTypes = new TaxInvestmentService ( ) . Get ( EnumStatus . Regardless ) ;
if ( this . _empTaxInvestments = = null ) this . _empTaxInvestments = new EmployeeTaxInvestmentService ( ) . GetByTaxParamID ( this . _taxParameter . ID ) ;
double nactualInvt = EmployeeTaxInvestment . GetAmount ( this . _employee . ID , _empTaxInvestments , _investmentTypes ) ;
investAmount = investAmount + nactualInvt ;
}
if ( investAmount > investmentCanBeShown )
investAmount = investmentCanBeShown ;
double taxCredit = 0 ;
taxCredit = ( investAmount * _taxParameter . MaxInvExempPercent ) / 100 ;
//if (totalIncome <= 1500000)
// taxCredit = investAmount * .15;
//else taxCredit = investAmount * .10;
//if (AnnItem.TotalAmount > 1000000 && AnnItem.TotalAmount <= 3000000)
// taxCredit = (investAmount > 250000) ? (250000 * .15) + (investAmount - 250000) * .12 : investAmount * .15;
//if (AnnItem.TotalAmount > 3000000)
//{
// taxCredit = (investAmount > 250000) ? (250000 * .15) : investAmount * .15;
// investAmount = investAmount - 250000;
// if (investAmount > 0)
// taxCredit = taxCredit + ((investAmount > 500000) ? (500000 * .12) + (investAmount - 500000) * .10 : investAmount * .12);
//}
//IncomeTax InvestmentItem = IncomeTax.Get(_currentYearTax, _employee.ID, EnumIncomeTaxItemGroup.Tax_Credit_On_Investment,
// (int)EnumIncomeTaxItemGroup.Tax_Credit_On_Investment);
return ( taxCredit ) ;
}
protected void CalculateThisMonth ( )
{
2026-11-30 10:14:40 +06:00
IncomeTax TaxDeductitem = _currentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID & &
2026-11-03 13:06:00 +06:00
x . ItemGroup = = EnumIncomeTaxItemGroup . Tax_Deducted & & x . ItemID = = ( int ) EnumIncomeTaxItemGroup . Tax_Deducted ) ;
if ( TaxDeductitem = = null ) TaxDeductitem = this . Add ( EnumIncomeTaxItemGroup . Tax_Deducted ,
( int ) EnumIncomeTaxItemGroup . Tax_Deducted , string . Empty , 0 , 0 , EnumIncomeTaxSide . Tax_fixed_Item ) ;
this . CalculateGrossTax ( ) ;
this . CalculateNetPayable ( ) ;
double onceOffTax = 0 ;
2026-11-30 10:14:40 +06:00
double netPayable = this . _currentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID & &
2026-11-03 13:06:00 +06:00
x . ItemGroup = = EnumIncomeTaxItemGroup . Net_Payable & & x . ItemID = = ( int ) EnumIncomeTaxItemGroup . Net_Payable ) . TotalAmount ;
double annualIncome = this . GetAnnualIncome ( ) ;
//double grossTax = IncomeTax.Get(this._currentYearTax, _employee.ID,
// EnumIncomeTaxItemGroup.Gross_Tax, (int)EnumIncomeTaxItemGroup.Gross_Tax).TotalAmount;
//if (_onceoffAmount > 0)
//{
// onceOffTax = grossTax - this.GetTaxAmount(annualIncome - _onceoffAmount);
// onceOffTax = onceOffTax - CalculateOnceOfInvestmentAmt();
// if (onceOffTax < 0) onceOffTax = 0;
//}
double exptionAmount = 0 ;
2026-11-30 10:14:40 +06:00
var expItem = this . _currentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID & &
x . ItemGroup = = EnumIncomeTaxItemGroup . AnnualExemption & & x . ItemID = =
2026-11-03 13:06:00 +06:00
( int ) EnumIncomeTaxItemGroup . AnnualExemption ) ;
if ( expItem ! = null ) exptionAmount = expItem . TotalAmount ;
2026-11-30 10:14:40 +06:00
2026-11-03 13:06:00 +06:00
if ( _employee . Status = = EnumEmployeeStatus . Discontinued )
TaxDeductitem . ThisMonthAmount = netPayable - TaxDeductitem . TotalAmount ;
else
{
if ( _projectedMonth < 0 )
throw new ServiceException ( "Projected month can't be less then Zero." ) ;
if ( _onceoffAmount > 0 & & netPayable > = _taxParameter . MinTaxAmount )
{
TaxDeductitem = this . Add ( EnumIncomeTaxItemGroup . last_OnceoffAmount ,
( int ) EnumIncomeTaxItemGroup . last_OnceoffAmount ,
string . Empty , _onceoffAmount , 0 , EnumIncomeTaxSide . Tax_Info_Item ) ;
double onceofIncome = annualIncome - _onceoffAmount + exptionAmount ;
double Onceexemption = ( onceofIncome / 3 ) * 1 ;
if ( Onceexemption > 500000 )
{
onceofIncome = onceofIncome - 500000 ;
}
else onceofIncome = onceofIncome - Onceexemption ;
onceOffTax = this . GetTaxAmount ( onceofIncome ) ;
double invAmount = CalculateOnceOfInvestmentAmt ( onceofIncome ) ;
onceOffTax = onceOffTax - invAmount ;
onceOffTax = onceOffTax + this . GetTaxRebate ( ) ;
if ( _taxParameter . MinTaxAmount > onceOffTax )
onceOffTax = _taxParameter . MinTaxAmount ;
double ntp = netPayable - onceOffTax ;
if ( ntp < 0 ) ntp = 0 ;
onceOffTax = onceOffTax - TaxDeductitem . TotalAmount ; // Tax to be paid rest of the year;
TaxDeductitem = this . Add ( EnumIncomeTaxItemGroup . last_Onceofftax ,
( int ) EnumIncomeTaxItemGroup . last_Onceofftax ,
string . Empty , onceOffTax , 0 , EnumIncomeTaxSide . Tax_Info_Item ) ;
TaxDeductitem . ThisMonthAmount = ntp + ( onceOffTax / ( _projectedMonth + 1 ) ) ;
}
else TaxDeductitem . ThisMonthAmount = ( ( netPayable - TaxDeductitem . TotalAmount ) / ( _projectedMonth + 1 ) ) ;
if ( TaxDeductitem . TotalAmount > netPayable )
TaxDeductitem . ThisMonthAmount = netPayable - TaxDeductitem . PreviousAmount ;
}
if ( TaxDeductitem . ThisMonthAmount < 0 )
{
TaxDeductitem . ThisMonthAmount = GlobalFunctions . Round ( 0 ) ;
}
else
{
TaxDeductitem . ThisMonthAmount = GlobalFunctions . Round ( TaxDeductitem . ThisMonthAmount ) ;
}
TaxDeductitem . ProjectedAmount = GlobalFunctions . Round ( TaxDeductitem . ProjectedAmount ) ;
if ( this . payrolltype . NextPayProcessDate . Month ! = 6 & & _employee . JoiningDate > GlobalFunctions . FirstDateOfMonth ( this . payrolltype . NextPayProcessDate ) & & _employee . JoiningDate < = this . payrolltype . NextPayProcessDate )
{
double fraction = GlobalFunctions . GetFraction ( _employee . JoiningDate , this . payrolltype . NextPayProcessDate ) ;
double thismonthtemp = TaxDeductitem . ThisMonthAmount ;
TaxDeductitem . ThisMonthAmount = GlobalFunctions . Round ( TaxDeductitem . ThisMonthAmount * fraction ) ;
TaxDeductitem . ProjectedAmount = TaxDeductitem . ProjectedAmount + ( thismonthtemp - GlobalFunctions . Round ( TaxDeductitem . ThisMonthAmount * fraction ) ) ;
}
}
protected double GetTaxAmount ( double TaxableIncome )
{
2026-11-30 10:14:40 +06:00
2026-11-03 13:06:00 +06:00
double taxAmount = 0 ;
if ( _employee . ForeignExPat = = true )
{
2026-11-30 10:14:40 +06:00
if ( ( _employee . JoiningDate - payrolltype . NextPayProcessDate ) . TotalDays < = 183 ) return TaxableIncome * . 3 ;
2026-11-03 13:06:00 +06:00
}
List < TaxParameterSlab > parameterSlabs = new TaxParameterService ( ) . CalculateTaxOnSlab ( payrolltype , _taxParameter , _employee , TaxableIncome ) ;
taxAmount = TaxParameterSlab . GetTotalTaxAmount ( parameterSlabs ) ;
return taxAmount ;
2026-11-30 10:14:40 +06:00
2026-11-03 13:06:00 +06:00
}
//protected void UpdateRawItems(List<TaxRawItem> rawItems, EnumSide nSide)
//{
//foreach (TaxRawItem item in rawItems)
//{
// if (item.Amount == 0) continue;
// IncomeTax taxItem = null;
// switch (item.ItemType)
// {
// case enumIncomeTaxItemType.Basic_Salary:
// taxItem = GetTaxItem(EnumTaxMergeType.NONE, (int)EnumIncomeTaxItemGroup.Basic_Salary, item.Description);
// break;
// case enumIncomeTaxItemType.Allowance:
// taxItem = GetTaxItem(EnumTaxMergeType.Allowance, item.ItemId, item.Description);
// break;
// case enumIncomeTaxItemType.Deduction:
// taxItem = GetTaxItem(EnumTaxMergeType.Allowance, item.ItemId, item.Description);
// break;
// case enumIncomeTaxItemType.OT:
// taxItem = GetTaxItem(EnumTaxMergeType.OT, item.ItemId, item.Description);
// break;
// case enumIncomeTaxItemType.Bonus:
// taxItem = GetTaxItem(EnumTaxMergeType.Bonus, item.ItemId, item.Description);
// break;
// case enumIncomeTaxItemType.FinalSettlement:
// taxItem = GetTaxItem(EnumTaxMergeType.Settlement, item.ItemId, item.Description);
// break;
// break;
// case enumIncomeTaxItemType.OPI:
// //taxItem = GetTaxItem(EnumTaxMergeType.Bonus, item.ItemId, item.Description);
// //taxItem.ThisMonthAmount = GlobalFunctions.Round(item.Amount);
// break;
// case enumIncomeTaxItemType.AdjustItem:
// taxItem = GetTaxItem(EnumTaxMergeType.TaxAdjustItem, item.ItemId, item.Description);
// break;
// case enumIncomeTaxItemType.Earned_Leave:
// taxItem = GetTaxItem(EnumTaxMergeType.NONE, (int)EnumIncomeTaxItemGroup.Earned_Leave, item.Description);
// break;
// default:
// break;
// }
// if (taxItem != null)
// {
// taxItem.ThisMonthAmount = (nSide == EnumSide.Deduct) ? -GlobalFunctions.Round(item.Amount) : GlobalFunctions.Round(item.Amount);
// if (taxItem != null) taxItem.Side = EnumIncomeTaxSide.Inc_SalaryIncome;
// this.Add(taxItem);
// }
//}
protected void UpdateRawItems ( List < TaxRawItem > rawItems , EnumSide nSide )
{
foreach ( TaxRawItem item in rawItems )
{
if ( item . Amount = = 0 ) continue ;
IncomeTax taxItem = null ;
switch ( item . ItemType )
{
case enumIncomeTaxItemType . Basic_Salary :
taxItem = GetTaxItem ( EnumTaxMergeType . NONE , ( int ) EnumIncomeTaxItemGroup . Basic_Salary , item . Description ) ;
taxItem . ThisMonthAmount = taxItem . ThisMonthAmount + item . Amount ;
if ( item . ChangePrgAmount = = true ) taxItem . ProjectedAmount = ( _employee . BasicSalary * _projectedMonth ) ;
break ;
case enumIncomeTaxItemType . Allowance :
if ( item . ChangePrgAmount = = true )
{
SalaryMonthlyDetail odtl = new SalaryMonthlyDetail ( ) ;
odtl . CalculatedAmount = item . Amount ;
odtl . ChangedAmount = item . Amount ;
odtl . Description = item . Description ;
odtl . itemGroupCode = EnumSalaryGroup . Gross ;
odtl . ItemCode = EnumSalaryItemCode . Allowance ;
odtl . ItemID = item . ItemId ;
odtl . SupportID = item . SupportID ;
//taxItem = GetTaxItem(EnumTaxMergeType.Allowance, item.ItemId, item.Description);
//double namount = taxItem.ThisMonthAmount;
taxItem = this . PayslipAllowanceDeduction ( odtl , EnumTaxMergeType . Allowance ) ;
//taxItem.ThisMonthAmount = taxItem.ThisMonthAmount + namount;
}
else
{
taxItem = GetTaxItem ( EnumTaxMergeType . Allowance , item . ItemId , item . Description ) ;
taxItem . ThisMonthAmount = taxItem . ThisMonthAmount + item . Amount ;
}
break ;
case enumIncomeTaxItemType . Deduction :
if ( item . ChangePrgAmount = = true )
{
SalaryMonthlyDetail odtl = new SalaryMonthlyDetail ( ) ;
odtl . CalculatedAmount = item . Amount ;
odtl . ChangedAmount = item . Amount ;
odtl . Description = item . Description ;
odtl . itemGroupCode = EnumSalaryGroup . Deductions ;
odtl . ItemCode = EnumSalaryItemCode . Deduction ;
odtl . ItemID = item . ItemId ;
odtl . SupportID = item . SupportID ;
//taxItem = GetTaxItem(EnumTaxMergeType.Allowance, item.ItemId, item.Description);
//double namount = taxItem.ThisMonthAmount;
taxItem = this . PayslipAllowanceDeduction ( odtl , EnumTaxMergeType . Deduction ) ;
//taxItem.ThisMonthAmount = taxItem.ThisMonthAmount + namount;
}
else
{
taxItem = GetTaxItem ( EnumTaxMergeType . Allowance , item . ItemId , item . Description ) ;
taxItem . ThisMonthAmount = taxItem . ThisMonthAmount + item . Amount ;
}
//taxItem = GetTaxItem(EnumTaxMergeType.Allowance, item.ItemId, item.Description);
break ;
case enumIncomeTaxItemType . OT :
taxItem = GetTaxItem ( EnumTaxMergeType . OT , item . ItemId , item . Description ) ;
taxItem . ThisMonthAmount = taxItem . ThisMonthAmount + item . Amount ;
break ;
case enumIncomeTaxItemType . Bonus :
taxItem = GetTaxItem ( EnumTaxMergeType . Bonus , item . ItemId , item . Description ) ;
if ( taxItem = = null )
taxItem = GetTaxItem ( EnumTaxMergeType . NONE , ( int ) EnumIncomeTaxItemGroup . Bonus , item . Description ) ;
taxItem . ThisMonthAmount = taxItem . ThisMonthAmount + item . Amount ;
break ;
case enumIncomeTaxItemType . FinalSettlement :
taxItem = GetTaxItem ( EnumTaxMergeType . Settlement , item . ItemId , item . Description ) ;
taxItem . ThisMonthAmount = taxItem . ThisMonthAmount + item . Amount ;
break ;
case enumIncomeTaxItemType . OPI :
//taxItem = GetTaxItem(EnumTaxMergeType.Bonus, item.ItemId, item.Description);
//taxItem.ThisMonthAmount = GlobalFunctions.Round(item.Amount);
break ;
case enumIncomeTaxItemType . AdjustItem :
taxItem = GetTaxItem ( EnumTaxMergeType . TaxAdjustItem , item . ItemId , item . Description ) ;
taxItem . ThisMonthAmount = taxItem . ThisMonthAmount + item . Amount ;
break ;
case enumIncomeTaxItemType . Earned_Leave :
taxItem = GetTaxItem ( EnumTaxMergeType . NONE , ( int ) EnumIncomeTaxItemGroup . Earned_Leave , item . Description ) ;
taxItem . ThisMonthAmount = taxItem . ThisMonthAmount + item . Amount ;
break ;
case enumIncomeTaxItemType . LFA :
taxItem = GetTaxItem ( EnumTaxMergeType . NONE , ( int ) EnumIncomeTaxItemGroup . LFA_Allowance , item . Description ) ;
taxItem . ThisMonthAmount = taxItem . ThisMonthAmount + item . Amount ;
break ;
default :
break ;
}
if ( taxItem ! = null )
{
// taxItem.ThisMonthAmount = (nSide == EnumSide.Deduct) ? -GlobalFunctions.Round(item.Amount) : GlobalFunctions.Round(item.Amount);
if ( taxItem ! = null ) taxItem . Side = EnumIncomeTaxSide . Inc_SalaryIncome ;
this . Add ( taxItem ) ;
}
}
}
private double GetTaxConciderInvestment ( double income )
{
double taxamount = this . GetTaxAmount ( income ) ;
if ( _employee . ForeignExPat = = true ) return 0 ;
2026-11-30 10:14:40 +06:00
if ( this . _investmentwithoutpf = = null )
this . _investmentwithoutpf = new SystemConfigarationService ( ) . GetconfigBooleanValue ( EnumConfigurationType . Logic , "incometax" , "investmentwithoutpf" ) ;
2026-11-03 13:06:00 +06:00
double investmentCanBeShown = ( ( taxamount * _taxParameter . MaxInvestPercent ) / 100 ) ;
if ( investmentCanBeShown > _taxParameter . MaxInvAmount ) investmentCanBeShown = _taxParameter . MaxInvAmount ;
double investAmount = investmentCanBeShown ;
_isActualInvestment = false ;
if ( _taxParameter . InvestmentActiveMonth = = null ) _isActualInvestment = false ;
else
{
DateTime investmonth = new DateTime ( _taxParameter . FiscalyearDatefrom . Year , ( ( DateTime ) _taxParameter . InvestmentActiveMonth ) . Month , 1 ) ;
investmonth = GlobalFunctions . LastDateOfMonth ( investmonth ) ;
if ( investmonth < = payrolltype . NextPayProcessDate )
_isActualInvestment = true ;
}
if ( _isActualInvestment = = true )
{
2026-11-30 10:14:40 +06:00
IncomeTax ActualInvestment = _currentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID & &
2026-11-03 13:06:00 +06:00
x . ItemGroup = = EnumIncomeTaxItemGroup . Investment_Actual & & x . ItemID = = ( int ) EnumIncomeTaxItemGroup . Investment_Actual ) ;
investAmount = ActualInvestment . ThisMonthAmount ;
}
if ( investAmount > investmentCanBeShown )
investAmount = investmentCanBeShown ;
double taxCredit = 0 ;
taxCredit = ( investAmount * _taxParameter . MaxInvExempPercent ) / 100 ;
taxamount = taxamount - taxCredit ;
return taxamount ;
}
private double GetTaxonTaxAmount ( double onAmount )
{
//IncomeTax carIncome = IncomeTax.Get(_currentYearTax, _employee.ID,
// EnumIncomeTaxItemGroup.Cmp_Provided_car,
// (int)EnumIncomeTaxItemGroup.Cmp_Provided_car);
this . CalculateTotalIncome ( ) ;
2026-11-30 10:14:40 +06:00
IncomeTax IncomeWithCar = _currentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID
2026-11-03 13:06:00 +06:00
& & x . ItemGroup = = EnumIncomeTaxItemGroup . Annual_Salary_Income & & x . ItemID = = ( int ) EnumIncomeTaxItemGroup . Annual_Salary_Income ) ;
double dif = 0 ;
double onlyCarTax = this . GetTaxConciderInvestment ( IncomeWithCar . TotalAmount - onAmount ) ; ;
double taxwithCar = this . GetTaxConciderInvestment ( IncomeWithCar . TotalAmount ) ;
dif = taxwithCar - onlyCarTax ;
double addedIncome = dif + taxwithCar ;
double prvTax = taxwithCar ;
while ( dif < 0 )
{
dif = this . GetTaxConciderInvestment ( addedIncome ) ;
dif = dif - prvTax ;
prvTax = addedIncome ;
if ( dif > 0 ) addedIncome = addedIncome + dif ;
}
dif = addedIncome - taxwithCar ;
return dif ;
}
/// <summary>
/// Find the gross tax
/// include gross tax in total salary income
/// calculate salary income, annual income
/// </summary>
protected double CulculateArrearOnMonth ( )
{
double nAmount = 0 ;
double nTaxAmount = 0 ;
2026-11-30 10:14:40 +06:00
IncomeTax TaxDeductitem = _currentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID & &
2026-11-03 13:06:00 +06:00
x . ItemGroup = = EnumIncomeTaxItemGroup . Tax_Deducted & & x . ItemID = = ( int ) EnumIncomeTaxItemGroup . Tax_Deducted ) ;
if ( TaxDeductitem = = null ) TaxDeductitem = this . Add ( EnumIncomeTaxItemGroup . Tax_Deducted ,
( int ) EnumIncomeTaxItemGroup . Tax_Deducted , string . Empty , 0 , 0 , EnumIncomeTaxSide . Tax_fixed_Item ) ;
2026-11-30 10:14:40 +06:00
IncomeTax onetTax = _currentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID
2026-11-03 13:06:00 +06:00
& & x . ItemGroup = = EnumIncomeTaxItemGroup . Net_Payable & & x . ItemID = = ( int ) EnumIncomeTaxItemGroup . Net_Payable ) ;
if ( onetTax ! = null )
{
nAmount = onetTax . TotalAmount ;
nAmount = nAmount / ( double ) 12 ;
int arrMonth = 12 - ( int ) _projectedMonth ;
nAmount = nAmount * arrMonth ;
if ( TaxDeductitem ! = null )
{
nAmount = nAmount - TaxDeductitem . TotalAmount ;
if ( nAmount < 0 ) nAmount = 0 ;
TaxDeductitem . ThisMonthAmount = nAmount ;
nTaxAmount = nAmount ;
}
}
//this.CalculateThisMonth();
//TaxDeductitem = IncomeTax.Get(_currentYearTax, _employee.ID,
// EnumIncomeTaxItemGroup.Tax_Deducted, (int)EnumIncomeTaxItemGroup.Tax_Deducted);
//if (TaxDeductitem != null)
//{
// nTaxAmount = TaxDeductitem.ThisMonthAmount - nAmount;
//}
return nTaxAmount ;
}
}
public interface ISalaryTax
{
SalaryMonthly Salary { set ; get ; }
List < IncomeTax > Calculate ( ) ;
}
public interface IBonusTax
{
BonusProcess . BonusProcessDetail Bonus { set ; get ; }
List < IncomeTax > Calculate ( ) ;
}
public interface ITaxCalculator
{
}
public class TaxCalculator : AbstractTaxCalculator
{
2026-11-30 10:14:40 +06:00
public TaxCalculator ( int taxparamid , int payrolltypeid ) : base ( taxparamid , payrolltypeid )
2026-11-03 13:06:00 +06:00
{
2026-11-30 10:14:40 +06:00
2026-11-03 13:06:00 +06:00
}
public TaxCalculator ( ) : base ( )
{
}
public override List < ADParameter > AdParameters
{
set { _adParameters = value ; }
}
public override SalaryMonthly Salary
{
set { _salary = value ; }
}
public override Employee Employee
{
set
{
if ( _taxParameter = = null ) throw new ServiceException ( "Taxparameter must set before Employee" ) ;
2026-11-30 10:14:40 +06:00
_taxSlabs = new TaxParameterService ( ) . GetEmployeeSlab ( payrolltype ,
2026-11-03 13:06:00 +06:00
_taxParameter , value ) ;
TaxParameter . SetMinimumTax ( value , _taxParameter ) ;
_employee = value ;
}
}
public override TaxParameter TaxParameter
{
set
{
_taxParameter = value ;
}
}
public List < IncomeTax > SalaryTax ( )
{
string smessage = "" ;
try
{
_isActualInvestment = true ;
this . _onceoffAmount = 0 ;
smessage = "InitiazedNextMonth" ;
this . InitializeForNextMonth ( ) ;
smessage = "CalcualteprojectMonth" ;
this . CalcualteprojectMonth ( ) ;
smessage = "IncludePayslipItems" ;
this . IncludePayslipItems ( ) ;
//smessage = "Calculate OT";
//this.CalculateOT();
smessage = "CmpProvidedHouseAndTransport" ;
this . CmpProvidedHouseAndTransport ( payrolltype . NextPayProcessDate ) ;
smessage = "Calculate-Bonus-Projection" ;
this . CalculateBonusProjection ( ) ;
smessage = "CalculateCPF" ;
this . CalculateCPF ( ) ;
//this.CalculateTaxOnTax();
//smessage = "Calculate tax on tax";
smessage = "Calculate-Exemption" ;
this . CalculateExemptionOnward2023 ( ) ;
smessage = "Calculate-Total-Income" ;
this . CalculateTotalIncome ( ) ;
smessage = "CalculateInvestment" ;
this . CalculateInvestment ( ) ;
smessage = "CalculateGrossTax" ;
this . CalculateGrossTax ( ) ;
smessage = "CalculateNetPayable" ;
this . CalculateNetPayable ( ) ;
smessage = "CalculateThisMonth" ;
this . CalculateThisMonth ( ) ;
smessage = "Trade of tool calculation" ;
// this.ToolOfTradeCalculation();
smessage = "End" ;
return this . CurrentYearTax ;
}
catch ( ServiceException ex )
{
throw new ServiceException ( ex . Message + "###" + smessage ) ;
}
catch ( Exception ex )
{
throw new ServiceException ( ex . Message + "###" + smessage ) ;
}
}
public List < IncomeTax > RecalculateTax ( int nTaxParamterID )
{
List < IncomeTax > empTaxCertificates = new List < IncomeTax > ( ) ;
try
{
// if IncomeTax.get() function not return employee order-by wise data, rest of the function will not culculate properly.
2026-11-30 10:14:40 +06:00
List < IncomeTax > oTaxYearly = new IncomeTaxService ( ) . GetPrvYear ( nTaxParamterID , this . payrolltype . ID ) ;
2026-11-03 13:06:00 +06:00
if ( this . payrolltype . TaxParamID = = nTaxParamterID )
oTaxYearly = new IncomeTaxService ( ) . GetByYear ( nTaxParamterID , EnumIncomeTaxDataFrom . ProcessTempData , this . payrolltype . ID ) ;
else
2026-11-30 10:14:40 +06:00
oTaxYearly = new IncomeTaxService ( ) . GetPrvYear ( nTaxParamterID , payrolltype . ID ) ;
2026-11-03 13:06:00 +06:00
int? nCurrEmployeeid = null ;
if ( oTaxYearly . Count > 0 ) nCurrEmployeeid = oTaxYearly [ 0 ] . EmployeeID ;
_taxParameter = new TaxParameterService ( ) . Get ( ( int ) nTaxParamterID ) ;
this . payrolltype . ActualTaxInvestment = true ;
List < Employee > oemps = new EmployeeService ( ) . GetAllEmps ( ) ;
while ( true )
{
_employee = oemps . FirstOrDefault ( x = > x . ID = = nCurrEmployeeid ) ;
2026-11-30 10:14:40 +06:00
if ( _employee = = null ) _employee = new EmployeeService ( ) . Get ( ( int ) nCurrEmployeeid ) ;
2026-11-03 13:06:00 +06:00
_isActualInvestment = true ;
2026-11-30 10:14:40 +06:00
this . CurrentYearTax = oTaxYearly . FindAll ( x = > x . EmployeeID = = nCurrEmployeeid ) ;
2026-11-03 13:06:00 +06:00
// Initialize the current data.
foreach ( IncomeTax item in this . CurrentYearTax )
oTaxYearly . Remove ( item ) ; // Remove from collection
this . CalculateTotalIncome ( ) ;
this . CalculateInvestment ( ) ;
this . CalculateGrossTax ( ) ;
this . CalculateNetPayable ( ) ;
foreach ( IncomeTax item in this . CurrentYearTax )
{
item . EmployeeID = _employee . ID ;
item . TaxParameterID = nTaxParamterID ;
empTaxCertificates . Add ( item ) ;
}
if ( oTaxYearly . Count > 0 ) nCurrEmployeeid = oTaxYearly [ 0 ] . EmployeeID ;
else break ;
}
}
catch ( Exception ex )
{
throw new ServiceException ( ex . Message ) ;
}
return empTaxCertificates ;
}
public List < IncomeTax > RecalculateTax ( string empIds , int nTaxParamterID )
{
List < IncomeTax > empTaxCertificates = new List < IncomeTax > ( ) ;
try
{
// if IncomeTax.get() function not return employee order-by wise data, rest of the function will not culculate properly.
List < IncomeTax > oTaxYearly ; // = new IncomeTaxService().GetPrvYear(nTaxParamterID, this.payrolltype.ID);
if ( this . payrolltype . TaxParamID = = nTaxParamterID )
oTaxYearly = new IncomeTaxService ( ) . GetByYear ( nTaxParamterID , empIds , EnumIncomeTaxDataFrom . ProcessTempData , this . payrolltype . ID ) ;
else
oTaxYearly = new IncomeTaxService ( ) . GetPrvYear ( nTaxParamterID , empIds , payrolltype . ID ) ;
int? nCurrEmployeeid = null ;
if ( oTaxYearly . Count > 0 ) nCurrEmployeeid = oTaxYearly [ 0 ] . EmployeeID ;
_taxParameter = new TaxParameterService ( ) . Get ( ( int ) nTaxParamterID ) ;
this . payrolltype . ActualTaxInvestment = _taxParameter . InvestmentActiveMonth ! = null ? true : false ;
//this.payrolltype.ActualTaxInvestment = true;
// List<Employee> oemps = new EmployeeService().GetAllEmps();
List < Employee > oemps = new EmployeeService ( ) . GetEmpsWithDiscontinue ( empIds , this . payrolltype . ID ) ;
while ( true )
{
_employee = oemps . FirstOrDefault ( x = > x . ID = = nCurrEmployeeid ) ;
if ( _employee = = null ) _employee = new EmployeeService ( ) . Get ( ( int ) nCurrEmployeeid ) ;
_isActualInvestment = this . payrolltype . ActualTaxInvestment ;
this . CurrentYearTax = oTaxYearly . FindAll ( x = > x . EmployeeID = = nCurrEmployeeid ) ;
// Initialize the current data.
foreach ( IncomeTax item in this . CurrentYearTax )
oTaxYearly . Remove ( item ) ; // Remove from collection
this . _onceoffAmount = 0 ;
this . CalculateExemptionOnward2023 ( ) ;
this . CalculateTotalIncome ( ) ;
this . CalculateInvestment ( ) ;
this . CalculateGrossTax ( ) ;
this . CalculateNetPayable ( ) ;
foreach ( IncomeTax item in this . CurrentYearTax )
{
item . EmployeeID = _employee . ID ;
item . TaxParameterID = nTaxParamterID ;
empTaxCertificates . Add ( item ) ;
}
if ( oTaxYearly . Count > 0 ) nCurrEmployeeid = oTaxYearly [ 0 ] . EmployeeID ;
else break ;
}
}
catch ( Exception ex )
{
throw new ServiceException ( ex . Message ) ;
}
return empTaxCertificates ;
}
//public List<IncomeTax> CalculateBonus(List<TaxRawItem> rawItems, ref double ntaxAmount)
//{
// try
// {
// double nTempAmount = 0;
// bool bStartMonth = false;
// _isActualInvestment = true;
// this._onceoffAmount = rawItems.Sum(x => x.Amount);
// IncomeTax oIncomeTax = new IncomeTax();
// EnumIncomeTaxDataFrom datafrom = new IncomeTaxService().GetEnumForSalaryIT(_employee.ID);
// if (datafrom == EnumIncomeTaxDataFrom.SalaryITTempData)
// {
// throw new ServiceException("Current month salary is processed and not yet finalized. Tax calculation "
// + " is not allowed middle of this process. You have to Undo or finalize the salary to calculate tax.");
// }
// this.CurrentYearTax = new List<IncomeTax>();
// this.CurrentYearTax = new IncomeTaxService().Get(_employee.ID, EnumIncomeTaxDataFrom.ProcessTempData);
// if (this.payrolltype.NextPayProcessDate.Month == 7) // if month is july and salary not yet processed then, clear all tax data
// {
// bStartMonth = true;
// this.CalcualteprojectMonth();
// this.CalculateOnlyProjection();
// }
// this.UpdateRawItems(rawItems, EnumSide.Add);
// this.CalculateExamtion();
// this.CalculateBonusProjection();
// this.CalculateCPF();
// this.CalculateTotalIncome();
// this.CalculateInvestment();
// this.CalculateGrossTax();
// double totalAmount = 0;
// IncomeTax netPayable = this.CurrentYearTax.FirstOrDefault(x => x.EmployeeID == _employee.ID
// && x.ItemGroup == EnumIncomeTaxItemGroup.Net_Payable && x.ItemID == (int)EnumIncomeTaxItemGroup.Net_Payable);
// if (netPayable != null)
// nTempAmount = netPayable.TotalAmount;
// ntaxAmount = 0;
// this.CalculateNetPayable();
// if (_ApplicableBonusParams != null)
// {
// BonusParameter oparam = _ApplicableBonusParams.FirstOrDefault(x => x.BonusID == rawItems[0].ItemId);
// if (oparam != null && oparam.IsFestival == true) // isFestival mean bonus is projected for tax. So no need to deduct tax in bonus process
// return this.CurrentYearTax;
// }
// ntaxAmount = nTempAmount;
// netPayable = this.CurrentYearTax.FirstOrDefault(x => x.EmployeeID == _employee.ID
// && x.ItemGroup == EnumIncomeTaxItemGroup.Net_Payable && x.ItemID == (int)EnumIncomeTaxItemGroup.Net_Payable);
// if (netPayable != null)
// if (totalAmount > 0)
// ntaxAmount = netPayable.TotalAmount - totalAmount;
// else
// ntaxAmount = (-totalAmount - netPayable.TotalAmount) > 0 ? 0 : netPayable.TotalAmount;
// double grossTax = this.CurrentYearTax.FirstOrDefault(x => x.EmployeeID == _employee.ID
// && x.ItemGroup == EnumIncomeTaxItemGroup.Gross_Tax && x.ItemID == (int)EnumIncomeTaxItemGroup.Gross_Tax).TotalAmount;
// if (_onceoffAmount > 0)
// {
// double annualIncome = this.GetAnnualIncome();
// ntaxAmount = grossTax - this.GetTaxAmount(annualIncome - _onceoffAmount);
// ntaxAmount = ntaxAmount - CalculateOnceOfInvestmentAmt();
// if (ntaxAmount < 0) ntaxAmount = 0;
// }
// IncomeTax TaxDeductitem = this.CurrentYearTax.FirstOrDefault(x => x.EmployeeID == _employee.ID &&
// x.ItemGroup == EnumIncomeTaxItemGroup.Tax_Deducted && x.ItemID == (int)EnumIncomeTaxItemGroup.Tax_Deducted);
// if (TaxDeductitem == null) TaxDeductitem = this.Add(EnumIncomeTaxItemGroup.Tax_Deducted,
// (int)EnumIncomeTaxItemGroup.Tax_Deducted, string.Empty, 0, 0, EnumIncomeTaxSide.Tax_fixed_Item);
// TaxDeductitem.ThisMonthAmount = TaxDeductitem.ThisMonthAmount + ntaxAmount;
// return this.CurrentYearTax;
// }
// catch (ServiceException ex)
// {
// throw new ServiceException(ex.Message);
// }
// catch (Exception ex)
// {
// throw new ServiceException(ex.Message);
// }
//}
public List < IncomeTax > CalculateBonus ( List < TaxRawItem > rawItems , BonusParameter bonusParam , ref double ntaxAmount , List < ADParameter > oParams , List < IncomeTax > oTaxes )
{
try
{
double nTempAmount = 0 ;
bool bStartMonth = false ;
_isActualInvestment = false ;
this . _onceoffAmount = rawItems . Sum ( x = > x . Amount ) ;
IncomeTax oIncomeTax = new IncomeTax ( ) ;
this . CurrentYearTax = new List < IncomeTax > ( ) ;
foreach ( IncomeTax item in oTaxes )
{
if ( item . EmployeeID = = _employee . ID )
this . CurrentYearTax . Add ( item ) ;
}
2026-11-30 10:14:40 +06:00
if ( this . payrolltype . NextPayProcessDate . Month = = 7 & & this . CurrentYearTax . Count = = 0 ) // if month is july and salary not yet processed then, clear all tax data
2026-11-03 13:06:00 +06:00
{
bStartMonth = true ;
_projectedMonth = 12 ;
if ( _projectedMonth < 0 ) _projectedMonth = 0 ;
if ( _employee . EndOfContractDate ! = null & & _employee . EndOfContractDate ! = DateTime . MinValue )
{
if ( _employee . EndOfContractDate < _taxParameter . FiscalyearDateTo )
_projectedMonth = 0 ;
}
this . CalculateOnlyProjection ( oParams ) ;
}
this . UpdateRawItems ( rawItems , EnumSide . Add ) ;
this . CalculateBonusProjection ( ) ;
this . CalculateExemptionOnward2023 ( ) ;
this . CalculateTotalIncome ( ) ;
this . CalculateInvestment ( ) ;
this . CalculateGrossTax ( ) ;
if ( bonusParam . IsProjectInTaxCalculation = = true )
{
this . CalculateNetPayable ( ) ;
return this . CurrentYearTax ;
}
IncomeTax ntpBeforeBonus = this . CurrentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID
& & x . ItemGroup = = EnumIncomeTaxItemGroup . Net_Payable & & x . ItemID = = ( int ) EnumIncomeTaxItemGroup . Net_Payable ) ;
this . CalculateNetPayable ( ) ;
//if (_ApplicableBonusParams != null)
//{
// BonusParameter oparam = _ApplicableBonusParams.FirstOrDefault(x => x.BonusID == rawItems[0].ItemId);
// if (oparam != null && oparam.IsFestival == true) // isFestival mean bonus is projected for tax. So no need to deduct tax in bonus process
// return this.CurrentYearTax;
//}
//netPayable = this.CurrentYearTax.FirstOrDefault(x => x.EmployeeID == _employee.ID &&
// x.ItemGroup == EnumIncomeTaxItemGroup.Net_Payable && x.ItemID == (int)EnumIncomeTaxItemGroup.Net_Payable);
//if (netPayable != null)
// if (totalAmount > 0)
// ntaxAmount = netPayable.TotalAmount - totalAmount;
// else
// ntaxAmount = (-totalAmount - netPayable.TotalAmount) > 0 ? 0 : netPayable.TotalAmount;
IncomeTax netPayable = this . CurrentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID & &
x . ItemGroup = = EnumIncomeTaxItemGroup . Net_Payable & & x . ItemID = = ( int ) EnumIncomeTaxItemGroup . Net_Payable ) ;
if ( netPayable ! = null )
{
2026-11-30 10:14:40 +06:00
2026-11-03 13:06:00 +06:00
double annualIncome = this . GetAnnualIncome ( ) ;
2026-11-30 10:14:40 +06:00
double newGross = this . GetTaxAmount ( annualIncome - _onceoffAmount ) ;
2026-11-03 13:06:00 +06:00
ntaxAmount = newGross - CalculateOnceOfInvestmentAmt ( annualIncome - _onceoffAmount ) ;
2026-11-30 10:14:40 +06:00
if ( newGross > 0 & & ntaxAmount < _taxParameter . MinTaxAmount )
2026-11-03 13:06:00 +06:00
ntaxAmount = _taxParameter . MinTaxAmount ;
ntaxAmount = ntaxAmount + this . GetTaxRebate ( ) ;
if ( ntaxAmount < 0 ) ntaxAmount = 0 ;
if ( ntpBeforeBonus ! = null & & ntpBeforeBonus . TotalAmount < _taxParameter . MinTaxAmount & &
ntaxAmount > = _taxParameter . MinTaxAmount ) // before bonus tax amount was zero,
// now eligible for tax
{
ntaxAmount = netPayable . TotalAmount ;
}
2026-11-30 10:14:40 +06:00
else if ( ntpBeforeBonus ! = null & & ntpBeforeBonus . TotalAmount = = _taxParameter . MinTaxAmount
2026-11-03 13:06:00 +06:00
& & ntaxAmount = = _taxParameter . MinTaxAmount ) // tax amount was min_tax
{
ntaxAmount = 0 ;
//IncomeTax ditem = this.CurrentYearTax.FirstOrDefault(x => x.EmployeeID == _employee.ID &&
// x.ItemGroup == EnumIncomeTaxItemGroup.Tax_Deducted && x.ItemID == (int)EnumIncomeTaxItemGroup.Tax_Deducted);
//if (ditem != null)
//{
// ntaxAmount = ntpBeforeBonus.TotalAmount - ditem.TotalAmount;
//}
//else ntaxAmount = _taxParameter.MinTaxAmount;
}
else
{
ntaxAmount = netPayable . TotalAmount - ntaxAmount ;
}
if ( ntaxAmount < 0 ) ntaxAmount = 0 ;
ntaxAmount = GlobalFunctions . Round ( ntaxAmount ) ;
}
2026-11-30 10:14:40 +06:00
if ( ntaxAmount > this . _onceoffAmount ) // if tax amount greater than bonus amount
2026-11-03 13:06:00 +06:00
{
ntaxAmount = this . _onceoffAmount ;
}
IncomeTax TaxDeductitem = this . CurrentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID & &
x . ItemGroup = = EnumIncomeTaxItemGroup . Tax_Deducted & & x . ItemID = = ( int ) EnumIncomeTaxItemGroup . Tax_Deducted ) ;
if ( TaxDeductitem = = null ) TaxDeductitem = this . Add ( EnumIncomeTaxItemGroup . Tax_Deducted ,
( int ) EnumIncomeTaxItemGroup . Tax_Deducted , string . Empty , 0 , 0 , EnumIncomeTaxSide . Tax_fixed_Item ) ;
2026-11-30 10:14:40 +06:00
TaxDeductitem . PreviousAmount = TaxDeductitem . PreviousAmount + TaxDeductitem . ThisMonthAmount ;
2026-11-03 13:06:00 +06:00
TaxDeductitem . ThisMonthAmount = ntaxAmount ;
return this . CurrentYearTax ;
}
catch ( ServiceException ex )
{
throw new ServiceException ( ex . Message ) ;
}
catch ( Exception ex )
{
throw new ServiceException ( ex . Message ) ;
}
}
public List < IncomeTax > UndoBonus ( List < TaxRawItem > rawItems , double taxAmount )
{
try
{
_isActualInvestment = true ;
this . _onceoffAmount = 0 ;
IncomeTax oIncomeTax = new IncomeTax ( ) ;
//EnumIncomeTaxDataFrom datafrom = oIncomeTax.GetEnumForSalaryIT(_employee.ID);
//if (datafrom == EnumIncomeTaxDataFrom.SalaryITTempData)
//{
// throw new ServiceException("Current month salary is processed and not yet finalized. Tax calculation "
// + " is not allowed middle of this process. You have to Undo or finalize the salary to calculate tax.");
//}
this . UpdateRawItems ( rawItems , EnumSide . Deduct ) ;
this . CalculateBonusProjection ( ) ;
this . CalculateTotalIncome ( ) ;
this . CalculateInvestment ( ) ;
this . CalculateGrossTax ( ) ;
this . CalculateNetPayable ( ) ;
this . UndoDecutedAmount ( taxAmount ) ;
return this . CurrentYearTax ;
}
catch ( ServiceException ex )
{
throw new ServiceException ( ex . Message ) ;
}
catch ( Exception ex )
{
throw new ServiceException ( ex . Message ) ;
}
}
/// <summary>
///
/// </summary>
/// <param name="rawItems"></param>
/// <returns></returns>
public double Calculate ( List < TaxRawItem > rawItems )
{
try
{
_isActualInvestment = true ;
this . _onceoffAmount = 0 ;
IncomeTax oIncomeTax = new IncomeTax ( ) ;
EnumIncomeTaxDataFrom datafrom = new IncomeTaxService ( ) . GetEnumForSalaryIT ( _employee . ID ) ;
this . CurrentYearTax = new List < IncomeTax > ( ) ;
this . CurrentYearTax = new IncomeTaxService ( ) . Get ( _employee . ID , datafrom ) ;
this . CalcualteprojectMonth ( ) ;
this . UpdateRawItems ( rawItems , EnumSide . Add ) ;
this . CmpProvidedHouseAndTransport ( this . payrolltype . NextPayProcessDate ) ;
this . CalculateExamtion ( ) ;
this . CalculateBonusProjection ( ) ;
this . CalculateCPF ( ) ;
this . CalculateTotalIncome ( ) ;
this . CalculateInvestment ( ) ;
this . CalculateGrossTax ( ) ;
double totalAmount = 0 ;
IncomeTax netPayable = this . CurrentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID & &
x . ItemGroup = = EnumIncomeTaxItemGroup . Net_Payable & & x . ItemID = = ( int ) EnumIncomeTaxItemGroup . Net_Payable ) ;
if ( netPayable ! = null )
totalAmount = netPayable . TotalAmount ;
this . CalculateNetPayable ( ) ;
netPayable = this . CurrentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID & &
x . ItemGroup = = EnumIncomeTaxItemGroup . Net_Payable & & x . ItemID = = ( int ) EnumIncomeTaxItemGroup . Net_Payable ) ;
if ( netPayable ! = null )
totalAmount = netPayable . TotalAmount - totalAmount ;
// if the amount is equal to yearly netpayable, the amount should be dsitributed next of the projected month
if ( totalAmount = = netPayable . TotalAmount & & netPayable . TotalAmount = = _taxParameter . MinTaxAmount & & _projectedMonth > 0 )
totalAmount = totalAmount / _projectedMonth ;
return totalAmount ;
}
catch ( ServiceException ex )
{
throw new ServiceException ( ex . Message ) ;
}
catch ( Exception ex )
{
throw new ServiceException ( ex . Message ) ;
}
}
//End OPI Calculation
/// <summary>
///
/// </summary>
/// <param name="rawItem"></param>
/// <param name="taxAmount"></param>
/// <returns></returns>
public List < IncomeTax > Calculate ( List < TaxRawItem > rawItems , ref double ntaxAmount )
{
try
{
_isActualInvestment = true ;
this . _onceoffAmount = rawItems [ 0 ] . Amount ;
IncomeTax oIncomeTax = new IncomeTax ( ) ;
EnumIncomeTaxDataFrom datafrom = new IncomeTaxService ( ) . GetEnumForSalaryIT ( _employee . ID ) ;
if ( datafrom = = EnumIncomeTaxDataFrom . SalaryITTempData )
{
throw new ServiceException ( "Current month salary is processed and not yet finalized. Tax calculation "
+ " is not allowed middle of this process. You have to Undo or finalize the salary to calculate tax." ) ;
}
this . CurrentYearTax = new List < IncomeTax > ( ) ;
this . CurrentYearTax = new IncomeTaxService ( ) . Get ( _employee . ID , EnumIncomeTaxDataFrom . ProcessTempData ) ;
this . CalcualteprojectMonth ( ) ;
this . UpdateRawItems ( rawItems , EnumSide . Add ) ;
this . CmpProvidedHouseAndTransport ( this . payrolltype . NextPayProcessDate ) ;
this . CalculateExamtion ( ) ;
this . CalculateBonusProjection ( ) ;
this . CalculateCPF ( ) ;
this . CalculateTotalIncome ( ) ;
this . CalculateInvestment ( ) ;
this . CalculateGrossTax ( ) ;
this . CalculateNetPayable ( ) ;
ntaxAmount = this . CalculateDecutedAmount ( ) ;
return this . CurrentYearTax ;
}
catch ( ServiceException ex )
{
throw new ServiceException ( ex . Message ) ;
}
catch ( Exception ex )
{
throw new ServiceException ( ex . Message ) ;
}
}
/// <summary>
///
/// </summary>
/// <param name="rawItem"></param>
/// <param name="taxAmount"></param>
/// <returns></returns>
public List < IncomeTax > CalculateSettlementTax ( List < TaxRawItem > rawItems )
{
try
{
_isActualInvestment = true ;
this . _onceoffAmount = 0 ;
IncomeTax oIncomeTax = new IncomeTax ( ) ;
EnumIncomeTaxDataFrom datafrom = new IncomeTaxService ( ) . GetEnumForSalaryIT ( _employee . ID ) ;
if ( datafrom = = EnumIncomeTaxDataFrom . SalaryITTempData )
{
throw new ServiceException ( "Current month salary is processed and not yet finalized. Tax calculation "
+ " is not allowed middle of this process. You have to Undo or finalize the salary to calculate tax." ) ;
}
this . CurrentYearTax = new List < IncomeTax > ( ) ;
this . CurrentYearTax = new IncomeTaxService ( ) . Get ( _employee . ID , EnumIncomeTaxDataFrom . ProcessTempData ) ;
this . _projectedMonth = 0 ;
foreach ( IncomeTax item in this . CurrentYearTax )
{
2026-11-30 10:14:40 +06:00
item . PreviousAmount = item . PreviousAmount + item . ThisMonthAmount ;
2026-11-03 13:06:00 +06:00
item . ThisMonthAmount = 0 ;
item . ProjectedAmount = 0 ;
}
this . UpdateRawItems ( rawItems , EnumSide . Add ) ;
this . CmpProvidedHouseAndTransport ( ( DateTime ) _employee . DiscontinueDate ) ;
this . CalculateExamtion ( ) ;
this . CalculateTotalIncome ( ) ;
this . CalculateInvestment ( ) ;
this . CalculateGrossTax ( ) ;
this . CalculateNetPayable ( ) ;
IncomeTax TaxDeductitem = _currentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID
& & x . ItemGroup = = EnumIncomeTaxItemGroup . Tax_Deducted & & x . ItemID = = ( int ) EnumIncomeTaxItemGroup . Tax_Deducted ) ;
IncomeTax netPayable = _currentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID
& & x . ItemGroup = = EnumIncomeTaxItemGroup . Net_Payable & & x . ItemID = = ( int ) EnumIncomeTaxItemGroup . Net_Payable ) ;
2026-11-30 10:14:40 +06:00
if ( TaxDeductitem ! = null )
2026-11-03 13:06:00 +06:00
TaxDeductitem . ThisMonthAmount = netPayable . TotalAmount - TaxDeductitem . TotalAmount ;
return this . CurrentYearTax ;
}
catch ( ServiceException ex )
{
throw new ServiceException ( ex . Message ) ;
}
catch ( Exception ex )
{
throw new ServiceException ( ex . Message ) ;
}
}
/// <summary>
/// function will return total year tax,
/// </summary>
/// <param name="rawItems"></param>
/// <param name="ntaxAmount"></param>
/// <returns></returns>
public List < IncomeTax > CalculateYearlyTax ( List < TaxRawItem > rawItems , ref double ntaxAmount )
{
try
{
this . CurrentYearTax = new List < IncomeTax > ( ) ;
_isActualInvestment = false ;
_projectedMonth = 0 ;
this . _onceoffAmount = 0 ;
this . UpdateRawItems ( rawItems , EnumSide . Add ) ;
this . CmpProvidedHouseAndTransport ( this . payrolltype . NextPayProcessDate ) ;
this . CalculateExamtion ( ) ;
this . CalculateBonusProjection ( ) ;
this . CalculateCPF ( ) ;
this . CalculateTotalIncome ( ) ;
this . CalculateInvestment ( ) ;
this . CalculateGrossTax ( ) ;
this . CalculateNetPayable ( ) ;
this . CalculateThisMonth ( ) ;
ntaxAmount = this . CurrentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID & & x . ItemGroup = = EnumIncomeTaxItemGroup . Tax_Deducted
& & x . ItemID = = ( int ) EnumIncomeTaxItemGroup . Tax_Deducted ) . TotalAmount ;
return this . CurrentYearTax ;
}
catch ( ServiceException ex )
{
throw new ServiceException ( ex . Message ) ;
}
catch ( Exception ex )
{
throw new ServiceException ( ex . Message ) ;
}
}
public List < IncomeTax > UndoCalculate ( List < TaxRawItem > rawItems , double taxAmount )
{
try
{
_isActualInvestment = true ;
this . _onceoffAmount = 0 ;
IncomeTax oIncomeTax = new IncomeTax ( ) ;
EnumIncomeTaxDataFrom datafrom = new IncomeTaxService ( ) . GetEnumForSalaryIT ( _employee . ID ) ;
if ( datafrom = = EnumIncomeTaxDataFrom . SalaryITTempData )
{
throw new ServiceException ( "Current month salary is processed and not yet finalized. Tax calculation "
+ " is not allowed middle of this process. You have to Undo or finalize the salary to calculate tax." ) ;
}
this . CurrentYearTax = new List < IncomeTax > ( ) ;
this . CurrentYearTax = new IncomeTaxService ( ) . Get ( _employee . ID , EnumIncomeTaxDataFrom . ProcessTempData ) ;
this . CalcualteprojectMonth ( ) ;
//foreach (IncomeTax item in this.CurrentYearTax)
// item.ProjectedAmount = 0;
this . UpdateRawItems ( rawItems , EnumSide . Deduct ) ;
this . CmpProvidedHouseAndTransport ( this . payrolltype . NextPayProcessDate ) ;
this . CalculateExamtion ( ) ;
this . CalculateBonusProjection ( ) ;
this . CalculateCPF ( ) ;
this . CalculateTotalIncome ( ) ;
this . CalculateInvestment ( ) ;
this . CalculateGrossTax ( ) ;
this . CalculateNetPayable ( ) ;
this . UndoDecutedAmount ( taxAmount ) ;
return this . CurrentYearTax ;
}
catch ( ServiceException ex )
{
throw new ServiceException ( ex . Message ) ;
}
catch ( Exception ex )
{
throw new ServiceException ( ex . Message ) ;
}
}
/// <summary>
///
/// </summary>
/// <param name="naxParameterID"></param>
public List < IncomeTax > DoTaxYearEnd ( int payrolltypeid )
{
List < IncomeTax > empTaxCertificates = new List < IncomeTax > ( ) ;
PayrollType ptyp = new PayrollTypeService ( ) . Get ( payrolltypeid ) ;
List < Employee > employess = new EmployeeService ( ) . GetAllEmps ( ) ;
try
{
// if IncomeTax.get() function not return employee order-by wise data, rest of the function will not culculate properly.
List < IncomeTax > oTaxYearly = new IncomeTaxService ( ) . Get ( EnumIncomeTaxDataFrom . ProcessTempData , ptyp . ID ) ;
2026-11-30 10:14:40 +06:00
oTaxYearly = oTaxYearly . OrderBy ( x = > x . EmployeeID ) . ToList ( ) ;
2026-11-03 13:06:00 +06:00
int? nCurrEmployeeid = null ;
if ( oTaxYearly . Count > 0 ) nCurrEmployeeid = oTaxYearly [ 0 ] . EmployeeID ;
_taxParameter = new TaxParameterService ( ) . Get ( ( int ) ptyp . TaxParamID ) ;
this . payrolltype = ptyp ;
while ( true )
{
_employee = employess . FirstOrDefault ( x = > x . ID = = oTaxYearly [ 0 ] . EmployeeID ) ;
this . CurrentYearTax = oTaxYearly . FindAll ( x = > x . EmployeeID = = nCurrEmployeeid ) ;
if ( this . CurrentYearTax = = null ) continue ;
if ( _employee . Status ! = EnumEmployeeStatus . Live )
{
foreach ( IncomeTax item in this . CurrentYearTax ) item . ProjectedAmount = 0 ;
_isActualInvestment = false ;
this . _onceoffAmount = 0 ;
this . CalculateExamtion ( ) ;
this . CalculateTotalIncome ( ) ;
this . CalculateInvestment ( ) ;
this . CalculateGrossTax ( ) ;
this . CalculateNetPayable ( ) ;
this . CalculateYearlyRefund ( ) ;
}
foreach ( IncomeTax item in this . CurrentYearTax )
{
2026-11-30 10:14:40 +06:00
item . TaxParameterID = ( int ) ptyp . TaxParamID ;
2026-11-03 13:06:00 +06:00
empTaxCertificates . Add ( item ) ;
oTaxYearly . Remove ( item ) ;
}
if ( oTaxYearly . Count > 0 ) nCurrEmployeeid = oTaxYearly [ 0 ] . EmployeeID ;
else break ;
}
}
catch ( Exception ex )
{
throw new ServiceException ( ex . Message ) ;
}
return empTaxCertificates ;
}
//public List<IncomeTax> DoTaxYearEndReProcess(int nTaxParamterID, bool isMaximumInvestment)
//{
// List<IncomeTax> empTaxCertificates = new List<IncomeTax>();
// try
// {
// // if IncomeTax.get() function not return employee order-by wise data, rest of the function will not culculate properly.
// List<IncomeTax> oTaxYearly = new IncomeTaxService().GetPrvYear(nTaxParamterID, this.payrolltype.ID);
// if (this.payrolltype.TaxParamID == nTaxParamterID)
// oTaxYearly = new IncomeTaxService().GetByYear(nTaxParamterID, EnumIncomeTaxDataFrom.ProcessTempData, this.payrolltype.ID);
// else
// oTaxYearly = new IncomeTaxService().GetPrvYear(nTaxParamterID, this.payrolltype.ID);
// int? nCurrEmployeeid = null;
// if (oTaxYearly.Count > 0) nCurrEmployeeid = oTaxYearly[0].EmployeeID;
// _taxParameter = new TaxParameterService().Get(nTaxParamterID);
// while (true)
// {
// _employee = new EmployeeService().Get((int)nCurrEmployeeid);
// this.CurrentYearTax = oTaxYearly.FindAll(x => x.EmployeeID == nCurrEmployeeid);
// // Initialize the current data.
// foreach (IncomeTax item in this.CurrentYearTax)
// {
// item.ProjectedAmount = 0;
// oTaxYearly.Remove(item); // Remove from collection
// }
// _isActualInvestment = !isMaximumInvestment;
// IncomeTax car = this.CurrentYearTax.FirstOrDefault(x => x.EmployeeID == _employee.ID
// && x.ItemGroup == EnumIncomeTaxItemGroup.Cmp_Provided_car && x.ItemID == (int)EnumIncomeTaxItemGroup.Cmp_Provided_car);
// if (car != null)
// {
// if (car.TotalAmount < 60000)
// car.TotalAmount = 60000;
// }
// this.CalculateExamtion();
// this.CalculateTotalIncome();
// this.CalculateInvestment();
// this.CalculateGrossTax();
// this.CalculateNetPayable();
// this.CalculateYearlyRefund();
// foreach (IncomeTax item in this.CurrentYearTax)
// {
// item.EmployeeID = _employee.ID;
// item.TaxParameterID = nTaxParamterID;
// empTaxCertificates.Add(item);
// }
// if (oTaxYearly.Count > 0) nCurrEmployeeid = oTaxYearly[0].EmployeeID;
// else break;
// }
// }
// catch (Exception ex)
// {
// throw new ServiceException(ex.Message);
// }
// return empTaxCertificates;
//}
public List < IncomeTax > CalculateLTATax ( List < TaxRawItem > rawItems , ref double ntaxAmount )
{
double namount = rawItems . Select ( c = > c . Amount ) . Sum ( ) ; ;
return this . CalculateLTATax ( rawItems , namount , ref ntaxAmount ) ;
}
public List < IncomeTax > CalculateLTATax ( List < TaxRawItem > rawItems , double onceoffAmount , ref double ntaxAmount )
{
try
{
_isActualInvestment = true ;
this . _onceoffAmount = onceoffAmount ;
IncomeTax oIncomeTax = new IncomeTax ( ) ;
EnumIncomeTaxDataFrom datafrom = new IncomeTaxService ( ) . GetEnumForSalaryIT ( _employee . ID ) ;
if ( datafrom = = EnumIncomeTaxDataFrom . SalaryITTempData )
{
throw new ServiceException ( "Current month salary is processed and not yet finalized. Tax calculation "
+ " is not allowed middle of this process. You have to Undo or finalize the salary to calculate tax." ) ;
}
this . CurrentYearTax = new List < IncomeTax > ( ) ;
this . CurrentYearTax = new IncomeTaxService ( ) . Get ( _employee . ID , EnumIncomeTaxDataFrom . ProcessTempData ) ;
this . CalcualteprojectMonth ( ) ;
_projectedMonth = _projectedMonth + 1 ;
foreach ( IncomeTax item in this . CurrentYearTax )
{
item . PreviousAmount = item . PreviousAmount + item . ThisMonthAmount ;
item . ThisMonthAmount = 0 ;
//if (item.ItemGroup != EnumIncomeTaxItemGroup.Other_Allowance)
// item.ProjectedAmount = 0;
}
this . UpdateRawItems ( rawItems , EnumSide . Add ) ;
// this.CmpProvidedHouseAndTransport(SystemInformation.CurrentSysInfo.LastPayProcessDate.AddMonths(-1));
this . CalculateExamtion ( ) ;
// this.CalculateBonusProjection();
this . CalculateCPF ( ) ;
this . CalculateTotalIncome ( ) ;
this . CalculateInvestment ( ) ;
this . CalculateGrossTax ( ) ;
this . CalculateNetPayable ( ) ;
ntaxAmount = this . CulculateArrearOnMonth ( ) ;
return this . CurrentYearTax ;
}
catch ( ServiceException ex )
{
throw new ServiceException ( ex . Message ) ;
}
catch ( Exception ex )
{
throw new ServiceException ( ex . Message ) ;
}
}
public List < IncomeTax > UndoEncashAmount ( List < TaxRawItem > oTaxRowItems , double nTaxAmount )
{
try
{
_isActualInvestment = true ;
this . _onceoffAmount = 0 ;
IncomeTaxService tempIncomeTaxService = new IncomeTaxService ( ) ;
EnumIncomeTaxDataFrom datafrom = tempIncomeTaxService . GetEnumForSalaryIT ( _employee . ID ) ;
if ( datafrom = = EnumIncomeTaxDataFrom . SalaryITTempData )
{
throw new ServiceException ( "Current month salary is processed and not yet finalized. Tax calculation "
+ " is not allowed middle of this process. You have to Undo or finalize the salary to calculate tax." ) ;
}
this . CurrentYearTax = new List < IncomeTax > ( ) ;
this . CurrentYearTax = tempIncomeTaxService . Get ( _employee . ID , EnumIncomeTaxDataFrom . ProcessTempData ) ;
this . UpdateRawItemsForEncash ( oTaxRowItems , EnumSide . Deduct ) ;
//this.CalculateBonusProjection();
IncomeTax taxitem = this . CurrentYearTax . Find ( x = > x . Description = = "Leave Encashment" & & x . ItemGroup = = EnumIncomeTaxItemGroup . Earned_Leave & & x . ItemID = = 100 ) ;
if ( taxitem ! = null )
taxitem . ThisMonthAmount = 0 ;
this . CalculateTotalIncome ( ) ;
this . CalculateInvestment ( ) ;
this . CalculateGrossTax ( ) ;
this . CalculateNetPayable ( ) ;
this . UndoDecutedAmount ( nTaxAmount ) ;
return this . CurrentYearTax ;
}
catch ( ServiceException ex )
{
throw new ServiceException ( ex . Message ) ;
}
catch ( Exception ex )
{
throw new ServiceException ( ex . Message ) ;
}
}
protected void UpdateRawItemsForEncash ( List < TaxRawItem > rawItems , EnumSide nSide )
{
foreach ( TaxRawItem item in rawItems )
{
if ( item . Amount = = 0 ) continue ;
IncomeTax taxItem = null ;
//nSide = EnumSide.Add;
switch ( item . ItemType )
{
case enumIncomeTaxItemType . Basic_Salary :
taxItem = GetTaxItem ( EnumTaxMergeType . NONE , ( int ) EnumIncomeTaxItemGroup . Basic_Salary , item . Description ) ;
break ;
case enumIncomeTaxItemType . Allowance :
taxItem = GetTaxItem ( EnumTaxMergeType . Allowance , item . ItemId , item . Description ) ;
break ;
case enumIncomeTaxItemType . Deduction :
taxItem = GetTaxItem ( EnumTaxMergeType . Allowance , item . ItemId , item . Description ) ;
break ;
case enumIncomeTaxItemType . OT :
taxItem = GetTaxItem ( EnumTaxMergeType . OT , item . ItemId , item . Description ) ;
break ;
case enumIncomeTaxItemType . Bonus :
taxItem = GetTaxItem ( EnumTaxMergeType . Bonus , item . ItemId , item . Description ) ;
break ;
case enumIncomeTaxItemType . FinalSettlement :
taxItem = GetTaxItem ( EnumTaxMergeType . Settlement , item . ItemId , item . Description ) ;
break ;
case enumIncomeTaxItemType . OPI :
//taxItem = GetTaxItem(EnumTaxMergeType.Bonus, item.ItemId, item.Description);
//taxItem.ThisMonthAmount = GlobalFunctions.Round(item.Amount);
break ;
case enumIncomeTaxItemType . AdjustItem :
taxItem = GetTaxItem ( EnumTaxMergeType . TaxAdjustItem , item . ItemId , item . Description ) ;
break ;
case enumIncomeTaxItemType . Earned_Leave :
taxItem = GetTaxItem ( EnumTaxMergeType . LeaveEncashment , 100 , item . Description ) ;
break ;
case enumIncomeTaxItemType . Compensation :
taxItem = GetTaxItem ( EnumTaxMergeType . Compensation , 0 , item . Description ) ;
break ;
case enumIncomeTaxItemType . NoticePay :
taxItem = GetTaxItem ( EnumTaxMergeType . NoticePayDeduction , 0 , item . Description ) ;
nSide = EnumSide . Deduct ;
break ;
default :
break ;
}
if ( taxItem ! = null )
{
taxItem . ThisMonthAmount = 0 ;
if ( taxItem ! = null ) taxItem . Side = nSide = = EnumSide . Add ? EnumIncomeTaxSide . Inc_SalaryIncome : EnumIncomeTaxSide . Dec_SalaryIncome ;
this . Add ( taxItem ) ;
}
}
}
private void Add ( IncomeTax taxItem )
{
if ( taxItem . Position = = 0 )
{
ProcessItem pitem = _processItems . Find ( delegate ( ProcessItem item )
{ return item . ItemCode = = ( int ) taxItem . ItemGroup ; } ) ;
if ( pitem = = null ) throw new ServiceException ( "Tax process item code not found in the process collection; Item Code:" + taxItem . ItemGroup . ToString ( ) ) ;
taxItem . Position = pitem . Position ;
}
IncomeTax existItem = _currentYearTax . Find ( delegate ( IncomeTax item )
{ return item . ItemGroup = = taxItem . ItemGroup & & item . ItemID = = taxItem . ItemID ; } ) ;
if ( existItem = = null ) _currentYearTax . Add ( taxItem ) ;
else
{
existItem . PreviousAmount = existItem . PreviousAmount + taxItem . PreviousAmount ;
existItem . ThisMonthAmount = existItem . ThisMonthAmount + taxItem . ThisMonthAmount ;
existItem . ProjectedAmount = existItem . ProjectedAmount + taxItem . ProjectedAmount ;
existItem . Position = taxItem . Position ;
existItem . Description = taxItem . Description ;
}
}
public List < IncomeTax > CalculateEncashAmount ( List < TaxRawItem > rawItems , ref double ntaxAmount , DateTime nextPayProcessDate )
{
try
{
double nTempAmount = 0 ;
bool bStartMonth = false ;
_isActualInvestment = true ;
this . _onceoffAmount = rawItems . Sum ( x = > x . Amount ) ;
IncomeTaxService tempIncomeTaxService = new IncomeTaxService ( ) ;
EnumIncomeTaxDataFrom datafrom = tempIncomeTaxService . GetEnumForSalaryIT ( _employee . ID ) ;
if ( datafrom = = EnumIncomeTaxDataFrom . SalaryITTempData )
{
throw new ServiceException ( "Current month salary is processed and not yet finalized. Tax calculation "
+ " is not allowed middle of this process. You have to Undo or finalize the salary to calculate tax." ) ;
}
if ( this . CurrentYearTax = = null )
{
this . CurrentYearTax = new List < IncomeTax > ( ) ;
this . CurrentYearTax = tempIncomeTaxService . Get ( _employee . ID , EnumIncomeTaxDataFrom . ProcessTempData ) ;
}
if ( nextPayProcessDate . Month = = 7 ) // if month is july and salary not yet processed then, clear all tax data
{
bStartMonth = true ;
this . CalcualteprojectMonth ( ) ;
this . CalculateOnlyProjection ( ) ;
}
this . UpdateRawItems ( rawItems , EnumSide . Add ) ;
IncomeTax taxitem = this . CurrentYearTax . Find ( x = > x . Description = = "Leave Encashment" & & x . ItemGroup = = EnumIncomeTaxItemGroup . Earned_Leave & & x . ItemID = = 100 ) ;
if ( taxitem ! = null )
taxitem . Side = EnumIncomeTaxSide . Inc_SalaryIncome ;
this . CalculateExamtion ( ) ;
//this.CalculateBonusProjection();
this . CalculateCPF ( ) ;
this . CalculateTotalIncome ( ) ;
this . CalculateInvestment ( ) ;
this . CalculateGrossTax ( ) ;
double totalAmount = 0 ;
IncomeTax netPayable = tempIncomeTaxService . Get ( this . CurrentYearTax , _employee . ID ,
EnumIncomeTaxItemGroup . Net_Payable , ( int ) EnumIncomeTaxItemGroup . Net_Payable ) ;
if ( netPayable ! = null )
nTempAmount = netPayable . TotalAmount ;
ntaxAmount = 0 ;
this . CalculateNetPayable ( ) ;
ntaxAmount = nTempAmount ;
//netPayable = IncomeTax.Get(this.CurrentYearTax, _employee.ID, EnumIncomeTaxItemGroup.Net_Payable, (int)EnumIncomeTaxItemGroup.Net_Payable);
if ( netPayable ! = null )
if ( totalAmount > 0 )
ntaxAmount = netPayable . TotalAmount - totalAmount ;
else
ntaxAmount = ( - totalAmount - netPayable . TotalAmount ) > 0 ? 0 : netPayable . TotalAmount ;
double grossTax = tempIncomeTaxService . Get ( this . CurrentYearTax , _employee . ID ,
EnumIncomeTaxItemGroup . Gross_Tax , ( int ) EnumIncomeTaxItemGroup . Gross_Tax ) . TotalAmount ;
if ( _onceoffAmount > 0 )
{
double annualIncome = this . GetAnnualIncome ( ) ;
ntaxAmount = grossTax - this . GetTaxAmount ( annualIncome - _onceoffAmount ) ;
ntaxAmount = ntaxAmount - CalculateOnceOfInvestmentAmt ( annualIncome - _onceoffAmount ) ;
if ( ntaxAmount < 0 ) ntaxAmount = 0 ;
}
IncomeTax TaxDeductitem = tempIncomeTaxService . Get ( this . CurrentYearTax , _employee . ID ,
EnumIncomeTaxItemGroup . Tax_Deducted , ( int ) EnumIncomeTaxItemGroup . Tax_Deducted ) ;
if ( TaxDeductitem = = null ) TaxDeductitem = this . Add ( EnumIncomeTaxItemGroup . Tax_Deducted ,
( int ) EnumIncomeTaxItemGroup . Tax_Deducted , string . Empty , 0 , 0 , EnumIncomeTaxSide . Tax_fixed_Item ) ;
TaxDeductitem . ThisMonthAmount = TaxDeductitem . ThisMonthAmount + ntaxAmount ;
return this . CurrentYearTax ;
}
catch ( ServiceException ex )
{
throw new ServiceException ( ex . Message ) ;
}
catch ( Exception ex )
{
throw new ServiceException ( ex . Message ) ;
}
}
public double getSalaryAmount ( List < SalaryMonthly > salareis , int employeeid , EnumSalaryItemCode ItemCode , int ItemID )
{
double aAmount = 0 ;
List < SalaryMonthly > empsalareis = salareis . FindAll ( x = > x . EmployeeID = = employeeid ) . ToList ( ) ;
if ( empsalareis ! = null )
{
2026-11-30 10:14:40 +06:00
foreach ( var salary in empsalareis )
2026-11-03 13:06:00 +06:00
{
foreach ( var salaryDetail in salary . Details )
{
if ( ItemCode = = EnumSalaryItemCode . PF_Contribution | | ItemCode = = EnumSalaryItemCode . Inc_Tax_Deduction )
{
2026-11-30 10:14:40 +06:00
if ( salaryDetail . ItemCode = = ItemCode & & ( salaryDetail . itemGroupCode = = EnumSalaryGroup . Deductions )
2026-11-03 13:06:00 +06:00
& & salaryDetail . ItemID = = ItemID )
{
aAmount = aAmount + salaryDetail . ChangedAmount ;
}
}
else if ( ItemCode = = EnumSalaryItemCode . Deduction & & ItemCode ! = EnumSalaryItemCode . PF_Contribution )
{
if ( salaryDetail . ItemCode = = ItemCode & & ( salaryDetail . itemGroupCode = = EnumSalaryGroup . Deductions )
& & salaryDetail . ItemID = = ItemID )
{
aAmount = aAmount - salaryDetail . ChangedAmount ;
}
}
else
{
if ( salaryDetail . ItemCode = = ItemCode & & ( salaryDetail . itemGroupCode = = EnumSalaryGroup . Gross
| | salaryDetail . itemGroupCode = = EnumSalaryGroup . Arrear ) & & salaryDetail . ItemID = = ItemID )
{
aAmount = aAmount + salaryDetail . ChangedAmount ;
}
if ( salaryDetail . ItemCode = = ItemCode & & salaryDetail . itemGroupCode = = EnumSalaryGroup . UnauthLeave
& & salaryDetail . ItemID = = ItemID )
{
aAmount = aAmount - salaryDetail . ChangedAmount ;
}
}
}
}
}
return aAmount ;
}
public double GetConvertedAmount ( EnumIncomeTaxItemGroup taxGroup , int taxItemID , string name ,
List < TaxMergeMaster > taxmergs , List < SalaryMonthly > salareis ,
List < BonusProcess . BonusProcessDetail > BonusPayments , EnumSalaryItemCode ? ItemCode )
{
double Amount = 0 ;
List < TaxMergeMaster > txgs = taxmergs . Where ( x = > x . ItemGroup = = taxGroup & & x . ItemID = = taxItemID ) . ToList ( ) ;
if ( txgs ! = null )
{
foreach ( TaxMergeMaster master in txgs )
{
if ( master . Description ! = name ) continue ;
foreach ( TaxMergeMaster . TaxMergeDetail mergeDetail in master . TaxMergeDetails )
{
if ( mergeDetail . Type = = EnumTaxMergeType . Allowance )
{
Amount = Amount + this . getSalaryAmount ( salareis , _employee . ID ,
EnumSalaryItemCode . Allowance , mergeDetail . ItemID ) ;
}
else if ( mergeDetail . Type = = EnumTaxMergeType . Deduction )
{
Amount = Amount + this . getSalaryAmount ( salareis , _employee . ID ,
EnumSalaryItemCode . Deduction , mergeDetail . ItemID ) ;
}
else if ( mergeDetail . Type = = EnumTaxMergeType . OT )
{
Amount = Amount + this . getSalaryAmount ( salareis , _employee . ID ,
EnumSalaryItemCode . Over_Time_Amount , mergeDetail . ItemID ) ;
}
else if ( mergeDetail . Type = = EnumTaxMergeType . Bonus )
{
2026-11-30 10:14:40 +06:00
Amount = Amount + BonusPayments . Where ( x = > x . EmployeeID = = _employee . ID
2026-11-03 13:06:00 +06:00
& & x . BonusID = = mergeDetail . ItemID ) . Sum ( x = > x . ChangeBonusAmount ) ;
}
else if ( ItemCode ! = null )
{
Amount = Amount + this . getSalaryAmount ( salareis , _employee . ID ,
( EnumSalaryItemCode ) ItemCode , ( int ) ItemCode ) ;
}
else
{
/// throw new Exception("Merge head not found");
}
}
}
}
//else
//{
// if (ItemCode != null)
// {
// Amount = Amount + this.getSalaryAmount(salareis, _employee.ID,
// (EnumSalaryItemCode)ItemCode, (int)ItemCode);
// }
//}
return Amount ;
}
2026-11-30 10:14:40 +06:00
public List < IncomeTax > TaxReconsiliation ( int payrolltypeid , List < Employee > emps ,
2026-11-03 13:06:00 +06:00
int nTaxParamterID , EnumIncomeTaxDataFrom datafrom )
{
List < SalaryMonthly > salareis = null ;
List < BonusProcess . BonusProcessDetail > bonuspaments = null ;
List < IncomeTax > empTaxCertificates = new List < IncomeTax > ( ) ;
List < IncomeTax > oTaxYearly = null ;
string inSQL = Employee . getEmpID ( emps ) ;
List < ITEmpHead > assignedHeads = new ITEmpHeadService ( ) . GetWithTaxParam ( nTaxParamterID ) ;
PayrollType ptype = new PayrollTypeService ( ) . Get ( payrolltypeid ) ;
List < EmployeeTaxInvestment > empInvestments = new EmployeeTaxInvestmentService ( ) . GetAllUsersInfo ( nTaxParamterID ) ;
double ProjectedMonths = 0 ;
bool isExemptionYearly = new SystemConfigarationService ( ) . GetconfigBooleanValue ( EnumConfigurationType . Logic , "incometax" , "monthlyexemption" ) ;
bool IsmaximumInvestment = new SystemConfigarationService ( ) . GetconfigBooleanValue ( EnumConfigurationType . Logic , "incometax" , "investmentwithoutpf" ) ;
this . _processItems = new ProcessItemService ( ) . Get ( ) ;
this . payrolltype = ptype ;
bool binvestmenton = new SystemConfigarationService ( ) . GetconfigBooleanValue ( EnumConfigurationType . Logic , "incometax" , "investmentwithoutpf" ) ;
try
{
if ( ptype . TaxParamID = = nTaxParamterID )
{
oTaxYearly = new IncomeTaxService ( ) . Get ( datafrom , inSQL , payrolltypeid , null ) ;
}
else
oTaxYearly = new IncomeTaxService ( ) . Get ( datafrom , inSQL , payrolltypeid , nTaxParamterID ) ;
_taxParameter = new TaxParameterService ( ) . Get ( nTaxParamterID ) ;
if ( emps ! = null )
{
salareis = new SalaryMonthlyService ( ) . Get ( inSQL , _taxParameter . FiscalyearDatefrom , _taxParameter . FiscalyearDateTo , payrolltypeid ) ;
bonuspaments = new BonusProcessService ( ) . GetBonusDetailsByEmps ( inSQL , _taxParameter . FiscalyearDatefrom , _taxParameter . FiscalyearDateTo , payrolltypeid ) ;
}
else
{
List < Employee > allemp = new EmployeeService ( ) . GetAllEmps ( payrolltypeid ) ;
2026-11-30 10:14:40 +06:00
salareis = new SalaryMonthlyService ( ) . GetByDateRange ( _taxParameter . FiscalyearDatefrom , _taxParameter . FiscalyearDateTo , payrolltypeid ) ;
2026-11-03 13:06:00 +06:00
emps = new List < BO . Employee > ( ) ;
foreach ( Employee item in allemp )
{
var isexist = salareis . FirstOrDefault ( x = > x . EmployeeID = = item . ID ) ;
if ( isexist ! = null )
{
emps . Add ( item ) ;
}
}
bonuspaments = new BonusProcessService ( ) . GetBonusDetailsByEmps ( inSQL , _taxParameter . FiscalyearDatefrom , _taxParameter . FiscalyearDateTo , payrolltypeid ) ;
}
List < TaxMergeMaster > taxMerges = new TaxMergeMasterService ( ) . GetbyTaxParameter ( _taxParameter . ID , payrolltypeid ) ;
foreach ( Employee emp in emps )
{
_employee = emp ; //employees.FirstOrDefault(x => x.ID.Integer == nCurrEmployeeid.Integer);
_isActualInvestment = true ;
_projectedMonth = 12 - ( ( ( ptype . NextPayProcessDate . Year - ptype . TaxYearEndDate . Year ) * 12 )
+ ptype . NextPayProcessDate . Month - ptype . TaxYearEndDate . Month ) ;
if ( ProjectedMonths < 0 ) ProjectedMonths = 0 ;
if ( emp . EndOfContractDate ! = null & & emp . EndOfContractDate ! = DateTime . MinValue )
{
if ( emp . EndOfContractDate < _taxParameter . FiscalyearDateTo )
if ( ( ( DateTime ) emp . EndOfContractDate ) . Month = = 7 )
ProjectedMonths = Convert . ToDouble ( 0 ) ;
else
ProjectedMonths = GlobalFunctions . GetFraction ( this . payrolltype . NextPayProcessDate . AddDays ( 1 ) , ( DateTime ) emp . EndOfContractDate ) ;
2026-11-30 10:14:40 +06:00
2026-11-03 13:06:00 +06:00
}
2026-11-30 10:14:40 +06:00
this . CurrentYearTax = oTaxYearly . FindAll ( x = > x . EmployeeID = = _employee . ID ) ;
2026-11-03 13:06:00 +06:00
#region Calculate From Salary & Bonus
double basicSalary = 0 ;
2026-11-30 10:14:40 +06:00
IncomeTax HrExption = this . CurrentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID
& & x . ItemGroup = = EnumIncomeTaxItemGroup . Exemption_House_Rent_Allowance
2026-11-03 13:06:00 +06:00
& & x . ItemID = = ( int ) EnumIncomeTaxItemGroup . Exemption_House_Rent_Allowance ) ;
if ( HrExption = = null ) HrExption = this . Add ( EnumIncomeTaxItemGroup . Exemption_House_Rent_Allowance ,
( int ) EnumIncomeTaxItemGroup . Exemption_House_Rent_Allowance , string . Empty , 0 , 0 , EnumIncomeTaxSide . Dec_SalaryIncome ) ;
HrExption . Description = "HR Exemption" ;
IncomeTax convExption = this . CurrentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID
& & x . ItemGroup = = EnumIncomeTaxItemGroup . Exemption_Conveyance_Allowance
& & x . ItemID = = ( int ) EnumIncomeTaxItemGroup . Exemption_Conveyance_Allowance ) ;
if ( convExption = = null ) convExption = this . Add ( EnumIncomeTaxItemGroup . Exemption_Conveyance_Allowance ,
( int ) EnumIncomeTaxItemGroup . Exemption_Conveyance_Allowance , string . Empty , 0 , 0 , EnumIncomeTaxSide . Dec_SalaryIncome ) ;
convExption . Description = "Transport Exemption" ;
IncomeTax mdExption = this . CurrentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID
& & x . ItemGroup = = EnumIncomeTaxItemGroup . Exemption_Medical_Allowance
& & x . ItemID = = ( int ) EnumIncomeTaxItemGroup . Exemption_Medical_Allowance ) ;
if ( mdExption = = null ) mdExption = this . Add ( EnumIncomeTaxItemGroup . Exemption_Medical_Allowance , ( int ) EnumIncomeTaxItemGroup . Exemption_Medical_Allowance , string . Empty , 0 , 0 , EnumIncomeTaxSide . Dec_SalaryIncome ) ;
mdExption . Description = "Medical Exemption" ;
IncomeTax lfaExption = this . CurrentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID
& & x . ItemGroup = = EnumIncomeTaxItemGroup . Exemption_LFA_Allowance
& & x . ItemID = = ( int ) EnumIncomeTaxItemGroup . Exemption_LFA_Allowance ) ;
if ( lfaExption = = null ) lfaExption = this . Add ( EnumIncomeTaxItemGroup . Exemption_LFA_Allowance , ( int ) EnumIncomeTaxItemGroup . Exemption_LFA_Allowance , string . Empty , 0 , 0 , EnumIncomeTaxSide . Dec_SalaryIncome ) ;
mdExption . Description = "LFA Exemption" ;
foreach ( IncomeTax item in this . CurrentYearTax )
{
if ( item . Side ! = EnumIncomeTaxSide . Inc_SalaryIncome & &
item . Side ! = EnumIncomeTaxSide . Inc_AnnualIncome )
continue ;
if ( ProjectedMonths = = 0 ) item . ProjectedAmount = 0 ;
double salaryCount = salareis . Count ( x = > x . EmployeeID = = _employee . ID ) ;
double reAmount = 0 ;
item . ThisMonthAmount = item . PreviousAmount + item . ThisMonthAmount + item . ProjectedAmount ;
item . PreviousAmount = item . ProjectedAmount ;
switch ( item . ItemGroup )
{
case EnumIncomeTaxItemGroup . None :
break ;
case EnumIncomeTaxItemGroup . Basic_Salary :
reAmount = this . GetConvertedAmount ( EnumIncomeTaxItemGroup . Basic_Salary , item . ItemID , item . Description , taxMerges , salareis , bonuspaments , EnumSalaryItemCode . Basic_Salary ) ;
basicSalary = reAmount + item . ProjectedAmount ;
break ;
case EnumIncomeTaxItemGroup . House_Rent_Allowance :
reAmount = this . GetConvertedAmount ( EnumIncomeTaxItemGroup . House_Rent_Allowance , item . ItemID , item . Description , taxMerges ,
salareis , bonuspaments , null ) ;
List < SalaryMonthly > empsalareis = salareis . FindAll ( x = > x . EmployeeID = = _employee . ID ) . ToList ( ) ;
if ( isExemptionYearly = = false )
{
TaxMergeMaster txg = taxMerges . FirstOrDefault ( x = > x . ItemGroup = = EnumIncomeTaxItemGroup . House_Rent_Allowance ) ;
double HRexemptedAmount = 0 ;
double LasHRExemptedAmount = 0 ;
if ( empsalareis ! = null )
{
empsalareis . ForEach ( x = >
{
double monthlyBasic = 0 ;
double monthlyHouserent = 0 ;
x . Details . ForEach ( y = >
{
if ( y . ItemCode = = EnumSalaryItemCode . Basic_Salary & & ( y . itemGroupCode = = EnumSalaryGroup . Gross
| | y . itemGroupCode = = EnumSalaryGroup . Arrear ) & & y . ItemID = = ( int ) EnumSalaryItemCode . Basic_Salary )
{
monthlyBasic = monthlyBasic + y . ChangedAmount ;
}
foreach ( TaxMergeMaster . TaxMergeDetail mergeDetail in txg . TaxMergeDetails )
{
if ( y . ItemCode = = EnumSalaryItemCode . Allowance & & ( y . itemGroupCode = = EnumSalaryGroup . Gross
| | y . itemGroupCode = = EnumSalaryGroup . Arrear ) & & y . ItemID = = mergeDetail . ItemID )
{
monthlyHouserent = monthlyHouserent + y . ChangedAmount ;
}
}
} ) ;
double basicPercent = monthlyBasic * _taxParameter . MaxHRPercent / 100 ;
if ( monthlyHouserent > _taxParameter . MaxHRAmount / 12 ) monthlyHouserent = _taxParameter . MaxHRAmount / 12 ;
if ( monthlyHouserent > basicPercent )
{
HRexemptedAmount = HRexemptedAmount + basicPercent ;
LasHRExemptedAmount = basicPercent ;
}
else
{
HRexemptedAmount = HRexemptedAmount + monthlyHouserent ;
LasHRExemptedAmount = monthlyHouserent ;
}
} ) ;
}
HRexemptedAmount = HRexemptedAmount + LasHRExemptedAmount * ProjectedMonths ;
HrExption . ThisMonthAmount = HrExption . ThisMonthAmount + HrExption . ProjectedAmount + HrExption . PreviousAmount ;
HrExption . PreviousAmount = HRexemptedAmount ;
}
else
{
double yearlyHR = basicSalary * _taxParameter . MaxHRPercent / 100 ;
if ( yearlyHR > _taxParameter . MaxHRAmount ) yearlyHR = _taxParameter . MaxHRAmount ;
if ( yearlyHR > reAmount ) yearlyHR = reAmount ;
HrExption . ThisMonthAmount = HrExption . ThisMonthAmount + HrExption . ProjectedAmount + HrExption . PreviousAmount ;
HrExption . PreviousAmount = yearlyHR ;
}
//HrExption.Description = "HR Exemption";
break ;
case EnumIncomeTaxItemGroup . Conveyance_Allowance :
reAmount = this . GetConvertedAmount ( EnumIncomeTaxItemGroup . Conveyance_Allowance , item . ItemID , item . Description , taxMerges ,
salareis , bonuspaments , null ) ;
//if (isExemptionYearly == false)
//{
// convExption.ThisMonthAmount = convExption.ThisMonthAmount + convExption.ProjectedAmount + convExption.PreviousAmount;
// double convAmount = (salaryCount + ProjectedMonths) * (_taxParameter.MaxConvAmount / 12);
// if (reAmount + item.ProjectedAmount > convAmount)
// convExption.PreviousAmount = convAmount;
// else convExption.PreviousAmount = reAmount + item.ProjectedAmount;
//}
//else
//{
convExption . ThisMonthAmount = convExption . ThisMonthAmount + convExption . ProjectedAmount + convExption . PreviousAmount ;
if ( reAmount + item . ProjectedAmount > _taxParameter . MaxConvAmount )
convExption . PreviousAmount = _taxParameter . MaxConvAmount ;
else convExption . PreviousAmount = reAmount + + item . ProjectedAmount ;
//}
//convExption.Description = "Transport Exemption";
break ;
case EnumIncomeTaxItemGroup . Medical_Allowance :
reAmount = this . GetConvertedAmount ( EnumIncomeTaxItemGroup . Medical_Allowance , item . ItemID , item . Description , taxMerges ,
salareis , bonuspaments , null ) ;
mdExption . ThisMonthAmount = mdExption . ThisMonthAmount + mdExption . ProjectedAmount + mdExption . PreviousAmount ;
double nconvAmount = basicSalary * _taxParameter . MaxMedicalPercent / 100 ;
if ( nconvAmount > _taxParameter . MaxMedicalAmount )
nconvAmount = _taxParameter . MaxMedicalAmount ;
if ( reAmount + item . ProjectedAmount < nconvAmount )
nconvAmount = reAmount + item . ProjectedAmount ;
mdExption . PreviousAmount = nconvAmount ;
//mdExption.Description = item.Description + " Exemption";
break ;
case EnumIncomeTaxItemGroup . Company_Contri_PF :
reAmount = this . GetConvertedAmount ( EnumIncomeTaxItemGroup . Company_Contri_PF , item . ItemID , item . Description , taxMerges ,
salareis , bonuspaments , EnumSalaryItemCode . PF_Contribution ) ;
item . Description = "PF" ;
break ;
case EnumIncomeTaxItemGroup . Bonus :
reAmount = this . GetConvertedAmount ( EnumIncomeTaxItemGroup . Bonus , item . ItemID , item . Description , taxMerges ,
salareis , bonuspaments , null ) ;
//if (isLFAInBonus == true)
//{
// double lfaAmount = 0;
// //bonuspaments.Where(x => x.EmployeeID == _employee.ID && x.IsLFA == true
// // ).Sum(y => y.ChangeBonusAmount);
// reAmount = reAmount - lfaAmount;
// lfaExption.ThisMonthAmount = lfaExption.ProjectedAmount;
// lfaExption.PreviousAmount = lfaAmount;
//}
break ;
case EnumIncomeTaxItemGroup . Earned_Leave :
break ;
case EnumIncomeTaxItemGroup . Other_Cash_Benefits :
reAmount = this . GetConvertedAmount ( EnumIncomeTaxItemGroup . Other_Cash_Benefits , item . ItemID , item . Description , taxMerges ,
salareis , bonuspaments , null ) ;
break ;
case EnumIncomeTaxItemGroup . Tax_Deducted :
reAmount = this . GetConvertedAmount ( EnumIncomeTaxItemGroup . Tax_Deducted , item . ItemID , item . Description , taxMerges ,
salareis , bonuspaments , EnumSalaryItemCode . Inc_Tax_Deduction ) ;
reAmount = reAmount + bonuspaments . Where ( x = > x . EmployeeID = = _employee . ID ) . Sum ( x = > x . ChangeTaxAmount ) ;
break ;
case EnumIncomeTaxItemGroup . LFA_Allowance :
reAmount = this . GetConvertedAmount ( EnumIncomeTaxItemGroup . LFA_Allowance , item . ItemID , item . Description , taxMerges ,
salareis , bonuspaments , null ) ;
break ;
case EnumIncomeTaxItemGroup . WPPF_Allowance :
reAmount = this . GetConvertedAmount ( EnumIncomeTaxItemGroup . WPPF_Allowance , item . ItemID , item . Description , taxMerges ,
salareis , bonuspaments , null ) ;
break ;
case EnumIncomeTaxItemGroup . Other_Allowance :
reAmount = this . GetConvertedAmount ( EnumIncomeTaxItemGroup . Other_Allowance , item . ItemID , item . Description , taxMerges ,
salareis , bonuspaments , null ) ;
break ;
case EnumIncomeTaxItemGroup . TimeCard :
reAmount = this . GetConvertedAmount ( EnumIncomeTaxItemGroup . TimeCard , item . ItemID , item . Description , taxMerges ,
salareis , bonuspaments , null ) ;
break ;
case EnumIncomeTaxItemGroup . Cmp_Provided_car :
List < ITEmpHead > cars = assignedHeads . Where ( x = > x . EmployeeID = = _employee . ID & & x . HeadID = = EnumIncomeTaxHead . Car ) . ToList ( ) ;
double carAmount = 0 ;
foreach ( ITEmpHead car in cars )
{
List < SalaryMonthly > empcarsalarys = salareis . Where ( x = > x . Employee . ID = = _employee . ID ) . ToList ( ) ;
if ( empcarsalarys ! = null )
{
while ( GlobalFunctions . LastDateOfMonth ( car . StartDate ) < = GlobalFunctions . LastDateOfMonth ( car . EndDate ) )
{
var carsalary = empcarsalarys . FirstOrDefault ( x = > x . SalaryMonth = = GlobalFunctions . LastDateOfMonth ( car . StartDate ) ) ;
if ( carsalary ! = null )
{
double tempcarAmount = carsalary . Details . Where ( x = > x . ItemCode = = EnumSalaryItemCode . Basic_Salary ) . Sum ( y = > y . ChangedAmount )
;
carAmount = carAmount + tempcarAmount ;
}
car . StartDate = GlobalFunctions . FirstDateOfMonth ( car . StartDate . AddMonths ( 1 ) ) ;
}
}
}
carAmount = carAmount * . 05 + item . PreviousAmount ;
if ( carAmount = = 0 ) carAmount = 0 ;
else if ( carAmount < 60000 ) carAmount = 60000 ;
reAmount = carAmount ;
item . PreviousAmount = 0 ;
//item.Description = "Car";
break ;
default :
break ;
}
item . PreviousAmount = item . PreviousAmount + reAmount ;
}
#endregion
#region Calculate Annual Income & Salary Income
IncomeTax annualIncome = this . CurrentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID
& & x . ItemGroup = = EnumIncomeTaxItemGroup . Annual_Income
& & x . ItemID = = ( int ) EnumIncomeTaxItemGroup . Annual_Income ) ;
IncomeTax salaryIncome = this . CurrentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID
& & x . ItemGroup = = EnumIncomeTaxItemGroup . Annual_Salary_Income
& & x . ItemID = = ( int ) EnumIncomeTaxItemGroup . Annual_Salary_Income ) ;
if ( annualIncome = = null ) annualIncome = this . Add ( EnumIncomeTaxItemGroup . Annual_Income ,
( int ) EnumIncomeTaxItemGroup . Annual_Income , string . Empty , 0 , 0 , EnumIncomeTaxSide . Tax_fixed_Item ) ;
if ( salaryIncome = = null ) salaryIncome = this . Add ( EnumIncomeTaxItemGroup . Annual_Salary_Income ,
( int ) EnumIncomeTaxItemGroup . Annual_Salary_Income , string . Empty , 0 , 0 , EnumIncomeTaxSide . Tax_fixed_Item ) ;
if ( annualIncome ! = null & & salaryIncome ! = null )
{
salaryIncome . ThisMonthAmount = salaryIncome . PreviousAmount + salaryIncome . ThisMonthAmount + salaryIncome . ProjectedAmount ;
annualIncome . ThisMonthAmount = annualIncome . PreviousAmount + annualIncome . ThisMonthAmount + annualIncome . ProjectedAmount ;
salaryIncome . PreviousAmount = this . CurrentYearTax . Where ( x = > x . Side = = EnumIncomeTaxSide . Inc_SalaryIncome ) . Sum ( y = > y . PreviousAmount )
- this . CurrentYearTax . Where ( x = > x . Side = = EnumIncomeTaxSide . Dec_SalaryIncome ) . Sum ( y = > y . PreviousAmount ) ;
annualIncome . PreviousAmount = salaryIncome . PreviousAmount + this . CurrentYearTax . Where ( x = > x . Side = = EnumIncomeTaxSide . Inc_AnnualIncome ) . Sum ( y = > y . PreviousAmount )
- this . CurrentYearTax . Where ( x = > x . Side = = EnumIncomeTaxSide . Dec_AnnualIncome ) . Sum ( y = > y . PreviousAmount ) ;
}
#endregion
#region Calculate Investment
IncomeTax investment = this . CurrentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID
& & x . ItemGroup = = EnumIncomeTaxItemGroup . Annual_Salary_Income
& & x . ItemID = = ( int ) EnumIncomeTaxItemGroup . Annual_Salary_Income ) ;
double taxCredit = 0 ;
if ( investment ! = null )
{
double investmentCanBeShown = 0 ;
if ( binvestmenton = = true )
investmentCanBeShown = ( ( salaryIncome . PreviousAmount * _taxParameter . MaxInvestPercent ) / 100 ) ;
else
investmentCanBeShown = ( ( annualIncome . PreviousAmount * _taxParameter . MaxInvestPercent ) / 100 ) ;
if ( _employee . Gender = = EnumGender . Male & & salaryIncome . PreviousAmount < = 400000 )
{
investmentCanBeShown = 0 ;
}
else if ( _employee . Gender = = EnumGender . Female & & salaryIncome . PreviousAmount < = 450000 )
{
investmentCanBeShown = 0 ;
}
if ( investmentCanBeShown > _taxParameter . MaxInvAmount ) investmentCanBeShown = _taxParameter . MaxInvAmount ;
double investAmount = investmentCanBeShown ;
if ( IsmaximumInvestment = = false )
{
IncomeTax ActualInvestment = this . CurrentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID
& & x . ItemGroup = = EnumIncomeTaxItemGroup . Investment_Actual
& & x . ItemID = = ( int ) EnumIncomeTaxItemGroup . Investment_Actual ) ;
if ( ActualInvestment = = null )
ActualInvestment = this . Add ( EnumIncomeTaxItemGroup . Investment_Actual , ( int ) EnumIncomeTaxItemGroup . Investment_Actual , string . Empty , 0 , 0 , EnumIncomeTaxSide . Tax_Info_Item ) ;
IncomeTax pfItem = this . CurrentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID
& & x . ItemGroup = = EnumIncomeTaxItemGroup . Company_Contri_PF
& & x . ItemID = = ( int ) EnumIncomeTaxItemGroup . Company_Contri_PF ) ;
investAmount = 0 ;
if ( pfItem ! = null )
investAmount = investAmount + ( pfItem . PreviousAmount * 2 ) ;
double nactualInvt = 0 ;
nactualInvt = empInvestments . Where ( x = > x . EmployeeID = = _employee . ID ) . Sum ( y = > y . Amount ) ;
investAmount = investAmount + nactualInvt ;
ActualInvestment . ThisMonthAmount = ActualInvestment . ProjectedAmount ;
ActualInvestment . PreviousAmount = nactualInvt ;
}
IncomeTax InvestmentAllowed = this . CurrentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID
& & x . ItemGroup = = EnumIncomeTaxItemGroup . Investment_Allowed
& & x . ItemID = = ( int ) EnumIncomeTaxItemGroup . Investment_Allowed ) ;
if ( InvestmentAllowed = = null ) InvestmentAllowed = this . Add ( EnumIncomeTaxItemGroup . Investment_Allowed ,
( int ) EnumIncomeTaxItemGroup . Investment_Allowed , string . Empty , 0 , 0 , EnumIncomeTaxSide . Tax_Info_Item ) ;
InvestmentAllowed . PreviousAmount = GlobalFunctions . Round ( investmentCanBeShown ) ;
InvestmentAllowed . ThisMonthAmount = InvestmentAllowed . ProjectedAmount ;
if ( investAmount > investmentCanBeShown )
investAmount = investmentCanBeShown ;
taxCredit = ( investAmount * _taxParameter . MaxInvExempPercent ) / 100 ;
//if (annualIncome.PreviousAmount <= 1500000)
// taxCredit = investAmount * .15;
//else taxCredit = investAmount * .10;
IncomeTax InvestmentItem = this . CurrentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID
& & x . ItemGroup = = EnumIncomeTaxItemGroup . Tax_Credit_On_Investment
& & x . ItemID = = ( int ) EnumIncomeTaxItemGroup . Tax_Credit_On_Investment ) ;
if ( InvestmentItem = = null ) InvestmentItem = this . Add ( EnumIncomeTaxItemGroup . Tax_Credit_On_Investment , ( int ) EnumIncomeTaxItemGroup . Tax_Credit_On_Investment , string . Empty , 0 , 0 , EnumIncomeTaxSide . Dec_GrossTax ) ;
InvestmentItem . ThisMonthAmount = InvestmentItem . ProjectedAmount ;
InvestmentItem . PreviousAmount = GlobalFunctions . Round ( taxCredit ) ;
}
#endregion
#region Calculate Gross Tax
IncomeTax GrossTax = this . CurrentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID
& & x . ItemGroup = = EnumIncomeTaxItemGroup . Gross_Tax
& & x . ItemID = = ( int ) EnumIncomeTaxItemGroup . Gross_Tax ) ;
if ( GrossTax = = null ) GrossTax = this . Add ( EnumIncomeTaxItemGroup . Gross_Tax ,
( int ) EnumIncomeTaxItemGroup . Gross_Tax , string . Empty , 0 , 0 , EnumIncomeTaxSide . Tax_fixed_Item ) ;
GrossTax . ThisMonthAmount = GrossTax . ProjectedAmount ;
GrossTax . PreviousAmount = this . GetTaxAmount ( annualIncome . PreviousAmount ) ;
#endregion
#region Calculate net Tax
IncomeTax NetTax = this . CurrentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID
& & x . ItemGroup = = EnumIncomeTaxItemGroup . Net_Payable
& & x . ItemID = = ( int ) EnumIncomeTaxItemGroup . Net_Payable ) ;
if ( NetTax = = null ) NetTax = this . Add ( EnumIncomeTaxItemGroup . Net_Payable ,
( int ) EnumIncomeTaxItemGroup . Net_Payable , string . Empty , 0 , 0 , EnumIncomeTaxSide . Tax_fixed_Item ) ;
NetTax . ThisMonthAmount = NetTax . ProjectedAmount ;
NetTax . PreviousAmount = GrossTax . PreviousAmount -
( this . CurrentYearTax . Where ( x = > x . ItemGroup = = EnumIncomeTaxItemGroup . Tax_Gross_Rebate ) . Sum ( x = > x . ProjectedAmount )
+ taxCredit ) ;
if ( GrossTax . PreviousAmount > 0 & & NetTax . PreviousAmount < _taxParameter . MinTaxAmount )
{
NetTax . PreviousAmount = _taxParameter . MinTaxAmount ;
}
else if ( GrossTax . PreviousAmount < = 0 )
{
NetTax . PreviousAmount = 0 ;
}
#endregion
IncomeTax taxdeducted = this . CurrentYearTax . FirstOrDefault ( x = > x . EmployeeID = = _employee . ID
& & x . ItemGroup = = EnumIncomeTaxItemGroup . Tax_Deducted
& & x . ItemID = = ( int ) EnumIncomeTaxItemGroup . Tax_Deducted ) ;
if ( taxdeducted = = null ) taxdeducted = this . Add ( EnumIncomeTaxItemGroup . Tax_Deducted ,
( int ) EnumIncomeTaxItemGroup . Tax_Deducted , string . Empty , 0 , 0 , EnumIncomeTaxSide . Tax_fixed_Item ) ;
taxdeducted . ThisMonthAmount = taxdeducted . PreviousAmount + taxdeducted . ThisMonthAmount + taxdeducted . ProjectedAmount ;
double taxdeductedamount = this . GetConvertedAmount ( EnumIncomeTaxItemGroup . Tax_Deducted , ( int ) EnumIncomeTaxItemGroup . Tax_Deducted , taxdeducted . Description , taxMerges ,
salareis , bonuspaments , EnumSalaryItemCode . Inc_Tax_Deduction ) ;
taxdeductedamount = taxdeductedamount + bonuspaments . Where ( x = > x . EmployeeID = = _employee . ID ) . Sum ( x = > x . ChangeTaxAmount ) ;
taxdeducted . PreviousAmount = taxdeductedamount ;
foreach ( IncomeTax ot in this . CurrentYearTax )
{
ot . EmployeeID = _employee . ID ;
ot . TaxParameterID = nTaxParamterID ;
empTaxCertificates . Add ( ot ) ;
}
}
}
catch ( Exception ex )
{
throw new ServiceException ( ex . Message ) ;
}
this . PaidBonues = bonuspaments ;
return empTaxCertificates ;
}
public List < IncomeTax > compareIncome ( int payrolltypeid , List < Employee > emps ,
int nTaxParamterID , bool liveEmpInYear , bool doconMiddleofYear )
{
List < SalaryMonthly > salareis = null ;
List < BonusProcess . BonusProcessDetail > bonuspaments = null ;
List < IncomeTax > empTaxCertificates = new List < IncomeTax > ( ) ;
List < IncomeTax > oTaxYearly = null ;
2026-11-30 10:14:40 +06:00
string inSQL = "" ;
2026-11-03 13:06:00 +06:00
List < ITEmpHead > assignedHeads = new ITEmpHeadService ( ) . GetWithTaxParam ( nTaxParamterID ) ;
PayrollType ptype = new PayrollTypeService ( ) . Get ( payrolltypeid ) ;
List < EmployeeTaxInvestment > empInvestments = new EmployeeTaxInvestmentService ( ) . GetAllUsersInfo ( nTaxParamterID ) ;
this . _processItems = new ProcessItemService ( ) . Get ( ) ;
this . payrolltype = ptype ;
try
{
_taxParameter = new TaxParameterService ( ) . Get ( nTaxParamterID ) ;
if ( emps ! = null )
{
inSQL = Employee . getEmpID ( emps ) ;
if ( ptype . TaxParamID = = nTaxParamterID )
oTaxYearly = new IncomeTaxService ( ) . Get ( EnumIncomeTaxDataFrom . ProcessTempData , inSQL , payrolltypeid , null ) ;
else
oTaxYearly = new IncomeTaxService ( ) . GetPrvYear ( nTaxParamterID , inSQL , payrolltypeid ) ;
salareis = new SalaryMonthlyService ( ) . Get ( inSQL , _taxParameter . FiscalyearDatefrom , _taxParameter . FiscalyearDateTo , payrolltypeid ) ;
bonuspaments = new BonusProcessService ( ) . GetBonusDetailsByEmps ( inSQL , _taxParameter . FiscalyearDatefrom , _taxParameter . FiscalyearDateTo , payrolltypeid ) ;
}
else
{
emps = new EmployeeService ( ) . GetAllEmps ( payrolltypeid ) ;
inSQL = Employee . getEmpID ( emps ) ;
if ( ptype . TaxParamID = = nTaxParamterID )
oTaxYearly = new IncomeTaxService ( ) . Get ( EnumIncomeTaxDataFrom . ProcessTempData , payrolltypeid ) ;
else
2026-11-30 10:14:40 +06:00
oTaxYearly = new IncomeTaxService ( ) . GetPrvYear ( nTaxParamterID , payrolltypeid ) ;
2026-11-03 13:06:00 +06:00
salareis = new SalaryMonthlyService ( ) . GetByDateRange ( _taxParameter . FiscalyearDatefrom , _taxParameter . FiscalyearDateTo , payrolltypeid ) ;
bonuspaments = new BonusProcessService ( ) . GetBonusDetailsByEmps ( inSQL , _taxParameter . FiscalyearDatefrom , _taxParameter . FiscalyearDateTo , payrolltypeid ) ;
}
if ( salareis ! = null & & salareis . Count > 0 )
{
var salaryEmpIds = new HashSet < int > ( salareis . Select ( s = > s . EmployeeID ) ) ;
emps = emps . Where ( e = > salaryEmpIds . Contains ( e . ID ) ) . ToList ( ) ;
List < Employee > filteremps = new List < Employee > ( ) ;
if ( doconMiddleofYear = = true )
{
2026-11-30 10:14:40 +06:00
var disconemps = emps . Where ( e = > ( e . EndOfContractDate < = _taxParameter . FiscalyearDateTo ) & &
2026-11-03 13:06:00 +06:00
( e . EndOfContractDate > = _taxParameter . FiscalyearDatefrom ) ) . ToList ( ) ;
filteremps . AddRange ( disconemps ) ;
}
if ( liveEmpInYear = = true )
{
// Remove discontinued employees from emps using LINQ
2026-11-30 10:14:40 +06:00
var liveemps = emps . Where ( e = > ! ( e . EndOfContractDate < = _taxParameter . FiscalyearDateTo & & e . EndOfContractDate > = _taxParameter . FiscalyearDatefrom ) ) . ToList ( ) ;
2026-11-03 13:06:00 +06:00
filteremps . AddRange ( liveemps ) ;
}
emps = filteremps ;
}
List < TaxMergeMaster > taxMerges = new TaxMergeMasterService ( ) . GetbyTaxParameter ( _taxParameter . ID , payrolltypeid ) ;
var taxdeductedItem = taxMerges . FirstOrDefault ( x = > x . ItemGroup = = EnumIncomeTaxItemGroup . Tax_Deducted ) ;
2026-11-30 10:14:40 +06:00
if ( taxdeductedItem = = null )
2026-11-03 13:06:00 +06:00
{
TaxMergeMaster taxMerge = new TaxMergeMaster
{
ItemGroup = EnumIncomeTaxItemGroup . Tax_Deducted ,
TaxParameterID = _taxParameter . ID ,
PayrollTypeID = payrolltypeid ,
ItemID = ( int ) EnumIncomeTaxItemGroup . Tax_Deducted ,
Description = "Tax Deducted" ,
Type = EnumTaxMergeType . Deduction ,
Position = 0
} ;
2026-11-30 10:14:40 +06:00
taxMerges . Add ( taxMerge ) ;
2026-11-03 13:06:00 +06:00
TaxMergeMaster . TaxMergeDetail taxMergeDetail = new TaxMergeMaster . TaxMergeDetail
{
ItemGroup = EnumIncomeTaxItemGroup . Tax_Deducted ,
TaxParameterID = _taxParameter . ID ,
PayrollTypeID = payrolltypeid ,
ItemID = ( int ) EnumSalaryItemCode . Inc_Tax_Deduction ,
Description = "Tax Deducted" ,
Type = EnumTaxMergeType . Deduction
} ;
taxMerge . TaxMergeDetails = new List < TaxMergeMaster . TaxMergeDetail > ( ) ;
taxMerge . TaxMergeDetails . Add ( taxMergeDetail ) ;
}
foreach ( Employee emp in emps )
{
_employee = emp ; //employees.FirstOrDefault(x => x.ID.Integer == nCurrEmployeeid.Integer);
this . CurrentYearTax = oTaxYearly . FindAll ( x = > x . EmployeeID = = _employee . ID ) ;
2026-11-30 10:14:40 +06:00
2026-11-03 13:06:00 +06:00
#region Calculate From Salary & Bonus
double basicSalary = 0 ;
foreach ( IncomeTax item in this . CurrentYearTax )
{
if ( item . ItemGroup ! = EnumIncomeTaxItemGroup . Tax_Deducted )
{
if ( item . Side ! = EnumIncomeTaxSide . Inc_SalaryIncome & &
item . Side ! = EnumIncomeTaxSide . Inc_AnnualIncome )
continue ;
}
if ( ptype . TaxParamID = = nTaxParamterID )
{
item . ProjectedAmount = 0 ;
item . ThisMonthAmount = item . PreviousAmount + item . ThisMonthAmount ;
item . PreviousAmount = 0 ;
}
else
{
item . ProjectedAmount = 0 ;
item . ThisMonthAmount = item . TotalAmount ;
item . PreviousAmount = 0 ;
}
double reAmount = 0 ;
switch ( item . ItemGroup )
{
case EnumIncomeTaxItemGroup . None :
break ;
case EnumIncomeTaxItemGroup . Basic_Salary :
reAmount = this . GetConvertedAmount ( EnumIncomeTaxItemGroup . Basic_Salary , item . ItemID , item . Description , taxMerges , salareis , bonuspaments , EnumSalaryItemCode . Basic_Salary ) ;
basicSalary = reAmount + item . ProjectedAmount ;
break ;
case EnumIncomeTaxItemGroup . House_Rent_Allowance :
reAmount = this . GetConvertedAmount ( EnumIncomeTaxItemGroup . House_Rent_Allowance , item . ItemID , item . Description , taxMerges ,
salareis , bonuspaments , null ) ;
break ;
case EnumIncomeTaxItemGroup . Conveyance_Allowance :
reAmount = this . GetConvertedAmount ( EnumIncomeTaxItemGroup . Conveyance_Allowance , item . ItemID , item . Description , taxMerges ,
salareis , bonuspaments , null ) ;
break ;
case EnumIncomeTaxItemGroup . Medical_Allowance :
reAmount = this . GetConvertedAmount ( EnumIncomeTaxItemGroup . Medical_Allowance , item . ItemID , item . Description , taxMerges ,
salareis , bonuspaments , null ) ;
break ;
case EnumIncomeTaxItemGroup . Company_Contri_PF :
reAmount = this . GetConvertedAmount ( EnumIncomeTaxItemGroup . Company_Contri_PF , item . ItemID , item . Description , taxMerges ,
salareis , bonuspaments , EnumSalaryItemCode . PF_Contribution ) ;
item . Description = "PF" ;
break ;
case EnumIncomeTaxItemGroup . Bonus :
reAmount = this . GetConvertedAmount ( EnumIncomeTaxItemGroup . Bonus , item . ItemID , item . Description , taxMerges ,
salareis , bonuspaments , null ) ;
break ;
case EnumIncomeTaxItemGroup . Earned_Leave :
break ;
case EnumIncomeTaxItemGroup . Other_Cash_Benefits :
reAmount = this . GetConvertedAmount ( EnumIncomeTaxItemGroup . Other_Cash_Benefits , item . ItemID , item . Description , taxMerges ,
salareis , bonuspaments , null ) ;
break ;
case EnumIncomeTaxItemGroup . Tax_Deducted :
reAmount = this . GetConvertedAmount ( EnumIncomeTaxItemGroup . Tax_Deducted , item . ItemID , item . Description , taxMerges ,
salareis , bonuspaments , EnumSalaryItemCode . Inc_Tax_Deduction ) ;
reAmount = reAmount + bonuspaments . Where ( x = > x . EmployeeID = = _employee . ID ) . Sum ( x = > x . ChangeTaxAmount ) ;
break ;
case EnumIncomeTaxItemGroup . LFA_Allowance :
reAmount = this . GetConvertedAmount ( EnumIncomeTaxItemGroup . LFA_Allowance , item . ItemID , item . Description , taxMerges ,
salareis , bonuspaments , null ) ;
break ;
case EnumIncomeTaxItemGroup . WPPF_Allowance :
reAmount = this . GetConvertedAmount ( EnumIncomeTaxItemGroup . WPPF_Allowance , item . ItemID , item . Description , taxMerges ,
salareis , bonuspaments , null ) ;
break ;
case EnumIncomeTaxItemGroup . Other_Allowance :
reAmount = this . GetConvertedAmount ( EnumIncomeTaxItemGroup . Other_Allowance , item . ItemID , item . Description , taxMerges ,
salareis , bonuspaments , null ) ;
break ;
case EnumIncomeTaxItemGroup . TimeCard :
reAmount = this . GetConvertedAmount ( EnumIncomeTaxItemGroup . TimeCard , item . ItemID , item . Description , taxMerges ,
salareis , bonuspaments , null ) ;
break ;
case EnumIncomeTaxItemGroup . Cmp_Provided_car :
List < ITEmpHead > cars = assignedHeads . Where ( x = > x . EmployeeID = = _employee . ID & & x . HeadID = = EnumIncomeTaxHead . Car ) . ToList ( ) ;
foreach ( ITEmpHead car in cars )
{
reAmount = reAmount +
GlobalFunctions . DateDiff ( "m" , car . EndDate , car . StartDate )
* car . HouseRent ;
}
break ;
default :
break ;
}
item . PreviousAmount = item . PreviousAmount + reAmount ;
}
#endregion
foreach ( IncomeTax ot in this . CurrentYearTax )
{
if ( ot . ItemGroup ! = EnumIncomeTaxItemGroup . Tax_Deducted )
{
if ( ot . Side ! = EnumIncomeTaxSide . Inc_SalaryIncome & &
ot . Side ! = EnumIncomeTaxSide . Inc_AnnualIncome )
continue ;
}
if ( ot . PreviousAmount = = 0 & & ot . ThisMonthAmount = = 0 ) continue ;
ot . PreviousAmount = GlobalFunctions . Round ( ot . PreviousAmount ) ;
ot . ThisMonthAmount = GlobalFunctions . Round ( ot . ThisMonthAmount ) ;
ot . EmployeeID = _employee . ID ;
ot . TaxParameterID = nTaxParamterID ;
empTaxCertificates . Add ( ot ) ;
}
}
}
catch ( Exception ex )
{
throw new ServiceException ( ex . Message ) ;
}
this . PaidBonues = bonuspaments ;
return empTaxCertificates ;
}
public List < IncomeTax > MaternityLeaveCalculate ( List < TaxRawItem > rawItems , CurrentUser currentUser , ref double ntaxAmount )
{
try
{
_isActualInvestment = true ;
this . _onceoffAmount = rawItems [ 0 ] . Amount ;
IncomeTax oIncomeTax = new IncomeTax ( ) ;
EnumIncomeTaxDataFrom datafrom = new IncomeTaxService ( ) . GetEnumForSalaryIT ( _employee . ID ) ;
if ( datafrom = = EnumIncomeTaxDataFrom . SalaryITTempData )
{
throw new ServiceException ( "Current month salary is processed and not yet finalized. Tax calculation "
+ " is not allowed middle of this process. You have to Undo or finalize the salary to calculate tax." ) ;
}
this . CurrentYearTax = new List < IncomeTax > ( ) ;
this . CurrentYearTax = new IncomeTaxService ( ) . Get ( _employee . ID , EnumIncomeTaxDataFrom . ProcessTempData ) ;
this . CalcualteprojectMonth ( ) ;
_projectedMonth = _projectedMonth - ( double ) 2 ;
if ( ( _projectedMonth ) < 0 ) _projectedMonth = 0 ;
foreach ( IncomeTax item in this . CurrentYearTax )
{
if ( ( item . Side = = EnumIncomeTaxSide . Inc_SalaryIncome | | item . Side = = EnumIncomeTaxSide . Inc_AnnualIncome )
& & item . ThisMonthAmount > 0 & & item . ProjectedAmount > 0 )
{
item . ProjectedAmount = item . ThisMonthAmount * _projectedMonth ;
}
}
this . UpdateRawItems ( rawItems , EnumSide . Add ) ;
this . CmpProvidedTransport ( currentUser ) ;
this . CalculateExamtion ( ) ;
this . CalculateBonusProjection ( ) ;
this . CalculateCPF ( ) ;
this . CalculateTotalIncome ( ) ;
this . CalculateInvestment ( ) ;
this . CalculateGrossTax ( ) ;
this . CalculateNetPayable ( ) ;
//ntaxAmount = this.CalculateDecutedAmount();
//double totalAmount = 0;
//IncomeTax netPayable = IncomeTax.Get(this.CurrentYearTax, _employee.ID,
// EnumIncomeTaxItemGroup.Net_Payable, (int)EnumIncomeTaxItemGroup.Net_Payable);
//if (netPayable != null)
// totalAmount = netPayable.TotalAmount;
//this.CalculateNetPayable();
//netPayable = IncomeTax.Get(this.CurrentYearTax, _employee.ID,
// EnumIncomeTaxItemGroup.Net_Payable, (int)EnumIncomeTaxItemGroup.Net_Payable);
//if (netPayable != null)
// ntaxAmount = netPayable.TotalAmount - totalAmount;
//// if the amount is equal to yearly netpayable, the amount should be dsitributed next of the projected month
//// following if logic is required while employee taxable for this bonus amount
//if (ntaxAmount == netPayable.TotalAmount && netPayable.TotalAmount == _taxParameter.MinTaxAmount && _projectedMonth > 0)
// ntaxAmount = ntaxAmount / _projectedMonth;
////this.CalculateNetPayable();
double netPayable = new IncomeTaxService ( ) . Get ( this . CurrentYearTax , _employee . ID ,
EnumIncomeTaxItemGroup . Net_Payable , ( int ) EnumIncomeTaxItemGroup . Net_Payable ) . TotalAmount ;
double annualIncome = this . GetAnnualIncome ( ) ;
double grossTax = new IncomeTaxService ( ) . Get ( this . CurrentYearTax , _employee . ID ,
EnumIncomeTaxItemGroup . Gross_Tax , ( int ) EnumIncomeTaxItemGroup . Gross_Tax ) . TotalAmount ;
if ( _onceoffAmount > 0 )
{
ntaxAmount = grossTax - this . GetTaxAmount ( annualIncome - _onceoffAmount ) ;
ntaxAmount = ntaxAmount - CalculateOnceOfInvestmentAmt ( annualIncome - _onceoffAmount ) ;
}
if ( ntaxAmount < 0 )
ntaxAmount = 0 ;
IncomeTax TaxDeductitem = new IncomeTaxService ( ) . Get ( this . CurrentYearTax , _employee . ID , EnumIncomeTaxItemGroup . Tax_Deducted ,
( int ) EnumIncomeTaxItemGroup . Tax_Deducted ) ;
if ( TaxDeductitem ! = null )
TaxDeductitem . ThisMonthAmount = TaxDeductitem . ThisMonthAmount + ntaxAmount ;
return this . CurrentYearTax ;
}
catch ( ServiceException ex )
{
throw new ServiceException ( ex . Message ) ;
}
catch ( Exception ex )
{
throw new ServiceException ( ex . Message ) ;
}
}
protected void CmpProvidedTransport ( CurrentUser currentUser )
{
try
{
DateTime month = ( DateTime ) currentUser . NextPayProcessDate ;
List < ITEmpHead > assignedHeads = new ITEmpHeadService ( ) . GetWithTaxParam ( ( int ) currentUser . TaxParamID ) ;
if ( assignedHeads . Count = = 0 ) return ;
List < ITEmpHead > ItemsAll = new ITEmpHeadService ( ) . Get ( assignedHeads , _employee . ID ) ;
if ( ItemsAll = = null ) return ;
List < ITEmpHead > Items = ItemsAll . FindAll ( x = > x . HeadID = = EnumIncomeTaxHead . Car ) ;
if ( Items = = null ) return ;
DateTime fromDate = GlobalFunctions . FirstDateOfMonth ( month ) ;
DateTime toDate = GlobalFunctions . LastDateOfMonth ( month ) ;
bool bvalid = false ;
double tempAmount = 0 ;
foreach ( ITEmpHead item in Items )
{
if ( item . HouseRent = = 0 ) continue ;
IncomeTax taxItem ;
bvalid = false ;
if ( item . StartDate < = fromDate | | item . EndDate > = fromDate ) bvalid = true ;
if ( item . StartDate < = toDate | | item . EndDate > = toDate ) bvalid = true ;
if ( item . StartDate > = fromDate ) { fromDate = item . StartDate ; bvalid = true ; }
if ( item . EndDate < = toDate ) { toDate = item . EndDate ; bvalid = true ; }
if ( bvalid = = false ) continue ;
#region Calculate Car calculation
if ( item . HeadID = = EnumIncomeTaxHead . Car )
{
taxItem = new IncomeTaxService ( ) . Get ( CurrentYearTax , _employee . ID ,
EnumIncomeTaxItemGroup . Cmp_Provided_car ,
( int ) EnumIncomeTaxItemGroup . Cmp_Provided_car ) ;
if ( taxItem = = null ) taxItem = this . Add ( EnumIncomeTaxItemGroup . Cmp_Provided_car ,
( int ) EnumIncomeTaxItemGroup . Cmp_Provided_car , "Company provided car" , 0 , 0 , EnumIncomeTaxSide . Inc_SalaryIncome ) ;
taxItem . PreviousAmount = item . HouseRent * GlobalFunctions . GetFraction ( item . StartDate , GlobalFunctions . LastDateOfMonth ( month . AddMonths ( - 1 ) ) ) ;
taxItem . ThisMonthAmount = item . HouseRent ;
if ( item . StartDate . Month = = month . Month & & item . StartDate . Year = = month . Year )
{
int nDays = 30 - item . StartDate . Day + 1 ;
taxItem . ThisMonthAmount = ( item . HouseRent / 30 ) * nDays ;
}
else if ( item . EndDate . Month = = month . Month & & item . EndDate . Year = = month . Year )
{
int nDays = ( item . EndDate - GlobalFunctions . FirstDateOfMonth ( month ) ) . Days + 1 ;
taxItem . ThisMonthAmount = ( item . HouseRent / 30 ) * nDays ;
}
else
{
taxItem . ThisMonthAmount = item . HouseRent * GlobalFunctions . GetFraction ( fromDate , GlobalFunctions . LastDateOfMonth ( month ) ) ;
}
toDate = item . EndDate ;
if ( item . EndDate > = _taxParameter . FiscalyearDateTo )
{
toDate = _taxParameter . FiscalyearDateTo ;
}
if ( _employee . EndOfContractDate ! = null & & _employee . EndOfContractDate < toDate )
{
toDate = Convert . ToDateTime ( _employee . EndOfContractDate ) ;
}
if ( toDate = = GlobalFunctions . LastDateOfMonth ( toDate ) )
{
taxItem . ProjectedAmount = ( item . HouseRent * Math . Abs ( ( double ) ( ( ( toDate . Year - month . Year ) * 12 ) + toDate . Month - month . Month ) ) ) ;
}
else
{
taxItem . ProjectedAmount = ( item . HouseRent * GlobalFunctions . GetFraction ( GlobalFunctions . LastDateOfMonth ( month ) . AddDays ( 1 ) , toDate ) ) ;
}
taxItem . ThisMonthAmount = GlobalFunctions . Round ( taxItem . ThisMonthAmount ) ;
taxItem . ProjectedAmount = GlobalFunctions . Round ( taxItem . ProjectedAmount ) ;
}
#endregion Calculate Car calculation
}
}
catch ( ServiceException ex )
{
throw new ServiceException ( ex . Message ) ;
}
catch ( Exception ex )
{
throw new ServiceException ( ex . Message ) ;
}
}
}
public class TaxProcess
{
public void CalculateTax ( )
{
}
#region ISalaryTax Members
public void Calculate ( )
{
}
#endregion
}
}