EchoTex_Payroll/HRM.BO/Leave/Leave.cs

355 lines
13 KiB
C#
Raw Permalink Normal View History

2024-10-14 10:01:49 +06:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ease.Core;
using Ease.Core.Model;
using System.Data;
namespace HRM.BO
{
#region Leave
public class Leave : BasicBaseObject
{
#region Constructor
public Leave()
{
Code = "";
Description = "";
DescriptionInBangla = "";
RemarksNeeded = false;
IsEarnedLeave = false;
CancelOnApprovalLeaveEntry = false;
Status = EnumStatus.Active;
BalanceRoundofDigit = 1;
//#### PayrollTypeID = SystemInformation.CurrentSysInfo.PayrollTypeID;
}
#endregion
#region Properties
public string Code { get; set; }
public string Description { get; set; }
public string DescriptionInBangla { get; set; }
public bool RemarksNeeded { get; set; }
public bool DependsOnHoliday { get; set; }
public EnumGender ApplicableFor { get; set; }
public bool IsGenderMatch(Employee oEmployee)
{
if (this.ApplicableFor == oEmployee.Gender ||
this.ApplicableFor == EnumGender.Other)
return true;
else return false;
}
public bool IsBalanceCalculationNeeded { get; set; }
public bool IsEarnedLeave { get; set; }
public bool IsAttachmentNeeded { get; set; }
public bool AutoLeaveReason { get; set; }
private bool _isHalfLeave = false;
public bool IsHalfDayLeave
{
get { return _isHalfLeave; }
set { _isHalfLeave = value; }
}
private bool _isCompensatoryLeave = false;
public bool IsCompensatoryLeave
{
get { return _isCompensatoryLeave; }
set { _isCompensatoryLeave = value; }
}
public int PayrollTypeID { get; set; }
public int AttachmentMaxDays { get; set; }
public bool IsLFA { get; set; }
public int LfaMaxDays { get; set; }
public bool AllowNegativeBalance { get; set; }
public int MaxConsequentDays { get; set; }
public bool IsPreApproval { get; set; }
public int PreApprovalDays { get; set; }
public bool IsSelfCancellation { get; set; }
public int SelfCancellationDays { get; set; }
public bool CancelOnApprovalLeaveEntry { get; set; }
public bool HasMinimumDays { get; set; }
public int MinimumDays { get; set; }
public int BalanceRoundofDigit { get; set; }
#endregion
//public double CalculateTotalDays(DateTime stDate, DateTime endDate, int locationID)
//{
// int nTotalDays = 0;
// int nCount = 0;
// TimeSpan oSpan = endDate.Subtract(stDate);
// nTotalDays = oSpan.Days + 1;
// return (nTotalDays - nCount);
//}
//public static double GetApplicableDays(Leave oLeave, Employee oEmployee, DateTime FromDate, DateTime ToDate, bool IsHalfDay = false)
//{
// if (FromDate == DateTime.MinValue || ToDate == DateTime.MinValue) return 0;
// if (FromDate.Date > ToDate.Date) return 0;
// if (oLeave == null) return 0;
// if (oEmployee == null) return 0;
// int nDays = 0;
// bool bIgnoreHoliday = false;
// LeaveParameter oLeaveParam = LeaveParameter.ApplicableParams(oEmployee).FirstOrDefault(x => x.LeaveId == oLeave.ID.Integer);
// bIgnoreHoliday = oLeaveParam == null ? false : oLeaveParam.IgnoreHoliday;
// EmployeeWorkPlanSetup oSetup = EmployeeWorkPlanSetup.GetByEmpID(oEmployee.ID);
// List<AttnNationalHoliday> _attnNationalHolidays = AttnNationalHoliday.GetByMonth(FromDate.Date, ToDate.Date);
// AttnNationalHoliday holiday = null;
// if (oSetup != null)
// {
// WorkPlanGroup workPlanGroup = WorkPlanGroup.Get(oSetup.WorkPlanGroupID);
// List<HolidayCalendar> oItems = HolidayCalendar.GetNationalHolidays();
// DateTime dtStart = FromDate.Date;
// for (int i = 0; dtStart <= ToDate.Date; i++)
// {
// holiday = AttnNationalHoliday.GetHoliday(_attnNationalHolidays, dtStart.Date, oEmployee.LocationID, workPlanGroup.ID);
// if (bIgnoreHoliday)
// {
// dtStart = dtStart.AddDays(1);
// nDays++;
// }
// else
// {
// if (workPlanGroup.WeekEndOn != null && dtStart.ToString("dddd").ToLower() == workPlanGroup.WeekEndOn.ToString().ToLower())
// {
// dtStart = dtStart.AddDays(1);
// continue;
// }
// else if (workPlanGroup.WeekEndOn2 != null && dtStart.ToString("dddd").ToLower() == workPlanGroup.WeekEndOn2.ToString().ToLower())
// {
// dtStart = dtStart.AddDays(1);
// continue;
// }
// else if (holiday != null)
// {
// dtStart = dtStart.AddDays(1);
// continue;
// }
// else
// {
// dtStart = dtStart.AddDays(1);
// nDays++;
// }
// }
// }
// return nDays > 0 ? (IsHalfDay ? (nDays - 0.5) : nDays) : 0;
// }
// else
// {
// int nDiff = (int)((ToDate.Date.Ticks - FromDate.Date.Ticks) / TimeSpan.TicksPerDay) + 1;
// List<HolidayCalendar> oItems = HolidayCalendar.GetHoliDays(oEmployee.LocationID.Integer);
// nDays = oItems.Where(x => x.HolidayDate.Date >= FromDate.Date && x.HolidayDate.Date <= ToDate.Date && bIgnoreHoliday).Count();
// return (nDiff - nDays) > 0 ? (IsHalfDay ? (nDiff - nDays) - 0.5 : (nDiff - nDays)) : 0;
// }
//}
//#region Functions
//public string[] InputValidator()
//{
// string[] sErrorString = new string[2];
// if (this.Code == "")
// {
// sErrorString[0] = "Code can not be empty";
// sErrorString[1] = "Code";
// return sErrorString;
// }
// if (this.Description == "")
// {
// sErrorString[0] = "Description can not be empty";
// sErrorString[1] = "Description";
// return sErrorString;
// }
// if (this.IsCompensatoryLeave && this.IsEarnedLeave )
// {
// sErrorString[0] = "Compensatory Leave and Earned Leave cannot be select together.";
// sErrorString[1] = "Error";
// return sErrorString;
// }
// if (this.ID.IsUnassigned)
// {
// List<Leave> oLeaves = Leave.Get(EnumStatus.Active);
// if (this.IsCompensatoryLeave)
// {
// Leave oleave = oLeaves.Find(delegate(Leave ol) { return ol.IsCompensatoryLeave == this.IsCompensatoryLeave; });
// if (oleave != null)
// {
// sErrorString[0] = "Compensatory Leave already created.";
// sErrorString[1] = "Error";
// return sErrorString;
// }
// }
// if (this.IsEarnedLeave)
// {
// Leave oleave = oLeaves.Find(delegate(Leave ol) { return ol.IsEarnedLeave == this.IsEarnedLeave; });
// if (oleave != null)
// {
// sErrorString[0] = "Earned Leave already created.";
// sErrorString[1] = "Error";
// return sErrorString;
// }
// }
// }
// sErrorString = null;
// return sErrorString;
//}
//public Leave Get(ID nLeaveID)
//{
// Leave oLeave = null;
// #region Cache Header
// oLeave = (Leave)_cache["Get", nLeaveID];
// if (oLeave != null)
// return oLeave;
// #endregion
// oLeave = Leave.Service.Get(nLeaveID,SystemInformation.CurrentSysInfo.PayrollTypeID.Integer);
// #region Cache Footer
// _cache.Add(oLeave, "Get", nLeaveID);
// #endregion
// return oLeave;
//}
//public Leave GetIDByName(string sLeave)
//{
// Leave oLeave = null;
// #region Cache Header
// oLeave = (Leave)_cache["Get", sLeave];
// if (oLeave != null)
// return oLeave;
// #endregion
// oLeave = Leave.Service.GetIDByName(sLeave,SystemInformation.CurrentSysInfo.PayrollTypeID.Integer);
// #region Cache Footer
// _cache.Add(oLeave, "Get", sLeave);
// #endregion
// return oLeave;
//}
//public Leave GetIDByCode(string sLeave)
//{
// Leave oLeave = null;
// LeaveService
// oLeave = Leave.Service.GetIDByCode(sLeave, SystemInformation.CurrentSysInfo.PayrollTypeID);
// return oLeave;
//}
//public ID Save()
//{
// this.SetAuditTrailProperties();
// return Leave.Service.Save(this);
//}
//public void Delete(ID id)
//{
// Leave.Service.Delete(id,SystemInformation.CurrentSysInfo.PayrollTypeID.Integer);
//}
//#endregion
//#region Collection Functions
//public static List<Leave> Get(string InParameterID)
//{
// List<Leave> Leaves = null;
// Leaves = Leave.Service.Get(InParameterID,SystemInformation.CurrentSysInfo.PayrollTypeID.Integer);
// return Leaves;
//}
//public static List<Leave> Get()
//{
// #region Cache Header
// List<Leave> Leaves = _cache["Get"] as List<Leave>;
// if (Leaves != null)
// return Leaves;
// #endregion
// Leaves = Leave.Service.Get(SystemInformation.CurrentSysInfo.PayrollTypeID.Integer);
// #region Cache Footer
// _cache.Add(Leaves, "Get");
// #endregion
// return Leaves;
//}
//public static List<Leave> Get(EnumStatus status)
//{
// #region Cache Header
// List<Leave> leaves = _cache["Get", status] as List<Leave>;
// if (leaves != null)
// return leaves;
// #endregion
// try
// {
// leaves = Service.Get(status,SystemInformation.CurrentSysInfo.PayrollTypeID.Integer);
// }
// catch (ServiceException e)
// {
// throw new Exception(e.Message, e);
// }
// #region Cache Footer
// _cache.Add(leaves, "Get", status);
// #endregion
// return leaves;
//}
//public static List<Leave> GetLeaves()
//{
// #region Cache Header
// List<Leave> leaves = _cache["Get"] as List<Leave>;
// if (leaves != null)
// return leaves;
// #endregion
// try
// {
// leaves = Service.GetLeaves(SystemInformation.CurrentSysInfo.PayrollTypeID.Integer);
// }
// catch (ServiceException e)
// {
// throw new Exception(e.Message, e);
// }
// #region Cache Footer
// _cache.Add(leaves, "Get");
// #endregion
// return leaves;
//}
//#endregion
//#region Service Factory
//internal static ILeaveService Service
//{
// get { return Services.Factory.CreateService<ILeaveService>(typeof(ILeaveService)); }
//}
//#endregion
}
#endregion
#region ILeave Service
public interface ILeaveService
{
Leave Get(int id);
List<Leave> Get(EnumStatus status, string code, string name, int payrollTypeID);
List<Leave> Get(EnumStatus status, int payrollTypeID);
List<Leave> Get();
List<Leave> getEmpApplicableLeave(int employeeid);
int Save(Leave oLeave);
void Delete(int id, int payrollTypeID);
bool IsAttachmentAplicable(Leave leave, decimal totalDays);
}
#endregion
}