CEL_Payroll/Payroll.BO/AllowDeduct/ADParameter.cs

1308 lines
46 KiB
C#
Raw Permalink Normal View History

2024-09-17 14:30:13 +06:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ease.CoreV35;
using Ease.CoreV35.Model;
using Ease.CoreV35.Caching;
using System.Data.Linq.Mapping;
namespace Payroll.BO
{
#region ADParameter
[Serializable]
public class ADParameter : AuditTrailBase
{
#region Cache Store
private static Cache _cache = new Cache(typeof(ADParameter));
#endregion
#region Constructor
public ADParameter()
{
_allowDeductID = null;
_isForConfirmOnly = false;
_flatAmount = 0;
_percentOfBasic = 0;
_percentOfGross = 0;
_minAmount = 0;
_maxAmount = 0;
_isCurrentlyActive = false;
_taxablePercentage = 100;
_isTaxable = true;
_isTaxProjection = true;
_isDependsOnAttendance = false;
_isDependsOnOTHour = false;
_isWithException = false;
_periodicity = EnumPeriodicity.Monthly;
_allowOrDeductType = EnumAllowOrDeduct.Allowance;
_gender = EnumGender.None;
_allowanceDeduction = null;
_ISDEPENDSONSPECIALHOUR = false;
_entitleType = EnumEntitleType.Grade;
}
#endregion
#region Internal Class
[Serializable]
public class ADParameterGrade : AuditTrailBase
{
#region Cache Store
private static Cache _cache = new Cache(typeof(ADParameterGrade));
#endregion
#region Constructor
public ADParameterGrade()
{
_aDParameterID = null;
_gradeID = null;
_allowDeductID = null;
_garde = null;
}
#endregion
#region Properties
#region ADParameterID : ID
private ID _aDParameterID;
public ID ADParameterID
{
get { return _aDParameterID; }
set
{
base.OnPropertyChange<ID>("ADParameterID", _aDParameterID, value);
_aDParameterID = value;
}
}
#endregion
#region GradeID : ID
private ID _gradeID;
public ID GradeID
{
get { return _gradeID; }
set
{
base.OnPropertyChange<ID>("GradeID", _gradeID, value);
_gradeID = value;
}
}
#endregion
#region AllowDeductID : ID
private ID _allowDeductID;
public ID AllowDeductID
{
get { return _allowDeductID; }
set
{
base.OnPropertyChange<ID>("AllowDeductID", _allowDeductID, value);
_allowDeductID = value;
}
}
#endregion
#region garde : Grade
private Grade _garde;
public Grade Garde
{
get
{
if (_gradeID.Integer > 0 && _garde == null)
{
_garde = Grade.Get(_gradeID);
}
return this._garde;
}
set
{
_garde = value;
}
}
#endregion
#endregion
}
#endregion
#region Properties
#region AllowDeductID : ID
private ID _allowDeductID;
public ID AllowDeductID
{
get { return _allowDeductID; }
set
{
base.OnPropertyChange<ID>("AllowDeductID", _allowDeductID, value);
_allowDeductID = value;
}
}
#endregion
#region isForConfirmOnly : bool
private bool _isForConfirmOnly = false;
public bool IsForConfirmOnly
{
get { return _isForConfirmOnly; }
set
{
base.OnPropertyChange<bool>("isForConfirmOnly", _isForConfirmOnly, value);
_isForConfirmOnly = value;
}
}
#endregion
#region isFractionateApplicable : bool
private bool _isFractionateApplicable = false;
public bool IsFractionateApplicable
{
get { return _isFractionateApplicable; }
set
{
base.OnPropertyChange<bool>("isFractionateApplicable", _isFractionateApplicable, value);
_isFractionateApplicable = value;
}
}
#endregion
#region flatAmount : double
private double _flatAmount=0;
public double FlatAmount
{
get { return _flatAmount; }
set
{
base.OnPropertyChange<double>("flatAmount", _flatAmount, value);
_flatAmount = value;
}
}
#endregion
#region percentOfBasic : double
private double _percentOfBasic=0;
public double PercentOfBasic
{
get { return _percentOfBasic; }
set
{
base.OnPropertyChange<double>("percentOfBasic", _percentOfBasic, value);
_percentOfBasic = value;
}
}
#endregion
#region percentOfEarnedBasic : double
private double _percentOfEarnedBasic=0;
public double PercentOfEarnedBasic
{
get { return _percentOfEarnedBasic; }
set
{
base.OnPropertyChange<double>("percentOfEarnedBasic", _percentOfEarnedBasic, value);
_percentOfEarnedBasic = value;
}
}
#endregion
#region percentOfGross : double
private double _percentOfGross=0;
public double PercentOfGross
{
get { return _percentOfGross; }
set
{
base.OnPropertyChange<double>("percentOfGross", _percentOfGross, value);
_percentOfGross = value;
}
}
#endregion
#region minAmount : double
private double _minAmount=0;
public double MinAmount
{
get { return _minAmount; }
set
{
base.OnPropertyChange<double>("minAmount", _minAmount, value);
_minAmount = value;
}
}
#endregion
#region maxAmount : double
private double _maxAmount=0;
public double MaxAmount
{
get { return _maxAmount; }
set
{
base.OnPropertyChange<double>("maxAmount", _maxAmount, value);
_maxAmount = value;
}
}
#endregion
#region isCurrentlyActive : bool
private bool _isCurrentlyActive;
public bool IsCurrentlyActive
{
get { return _isCurrentlyActive; }
set
{
base.OnPropertyChange<bool>("isCurrentlyActive", _isCurrentlyActive, value);
_isCurrentlyActive = value;
}
}
#endregion
#region taxablePercentage : double
private double _taxablePercentage=100;
public double TaxablePercentage
{
get { return _taxablePercentage; }
set
{
base.OnPropertyChange<double>("taxablePercentage", _taxablePercentage, value);
_taxablePercentage = value;
}
}
#endregion
#region isTaxable : bool
private bool _isTaxable;
public bool IsTaxable
{
get { return _isTaxable; }
set
{
base.OnPropertyChange<bool>("isTaxable", _isTaxable, value);
_isTaxable = value;
}
}
#endregion
#region isFlatAmount : bool
public bool IsFlatAmount
{
get
{
if (_flatAmount != 0)
{
return true;
}
return false;
}
}
#endregion
#region isTaxProjection : bool
private bool _isTaxProjection;
public bool IsTaxProjection
{
get { return _isTaxProjection; }
set
{
base.OnPropertyChange<bool>("isTaxProjection", _isTaxProjection, value);
_isTaxProjection = value;
}
}
#endregion
#region isDependsOnAttendance : bool
private bool _isDependsOnAttendance;
public bool IsDependsOnAttendance
{
get { return _isDependsOnAttendance; }
set
{
base.OnPropertyChange<bool>("isDependsOnAttendance", _isDependsOnAttendance, value);
_isDependsOnAttendance = value;
}
}
#endregion
#region isDependsOnOTlHour : bool
private bool _ISDEPENDSONSPECIALHOUR;
public bool ISDEPENDSONSPECIALHOUR
{
get { return _ISDEPENDSONSPECIALHOUR; }
set
{
base.OnPropertyChange<bool>("ISDEPENDSONSPECIALHOUR", _ISDEPENDSONSPECIALHOUR, value);
_ISDEPENDSONSPECIALHOUR = value;
}
}
#endregion
#region isDependsOnOTlHour : bool
private bool _isDependsOnOTHour;
public bool IsDependsOnOTHour
{
get { return _isDependsOnOTHour; }
set
{
base.OnPropertyChange<bool>("isDependsOnOTlHour", _isDependsOnOTHour, value);
_isDependsOnOTHour = value;
}
}
#endregion
#region isWithException : bool
private bool _isWithException;
public bool IsWithException
{
get { return _isWithException; }
set
{
base.OnPropertyChange<bool>("isWithException", _isWithException, value);
_isWithException = value;
}
}
#endregion
#region periodicity : EnumPeriodicity
private EnumPeriodicity _periodicity;
public EnumPeriodicity Periodicity
{
get { return _periodicity; }
set
{
base.OnPropertyChange<short>("periodicity",(short) _periodicity, (short)value);
_periodicity = value;
}
}
#endregion
#region periodicity : EnumPeriodicity
private EnumEntitleType _entitleType;
public EnumEntitleType EntitleType
{
get { return _entitleType; }
set
{
base.OnPropertyChange<short>("entitletype", (short)_entitleType, (short)value);
_entitleType = value;
}
}
#endregion
#region allowOrDeductType : EnumADType
private EnumAllowOrDeduct _allowOrDeductType;
public EnumAllowOrDeduct AllowOrDeductType
{
get { return _allowOrDeductType; }
set
{
base.OnPropertyChange<short>("allowOrDeductType",(short) _allowOrDeductType,(short) value);
_allowOrDeductType = value;
}
}
#endregion
#region gender : EnumGender
private EnumGender _gender;
public EnumGender Gender
{
get { return _gender; }
set
{
base.OnPropertyChange<short>("gender",(short) _gender, (short)value);
_gender = value;
}
}
#endregion
#region allowanceDeduction : AllowanceDeduction
private AllowanceDeduction _allowanceDeduction;
public AllowanceDeduction AllowanceDeduction
{
get
{
if (_allowDeductID.Integer > 0 && _allowanceDeduction == null)
{
_allowanceDeduction = new AllowanceDeduction();
_allowanceDeduction = AllowanceDeduction.Get(_allowDeductID);
}
return this._allowanceDeduction;
}
set
{
_allowanceDeduction = value;
}
}
#endregion
#region ADParamEmployee : ADParameterEmployee
private ObjectsTemplate<ADParameterEmployee> _ADParameterEmployee = null;
public ObjectsTemplate<ADParameterEmployee> ADParameterEmployees
{
get
{
if (_ADParameterEmployee == null && !this.ID.IsUnassigned && this.ID.Integer > 0)
{
_ADParameterEmployee = ADParameterEmployee.GetbyParameter(this.ID);
}
return this._ADParameterEmployee;
}
set
{
_ADParameterEmployee = value;
}
}
#endregion
#region Exception : ADParameterEmployee
private ObjectsTemplate<ADParameterEmployee> _Exception = null;
public ObjectsTemplate<ADParameterEmployee> Exception
{
get
{
if (_Exception == null && !this.ID.IsUnassigned && this.ID.Integer > 0)
{
_Exception = ADParameterEmployee.GetbyParameter(this.ID,EnumADEmpType.Exception);
}
return this._Exception;
}
set
{
this._Exception = value;
}
}
#endregion
#region NotApplicable : ADParameterEmployee
private ObjectsTemplate<ADParameterEmployee> _NotApplicable = null;
public ObjectsTemplate<ADParameterEmployee> NotApplicable
{
get
{
if (_NotApplicable == null && !this.ID.IsUnassigned && this.ID.Integer > 0)
{
_NotApplicable = ADParameterEmployee.GetbyParameter(this.ID, EnumADEmpType.NotApplicable);
}
return this._NotApplicable;
}
set
{
this._NotApplicable = value;
}
}
#endregion
#region ADParamGrade : ADParameterGrade
private ObjectsTemplate<ADParameter.ADParameterGrade> _ADParameterGrades = null;
public ObjectsTemplate<ADParameter.ADParameterGrade> ADParameterGrades
{
get
{
if (_ADParameterGrades == null && !this.ID.IsUnassigned && this.ID.Integer > 0)
{
_ADParameterGrades = ADParameter.GetGrades(this.ID);
}
return this._ADParameterGrades;
}
set
{
_ADParameterGrades = value;
}
}
#endregion
#region Service Factory IADParameterService : IADParameterService
internal static IADParameterService Service
{
get { return Services.Factory.CreateService<IADParameterService>(typeof(IADParameterService)); }
}
#endregion
#endregion
#region Functions
public static ADParameter Get(ID nID)
{
ADParameter oADParameter = null;
#region Cache Header
oADParameter = (ADParameter)_cache["Get", nID];
if (oADParameter != null)
return oADParameter;
#endregion
oADParameter = ADParameter.Service.Get(nID, SystemInformation.CurrentSysInfo.PayrollTypeID);
#region Cache Footer
_cache.Add(oADParameter, "Get", nID);
#endregion
return oADParameter;
}
public static List<ADParameter> GetApplicableParameters(Employee employee,
ID graId, ObjectsTemplate<ADParameter> parameters)
{
List<ADParameter> applicableParams = parameters.FindAll(delegate(ADParameter param) { return IsApplicable(param, graId, employee) ;});
return applicableParams;
}
//public static ADParameter GetApplicableParameter(Employee employee,
// ID graId, ObjectsTemplate<ADParameter> parameters)
//{
// foreach (ADParameter item in parameters)
// {
// if (IsApplicable(item, graId, employee) == true)
// return item;
// }
// return null;
//}
public static ADParameter GetApplicableParameter(Employee employee,
ID graId, ObjectsTemplate<ADParameter> parameters, ID allowdeductID)
{
foreach (ADParameter item in parameters)
{
if (item.AllowDeductID == allowdeductID)
{
if (IsApplicable(item, graId, employee) == true)
return item;
}
}
return null;
}
private static bool IsApplicable(ADParameter param, ID graid, Employee employee)
{
bool isApplicable = false;
foreach (ADParameterGrade adgrade in param.ADParameterGrades)
{
if (adgrade.GradeID.Integer == graid.Integer)
{
isApplicable = true;
}
}
if (!isApplicable) return false;
if (param.Gender != EnumGender.None
&& param.Gender != employee.Gender)
{
return false;
}
if (param.IsForConfirmOnly && !employee.IsConfirmed)
{
return false;
}
return true;
}
public double CalculateAmount(Employee oEmp)
{
double amount = 0;
if (this.PercentOfBasic > 0)
{
amount = this.FlatAmount + (this.PercentOfBasic * oEmp.BasicSalary)/100;
}
else if (this.PercentOfGross > 0)
{
amount = this.FlatAmount + (this.PercentOfGross * oEmp.GrossSalary)/100;
}
else
{
amount = this.FlatAmount;
}
return amount;
}
public static ObjectsTemplate<ADParameter> Get(EnumStatus status)
{
#region Cache Header
ObjectsTemplate<ADParameter> aDParameters = _cache["Get"] as ObjectsTemplate<ADParameter>;
if (aDParameters != null)
return aDParameters;
#endregion
try
{
aDParameters = Service.GetByPayrolltypeid(status, Payroll.BO.SystemInformation.CurrentSysInfo.PayrollTypeID);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(aDParameters, "Get",status);
#endregion
return aDParameters;
}
public static ObjectsTemplate<ADParameter> GetWithDetail(EnumStatus status)
{
#region Cache Header
ObjectsTemplate<ADParameter> aDParameters = _cache["Get"] as ObjectsTemplate<ADParameter>;
if (aDParameters != null)
return aDParameters;
#endregion
try
{
aDParameters = Service.GetWithDetail(status, Payroll.BO.SystemInformation.CurrentSysInfo.PayrollTypeID);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(aDParameters, "Get", status);
#endregion
return aDParameters;
}
public static ObjectsTemplate<ADParameter> Get(EnumStatus status, EnumAllowOrDeduct type)
{
#region Cache Header
ObjectsTemplate<ADParameter> aDParameters = _cache["Get", type] as ObjectsTemplate<ADParameter>;
if (aDParameters != null)
return aDParameters;
#endregion
try
{
aDParameters = Service.Get(status, type, SystemInformation.CurrentSysInfo.PayrollTypeID);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(aDParameters, "Get", status, type);
#endregion
return aDParameters;
}
public static ObjectsTemplate<ADParameter> Get(EnumStatus status, ID nAllowDeducID)
{
#region Cache Header
ObjectsTemplate<ADParameter> aDParameters = _cache["Get", nAllowDeducID] as ObjectsTemplate<ADParameter>;
if (aDParameters != null)
return aDParameters;
#endregion
try
{
aDParameters = Service.Get(status, nAllowDeducID);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(aDParameters, "Get", status, nAllowDeducID);
#endregion
return aDParameters;
}
public static ObjectsTemplate<ADParameter> Get(ID gradeID, EnumEntitleType nADEmpType, EnumAllowOrDeduct nType)
{
#region Cache Header
ObjectsTemplate<ADParameter> aDParameters = _cache["Get", gradeID, nADEmpType, nType] as ObjectsTemplate<ADParameter>;
if (aDParameters != null)
return aDParameters;
#endregion
try
{
aDParameters = Service.Get(gradeID, nADEmpType, nType, SystemInformation.CurrentSysInfo.PayrollTypeID);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(aDParameters, "Get", gradeID, nADEmpType, nType);
#endregion
return aDParameters;
}
public static ADParameter GetADParamByGradeAndAD(ID gradeID, ID nAllowdeducID)
{
#region Cache Header
ADParameter aDParameter = null;
try
{
aDParameter = Service.GetADParamByGradeAndAD(gradeID, nAllowdeducID);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
return aDParameter;
}
public static ObjectsTemplate<ADParameter.ADParameterGrade> GetGrades(ID adID)
{
#region Cache Header
ObjectsTemplate<ADParameter.ADParameterGrade> aDParameterGrades = _cache["Get", adID] as ObjectsTemplate<ADParameter.ADParameterGrade>;
if (aDParameterGrades != null)
return aDParameterGrades;
#endregion
try
{
aDParameterGrades = Service.GetGrades(adID);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(aDParameterGrades, "Get", adID);
#endregion
return aDParameterGrades;
}
public ID Save()
{
base.SetAuditTrailProperties();
return ADParameter.Service.Save(this,SystemInformation.CurrentSysInfo.PayrollTypeID);
}
public void Delete()
{
ADParameter.Service.Delete(ID);
}
public void ChangeStatus(EnumStatus enumStatus)
{
ADParameter.Service.ChangeStatus(this.ID,enumStatus);
}
private ObjectsTemplate<ADParameter> GetParametes(Employee employee,
ID gradeId, ObjectsTemplate<ADParameter> allparameters)
{
ObjectsTemplate<ADParameter> parameters = new ObjectsTemplate<ADParameter>();
return parameters;
}
public static void ApplicableParameters(Employee emlpoyee,
SalaryMonthly salary, ObjectsTemplate<ADParameter> allAdparameters)
{
foreach (EmployeeGradeSalary gs in salary.GradeSalaries)
{
List<ADParameter> lparameter = ADParameter.GetApplicableParameters(emlpoyee, gs.GradeID, allAdparameters);
gs.ADParameters = new ObjectsTemplate<ADParameter>();
foreach (ADParameter item in lparameter)
gs.ADParameters.Add(item);
}
foreach (EmployeeGradeSalary gs in salary.ArrearGradeSalaries)
{
List<ADParameter> alparameter = ADParameter.GetApplicableParameters(emlpoyee, gs.GradeID, allAdparameters);
gs.ADParameters = new ObjectsTemplate<ADParameter>();
foreach (ADParameter item in alparameter)
gs.ADParameters.Add(item);
}
foreach (EmployeeGradeSalary gs in salary.ArrearPaidGradeSalaries)
{
List<ADParameter> aplparameter = ADParameter.GetApplicableParameters(emlpoyee, gs.GradeID, allAdparameters);
gs.ADParameters = new ObjectsTemplate<ADParameter>();
foreach (ADParameter item in aplparameter)
gs.ADParameters.Add(item);
}
}
public double GetGradeDefinedAmount(Employee employee, double basicSalary,
double grossSalary)
{
ADParameterEmployee adEmp = null;
double nAmount = 0.0;
switch (this.EntitleType)
{
case EnumEntitleType.Grade:
if (this.PercentOfBasic > 0)
nAmount = basicSalary * this.PercentOfBasic / 100.0 + this.FlatAmount;
else if (this.PercentOfGross > 0)
nAmount = grossSalary * this.PercentOfGross / 100.0 + this.FlatAmount;
else
nAmount = this.FlatAmount;
if (this.NotApplicable.Exists(delegate(ADParameterEmployee adEmployee) { return adEmployee.EmployeeID.Integer == employee.ID.Integer; }))
{
nAmount = 0;
}
else
{
adEmp = this.Exception.Find(delegate(ADParameterEmployee adEmployee) { return adEmployee.EmployeeID.Integer == employee.ID.Integer; });
if (adEmp != null)
{
switch (adEmp.ValueType)
{
case EnumValueType.Amount:
nAmount = adEmp.MonthlyAmount;
break;
case EnumValueType.Other:
if (this.PercentOfBasic > 0)
nAmount = basicSalary * adEmp.MonthlyAmount / 100.0 + this.FlatAmount;
else if (this.PercentOfGross > 0)
nAmount = grossSalary * adEmp.MonthlyAmount / 100.0 + this.FlatAmount;
break;
}
}
}
break;
case EnumEntitleType.Individual:
throw new ServiceException("You have choosed the wrong overloaded function to calculate"
+ " Individual Allowance" + " Employee:(" + employee.EmployeeNo + ")" + employee.Name + "; Item Name:" + this.AllowanceDeduction.Name);
}
if (this.MinAmount != 0 || this.MaxAmount != 0)
{
if (nAmount < this.MinAmount)
{
nAmount = this.MinAmount;
}
if (nAmount > this.MaxAmount)
{
nAmount = this.MaxAmount;
}
}
return nAmount;
}
public double GetGradeDefinedAmount(Employee employee, double basicSalary,
double grossSalary,EmployeeGradeSalary oEmpGradeSalary)
{
ADParameterEmployee adEmp = null;
double nAmount = 0.0;
switch (this.EntitleType)
{
case EnumEntitleType.Grade:
if (this.PercentOfBasic > 0)
nAmount = nAmount + this.FlatAmount * oEmpGradeSalary.FractionofFromTo + basicSalary * this.PercentOfBasic / 100.0;
//nAmount = basicSalary * this.PercentOfBasic / 100.0;// + this.FlatAmount;
else if (this.PercentOfGross > 0)
nAmount = nAmount + this.FlatAmount * oEmpGradeSalary.FractionofFromTo + grossSalary * this.PercentOfGross / 100.0;
//nAmount = grossSalary * this.PercentOfGross / 100.0;// + this.FlatAmount;
else
nAmount = this.FlatAmount * oEmpGradeSalary.FractionofFromTo;
if (this.NotApplicable.Exists(delegate(ADParameterEmployee adEmployee) { return adEmployee.EmployeeID.Integer == employee.ID.Integer; }))
{
nAmount = 0;
}
else
{
adEmp = this.Exception.Find(delegate(ADParameterEmployee adEmployee) { return adEmployee.EmployeeID.Integer == employee.ID.Integer; });
if (adEmp != null)
{
switch (adEmp.ValueType)
{
case EnumValueType.Amount:
nAmount = adEmp.MonthlyAmount * oEmpGradeSalary.FractionofFromTo;
break;
case EnumValueType.Other:
if (this.PercentOfBasic > 0 || adEmp.MonthlyAmount>0)
nAmount = basicSalary * adEmp.MonthlyAmount / 100.0;//* oEmpGradeSalary.FractionofFromTo; //+ this.FlatAmount;
else if (this.PercentOfGross > 0 || adEmp.MonthlyAmount>0)
nAmount = grossSalary * adEmp.MonthlyAmount / 100.0;//* oEmpGradeSalary.FractionofFromTo; //+ this.FlatAmount;
break;
}
}
}
break;
case EnumEntitleType.Individual:
throw new ServiceException("You have choosed the wrong overloaded function to calculate"
+ " Individual Allowance" + " Employee:(" + employee.EmployeeNo + ")" + employee.Name +"; Item Name:" + this.AllowanceDeduction.Name);
}
if (this.MinAmount != 0 || this.MaxAmount != 0)
{
if (nAmount < this.MinAmount)
{
nAmount = this.MinAmount;
}
if (nAmount > this.MaxAmount)
{
nAmount = this.MaxAmount;
}
}
return nAmount;
}
public double GetGradeDefinedAmountTrainee(Employee employee, double basicSalary,
double grossSalary, EmployeeGradeSalary oEmpGradeSalary)
{
ADParameterEmployee adEmp = null;
double nAmount = 0.0;
oEmpGradeSalary.FractionofFromTo = 1;
switch (this.EntitleType)
{
case EnumEntitleType.Grade:
if (this.PercentOfBasic > 0)
nAmount = nAmount + this.FlatAmount * oEmpGradeSalary.FractionofFromTo + basicSalary * this.PercentOfBasic / 100.0;
//nAmount = basicSalary * this.PercentOfBasic / 100.0;// + this.FlatAmount;
else if (this.PercentOfGross > 0)
nAmount = nAmount + this.FlatAmount * oEmpGradeSalary.FractionofFromTo + grossSalary * this.PercentOfGross / 100.0;
//nAmount = grossSalary * this.PercentOfGross / 100.0;// + this.FlatAmount;
else
nAmount = this.FlatAmount * oEmpGradeSalary.FractionofFromTo;
if (this.NotApplicable.Exists(delegate(ADParameterEmployee adEmployee) { return adEmployee.EmployeeID.Integer == employee.ID.Integer; }))
{
nAmount = 0;
}
else
{
adEmp = this.Exception.Find(delegate(ADParameterEmployee adEmployee) { return adEmployee.EmployeeID.Integer == employee.ID.Integer; });
if (adEmp != null)
{
switch (adEmp.ValueType)
{
case EnumValueType.Amount:
nAmount = adEmp.MonthlyAmount * oEmpGradeSalary.FractionofFromTo;
break;
case EnumValueType.Other:
if (this.PercentOfBasic > 0 || adEmp.MonthlyAmount > 0)
nAmount = basicSalary * adEmp.MonthlyAmount / 100.0;//* oEmpGradeSalary.FractionofFromTo; //+ this.FlatAmount;
else if (this.PercentOfGross > 0 || adEmp.MonthlyAmount > 0)
nAmount = grossSalary * adEmp.MonthlyAmount / 100.0;//* oEmpGradeSalary.FractionofFromTo; //+ this.FlatAmount;
break;
}
}
}
break;
case EnumEntitleType.Individual:
throw new ServiceException("You have choosed the wrong overloaded function to calculate"
+ " Individual Allowance" + " Employee:(" + employee.EmployeeNo + ")" + employee.Name + "; Item Name:" + this.AllowanceDeduction.Name);
}
if (this.MinAmount != 0 || this.MaxAmount != 0)
{
if (nAmount < this.MinAmount)
{
nAmount = this.MinAmount;
}
if (nAmount > this.MaxAmount)
{
nAmount = this.MaxAmount;
}
}
return nAmount;
}
public double GetIndividualAmount(Employee employee, DateTime fortheMonth,
ADParameterEmployee ademployee, double grossSalary, double basicSalary)
{
double nAmount = 0.0;
switch (this.EntitleType)
{
case EnumEntitleType.Grade:
throw new ServiceException("You have choosed the wrong overloaded function to calculate"
+ " Grade defined Allowance" + " Employee:(" + employee.EmployeeNo + ")" + employee.Name + "; Item Name:" + this.AllowanceDeduction.Name);
case EnumEntitleType.Individual:
if (this.IsDependsOnAttendance)
{
nAmount = this.FlatAmount * ademployee.MonthlyAmount;
}
else if (ademployee.Arreartype == EnumArrearType.NotPresent)
{
DateTime fromDate = GlobalFunctions.FirstDateOfMonth(SystemInformation.CurrentSysInfo.NextPayProcessDate);
DateTime toDate = SystemInformation.CurrentSysInfo.NextPayProcessDate;
if (ademployee.FormDate < GlobalFunctions.FirstDateOfMonth(fortheMonth))
fromDate = GlobalFunctions.FirstDateOfMonth(fortheMonth);
else fromDate = ademployee.FormDate;
if (ademployee.TillDate == null || ademployee.TillDate == DateTime.MinValue)
toDate = GlobalFunctions.LastDateOfMonth(fortheMonth);
else toDate = (DateTime)ademployee.TillDate;
if (toDate > GlobalFunctions.LastDateOfMonth(fortheMonth))
toDate = GlobalFunctions.LastDateOfMonth(fortheMonth);
if (this.Periodicity != EnumPeriodicity.OneOff)
if (employee.EndOfContractDate != null || employee.EndOfContractDate != DateTime.MinValue)
if (employee.EndOfContractDate < toDate)
toDate = (DateTime)employee.EndOfContractDate;
if (ademployee.ValueType == EnumValueType.Other)
{
//while percent of basic then not required to do fractionate of date basis
//if (this.PercentOfBasic > 0 || ademployee.MonthlyAmount >0 )
// nAmount = (basicSalary * ademployee.MonthlyAmount) / 100 * GlobalFunctions.GetFraction(ademployee.FormDate, toDate);
//else if (this.PercentOfGross > 0 || ademployee.MonthlyAmount > 0)
// nAmount = (grossSalary * ademployee.MonthlyAmount) / 100 * GlobalFunctions.GetFraction(ademployee.FormDate, toDate);
if (this.PercentOfBasic > 0 || ademployee.MonthlyAmount > 0)
nAmount = (employee.BasicSalary * ademployee.MonthlyAmount) / 100 * GlobalFunctions.GetFraction(fromDate, toDate);
else if (this.PercentOfGross > 0 || ademployee.MonthlyAmount > 0)
nAmount = (employee.GrossSalary * ademployee.MonthlyAmount) / 100 * GlobalFunctions.GetFraction(fromDate, toDate);
}
else nAmount = ademployee.MonthlyAmount * GlobalFunctions.GetFraction(fromDate, toDate);
}
else if (ademployee.Arreartype == EnumArrearType.ToCalculate)
{
if (ademployee.ValueType == EnumValueType.Other)
{
if (this.PercentOfBasic > 0 || ademployee.MonthlyAmount > 0)
nAmount = (employee.BasicSalary * ademployee.MonthlyAmount) / 100 * GlobalFunctions.GetFraction(ademployee.FormDate, (DateTime)ademployee.TillDate);
else if (this.PercentOfGross > 0 || ademployee.MonthlyAmount > 0)
nAmount = (employee.GrossSalary * ademployee.MonthlyAmount) / 100 * GlobalFunctions.GetFraction(ademployee.FormDate, (DateTime)ademployee.TillDate);
}
else nAmount = ademployee.MonthlyAmount *
GlobalFunctions.GetFraction(ademployee.FormDate, (DateTime)ademployee.TillDate);
}
break;
}
return nAmount;
}
public double GetIndividualAmount(Employee employee, DateTime fortheMonth,
ADParameterEmployee ademployee, double grossSalary, double basicSalary,SalaryMonthly salary)
{
double nAmount = 0.0;
switch (this.EntitleType)
{
case EnumEntitleType.Grade:
throw new ServiceException("You have choosed the wrong overloaded function to calculate"
+ " Grade defined Allowance" + " Employee:(" + employee.EmployeeNo + ")" + employee.Name + "; Item Name:" + this.AllowanceDeduction.Name);
case EnumEntitleType.Individual:
if (this.IsDependsOnAttendance)
{
nAmount = this.FlatAmount * ademployee.MonthlyAmount;
}
else if (ademployee.Arreartype == EnumArrearType.NotPresent)
{
DateTime fromDate = GlobalFunctions.FirstDateOfMonth(SystemInformation.CurrentSysInfo.NextPayProcessDate);
DateTime toDate = SystemInformation.CurrentSysInfo.NextPayProcessDate;
if (ademployee.FormDate < GlobalFunctions.FirstDateOfMonth(fortheMonth))
fromDate = GlobalFunctions.FirstDateOfMonth(fortheMonth);
else fromDate = ademployee.FormDate;
if (ademployee.TillDate == null || ademployee.TillDate == DateTime.MinValue)
toDate = GlobalFunctions.LastDateOfMonth(fortheMonth);
else toDate = (DateTime)ademployee.TillDate;
if (toDate > GlobalFunctions.LastDateOfMonth(fortheMonth))
toDate = GlobalFunctions.LastDateOfMonth(fortheMonth);
if (this.Periodicity != EnumPeriodicity.OneOff)
if (employee.EndOfContractDate != null || employee.EndOfContractDate != DateTime.MinValue)
if (employee.EndOfContractDate < toDate)
toDate = (DateTime)employee.EndOfContractDate;
if (ademployee.ValueType == EnumValueType.Other)
{
//while percent of basic then not required to do fractionate of date basis
//if (this.PercentOfBasic > 0 || ademployee.MonthlyAmount >0 )
// nAmount = (basicSalary * ademployee.MonthlyAmount) / 100 * GlobalFunctions.GetFraction(ademployee.FormDate, toDate);
//else if (this.PercentOfGross > 0 || ademployee.MonthlyAmount > 0)
// nAmount = (grossSalary * ademployee.MonthlyAmount) / 100 * GlobalFunctions.GetFraction(ademployee.FormDate, toDate);
if (this.PercentOfBasic > 0 || ademployee.MonthlyAmount > 0)
nAmount = (employee.BasicSalary * ademployee.MonthlyAmount) / 100 * GlobalFunctions.GetFraction(fromDate, toDate);
else if (this.PercentOfGross > 0 || ademployee.MonthlyAmount > 0)
nAmount = (employee.GrossSalary * ademployee.MonthlyAmount) / 100 * GlobalFunctions.GetFraction(fromDate, toDate);
}
else nAmount = ademployee.MonthlyAmount * GlobalFunctions.GetFraction(fromDate, toDate);
}
else if (ademployee.Arreartype == EnumArrearType.ToCalculate)
{
if (ademployee.ValueType == EnumValueType.Other)
{
if (this.PercentOfBasic > 0 || ademployee.MonthlyAmount > 0)
nAmount = (employee.BasicSalary * ademployee.MonthlyAmount) / 100 * GlobalFunctions.GetFraction(ademployee.FormDate, (DateTime)ademployee.TillDate);
else if (this.PercentOfGross > 0 || ademployee.MonthlyAmount > 0)
nAmount = (employee.GrossSalary * ademployee.MonthlyAmount) / 100 * GlobalFunctions.GetFraction(ademployee.FormDate, (DateTime)ademployee.TillDate);
}
else nAmount = ademployee.MonthlyAmount *
GlobalFunctions.GetFraction(ademployee.FormDate, (DateTime)ademployee.TillDate);
}
break;
}
return nAmount;
}
public double GetAmount(Employee oEmp)
{
ADParameterEmployee adEmp = null;
double nAmount = 0.0;
switch (this.EntitleType)
{
case EnumEntitleType.Grade:
if (this.PercentOfBasic > 0)
nAmount = oEmp.BasicSalary * this.PercentOfBasic / 100.0 + this.FlatAmount;
else if (this.PercentOfGross > 0)
nAmount = oEmp.GrossSalary * this.PercentOfBasic / 100.0 + this.FlatAmount;
else
nAmount = this.FlatAmount;
break;
case EnumEntitleType.Individual:
adEmp = ADParameterEmployee.Get(oEmp.ID, this.AllowDeductID, this.ID);
if (adEmp != null)
nAmount = adEmp.MonthlyAmount;
else
{
if (this.PercentOfBasic > 0)
nAmount = oEmp.BasicSalary * this.PercentOfBasic / 100.0 + this.FlatAmount;
else if (this.PercentOfGross > 0)
nAmount = oEmp.GrossSalary * this.PercentOfBasic / 100.0 + this.FlatAmount;
else
nAmount = this.FlatAmount;
}
break;
}
if (this.MinAmount != 0 || this.MaxAmount != 0)
{
if (nAmount < this.MinAmount)
{
nAmount = this.MinAmount;
}
if (nAmount > this.MaxAmount)
{
nAmount = this.MaxAmount;
}
}
return nAmount;
}
#endregion
#endregion
}
#region IADParameter Service
public interface IADParameterService
{
ADParameter Get(ID id, ID PayrolltypeID);
ObjectsTemplate<ADParameter.ADParameterGrade> GetGrades(ID adID);
ObjectsTemplate<ADParameter> GetByPayrolltypeid(EnumStatus status, ID PayrolltypeID);
ObjectsTemplate<ADParameter> Get(EnumStatus status, EnumAllowOrDeduct nType, ID PayrolltypeID);
ObjectsTemplate<ADParameter> Get(EnumStatus status, ID nAllowDeducID);
ID Save(ADParameter item, ID PayrolltypeID);
void Delete(ID id);
void ChangeStatus(ID id, EnumStatus enumStatus);
ObjectsTemplate<ADParameter> Get(ID gradeID, EnumEntitleType nADEmpType, EnumAllowOrDeduct nType,ID PayrolltypeID);
ADParameter GetADParamByGradeAndAD(ID gradeID, ID nAllowdeducID);
ObjectsTemplate<ADParameter> GetWithDetail(EnumStatus status, ID PayrolltypeID);
}
#endregion
}
#endregion