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("ADParameterID", _aDParameterID, value); _aDParameterID = value; } } #endregion #region GradeID : ID private ID _gradeID; public ID GradeID { get { return _gradeID; } set { base.OnPropertyChange("GradeID", _gradeID, value); _gradeID = value; } } #endregion #region AllowDeductID : ID private ID _allowDeductID; public ID AllowDeductID { get { return _allowDeductID; } set { base.OnPropertyChange("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("AllowDeductID", _allowDeductID, value); _allowDeductID = value; } } #endregion #region isForConfirmOnly : bool private bool _isForConfirmOnly = false; public bool IsForConfirmOnly { get { return _isForConfirmOnly; } set { base.OnPropertyChange("isForConfirmOnly", _isForConfirmOnly, value); _isForConfirmOnly = value; } } #endregion #region isFractionateApplicable : bool private bool _isFractionateApplicable = false; public bool IsFractionateApplicable { get { return _isFractionateApplicable; } set { base.OnPropertyChange("isFractionateApplicable", _isFractionateApplicable, value); _isFractionateApplicable = value; } } #endregion #region flatAmount : double private double _flatAmount=0; public double FlatAmount { get { return _flatAmount; } set { base.OnPropertyChange("flatAmount", _flatAmount, value); _flatAmount = value; } } #endregion #region percentOfBasic : double private double _percentOfBasic=0; public double PercentOfBasic { get { return _percentOfBasic; } set { base.OnPropertyChange("percentOfBasic", _percentOfBasic, value); _percentOfBasic = value; } } #endregion #region percentOfEarnedBasic : double private double _percentOfEarnedBasic=0; public double PercentOfEarnedBasic { get { return _percentOfEarnedBasic; } set { base.OnPropertyChange("percentOfEarnedBasic", _percentOfEarnedBasic, value); _percentOfEarnedBasic = value; } } #endregion #region percentOfGross : double private double _percentOfGross=0; public double PercentOfGross { get { return _percentOfGross; } set { base.OnPropertyChange("percentOfGross", _percentOfGross, value); _percentOfGross = value; } } #endregion #region minAmount : double private double _minAmount=0; public double MinAmount { get { return _minAmount; } set { base.OnPropertyChange("minAmount", _minAmount, value); _minAmount = value; } } #endregion #region maxAmount : double private double _maxAmount=0; public double MaxAmount { get { return _maxAmount; } set { base.OnPropertyChange("maxAmount", _maxAmount, value); _maxAmount = value; } } #endregion #region isCurrentlyActive : bool private bool _isCurrentlyActive; public bool IsCurrentlyActive { get { return _isCurrentlyActive; } set { base.OnPropertyChange("isCurrentlyActive", _isCurrentlyActive, value); _isCurrentlyActive = value; } } #endregion #region taxablePercentage : double private double _taxablePercentage=100; public double TaxablePercentage { get { return _taxablePercentage; } set { base.OnPropertyChange("taxablePercentage", _taxablePercentage, value); _taxablePercentage = value; } } #endregion #region isTaxable : bool private bool _isTaxable; public bool IsTaxable { get { return _isTaxable; } set { base.OnPropertyChange("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("isTaxProjection", _isTaxProjection, value); _isTaxProjection = value; } } #endregion #region isDependsOnAttendance : bool private bool _isDependsOnAttendance; public bool IsDependsOnAttendance { get { return _isDependsOnAttendance; } set { base.OnPropertyChange("isDependsOnAttendance", _isDependsOnAttendance, value); _isDependsOnAttendance = value; } } #endregion #region isDependsOnOTlHour : bool private bool _ISDEPENDSONSPECIALHOUR; public bool ISDEPENDSONSPECIALHOUR { get { return _ISDEPENDSONSPECIALHOUR; } set { base.OnPropertyChange("ISDEPENDSONSPECIALHOUR", _ISDEPENDSONSPECIALHOUR, value); _ISDEPENDSONSPECIALHOUR = value; } } #endregion #region isDependsOnOTlHour : bool private bool _isDependsOnOTHour; public bool IsDependsOnOTHour { get { return _isDependsOnOTHour; } set { base.OnPropertyChange("isDependsOnOTlHour", _isDependsOnOTHour, value); _isDependsOnOTHour = value; } } #endregion #region isWithException : bool private bool _isWithException; public bool IsWithException { get { return _isWithException; } set { base.OnPropertyChange("isWithException", _isWithException, value); _isWithException = value; } } #endregion #region periodicity : EnumPeriodicity private EnumPeriodicity _periodicity; public EnumPeriodicity Periodicity { get { return _periodicity; } set { base.OnPropertyChange("periodicity",(short) _periodicity, (short)value); _periodicity = value; } } #endregion #region periodicity : EnumPeriodicity private EnumEntitleType _entitleType; public EnumEntitleType EntitleType { get { return _entitleType; } set { base.OnPropertyChange("entitletype", (short)_entitleType, (short)value); _entitleType = value; } } #endregion #region allowOrDeductType : EnumADType private EnumAllowOrDeduct _allowOrDeductType; public EnumAllowOrDeduct AllowOrDeductType { get { return _allowOrDeductType; } set { base.OnPropertyChange("allowOrDeductType",(short) _allowOrDeductType,(short) value); _allowOrDeductType = value; } } #endregion #region gender : EnumGender private EnumGender _gender; public EnumGender Gender { get { return _gender; } set { base.OnPropertyChange("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 = null; public ObjectsTemplate 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 _Exception = null; public ObjectsTemplate 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 _NotApplicable = null; public ObjectsTemplate 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 _ADParameterGrades = null; public ObjectsTemplate 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(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 GetApplicableParameters(Employee employee, ID graId, ObjectsTemplate parameters) { List applicableParams = parameters.FindAll(delegate(ADParameter param) { return IsApplicable(param, graId, employee) ;}); return applicableParams; } //public static ADParameter GetApplicableParameter(Employee employee, // ID graId, ObjectsTemplate 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 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 Get(EnumStatus status) { #region Cache Header ObjectsTemplate aDParameters = _cache["Get"] as ObjectsTemplate; 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 GetWithDetail(EnumStatus status) { #region Cache Header ObjectsTemplate aDParameters = _cache["Get"] as ObjectsTemplate; 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 Get(EnumStatus status, EnumAllowOrDeduct type) { #region Cache Header ObjectsTemplate aDParameters = _cache["Get", type] as ObjectsTemplate; 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 Get(EnumStatus status, ID nAllowDeducID) { #region Cache Header ObjectsTemplate aDParameters = _cache["Get", nAllowDeducID] as ObjectsTemplate; 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 Get(ID gradeID, EnumEntitleType nADEmpType, EnumAllowOrDeduct nType) { #region Cache Header ObjectsTemplate aDParameters = _cache["Get", gradeID, nADEmpType, nType] as ObjectsTemplate; 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 GetGrades(ID adID) { #region Cache Header ObjectsTemplate aDParameterGrades = _cache["Get", adID] as ObjectsTemplate; 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 GetParametes(Employee employee, ID gradeId, ObjectsTemplate allparameters) { ObjectsTemplate parameters = new ObjectsTemplate(); return parameters; } public static void ApplicableParameters(Employee emlpoyee, SalaryMonthly salary, ObjectsTemplate allAdparameters) { foreach (EmployeeGradeSalary gs in salary.GradeSalaries) { List lparameter = ADParameter.GetApplicableParameters(emlpoyee, gs.GradeID, allAdparameters); gs.ADParameters = new ObjectsTemplate(); foreach (ADParameter item in lparameter) gs.ADParameters.Add(item); } foreach (EmployeeGradeSalary gs in salary.ArrearGradeSalaries) { List alparameter = ADParameter.GetApplicableParameters(emlpoyee, gs.GradeID, allAdparameters); gs.ADParameters = new ObjectsTemplate(); foreach (ADParameter item in alparameter) gs.ADParameters.Add(item); } foreach (EmployeeGradeSalary gs in salary.ArrearPaidGradeSalaries) { List aplparameter = ADParameter.GetApplicableParameters(emlpoyee, gs.GradeID, allAdparameters); gs.ADParameters = new ObjectsTemplate(); 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 GetGrades(ID adID); ObjectsTemplate GetByPayrolltypeid(EnumStatus status, ID PayrolltypeID); ObjectsTemplate Get(EnumStatus status, EnumAllowOrDeduct nType, ID PayrolltypeID); ObjectsTemplate Get(EnumStatus status, ID nAllowDeducID); ID Save(ADParameter item, ID PayrolltypeID); void Delete(ID id); void ChangeStatus(ID id, EnumStatus enumStatus); ObjectsTemplate Get(ID gradeID, EnumEntitleType nADEmpType, EnumAllowOrDeduct nType,ID PayrolltypeID); ADParameter GetADParamByGradeAndAD(ID gradeID, ID nAllowdeducID); ObjectsTemplate GetWithDetail(EnumStatus status, ID PayrolltypeID); } #endregion } #endregion