CEL_Payroll/Payroll.BO/Attendence/BuyerDailyAttProcess.cs

707 lines
23 KiB
C#
Raw 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.Caching;
using Ease.CoreV35.Model;
using System.Data;
namespace Payroll.BO
{
#region BuyerDailyAttProcess
[Serializable]
public class BuyerDailyAttProcess : AuditTrailBase
{
#region Cache Store
private static Cache _cache = new Cache(typeof(BuyerDailyAttProcess));
#endregion
#region Constructor
public BuyerDailyAttProcess()
{
_employeeID = null;
_attnDate = DateTime.MinValue;
_shiftID = ID.FromInteger(0);
_inTime = DateTime.MinValue;
_outTime = DateTime.MinValue;
_attenType = 0;
_comments = string.Empty;
_isManualEntry = false;
_referenceID = null;
_employee = null;
_buyerID = null;
}
#endregion
#region Properties
#region employeeID : ID
private ID _employeeID;
public ID EmployeeID
{
get { return _employeeID; }
set
{
base.OnPropertyChange<ID>("employeeID", _employeeID, value);
_employeeID = value;
}
}
#endregion
#region attnDate : DateTime
private DateTime _attnDate;
public DateTime AttnDate
{
get { return _attnDate; }
set
{
base.OnPropertyChange<DateTime>("attnDate", _attnDate, value);
_attnDate = value;
}
}
#endregion
#region shiftID : ID
private ID _shiftID;
public ID ShiftID
{
get { return _shiftID; }
set
{
base.OnPropertyChange<ID>("shiftID", _shiftID, value);
_shiftID = value;
}
}
#endregion
#region inTime : DateTime
private DateTime _inTime;
public DateTime InTime
{
get { return _inTime; }
set
{
base.OnPropertyChange<DateTime>("inTime", _inTime, value);
_inTime = value;
}
}
#endregion
#region outTime : DateTime
private DateTime _outTime;
public DateTime OutTime
{
get { return _outTime; }
set
{
base.OnPropertyChange<DateTime>("outTime", _outTime, value);
_outTime = value;
}
}
#endregion
#region attenType : EnumAttendanceType
private EnumAttendanceType _attenType;
public EnumAttendanceType AttenType
{
get { return _attenType; }
set
{
base.OnPropertyChange<short>("attenType", (short)_attenType, (short)value);
_attenType = value;
}
}
#endregion
#region comments : string
private string _comments;
public string Comments
{
get { return _comments; }
set
{
base.OnPropertyChange<string>("comments", _comments, value);
_comments = value;
}
}
#endregion
#region isManualEntry : bool
private bool _isManualEntry;
public bool IsManualEntry
{
get { return _isManualEntry; }
set
{
base.OnPropertyChange<bool>("isManualEntry", _isManualEntry, value);
_isManualEntry = value;
}
}
#endregion
#region LateHour : double
private double _lateHour;
public double LateHour
{
get { return _lateHour; }
set
{
base.OnPropertyChange<double>("LateHour", _lateHour, value);
_lateHour = value;
}
}
#endregion
#region EarlyHour : double
private double _earlyHour;
public double EarlyHour
{
get { return _earlyHour; }
set
{
base.OnPropertyChange<double>("EarlyHour", _earlyHour, value);
_earlyHour = value;
}
}
#endregion
#region OTHour : double
private double _oTHour;
public double OTHour
{
get { return _oTHour; }
set
{
base.OnPropertyChange<double>("OTHour", _oTHour, value);
_oTHour = value;
}
}
#endregion
#region referenceID : ID
private ID _referenceID;
public ID ReferenceID
{
get { return _referenceID; }
set
{
base.OnPropertyChange<ID>("referenceID", _referenceID, value);
_referenceID = value;
}
}
#endregion
#region employeeID : ID
private ID _buyerID;
public ID BuyerID
{
get { return _buyerID; }
set
{
base.OnPropertyChange<ID>("BuyerID", _buyerID, value);
_buyerID = value;
}
}
#endregion
#region employee : Employee
private Employee _employee;
public Employee Employee
{
get
{
if (_employeeID.Integer > 0 && _employee == null)
{
_employee = new Employee();
_employee = Employee.Get(_employeeID);
}
return this._employee;
}
set
{
_employee = value;
}
}
#endregion
#region Shift : Shift
private Shift _shift;
public Shift Shift
{
get
{
if (_shiftID.Integer > 0 && _shift == null)
{
_shift = new Shift();
_shift = Shift.Get(_shiftID);
}
return this._shift;
}
set
{
_shift = value;
}
}
#endregion
#region Service Factory IBuyerDailyAttProcessService : IBuyerDailyAttProcessService
internal static IBuyerDailyAttProcessService Service
{
get { return Services.Factory.CreateService<IBuyerDailyAttProcessService>(typeof(IBuyerDailyAttProcessService)); }
}
#endregion
#endregion
#region Functions
public static BuyerDailyAttProcess Get(ID nID)
{
BuyerDailyAttProcess oBuyerDailyAttProcess = null;
#region Cache Header
oBuyerDailyAttProcess = (BuyerDailyAttProcess)_cache["Get", nID];
if (oBuyerDailyAttProcess != null)
return oBuyerDailyAttProcess;
#endregion
oBuyerDailyAttProcess = BuyerDailyAttProcess.Service.Get(nID);
#region Cache Footer
_cache.Add(oBuyerDailyAttProcess, "Get", nID);
#endregion
return oBuyerDailyAttProcess;
}
public static BuyerDailyAttProcess GetDailyEmployeeAbsent(ID empID, DateTime dateTime, ID buyerID)
{
BuyerDailyAttProcess oBuyerDailyAttProcess = null;
#region Cache Header
oBuyerDailyAttProcess = (BuyerDailyAttProcess)_cache["GetDailyEmployeeAbsent", empID, dateTime, buyerID];
if (oBuyerDailyAttProcess != null)
return oBuyerDailyAttProcess;
#endregion
oBuyerDailyAttProcess = BuyerDailyAttProcess.Service.GetDailyEmployeeAbsent(empID, dateTime, buyerID);
#region Cache Footer
_cache.Add(oBuyerDailyAttProcess, "Get", "GetDailyEmployeeAbsent", empID, dateTime, buyerID);
#endregion
return oBuyerDailyAttProcess;
}
public static ObjectsTemplate<BuyerDailyAttProcess> Get()
{
#region Cache Header
ObjectsTemplate<BuyerDailyAttProcess> buyerDailyAttnProcesses = _cache["Get"] as ObjectsTemplate<BuyerDailyAttProcess>;
if (buyerDailyAttnProcesses != null)
return buyerDailyAttnProcesses;
#endregion
try
{
buyerDailyAttnProcesses = Service.Get();
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(buyerDailyAttnProcesses, "Get");
#endregion
return buyerDailyAttnProcesses;
}
public static ObjectsTemplate<BuyerDailyAttProcess> Get(DateTime attnDate)
{
#region Cache Header
ObjectsTemplate<BuyerDailyAttProcess> buyerDailyAttnProcesses = _cache["Get", attnDate] as ObjectsTemplate<BuyerDailyAttProcess>;
if (buyerDailyAttnProcesses != null)
return buyerDailyAttnProcesses;
#endregion
try
{
buyerDailyAttnProcesses = Service.Get(attnDate);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(buyerDailyAttnProcesses, "Get", attnDate);
#endregion
return buyerDailyAttnProcesses;
}
public static ObjectsTemplate<BuyerDailyAttProcess> GetManualEntry(DateTime attnDate)
{
#region Cache Header
ObjectsTemplate<BuyerDailyAttProcess> buyerDailyAttnProcesses = _cache["GetManualEntry", attnDate] as ObjectsTemplate<BuyerDailyAttProcess>;
if (buyerDailyAttnProcesses != null)
return buyerDailyAttnProcesses;
#endregion
try
{
buyerDailyAttnProcesses = Service.GetManualEntry(attnDate);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(buyerDailyAttnProcesses, "GetManualEntry", attnDate);
#endregion
return buyerDailyAttnProcesses;
}
public static ObjectsTemplate<BuyerDailyAttProcess> Get(ID empID, DateTime fromDate, DateTime toDate, ID buyerID)
{
#region Cache Header
ObjectsTemplate<BuyerDailyAttProcess> buyerDailyAttnProcesses = _cache["Get", empID, fromDate, toDate, buyerID] as ObjectsTemplate<BuyerDailyAttProcess>;
if (buyerDailyAttnProcesses != null)
return buyerDailyAttnProcesses;
#endregion
try
{
buyerDailyAttnProcesses = Service.Get(empID, fromDate, toDate, buyerID);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(buyerDailyAttnProcesses, "Get", empID, fromDate, toDate, buyerID);
#endregion
return buyerDailyAttnProcesses;
}
public static ObjectsTemplate<BuyerDailyAttProcess> Get(DateTime attnDate, ID shiftID, EnumAttendanceType attnType)
{
#region Cache Header
ObjectsTemplate<BuyerDailyAttProcess> buyerDailyAttnProcesses = _cache["Get", attnDate, shiftID, attnType] as ObjectsTemplate<BuyerDailyAttProcess>;
if (buyerDailyAttnProcesses != null)
return buyerDailyAttnProcesses;
#endregion
try
{
buyerDailyAttnProcesses = Service.Get(attnDate, shiftID, attnType);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(buyerDailyAttnProcesses, "Get", attnDate, shiftID, attnType);
#endregion
return buyerDailyAttnProcesses;
}
public ID Save()
{
this.SetAuditTrailProperties();
return BuyerDailyAttProcess.Service.Save(this);
}
public static void Save(ObjectsTemplate<BuyerDailyAttProcess> _dAttnProcessess, bool IsCounterClock)
{
foreach (BuyerDailyAttProcess dAttnProcess in _dAttnProcessess)
{
dAttnProcess.SetAuditTrailProperties();
}
BuyerDailyAttProcess.Service.Save(_dAttnProcessess, IsCounterClock);
}
//public void Process(DateTime Attdate)
//{
// ObjectsTemplate<Employee> employees = Employee.Get();
// //ObjectsTemplate<AttnRawData> attRawdatas = AttnRawData.Get(Attdate);// get raw data by a date and order by date, employee, punchTime
// ObjectsTemplate<DailyAttnProcess> dailyattProcesses = new ObjectsTemplate<DailyAttnProcess>();
// ObjectsTemplate<EmployeeOutsideDuty> outSideDuties = EmployeeOutsideDuty.Get(Attdate); // get transaction by the a rate
// ObjectsTemplate<MonthlyWorkPlan> monthlyWorkPlans = MonthlyWorkPlan.Get(Attdate); // get workplans by the date
// ObjectsTemplate<LeaveEntry> leaves = LeaveEntry.Get(Attdate); // workplans by the date
// ObjectsTemplate<BuyerSetup> buyers = BuyerSetup.Get();
// #region BuyerWiseProcess
// foreach (BuyerSetup buyer in buyers)
// {
// ObjectsTemplate<BuyerDailyAttProcess> bDailyattProcesses = new ObjectsTemplate<BuyerDailyAttProcess>();
// foreach (Employee emp in employees)
// {
// BuyerDailyAttProcess bAttnProcess = new BuyerDailyAttProcess();
// bAttnProcess.BuyerID = buyer.ID;
// bAttnProcess.AttnDate = Attdate;
// bAttnProcess.EmployeeID = emp.ID;
// bAttnProcess.IsManualEntry = false;
// List<AttnRawData> empAttnDatas = null;
// EmployeeOutsideDuty empOutsideDuty = null;
// LeaveEntry empLeaveEntry = null;
// if (attRawdatas != null && attRawdatas.Count > 0)
// {
// var attnDatas = from AttnRawData item in attRawdatas
// where item.EmployeeID == emp.ID
// select item;
// if (attnDatas.ToList().Count > 0)
// {
// empAttnDatas = attnDatas.ToList();
// }
// }
// if (outSideDuties != null && outSideDuties.Count > 0)
// {
// var outSideDuty = from EmployeeOutsideDuty item in outSideDuties
// where item.EmployeeID == emp.ID
// select item;
// if (outSideDuty.ToList().Count > 0)
// {
// empOutsideDuty = outSideDuty.FirstOrDefault();
// }
// }
// if (leaves != null && leaves.Count > 0)
// {
// var leave = from LeaveEntry item in leaves
// where item.EmpID == emp.ID.Integer
// select item;
// if (leave.ToList().Count > 0)
// {
// empLeaveEntry = leave.FirstOrDefault();
// }
// }
// if (empAttnDatas != null)
// {
// bAttnProcess.InTime = empAttnDatas[0].PunchTime;
// bAttnProcess.OutTime = empAttnDatas[empAttnDatas.Count - 1].PunchTime;
// if (monthlyWorkPlans != null && monthlyWorkPlans.Count > 0)
// {
// var monthlyWorkPlan = from MonthlyWorkPlan item in monthlyWorkPlans
// where item.EmployeeID == emp.ID
// select item;
// if (monthlyWorkPlan != null)
// {
// MonthlyWorkPlan empMonthlyWorkPlan = monthlyWorkPlan.FirstOrDefault();
// if (empMonthlyWorkPlan.ShiftID.Integer != 0)
// {
// bAttnProcess.ShiftID = empMonthlyWorkPlan.ShiftID;
// bAttnProcess.AttenType = GetAttnType(bAttnProcess.InTime, bAttnProcess.OutTime, bAttnProcess.ShiftID);
// if (bAttnProcess.AttenType == EnumAttendanceType.Late)
// {
// bAttnProcess.LateHour = _lateHour;
// }
// }
// else if (empMonthlyWorkPlan.HolidayID.Integer != 0)
// {
// bAttnProcess.AttenType = EnumAttendanceType.Holiday;
// bAttnProcess.ReferenceID = empMonthlyWorkPlan.HolidayID;
// }
// else
// {
// bAttnProcess.AttenType = EnumAttendanceType.Present;
// }
// }
// }
// }
// else if (empOutsideDuty != null)
// {
// bAttnProcess.AttenType = EnumAttendanceType.OutSideDuty;
// bAttnProcess.ReferenceID = empOutsideDuty.ID;
// }
// else if (empLeaveEntry != null)
// {
// bAttnProcess.AttenType = EnumAttendanceType.Leave;
// bAttnProcess.ReferenceID = empLeaveEntry.ID;
// }
// else
// {
// bAttnProcess.AttenType = EnumAttendanceType.Absent;
// }
// bDailyattProcesses.Add(bAttnProcess);
// }
// BuyerDailyAttProcess.Save(bDailyattProcesses);
// }
// #endregion
//}
public EnumAttendanceType GetAttnType(DateTime empInTime, DateTime empOutTime, ID ShiftID)
{
TimeSpan EmpInTime = empInTime.TimeOfDay;
Shift shift = Shift.Get(ShiftID);
TimeSpan shiftInTime = shift.InTime.TimeOfDay;
TimeSpan shiftInTimeWithLatehour = shift.InTime.TimeOfDay.Add(TimeSpan.FromMinutes(shift.LateCalcualtion));
TimeSpan EmpOutTime = empOutTime.TimeOfDay;
TimeSpan shiftIOutTimeWithEarlyExit = shift.OutTime.TimeOfDay.Subtract(TimeSpan.FromMinutes(shift.EarlyExitBefore));
if (EmpInTime >= shiftInTime && EmpInTime <= shiftInTimeWithLatehour)
{
return EnumAttendanceType.Delay;
}
else if (EmpInTime >= shiftInTimeWithLatehour)
{
TimeSpan lateBy = EmpInTime - shiftInTimeWithLatehour;
_lateHour = Convert.ToDouble(lateBy.Hours + "." + lateBy.Minutes);
return EnumAttendanceType.Late;
}
else if (EmpOutTime >= shiftIOutTimeWithEarlyExit)
{
TimeSpan earlyBy = shift.OutTime.TimeOfDay - EmpOutTime;
_earlyHour = Convert.ToDouble(earlyBy.Hours + "." + earlyBy.Minutes);
return EnumAttendanceType.Early;
}
return EnumAttendanceType.Present;
}
public void Delete()
{
BuyerDailyAttProcess.Service.Delete(ID);
}
public static DataSet GetMonthlyAttn(DateTime dFromDate, DateTime dToDate, ID buyerID, string sEmpID)
{
DataSet monthlyAttn = null;
try
{
monthlyAttn = Service.GetMonthlyAttn(dFromDate, dToDate, buyerID, sEmpID);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
return monthlyAttn;
}
public static DataSet GetDailyInOut(DateTime attndate, ID buyerID, string sEmpID)
{
DataSet dailyInOut = null;
try
{
dailyInOut = Service.GetDailyInOut(attndate, buyerID, sEmpID);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
return dailyInOut;
}
public static DataSet GetMonthlyDetail(DateTime dFromDate, DateTime dToDate, ID buyerID, string sEmpID)
{
DataSet monthlyDetail = null;
try
{
monthlyDetail = Service.GetMonthlyDetail(dFromDate, dToDate, buyerID, sEmpID);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
return monthlyDetail;
}
public static DataSet GetDailyAbsent(DateTime attndate, ID buyerID, string sEmpID)
{
DataSet dailyAbsent = null;
try
{
dailyAbsent = Service.GetDailyAbsent(attndate, buyerID, sEmpID);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
return dailyAbsent;
}
public static DataSet GetMonthlyAttnData(DateTime attnMonth, ID empID)
{
DataSet monthlyDataBuyreWise = null;
try
{
monthlyDataBuyreWise = Service.GetMonthlyAttnData(attnMonth, empID);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
return monthlyDataBuyreWise;
}
#endregion
}
#endregion
#region IBuyerDailyAttProcess Service
public interface IBuyerDailyAttProcessService
{
BuyerDailyAttProcess Get(ID id);
BuyerDailyAttProcess GetDailyEmployeeAbsent(ID empID, DateTime dateTime, ID buyerID);
ObjectsTemplate<BuyerDailyAttProcess> Get();
ObjectsTemplate<BuyerDailyAttProcess> Get(DateTime attnDate);
ObjectsTemplate<BuyerDailyAttProcess> GetManualEntry(DateTime attnDate);
ObjectsTemplate<BuyerDailyAttProcess> Get(ID empID, DateTime fromDate, DateTime toDate, ID buyerID);
ObjectsTemplate<BuyerDailyAttProcess> Get(DateTime attnDate, ID shiftID, EnumAttendanceType attnType);
ID Save(BuyerDailyAttProcess item);
void Save(ObjectsTemplate<BuyerDailyAttProcess> _dAttnProcessess, bool IsCounterClock);
void Delete(ID id);
DataSet GetMonthlyAttn(DateTime dFromDate, DateTime dToDate, ID buyerID, string sEmpID);
DataSet GetDailyInOut(DateTime attndate, ID buyerID, string sEmpID);
DataSet GetMonthlyDetail(DateTime dFromDate, DateTime dToDate, ID buyerID, string sEmpID);
DataSet GetDailyAbsent(DateTime attndate, ID buyerID, string sEmpID);
DataSet GetMonthlyAttnData(DateTime attnMonth, ID empID);
}
#endregion
}