EchoTex_Payroll/HRM.DA/Service/Basic/GradeService.cs
2024-10-14 10:01:49 +06:00

671 lines
19 KiB
C#

using HRM.BO;
using HRM.DA;
using Ease.Core.DataAccess;
using Ease.Core.Model;
using Ease.Core.Utility;
using System;
using System.Collections.Generic;
using NPOI.SS.Formula.Functions;
namespace HRM.DA
{
public class GradeService : ServiceTemplate, IGradeService
{
public GradeService()
{
}
private void MapObject(Grade oGrade, DataReader oReader)
{
base.SetObjectID(oGrade, oReader.GetInt32("GradeID").Value);
oGrade.Code = oReader.GetString("code");
oGrade.Name = oReader.GetString("description");
oGrade.NameInBangla = oReader.GetString("descriptioninbangla", true, null);
oGrade.ColorCode = oReader.GetString("ColorCode");
oGrade.MaxBasic = oReader.GetDouble("maxbasic").Value;
oGrade.MinBasic = oReader.GetDouble("minbasic").Value;
oGrade.IsTransport = oReader.GetBoolean("isfreetransport").Value;
oGrade.HasGrossConcept = oReader.GetBoolean("hasGrossConcept").Value;
oGrade.IsOTApplicable = oReader.GetBoolean("IsOTApplicable", false);
oGrade.BasicPercentOfGross = oReader.GetDouble("basicPercentofGross").Value;
oGrade.HasPayscale = oReader.GetBoolean("hasPayscale").Value;
oGrade.ConfirmMonthDuration = oReader.GetInt32("confirmMonthDuration").Value;
oGrade.GradeSegmentID = oReader.GetInt32("gradeSegmentID", 0);
oGrade.RequiredDays = oReader.GetDouble("RequiredDays").Value;
oGrade.Sequence = oReader.GetInt32("SequenceNo", 0);
oGrade.Increment = oReader.GetDouble("IncrementAmount", 0);
oGrade.MarketAnchor = oReader.GetDouble("MarketAnchor", 0);
oGrade.InsuranceCoverage = oReader.GetInt32("InsuranceCoverage", 0);
oGrade.Status = (EnumStatus)oReader.GetInt32("Status", (int)EnumStatus.Regardless);
oGrade.CreatedBy = oReader.GetInt32("CreatedBy", 0);
oGrade.CreatedDate = oReader.GetDateTime("CreationDate", DateTime.MinValue);
oGrade.ModifiedBy = oReader.GetInt32("ModifiedBy", 0);
oGrade.ModifiedDate = oReader.GetDateTime("ModifiedDate", DateTime.MinValue);
oGrade.PayrollTypeID = oReader.GetInt32("PAYROLLTYPEID", 0);
this.SetObjectState(oGrade, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
Grade oGrade = new Grade();
MapObject(oGrade, oReader);
return oGrade as T;
}
#region Service implementation
public Grade Get(int id)
{
Grade oGrade = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(GradeDA.Get(tc, id));
if (oreader.Read())
{
oGrade = this.CreateObject<Grade>(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 oGrade;
}
public Grade Get(TransactionContext tc, int id)
{
Grade oGrade = null;
try
{
DataReader oreader = new DataReader(GradeDA.Get(tc, id));
if (oreader.Read())
{
oGrade = this.CreateObject<Grade>(oreader);
}
oreader.Close();
}
catch (Exception e)
{
#region Handle Exception
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return oGrade;
}
public Grade Get(string sCode)
{
Grade oGrade = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(GradeDA.Get(tc, sCode));
if (oreader.Read())
{
oGrade = this.CreateObject<Grade>(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 oGrade;
}
public Grade GetByPayrollType(string sCode, int payrollTypeID)
{
Grade oGrade = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(GradeDA.GetByPayrollType(tc, sCode, payrollTypeID));
if (oreader.Read())
{
oGrade = this.CreateObject<Grade>(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 oGrade;
}
public int GetMaxGradeID()
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
int id = tc.GenerateID("GRADES", "GRADEID");
return id - 1;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
finally
{
tc.End();
}
}
public List<Grade> Get(EnumStatus status, int payrollTypeID)
{
List<Grade> grades = new List<Grade>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(GradeDA.Get(tc, status, payrollTypeID));
grades = this.CreateObjects<Grade>(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 grades;
}
public List<Grade> Get(EnumStatus status)
{
List<Grade> grades = new List<Grade>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(GradeDA.Get(tc, status));
grades = this.CreateObjects<Grade>(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 grades;
}
public List<Grade> Get(EnumStatus status, string sIDs, string sTargetPropertyName, int payrolltypeid)
{
List<Grade> grades = new List<Grade>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(GradeDA.Get(tc, status, sIDs, sTargetPropertyName, payrolltypeid));
grades = this.CreateObjects<Grade>(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 grades;
}
public List<Grade> GetAddableGrades(int nAllowDeductID, int nADParamID, int payrollTypeID)
{
List<Grade> grades = new List<Grade>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = null;
if (nADParamID == 0)
{
dr = new DataReader(GradeDA.GetAddableGrades(tc, nAllowDeductID, 0, payrollTypeID));
}
else
{
dr = new DataReader(GradeDA.GetAddableGrades(tc, nAllowDeductID, nADParamID, payrollTypeID));
}
grades = this.CreateObjects<Grade>(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 grades;
}
public List<Grade> GetAllPayrollTypes(EnumStatus status)
{
List<Grade> grades = new List<Grade>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(GradeDA.GetAllPayrollTypes(tc, status));
grades = this.CreateObjects<Grade>(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 grades;
}
public List<Grade> GetAddableGradesForLoanParameter(int LoaniD, int LoanParameterId, int payrolltypeid)
{
List<Grade> grades = new List<Grade>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = null;
if (LoanParameterId == 0)
{
dr = new DataReader(GradeDA.GetAddableGradesForLoanParameter(tc, LoaniD, 0, payrolltypeid));
}
else
{
dr = new DataReader(
GradeDA.GetAddableGradesForLoanParameter(tc, LoaniD, LoanParameterId, payrolltypeid));
}
grades = this.CreateObjects<Grade>(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 grades;
}
public List<Grade> GetAddableGradesForOT(int nTermID, int nTermParameterID, int payrollTypeID)
{
List<Grade> grades = new List<Grade>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = null;
if (nTermParameterID == 0)
{
dr = new DataReader(GradeDA.GetAddableGradesForOT(tc, nTermID, 0, payrollTypeID));
}
else
{
dr = new DataReader(GradeDA.GetAddableGradesForOT(tc, nTermID, nTermParameterID, payrollTypeID));
}
grades = this.CreateObjects<Grade>(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 grades;
}
public List<Grade> GetAddableGradesForBonus(int nBonusID, int payrollTypeID)
{
List<Grade> grades = new List<Grade>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = null;
//if (nBonusID.IsUnassigned)
//{
// dr = new DataReader(GradeDA.GetAddableGradesForBonus(tc,0));
//}
//else
//{
dr = new DataReader(GradeDA.GetAddableGradesForBonus(tc, nBonusID, payrollTypeID));
//}
grades = this.CreateObjects<Grade>(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 grades;
}
public int Save(Grade oGrade)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oGrade.IsNew)
{
int id = tc.GenerateID("GRADES", "GRADEID");
base.SetObjectID(oGrade, id);
GradeDA.Insert(tc, oGrade);
}
else
{
GradeDA.Update(tc, oGrade);
}
tc.End();
return oGrade.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);
GradeDA.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 List<Grade> GetAllowableGrades(int nOpiItmeID, int nOpiParamID, int payrollTypeID)
{
List<Grade> grades = new List<Grade>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = null;
if (nOpiParamID == 0)
{
dr = new DataReader(GradeDA.GetAllowableGrades(tc, nOpiItmeID, 0, payrollTypeID));
}
else
{
dr = new DataReader(GradeDA.GetAllowableGrades(tc, nOpiItmeID, nOpiParamID, payrollTypeID));
}
grades = this.CreateObjects<Grade>(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 grades;
}
#endregion
//For excel Upload
public static void SaveForUpload(TransactionContext tc, List<Grade> grades, List<Grade> saveItems)
{
try
{
foreach (Grade oGrade in grades)
{
if (saveItems.FindIndex(x => x.ID == oGrade.ID) < 0)
{
int seqNo = tc.GenerateID("GRADES", "SequenceNo");
oGrade.Sequence = seqNo;
if(oGrade.Code ==string.Empty)
{
oGrade.Code =GlobalFunctionService.GetMaxCode(tc, "Grades", "Code");
}
oGrade.CreatedDate = DateTime.Now;
GradeDA.Insert(tc, oGrade);
}
else
{
//oGrade.ModifiedBy = oGrade.ModifiedBy;
//oGrade.ModifiedDate = DateTime.Now;
//GradeDA.Update(tc, oGrade);
}
}
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public List<Grade> Get(EnumStatus status, string sIDs, string sTargetPropertyName)
{
throw new NotImplementedException();
}
public List<Grade> GetAddableGradesForLoanParameter(int LoaniD, int LoanParameterId)
{
throw new NotImplementedException();
}
public List<Grade> GetAllGrade(int payrollTypeID, EnumStatus status, string code, string name)
{
List<Grade> grades = new List<Grade>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(GradeDA.GetAllGrade(tc, payrollTypeID, status, code, name));
grades = this.CreateObjects<Grade>(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 grades;
}
}
}