683 lines
31 KiB
C#
683 lines
31 KiB
C#
|
|
|||
|
using Ease.Core.Model;
|
|||
|
|
|||
|
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Data;
|
|||
|
using HRM.BO;
|
|||
|
using System.Linq;
|
|||
|
namespace HRM.DA
|
|||
|
{
|
|||
|
|
|||
|
|
|||
|
public class BonusCalculator
|
|||
|
{
|
|||
|
public BonusCalculator()
|
|||
|
{
|
|||
|
|
|||
|
}
|
|||
|
public List<SalaryProcessStatus> ErrorList { get; set; }
|
|||
|
public bool? bjoiningproporate = null;
|
|||
|
public PayrollType _payrolltype;
|
|||
|
List<BonusParameter> _parameters;
|
|||
|
//private void UpdateprocessStatus(string statusString)
|
|||
|
//{
|
|||
|
// if (ProcessStatus != null) ProcessStatus(statusString);
|
|||
|
//}
|
|||
|
//private void UpdateProgressStatus(EnumProcessStatus status)
|
|||
|
//{
|
|||
|
// if (ProgressStatus != null) ProgressStatus(status);
|
|||
|
//}
|
|||
|
|
|||
|
public void BCalculate(List<Employee> oEmployees,int BonusID,DateTime payDate)
|
|||
|
{
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
public double ConvertToDailyRate(double nBasic, DateTime dMonthDate)
|
|||
|
{
|
|||
|
double amount = 0;
|
|||
|
amount = nBasic / Convert.ToDouble(DateTime.DaysInMonth(dMonthDate.Year, dMonthDate.Month));
|
|||
|
return amount;
|
|||
|
}
|
|||
|
|
|||
|
public double GeneralAmount(Employee oEmp, BonusParameter oBParameter, DateTime SalaryMonthDate)
|
|||
|
{
|
|||
|
double nTotalBonus = 0.0;
|
|||
|
nTotalBonus = oBParameter.FlatAmount + (oEmp.GrossSalary * oBParameter.NoOfGross) + (oEmp.BasicSalary * oBParameter.NoOfBasic) + (oEmp.GrossSalary * oBParameter.PercentOfGross / 100) + (oEmp.BasicSalary * oBParameter.NoOfEarnedBasic);
|
|||
|
// nTotalBonus = nTotalBonus + ConvertToDailyRate(oEmp.BasicSalary, SalaryMonthDate) * oBParameter.NoOfDays + ConvertToDailyRate(oEmp.GrossSalary, SalaryMonthDate) * oBParameter.GrossOfDays;
|
|||
|
return nTotalBonus;
|
|||
|
}
|
|||
|
|
|||
|
public double GeneralAmount(Employee oEmp,BonusParameter oBParameter, double basicSalary, double GrossSalary )
|
|||
|
{
|
|||
|
double nTotalBonus = 0.0;
|
|||
|
nTotalBonus = oBParameter.FlatAmount +(GrossSalary *oBParameter.NoOfGross) + (basicSalary * oBParameter.NoOfBasic) + (GrossSalary * oBParameter.PercentOfGross / 100) + (basicSalary * oBParameter.NoOfEarnedBasic);
|
|||
|
// nTotalBonus = nTotalBonus + ConvertToDailyRate(oEmp.BasicSalary, SalaryMonthDate) * oBParameter.NoOfDays + ConvertToDailyRate(oEmp.GrossSalary, SalaryMonthDate) * oBParameter.GrossOfDays;
|
|||
|
return nTotalBonus;
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// /// </summary>
|
|||
|
/// <param name="oBonusPSalaryItem"></param>
|
|||
|
/// <param name="oEmp"></param>
|
|||
|
/// <param name="dSalaryMonth"></param>
|
|||
|
/// <returns></returns>
|
|||
|
|
|||
|
public double CalculateOverTheYearAmount(BonusParameter oBonusParameter, Employee oEmp,DateTime dPayDate,double TotalBonusAmount)
|
|||
|
{
|
|||
|
double BonusOvertheAmount = 0.0;
|
|||
|
DateTime JoiningDate = oEmp.JoiningDate;
|
|||
|
DateTime CompareDate=DateTime.Now;
|
|||
|
DateTime FirstDateofYear= Ease.Core.Utility.Global.DateFunctions.FirstDateOfYear(dPayDate);
|
|||
|
DateTime LastDateofYear = Ease.Core.Utility.Global.DateFunctions.LastDateOfYear(dPayDate);
|
|||
|
if(oEmp.JoiningDate<=FirstDateofYear)
|
|||
|
{
|
|||
|
CompareDate = FirstDateofYear;
|
|||
|
}
|
|||
|
|
|||
|
if(CompareDate<=FirstDateofYear)
|
|||
|
{
|
|||
|
BonusOvertheAmount = TotalBonusAmount;
|
|||
|
}
|
|||
|
else if(JoiningDate>FirstDateofYear)
|
|||
|
{
|
|||
|
int nDays = (LastDateofYear - JoiningDate).Days + 1;
|
|||
|
BonusOvertheAmount = (TotalBonusAmount * nDays) / 365;
|
|||
|
}
|
|||
|
|
|||
|
return BonusOvertheAmount;
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
public double CaculatedProratedCutOffAmount(BonusParameter oBonusParameter, Employee oEmp, double TotalBonusAmount, DateTime dCuttOffDate)
|
|||
|
{
|
|||
|
double BonusProAmount = 0.0;
|
|||
|
DateTime JoiningDate = oEmp.JoiningDate;
|
|||
|
DateTime CompareDate = DateTime.Now;
|
|||
|
DateTime FirstDateofYear = Ease.Core.Utility.Global.DateFunctions.FirstDateOfYear(dCuttOffDate);
|
|||
|
DateTime LastDateofYear = Ease.Core.Utility.Global.DateFunctions.LastDateOfYear(dCuttOffDate);
|
|||
|
|
|||
|
if (JoiningDate <= FirstDateofYear)
|
|||
|
{
|
|||
|
CompareDate = FirstDateofYear;
|
|||
|
}
|
|||
|
else if (JoiningDate > FirstDateofYear)
|
|||
|
{
|
|||
|
CompareDate = JoiningDate;
|
|||
|
}
|
|||
|
BonusProAmount = TotalBonusAmount * ((dCuttOffDate - CompareDate).Days + 1) / ((dCuttOffDate - FirstDateofYear).Days + 1);
|
|||
|
TimeSpan dd = dCuttOffDate.AddDays(1)-JoiningDate ;
|
|||
|
if (dd.Days >= 365)
|
|||
|
{
|
|||
|
BonusProAmount = TotalBonusAmount;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
BonusProAmount = TotalBonusAmount / 365 * dd.Days;
|
|||
|
}
|
|||
|
|
|||
|
return BonusProAmount;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
public double CaculatedProratedAmount(BonusParameter oBonusParameter, Employee oEmp, double TotalBonusAmount, DateTime dCuttOffDate)
|
|||
|
{
|
|||
|
double BonusProAmount = 0.0;
|
|||
|
DateTime JoiningDate = oEmp.JoiningDate;
|
|||
|
DateTime CompareDate = DateTime.Now;
|
|||
|
DateTime FirstDateofYear = Ease.Core.Utility.Global.DateFunctions.FirstDateOfYear(dCuttOffDate);
|
|||
|
DateTime LastDateofYear = Ease.Core.Utility.Global.DateFunctions.LastDateOfYear(dCuttOffDate);
|
|||
|
if (oEmp.JoiningDate <= FirstDateofYear)
|
|||
|
{
|
|||
|
CompareDate = FirstDateofYear;
|
|||
|
}
|
|||
|
|
|||
|
if (CompareDate <= FirstDateofYear)
|
|||
|
{
|
|||
|
BonusProAmount = TotalBonusAmount;
|
|||
|
}
|
|||
|
else if (JoiningDate > FirstDateofYear)
|
|||
|
{
|
|||
|
int nDays = (LastDateofYear - JoiningDate).Days + 1;
|
|||
|
BonusProAmount = (TotalBonusAmount * nDays) / 365;
|
|||
|
}
|
|||
|
|
|||
|
return BonusProAmount;
|
|||
|
}
|
|||
|
|
|||
|
public double CaculatedServiceLengthAmount(BonusParameter oBonusParameter,Employee oEmp,double TotalBonusAmount,DateTime dCuttOffDate)
|
|||
|
{
|
|||
|
DateTime toDate = DateTime.Now;
|
|||
|
DateTime joiningDate = oEmp.JoiningDate;
|
|||
|
double BonusSLengthAmount = 0.0;
|
|||
|
int ServiceLength = 100;
|
|||
|
int Counter = 0;
|
|||
|
// if paramter applicable cutt of date, other wise deduct from last date of year.
|
|||
|
Counter = (dCuttOffDate - joiningDate).Days + 1;
|
|||
|
if (oBonusParameter.BonusServiceLengths != null)
|
|||
|
{
|
|||
|
oBonusParameter.BonusServiceLengths = (from num in oBonusParameter.BonusServiceLengths
|
|||
|
orderby num.EntitlePercent ascending
|
|||
|
select num).ToList();
|
|||
|
for (int i = oBonusParameter.BonusServiceLengths.Count; i >=1 ; i--)
|
|||
|
{
|
|||
|
// ServiceLength = oBonusParameter.BonusServiceLengths[i-1].LengthOfService;
|
|||
|
if (oBonusParameter.BonusServiceLengths[i-1].LengthOfService < Counter)
|
|||
|
{
|
|||
|
ServiceLength = oBonusParameter.BonusServiceLengths[i - 1].EntitlePercent;
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
BonusSLengthAmount = (TotalBonusAmount * ServiceLength)/100;
|
|||
|
}
|
|||
|
return BonusSLengthAmount;
|
|||
|
}
|
|||
|
|
|||
|
//public double CalculationSlabOnBasic(BonusParameter oBonusParameter, Employee oEmp, double basicSalary)
|
|||
|
//{
|
|||
|
// double BonusDearnessAmount=0.0;
|
|||
|
|
|||
|
// if (oBonusParameter.BonusSlabs != null)
|
|||
|
// {
|
|||
|
// for (int i = oBonusParameter.BonusSlabs.Count; i >= 1; i--)
|
|||
|
// {
|
|||
|
// if (oBonusParameter.BonusSlabs[i - 1].SlabAmount < basicSalary)
|
|||
|
// {
|
|||
|
|
|||
|
// if(oBonusParameter.BonusSlabs[i - 1].AmountType==EnumSlabAmountType.ActualBasic)
|
|||
|
// {
|
|||
|
// BonusDearnessAmount = basicSalary;
|
|||
|
// break;
|
|||
|
// }
|
|||
|
// else if (oBonusParameter.BonusSlabs[i - 1].AmountType == EnumSlabAmountType.FlatAmount)
|
|||
|
// {
|
|||
|
// BonusDearnessAmount = oBonusParameter.BonusSlabs[i - 1].Amount;
|
|||
|
// break;
|
|||
|
// }
|
|||
|
// }
|
|||
|
// }
|
|||
|
// }
|
|||
|
// return BonusDearnessAmount;
|
|||
|
//}
|
|||
|
|
|||
|
////public double CalculationCasualBonusAmount(BonusParameter oBonusParameter, Employee oEmp, double basicSalary)
|
|||
|
////{
|
|||
|
//// double BonusCasualAmount = 0.0;
|
|||
|
//// List<EmpLeaveStatus> oEmpLStatuses = EmpLeaveStatus.EmpCurrentYearStatus(oEmp);
|
|||
|
|
|||
|
//// double nCLeave = 0;
|
|||
|
//// //foreach(EmpLeaveStatus oEmpLStatus in oEmpLStatuses)
|
|||
|
//// //{
|
|||
|
//// // if(oEmpLStatus.LeaveId==5)
|
|||
|
//// // {
|
|||
|
//// // nCLeave = oEmpLStatus.LeaveAvailed;
|
|||
|
//// // }
|
|||
|
//// //}
|
|||
|
//// if (oBonusParameter.BonusSlabs != null)
|
|||
|
//// {
|
|||
|
//// for (int i = oBonusParameter.BonusSlabs.Count; i >= 1; i--)
|
|||
|
//// {
|
|||
|
//// if (oBonusParameter.BonusSlabs[i - 1].SlabAmount < nCLeave)
|
|||
|
//// {
|
|||
|
//// if (oBonusParameter.BonusSlabs[i - 1].AmountType == EnumSlabAmountType.Percentage)
|
|||
|
//// {
|
|||
|
//// BonusCasualAmount = basicSalary * (oBonusParameter.BonusSlabs[i - 1].Amount / 100);//oBonusParameter.BonusSlabs[i - 1].Amount;
|
|||
|
//// break;
|
|||
|
//// }
|
|||
|
//// }
|
|||
|
//// }
|
|||
|
//// }
|
|||
|
//// return BonusCasualAmount;
|
|||
|
////}
|
|||
|
////public double CaculatedBonusAdjustAmount(BonusParameter.BonusParamAdjustItem oBonusPAdjustAmount)
|
|||
|
////{
|
|||
|
//// double BonusAdjustAmount = 0.0;
|
|||
|
//// if (oBonusParameter.BonusParamAdjustItems != null)
|
|||
|
//// {
|
|||
|
//// foreach (BonusParameter.BonusParamAdjustItem oBAdjustAmount in oBonusParameter.BonusParamAdjustItems)
|
|||
|
//// {
|
|||
|
//// BonusAdjustAmount += oBAdjustAmount.Amount;
|
|||
|
//// }
|
|||
|
//// }
|
|||
|
//// return BonusAdjustAmount;
|
|||
|
////}
|
|||
|
|
|||
|
public double CalcluateBonus(BonusParameter param, Employee oemployee,
|
|||
|
double basicSalary, double GrossSalary, DateTime dCuttOfDate)
|
|||
|
{
|
|||
|
|
|||
|
double BonusGeneralAmount=0;
|
|||
|
double TotalAmount=0;
|
|||
|
|
|||
|
BonusGeneralAmount = this.GeneralAmount(oemployee, param, basicSalary, GrossSalary);
|
|||
|
TotalAmount = BonusGeneralAmount;
|
|||
|
//#####
|
|||
|
//if (bjoiningproporate ==null)
|
|||
|
// bjoiningproporate =new SystemConfigarationService().GetconfigBooleanValue(EnumConfigurationType.Logic, "bonus", "joiningprorate");
|
|||
|
|
|||
|
|
|||
|
|
|||
|
if (param.BonusServiceLengths != null && param.BonusServiceLengths.Count > 0)
|
|||
|
TotalAmount = this.CaculatedServiceLengthAmount(param, oemployee, TotalAmount, dCuttOfDate);
|
|||
|
else if (param.IsProrated && param.IsOverYearCalculation)
|
|||
|
TotalAmount = this.CaculatedProratedCutOffAmount(param, oemployee, TotalAmount, dCuttOfDate);
|
|||
|
else if (param.IsProrated)
|
|||
|
TotalAmount = this.CaculatedProratedAmount(param, oemployee, TotalAmount, dCuttOfDate);
|
|||
|
|
|||
|
return TotalAmount;
|
|||
|
}
|
|||
|
|
|||
|
public double CalculateRemainingBonusAmount(BonusParameter param, Employee oemployee,
|
|||
|
double basicSalary, double GrossSalary, DateTime dCuttOfDate, BonusProcess.BonusProcessDetail odetail)
|
|||
|
{
|
|||
|
if (odetail != null)
|
|||
|
{
|
|||
|
if (param.NoOfBasic > 0)
|
|||
|
{
|
|||
|
param.NoOfBasic = param.NoOfBasic - odetail.ChangeSalaryItemAmount; // here changetaxamount contain count
|
|||
|
}
|
|||
|
|
|||
|
if (param.NoOfGross > 0)
|
|||
|
{
|
|||
|
param.NoOfGross = param.NoOfGross - odetail.ChangeSalaryItemAmount; // here changetaxamount contain count
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
if((param.NoOfBasic + param.NoOfGross + param.FlatAmount) <=0) return 0;
|
|||
|
|
|||
|
double namount = 0;
|
|||
|
namount= CalcluateBonus(param, oemployee,
|
|||
|
basicSalary, GrossSalary, dCuttOfDate);
|
|||
|
if (odetail != null)
|
|||
|
{
|
|||
|
if (param.NoOfBasic > 0)
|
|||
|
{
|
|||
|
param.NoOfBasic = param.NoOfBasic + odetail.ChangeSalaryItemAmount; // here changetaxamount contain count
|
|||
|
}
|
|||
|
|
|||
|
if (param.NoOfGross > 0)
|
|||
|
{
|
|||
|
param.NoOfGross = param.NoOfGross + odetail.ChangeSalaryItemAmount; // here changetaxamount contain count
|
|||
|
}
|
|||
|
}
|
|||
|
return namount;
|
|||
|
}
|
|||
|
|
|||
|
public double CalcluateFestivalBonus(BonusParameter param, Employee oemployee,
|
|||
|
double basicSalary, double GrossSalary, DateTime dCuttOfDate)
|
|||
|
{
|
|||
|
double TotalAmount = 0;
|
|||
|
double basic = basicSalary;
|
|||
|
|
|||
|
|
|||
|
//DateDifferenceInYearsMonthDays dd = DateDifferenceInYearsMonthDays.CompareDates(dCuttOfDate, oemployee.JoiningDate);
|
|||
|
////int year = dCuttOfDate.Year - oemployee.JoiningDate.Year;
|
|||
|
//if (dd.Years >=1)
|
|||
|
//{
|
|||
|
// TotalAmount = basic;
|
|||
|
//}
|
|||
|
//else
|
|||
|
//{
|
|||
|
// TotalAmount = basic/365*dd.Days;
|
|||
|
//}
|
|||
|
|
|||
|
|
|||
|
return TotalAmount;
|
|||
|
}
|
|||
|
public BonusProcess CalCulate(int payrolltypeid, List<Employee> employees, int bonusid, DateTime dBasicMonth,
|
|||
|
DateTime dPayDate, DateTime dCuttOfDate, double CurrProcess, bool IsDisburseWithSalary, bool IsTaxProcess)
|
|||
|
{
|
|||
|
Bonus oBonus = new BonusService().Get(bonusid);
|
|||
|
bool CheckOvertheYearCal = new SystemConfigarationService().GetconfigBooleanValue(EnumConfigurationType.Logic, "bonus", "overtheyearcalculation");
|
|||
|
bool hmbonusCal = new SystemConfigarationService().GetconfigBooleanValue(EnumConfigurationType.Logic, "bonus", "hmbonuscalculation");
|
|||
|
|
|||
|
_payrolltype = new PayrollTypeService().Get(payrolltypeid);
|
|||
|
BonusProcess oProssBonus = new BonusProcess();
|
|||
|
oProssBonus.BonusProcessDetails = new List<BonusProcess.BonusProcessDetail>();
|
|||
|
double nBasicSalary = 0;
|
|||
|
double nGrossSalary = 0;
|
|||
|
|
|||
|
List<EmployeeGradeSalary> ogsAll = new EmployeeGradeSalaryService().GetBasicOnDate(GlobalFunctions.LastDateOfMonth(dBasicMonth));
|
|||
|
_parameters = new BonusParameterService().Get(EnumStatus.Regardless, payrolltypeid);
|
|||
|
foreach (Employee oEmp in employees)
|
|||
|
{
|
|||
|
|
|||
|
|
|||
|
double TotalAmount = 0;
|
|||
|
BonusParameter oBonusParm = new BonusParameterService().GetApplicableParameter(oEmp, (int)oEmp.GradeID, _parameters, oBonus.ID);
|
|||
|
|
|||
|
if (oBonusParm == null)
|
|||
|
throw new ServiceException("Parameter not found for the employee " + oEmp.Name + " (" + oEmp.EmployeeNo + ")");
|
|||
|
|
|||
|
|
|||
|
#region prepare bonusProcess
|
|||
|
oProssBonus.BonusID = oBonusParm.BonusID;
|
|||
|
oProssBonus.UsedProcess = CurrProcess;
|
|||
|
oProssBonus.BasicOnMonth = GlobalFunctions.LastDateOfMonth(dBasicMonth);
|
|||
|
oProssBonus.BonusMonth = _payrolltype.NextPayProcessDate;
|
|||
|
oProssBonus.DisburseDate = dPayDate;
|
|||
|
oProssBonus.IsDisburseWithSalary = IsDisburseWithSalary;
|
|||
|
oProssBonus.IsTaxProcess = IsTaxProcess;
|
|||
|
|
|||
|
EmployeeGradeSalary ogs = ogsAll.Find(delegate (EmployeeGradeSalary eg) { return eg.EmployeeID == oEmp.ID; });
|
|||
|
if (ogs == null)
|
|||
|
{
|
|||
|
nBasicSalary = oEmp.BasicSalary;
|
|||
|
nGrossSalary = oEmp.GrossSalary;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
nBasicSalary = ogs.BasicSalary;
|
|||
|
nGrossSalary = ogs.GrossSalary;
|
|||
|
}
|
|||
|
#endregion prepare bonusProcess
|
|||
|
BonusProcess.BonusProcessDetail oBPDetail = new BonusProcess.BonusProcessDetail();
|
|||
|
oBPDetail.BonusID = oBonusParm.BonusID;
|
|||
|
oBPDetail.EmployeeID = oEmp.ID;
|
|||
|
oBPDetail.BasicSalary = nBasicSalary;
|
|||
|
oBPDetail.GrossSalary = nGrossSalary;
|
|||
|
oBPDetail.BonusParam = oBonusParm;
|
|||
|
oBPDetail.BonusMonth = _payrolltype.NextPayProcessDate;
|
|||
|
oBPDetail.Employee = oEmp;
|
|||
|
|
|||
|
if (hmbonusCal == true)
|
|||
|
{
|
|||
|
oBPDetail.BonusAmount = this.CalculateHMBonus(oBonus, oProssBonus, oBPDetail, oBonusParm,
|
|||
|
_payrolltype, nBasicSalary, dCuttOfDate);
|
|||
|
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
TotalAmount = this.CalcluateBonus(oBonusParm, oEmp, nBasicSalary, nGrossSalary, dCuttOfDate);
|
|||
|
if (oBonusParm.IsOverYearCalculation)
|
|||
|
{
|
|||
|
// double noOfItem = oBonusParm.NoOfBasic + oBonusParm.NoOfGross;
|
|||
|
double preAmount = new BonusProcessService().GetBonusAmountWithinYear(dCuttOfDate, oEmp.ID, oBonusParm.BonusID);
|
|||
|
if (preAmount > 0)
|
|||
|
{
|
|||
|
int nNoOfPaid = new BonusProcessService().GetForNoOfPaidForEmp(dCuttOfDate, oBonusParm.BonusID, oEmp.ID);
|
|||
|
oBPDetail.BonusAmount = (TotalAmount - preAmount) * CurrProcess / (oBonusParm.NoOfDisbusement - nNoOfPaid);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
oBPDetail.BonusAmount = TotalAmount / oBonusParm.NoOfDisbusement * CurrProcess;
|
|||
|
}
|
|||
|
}
|
|||
|
else if (oBonusParm.IsPercent() == true)
|
|||
|
oBPDetail.BonusAmount = (TotalAmount / 100) * CurrProcess;
|
|||
|
|
|||
|
else
|
|||
|
{
|
|||
|
double noOfItem = oBonusParm.NoOfBasic + oBonusParm.NoOfGross;
|
|||
|
oBPDetail.BonusAmount = TotalAmount / noOfItem * CurrProcess;
|
|||
|
}
|
|||
|
}
|
|||
|
oBPDetail.BonusAmount = GlobalFunctions.Round(oBPDetail.BonusAmount);
|
|||
|
oBPDetail.ChangeBonusAmount = GlobalFunctions.Round(oBPDetail.BonusAmount);
|
|||
|
oBPDetail.IsProjectedBonus = oBonusParm.IsFestival;
|
|||
|
if (oBPDetail.BonusAmount > 0)
|
|||
|
oProssBonus.BonusProcessDetails.Add(oBPDetail);
|
|||
|
|
|||
|
}
|
|||
|
if(IsDisburseWithSalary ==false && IsTaxProcess ==true)
|
|||
|
this.CalculateTax(oProssBonus.BonusProcessDetails, employees, oBonus, payrolltypeid);
|
|||
|
|
|||
|
return oProssBonus;
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
public void CalculateTax(List<BonusProcess.BonusProcessDetail> bprocesdetails , List<Employee> oEmployees, Bonus oBonus, int payrolltypeid)
|
|||
|
{
|
|||
|
if (_payrolltype == null)
|
|||
|
_payrolltype = new PayrollTypeService().Get(payrolltypeid);
|
|||
|
|
|||
|
if(_parameters == null)
|
|||
|
_parameters = new BonusParameterService().Get(EnumStatus.Regardless, payrolltypeid);
|
|||
|
|
|||
|
if (_payrolltype.TaxParamID == null) throw new ServiceException("Current year Tax paramter setup not found.");
|
|||
|
TaxParameter oparamter = new TaxParameterService().Get((int)_payrolltype.TaxParamID);
|
|||
|
|
|||
|
List<ADParameter> oParams = new ADParameterService().Get(EnumStatus.Regardless, EnumAllowOrDeduct.Allowance, _payrolltype.ID);
|
|||
|
List<IncomeTax> oTaxes = new IncomeTaxService().Get(EnumIncomeTaxDataFrom.ProcessTempData, _payrolltype.ID);
|
|||
|
double nTaxAmount = 0;
|
|||
|
int nCount = 0;
|
|||
|
bool salaryProcessed = new IncomeTaxService().hasTaxDataInSalaryTemp(Employee.getEmpID(oEmployees));
|
|||
|
if (salaryProcessed == true)
|
|||
|
{
|
|||
|
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.");
|
|||
|
}
|
|||
|
TaxCalculator oCalculator = new TaxCalculator((int)_payrolltype.TaxParamID, _payrolltype.ID);
|
|||
|
oCalculator.TaxParameter = oparamter;
|
|||
|
oCalculator.payrolltype = _payrolltype;
|
|||
|
foreach (BonusProcess.BonusProcessDetail item in bprocesdetails)
|
|||
|
{
|
|||
|
nCount++;
|
|||
|
oCalculator.Employee = oEmployees.FirstOrDefault(x=>x.ID == item.EmployeeID);
|
|||
|
if(item.BonusParam ==null)
|
|||
|
{
|
|||
|
item.BonusParam = new BonusParameterService().GetApplicableParameter(item.Employee, (int)item.Employee.GradeID, _parameters, oBonus.ID);
|
|||
|
}
|
|||
|
|
|||
|
if (item.ChangeBonusAmount > 0)
|
|||
|
{
|
|||
|
List<TaxRawItem> oTaxRowItems = new List<TaxRawItem>();
|
|||
|
oTaxRowItems.Add(TaxRawItem.Create(oBonus.Name, item.ChangeBonusAmount, enumIncomeTaxItemType.Bonus, item.BonusID));
|
|||
|
nTaxAmount = 0;
|
|||
|
item.IncomeTaxcoll = oCalculator.CalculateBonus(oTaxRowItems, item.BonusParam, ref nTaxAmount, oParams, oTaxes);
|
|||
|
item.TaxAmount = nTaxAmount;
|
|||
|
item.ChangeTaxAmount = nTaxAmount;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public void UndoTax(BonusProcess oProcessedItems, List<Employee> oEmployees, Bonus oBonus)
|
|||
|
{
|
|||
|
if (_payrolltype.TaxParamID == null) throw new ServiceException("Current year Tax paramter setup not found.");
|
|||
|
TaxParameter oparamter = new TaxParameterService().Get((int)_payrolltype.TaxParamID);
|
|||
|
|
|||
|
List<ADParameter> oParams = new ADParameterService().Get(EnumStatus.Regardless, EnumAllowOrDeduct.Allowance, _payrolltype.ID);
|
|||
|
List<IncomeTax> oTaxes = new IncomeTaxService().Get(EnumIncomeTaxDataFrom.ProcessTempData, _payrolltype.ID);
|
|||
|
bool salaryProcessed = new IncomeTaxService().hasTaxDataInSalaryTemp(Employee.getEmpID(oEmployees));
|
|||
|
if (salaryProcessed == true)
|
|||
|
{
|
|||
|
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.");
|
|||
|
}
|
|||
|
TaxCalculator oCalculator = new TaxCalculator();
|
|||
|
oCalculator.TaxParameter = oparamter;
|
|||
|
|
|||
|
foreach (BonusProcess.BonusProcessDetail item in oProcessedItems.BonusProcessDetails)
|
|||
|
{
|
|||
|
Employee oemp = oEmployees.FirstOrDefault(x=>x.ID== item.EmployeeID);
|
|||
|
if (oemp == null)
|
|||
|
{
|
|||
|
oemp = new EmployeeService().Get(item.EmployeeID);
|
|||
|
}
|
|||
|
if (oemp == null) throw new ServiceException("Employee not found while undo tax process; employee No:" + item.Employee.EmployeeNo);
|
|||
|
|
|||
|
oCalculator.Employee = oemp;
|
|||
|
oCalculator.CurrentYearTax = oTaxes.FindAll(x=>x.EmployeeID == item.EmployeeID);
|
|||
|
|
|||
|
List<TaxRawItem> oTaxRowItems = new List<TaxRawItem>();
|
|||
|
oTaxRowItems.Add(TaxRawItem.Create(oBonus.Name, item.ChangeBonusAmount, enumIncomeTaxItemType.Bonus, item.BonusID));
|
|||
|
item.IncomeTaxcoll = oCalculator.UndoBonus(oTaxRowItems, item.ChangeTaxAmount);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
private double CalculateHMBonus(Bonus oBonus, BonusProcess oProssBonus,
|
|||
|
BonusProcess.BonusProcessDetail oBPDetail, BonusParameter oBonusParm, PayrollType ptype
|
|||
|
, double nBasicSalary, DateTime dCuttOfDate)
|
|||
|
{
|
|||
|
double nGrossSalary = 0;
|
|||
|
double TotalAmount = 0;
|
|||
|
if (oBonus.Code == "001")
|
|||
|
{
|
|||
|
int prevyear = ptype.NextPayProcessDate.Year - 1;
|
|||
|
oProssBonus.BasicOnMonth = new DateTime(prevyear, 12, 31);
|
|||
|
SalaryMonthly salary = new SalaryMonthlyService().Get(oBPDetail.EmployeeID, new DateTime(prevyear, 12, 31));
|
|||
|
if (salary != null)
|
|||
|
{
|
|||
|
nGrossSalary = salary.ThisMonthGross;
|
|||
|
oBPDetail.BasicSalary = nGrossSalary;
|
|||
|
TotalAmount = this.CalcluateLoyalityBonus(oBonusParm, oBPDetail.Employee,
|
|||
|
nGrossSalary, ptype.NextPayProcessDate);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
|
|||
|
nGrossSalary = oBPDetail.Employee.GrossSalary;
|
|||
|
oBPDetail.BasicSalary = nGrossSalary;
|
|||
|
TotalAmount = this.CalcluateLoyalityBonus(oBonusParm, oBPDetail.Employee,
|
|||
|
nGrossSalary, ptype.NextPayProcessDate);
|
|||
|
}
|
|||
|
}
|
|||
|
else if (oBonus.Code == "002" || oBonus.Code == "003")
|
|||
|
{
|
|||
|
TotalAmount = this.CalcluateAnnualBonus(oBonusParm, oBonus, oBPDetail.Employee, oBPDetail.Employee.GrossSalary,
|
|||
|
ptype.NextPayProcessDate);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
TotalAmount = this.CalcluateBonus(oBonusParm, oBPDetail.Employee, nBasicSalary, nGrossSalary, dCuttOfDate);
|
|||
|
}
|
|||
|
return TotalAmount;
|
|||
|
}
|
|||
|
public double CalcluateLoyalityBonus(BonusParameter param, Employee oemployee,
|
|||
|
double GrossSalary, DateTime dCuttOfDate)
|
|||
|
{
|
|||
|
|
|||
|
|
|||
|
double TotalAmount = 0;
|
|||
|
double basic = GrossSalary;
|
|||
|
|
|||
|
|
|||
|
//if (salary != null)
|
|||
|
//{
|
|||
|
// basic = salary.ThisMonthBasic;
|
|||
|
//}
|
|||
|
//GrossSalary=salary.Details.Where()
|
|||
|
if (oemployee.JoiningDate < DateTime.Parse("2011-05-13"))
|
|||
|
{
|
|||
|
//DateDifferenceInYearsMonthDays dd = DateDifferenceInYearsMonthDays.CompareDates(dCuttOfDate, oemployee.JoiningDate);
|
|||
|
int year = (dCuttOfDate.Year - oemployee.JoiningDate.Year) + 1;
|
|||
|
if (year >= 25)
|
|||
|
{
|
|||
|
TotalAmount = basic * 2;
|
|||
|
}
|
|||
|
else if (year >= 20)
|
|||
|
{
|
|||
|
TotalAmount = basic * 1.5;
|
|||
|
}
|
|||
|
else if (year >= 15)
|
|||
|
{
|
|||
|
TotalAmount = basic;
|
|||
|
}
|
|||
|
else if (year >= 10)
|
|||
|
{
|
|||
|
TotalAmount = basic * 0.5;
|
|||
|
}
|
|||
|
else if (year > 5)
|
|||
|
{
|
|||
|
TotalAmount = basic * 0.3;
|
|||
|
}
|
|||
|
}
|
|||
|
return TotalAmount;
|
|||
|
}
|
|||
|
private double CalcluateAnnualBonus(BonusParameter oBonusParm, Bonus oBonus, Employee oEmp, double nGrossSalary, DateTime dCuttOfDate)
|
|||
|
{
|
|||
|
List<Bonus> obnuses = new BonusService().Get(EnumStatus.Regardless, this._payrolltype.ID);
|
|||
|
double TotalAmount = 0;
|
|||
|
double prevAmount = 0;
|
|||
|
int prevyear = dCuttOfDate.Year - 1;
|
|||
|
//if (dCuttOfDate.Month == 3 || dCuttOfDate.Month == 9)
|
|||
|
//{
|
|||
|
double arearAmount = 0;
|
|||
|
if (oBonus.Code == "002")
|
|||
|
{
|
|||
|
Bonus ob = obnuses.FirstOrDefault(x => x.Code == "003");
|
|||
|
prevAmount = new BonusProcessService().GetBonusAmountWithinYear(new DateTime(prevyear, 9, 30), oEmp.ID, ob.ID, this._payrolltype.ID);
|
|||
|
|
|||
|
// prevAmount = new BonusProcessService().GetBonusAmountWithinYear(new DateTime(prevyear, 9, 30), oEmp.ID, 3);
|
|||
|
if (prevAmount == 0)
|
|||
|
{
|
|||
|
if (oEmp.JoiningDate < new DateTime(prevyear, 10, 1))
|
|||
|
{
|
|||
|
|
|||
|
if (oEmp.JoiningDate > new DateTime(prevyear, 4, 1))
|
|||
|
{
|
|||
|
TimeSpan bPeriod = new DateTime(prevyear, 9, 30) - new DateTime(prevyear, 4, 1);
|
|||
|
TimeSpan abd = new DateTime(prevyear, 9, 30) - oEmp.JoiningDate;
|
|||
|
arearAmount = (oEmp.GrossSalary / (bPeriod.Days + 1)) * (abd.Days + 1);
|
|||
|
TotalAmount = oEmp.GrossSalary + arearAmount;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
TotalAmount = oEmp.GrossSalary;
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
TimeSpan bPeriod = new DateTime(dCuttOfDate.Year, 3, 31) - new DateTime(prevyear, 10, 1);
|
|||
|
TimeSpan abd = new DateTime(dCuttOfDate.Year, 3, 31) - oEmp.JoiningDate;
|
|||
|
arearAmount = (oEmp.GrossSalary / (bPeriod.Days + 1)) * (abd.Days + 1);
|
|||
|
TotalAmount = arearAmount;
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
TotalAmount = nGrossSalary;
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
else if (oBonus.Code == "003")
|
|||
|
{
|
|||
|
Bonus ob = obnuses.FirstOrDefault(x => x.Code == "002");
|
|||
|
prevAmount = new BonusProcessService().GetBonusAmountWithinYear(new DateTime(dCuttOfDate.Year, 3, 31), oEmp.ID, ob.ID, this._payrolltype.ID);
|
|||
|
if (prevAmount == 0)
|
|||
|
{
|
|||
|
if (oEmp.JoiningDate < new DateTime(dCuttOfDate.Year, 4, 1))
|
|||
|
{
|
|||
|
if (oEmp.JoiningDate > new DateTime(prevyear, 10, 1))
|
|||
|
{
|
|||
|
TimeSpan bPeriod = new DateTime(dCuttOfDate.Year, 3, 31) - new DateTime(prevyear, 10, 1);
|
|||
|
TimeSpan abd = new DateTime(dCuttOfDate.Year, 3, 31) - oEmp.JoiningDate;
|
|||
|
arearAmount = (oEmp.GrossSalary / (bPeriod.Days + 1)) * (abd.Days + 1);
|
|||
|
TotalAmount = oEmp.GrossSalary + arearAmount;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
TotalAmount = oEmp.GrossSalary;
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
TimeSpan bPeriod = new DateTime(dCuttOfDate.Year, 9, 30) - new DateTime(dCuttOfDate.Year, 4, 1);
|
|||
|
TimeSpan abd = new DateTime(dCuttOfDate.Year, 9, 30) - oEmp.JoiningDate;
|
|||
|
arearAmount = (oEmp.GrossSalary / (bPeriod.Days + 1)) * (abd.Days + 1);
|
|||
|
TotalAmount = arearAmount;
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
TotalAmount = nGrossSalary;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
//}
|
|||
|
return TotalAmount;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
}
|