537 lines
15 KiB
C#
537 lines
15 KiB
C#
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 TermParameter
|
|
|
|
[Serializable]
|
|
public class TermParameter : AuditTrailBase, ISetupManager
|
|
{
|
|
#region Cache Store
|
|
|
|
private static Cache _cache = new Cache(typeof(TermParameter));
|
|
|
|
#endregion
|
|
|
|
#region Constructor
|
|
|
|
public TermParameter()
|
|
{
|
|
_termID = ID.FromInteger(0);
|
|
_effectDate = DateTime.MinValue;
|
|
_amount = 0;
|
|
_type = EnumOverTimeType.NONE;
|
|
_term = null;
|
|
_TermEntityGrades = null;
|
|
//_manager = null;
|
|
_payrollTypeID = 0;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Internal Class
|
|
public class TermEntityGrade : AuditTrailBase
|
|
{
|
|
#region Cache Store
|
|
|
|
private static Cache _cache = new Cache(typeof(TermEntityGrade));
|
|
|
|
#endregion
|
|
|
|
#region Constructor
|
|
|
|
public TermEntityGrade()
|
|
{
|
|
_termEntityID = ID.FromInteger(0);
|
|
_gradeID = ID.FromInteger(0);
|
|
_grade = null;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Properties
|
|
|
|
#region termEntityID : ID
|
|
|
|
private ID _termEntityID;
|
|
public ID TermEntityID
|
|
{
|
|
get { return _termEntityID; }
|
|
set
|
|
{
|
|
base.OnPropertyChange<ID>("termEntityID", _termEntityID, value);
|
|
_termEntityID = 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 Grade: Grade
|
|
|
|
private Grade _grade;
|
|
public Grade Grade
|
|
{
|
|
get
|
|
{
|
|
if (_gradeID.Integer > 0 && _grade == null)
|
|
{
|
|
_grade = new Grade();
|
|
_grade = Grade.Get(_gradeID);
|
|
}
|
|
return this._grade;
|
|
}
|
|
set
|
|
{
|
|
_grade = value;
|
|
}
|
|
}
|
|
#endregion
|
|
#endregion
|
|
}
|
|
#endregion
|
|
|
|
#region Properties
|
|
|
|
#region TermID : ID
|
|
|
|
private ID _termID;
|
|
public ID TermID
|
|
{
|
|
get { return _termID; }
|
|
set
|
|
{
|
|
base.OnPropertyChange<ID>("TermID", _termID, value);
|
|
_termID = value;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region effectDate : DateTime
|
|
|
|
private DateTime _effectDate;
|
|
public DateTime EffectDate
|
|
{
|
|
get { return _effectDate; }
|
|
set
|
|
{
|
|
base.OnPropertyChange<DateTime>("effectDate", _effectDate, value);
|
|
_effectDate = value;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region amount : double
|
|
|
|
private double _amount;
|
|
public double Amount
|
|
{
|
|
get { return _amount; }
|
|
set
|
|
{
|
|
base.OnPropertyChange<double>("amount", _amount, value);
|
|
_amount = value;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region type : EnumOverTimeType
|
|
|
|
private EnumOverTimeType _type;
|
|
public EnumOverTimeType Type
|
|
{
|
|
get { return _type; }
|
|
set
|
|
{
|
|
base.OnPropertyChange<short>("type",(short) _type, (short)value);
|
|
_type = value;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region EntryType : String
|
|
|
|
private static string _EntryType = string.Empty;
|
|
public static string EntryType
|
|
{
|
|
get
|
|
{
|
|
return _EntryType;
|
|
}
|
|
set
|
|
{
|
|
_EntryType = value;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region PayrollTypeID : int
|
|
|
|
private int _payrollTypeID;
|
|
public int PayrollTypeID
|
|
{
|
|
get { return _payrollTypeID; }
|
|
set
|
|
{
|
|
base.OnPropertyChange<int>("PayrollTypeID", _payrollTypeID, value);
|
|
_payrollTypeID = value;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Term: Term
|
|
|
|
private Term _term;
|
|
public Term Term
|
|
{
|
|
get
|
|
{
|
|
if (_termID.Integer > 0 && _term == null)
|
|
{
|
|
_term = new Term();
|
|
_term = Term.Get(_termID);
|
|
}
|
|
return this._term;
|
|
}
|
|
set
|
|
{
|
|
_term = value;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region TermEntityGrade : TermEntityGrade
|
|
|
|
private ObjectsTemplate<TermParameter.TermEntityGrade> _TermEntityGrades = null;
|
|
public ObjectsTemplate<TermParameter.TermEntityGrade> TermEntityGrades
|
|
{
|
|
get
|
|
{
|
|
if (_TermEntityGrades == null && !this.ID.IsUnassigned && this.ID.Integer > 0)
|
|
{
|
|
_TermEntityGrades = TermParameter.GetGrades(this.ID);
|
|
}
|
|
return this._TermEntityGrades;
|
|
}
|
|
set
|
|
{
|
|
_TermEntityGrades = value;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region Service Factory ITermParameterService : ITermParameterService
|
|
|
|
internal static ITermParameterService Service
|
|
{
|
|
get { return Services.Factory.CreateService<ITermParameterService>(typeof(ITermParameterService)); }
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
#region Functions
|
|
|
|
public double ConvertToDailyRate(double nBasic, DateTime dMonthDate)
|
|
{
|
|
double amount = 0;
|
|
amount = nBasic / Convert.ToDouble(DateTime.DaysInMonth(dMonthDate.Year,dMonthDate.Month));
|
|
return amount;
|
|
}
|
|
|
|
public double ConvertToHourlyRate(double nBasic, DateTime dMonthDate)
|
|
{
|
|
double amount = 0;
|
|
int hours = ConfigurationManager.GetIntValue("overtime", "hoursonmonth", EnumConfigurationType.Logic);
|
|
if (hours <= 0) hours = 176;
|
|
double doubleHOur = Convert.ToDouble(hours);
|
|
amount = nBasic / doubleHOur;
|
|
return amount;
|
|
|
|
}
|
|
|
|
public double GetPayableAmount(EmployeeOverTime ot,double nBasic)
|
|
{
|
|
double nHour = ot.OTHours;
|
|
//switch (TermParameter.EntryType.ToUpper())
|
|
//{
|
|
// case "MINUTE":
|
|
// nHour = Math.Floor(ot.OTHours);
|
|
// nHour += (ot.OTHours - nHour) / 100 * 60;
|
|
// break;
|
|
// default:
|
|
// nHour = Math.Floor(ot.OTHours);
|
|
// nHour += (ot.OTHours - nHour) / 100 * 60;
|
|
// break;
|
|
//}
|
|
ot.OTHours = nHour;
|
|
switch (this.Type)
|
|
{
|
|
case EnumOverTimeType.AnyAmount:
|
|
return ot.OTHours;
|
|
case EnumOverTimeType.DailyBasicPercent:
|
|
return (this.ConvertToDailyRate(nBasic, ot.OTMonth) * ot.OTHours * ot.Value / 100);
|
|
case EnumOverTimeType.DailyFlatAmount:
|
|
return ot.OTHours*ot.Value;
|
|
case EnumOverTimeType.FixedAmount:
|
|
return ot.OTHours;
|
|
case EnumOverTimeType.HourlyBasicPercent:
|
|
return this.ConvertToHourlyRate(nBasic, ot.OTMonth) * ot.OTHours * ot.Value / 100;
|
|
case EnumOverTimeType.HourlyFlatAmount:
|
|
return ot.OTHours * this.Amount;
|
|
case EnumOverTimeType.HoursOfMonth:
|
|
break;
|
|
case EnumOverTimeType.Slab:
|
|
ObjectsTemplate<OTSlab> slabs= OTSlab.GetByTermID(ot.TermID);
|
|
double amount = 0;
|
|
if (slabs != null)
|
|
{
|
|
for (int i = 1; i < slabs.Count; i++)
|
|
{
|
|
amount = slabs[i].Amount;
|
|
if (slabs[i].Hours > Math.Round(ot.OTHours,0))
|
|
{
|
|
amount = slabs[i-1].Amount;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
return amount;
|
|
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
public static TermParameter Get(ID nID)
|
|
{
|
|
TermParameter oTermParameter = null;
|
|
#region Cache Header
|
|
oTermParameter = (TermParameter)_cache["Get", nID];
|
|
if (oTermParameter != null)
|
|
return oTermParameter;
|
|
#endregion
|
|
oTermParameter = TermParameter.Service.Get(nID);
|
|
#region Cache Footer
|
|
_cache.Add(oTermParameter, "Get", nID);
|
|
#endregion
|
|
return oTermParameter;
|
|
}
|
|
|
|
public static ObjectsTemplate<TermParameter.TermEntityGrade> GetGrades(ID tpID)
|
|
{
|
|
#region Cache Header
|
|
|
|
ObjectsTemplate<TermParameter.TermEntityGrade> termEntityGrades = _cache["Get", tpID] as ObjectsTemplate<TermParameter.TermEntityGrade>;
|
|
if (termEntityGrades != null)
|
|
return termEntityGrades;
|
|
|
|
#endregion
|
|
|
|
try
|
|
{
|
|
termEntityGrades = Service.GetGrades(tpID);
|
|
}
|
|
catch (ServiceException e)
|
|
{
|
|
throw new Exception(e.Message, e);
|
|
}
|
|
|
|
#region Cache Footer
|
|
|
|
_cache.Add(termEntityGrades, "Get", tpID);
|
|
|
|
#endregion
|
|
|
|
return termEntityGrades;
|
|
}
|
|
|
|
public static ObjectsTemplate<TermParameter> Get()
|
|
{
|
|
#region Cache Header
|
|
|
|
ObjectsTemplate<TermParameter> termParams = _cache["Get"] as ObjectsTemplate<TermParameter>;
|
|
if (termParams != null)
|
|
return termParams;
|
|
|
|
#endregion
|
|
|
|
try
|
|
{
|
|
termParams = Service.Get2(SystemInformation.CurrentSysInfo.PayrollTypeID);
|
|
}
|
|
catch (ServiceException e)
|
|
{
|
|
throw new Exception(e.Message, e);
|
|
}
|
|
|
|
#region Cache Footer
|
|
|
|
_cache.Add(termParams, "Get");
|
|
|
|
#endregion
|
|
|
|
return termParams;
|
|
}
|
|
|
|
public static ObjectsTemplate<TermParameter> GetByGradeID(ID nGradeID)
|
|
{
|
|
#region Cache Header
|
|
|
|
ObjectsTemplate<TermParameter> termParams = _cache["Get",nGradeID] as ObjectsTemplate<TermParameter>;
|
|
if (termParams != null)
|
|
return termParams;
|
|
|
|
#endregion
|
|
|
|
try
|
|
{
|
|
termParams = Service.GetByGradeID(nGradeID);
|
|
}
|
|
catch (ServiceException e)
|
|
{
|
|
throw new Exception(e.Message, e);
|
|
}
|
|
|
|
#region Cache Footer
|
|
|
|
_cache.Add(termParams, "Get",nGradeID);
|
|
|
|
#endregion
|
|
|
|
return termParams;
|
|
}
|
|
|
|
public ID Save()
|
|
{
|
|
this.SetAuditTrailProperties();
|
|
return TermParameter.Service.Save(this);
|
|
}
|
|
public void Delete()
|
|
{
|
|
TermParameter.Service.Delete(ID);
|
|
}
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="parameters"> All paramters of current payroll type</param>
|
|
/// <param name="employee"> employee</param>
|
|
/// <param name="TermID"> Term/OT basic IS</param>
|
|
/// <returns></returns>
|
|
public static TermParameter GetParameter(ObjectsTemplate<TermParameter> parameters, Employee employee, ID TermID)
|
|
{
|
|
// Get applicable parameter for the employee
|
|
List<int> paramerIDs = SetupManager.ApplicableParameters(employee, EnumParameterSetup.OT);
|
|
foreach (int i in paramerIDs)
|
|
{
|
|
foreach (TermParameter param in parameters)
|
|
{
|
|
if (param.ID.Integer == i && param.TermID.Integer == TermID.Integer)
|
|
return param;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ISetupManager Members
|
|
private ObjectsTemplate<SetupDetail> _setupDetails;
|
|
public ObjectsTemplate<SetupDetail> SetupDetails
|
|
{
|
|
get
|
|
{
|
|
return _setupDetails;
|
|
}
|
|
set
|
|
{
|
|
_setupDetails = value;
|
|
}
|
|
}
|
|
|
|
public EmployeeSetupParameter ApplicableParameters(Employee employee)
|
|
{
|
|
EmployeeSetupParameter empParameter = new EmployeeSetupParameter(EnumParameterSetup.OT);
|
|
empParameter.Employee = employee;
|
|
empParameter.ParameterIDs = SetupManager.ApplicableParameters(employee, EnumParameterSetup.OT);
|
|
return empParameter;
|
|
}
|
|
|
|
public List<EmployeeSetupParameter> ApplicableParameters(ObjectsTemplate<Employee> employees)
|
|
{
|
|
ObjectsTemplate<SetupDetail> details = SetupDetail.GetParameters(EnumParameterSetup.OT);
|
|
List<EnmSetupManagerTranType> types = SetupDetail.GetTypes(EnumParameterSetup.OT);
|
|
List<EmployeeSetupParameter> empParametes = new List<EmployeeSetupParameter>();
|
|
foreach (Employee emp in employees)
|
|
{
|
|
EmployeeSetupParameter empparameter = new EmployeeSetupParameter(EnumParameterSetup.OT);
|
|
empparameter.Employee = emp;
|
|
empparameter.ParameterIDs = SetupManager.ApplicableParameters(emp, EnumParameterSetup.OT,
|
|
types, details);
|
|
empParametes.Add(empparameter);
|
|
}
|
|
return empParametes;
|
|
}
|
|
public void FillMe(ID id)
|
|
{
|
|
TermParameter tpm = TermParameter.Get(id);
|
|
|
|
this.TermID = tpm.TermID;
|
|
this.EffectDate = tpm.EffectDate;
|
|
this.Amount = tpm.Amount;
|
|
this.Type = tpm.Type;
|
|
this.CreatedBy = tpm.CreatedBy;
|
|
this.CreatedDate = tpm.CreatedDate;
|
|
this.ModifiedBy = tpm.ModifiedBy;
|
|
this.ModifiedDate = tpm.ModifiedDate;
|
|
this.SetID(tpm.ID);
|
|
this.SetState(ObjectState.Saved);
|
|
}
|
|
#endregion
|
|
}
|
|
#endregion
|
|
|
|
#region ITermParameter Service
|
|
|
|
public interface ITermParameterService
|
|
{
|
|
TermParameter Get(ID id);
|
|
ObjectsTemplate<TermParameter> Get2(ID payrollTypeID);
|
|
ObjectsTemplate<TermParameter> GetByGradeID(ID nGradeID);
|
|
ObjectsTemplate<TermParameter.TermEntityGrade> GetGrades(ID ntpID);
|
|
ID Save(TermParameter item);
|
|
void Delete(ID id);
|
|
}
|
|
|
|
#endregion
|
|
}
|