CEL_Payroll/Payroll.BO/Employee/EmployeeCostCenter.cs

418 lines
11 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;
using Ease.CoreV35.Model;
using Ease.CoreV35.Caching;
using System.Data.Linq.Mapping;
using System.Data;
namespace Payroll.BO
{
#region EmployeeCostCenter
[Serializable]
public class EmployeeCostCenter : AuditTrailBase
{
#region Cache Store
private static Cache _cache = new Cache(typeof(EmployeeCostCenter));
#endregion
#region Constructor
public EmployeeCostCenter()
{
_employeeID = null;
_monthDate = DateTime.MinValue;
_costCenterID = null;
_percentage = 0;
_isCurrentCC = false;
_tillDate = DateTime.MinValue;
_costcenter = 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 monthDate : DateTime
private DateTime _monthDate;
public DateTime MonthDate
{
get { return _monthDate; }
set
{
base.OnPropertyChange<DateTime>("monthDate", _monthDate, value);
_monthDate = value;
}
}
#endregion
#region costCenterID : ID
private ID _costCenterID;
public ID CostCenterID
{
get { return _costCenterID; }
set
{
base.OnPropertyChange<ID>("costCenterID", _costCenterID, value);
_costCenterID = value;
}
}
#endregion
#region percentage : double
private double _percentage;
public double Percentage
{
get { return _percentage; }
set
{
base.OnPropertyChange<double>("percentage", _percentage, value);
_percentage = value;
}
}
#endregion
#region isCurrentCC : bool
private bool _isCurrentCC;
public bool IsCurrentCC
{
get { return _isCurrentCC; }
set
{
base.OnPropertyChange<bool>("isCurrentCC", _isCurrentCC, value);
_isCurrentCC = value;
}
}
#endregion
#region tillDate : DateTime
private DateTime _tillDate;
public DateTime TillDate
{
get { return _tillDate; }
set
{
base.OnPropertyChange<DateTime>("tillDate", _tillDate, value);
_tillDate = value;
}
}
#endregion
#region costcenter : Costcenter
private Costcenter _costcenter;
public Costcenter Costcenter
{
get
{
if (_costCenterID.Integer > 0 && _costcenter == null)
{
_costcenter = new Costcenter();
_costcenter = Costcenter.Get(_costCenterID);
}
return this._costcenter;
}
set
{
_costcenter = value;
}
}
#endregion
#region Service Factory IEmployeeCostCenterService : IEmployeeCostCenterService
internal static IEmployeeCostCenterService Service
{
get { return Services.Factory.CreateService<IEmployeeCostCenterService>(typeof(IEmployeeCostCenterService)); }
}
#endregion
#endregion
#region Functions
public static EmployeeCostCenter Get(ID nID)
{
EmployeeCostCenter oEmployeeCostCenter = null;
#region Cache Header
oEmployeeCostCenter = (EmployeeCostCenter)_cache["Get", nID];
if (oEmployeeCostCenter != null)
return oEmployeeCostCenter;
#endregion
oEmployeeCostCenter = EmployeeCostCenter.Service.Get(nID);
#region Cache Footer
_cache.Add(oEmployeeCostCenter, "Get", nID);
#endregion
return oEmployeeCostCenter;
}
/// <summary>
/// Get employee current cost-center(s) involvement
/// </summary>
/// <param name="employeeid"></param>
/// <returns></returns>
public static ObjectsTemplate<EmployeeCostCenter> GetByEmpID(ID employeeid)
{
#region Cache Header
ObjectsTemplate<EmployeeCostCenter> employeeCostCenters = _cache["Get"] as ObjectsTemplate<EmployeeCostCenter>;
if (employeeCostCenters != null)
return employeeCostCenters;
#endregion
try
{
employeeCostCenters = Service.GetByEmpID(employeeid);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(employeeCostCenters, "Get");
#endregion
return employeeCostCenters;
}
/// <summary>
/// Get all employee's current cost-center involvement
/// </summary>
/// <returns></returns>
public static ObjectsTemplate<EmployeeCostCenter> Get()
{
#region Cache Header
ObjectsTemplate<EmployeeCostCenter> employeeCostCenters = _cache["Get"] as ObjectsTemplate<EmployeeCostCenter>;
if (employeeCostCenters != null)
return employeeCostCenters;
#endregion
try
{
employeeCostCenters = Service.Get();
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(employeeCostCenters, "Get");
#endregion
return employeeCostCenters;
}
public static ObjectsTemplate<EmployeeCostCenter> Get(ObjectsTemplate<EmployeeCostCenter> empCRGInvolvements, ID employeeID)
{
ObjectsTemplate<EmployeeCostCenter> empCRGs = null;
foreach (EmployeeCostCenter crg in empCRGInvolvements)
{
if (crg.EmployeeID == employeeID)
{
if (empCRGs == null) empCRGs = new ObjectsTemplate<EmployeeCostCenter>();
empCRGs.Add(crg);
}
}
return empCRGs;
}
/// <summary>
/// get costcenter current involvement all employee(s)
/// </summary>
/// <param name="nCCID">cost center ID</param>
/// <returns></returns>
public static ObjectsTemplate<EmployeeCostCenter> GetByCCID(ID nCCID)
{
#region Cache Header
ObjectsTemplate<EmployeeCostCenter> employeeCostCenters = _cache["Get"] as ObjectsTemplate<EmployeeCostCenter>;
if (employeeCostCenters != null)
return employeeCostCenters;
#endregion
try
{
employeeCostCenters = Service.GetByCCID(nCCID);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(employeeCostCenters, "Get");
#endregion
return employeeCostCenters;
}
public static ObjectsTemplate<EmployeeCostCenter> GetByEmpIDCCID(ID nCCID, ID nEmpID)
{
#region Cache Header
ObjectsTemplate<EmployeeCostCenter> employeeCostCenters = _cache["GetByEmpIDCCID"] as ObjectsTemplate<EmployeeCostCenter>;
if (employeeCostCenters != null)
return employeeCostCenters;
#endregion
try
{
employeeCostCenters = Service.GetByEmpIDCCID(nCCID, nEmpID);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(employeeCostCenters, "Get");
#endregion
return employeeCostCenters;
}
public static DataSet GetEmpCC(DateTime dMonthDate, string sEmpID)
{
DataSet ds = null;
try
{
ds = Service.GetEmpCC(dMonthDate, sEmpID);
}
catch (Exception e)
{
throw new Exception(e.Message, e);
}
return ds;
}
public static DataSet GetEmpCCDetails(DateTime dMonthDate, string nEmpID)
{
DataSet ds = null;
try
{
ds = Service.GetEmpCCDetails(dMonthDate, nEmpID);
}
catch (Exception e)
{
throw new Exception(e.Message, e);
}
return ds;
}
public static DateTime GetMaxDate(string EmpID, DateTime monthDate)
{
DateTime dMonthDate;
try
{
dMonthDate = Service.GetMaxDate(EmpID, monthDate);
}
catch (Exception e)
{
throw new Exception(e.Message, e);
}
return dMonthDate;
}
public static ObjectsTemplate<EmployeeCostCenter>GetByMonthStartEnd(DateTime strt, DateTime end)
{
return EmployeeCostCenter.Service.GetByMonthStartEnd(strt, end,SystemInformation.CurrentSysInfo.PayrollTypeID.Integer);
}
public ID Save()
{
base.SetAuditTrailProperties();
this.IsCurrentCC = true;
return EmployeeCostCenter.Service.Save(this);
}
public void Save(ObjectsTemplate<EmployeeCostCenter> _empCostCenters)
{
foreach (EmployeeCostCenter item in _empCostCenters)
{
item.SetAuditTrailProperties();
item.IsCurrentCC = true;
}
EmployeeCostCenter.Service.Save(_empCostCenters);
}
public void Delete()
{
EmployeeCostCenter.Service.Delete(ID);
}
#endregion
}
#endregion
#region IEmployeeCostCenter Service
public interface IEmployeeCostCenterService
{
EmployeeCostCenter Get(ID id);
ObjectsTemplate<EmployeeCostCenter> Get();
ObjectsTemplate<EmployeeCostCenter> GetByEmpID(ID nID);
ObjectsTemplate<EmployeeCostCenter> GetByCCID(ID nID);
ObjectsTemplate<EmployeeCostCenter> GetByEmpIDCCID(ID nCCID, ID nEmpID);
DataSet GetEmpCC(DateTime dMonthDate, string sEmpID);
DataSet GetEmpCCDetails(DateTime dMonthDate, string nEmpID);
DateTime GetMaxDate(string nEmpID, DateTime monthDate);
ID Save(EmployeeCostCenter item);
void Save(ObjectsTemplate<EmployeeCostCenter> _empCostCenters);
void Delete(ID id);
ObjectsTemplate<EmployeeCostCenter> GetByMonthStartEnd(DateTime strt, DateTime end, int payrollTypeID);
}
#endregion
}