EchoTex_Payroll/HRM.BO/Budget/BudgetComponent.cs
2024-10-14 10:01:49 +06:00

715 lines
18 KiB
C#

using Ease.Core.Model;
using System;
using System.Collections.Generic;
using System.Data;
namespace HRM.BO
{
#region BudgetComponent BaseObject
public class BudgetComponent : BasicBaseObject
{
#region Constructor
public BudgetComponent()
{
_basedOn = EnumBasedOnPercent.None;
_budgetID = 0;
_componentType = EnumBudgetComponent.None;
_flatAmount = 0;
_name = string.Empty;
_originID = 0;
_parameterID = 0;
_percentage = 0;
_periodicity = 0;
_taxable = false;
_payrollTypeID = 0;
#region Child Variables
_oBudgetComponentIndivisuals = null;
_oBudgetComponentGrades = null;
#endregion
}
#endregion
#region Properties
#region Parent Properties
#region BasedOn : EnumBasedOnPercent
private EnumBasedOnPercent _basedOn;
public EnumBasedOnPercent BasedOn
{
get { return _basedOn; }
set { _basedOn = value; }
}
#endregion
#region BudgetID : ID
private int _budgetID;
public int BudgetID
{
get { return _budgetID; }
set { _budgetID = value; }
}
#endregion
#region PayrollTypeID : ID
private int _payrollTypeID;
public int PayrollTypeID
{
get { return _payrollTypeID; }
set { _payrollTypeID = value; }
}
#endregion
#region ComponentType : EnumBudgetComponent
private EnumBudgetComponent _componentType;
public EnumBudgetComponent ComponentType
{
get { return _componentType; }
set { _componentType = value; }
}
#endregion
#region FlatAmount : double
private double _flatAmount;
public double FlatAmount
{
get { return _flatAmount; }
set { _flatAmount = value; }
}
#endregion
#region Name : string
private string _name;
public string Name
{
get { return _name; }
set { _name = value; }
}
#endregion
#region OriginID : ID
private int _originID;
public int OriginID
{
get { return _originID; }
set { _originID = value; }
}
#endregion
#region ParameterID : ID
private int _parameterID;
public int ParameterID
{
get { return _parameterID; }
set { _parameterID = value; }
}
#endregion
#region Percentage : double
private double _percentage;
public double Percentage
{
get { return _percentage; }
set { _percentage = value; }
}
#endregion
#region Periodicity : double
private double _periodicity;
public double Periodicity
{
get { return _periodicity; }
set { _periodicity = value; }
}
#endregion
#region Taxable : bool
private bool _taxable;
public bool Taxable
{
get { return _taxable; }
set { _taxable = value; }
}
#endregion
#region IndivisuallyDefined : bool
private bool _indivisuallyDefined;
public bool IndivisuallyDefined
{
get { return _indivisuallyDefined; }
set { _indivisuallyDefined = value; }
}
#endregion
public AllowanceDeduction AllowanceDeduction { get; set; }
//#region allowanceDeduction : AllowanceDeduction
//private AllowanceDeduction _allowanceDeduction;
//public AllowanceDeduction AllowanceDeduction
//{
// get
// {
// if (_originID.Integer > 0 && _allowanceDeduction == null)
// {
// _allowanceDeduction = new AllowanceDeduction();
// _allowanceDeduction = AllowanceDeduction.Get(_originID);
// }
// return this._allowanceDeduction;
// }
// set
// {
// _allowanceDeduction = value;
// }
//}
//#endregion
#endregion
#region Child Properties
#region BudgetComponentIndivisual Property
private List<BudgetComponentIndivisual> _oBudgetComponentIndivisuals;
public List<BudgetComponentIndivisual> OBudgetComponentIndivisuals
{
get
{
if (_oBudgetComponentIndivisuals == null)
{
//_oBudgetComponentIndivisuals = new List<BudgetComponentIndivisual>();
//if (!this.ID.IsUnassigned && _oBudgetComponentIndivisuals.Count>=0)
//{
// if (this.ID.Integer > 0)
// _oBudgetComponentIndivisuals = Service.GetBudgetComponentIndivisuals(this.ID);
//}
_oBudgetComponentIndivisuals = new List<BudgetComponentIndivisual>();
}
return _oBudgetComponentIndivisuals;
}
set { _oBudgetComponentIndivisuals = value; }
}
#endregion
#region BudgetComponentGrade Property
private List<BudgetComponentGrade> _oBudgetComponentGrades;
public List<BudgetComponentGrade> OBudgetComponentGrades
{
get
{
if (_oBudgetComponentGrades == null)
{
_oBudgetComponentGrades = new List<BudgetComponentGrade>();
//if (!this.ID.IsUnassigned)
// _oBudgetComponentGrades = Service.GetBudgetComponentGrades(this.ID);
}
return _oBudgetComponentGrades;
}
set { _oBudgetComponentGrades = value; }
}
#endregion
#endregion
#endregion
public double CalculateAmount(Employee oEmp)
{
double amount = 0;
switch (_basedOn)
{
case EnumBasedOnPercent.None:
break;
case EnumBasedOnPercent.Basic:
amount = this.FlatAmount + (this.Percentage * oEmp.BasicSalary) / 100;
break;
case EnumBasedOnPercent.Base:
amount = 0; //(this.Percentage * oEmp.GrossSalary) / 100;
break;
case EnumBasedOnPercent.Gross:
amount = this.FlatAmount + (this.Percentage * oEmp.GrossSalary) / 100;
break;
case EnumBasedOnPercent.Fixed_Amount:
amount = this.FlatAmount;
break;
default:
break;
}
return amount;
}
public double CalculateExceptionAmount(Employee oEmp, DateTime processMonth)
{
double amount = 0;
switch (_basedOn)
{
case EnumBasedOnPercent.None:
break;
case EnumBasedOnPercent.Basic:
if (this.IndivisuallyDefined)
{
amount = GetIndvAmt(processMonth, oEmp.BasicSalary);
}
if (amount == 0)
amount = this.FlatAmount + (this.Percentage * oEmp.BasicSalary) / 100;
break;
case EnumBasedOnPercent.Base:
amount = 0; //(this.Percentage * oEmp.GrossSalary) / 100;
break;
case EnumBasedOnPercent.Gross:
if (this.IndivisuallyDefined)
{
amount = GetIndvAmt(processMonth, oEmp.GrossSalary);
}
if (amount == 0)
amount = this.FlatAmount + (this.Percentage * oEmp.GrossSalary) / 100;
break;
case EnumBasedOnPercent.Fixed_Amount:
amount = this.FlatAmount;
break;
default:
break;
}
if (!this.IndivisuallyDefined)
{
if (GetExceptionAmt(oEmp) != 0)
amount = GetExceptionAmt(oEmp);
if (GetNotAppAmt(oEmp) != null)
amount = 0;
}
return amount;
}
private double GetIndvAmt(DateTime dMonth, double nAmount)
{
double amount = 0.0;
BudgetComponentIndivisual budIndv = this.OBudgetComponentIndivisuals.Find(
delegate(BudgetComponentIndivisual item)
{
return item.FromDate.Date >= dMonth.Date && item.ToDate.Date <= dMonth.Date &&
item.DetailType == EnumADEmpType.AppliedToIndividual;
});
if (budIndv != null)
{
if (budIndv.ValueType == EnumValueType.Amount)
{
amount = budIndv.Amount;
}
else
{
amount = (budIndv.Amount * nAmount) / 100;
}
}
return amount;
}
private double GetExceptionAmt(Employee oEmp)
{
double amount = 0.0;
BudgetComponentIndivisual budIndv = this.OBudgetComponentIndivisuals.Find(
delegate(BudgetComponentIndivisual item)
{
return item.EmployeeID == oEmp.ID && item.DetailType == EnumADEmpType.Exception;
});
if (budIndv != null)
{
if (budIndv.ValueType == EnumValueType.Amount)
{
amount = budIndv.Amount;
}
else
{
amount = (oEmp.BasicSalary * budIndv.Amount) / 100;
}
}
return amount;
}
private BudgetComponentIndivisual GetNotAppAmt(Employee oEmp)
{
BudgetComponentIndivisual budIndv = this.OBudgetComponentIndivisuals.Find(
delegate(BudgetComponentIndivisual item)
{
return item.EmployeeID == oEmp.ID && item.DetailType == EnumADEmpType.NotApplicable;
});
return budIndv;
}
//#region Function(s)
//#region Get
//public static BudgetComponent Get(int nID)
//{
// BudgetComponent oBudgetComponent = null;
// #region Cache Header
// oBudgetComponent = (BudgetComponent)_cache["Get", nID];
// if (oBudgetComponent != null)
// return oBudgetComponent;
// #endregion
// try
// {
// oBudgetComponent = Service.Get(nID);
// }
// catch (ServiceException e)
// {
// throw new Exception(e.Message, e);
// }
// #region Cache Footer
// _cache.Add(oBudgetComponent, "Get", nID);
// #endregion
// return oBudgetComponent;
//}
//public static List<BudgetComponent> Get()
//{
// #region Cache Header
// List<BudgetComponent> oBudgetComponents = _cache["Get"] as List<BudgetComponent>;
// if (oBudgetComponents != null)
// return oBudgetComponents;
// #endregion
// try
// {
// oBudgetComponents = Service.Get();
// }
// catch (ServiceException e)
// {
// throw new Exception(e.Message, e);
// }
// #region Cache Footer
// _cache.Add(oBudgetComponents, "Get");
// #endregion
// return oBudgetComponents;
//}
//public static List<BudgetComponent> Get(int BudgetID)
//{
// #region Cache Header
// List<BudgetComponent> oBudgetComponents = _cache["Get"] as List<BudgetComponent>;
// if (oBudgetComponents != null)
// return oBudgetComponents;
// #endregion
// try
// {
// oBudgetComponents = Service.Get(BudgetID);
// }
// catch (ServiceException e)
// {
// throw new Exception(e.Message, e);
// }
// #region Cache Footer
// _cache.Add(oBudgetComponents, "Get");
// #endregion
// return oBudgetComponents;
//}
//#endregion
//#region Save
//public int Save()
//{
// //SetAuditTrailProperties();
// return Service.Save(this);
//}
//#endregion
//#region Delete
//public void Delete(int id)
//{
// Service.Delete(id);
//}
//#endregion
//#endregion
//#region Service Factory
//internal static IBudgetComponentService Service
//{
// get { return Services.Factory.CreateService<IBudgetComponentService>(typeof(IBudgetComponentService)); }
//}
//#endregion
}
#endregion
#region child Objects
#region BudgetComponentIndivisual
public class BudgetComponentIndivisual : ObjectTemplate
{
#region Constructor
public BudgetComponentIndivisual()
{
_amount = 0;
_budgetComponentID = 0;
_employeeID = 0;
_detailType = EnumADEmpType.AppliedToIndividual;
_fromDate = DateTime.MinValue;
_toDate = DateTime.MinValue;
_valueType = EnumValueType.Amount;
}
#endregion
#region Properties
#region Amount : double
private double _amount;
public double Amount
{
get { return _amount; }
set { _amount = value; }
}
#endregion
#region BudgetComponentID : ID
private int _budgetComponentID;
public int BudgetComponentID
{
get { return _budgetComponentID; }
set { _budgetComponentID = value; }
}
#endregion
#region DetailType : EnumBudgetDetailType
private EnumADEmpType _detailType;
public EnumADEmpType DetailType
{
get { return _detailType; }
set { _detailType = value; }
}
#endregion
#region EmployeeID : ID
private int _employeeID;
public int EmployeeID
{
get { return _employeeID; }
set { _employeeID = value; }
}
#endregion
#region FromDate : DateTime
private DateTime _fromDate;
public DateTime FromDate
{
get { return _fromDate; }
set { _fromDate = value; }
}
#endregion
#region ToDate : DateTime
private DateTime _toDate;
public DateTime ToDate
{
get { return _toDate; }
set { _toDate = value; }
}
#endregion
#region ValueType : EnumValueType
private EnumValueType _valueType;
public EnumValueType ValueType
{
get { return _valueType; }
set { _valueType = value; }
}
#endregion
public Employee Employee { get; set; }
//#region Employee : Employee
//private Employee _employee;
//public Employee Employee
//{
// get
// {
// if (_employeeID != null)
// {
// if (_employee == null && !_employeeID.IsUnassigned)
// {
// _employee = new Employee();
// _employee = Employee.Get(_employeeID);
// }
// }
// return this._employee;
// }
// set
// {
// _employee = value;
// }
//}
//#endregion
#endregion
}
#endregion
#region BudgetComponentGrade
public class BudgetComponentGrade : ObjectTemplate
{
#region Constructor
public BudgetComponentGrade()
{
_budgetComponentID = 0;
_gradeID = 0;
}
#endregion
#region Properties
#region BudgetComponentID : ID
private int _budgetComponentID;
public int BudgetComponentID
{
get { return _budgetComponentID; }
set { _budgetComponentID = value; }
}
#endregion
#region GradeID : ID
private int _gradeID;
public int GradeID
{
get { return _gradeID; }
set { _gradeID = value; }
}
#endregion
#endregion
}
#endregion
#endregion
#region IBudgetComponentService
public interface IBudgetComponentService
{
#region parent's function definition
BudgetComponent Get(int nID);
List<BudgetComponent> Get();
List<BudgetComponent> GetWithBudgetID(int BudgetID);
int Save(BudgetComponent item);
void Delete(int nID);
#endregion
#region child's function Definition
List<BudgetComponentIndivisual> GetBudgetComponentIndivisuals(int id);
List<BudgetComponentGrade> GetBudgetComponentGrades(int id);
#endregion
}
#endregion
}