CEL_Payroll/Payroll.BO/Gratuity/ESBDefinition.cs

843 lines
22 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;
using System.Data;
namespace Payroll.BO
{
#region ESBDefinition
[Serializable]
public class ESBDefinition : BasicBaseObject
{
#region Cache Store
private static Cache _cache = new Cache(typeof(ESBDefinition));
#endregion
#region Constructor
public ESBDefinition()
{
_description = string.Empty;
_maxServiceLength = 0.0;
_payrollTypeID = null;
_trading = 0.0;
_userID = null;
}
#endregion
#region Properties
#region Description : string
private string _description;
public string Description
{
get { return _description; }
set
{
base.OnPropertyChange<string>("Description", _description, value);
_description = value;
}
}
#endregion
#region PayrollTypeID : ID
private ID _payrollTypeID;
public ID PayrollTypeID
{
get { return _payrollTypeID; }
set
{
base.OnPropertyChange<ID>("name", _payrollTypeID, value);
_payrollTypeID = value;
}
}
#endregion
#region MaxServiceLength : double
private double _maxServiceLength;
public double MaxServiceLength
{
get { return _maxServiceLength; }
set
{
base.OnPropertyChange<double>("MaxServiceLength", _maxServiceLength, value);
_maxServiceLength = value;
}
}
#endregion
#region Trading : double
private double _trading;
public double Trading
{
get { return _trading; }
set
{
base.OnPropertyChange<double>("Trading", _trading, value);
_trading = value;
}
}
#endregion
#region UserID : ID
private ID _userID;
public ID UserID
{
get { return _userID; }
set
{
base.OnPropertyChange<ID>("UserID", _userID, value);
_userID = value;
}
}
#endregion
#region ESBSlabs : ObjectsTemplate<ESBSlab>
private ObjectsTemplate<ESBSlab> _esbSlabs;
public ObjectsTemplate<ESBSlab> ESBSlabs
{
get
{
if (_esbSlabs == null && !this.ID.IsUnassigned && this.ID.Integer > 0)
{
_esbSlabs = ESBSlab.GetSlabs(this.ID.Integer);
}
if (_esbSlabs == null)
{
_esbSlabs = new ObjectsTemplate<ESBSlab>();
}
return _esbSlabs;
}
set
{
_esbSlabs = value;
}
}
#endregion
#region ESBGrades : ObjectsTemplate<ESBGrade>
private ObjectsTemplate<ESBGrade> _esbGrades;
public ObjectsTemplate<ESBGrade> ESBGrades
{
get
{
if (_esbGrades == null && !this.ID.IsUnassigned && this.ID.Integer > 0)
{
_esbGrades = ESBGrade.GetESBGrade(this.ID.Integer);
}
if (_esbGrades == null)
{
_esbGrades = new ObjectsTemplate<ESBGrade>();
}
return _esbGrades;
}
set
{
_esbGrades = value;
}
}
#endregion
#region ESBElements : ObjectsTemplate<ESBElement>
private ObjectsTemplate<ESBElement> _esbElements;
public ObjectsTemplate<ESBElement> ESBElements
{
get
{
if (_esbElements == null && !this.ID.IsUnassigned && this.ID.Integer > 0)
{
_esbElements = ESBElement.GetESBElement(this.ID.Integer);
}
if (_esbElements == null)
{
_esbElements = new ObjectsTemplate<ESBElement>();
}
return _esbElements;
}
set
{
_esbElements = value;
}
}
#endregion
#region Service Factory IESBDefinitionService : IESBDefinitionService
internal static IESBDefinitionService Service
{
get { return Services.Factory.CreateService<IESBDefinitionService>(typeof(IESBDefinitionService)); }
}
#endregion
#endregion
#region Functions
public static ESBDefinition Get(ID nID)
{
ESBDefinition oESBDefinition = null;
#region Cache Header
oESBDefinition = (ESBDefinition)_cache["Get", nID];
if (oESBDefinition != null)
return oESBDefinition;
#endregion
oESBDefinition = ESBDefinition.Service.Get(nID);
#region Cache Footer
_cache.Add(oESBDefinition, "Get", nID);
#endregion
return oESBDefinition;
}
public static ESBDefinition GetByPayrollID(int nID)
{
ESBDefinition oESBDefinition = null;
#region Cache Header
oESBDefinition = (ESBDefinition)_cache["GetByPayrollID", nID];
if (oESBDefinition != null)
return oESBDefinition;
#endregion
oESBDefinition = ESBDefinition.Service.GetByPayrollID(nID);
#region Cache Footer
_cache.Add(oESBDefinition, "GetByPayrollID", nID);
#endregion
return oESBDefinition;
}
public static ESBDefinition Get(int nID)
{
ESBDefinition oESBDefinition = null;
#region Cache Header
oESBDefinition = (ESBDefinition)_cache["Get", nID];
if (oESBDefinition != null)
return oESBDefinition;
#endregion
oESBDefinition = ESBDefinition.Service.Get(nID);
#region Cache Footer
_cache.Add(oESBDefinition, "Get", nID);
#endregion
return oESBDefinition;
}
public static ESBDefinition Get(ObjectsTemplate<ESBDefinition> definations, Employee employee)
{
ESBDefinition odefinaiton =null;
ESBGrade oESBGrade = null;
odefinaiton = definations.Where(x => x.PayrollTypeID == employee.PayrollTypeID).SingleOrDefault();
if (odefinaiton !=null)
oESBGrade = odefinaiton.ESBGrades.Where(t=> t.GradeID == employee.GradeID).SingleOrDefault();
return odefinaiton;
}
public static ObjectsTemplate<ESBDefinition> Get()
{
#region Cache Header
ObjectsTemplate<ESBDefinition> oESBDefinition = _cache["Get"] as ObjectsTemplate<ESBDefinition>;
if (oESBDefinition != null)
return oESBDefinition;
#endregion
try
{
oESBDefinition = Service.Get();
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(oESBDefinition, "Get");
#endregion
return oESBDefinition;
}
public static ObjectsTemplate<ESBDefinition> GetByPayrollType(int nPayrollTypeID)
{
#region Cache Header
ObjectsTemplate<ESBDefinition> oESBDefinition = _cache["GetByPayrollType", nPayrollTypeID] as ObjectsTemplate<ESBDefinition>;
if (oESBDefinition != null)
return oESBDefinition;
#endregion
try
{
oESBDefinition = Service.GetByPayrollType(nPayrollTypeID);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(oESBDefinition, "GetByPayrollType", nPayrollTypeID);
#endregion
return oESBDefinition;
}
public void CalculateProvisionAmount(Employee oEmployee,ObjectsTemplate<SalaryMonthlyDetail> oSalaryMonthlyDetails, ESBProvision oESBProvision,DataSet oDS)
{
EnumSalaryItemCode nItemCode = EnumSalaryItemCode.Basic_Salary;
double nESBAmount = 0.0;
double nProvisioned = 0.0;
double nToBeProvisioned = 0.0;
double nServiceLength = 0.0;
double nNoOfEntitlement = 0.0;
double nNoRestofMonth = 0;
double nAvgAmount = 0.0;
SalaryMonthlyDetail oSalaryMonthlyDetail=null;
foreach (ESBElement oElement in this.ESBElements)
{
if (oElement.ElementID == ID.FromInteger((int)EnumSalaryItemCode.Basic_Salary))
nItemCode = EnumSalaryItemCode.Basic_Salary;
else
nItemCode = EnumSalaryItemCode.Allowance;
oSalaryMonthlyDetail = new SalaryMonthlyDetail();
oSalaryMonthlyDetail = oSalaryMonthlyDetails.Find(delegate(SalaryMonthlyDetail t) { return t.ItemCode == nItemCode && t.ItemID == oElement.ElementID.Integer && t.itemGroupCode == EnumSalaryGroup.Gross; });
if (oSalaryMonthlyDetail != null)
{
nESBAmount = nESBAmount + oSalaryMonthlyDetail.ChangedAmount;
nAvgAmount = nAvgAmount + oSalaryMonthlyDetail.ChangedAmount;
}
}
nServiceLength = oEmployee.ServiceYears(Ease.CoreV35.Utility.Global.DateFunctions.LastDateOfYear(Payroll.BO.SystemInformation.CurrentSysInfo.NextPayProcessDate));
nNoRestofMonth = Ease.CoreV35.Utility.Global.DateFunctions.DateDiff("m", Payroll.BO.SystemInformation.CurrentSysInfo.NextPayProcessDate, Ease.CoreV35.Utility.Global.DateFunctions.LastDateOfYear(Payroll.BO.SystemInformation.CurrentSysInfo.NextPayProcessDate))+1;
nProvisioned = 0.0;
//foreach(DataRow oRow in oDS.Tables[0].Rows)
//{
// if (oEmployee.ID.Integer == Convert.ToInt16(oRow[0].ToString()))
// {
// nProvisioned = Convert.ToDouble(oRow[1].ToString());
// break;
// }
//}
if (nServiceLength > MaxServiceLength)
nServiceLength = MaxServiceLength;
nNoOfEntitlement = ESBSlab.GetCalcualateNo(nServiceLength, oEmployee.PayrollTypeID.Integer);
if (nNoOfEntitlement <= 0.0)
nNoOfEntitlement = 1;
nToBeProvisioned = (nESBAmount) * nServiceLength * nNoOfEntitlement;
oESBProvision.Provision = Math.Round((nToBeProvisioned - nProvisioned) / nNoRestofMonth);
oESBProvision.Provision = GlobalFunctions.Round(oESBProvision.Provision);
}
public ID Save()
{
this.SetAuditTrailProperties();
return ESBDefinition.Service.Save(this);
}
public void Delete(ID id)
{
ESBDefinition.Service.Delete(id);
}
#endregion
}
#endregion
#region IESBDefinition Service
public interface IESBDefinitionService
{
ESBDefinition Get(ID id);
ESBDefinition GetByPayrollID(int nID);
ESBDefinition Get(int nID);
ObjectsTemplate<ESBDefinition> Get();
ObjectsTemplate<ESBDefinition> GetByPayrollType(int nPayrollTypeID);
ID Save(ESBDefinition item);
void Delete(ID id);
//
ObjectsTemplate<ESBElement> GetESBElement(int nESBID);
ID SaveESBElement(ESBElement item);
void DeleteESBElement(ID id);
//
ObjectsTemplate<ESBGrade> GetESBGrade(int nESBID);
ID SaveESBGrade(ESBGrade item);
void DeleteESBGrade(ID id);
//
ObjectsTemplate<ESBSlab> GetSlabs(int nESBID);
ID SaveESBSlab(ESBSlab item);
void DeleteESBSlab(ID id);
}
#endregion
#region ESBElement
[Serializable]
public class ESBElement :BasicBaseObject
{
#region Cache Store
private static Cache _cache = new Cache(typeof(ESBElement));
#endregion
#region Constructor
public ESBElement()
{
_elementType = EnumSalaryComponent.Basic;
_esbID = null;
_elementID = null;
}
#endregion
#region Properties
#region ESBID : ID
private ID _esbID;
public ID ESBID
{
get { return _esbID; }
set
{
_esbID = value;
}
}
#endregion
#region ESBID : ID
private ID _elementID;
public ID ElementID
{
get { return _elementID; }
set
{
_elementID = value;
}
}
#endregion
#region ElementType : EnumSalaryComponent
private EnumSalaryComponent _elementType;
public EnumSalaryComponent ElementType
{
get { return _elementType; }
set
{
_elementType = value;
}
}
#endregion
#endregion
#region Service Factory IESBDefinitionService : IESBDefinitionService
internal static IESBDefinitionService Service
{
get { return Services.Factory.CreateService<IESBDefinitionService>(typeof(IESBDefinitionService)); }
}
#endregion
#region Functions
public static ObjectsTemplate<ESBElement> GetESBElement(int nESBID)
{
#region Cache Header
ObjectsTemplate<ESBElement> oESBElements = _cache["Get", nESBID] as ObjectsTemplate<ESBElement>;
if (oESBElements != null)
return oESBElements;
#endregion
try
{
oESBElements = Service.GetESBElement(nESBID);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(oESBElements, "Get", nESBID);
#endregion
return oESBElements;
}
public ID SaveESBElement()
{
return ESBDefinition.Service.SaveESBElement(this);
}
public void DeleteESBElement(ID id)
{
ESBDefinition.Service.DeleteESBElement(id);
}
#endregion
}
#endregion
#region ESBGrade
[Serializable]
public class ESBGrade : BasicBaseObject
{
#region Cache Store
private static Cache _cache = new Cache(typeof(ESBGrade));
#endregion
#region Constructor
public ESBGrade()
{
_gradeID = null;
_esbID = null;
_grade = null;
}
#endregion
#region Properties
#region GradeID : ID
private ID _gradeID;
public ID GradeID
{
get { return _gradeID; }
set
{
_gradeID = value;
}
}
#endregion
#region GradeID : ID
private ID _esbID;
public ID ESBID
{
get { return _esbID; }
set
{
_esbID = value;
}
}
#endregion
#region grade : Grade
private Grade _grade;
public Grade Grade
{
get
{
if (_gradeID != null)
{
if (_gradeID.Integer > 0 && _grade == null)
{
_grade = new Grade();
_grade = Grade.Get(_gradeID);
}
}
return this._grade;
}
set
{
_grade = value;
}
}
#endregion
public static ObjectsTemplate<ESBGrade> GetESBGrade(int nESBID)
{
#region Cache Header
ObjectsTemplate<ESBGrade> oESBGrade = _cache["GetESBGrade", nESBID] as ObjectsTemplate<ESBGrade>;
if (oESBGrade != null)
return oESBGrade;
#endregion
try
{
oESBGrade = Service.GetESBGrade(nESBID);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(oESBGrade, "GetESBGrade", nESBID);
#endregion
return oESBGrade;
}
#region Service Factory IESBDefinitionService : IESBDefinitionService
internal static IESBDefinitionService Service
{
get { return Services.Factory.CreateService<IESBDefinitionService>(typeof(IESBDefinitionService)); }
}
#endregion
#endregion
#region Functions
public ID Save()
{
//this.SetAuditTrailProperties();
return ESBDefinition.Service.SaveESBGrade(this);
}
public void Delete(ID id)
{
ESBDefinition.Service.DeleteESBGrade(id);
}
#endregion
}
#endregion
#region ESBSlab
[Serializable]
public class ESBSlab : BasicBaseObject
{
#region Cache Store
private static Cache _cache = new Cache(typeof(ESBSlab));
#endregion
#region Constructor
public ESBSlab()
{
_calculateNo = 0.0;
_daysToConsider = 0.0;
_esbID = null;
_serviceYear = 0.0;
_uptoServiceYear = 0;
_esbDefinition = null;
}
#endregion
#region Properties
#region CalculateNo : double
private double _calculateNo;
public double CalculateNo
{
get { return _calculateNo; }
set
{
_calculateNo = value;
}
}
#endregion
#region DaysToConsider : double
private double _daysToConsider;
public double DaysToConsider
{
get { return _daysToConsider; }
set
{
_daysToConsider = value;
}
}
#endregion
#region ESBID : ID
private ID _esbID;
public ID ESBID
{
get { return _esbID; }
set
{
_esbID = value;
}
}
#endregion
#region ServiceYear : int
private double _serviceYear;
public double ServiceYear
{
get { return _serviceYear; }
set
{
_serviceYear = value;
}
}
#endregion
#region _esbDefinition : Grade
private ESBDefinition _esbDefinition;
public ESBDefinition ESBDefinition
{
get
{
if (_esbID != null)
{
if (_esbID.Integer > 0 && _esbDefinition == null)
{
_esbDefinition = new ESBDefinition();
_esbDefinition = ESBDefinition.Get(_esbID);
}
}
return this._esbDefinition;
}
set
{
_esbDefinition = value;
}
}
#endregion
#region UptoServiceYear : int
private int _uptoServiceYear;
public int UptoServiceYear
{
get { return _uptoServiceYear; }
set
{
_uptoServiceYear = value;
}
}
#endregion
#region Service Factory IESBDefinitionService : IESBDefinitionService
internal static IESBDefinitionService Service
{
get { return Services.Factory.CreateService<IESBDefinitionService>(typeof(IESBDefinitionService)); }
}
#endregion
#endregion
#region Functions
public static ObjectsTemplate<ESBSlab> GetSlabs(int nESBID)
{
#region Cache Header
ObjectsTemplate<ESBSlab> ESBSlab = _cache["GetSlabs", nESBID] as ObjectsTemplate<ESBSlab>;
if (ESBSlab != null)
return ESBSlab;
#endregion
try
{
ESBSlab = Service.GetSlabs(nESBID);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(ESBSlab, "GetSlabs", nESBID);
#endregion
return ESBSlab;
}
public static double GetCalcualateNo(double nServiceYear,int nPID)
{
ESBDefinition oItem= new ESBDefinition();
double n=0.0;
oItem = ESBDefinition.GetByPayrollID(nPID);
ObjectsTemplate<ESBSlab> oSlabs = new ObjectsTemplate<ESBSlab>();
oSlabs = ESBSlab.GetSlabs(oItem.ID.Integer);
foreach (ESBSlab oSl in oSlabs)
{
if (oSl.ServiceYear <= nServiceYear)
n = oSl.CalculateNo;
}
return n;
}
public static double GetCalcualateNo(double nServiceYear, ESBDefinition oESBDefinition)
{
ESBDefinition oItem = new ESBDefinition();
double n = 0.0;
oItem = ESBDefinition.Get(oESBDefinition.ID);
foreach (ESBSlab oSl in oItem.ESBSlabs)
{
if (oSl.ServiceYear <= nServiceYear)
n = oSl.CalculateNo;
}
return n;
}
public ID SaveESBSlab()
{
return ESBDefinition.Service.SaveESBSlab(this);
}
public void Delete(ID id)
{
ESBDefinition.Service.DeleteESBSlab(id);
}
#endregion
}
#endregion
}