using System; using System.Collections.Generic; using System.Linq; using System.Text; using Ease.CoreV35.Model; using Ease.CoreV35.Caching; namespace Payroll.BO { #region DailyOTProcess [Serializable] public class DailyOTProcess : AuditTrailBase { #region Cache Store private static Cache _cache = new Cache(typeof(DailyOTProcess)); #endregion #region Constructor public DailyOTProcess() { _termID = null; _value = 0; _employeeID = null; _workingDate = DateTime.MinValue; } #endregion #region Properties #region TermID : ID private ID _termID; public ID TermID { get { return _termID; } set { base.OnPropertyChange("TermID", _termID, value); _termID = value; } } #endregion #region value : int private double _value; public double Value { get { return _value; } set { base.OnPropertyChange("value", _value, value); _value = value; } } #endregion #region EmployeeID : ID private ID _employeeID; public ID EmployeeID { get { return _employeeID; } set { base.OnPropertyChange("EmployeeID", _employeeID, value); _employeeID = value; } } #endregion #region WorkingDate : DateTime private DateTime _workingDate; public DateTime WorkingDate { get { return _workingDate; } set { base.OnPropertyChange("workingdate", _workingDate, value); _workingDate = value; } } #endregion #region Service Factory IDailyOTProcessService : IDailyOTProcessService internal static IDailyOTProcessService Service { get { return Services.Factory.CreateService(typeof(IDailyOTProcessService)); } } #endregion public void Proecess(ObjectsTemplate attProcesses) { ObjectsTemplate processItems = new ObjectsTemplate(); ObjectsTemplate shifTerms = ShiftTerm.Get(); ObjectsTemplate employees = Employee.Get(); ObjectsTemplate shifts = Shift.Get(); double ExtraHour = 0; foreach (DailyAttnProcess attProcess in attProcesses) { if (attProcess.AttenType != EnumAttendanceType.Present) continue; Employee emp = employees.GetItem(attProcess.EmployeeID); if (emp == null && emp.IsEligibleOT == false) continue; Shift shift = shifts.GetItem(attProcess.ShiftID); if (shift == null) throw new ServiceException("shift not found for the employee:"); // find extra hour ExtraHour TimeSpan st = attProcess.OutTime - attProcess.InTime; ExtraHour = st.Hours; ShiftTerm oShiftTerm = ShiftTerm.GetByShiftID(attProcess.ShiftID); foreach (ShiftTermDetail item in oShiftTerm.ShiftTermDetail) { if (ExtraHour > 0) { DailyOTProcess otP = new DailyOTProcess(); otP.EmployeeID = attProcess.EmployeeID; otP.TermID = item.TermID; otP.WorkingDate = attProcess.AttnDate; otP.Value = (ExtraHour > item.Hour) ? item.Hour : ExtraHour; ExtraHour = ExtraHour - item.Hour; if (otP.Value > 0) { processItems.Add(otP); } } } } this.Save(processItems); } #endregion #region Functions public static DailyOTProcess Get(ID nID) { DailyOTProcess oDailyOTProcess = null; #region Cache Header oDailyOTProcess = (DailyOTProcess)_cache["Get", nID]; if (oDailyOTProcess != null) return oDailyOTProcess; #endregion oDailyOTProcess = DailyOTProcess.Service.Get(nID); #region Cache Footer _cache.Add(oDailyOTProcess, "Get", nID); #endregion return oDailyOTProcess; } public static ObjectsTemplate Get() { #region Cache Header ObjectsTemplate dailyOTProcesses = _cache["Get"] as ObjectsTemplate; if (dailyOTProcesses != null) return dailyOTProcesses; #endregion try { dailyOTProcesses = Service.Get(); } catch (ServiceException e) { throw new Exception(e.Message, e); } #region Cache Footer _cache.Add(dailyOTProcesses, "Get"); #endregion return dailyOTProcesses; } public ID Save() { return DailyOTProcess.Service.Save(this); } public void Save(ObjectsTemplate oDailyOTProcesses) { DailyOTProcess.Service.Save(oDailyOTProcesses); } public void Delete() { DailyOTProcess.Service.Delete(ID); } #endregion } #endregion #region IDailyOTProcess Service public interface IDailyOTProcessService { DailyOTProcess Get(ID id); ObjectsTemplate Get(); ID Save(DailyOTProcess item); void Save(ObjectsTemplate oDailyOTProcesses); void Delete(ID id); } #endregion }