HRM-10/HRM.DA/Service/AllowDeduct/ComponentUploadSetupService.cs

466 lines
17 KiB
C#
Raw Normal View History

2026-11-03 13:06:00 +06:00
using System;
using Ease.Core.Model;
using Ease.Core.DataAccess;
using System.Collections.Generic;
using Ease.Core.Utility;
using HRM.BO;
using System.Data;
2026-11-03 13:06:00 +06:00
namespace HRM.DA
{
public class ComponentUploadSetupService : ServiceTemplate, IComponentUploadSetupService
{
#region Private functions and declaration
public ComponentUploadSetupService() { }
2026-11-03 13:06:00 +06:00
private void MapObject(ComponentUploadSetup componentSetup, DataReader oReader)
{
base.SetObjectID(componentSetup, oReader.GetInt32("ComponentUploadSetupID", true, 0));
componentSetup.EmployeeID = oReader.GetInt32("EmployeeID", true, 0);
componentSetup.ApproverID = oReader.GetInt32("ApproverID", true, 0);
componentSetup.ItemID = oReader.GetInt32("ItemID", true, 0);
componentSetup.ComponentType = (EnumComponentType)oReader.GetInt32("ComponentType", true, 0);
componentSetup.Description = oReader.GetString("Description", true, null);
componentSetup.IsDamageManagement = oReader.GetBoolean("IsDamageManagement", true, false);
2026-11-03 13:06:00 +06:00
this.SetObjectState(componentSetup, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
ComponentUploadSetup componentSetup = new ComponentUploadSetup();
MapObject(componentSetup, oReader);
return componentSetup as T;
}
private ComponentUploadSetup CreateObject(DataReader oReader)
{
ComponentUploadSetup componentSetup = new ComponentUploadSetup();
MapObject(componentSetup, oReader);
return componentSetup;
}
2026-11-03 13:06:00 +06:00
#endregion
#region Service implementation
public List<ComponentUploadSetup> Get()
{
List<ComponentUploadSetup> componentSetups = new List<ComponentUploadSetup>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ComponentUploadSetupDA.Get(tc));
componentSetups = this.CreateObjects<ComponentUploadSetup>(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 componentSetups;
}
public DataTable GetUploadedComponent(DateTime uploadMonth)
{
DataTable dtUploadedComponent = new DataTable();
List <ComponentUploadSetup> componentSetups = new List<ComponentUploadSetup>();
2026-11-03 13:06:00 +06:00
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataSet ds = ComponentUploadSetupDA.GetUploadedComponent(tc, uploadMonth);
dtUploadedComponent = (ds != null && (ds.Tables != null && ds.Tables.Count > 0)) ? ds.Tables[0] : new DataTable();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
2026-11-03 13:06:00 +06:00
#endregion
}
return dtUploadedComponent;
}
2026-11-03 13:06:00 +06:00
public List<ComponentUploadSetup> Get(int empid)
{
List<ComponentUploadSetup> componentSetups = new List<ComponentUploadSetup>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ComponentUploadSetupDA.Get(tc, empid));
componentSetups = this.CreateObjects<ComponentUploadSetup>(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
}
2026-11-03 13:06:00 +06:00
return componentSetups;
}
public List<ComponentUploadSetup> GetByEmpIDandItemID(int empId, int itemId)
2026-11-03 13:06:00 +06:00
{
List<ComponentUploadSetup> componentSetups = new List<ComponentUploadSetup>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ComponentUploadSetupDA.GetByEmpIDandItemID(tc, empId, itemId));
componentSetups = this.CreateObjects<ComponentUploadSetup>(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 componentSetups;
}
2026-11-03 13:06:00 +06:00
public List<ComponentUploadSetup> GetByApproverID(int apprvrID)
{
List<ComponentUploadSetup> componentSetups = new List<ComponentUploadSetup>();
2026-11-03 13:06:00 +06:00
TransactionContext tc = null;
2026-11-03 13:06:00 +06:00
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ComponentUploadSetupDA.GetByApproverID(tc, apprvrID));
2026-11-03 13:06:00 +06:00
componentSetups = this.CreateObjects<ComponentUploadSetup>(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 componentSetups;
}
public DataTable GetUploadedComponentReportData(DateTime fromDate, DateTime toDate)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataSet ds = ComponentUploadSetupDA.GetUploadedComponentReportData(tc, fromDate, toDate);
tc.End();
if (ds != null && ds.Tables.Count > 0)
return ds.Tables[0].Copy();
2026-11-03 13:06:00 +06:00
return new DataTable();
}
catch (Exception e)
{
2026-11-03 13:06:00 +06:00
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
}
}
2026-11-03 13:06:00 +06:00
public DataTable GetUploadedComponentEmpReportData(DateTime salaryMonth, int componentId, string empIds)
{
DataTable dtComponentSetups = new DataTable();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataSet ds = ComponentUploadSetupDA.GetUploadedComponentEmpReportData(tc, salaryMonth, componentId, empIds);
dtComponentSetups = (ds != null && (ds.Tables != null && ds.Tables.Count > 0)) ? ds.Tables[0] : new DataTable();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
2026-11-03 13:06:00 +06:00
#endregion
}
return dtComponentSetups;
}
2026-11-03 13:06:00 +06:00
public DataTable GetUploadedComponentEmpReportData(DateTime salaryMonth, string empIds)
{
DataTable dtComponentSetups = new DataTable();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataSet ds = ComponentUploadSetupDA.GetUploadedComponentEmpReportData(tc, salaryMonth, empIds);
dtComponentSetups = (ds != null && (ds.Tables != null && ds.Tables.Count > 0)) ? ds.Tables[0] : new DataTable();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return dtComponentSetups;
2026-11-03 13:06:00 +06:00
}
public void Save(List<ComponentUploadSetup> componentSetups)
2026-11-03 13:06:00 +06:00
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
int id;
foreach (ComponentUploadSetup componentSetup in componentSetups)
2026-11-03 13:06:00 +06:00
{
if (componentSetup.IsNew)
{
id = tc.GenerateID("ComponentUploadSetup", "ComponentUploadSetupID");
base.SetObjectID(componentSetup, id);
ComponentUploadSetupDA.Insert(tc, componentSetup);
}
else
{
ComponentUploadSetupDA.Update(tc, componentSetup);
}
2026-11-03 13:06:00 +06:00
}
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new Exception("Failed to Component Upload Setup. Because " + e.Message, e);
#endregion
}
2026-11-03 13:06:00 +06:00
}
public void Delete(int id)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
ComponentUploadSetupDA.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 void DeleteSingleComponent(ComponentUploadSetup oComponentUploadSetup)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
ComponentUploadSetupDA.DeleteSingleComponent(tc, oComponentUploadSetup.EmployeeID, oComponentUploadSetup.ApproverID, oComponentUploadSetup.ComponentType, oComponentUploadSetup.ItemID);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
2026-11-03 13:06:00 +06:00
public bool IsExist(int empId, int apprvrId, EnumComponentType componentType, int itemId)
2026-11-03 13:06:00 +06:00
{
bool exist = false;
2026-11-03 13:06:00 +06:00
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
exist = ComponentUploadSetupDA.IsExist(tc, empId, apprvrId, componentType, itemId);
2026-11-03 13:06:00 +06:00
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return exist;
}
2026-11-03 13:06:00 +06:00
/// <summary>The employee is the approver of at least one component upload setup.</summary>
public bool HasApproverSetup(int approverId)
{
bool exist = false;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
exist = ComponentUploadSetupDA.HasApproverSetup(tc, approverId);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
2026-11-03 13:06:00 +06:00
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return exist;
}
2026-11-03 13:06:00 +06:00
/// <summary>The employee has at least one component upload setup (may upload components).</summary>
public bool HasUploaderSetup(int employeeId)
{
bool exist = false;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
exist = ComponentUploadSetupDA.HasUploaderSetup(tc, employeeId);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
2026-11-03 13:06:00 +06:00
#endregion
}
return exist;
}
public List<ComponentUploadSetup> LoadComponentType(int payrollTypeID)
{
List<ComponentUploadSetup> oComponentUploadSetups = new List<ComponentUploadSetup>();
ComponentUploadSetup oallance = null;
ComponentUploadSetup odeduction = null;
ComponentUploadSetup oterm = null;
ComponentUploadSetup obonus = null;
ComponentUploadSetup oloan = null;
ComponentUploadSetup opiItem = null;
ComponentUploadSetup opf = null;
List<AllowanceDeduction> allowances = new AllowanceDeductionService().GetAllowance(EnumStatus.Regardless, payrollTypeID);
foreach (AllowanceDeduction item in allowances)
{
oallance = new ComponentUploadSetup();
oallance.ComponentType = EnumComponentType.Allowance;
oallance.Description = item.Name;
oallance.ItemID = item.ID;
oComponentUploadSetups.Add(oallance);
}
2026-11-03 13:06:00 +06:00
List<AllowanceDeduction> deductions = new AllowanceDeductionService().GetDeduction(EnumStatus.Regardless, payrollTypeID);
foreach (AllowanceDeduction item in deductions)
{
odeduction = new ComponentUploadSetup();
odeduction.ComponentType = EnumComponentType.Deduction;
odeduction.Description = item.Name;
odeduction.ItemID = item.ID;
oComponentUploadSetups.Add(odeduction);
}
List<Term> terms = new TermService().Get(EnumStatus.Regardless, payrollTypeID);
foreach (Term item in terms)
{
oterm = new ComponentUploadSetup();
oterm.ComponentType = EnumComponentType.OverTime;
oterm.Description = item.Name;
oterm.ItemID = item.ID;
oComponentUploadSetups.Add(oterm);
}
List<Bonus> bonuss = new BonusService().Get(EnumStatus.Regardless, payrollTypeID);
foreach (Bonus item in bonuss)
{
obonus = new ComponentUploadSetup();
obonus.ComponentType = EnumComponentType.Bonus;
obonus.Description = item.Name;
obonus.ItemID = item.ID;
oComponentUploadSetups.Add(obonus);
}
List<Loan> loans = new LoanService().Get(EnumStatus.Regardless);
foreach (Loan item in loans)
{
oloan = new ComponentUploadSetup();
oloan.ComponentType = EnumComponentType.Loan;
oloan.Description = item.Name;
oloan.ItemID = item.ID;
oComponentUploadSetups.Add(oloan);
}
List<OpiItem> opiItems = new OpiItemService().Get(EnumStatus.Regardless, payrollTypeID);
foreach (OpiItem item in opiItems)
{
opiItem = new ComponentUploadSetup();
opiItem.ComponentType = EnumComponentType.OPI;
opiItem.Description = item.Name;
opiItem.ItemID = item.ID;
oComponentUploadSetups.Add(opiItem);
}
opf = new ComponentUploadSetup();
opf.ComponentType = EnumComponentType.PF;
opf.Description = "PF";
opf.ItemID = (int)EnumComponentType.PF;
oComponentUploadSetups.Add(opf);
return oComponentUploadSetups;
2026-11-03 13:06:00 +06:00
}
2026-11-03 13:06:00 +06:00
#endregion
}
}