EchoTex_Payroll/HRM.DA/Service/Bonus/BonusParameterService.cs

749 lines
28 KiB
C#
Raw Normal View History

2024-10-14 10:01:49 +06:00
using System;
using System.Data;
using Ease.Core.Model;
using Ease.Core.DataAccess;
using Ease.Core;
using System.Collections.Generic;
using Ease.Core.Utility;
using HRM.BO;
using System.Linq;
namespace HRM.DA
{
#region Bonus Service
public class BonusParameterService : ServiceTemplate, IBonusParameterService
{
public BonusParameterService()
{
}
private void MapObject(BonusParameter oBonusParameter, DataReader oReader)
{
base.SetObjectID(oBonusParameter, oReader.GetInt32("BonusParameterID", 0));
oBonusParameter.BonusID = oReader.GetInt32("BonusID", 0);
oBonusParameter.ConfirmeRequired = oReader.GetBoolean("ConfimRequired").Value;
oBonusParameter.IsFestival = oReader.GetBoolean("IsFestival").HasValue
? oReader.GetBoolean("IsFestival").Value
: false;
oBonusParameter.IsProrated = oReader.GetBoolean("IsProrated").Value;
oBonusParameter.IsOverYearCalculation = oReader.GetBoolean("IsOverYearCalculation").Value;
oBonusParameter.IsProjectInTaxCalculation = oReader.GetBoolean("IsProjectInTaxCalculation").Value;
oBonusParameter.EligibleCuttoffDate = oReader.GetBoolean("EligibleCuttoffDate").Value;
oBonusParameter.FlatAmount = oReader.GetDouble("flatAmount").Value;
oBonusParameter.NoOfBasic = oReader.GetInt32("noOfBasic").Value;
oBonusParameter.NoOfDays = oReader.GetInt32("noOfDays").Value;
oBonusParameter.NoOfGross = oReader.GetInt32("NOOFGROSS").Value;
oBonusParameter.PercentOfGross = oReader.GetInt32("PERCENTOFGROSS").Value;
oBonusParameter.GrossOfDays = oReader.GetInt32("GROSSOFDAYS").Value;
oBonusParameter.PayrollTypeID = oReader.GetInt32("payrollTypeID", 0);
oBonusParameter.NoOfEarnedBasic = oReader.GetInt32("noOfEarnedBasic").Value;
oBonusParameter.firstProjectMonth = oReader.GetDateTime("firstProjectMonth");
oBonusParameter.secondProjectMonth = oReader.GetDateTime("SecondProjectMonth");
oBonusParameter.NoOfDisbusement = oReader.GetInt32("NoOfDisbusement").HasValue
? oReader.GetInt32("NoOfDisbusement").Value
: 0;
oBonusParameter.Sequence = oReader.GetInt32("SequenceNO").Value;
oBonusParameter.TaxProjectInMonth = oReader.GetInt32("TaxProjectInMonth").HasValue
? oReader.GetInt32("TaxProjectInMonth").Value
: 0;
oBonusParameter.Status = (EnumStatus)oReader.GetInt32("Status").Value;
oBonusParameter.CreatedBy = oReader.GetInt32("CreatedBy", 0);
oBonusParameter.CreatedDate = oReader.GetDateTime("CreationDate").HasValue
? oReader.GetDateTime("CreationDate").Value
: DateTime.MinValue;
oBonusParameter.ModifiedBy = oReader.GetInt32("ModifiedBy", 0);
oBonusParameter.ModifiedDate = oReader.GetDateTime("ModifiedDate").HasValue
? oReader.GetDateTime("ModifiedDate").Value
: (DateTime?)null;
this.SetObjectState(oBonusParameter, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
BonusParameter oBonus = new BonusParameter();
MapObject(oBonus, oReader);
return oBonus as T;
}
protected BonusParameter CreateObject(DataReader oReader)
{
BonusParameter oBonus = new BonusParameter();
MapObject(oBonus, oReader);
return oBonus;
}
private void MapBonusSLengthObject(BonusParameter.BonusServiceLength oBonusSLength, DataReader oReader)
{
base.SetObjectID(oBonusSLength, oReader.GetInt32("BonusSLengthID", 0));
oBonusSLength.BonusParameterID = oReader.GetInt32("BonusParameterID", 0);
oBonusSLength.LengthOfService = oReader.GetInt32("LengthOfService").Value;
oBonusSLength.EntitlePercent = oReader.GetInt32("EntitlePercent").Value;
this.SetObjectState(oBonusSLength, Ease.Core.ObjectState.Saved);
}
protected List<BonusParameter.BonusServiceLength> CreateBonusSLengthObject(DataReader oReader)
{
List<BonusParameter.BonusServiceLength> oBonusSLengts = new List<BonusParameter.BonusServiceLength>();
while (oReader.Read())
{
BonusParameter.BonusServiceLength oBonusSLength = new BonusParameter.BonusServiceLength();
MapBonusSLengthObject(oBonusSLength, oReader);
oBonusSLengts.Add(oBonusSLength);
}
return oBonusSLengts;
}
private void MapBonusSItemObject(BonusParameter.BonusParamSalaryItem oBonusSItem, DataReader oReader)
{
base.SetObjectID(oBonusSItem, oReader.GetInt32("BonusParamSalaryItemID", 0));
oBonusSItem.BonusParameterID = oReader.GetInt32("BonusParameterID", 0);
oBonusSItem.AllowDeductID = oReader.GetInt32("AllowDeductID", 0);
oBonusSItem.Percent = oReader.GetInt32("Percent").Value;
oBonusSItem.SalaryGroupCode = oReader.GetInt32("SalaryGroupCode").Value;
oBonusSItem.NoOfSalary = oReader.GetInt32("NoOfSalary").Value;
this.SetObjectState(oBonusSItem, Ease.Core.ObjectState.Saved);
}
protected List<BonusParameter.BonusParamSalaryItem> CreateBonusSItemObject(DataReader oReader)
{
List<BonusParameter.BonusParamSalaryItem> oBonusSItems = new List<BonusParameter.BonusParamSalaryItem>();
while (oReader.Read())
{
BonusParameter.BonusParamSalaryItem oBonusSItem = new BonusParameter.BonusParamSalaryItem();
MapBonusSItemObject(oBonusSItem, oReader);
oBonusSItems.Add(oBonusSItem);
}
return oBonusSItems;
}
private void MapBonusAItemObject(BonusParameter.BonusParamAdjustItem oBonusAItem, DataReader oReader)
{
base.SetObjectID(oBonusAItem, oReader.GetInt32("BonusParamAdjustItemID", 0));
oBonusAItem.BonusParameterID = oReader.GetInt32("BonusParameterID", 0);
oBonusAItem.Amount = oReader.GetDouble("Amount").Value;
oBonusAItem.BonusAdjustItemID = oReader.GetInt32("BonusAdjustItemID").Value;
this.SetObjectState(oBonusAItem, Ease.Core.ObjectState.Saved);
}
protected List<BonusParameter.BonusParamAdjustItem> CreateBonusAItemObject(DataReader oReader)
{
List<BonusParameter.BonusParamAdjustItem> oBonusAItems = new List<BonusParameter.BonusParamAdjustItem>();
while (oReader.Read())
{
BonusParameter.BonusParamAdjustItem oBonusAItem = new BonusParameter.BonusParamAdjustItem();
MapBonusAItemObject(oBonusAItem, oReader);
oBonusAItems.Add(oBonusAItem);
}
return oBonusAItems;
}
private void MapBonusSlabObject(BonusParameter.BonusSlab oBonusSlab, DataReader oReader)
{
base.SetObjectID(oBonusSlab, oReader.GetInt32("BonusSlabID", 0));
oBonusSlab.BonusParameterID = oReader.GetInt32("BonusParameterID", 0);
oBonusSlab.SlabType = (EnumSlabType)oReader.GetInt32("SlabType").Value;
oBonusSlab.SlabAmount = oReader.GetDouble("SlabAmount").Value;
oBonusSlab.Amount = oReader.GetDouble("Amount").Value;
oBonusSlab.AmountType = (EnumSlabAmountType)oReader.GetInt32("AmountType").Value;
this.SetObjectState(oBonusSlab, Ease.Core.ObjectState.Saved);
}
protected List<BonusParameter.BonusSlab> CreateBonusSlabObject(DataReader oReader)
{
List<BonusParameter.BonusSlab> oBonusSlabs = new List<BonusParameter.BonusSlab>();
while (oReader.Read())
{
BonusParameter.BonusSlab oBonusSlab = new BonusParameter.BonusSlab();
MapBonusSlabObject(oBonusSlab, oReader);
oBonusSlabs.Add(oBonusSlab);
}
return oBonusSlabs;
}
private void MapSetupDetail(SetupDetail obDetail, DataReader oReader)
{
base.SetObjectID(obDetail, oReader.GetInt32("DetailID", 0));
obDetail.SetupID = oReader.GetInt32("SetupID", 0);
obDetail.TranID = oReader.GetInt32("TranID", 0);
obDetail.TranType = (EnmSetupManagerTranType)oReader.GetInt32("TranType");
this.SetObjectState(obDetail, Ease.Core.ObjectState.Saved);
}
private List<SetupDetail> CreateSetupDetailObjects(DataReader oReader)
{
List<SetupDetail> allsetUps = new List<SetupDetail>();
while (oReader.Read())
{
SetupDetail obstup = new SetupDetail();
MapSetupDetail(obstup, oReader);
allsetUps.Add(obstup);
}
return allsetUps;
}
private void MapObjectForBonusParamGrade(BonusParameter.BonusParamGrade oBonusParamGrade, DataReader oReader)
{
base.SetObjectID(oBonusParamGrade, oReader.GetInt32("BonusParamID").Value);
oBonusParamGrade.BonusParamID =
oReader.GetString("BonusParamID") == null ? 0 : oReader.GetInt32("BonusParamID").Value;
oBonusParamGrade.GradeID = oReader.GetString("GRADEID") == null ? 0 : oReader.GetInt32("GRADEID").Value;
this.SetObjectState(oBonusParamGrade, Ease.Core.ObjectState.Saved);
}
//protected override T CreateObject1<T>(DataReader oReader)
//{
// TermEntityGrade oTermEGrade = new TermEntityGrade();
// MapObjectForTEGrade(oTermEGrade, oReader);
// return oTermEGrade as T;
//}
protected BonusParameter.BonusParamGrade CreateObjectForBonusParamGrade(DataReader oReader)
{
BonusParameter.BonusParamGrade oBonusParamGrade = new BonusParameter.BonusParamGrade();
MapObjectForBonusParamGrade(oBonusParamGrade, oReader);
return oBonusParamGrade;
}
private List<BonusParameter.BonusParamGrade> FillChildren(DataReader dr)
{
List<BonusParameter.BonusParamGrade> _BonusParamGrades = new List<BonusParameter.BonusParamGrade>();
while (dr.Read())
{
BonusParameter.BonusParamGrade item = this.CreateObjectForBonusParamGrade(dr);
_BonusParamGrades.Add(item);
}
return _BonusParamGrades;
}
public List<BonusParameter> GetApplicableParameters(Employee employee, int graId, List<BonusParameter> parameters)
{
List<BonusParameter> applicableParams = parameters.FindAll(delegate (BonusParameter param) { return IsApplicable(param, graId, employee); });
return applicableParams;
}
public BonusParameter GetApplicableParameter(Employee employee, int graId, List<BonusParameter> parameters, int bonusID)
{
foreach (BonusParameter item in parameters)
{
if (item.BonusID == bonusID)
{
if (IsApplicable(item, graId, employee) == true)
return item;
}
}
return null;
}
public static List<int> ApplicableParameters(Employee oEmp, EnumParameterSetup setup, List<EnmSetupManagerTranType> setupTypes, List<SetupDetail> details)
{
List<int> parametersID = new List<int>();
if (setupTypes == null) return parametersID;
foreach (EnmSetupManagerTranType type in setupTypes)
{
int nTranID = SetupDetailService.GetTranID(oEmp, type);
if (nTranID == 0)
{
continue;
}
var setupIds = (from detail in details
where detail.TranType == type
&& detail.TranID == nTranID
select detail.SetupID).Distinct();
if (setupIds != null)
{
foreach (var id in setupIds)
parametersID.Add(id);
}
}
return parametersID;
}
private bool IsApplicable(BonusParameter param, int graid, Employee employee)
{
bool isApplicable = false;
foreach (BonusParameter.BonusParamGrade adgrade in param.BonusParamGrads)
{
if (adgrade.GradeID == graid)
{
isApplicable = true;
}
}
if (!isApplicable) return false;
return true;
}
#region Service implementation
public List<SetupDetail> GetSetupDetail(int parmID)
{
List<SetupDetail> resultSet = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
DataReader oReader = new DataReader(SetupDetailDA.GetByID(EnumParameterSetup.Bonus, parmID, tc));
resultSet = this.CreateSetupDetailObjects(oReader);
oReader.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return resultSet;
}
public BonusParameter Get(int nBonusParamID)
{
BonusParameter oBonus = new BonusParameter();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(BonusParameterDA.Get(tc, nBonusParamID));
if (oreader.Read())
{
oBonus = this.CreateObject<BonusParameter>(oreader);
}
oreader.Close();
if (oBonus != null)
{
DataReader ord = new DataReader(BonusParameterDA.GetGrades(tc, nBonusParamID));
oBonus.BonusParamGrads = this.FillChildren(ord);
ord.Close();
}
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return oBonus;
}
public List<BonusParameter.BonusParamGrade> GetUsedGrades(int termID)
{
List<BonusParameter.BonusParamGrade> usedGrades = new List<BonusParameter.BonusParamGrade>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(BonusParameterDA.GetUsedGrades(tc, termID));
usedGrades = this.FillChildren(dr);
dr.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return usedGrades;
}
public BonusParameter GetByBonusID(int nBonusID, int payrolltypeid)
{
BonusParameter oBonus = new BonusParameter();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(BonusParameterDA.GetByBonusID(tc, nBonusID, payrolltypeid));
if (oreader.Read())
{
oBonus = this.CreateObject<BonusParameter>(oreader);
}
oreader.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return oBonus;
}
public List<BonusParameter> Get(EnumStatus status, int payrolltypeid)
{
List<BonusParameter> bonusParameters = new List<BonusParameter>();
List<Bonus> bonuses = new BonusService().Get(EnumStatus.Active, payrolltypeid);
List<Grade> grades = new GradeService().Get(EnumStatus.Active, payrolltypeid);
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(BonusParameterDA.Get(tc, status, payrolltypeid));
bonusParameters = this.CreateObjects<BonusParameter>(dr);
dr.Close();
foreach (BonusParameter item in bonusParameters)
{
DataReader ord = new DataReader(BonusParameterDA.GetGrades(tc, item.ID));
item.BonusParamGrads = this.FillChildren(ord);
ord.Close();
}
dr = new DataReader(BonusParameterDA.GetallSerLengthByBonus(tc));
var slenths = this.CreateBonusSLengthObject(dr);
dr.Close();
foreach (BonusParameter item in bonusParameters)
{
item.BonusServiceLengths = slenths.FindAll(x => x.BonusParameterID == item.ID);
}
tc.End();
foreach (BonusParameter item in bonusParameters)
{
Bonus bonus = bonuses.Where(x => x.ID == item.BonusID).FirstOrDefault();
if (bonus != null)
{
item.BonusName = bonus.Name;
}
item.ForConfirmed = item.ConfirmeRequired ? "Yes" : "No";
foreach (BonusParameter.BonusParamGrade bonusParamGrade in item.BonusParamGrads)
{
Grade grade = grades.Where(x => x.ID == bonusParamGrade.GradeID).FirstOrDefault();
if (grade != null)
{
item.ApplicableGrades = string.IsNullOrEmpty(item.ApplicableGrades)
? grade.Code
: item.ApplicableGrades + ", " + grade.Code;
}
}
}
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return bonusParameters;
}
public List<BonusParameter.BonusServiceLength> GetSerLengthByBonus(int nID)
{
List<BonusParameter.BonusServiceLength> bonusServiceLengths = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(BonusParameterDA.GetSerLengthByBonus(tc, nID));
bonusServiceLengths = this.CreateBonusSLengthObject(dr);
dr.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return bonusServiceLengths;
}
public List<BonusParameter.BonusSlab> GetSlabByBonus(int nID)
{
List<BonusParameter.BonusSlab> bonusSlabs = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(BonusParameterDA.GetSlabByBonus(tc, nID));
bonusSlabs = this.CreateBonusSlabObject(dr);
dr.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return bonusSlabs;
}
public List<BonusParameter.BonusParamSalaryItem> GetSalaryItemByBonus(int nID)
{
List<BonusParameter.BonusParamSalaryItem> bonusParamSalaryItems = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(BonusParameterDA.GetSalaryItemByBonus(tc, nID));
bonusParamSalaryItems = this.CreateBonusSItemObject(dr);
dr.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return bonusParamSalaryItems;
}
public List<BonusParameter.BonusParamAdjustItem> GetAdjustItemByBonus(int nID)
{
List<BonusParameter.BonusParamAdjustItem> bonusParamAdjustItems = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(BonusParameterDA.GetAdjustItemByBonus(tc, nID));
bonusParamAdjustItems = this.CreateBonusAItemObject(dr);
dr.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return bonusParamAdjustItems;
}
public int Save(BonusParameter oBonusParameter)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oBonusParameter.IsNew)
{
int id = tc.GenerateID("BONUSPARAMETER", "BonusParameterID");
base.SetObjectID(oBonusParameter, (id));
oBonusParameter.Status = EnumStatus.Active;
BonusParameterDA.Insert(tc, oBonusParameter);
}
else
{
BonusParameterDA.Update(tc, oBonusParameter);
BonusParameterDA.DeleteBonusSLength(tc, oBonusParameter.ID);
BonusParameterDA.DeleteBonusSlab(tc, oBonusParameter.ID);
BonusParameterDA.DeleteBonusSalaryItem(tc, oBonusParameter.ID);
BonusParameterDA.DeleteBonusAdjustItem(tc, oBonusParameter.ID);
BonusParameterDA.DeleteBonusParamGrade(tc, oBonusParameter.ID);
}
if (oBonusParameter.BonusServiceLengths != null)
{
foreach (BonusParameter.BonusServiceLength bonusSLength in oBonusParameter.BonusServiceLengths)
{
bonusSLength.BonusParameterID = oBonusParameter.ID;
int id = tc.GenerateID("BonusServiceLength", "BonusSLengthID");
base.SetObjectID(bonusSLength, (id));
BonusParameterDA.Insert(tc, bonusSLength);
}
}
if (oBonusParameter.BonusSlabs != null)
{
foreach (BonusParameter.BonusSlab bonusSlab in oBonusParameter.BonusSlabs)
{
bonusSlab.BonusParameterID = oBonusParameter.ID;
int id = tc.GenerateID("BonusSlab", "BonusSlabID");
base.SetObjectID(bonusSlab, (id));
BonusParameterDA.Insert(tc, bonusSlab);
}
}
if (oBonusParameter.BonusParamSalaryItems != null)
{
foreach (BonusParameter.BonusParamSalaryItem bonusSalaryItem in oBonusParameter.BonusParamSalaryItems)
{
bonusSalaryItem.BonusParameterID = oBonusParameter.ID;
int id = tc.GenerateID("BonusParamSalaryItem", "BonusParamSalaryItemID");
base.SetObjectID(bonusSalaryItem, (id));
BonusParameterDA.Insert(tc, bonusSalaryItem);
}
}
if (oBonusParameter.BonusParamAdjustItems != null)
{
foreach (BonusParameter.BonusParamAdjustItem bonusAdjustItem in oBonusParameter.BonusParamAdjustItems)
{
bonusAdjustItem.BonusParameterID = oBonusParameter.ID;
int id = tc.GenerateID("BonusParamAdjustItem", "BonusParamAdjustItemID");
base.SetObjectID(bonusAdjustItem, (id));
BonusParameterDA.Insert(tc, bonusAdjustItem);
}
}
if (oBonusParameter.BonusParamGrads != null)
{
foreach (BonusParameter.BonusParamGrade bonusAdjustItem in oBonusParameter.BonusParamGrads)
{
bonusAdjustItem.BonusParamID = oBonusParameter.ID;
int id = tc.GenerateID("BonusParamAdjustItem", "BonusParamAdjustItemID");
base.SetObjectID(bonusAdjustItem, (id));
BonusParameterDA.Insert(tc, bonusAdjustItem);
}
}
//SetupDetailService sdetailService = new SetupDetailService();
//sdetailService.Insert(tc, EnumParameterSetup.Bonus,
// oBonusParameter.SetupDetails, oBonusParameter.ID);
tc.End();
return oBonusParameter.ID;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public void Delete(int id)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
BonusParameterDA.Delete(tc, id);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public BonusParameter GetByBonusID(int nBonusID)
{
throw new NotImplementedException();
}
public List<BonusParameter> Get(EnumStatus status)
{
throw new NotImplementedException();
}
#endregion
}
#endregion
}