CEL_Payroll/Payroll.Service/Employee/Service/EmployeeBankAccountService.cs

740 lines
26 KiB
C#
Raw Permalink Normal View History

2024-09-17 14:30:13 +06:00
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 EmployeeBankAccount Service
[Serializable]
public class EmployeeBankAccountService : ServiceTemplate, IEmployeeBankAccountService
{
#region Private functions and declaration
Cache _cache = new Cache(typeof(EmployeeBankAccount));
#endregion
public EmployeeBankAccountService() { }
private void MapObject(EmployeeBankAccount oEmployeeBankAccount, DataReader oReader)
{
base.SetObjectID(oEmployeeBankAccount, oReader.GetID("EmpBankAccountID"));
oEmployeeBankAccount.EmployeeID = oReader.GetID("employeeID");
oEmployeeBankAccount.EffectDate = oReader.GetDateTime("changeDate").Value;
oEmployeeBankAccount.AccountNo = oReader.GetString("accountNo");
oEmployeeBankAccount.BranchID = oReader.GetID("branchID");
oEmployeeBankAccount.AccountType = (EnumBankAccountType)oReader.GetInt32("accountType").Value;
oEmployeeBankAccount.CreatedBy = oReader.GetID("CreatedBy");
oEmployeeBankAccount.CreatedDate = oReader.GetDateTime("CreationDate").Value;
oEmployeeBankAccount.ModifiedBy = oReader.GetID("ModifiedBy");
oEmployeeBankAccount.ModifiedDate = oReader.GetDateTime("ModifiedDate");
this.SetObjectState(oEmployeeBankAccount, Ease.CoreV35.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
EmployeeBankAccount oEmployeeBankAccount = new EmployeeBankAccount();
MapObject(oEmployeeBankAccount, oReader);
return oEmployeeBankAccount as T;
}
protected EmployeeBankAccount CreateObject(DataReader oReader)
{
EmployeeBankAccount oEmployeeBankAccount = new EmployeeBankAccount();
MapObject(oEmployeeBankAccount, oReader);
return oEmployeeBankAccount;
}
#region Service implementation
public EmployeeBankAccount Get(ID id)
{
EmployeeBankAccount oEmployeeBankAccount = new EmployeeBankAccount();
#region Cache Header
oEmployeeBankAccount = _cache["Get", id] as EmployeeBankAccount;
if (oEmployeeBankAccount != null)
return oEmployeeBankAccount;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(EmployeeBankAccountDA.Get(tc, id));
if (oreader.Read())
{
oEmployeeBankAccount = this.CreateObject<EmployeeBankAccount>(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(oEmployeeBankAccount, "Get", id);
#endregion
return oEmployeeBankAccount;
}
public EmployeeBankAccount Get(ID nEmpID, DateTime dEffectDate, int payrollTypeID)
{
EmployeeBankAccount oEmployeeBankAccount = new EmployeeBankAccount();
#region Cache Header
oEmployeeBankAccount = _cache["Get", nEmpID, dEffectDate] as EmployeeBankAccount;
if (oEmployeeBankAccount != null)
return oEmployeeBankAccount;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(EmployeeBankAccountDA.Get(tc, nEmpID, dEffectDate, payrollTypeID));
if (oreader.Read())
{
oEmployeeBankAccount = this.CreateObject<EmployeeBankAccount>(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(oEmployeeBankAccount, "Get", nEmpID,dEffectDate);
#endregion
return oEmployeeBankAccount;
}
public ObjectsTemplate<EmployeeBankAccount> Get()
{
#region Cache Header
ObjectsTemplate<EmployeeBankAccount> employeeBankAccounts = _cache["Get"] as ObjectsTemplate<EmployeeBankAccount>;
if (employeeBankAccounts != null)
return employeeBankAccounts;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(EmployeeBankAccountDA.Get(tc));
employeeBankAccounts = this.CreateObjects<EmployeeBankAccount>(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(employeeBankAccounts, "Get");
#endregion
return employeeBankAccounts;
}
public ObjectsTemplate<EmployeeBankAccount> GetByEmployeeID(ID nID)
{
#region Cache Header
ObjectsTemplate<EmployeeBankAccount> employeeBankAccounts = _cache["GetByEmployeeID"] as ObjectsTemplate<EmployeeBankAccount>;
if (employeeBankAccounts != null)
return employeeBankAccounts;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(EmployeeBankAccountDA.GetByEmployeeID(tc, nID));
employeeBankAccounts = this.CreateObjects<EmployeeBankAccount>(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(employeeBankAccounts, "GetByEmployeeID");
#endregion
return employeeBankAccounts;
}
public DataSet GetEmpBankAdvice(DateTime dateTime,string sEmpID)
{
DataSet oBankAdvices = new DataSet();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
oBankAdvices = EmployeeBankAccountDA.GetEmpBankAdvice(tc, dateTime,sEmpID);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return oBankAdvices;
}
public DataSet GetEmpEuroBankAdvice(DateTime dateTime, string sEmpID)
{
DataSet oEuroBankAdvices = new DataSet();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
oEuroBankAdvices = EmployeeBankAccountDA.GetEmpEuroBankAdvice(tc, dateTime, sEmpID);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return oEuroBankAdvices;
}
public DataSet GetOPIEmpBankAdvice(DateTime dateTime, string sEmpID, int bankID)
{
DataSet oBankAdvices = new DataSet();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
oBankAdvices = EmployeeBankAccountDA.GetEmpOPIBankAdvice(tc, dateTime, sEmpID,bankID);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return oBankAdvices;
}
public DataSet GetEmpCarFuelBankAdvice(DateTime dateTime, string sEmpID, int bankID)
{
DataSet oBankAdvices = new DataSet();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
oBankAdvices = EmployeeBankAccountDA.GetEmpCarFuelBankAdvice(tc, dateTime, sEmpID, bankID);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return oBankAdvices;
}
public DataSet GetHNMOPIEmpBankAdvice(DateTime dateTime, string sEmpID)
{
DataSet oBankAdvices = new DataSet();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
oBankAdvices = EmployeeBankAccountDA.GetHNMEmpOPIBankAdvice(tc, dateTime, sEmpID);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return oBankAdvices;
}
//public DataSet GetEmpExpenseAmount(DateTime dateTime, string sEmpID)
//{
// DataSet oEmpExpenseAmount = new DataSet();
// TransactionContext tc = null;
// try
// {
// tc = TransactionContext.Begin();
// oEmpExpenseAmount = EmployeeBankAccountDA.GetEmpExpenseAmount(tc, dateTime, sEmpID);
// tc.End();
// }
// catch (Exception e)
// {
// #region Handle Exception
// if (tc != null)
// tc.HandleError();
// ExceptionLog.Write(e);
// throw new ServiceException(e.Message, e);
// #endregion
// }
// return oEmpExpenseAmount;
//}
public DataSet GetEmpBankHistory(DateTime dateTime, int payrollTypeID)
{
DataSet oBankHistories = new DataSet();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
oBankHistories = EmployeeBankAccountDA.GetEmpBankHistory(tc, dateTime, payrollTypeID);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return oBankHistories;
}
public DataSet GetEmpBankHistory(DateTime dSFromDate, DateTime dSToDate, int payrollTypeID)
{
DataSet oBankHistories = new DataSet();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
oBankHistories = EmployeeBankAccountDA.GetEmpBankHistory(tc, dSFromDate, dSToDate, payrollTypeID);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return oBankHistories;
}
public DataSet GetEmpPrvBankHistory(DateTime dateTime, int payrollTypeID)
{
DataSet oBankHistories = new DataSet();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
oBankHistories = EmployeeBankAccountDA.GetEmpPrvBankHistory(tc, dateTime, payrollTypeID);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return oBankHistories;
}
public DataSet GetEmpBankAdvice(DateTime salaryMonthDate, int bankID)
{
DataSet oBankHistories = new DataSet();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
oBankHistories = EmployeeBankAccountDA.GetEmpBankAdvice(tc, salaryMonthDate, bankID);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return oBankHistories;
}
public DataSet GetEmpOPIBankAdvice(DateTime salaryMonthDate, int bankID)
{
DataSet oBankHistories = new DataSet();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
oBankHistories = EmployeeBankAccountDA.GetEmpOPIBankAdvice(tc, salaryMonthDate, bankID);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return oBankHistories;
}
public ObjectsTemplate<EmployeeBankAccount> GetNotYetProcessUptoToday()
{
ObjectsTemplate<EmployeeBankAccount> oEmployees = new ObjectsTemplate<EmployeeBankAccount>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(EmployeeBankAccountDA.GetNotYetProcessUptoToday(tc));
oEmployees = this.CreateObjects<EmployeeBankAccount>(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 oEmployees;
}
public ID Save(EmployeeBankAccount oEmployeeBankAccount)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
EmployeeService empservice = new EmployeeService();
if (oEmployeeBankAccount.IsNew)
{
EmployeeBankAccountDA.DeleteByBankEffectDate(tc, oEmployeeBankAccount.EffectDate, oEmployeeBankAccount.EmployeeID, oEmployeeBankAccount.AccountType);
int id = tc.GenerateID("BANKACCOUNTHISTORY", "EmpBankAccountID");
base.SetObjectID(oEmployeeBankAccount, ID.FromInteger(id));
EmployeeBankAccountDA.Insert(tc, oEmployeeBankAccount);
}
else
{
EmployeeBankAccountDA.Update(tc, oEmployeeBankAccount);
}
if (oEmployeeBankAccount.AccountType == EnumBankAccountType.SalaryAccount)
{
empservice.UpdateBankAcc(tc, oEmployeeBankAccount.EmployeeID, oEmployeeBankAccount.BranchID,
oEmployeeBankAccount.AccountNo, EnumPaymentMode.BankTransfer);
}
else
{
empservice.UpdateOPIBankAcc(tc, oEmployeeBankAccount.EmployeeID, oEmployeeBankAccount.BranchID,
oEmployeeBankAccount.AccountNo, EnumPaymentMode.BankTransfer);
}
tc.End();
return oEmployeeBankAccount.ID;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public void SaveIntegration(EmployeeBankAccount oEmployeeBankAccount,TransactionContext tc)
{
// TransactionContext tc = null;
try
{
// tc = TransactionContext.Begin(true);
EmployeeService empservice = new EmployeeService();
//if (oEmployeeBankAccount.IsNew)
//{
EmployeeBankAccountDA.DeleteByBankEffectDate(tc, oEmployeeBankAccount.EffectDate, oEmployeeBankAccount.EmployeeID, oEmployeeBankAccount.AccountType);
int id = tc.GenerateID("BANKACCOUNTHISTORY", "EmpBankAccountID");
base.SetObjectID(oEmployeeBankAccount, ID.FromInteger(id));
EmployeeBankAccountDA.Insert(tc, oEmployeeBankAccount);
//}
//else
//{
// EmployeeBankAccountDA.Update(tc, oEmployeeBankAccount);
//}
if (oEmployeeBankAccount.AccountType == EnumBankAccountType.SalaryAccount)
{
empservice.UpdateBankAcc(tc, oEmployeeBankAccount.EmployeeID, oEmployeeBankAccount.BranchID,
oEmployeeBankAccount.AccountNo, EnumPaymentMode.BankTransfer);
}
else
{
empservice.UpdateOPIBankAcc(tc, oEmployeeBankAccount.EmployeeID, oEmployeeBankAccount.BranchID,
oEmployeeBankAccount.AccountNo, EnumPaymentMode.BankTransfer);
}
//tc.End();
// return oEmployeeBankAccount.ID;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public void Save(TransactionContext tc, ObjectsTemplate<EmployeeBankAccount> EmpBankAccounts, DateTime salaryCutoffDate)
{
try
{
foreach (EmployeeBankAccount item in EmpBankAccounts)
{
this.Save(tc, item, salaryCutoffDate);
}
}
catch (Exception ex)
{
throw new ServiceException(ex.Message);
}
}
public void Save(ObjectsTemplate<EmployeeBankAccount> EmpBankAccounts, DateTime salaryCutoffDate)
{
TransactionContext tc = null;
try
{
foreach (EmployeeBankAccount item in EmpBankAccounts)
{
tc = TransactionContext.Begin(true);
this.Save(tc, item, salaryCutoffDate);
tc.End();
}
}
catch (Exception ex)
{
if (tc == null)
tc.HandleError();
throw new ServiceException(ex.Message);
}
}
public ID Save(TransactionContext tc, EmployeeBankAccount oEmployeeBankAccount, DateTime salaryCutoffDate)
{
try
{
// temporary disabled
//if (salaryCutoffDate <= DateTime.Today &&
// salaryCutoffDate.Month == SystemInformation.CurrentSysInfo.NextPayProcessDate.Month)
// oEmployeeBankAccount.IsProcessed = false;
//else if (SystemInformation.CurrentSysInfo.NextPayProcessDate < DateTime.Today)
// oEmployeeBankAccount.IsProcessed = false;
//else
//{
// if (oEmployeeBankAccount.EffectDate > DateTime.Today)
// oEmployeeBankAccount.IsProcessed = false;
// else
// oEmployeeBankAccount.IsProcessed = true;
//}
// temporary , need to comment
//oEmployeeBankAccount.IsProcessed = true;
EmployeeService empservice = new EmployeeService();
if (oEmployeeBankAccount.IsNew)
{
EmployeeBankAccountDA.DeleteByBankEffectDate(tc, oEmployeeBankAccount.EffectDate, oEmployeeBankAccount.EmployeeID);
int id = tc.GenerateID("BANKACCOUNTHISTORY", "EmpBankAccountID");
base.SetObjectID(oEmployeeBankAccount, ID.FromInteger(id));
EmployeeBankAccountDA.Insert(tc, oEmployeeBankAccount);
//if (oEmployeeBankAccount.IsProcessed == true)
//{
empservice.UpdateBankAcc(tc, oEmployeeBankAccount.EmployeeID, oEmployeeBankAccount.BranchID,
oEmployeeBankAccount.AccountNo, EnumPaymentMode.BankTransfer);
//}
}
else
{
EmployeeBankAccountDA.Update(tc, oEmployeeBankAccount);
//if (oEmployeeBankAccount.IsProcessed == true)
empservice.UpdateBankAcc(tc, oEmployeeBankAccount.EmployeeID, oEmployeeBankAccount.BranchID,
oEmployeeBankAccount.AccountNo, EnumPaymentMode.BankTransfer);
}
return oEmployeeBankAccount.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)
{
TransactionContext tc = null;
try
{
EmployeeBankAccount oacc = EmployeeBankAccount.Get(id);
tc = TransactionContext.Begin(true);
EmployeeBankAccountDA.Delete(tc, id);
EmployeeService sv = new EmployeeService();
if (oacc.AccountType == EnumBankAccountType.SalaryAccount)
{
sv.UpdateBankAcc(tc, oacc.EmployeeID, null,
string.Empty, EnumPaymentMode.CashPayment);
}
else
{
sv.UpdateOPIBankAcc(tc, oacc.EmployeeID, null,
string.Empty, EnumPaymentMode.CashPayment);
}
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 DeleteAll()
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
EmployeeBankAccountDA.DeleteAll(tc);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public ObjectsTemplate<EmployeeBankAccount> GetByDate(DateTime startDate, DateTime endDate, int payrollTypeID, string sEmpIDs)
{
ObjectsTemplate<EmployeeBankAccount> oEmployees = new ObjectsTemplate<EmployeeBankAccount>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(EmployeeBankAccountDA.GetByDate(tc, startDate, endDate, payrollTypeID, sEmpIDs));
oEmployees = this.CreateObjects<EmployeeBankAccount>(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 oEmployees;
}
#endregion
}
#endregion
}