EchoTex_Payroll/HRM.DA/Service/Tax/TaxMergeMasterService.cs

386 lines
13 KiB
C#
Raw Normal View History

2024-10-14 10:01:49 +06:00
using Ease.Core.Model;
using Ease.Core.DataAccess;
using HRM.BO;
using Ease.Core.Utility;
using System.Collections.Generic;
using System.Data;
using Ease.Core;
using Payroll.Service;
using System;
namespace HRM.DA
{
public class TaxMergeMasterService : ServiceTemplate, ITaxMergeMasterService
{
public TaxMergeMasterService()
{
}
private void MapObject(TaxMergeMaster oTaxMergeMaster, DataReader oReader)
{
base.SetObjectID(oTaxMergeMaster, oReader.GetInt32("TaxMergeID").Value);
oTaxMergeMaster.TaxParameterID = oReader.GetInt32("TAXPARAMID", 0);
oTaxMergeMaster.ItemID = oReader.GetInt32("ItemID").Value;
oTaxMergeMaster.ItemGroup = (EnumIncomeTaxItemGroup)oReader.GetInt32("ItemGroup").Value;
oTaxMergeMaster.Description = oReader.GetString("DESCRIPTION");
oTaxMergeMaster.Position = oReader.GetInt32("position").Value;
oTaxMergeMaster.Type = (EnumTaxMergeType)oReader.GetInt32("Type").Value;
oTaxMergeMaster.CreatedBy = oReader.GetInt32("CreatedBy", 0);
oTaxMergeMaster.CreatedDate = oReader.GetDateTime("CreationDate").Value;
oTaxMergeMaster.ModifiedBy = oReader.GetInt32("ModifiedBy", 0);
oTaxMergeMaster.ModifiedDate = oReader.GetDateTime("ModifiedDate");
oTaxMergeMaster.PayrollTypeID = oReader.GetInt32("PAYROLLTYPEID", 0);
this.SetObjectState(oTaxMergeMaster, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
TaxMergeMaster oTaxMergeMaster = new TaxMergeMaster();
MapObject(oTaxMergeMaster, oReader);
return oTaxMergeMaster as T;
}
protected TaxMergeMaster CreateObject(DataReader oReader)
{
TaxMergeMaster oTaxMergeMaster = new TaxMergeMaster();
MapObject(oTaxMergeMaster, oReader);
return oTaxMergeMaster;
}
private void MapTaxMDetailObject(TaxMergeMaster.TaxMergeDetail oTaxMergeDetail, DataReader oReader)
{
base.SetObjectID(oTaxMergeDetail, oReader.GetInt32("detailId").Value);
oTaxMergeDetail.TaxMergeID = oReader.GetInt32("TaxMergeID", 0);
oTaxMergeDetail.TaxParameterID = oReader.GetInt32("TaxParameterID", 0);
oTaxMergeDetail.ItemGroup = (EnumIncomeTaxItemGroup)oReader.GetInt32("ItemGroup").Value;
oTaxMergeDetail.ItemID = oReader.GetInt32("ItemID").Value;
oTaxMergeDetail.Type = (EnumTaxMergeType)oReader.GetInt32("Type").Value;
oTaxMergeDetail.Description = oReader.GetString("Description");
oTaxMergeDetail.PayrollTypeID = oReader.GetInt32("PAYROLLTYPEID", 0);
this.SetObjectState(oTaxMergeDetail, Ease.Core.ObjectState.Saved);
}
protected List<TaxMergeMaster.TaxMergeDetail> CreateTaxMDetailObject(DataReader oReader)
{
List<TaxMergeMaster.TaxMergeDetail> oTaxMergeDetails = new List<TaxMergeMaster.TaxMergeDetail>();
while (oReader.Read())
{
TaxMergeMaster.TaxMergeDetail oTaxMergeDetail = new TaxMergeMaster.TaxMergeDetail();
MapTaxMDetailObject(oTaxMergeDetail, oReader);
oTaxMergeDetails.Add(oTaxMergeDetail);
}
return oTaxMergeDetails;
}
#region Service implementation
public TaxMergeMaster Get(int id, int payrollTypeID)
{
TaxMergeMaster oTaxMergeMaster = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(TaxMergeMasterDA.Get(tc, id, payrollTypeID));
if (oreader.Read())
{
oTaxMergeMaster = this.CreateObject<TaxMergeMaster>(oreader);
}
oreader.Close();
if (oTaxMergeMaster != null)
{
DataReader dr = new DataReader(TaxMergeMasterDA.GetDetail(tc, oTaxMergeMaster.ID, payrollTypeID));
oTaxMergeMaster.TaxMergeDetails = this.CreateTaxMDetailObject(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 oTaxMergeMaster;
}
public TaxMergeMaster Get(int payrolltypeid, int taxParamid, EnumTaxMergeType type, int itemid)
{
TaxMergeMaster oTaxMergeMaster = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(TaxMergeMasterDA.Get(tc, payrolltypeid, taxParamid, type, itemid));
if (oreader.Read())
{
oTaxMergeMaster = this.CreateObject<TaxMergeMaster>(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 oTaxMergeMaster;
}
public List<TaxMergeMaster> GetbyTaxParameter(int TaxParameterID, int payrollTypeID)
{
List<TaxMergeMaster> taxMergeMasters = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(TaxMergeMasterDA.GetbyTaxParameter(tc, TaxParameterID, payrollTypeID));
taxMergeMasters = this.CreateObjects<TaxMergeMaster>(dr);
dr.Close();
if (taxMergeMasters != null)
{
dr = new DataReader(TaxMergeMasterDA.GetDetailbyTaxParamID(tc, TaxParameterID, payrollTypeID));
List<TaxMergeMaster.TaxMergeDetail> odetails = this.CreateTaxMDetailObject(dr);
dr.Close();
foreach (TaxMergeMaster item in taxMergeMasters)
{
item.TaxMergeDetails = odetails.FindAll(x => x.TaxMergeID == item.ID);
}
}
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return taxMergeMasters;
}
public List<TaxMergeMaster> Get(int payrolltypeid)
{
List<TaxMergeMaster> taxMergeMasters = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(TaxMergeMasterDA.GetbyPayrollType(tc, payrolltypeid));
taxMergeMasters = this.CreateObjects<TaxMergeMaster>(dr);
dr.Close();
if (taxMergeMasters != null)
{
foreach (TaxMergeMaster item in taxMergeMasters)
{
// dr = new DataReader(TaxMergeMasterDA.GetDetail(tc, item.ID));
item.TaxMergeDetails = this.CreateTaxMDetailObject(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 taxMergeMasters;
}
public List<TaxMergeMaster> GetByTaxParamID(TransactionContext tc, int id, int payrollTypeID)
{
List<TaxMergeMaster> taxMergeMasters = null;
try
{
DataReader dr = new DataReader(TaxMergeMasterDA.GetByTaxParamID(tc, id, payrollTypeID));
taxMergeMasters = this.CreateObjects<TaxMergeMaster>(dr);
dr.Close();
if (taxMergeMasters != null)
{
foreach (TaxMergeMaster item in taxMergeMasters)
{
dr = new DataReader(TaxMergeMasterDA.GetDetail(tc, item.ID, payrollTypeID));
item.TaxMergeDetails = this.CreateTaxMDetailObject(dr);
dr.Close();
}
}
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return taxMergeMasters;
}
//public List<TaxMergeMaster.TaxMergeDetail> GetTMDetailByParamID(int nID)
//{
// #region Cache Header
// List<TaxMergeMaster.TaxMergeDetail> taxMergeDetails = _cache["GetTMDetailByParamID", nID] as List<TaxMergeDetail>;
// if (taxMergeDetails != null)
// return taxMergeDetails;
// #endregion
// TransactionContext tc = null;
// try
// {
// tc = TransactionContext.Begin();
// DataReader dr = new DataReader(TaxParameterDA.GetSlabsByParamID(tc, nID));
// taxMergeDetails = this.CreateTaxMDetailObject(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(taxMergeDetails, "GetTMDetailByParamID", nID);
// #endregion
// return taxMergeDetails;
//}
public int Save(TaxMergeMaster oTaxMergeMaster)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oTaxMergeMaster.IsNew)
{
int id = tc.GenerateID("TaxMergeMaster", "TaxMergeID");
int position = tc.GenerateID("TaxMergeMaster", "Position");
oTaxMergeMaster.Position = position;
base.SetObjectID(oTaxMergeMaster, (id));
TaxMergeMasterDA.Insert(tc, oTaxMergeMaster);
}
else
{
TaxMergeMasterDA.Update(tc, oTaxMergeMaster);
TaxMergeMasterDA.DeleteMDetailByMergeID(tc, oTaxMergeMaster.ID);
}
foreach (TaxMergeMaster.TaxMergeDetail oTaxMergeDetail in oTaxMergeMaster.TaxMergeDetails)
{
int detailid = tc.GenerateID("TaxMergeDetail", "DetailId");
base.SetObjectID(oTaxMergeDetail, (detailid));
oTaxMergeDetail.TaxMergeID = oTaxMergeMaster.ID;
oTaxMergeDetail.TaxParameterID = oTaxMergeMaster.TaxParameterID;
oTaxMergeDetail.PayrollTypeID = oTaxMergeMaster.PayrollTypeID;
TaxMergeMasterDA.Insert(tc, oTaxMergeDetail);
}
tc.End();
return oTaxMergeMaster.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);
TaxMergeMasterDA.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
}
}