264 lines
7.6 KiB
C#
264 lines
7.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using Ease.CoreV35.Caching;
|
|
using Ease.CoreV35.Model;
|
|
using System.Data;
|
|
|
|
namespace Payroll.BO
|
|
{
|
|
#region ShiftTerm
|
|
|
|
[Serializable]
|
|
public class ShiftTerm : AuditTrailBase
|
|
{
|
|
#region Cache Store
|
|
|
|
private static Cache _cache = new Cache(typeof(ShiftTerm));
|
|
|
|
#endregion
|
|
|
|
#region Constructor
|
|
|
|
public ShiftTerm()
|
|
{
|
|
_shiftID = null;
|
|
_weekendTermID = null;
|
|
_holidayTermID = null;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Properties
|
|
|
|
#region shiftID : ID
|
|
|
|
private ID _shiftID;
|
|
public ID ShiftID
|
|
{
|
|
get { return _shiftID; }
|
|
set
|
|
{
|
|
base.OnPropertyChange<ID>("shiftID", _shiftID, value);
|
|
_shiftID = value;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region weekendTermID : ID
|
|
|
|
private ID _weekendTermID;
|
|
public ID WeekendTermID
|
|
{
|
|
get { return _weekendTermID; }
|
|
set
|
|
{
|
|
base.OnPropertyChange<ID>("weekendTermID", _weekendTermID, value);
|
|
_weekendTermID = value;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region holidayTermID : ID
|
|
|
|
private ID _holidayTermID;
|
|
public ID HolidayTermID
|
|
{
|
|
get { return _holidayTermID; }
|
|
set
|
|
{
|
|
base.OnPropertyChange<ID>("holidayTermID", _holidayTermID, value);
|
|
_holidayTermID = value;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Shift Term Detail : Shift Term Detail
|
|
private ObjectsTemplate<ShiftTermDetail> _shiftTermDetail;
|
|
public ObjectsTemplate<ShiftTermDetail> ShiftTermDetail
|
|
{
|
|
get
|
|
{
|
|
if (_shiftTermDetail == null)
|
|
{
|
|
_shiftTermDetail = Payroll.BO.ShiftTermDetail.GetByShiftTermID(this.ID);
|
|
}
|
|
return _shiftTermDetail;
|
|
}
|
|
set
|
|
{
|
|
_shiftTermDetail = value;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Service Factory IShiftTermService : IShiftTermService
|
|
|
|
internal static IShiftTermService Service
|
|
{
|
|
get { return Services.Factory.CreateService<IShiftTermService>(typeof(IShiftTermService)); }
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
#region Functions
|
|
|
|
public static ShiftTerm Get(ID nID)
|
|
{
|
|
ShiftTerm oShiftTerm = null;
|
|
#region Cache Header
|
|
oShiftTerm = (ShiftTerm)_cache["Get", nID];
|
|
if (oShiftTerm != null)
|
|
return oShiftTerm;
|
|
#endregion
|
|
oShiftTerm = ShiftTerm.Service.Get(nID);
|
|
#region Cache Footer
|
|
_cache.Add(oShiftTerm, "Get", nID);
|
|
#endregion
|
|
return oShiftTerm;
|
|
}
|
|
|
|
public static ShiftTerm GetByShiftID(ID shiftID)
|
|
{
|
|
ShiftTerm oShiftTerm = null;
|
|
#region Cache Header
|
|
oShiftTerm = (ShiftTerm)_cache["GetByShiftID", shiftID];
|
|
if (oShiftTerm != null)
|
|
return oShiftTerm;
|
|
#endregion
|
|
oShiftTerm = ShiftTerm.Service.GetByShiftID(shiftID);
|
|
#region Cache Footer
|
|
_cache.Add(oShiftTerm, "GetByShiftID", shiftID);
|
|
#endregion
|
|
return oShiftTerm;
|
|
}
|
|
public static ObjectsTemplate<ShiftTerm> Get()
|
|
{
|
|
#region Cache Header
|
|
ObjectsTemplate<ShiftTerm> shiftTerms = _cache["Get"] as ObjectsTemplate<ShiftTerm>;
|
|
if (shiftTerms != null)
|
|
return shiftTerms;
|
|
#endregion
|
|
try
|
|
{
|
|
shiftTerms = Service.Get();
|
|
}
|
|
catch (ServiceException e)
|
|
{
|
|
throw new Exception(e.Message, e);
|
|
}
|
|
#region Cache Footer
|
|
_cache.Add(shiftTerms, "Get");
|
|
#endregion
|
|
return shiftTerms;
|
|
}
|
|
public ID Save()
|
|
{
|
|
this.SetAuditTrailProperties();
|
|
return ShiftTerm.Service.Save(this);
|
|
}
|
|
public void Delete()
|
|
{
|
|
ShiftTerm.Service.Delete(ID);
|
|
}
|
|
|
|
public DataSet GetEmpOT(DateTime date, ID termID)
|
|
{
|
|
DataSet empOT = null;
|
|
|
|
try
|
|
{
|
|
empOT = Service.GetEmpOT(date, termID);
|
|
}
|
|
catch (ServiceException e)
|
|
{
|
|
throw new Exception(e.Message, e);
|
|
}
|
|
|
|
return empOT;
|
|
}
|
|
|
|
public void PrepareOT(DateTime date)
|
|
{
|
|
try
|
|
{
|
|
ObjectsTemplate<Term> terms = Term.Get(EnumStatus.Active);
|
|
ObjectsTemplate<EmployeeOverTime> empOTs = new ObjectsTemplate<EmployeeOverTime>();
|
|
EmployeeOverTime empOT = new EmployeeOverTime();
|
|
TermParameter oTermParamerer = null;
|
|
ObjectsTemplate<TermParameter> oTermParamerers = TermParameter.Get();
|
|
ObjectsTemplate<Employee> employees = Employee.Get();
|
|
Employee employee = null;
|
|
foreach (Term trm in terms)
|
|
{
|
|
DataSet EmpOTHours = this.GetEmpOT(date, trm.ID);
|
|
|
|
foreach (DataRow Dr in EmpOTHours.Tables[0].Rows)
|
|
{
|
|
empOT = new EmployeeOverTime();
|
|
|
|
empOT.TermID = trm.ID;
|
|
empOT.OTHours = Convert.ToDouble(Dr["TotalOT"]);
|
|
if (empOT.OTHours <= 0) continue;
|
|
|
|
empOT.EmployeeID = ID.FromInteger(Convert.ToInt32(Dr["EmployeeID"]));
|
|
employee = employees.GetItem(empOT.EmployeeID);
|
|
if (employee == null) continue;
|
|
if (employee.IsEligibleOT == false) continue;
|
|
|
|
oTermParamerer = TermParameter.GetParameter(oTermParamerers, employee, trm.ID);
|
|
try
|
|
{
|
|
if (oTermParamerer == null)
|
|
throw new ServiceException("Invalid Parameter, Term parameter/rule not found for the employee:" + employee.EmployeeNo);
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
empOT.TermParameterID = oTermParamerer.ID;
|
|
empOT.Value = oTermParamerer.Amount;
|
|
empOT.MonthDate = Payroll.BO.SystemInformation.CurrentSysInfo.NextPayProcessDate;
|
|
empOT.OTMonth = GlobalFunctions.LastDateOfMonth(date);
|
|
empOT.PayrollTypeID = employee.PayrollTypeID;
|
|
empOT.OTMonthBasic = employee.BasicSalary;
|
|
if (empOT.OTHours > 0)
|
|
empOTs.Add(empOT);
|
|
}
|
|
}
|
|
|
|
EmployeeOverTime.Save(empOTs);
|
|
}
|
|
catch (ServiceException e)
|
|
{
|
|
throw new Exception(e.Message, e);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region IShiftTerm Service
|
|
|
|
public interface IShiftTermService
|
|
{
|
|
ShiftTerm Get(ID id);
|
|
ObjectsTemplate<ShiftTerm> Get();
|
|
ShiftTerm GetByShiftID(ID shiftID);
|
|
ID Save(ShiftTerm item);
|
|
void Delete(ID id);
|
|
DataSet GetEmpOT(DateTime date, ID termID);
|
|
}
|
|
|
|
#endregion
|
|
}
|