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 TaxParameter Service [Serializable] public class TaxParameterService : ServiceTemplate, ITaxParameterService { #region Private functions and declaration Cache _cache = new Cache(typeof(TaxParameter)); #endregion public TaxParameterService() { } private void MapObject(TaxParameter oTaxParameter, DataReader oReader) { base.SetObjectID(oTaxParameter, ID.FromInteger(oReader.GetInt32("TaxParamID").GetValueOrDefault())); oTaxParameter.FiscalYear = oReader.GetString("fiscalYear"); oTaxParameter.AssessmentYear = oReader.GetString("assessmentYear"); oTaxParameter.MaxInvestPercent = oReader.GetDouble("maxInvestPercent").Value; oTaxParameter.MaxHRPercent = oReader.GetDouble("maxHRPercent").Value; oTaxParameter.MaxHRAmount = oReader.GetDouble("maxHRAmount").Value; oTaxParameter.MaxMedicalPercent = oReader.GetDouble("MaxMedicalPercent").GetValueOrDefault(); oTaxParameter.MaxMedicalAmount = oReader.GetDouble("MaxMedicalAmount").GetValueOrDefault(); oTaxParameter.MaxConvAmount = oReader.GetDouble("maxConvAmount").Value; oTaxParameter.MaxCPFPercent = oReader.GetDouble("maxCPFPercent").Value; oTaxParameter.MaxInvExempPercent = oReader.GetDouble("maxInvExempPercent").Value; oTaxParameter.MaxInvAmount = oReader.GetDouble("maxInvAmount").Value; oTaxParameter.MinTaxAmount = oReader.GetDouble("minTaxAmount").Value; oTaxParameter.PfIntProjection = oReader.GetDouble("pfIntProjection").Value; oTaxParameter.MaxAge = oReader.GetDouble("maxAge").GetValueOrDefault(); oTaxParameter.InvestmentActiveMonth = oReader.GetDateTime("InvestmentActiveMonth"); oTaxParameter.CreatedBy = oReader.GetID("CreatedBy"); oTaxParameter.CreatedDate = oReader.GetDateTime("CreationDate").GetValueOrDefault(); oTaxParameter.ModifiedBy = oReader.GetID("ModifiedBy"); oTaxParameter.ModifiedDate = oReader.GetDateTime("ModifiedDate").GetValueOrDefault(); this.SetObjectState(oTaxParameter, Ease.CoreV35.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { TaxParameter oTaxParameter = new TaxParameter(); MapObject(oTaxParameter, oReader); return oTaxParameter as T; } protected TaxParameter CreateObject(DataReader oReader) { TaxParameter oTaxParameter = new TaxParameter(); MapObject(oTaxParameter, oReader); return oTaxParameter; } private void MapTaxSlabObject(TaxParameterSlab oTaxParamSlab, DataReader oReader) { base.SetObjectID(oTaxParamSlab, oReader.GetID("TAXPARAMID")); oTaxParamSlab.TaxparamID = oReader.GetID("TAXPARAMID"); oTaxParamSlab.SequenceNo = oReader.GetInt32("SEQUENCENO").Value; oTaxParamSlab.IncomeAmount = oReader.GetDouble("INCOMEAMOUNT").Value; oTaxParamSlab.TaxPercent = oReader.GetDouble("TAXPERCENT").Value; oTaxParamSlab.ParamType = (EnumTaxSlabType)oReader.GetInt32("TYPE").GetValueOrDefault(); this.SetObjectState(oTaxParamSlab, Ease.CoreV35.ObjectState.Saved); } protected ObjectsTemplate CreateTaxSlabObject(DataReader oReader) { ObjectsTemplate oTaxParamSlabs = new ObjectsTemplate(); while (oReader.Read()) { TaxParameterSlab oTaxParamSlab = new TaxParameterSlab(); MapTaxSlabObject(oTaxParamSlab, oReader); oTaxParamSlabs.Add(oTaxParamSlab); } return oTaxParamSlabs; } #region Service implementation public TaxParameter Get(ID id) { TaxParameter oTaxParameter = new TaxParameter(); #region Cache Header oTaxParameter = _cache["Get", id] as TaxParameter; if (oTaxParameter != null) return oTaxParameter; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(TaxParameterDA.Get(tc, id)); if (oreader.Read()) { oTaxParameter = this.CreateObject(oreader); oreader.Close(); if (oTaxParameter != null) { DataReader dr = new DataReader(TaxParameterDA.GetSlabsByParamID(tc, oTaxParameter.ID)); //dr.Close(); oTaxParameter.TaxParameterSlabs = this.CreateTaxSlabObject(dr); dr.Close(); } } //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(oTaxParameter, "Get", id); #endregion return oTaxParameter; } public TaxParameter GetOldTaxParameter(ID id) { TaxParameter oTaxParameter = new TaxParameter(); #region Cache Header oTaxParameter = _cache["GetOldTaxParameter", id] as TaxParameter; if (oTaxParameter != null) return oTaxParameter; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(TaxParameterDA.GetOldTaxParameter(tc, id)); if (oreader.Read()) { oTaxParameter = this.CreateObject(oreader); oreader.Close(); if (oTaxParameter != null) { DataReader dr = new DataReader(TaxParameterDA.GetOldSlabsByParamID(tc, oTaxParameter.ID)); //dr.Close(); oTaxParameter.TaxParameterSlabs = this.CreateTaxSlabObject(dr); dr.Close(); } } //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(oTaxParameter, "GetOldTaxParameter", id); #endregion return oTaxParameter; } public TaxParameter Get(string assessmentYear) { TaxParameter oTaxParameter = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(TaxParameterDA.Get(tc, assessmentYear)); if (oreader.Read()) { oTaxParameter = 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 } return oTaxParameter; } public ObjectsTemplate Get(bool IsCurrentFY, int payrollTypeID) { #region Cache Header ObjectsTemplate taxParameters = _cache["Get", IsCurrentFY] as ObjectsTemplate; if (taxParameters != null) return taxParameters; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(TaxParameterDA.Get(tc, IsCurrentFY, payrollTypeID)); taxParameters = 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(taxParameters, "Get", IsCurrentFY); #endregion return taxParameters; } //Tax Card From Old Table public DataTable GetOldTaxCard(bool IsCurrentFY, int payrollTypeID) { DataTable dtTaxCard = new DataTable(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); dtTaxCard = TaxParameterDA.GetOldTaxCard(tc, IsCurrentFY, payrollTypeID).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 } return dtTaxCard; } public ObjectsTemplate Get() { #region Cache Header ObjectsTemplate taxParameters = _cache["Get"] as ObjectsTemplate; if (taxParameters != null) return taxParameters; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(TaxParameterDA.Get(tc)); taxParameters = 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(taxParameters, "Get"); #endregion return taxParameters; } public ObjectsTemplate GetTaxSlabs(ID nID, EnumTaxSlabType TaxType) { #region Cache Header ObjectsTemplate taxParameterSlabs = _cache["GetTaxSlabs", nID, TaxType] as ObjectsTemplate; if (taxParameterSlabs != null) return taxParameterSlabs; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(TaxParameterDA.GetTaxSlabs(tc, nID, TaxType)); dr.Close(); taxParameterSlabs = this.CreateTaxSlabObject(dr); 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(taxParameterSlabs, "GetTaxSlabs", nID, TaxType); #endregion return taxParameterSlabs; } public DataSet GetTSByParamAndType(ID nID, EnumTaxSlabType TaxType) { DataSet taxParameterSlabs = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); taxParameterSlabs = TaxParameterDA.GetTSByParamAndType(tc, nID, TaxType); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return taxParameterSlabs; } public ObjectsTemplate GetSlabsByParamID(ID nID) { #region Cache Header ObjectsTemplate taxParameterSlabs = _cache["GetSlabsByParamID", nID] as ObjectsTemplate; if (taxParameterSlabs != null) return taxParameterSlabs; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(TaxParameterDA.GetSlabsByParamID(tc, nID)); taxParameterSlabs = this.CreateTaxSlabObject(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(taxParameterSlabs, "GetSlabsByParamID", nID); #endregion return taxParameterSlabs; } public DataTable GetFiscalYearFromOldTable(ID payrollTypeID) { #region Cache Header DataTable dtTaxParameter = _cache["GetFiscalYearFromOldTable", payrollTypeID] as DataTable; if (dtTaxParameter != null) return dtTaxParameter; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); dtTaxParameter = TaxParameterDA.GetFiscalYearFromOldTable(tc, payrollTypeID).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(dtTaxParameter, "GetFiscalYearFromOldTable", payrollTypeID); #endregion return dtTaxParameter; } public ID Save(TaxParameter oTaxParameter) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oTaxParameter.IsNew) { int MaxID = TaxParameterDA.GetMaxID(tc); int id = tc.GenerateID("TaxParameter", "TaxParamID"); base.SetObjectID(oTaxParameter, ID.FromInteger(id)); TaxParameterDA.Insert(tc, oTaxParameter); if (MaxID != 0) { ObjectsTemplate TaxMergeMasters = new TaxMergeMasterService().GetByTaxParamID(tc, MaxID); if (TaxMergeMasters != null) { foreach (TaxMergeMaster oTaxMergeMaster in TaxMergeMasters) { int newId = tc.GenerateID("TaxMergeMaster", "TaxMergeID"); int position = tc.GenerateID("TaxMergeMaster", "Position"); oTaxMergeMaster.Position = position; oTaxMergeMaster.TaxParameterID = ID.FromInteger(id); base.SetObjectID(oTaxMergeMaster, ID.FromInteger(newId)); TaxMergeMasterDA.Insert(tc, oTaxMergeMaster); foreach (TaxMergeMaster.TaxMergeDetail oTaxMergeDetail in oTaxMergeMaster.TaxMergeDetails) { int detailid = tc.GenerateID("TaxMergeDetail", "DetailId"); base.SetObjectID(oTaxMergeDetail, ID.FromInteger(detailid)); oTaxMergeDetail.TaxMergeID = ID.FromInteger(newId); oTaxMergeDetail.TaxParameterID = oTaxMergeMaster.TaxParameterID; TaxMergeMasterDA.Insert(tc, oTaxMergeDetail); } } } } } else { TaxParameterDA.Update(tc, oTaxParameter); TaxParameterDA.DeleteByParamID(tc, oTaxParameter.ID); } int seqNo = 1; foreach (TaxParameterSlab taxParamSlab in oTaxParameter.TaxParameterSlabs) { if (taxParamSlab.ParamType == EnumTaxSlabType.Male) { taxParamSlab.TaxparamID = oTaxParameter.ID; taxParamSlab.SequenceNo = seqNo++; TaxParameterDA.Insert(tc, taxParamSlab); } } seqNo = 1; foreach (TaxParameterSlab taxParamSlab in oTaxParameter.TaxParameterSlabs) { if (taxParamSlab.ParamType == EnumTaxSlabType.Female) { taxParamSlab.TaxparamID = oTaxParameter.ID; taxParamSlab.SequenceNo = seqNo++; TaxParameterDA.Insert(tc, taxParamSlab); } } seqNo = 1; foreach (TaxParameterSlab taxParamSlab in oTaxParameter.TaxParameterSlabs) { if (taxParamSlab.ParamType == EnumTaxSlabType.Age) { taxParamSlab.TaxparamID = oTaxParameter.ID; taxParamSlab.SequenceNo = seqNo++; TaxParameterDA.Insert(tc, taxParamSlab); } } seqNo = 1; foreach (TaxParameterSlab taxParamSlab in oTaxParameter.TaxParameterSlabs) { if (taxParamSlab.ParamType == EnumTaxSlabType.Disable) { taxParamSlab.TaxparamID = oTaxParameter.ID; taxParamSlab.SequenceNo = seqNo++; TaxParameterDA.Insert(tc, taxParamSlab); } } seqNo = 1; foreach (TaxParameterSlab taxParamSlab in oTaxParameter.TaxParameterSlabs) { if (taxParamSlab.ParamType == EnumTaxSlabType.Freedom_Fighter) { taxParamSlab.TaxparamID = oTaxParameter.ID; taxParamSlab.SequenceNo = seqNo++; TaxParameterDA.Insert(tc, taxParamSlab); } } tc.End(); return oTaxParameter.ID; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public ID SaveCopy(TaxParameter oTaxParameter) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); int MaxID = TaxParameterDA.GetMaxID(tc); int id = tc.GenerateID("TaxParameter", "TaxParamID"); base.SetObjectID(oTaxParameter, ID.FromInteger(id)); TaxParameterDA.Insert(tc, oTaxParameter); TaxParameterDA.DeleteByParamID(tc, oTaxParameter.ID); TaxMergeMasterDA.DeleteByTaxParamID(tc, oTaxParameter.ID); if (MaxID != 0) { ObjectsTemplate TaxMergeMasters = new TaxMergeMasterService().GetByTaxParamID(tc, MaxID); if (TaxMergeMasters != null) { foreach (TaxMergeMaster oTaxMergeMaster in TaxMergeMasters) { int newId = tc.GenerateID("TaxMergeMaster", "TaxMergeID"); int position = tc.GenerateID("TaxMergeMaster", "Position"); oTaxMergeMaster.Position = position; oTaxMergeMaster.TaxParameterID = ID.FromInteger(id); base.SetObjectID(oTaxMergeMaster, ID.FromInteger(newId)); TaxMergeMasterDA.Insert(tc, oTaxMergeMaster); foreach (TaxMergeMaster.TaxMergeDetail oTaxMergeDetail in oTaxMergeMaster.TaxMergeDetails) { int detailid = tc.GenerateID("TaxMergeDetail", "DetailId"); base.SetObjectID(oTaxMergeDetail, ID.FromInteger(detailid)); oTaxMergeDetail.TaxMergeID = ID.FromInteger(newId); oTaxMergeDetail.TaxParameterID = oTaxMergeMaster.TaxParameterID; TaxMergeMasterDA.Insert(tc, oTaxMergeDetail); } } } } int seqNo = 1; foreach (TaxParameterSlab taxParamSlab in oTaxParameter.TaxParameterSlabs) { if (taxParamSlab.ParamType == EnumTaxSlabType.Male) { taxParamSlab.TaxparamID = oTaxParameter.ID; taxParamSlab.SequenceNo = seqNo++; TaxParameterDA.Insert(tc, taxParamSlab); } } seqNo = 1; foreach (TaxParameterSlab taxParamSlab in oTaxParameter.TaxParameterSlabs) { if (taxParamSlab.ParamType == EnumTaxSlabType.Female) { taxParamSlab.TaxparamID = oTaxParameter.ID; taxParamSlab.SequenceNo = seqNo++; TaxParameterDA.Insert(tc, taxParamSlab); } } seqNo = 1; foreach (TaxParameterSlab taxParamSlab in oTaxParameter.TaxParameterSlabs) { if (taxParamSlab.ParamType == EnumTaxSlabType.Age) { taxParamSlab.TaxparamID = oTaxParameter.ID; taxParamSlab.SequenceNo = seqNo++; TaxParameterDA.Insert(tc, taxParamSlab); } } seqNo = 1; foreach (TaxParameterSlab taxParamSlab in oTaxParameter.TaxParameterSlabs) { if (taxParamSlab.ParamType == EnumTaxSlabType.Disable) { taxParamSlab.TaxparamID = oTaxParameter.ID; taxParamSlab.SequenceNo = seqNo++; TaxParameterDA.Insert(tc, taxParamSlab); } } seqNo = 1; foreach (TaxParameterSlab taxParamSlab in oTaxParameter.TaxParameterSlabs) { if (taxParamSlab.ParamType == EnumTaxSlabType.Freedom_Fighter) { taxParamSlab.TaxparamID = oTaxParameter.ID; taxParamSlab.SequenceNo = seqNo++; TaxParameterDA.Insert(tc, taxParamSlab); } } tc.End(); return oTaxParameter.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(ID id, int payrollTypeID) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); TaxParameterDA.Delete(tc, id, payrollTypeID); 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 }