using System; using System.Data; using System.Linq; using Ease.CoreV35; using Ease.CoreV35.Model; using Ease.CoreV35.DataAccess; using System.Collections.Generic; using Payroll.BO; using Ease.CoreV35.Caching; namespace Payroll.Service { #region Bonus Service [Serializable] public class BonusParameterService : ServiceTemplate, IBonusParameterService { #region Private functions and declaration Cache _cache = new Cache(typeof(BonusParameter)); #endregion public BonusParameterService() { } private void MapObject(BonusParameter oBonusParameter, DataReader oReader) { base.SetObjectID(oBonusParameter, oReader.GetID("BonusParameterID")); oBonusParameter.BonusID = oReader.GetID("BonusID"); 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.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.GetDouble("PERCENTOFGROSS").Value; oBonusParameter.GrossOfDays = oReader.GetInt32("GROSSOFDAYS").Value; oBonusParameter.PayrollTypeID = oReader.GetID("payrollTypeID"); oBonusParameter.NoOfEarnedBasic = oReader.GetInt32("noOfEarnedBasic").Value; 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.GetID("CreatedBy"); oBonusParameter.CreatedDate = oReader.GetDateTime("CreationDate").Value; oBonusParameter.ModifiedBy = oReader.GetID("ModifiedBy"); oBonusParameter.ModifiedDate = oReader.GetDateTime("ModifiedDate"); oBonusParameter.PerformanceBonusPercent = oReader.GetDouble("PerformanceBonusPercent").Value; oBonusParameter.Q1 = oReader.GetDouble("Q1").Value; oBonusParameter.Q2 = oReader.GetDouble("Q2").Value; oBonusParameter.Q3 = oReader.GetDouble("Q3").Value; oBonusParameter.Q4 = oReader.GetDouble("Q4").Value; this.SetObjectState(oBonusParameter, Ease.CoreV35.ObjectState.Saved); } protected override T CreateObject(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.GetID("BonusSLengthID")); oBonusSLength.BonusParameterID = oReader.GetID("BonusParameterID"); oBonusSLength.LengthOfService = oReader.GetInt32("LengthOfService").Value; oBonusSLength.EntitlePercent = oReader.GetInt32("EntitlePercent").Value; this.SetObjectState(oBonusSLength, Ease.CoreV35.ObjectState.Saved); } protected ObjectsTemplate CreateBonusSLengthObject(DataReader oReader) { ObjectsTemplate oBonusSLengts = new ObjectsTemplate(); 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.GetID("BonusParamSalaryItemID")); oBonusSItem.BonusParameterID = oReader.GetID("BonusParameterID"); oBonusSItem.AllowDeductID = oReader.GetInt32("AllowDeductID").Value; oBonusSItem.Percent = oReader.GetInt32("Percent").Value; oBonusSItem.SalaryGroupCode = oReader.GetInt32("SalaryGroupCode").Value; oBonusSItem.NoOfSalary = oReader.GetInt32("NoOfSalary").Value; this.SetObjectState(oBonusSItem, Ease.CoreV35.ObjectState.Saved); } protected ObjectsTemplate CreateBonusSItemObject(DataReader oReader) { ObjectsTemplate oBonusSItems = new ObjectsTemplate(); 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.GetID("BonusParamAdjustItemID")); oBonusAItem.BonusParameterID = oReader.GetID("BonusParameterID"); oBonusAItem.Amount = oReader.GetDouble("Amount").Value; oBonusAItem.BonusAdjustItemID = oReader.GetInt32("BonusAdjustItemID").Value; this.SetObjectState(oBonusAItem, Ease.CoreV35.ObjectState.Saved); } protected ObjectsTemplate CreateBonusAItemObject(DataReader oReader) { ObjectsTemplate oBonusAItems = new ObjectsTemplate(); 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.GetID("BonusSlabID")); oBonusSlab.BonusParameterID = oReader.GetID("BonusParameterID"); 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.CoreV35.ObjectState.Saved); } protected ObjectsTemplate CreateBonusSlabObject(DataReader oReader) { ObjectsTemplate oBonusSlabs = new ObjectsTemplate(); 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.GetID("DetailID")); obDetail.SetupID = oReader.GetID("SetupID"); obDetail.TranID = oReader.GetID("TranID"); obDetail.TranType = (EnmSetupManagerTranType)oReader.GetInt32("TranType"); this.SetObjectState(obDetail, Ease.CoreV35.ObjectState.Saved); } private ObjectsTemplate CreateSetupDetailObjects(DataReader oReader) { ObjectsTemplate allsetUps = new ObjectsTemplate(); while (oReader.Read()) { SetupDetail obstup = new SetupDetail(); MapSetupDetail(obstup, oReader); allsetUps.Add(obstup); } return allsetUps; } #region Service implementation public ObjectsTemplate GetSetupDetail(ID parmID) { ObjectsTemplate resultSet = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(true); DataReader oReader = new DataReader(SetupDetailDA.GetByID(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(ID nBonusParamID) { BonusParameter oBonus = new BonusParameter(); #region Cache Header oBonus = _cache["Get", nBonusParamID] as BonusParameter; if (oBonus != null) return oBonus; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(BonusParameterDA.Get(tc, nBonusParamID)); if (oreader.Read()) { oBonus = this.CreateObject(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 } #region Cache Footer _cache.Add(oBonus, "Get", nBonusParamID); #endregion return oBonus; } public BonusParameter GetByBonusID(ID nBonusID, ID PayrollTypeID) { BonusParameter oBonus = new BonusParameter(); #region Cache Header oBonus = _cache["Get", nBonusID] as BonusParameter; if (oBonus != null) return oBonus; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(BonusParameterDA.GetByBonusID(tc, nBonusID, PayrollTypeID)); if (oreader.Read()) { oBonus = this.CreateObject(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 } #region Cache Footer _cache.Add(oBonus, "Get", nBonusID); #endregion return oBonus; } public ObjectsTemplate Get(EnumStatus status, ID PayrollTypeID) { #region Cache Header ObjectsTemplate bonuss = _cache["Get", status] as ObjectsTemplate; if (bonuss != null) return bonuss; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(BonusParameterDA.Get(tc, status, PayrollTypeID)); bonuss = this.CreateObjects(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 } #region Cache Footer _cache.Add(bonuss, "Get", status); #endregion return bonuss; } public ObjectsTemplate Get(ID nBonusID, ID PayrollTypeID) { #region Cache Header ObjectsTemplate bonuss = _cache["Get", nBonusID] as ObjectsTemplate; if (bonuss != null) return bonuss; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(BonusParameterDA.GetByBonusID(tc, nBonusID, PayrollTypeID)); bonuss = this.CreateObjects(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 } #region Cache Footer _cache.Add(bonuss, "Get", nBonusID); #endregion return bonuss; } public ObjectsTemplate GetSerLengthByBonus(ID nID) { #region Cache Header ObjectsTemplate bonusServiceLengths = _cache["GetSerLengthByBonus", nID] as ObjectsTemplate; if (bonusServiceLengths != null) return bonusServiceLengths; #endregion 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 } #region Cache Footer _cache.Add(bonusServiceLengths, "GetSerLengthByBonus", nID); #endregion return bonusServiceLengths; } public ObjectsTemplate GetSlabByBonus(ID nID) { #region Cache Header ObjectsTemplate bonusSlabs = _cache["GetSlabByBonus", nID] as ObjectsTemplate; if (bonusSlabs != null) return bonusSlabs; #endregion 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 } #region Cache Footer _cache.Add(bonusSlabs, "GetSlabByBonus", nID); #endregion return bonusSlabs; } public ObjectsTemplate GetSalaryItemByBonus(ID nID) { #region Cache Header ObjectsTemplate bonusParamSalaryItems = _cache["GetSalaryItemByBonus", nID] as ObjectsTemplate; if (bonusParamSalaryItems != null) return bonusParamSalaryItems; #endregion 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 } #region Cache Footer _cache.Add(bonusParamSalaryItems, "GetSalaryItemByBonus", nID); #endregion return bonusParamSalaryItems; } public ObjectsTemplate GetAdjustItemByBonus(ID nID) { #region Cache Header ObjectsTemplate bonusParamAdjustItems = _cache["GetAdjustItemByBonus", nID] as ObjectsTemplate; if (bonusParamAdjustItems != null) return bonusParamAdjustItems; #endregion 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 } #region Cache Footer _cache.Add(bonusParamAdjustItems, "GetAdjustItemByBonus", nID); #endregion return bonusParamAdjustItems; } public ID Save(BonusParameter oBonusParameter) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oBonusParameter.IsNew) { int id = tc.GenerateID("BONUSPARAMETER", "BonusParameterID"); base.SetObjectID(oBonusParameter, ID.FromInteger(id)); 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); } foreach (BonusParameter.BonusServiceLength bonusSLength in oBonusParameter.BonusServiceLengths) { bonusSLength.BonusParameterID = oBonusParameter.ID; int id = tc.GenerateID("BonusServiceLength", "BonusSLengthID"); base.SetObjectID(bonusSLength, ID.FromInteger(id)); BonusParameterDA.Insert(tc, bonusSLength); } foreach (BonusParameter.BonusSlab bonusSlab in oBonusParameter.BonusSlabs) { bonusSlab.BonusParameterID = oBonusParameter.ID; int id = tc.GenerateID("BonusSlab", "BonusSlabID"); base.SetObjectID(bonusSlab, ID.FromInteger(id)); BonusParameterDA.Insert(tc, bonusSlab); } foreach (BonusParameter.BonusParamSalaryItem bonusSalaryItem in oBonusParameter.BonusParamSalaryItems) { bonusSalaryItem.BonusParameterID = oBonusParameter.ID; int id = tc.GenerateID("BonusParamSalaryItem", "BonusParamSalaryItemID"); base.SetObjectID(bonusSalaryItem, ID.FromInteger(id)); BonusParameterDA.Insert(tc, bonusSalaryItem); } foreach (BonusParameter.BonusParamAdjustItem bonusAdjustItem in oBonusParameter.BonusParamAdjustItems) { bonusAdjustItem.BonusParameterID = oBonusParameter.ID; int id = tc.GenerateID("BonusParamAdjustItem", "BonusParamAdjustItemID"); base.SetObjectID(bonusAdjustItem, ID.FromInteger(id)); BonusParameterDA.Insert(tc, bonusAdjustItem); } SetupDetailService sdetailService = new SetupDetailService(); sdetailService.Save(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 DataTable GetByBonusIDAndTranType(string bonusIDs, EnmSetupManagerTranType tranType) { #region Cache Header DataTable dtBonusParam = _cache["GetByBonusIDAndTranType", bonusIDs, tranType] as DataTable; if (dtBonusParam != null) return dtBonusParam; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); dtBonusParam = BonusParameterDA.GetByBonusIDAndTranType(tc, bonusIDs, tranType) == null ? new DataTable() : BonusParameterDA.GetByBonusIDAndTranType(tc, bonusIDs, tranType).Tables[0]; tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } #region Cache Footer _cache.Add(dtBonusParam, "GetByBonusIDAndTranType", bonusIDs, tranType); #endregion return dtBonusParam; } public void Delete(ID id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); SetupDetailService sd = new SetupDetailService(); sd.Delete(tc, EnumParameterSetup.Bonus, id); 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 } } #endregion } #endregion }