CEL_Payroll/Payroll.Service/OPI/Service/OPIProcessService.cs

1108 lines
37 KiB
C#
Raw 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 OPIProcess Service
[Serializable]
public class OPIProcessService : ServiceTemplate, IOPIProcessService
{
#region Private functions and declaration
Cache _cache = new Cache(typeof(OPIProcess));
public OPIProcessService() { }
#region OPIProcess
private void MapObject(OPIProcess oOPIProcess, DataReader oReader)
{
base.SetObjectID(oOPIProcess, oReader.GetID("OPIProcessID"));
oOPIProcess.OPIMonth = oReader.GetDateTime("OPIMonth").Value;
oOPIProcess.ProcessDate = oReader.GetDateTime("ProcessDate").Value;
oOPIProcess.CreatedBy = oReader.GetID("CreatedBy");
oOPIProcess.CreatedDate = oReader.GetDateTime("CreationDate").Value;
oOPIProcess.ModifiedBy = oReader.GetID("ModifiedBy");
oOPIProcess.ModifiedDate = oReader.GetDateTime("ModifiedDate");
oOPIProcess.IsApproved = oReader.GetBoolean("IsApproved").Value;
this.SetObjectState(oOPIProcess, Ease.CoreV35.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
OPIProcess oOPIProcess = new OPIProcess();
MapObject(oOPIProcess, oReader);
return oOPIProcess as T;
}
protected OPIProcess CreateObject(DataReader oReader)
{
OPIProcess oOPIProcess = new OPIProcess();
MapObject(oOPIProcess, oReader);
return oOPIProcess;
}
#endregion
#region OPIProcessDetail
private void MapProcessDetailObject(OPIProcessDetail oProcessDetail, DataReader oReader)
{
base.SetObjectID(oProcessDetail, oReader.GetID("OPIProcessDetailID"));
oProcessDetail.AccountNo = oReader.GetString("AccountNo");
oProcessDetail.BankID = oReader.GetID("BankID");
oProcessDetail.BranchID = oReader.GetID("BranchID");
oProcessDetail.CategoryID = oReader.GetID("CategoryID");
oProcessDetail.DepartmentID = oReader.GetID("DepartmentID");
oProcessDetail.DesignationID = oReader.GetID("DesignationID");
oProcessDetail.EmployeeID = oReader.GetID("EmployeeID");
oProcessDetail.Gender = (EnumGender)oReader.GetInt32("Gender");
oProcessDetail.GradeID = oReader.GetID("GradeID");
oProcessDetail.IsConfirmed = oReader.GetBoolean("IsConfirmed").Value;
oProcessDetail.IsFinalize = oReader.GetBoolean("IsFinalize").Value;
oProcessDetail.LocationID = oReader.GetID("LocationID");
oProcessDetail.OPIProcessID = oReader.GetID("OPIProcessID");
oProcessDetail.PayrollTypeID = oReader.GetID("PayrollTypeID");
oProcessDetail.PFMemberType = (EnumPFMembershipType)oReader.GetInt32("PFMemberType");
oProcessDetail.ReligionID = oReader.GetID("ReligionID");
oProcessDetail.Remarks = oReader.GetString("Remarks");
this.SetObjectState(oProcessDetail, Ease.CoreV35.ObjectState.Saved);
}
protected ObjectsTemplate<OPIProcessDetail> CreateProcessDetailObject(DataReader oReader)
{
ObjectsTemplate<OPIProcessDetail> oProcessDetails = new ObjectsTemplate<OPIProcessDetail>();
while (oReader.Read())
{
OPIProcessDetail oProcessDetail = new OPIProcessDetail();
MapProcessDetailObject(oProcessDetail, oReader);
oProcessDetails.Add(oProcessDetail);
}
return oProcessDetails;
}
#endregion
#region OPIProcessDetailItem
private void MapProcessDetailItemObject(OPIProcessDetailItem oOPIProcessDetailItem, DataReader oReader)
{
base.SetObjectID(oOPIProcessDetailItem, oReader.GetID("OPIProcessDetailItemID"));
oOPIProcessDetailItem.ChangeNetAmount = oReader.GetDouble("ChangeNetAmount").Value;
oOPIProcessDetailItem.Description = oReader.GetString("Description");
oOPIProcessDetailItem.NetAmount = oReader.GetDouble("NetAmount").Value;
oOPIProcessDetailItem.TaxAmount = oReader.GetDouble("TaxAmount").Value;
oOPIProcessDetailItem.OPIItemID = oReader.GetID("OPIItemID");
oOPIProcessDetailItem.OPIProcessDetailID = oReader.GetID("OPIProcessDetailID");
oOPIProcessDetailItem.OPIType = (EnumOpiType)oReader.GetInt32("OPIType").Value;
oOPIProcessDetailItem.CreatedBy = oReader.GetID("CreatedBy");
oOPIProcessDetailItem.CreatedDate = oReader.GetDateTime("CreationDate").Value;
oOPIProcessDetailItem.ModifiedBy = oReader.GetID("ModifiedBy");
oOPIProcessDetailItem.ModifiedDate = oReader.GetDateTime("ModifiedDate");
this.SetObjectState(oOPIProcessDetailItem, Ease.CoreV35.ObjectState.Saved);
}
protected ObjectsTemplate<OPIProcessDetailItem> CreateProcessDetailItemObject(DataReader oReader)
{
ObjectsTemplate<OPIProcessDetailItem> oProcessDetailItems = new ObjectsTemplate<OPIProcessDetailItem>();
while (oReader.Read())
{
OPIProcessDetailItem oProcessDetailItem = new OPIProcessDetailItem();
MapProcessDetailItemObject(oProcessDetailItem, oReader);
oProcessDetailItems.Add(oProcessDetailItem);
}
return oProcessDetailItems;
}
#endregion
#endregion
#region Service implementation
public OPIProcess Get2(ID id, ID payrollTypeID)
{
OPIProcess oOPIProcess = new OPIProcess();
#region Cache Header
oOPIProcess = (OPIProcess)_cache["Get", id] as OPIProcess;
if (oOPIProcess != null)
return oOPIProcess;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oReader = new DataReader(OPIProcessDA.Get2(tc, id, payrollTypeID));
if (oReader.Read())
{
oOPIProcess = 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
}
#region Cache Footer
_cache.Add(oOPIProcess, "Get", id);
#endregion
return oOPIProcess;
}
public OPIProcess Get(DateTime fromdate, ID empiD)
{
OPIProcess oOPIProcess = new OPIProcess();
#region Cache Header
oOPIProcess = (OPIProcess)_cache["Get", fromdate, empiD] as OPIProcess;
if (oOPIProcess != null)
return oOPIProcess;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oReader = new DataReader(OPIProcessDA.Get(tc, fromdate, empiD));
if (oReader.Read())
{
oOPIProcess = 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
}
#region Cache Footer
_cache.Add(oOPIProcess, "Get", fromdate, empiD);
#endregion
return oOPIProcess;
}
public ObjectsTemplate<OPIProcess> Get3(ID payrollTypeID)
{
#region Cache Header
ObjectsTemplate<OPIProcess> oOPIProcesss = _cache["Get"] as ObjectsTemplate<OPIProcess>;
if (oOPIProcesss != null)
return oOPIProcesss;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(OPIProcessDA.Get3(tc, payrollTypeID));
oOPIProcesss = this.CreateObjects<OPIProcess>(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(oOPIProcesss, "Get");
#endregion
return oOPIProcesss;
}
public ObjectsTemplate<OPIProcess> Get4(DateTime dOPIMonth, ID payrollTypeID)
{
#region Cache Header
ObjectsTemplate<OPIProcess> oProcesss = _cache["Get", dOPIMonth] as ObjectsTemplate<OPIProcess>;
if (oProcesss != null)
return oProcesss;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(OPIProcessDA.Get4(tc, dOPIMonth, payrollTypeID));
oProcesss = this.CreateObjects<OPIProcess>(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(oProcesss, "Get", dOPIMonth);
#endregion
return oProcesss;
}
public ObjectsTemplate<OPIProcessDetail> GetProcessDetails(ID opiProcessID, ID payrollTypeID)
{
#region Cache Header
ObjectsTemplate<OPIProcessDetail> oProcessDetails = _cache["GetProcessDetails", opiProcessID] as ObjectsTemplate<OPIProcessDetail>;
if (oProcessDetails != null)
return oProcessDetails;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(OPIProcessDA.GetProcessDetails(tc, opiProcessID, payrollTypeID));
oProcessDetails = this.CreateProcessDetailObject(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(oProcessDetails, "GetProcessDetails", opiProcessID);
#endregion
return oProcessDetails;
}
public ObjectsTemplate<OPIProcessDetail> GetDetail(DateTime processMonth)
{
#region Cache Header
ObjectsTemplate<OPIProcessDetail> oProcessDetails = _cache["GetDetail", processMonth] as ObjectsTemplate<OPIProcessDetail>;
if (oProcessDetails != null)
return oProcessDetails;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(OPIProcessDA.GetDetail(tc, processMonth));
oProcessDetails = this.CreateProcessDetailObject(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(oProcessDetails, "GetDetail", processMonth);
#endregion
return oProcessDetails;
}
public OPIProcessDetail GetDetail(ID employeeID, DateTime processMonth, ID payrollTypeID)
{
ObjectsTemplate<OPIProcessDetail> oDetails = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oReader = new DataReader(OPIProcessDA.GetDetails(tc, employeeID, processMonth, payrollTypeID));
oDetails = this.CreateProcessDetailObject(oReader);
oReader.Close();
tc.End();
foreach (OPIProcessDetail oDetail in oDetails)
{
ObjectsTemplate<OPIProcessDetailItem> oItems = new ObjectsTemplate<OPIProcessDetailItem>();
oItems = GetProcessDetailItems(oDetail.ID, payrollTypeID);
oDetail.OPIProcessDetailItems = oItems;
}
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
if (oDetails.Count > 0) return oDetails[0];
else return null;
}
public DataSet GetOPIRegister(string sOPIItemID, DateTime dOPIMonth, DateTime dOPIMonth2, string sEmpID)
{
DataSet oOPIRegisters = new DataSet();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
oOPIRegisters = OPIProcessDA.GetOPIRegister(tc, sOPIItemID, dOPIMonth, dOPIMonth2, 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 oOPIRegisters;
}
public ObjectsTemplate<OPIProcessDetail> GetProcessDetails(DateTime processMonth, ID payrollTypeID)
{
ObjectsTemplate<OPIProcessDetail> oProcessDetails;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(OPIProcessDA.GetProcessDetails(tc, processMonth, payrollTypeID));
oProcessDetails = this.CreateProcessDetailObject(dr);
dr.Close();
DataReader drItems = new DataReader(OPIProcessDA.GetProcessDetailsItems(tc, processMonth, payrollTypeID));
ObjectsTemplate<OPIProcessDetailItem> detialItems = this.CreateProcessDetailItemObject(drItems);
dr.Close();
int check = 0;
foreach (OPIProcessDetail pro in oProcessDetails)
{
check = 0;
foreach (OPIProcessDetailItem detail in detialItems)
{
if (pro.ID.Integer == detail.OPIProcessDetailID.Integer)
{
pro.OPIProcessDetailItems.Add(detail);
//check = 1;
}
// else
// {
// if (check == 1) break;
// }
}
}
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return oProcessDetails;
}
public ObjectsTemplate<OPIProcessDetail> GetProcessDetailWithItems(ID opiProcessID, ID payrollTypeID)
{
#region Cache Header
ObjectsTemplate<OPIProcessDetail> oProcessDetails = _cache["GetProcessDetails", opiProcessID] as ObjectsTemplate<OPIProcessDetail>;
if (oProcessDetails != null)
return oProcessDetails;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(OPIProcessDA.GetProcessDetails(tc, opiProcessID, payrollTypeID));
oProcessDetails = this.CreateProcessDetailObject(dr);
dr.Close();
tc.End();
foreach (OPIProcessDetail oDetail in oProcessDetails)
{
ObjectsTemplate<OPIProcessDetailItem> oItems = new ObjectsTemplate<OPIProcessDetailItem>();
oItems = GetProcessDetailItems(oDetail.ID, payrollTypeID);
oDetail.OPIProcessDetailItems = oItems;
}
}
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(oProcessDetails, "GetProcessDetails", opiProcessID);
#endregion
return oProcessDetails;
}
public ObjectsTemplate<OPIProcessDetailItem> GetProcessDetailItems(ID nProcessDetailID, ID payrollTypeID)
{
#region Cache Header
ObjectsTemplate<OPIProcessDetailItem> oProcessDetailItems = _cache["GetProcessDetailItems", nProcessDetailID] as ObjectsTemplate<OPIProcessDetailItem>;
if (oProcessDetailItems != null)
return oProcessDetailItems;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(OPIProcessDA.GetProcessDetailItems(tc, nProcessDetailID, payrollTypeID));
oProcessDetailItems = this.CreateProcessDetailItemObject(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(oProcessDetailItems, "GetProcessDetailItems", nProcessDetailID);
#endregion
return oProcessDetailItems;
}
public ObjectsTemplate<OPIProcessDetailItem> GetOPiProcessItems(DateTime dateTime, ID payrollTypeID)
{
#region Cache Header
ObjectsTemplate<OPIProcessDetailItem> oProcessDetailItems = _cache["GetOPiProcessItems", dateTime] as ObjectsTemplate<OPIProcessDetailItem>;
if (oProcessDetailItems != null)
return oProcessDetailItems;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(OPIProcessDA.GetProcessDetailsItems(tc, dateTime, payrollTypeID));
oProcessDetailItems = this.CreateProcessDetailItemObject(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(oProcessDetailItems, "GetOPiProcessItems", dateTime);
#endregion
return oProcessDetailItems;
}
public double GetProvisionAmountByEmpID(ID nEmpID)
{
double nAmount = 0;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
nAmount = OPIProcessDA.GetProvisionAmountByEmpID(tc, nEmpID);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return nAmount;
}
public double GetPrevMonthAmount(ID nEmpID, ID nOPIItemID, DateTime dFromOpiMonth, DateTime dToOpiMonth)
{
double nAmount = 0;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
nAmount = OPIProcessDA.GetPrevMonthAmount(tc, nEmpID, nOPIItemID, dFromOpiMonth, dToOpiMonth);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return nAmount;
}
public DataSet GetDataSetOfOPIRegister(string sSearch)
{
DataSet dsOPIRegister = new DataSet();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
dsOPIRegister = OPIProcessDA.GetDataSetOfOPIRegister(tc, sSearch);
tc.End();
}
catch (Exception e)
{
throw new ServiceException("Failed to get OPI Register data due to " + e.Message);
}
return dsOPIRegister;
}
public DataSet GetOPIRegister(string sOPIItemID, DateTime dOPIMonth, string sEmpID)
{
DataSet oOPIRegisters = new DataSet();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
oOPIRegisters = OPIProcessDA.GetOPIRegister(tc, sOPIItemID, dOPIMonth, 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 oOPIRegisters;
}
public DataSet GetIDLCOPIRegister(DateTime dOPIMonth, string sEmpID)
{
DataSet oOPIRegisters = new DataSet();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
oOPIRegisters = OPIProcessDA.GetIDLCOPIRegister(tc, dOPIMonth, 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 oOPIRegisters;
}
public DataSet GetDetailOtherPayrollItems(string sOPIItemID, DateTime dOPIMonth, string sEmpID)
{
DataSet oOPIRegisters = new DataSet();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
oOPIRegisters = OPIProcessDA.GetDetailOtherPayrollItems(tc, sOPIItemID, dOPIMonth, 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 oOPIRegisters;
}
public DataSet GetOPITotalValueRegister(DateTime dFromOpiMonth, DateTime dToOpiMonth, int nOPIItemID, string sEmpID)
{
DataSet oOPIRegisters = new DataSet();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
oOPIRegisters = OPIProcessDA.GetOPITotalValueRegister(tc, dFromOpiMonth, dToOpiMonth, nOPIItemID, 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 oOPIRegisters;
}
private void SaveProcessDetail(TransactionContext tc, OPIProcessDetail oPDetail, ID payrollTypeID)
{
string tableName = "OPIProcessDetail";
try
{
//inserting OPIProcessDetail
int id = tc.GenerateID("OPIProcessDetail", "OPIProcessDetailID");
int itemID = tc.GenerateID("OPIProcessDetailItem", "OPIProcessDetailItemID");
if (oPDetail.IsNew)
{
base.SetObjectID(oPDetail, ID.FromInteger(id));
oPDetail.CreatedBy = User.CurrentUser.ID;
oPDetail.CreatedDate = DateTime.Now;
OPIProcessDA.InsertProcessDetail(tc, oPDetail);
}
else
{
OPIProcessDA.UpdateProcessDetail(tc, oPDetail, payrollTypeID);
OPIProcessDA.DeleteProcessDetailItem(tc, oPDetail.ID, payrollTypeID);
}
//inserting OPIProcessDetailItem
tableName = "OPIProcessDetailItem";
foreach (OPIProcessDetailItem oPDItem in oPDetail.OPIProcessDetailItems)
{
oPDItem.OPIProcessDetailID = oPDetail.ID;
base.SetObjectID(oPDItem, ID.FromInteger(itemID));
oPDItem.CreatedBy = User.CurrentUser.ID;
oPDItem.CreatedDate = DateTime.Now;
OPIProcessDA.InsertProcessDetailItem(tc, oPDItem, payrollTypeID);
itemID++;
}
}
catch (Exception e)
{
#region Handle Exception
ExceptionLog.Write(e);
string smessage = "Faliled to save opi process (table:" + tableName
+ " for employee (" + oPDetail.Employee.EmployeeNo + " - " + oPDetail.Employee.Name + " ) due to :";
throw new ServiceException(smessage + e.Message, e);
#endregion
}
}
public ID Save(OPIProcess oProcess, ID payrollTypeID)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oProcess.IsNew)
{
int id = tc.GenerateID("OPIProcess", "OPIProcessID");
base.SetObjectID(oProcess, ID.FromInteger(id));
OPIProcessDA.InsertProcess(tc, oProcess, payrollTypeID);
}
else
{
OPIProcessDA.UpdateProcess(tc, oProcess, payrollTypeID);
}
tc.End();
return oProcess.ID;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public ID SaveProcess(TransactionContext tc, OPIProcess oOPIProcess, ID payrollTypeID)
{
string tableName = "OPIProcess";
try
{
if (oOPIProcess.IsNew)
{
int id = tc.GenerateID("OPIProcess", "OPIProcessID");
base.SetObjectID(oOPIProcess, ID.FromInteger(id));
OPIProcessDA.InsertProcess(tc, oOPIProcess, payrollTypeID);
}
else
{
OPIProcessDA.UpdateProcess(tc, oOPIProcess, payrollTypeID);
}
return oOPIProcess.ID;
}
catch (Exception e)
{
#region Handle Exception
ExceptionLog.Write(e);
string smessage = "Faliled to save opi process (table:" + tableName + ") due to : ";
throw new ServiceException(smessage + e.Message, e);
#endregion
}
}
public void Save(OPIProcess oProcess, ObjectsTemplate<OPIProcessDetail> oPDetails, ID payrollTypeID)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
ID processId = this.SaveProcess(tc, oProcess, payrollTypeID);
foreach (OPIProcessDetail oPDetail in oPDetails)
{
oPDetail.OPIProcessID = processId;
this.SaveProcessDetail(tc, oPDetail, payrollTypeID);
}
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 Delete(ID id, ID payrollTypeID)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
OPIProcessDA.DeleteProcess(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
}
}
public void Undo(DateTime OpiMonth, ID payrollTypeID)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
OPIProcessDA.Undo(tc, OpiMonth, payrollTypeID);
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 UpdateDetail(ObjectsTemplate<OPIProcessDetailItem> oOPIDetails, ID payrollTypeID)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
foreach (OPIProcessDetailItem odetail in oOPIDetails)
{
OPIProcessDA.UpdateSalaryDetail(tc, odetail, payrollTypeID);
}
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<OPIProcessDetailItem> GetLastMonthItems(int nID, ID payrollTypeID)
{
#region Cache Header
ObjectsTemplate<OPIProcessDetailItem> oProcessDetailItems = _cache["GetLastMonthItems", nID] as ObjectsTemplate<OPIProcessDetailItem>;
if (oProcessDetailItems != null)
return oProcessDetailItems;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(OPIProcessDA.GetLastMonthItems(tc, nID, payrollTypeID));
oProcessDetailItems = this.CreateProcessDetailItemObject(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(oProcessDetailItems, "GetLastMonthItems", nID);
#endregion
return oProcessDetailItems;
}
public DataSet GetEmpOPIPaySlip(DateTime dateTime, string sEmpID)
{
DataSet oOPIProcesses = new DataSet();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
oOPIProcesses = OPIProcessDA.GetEmpOPIPaySlip(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 oOPIProcesses;
}
public DataSet GetItemWiseOPI(DateTime dFromOPIMonth, int opiItemID, string sEmpID)
{
DataSet oOPIRegisters = new DataSet();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
oOPIRegisters = OPIProcessDA.GetItemWiseOPI(tc, dFromOPIMonth, opiItemID, 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 oOPIRegisters;
}
public DataSet GetManagersOPI(DateTime dtFromOPI, DateTime dtToOPI, int opiItemID, string sEmpID)
{
DataSet oOPIRegisters = new DataSet();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
oOPIRegisters = OPIProcessDA.GetManagersOPI(tc, dtFromOPI, dtToOPI, opiItemID, 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 oOPIRegisters;
}
public DateTime? GetLastPaidOPIMonth(int nEmpID)
{
DateTime? dt;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
dt = OPIProcessDA.GetLastPaidOPIMonth(tc, nEmpID);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return dt;
}
#endregion
#region IOPIProcessService Members
public ID UpdateOnlyProcess(OPIProcess oProcess, ID payrollTypeID)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (!oProcess.IsNew)
{
OPIProcessDA.UpdateProcess(tc, oProcess, payrollTypeID);
}
tc.End();
return oProcess.ID;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
#endregion
}
#endregion
}