EchoTex_Payroll/HRM.DA/Service/OPI/OPIProcessService.cs

1125 lines
36 KiB
C#
Raw Normal View History

2024-10-14 10:01:49 +06:00
using Ease.Core.DataAccess;
using Ease.Core.Model;
using Ease.Core.Utility;
using System;
using System.Collections.Generic;
using System.Data;
using HRM.BO;
namespace HRM.DA
{
#region OPIProcess Service
public class OPIProcessService : ServiceTemplate, IOPIProcessService
{
#region Private functions and declaration
public OPIProcessService()
{
}
#region OPIProcess
private void MapObject(OPIProcess oOPIProcess, DataReader oReader)
{
base.SetObjectID(oOPIProcess, oReader.GetInt32("OPIProcessID").Value);
oOPIProcess.OPIMonth = oReader.GetDateTime("OPIMonth").Value;
oOPIProcess.ProcessDate = oReader.GetDateTime("ProcessDate").Value;
oOPIProcess.ItemCount = oReader.GetInt32("Count", true, 0);
oOPIProcess.CreatedBy = oReader.GetString("CreatedBy") == null ? 0 : oReader.GetInt32("CreatedBy").Value;
oOPIProcess.CreatedDate = oReader.GetDateTime("CreationDate").Value;
oOPIProcess.ModifiedBy = oReader.GetString("ModifiedBy") == null ? 0 : oReader.GetInt32("ModifiedBy").Value;
oOPIProcess.ModifiedDate = oReader.GetDateTime("ModifiedDate");
oOPIProcess.IsApproved = oReader.GetBoolean("IsApproved").Value;
oOPIProcess.PayrollTypeID =
oReader.GetString("PayrollTypeID") == null ? 0 : oReader.GetInt32("PayrollTypeID").Value;
this.SetObjectState(oOPIProcess, Ease.Core.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.GetInt32("OPIProcessDetailID").Value);
oProcessDetail.AccountNo = oReader.GetString("AccountNo");
oProcessDetail.BankID = oReader.GetInt32("BankID").GetValueOrDefault();
oProcessDetail.BranchID = oReader.GetInt32("BranchID").GetValueOrDefault();
oProcessDetail.CategoryID = oReader.GetInt32("CategoryID").Value;
oProcessDetail.DepartmentID = oReader.GetInt32("DepartmentID").Value;
oProcessDetail.DesignationID = oReader.GetInt32("DesignationID").Value;
oProcessDetail.EmployeeID = oReader.GetInt32("EmployeeID").Value;
oProcessDetail.Gender = (EnumGender)oReader.GetInt32("Gender");
oProcessDetail.GradeID = oReader.GetInt32("GradeID").Value;
oProcessDetail.IsConfirmed = oReader.GetBoolean("IsConfirmed").Value;
oProcessDetail.IsFinalize = oReader.GetBoolean("IsFinalize").Value;
oProcessDetail.LocationID = oReader.GetInt32("LocationID").Value;
oProcessDetail.OPIProcessID = oReader.GetInt32("OPIProcessID").Value;
oProcessDetail.PayrollTypeID = oReader.GetInt32("PayrollTypeID").Value;
oProcessDetail.PFMemberType = (EnumPFMembershipType)oReader.GetInt32("PFMemberType");
oProcessDetail.ReligionID = oReader.GetInt32("ReligionID").Value;
oProcessDetail.Remarks = oReader.GetString("Remarks");
this.SetObjectState(oProcessDetail, Ease.Core.ObjectState.Saved);
}
protected List<OPIProcessDetail> CreateProcessDetailObject(DataReader oReader)
{
List<OPIProcessDetail> oProcessDetails = new List<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.GetInt32("OPIProcessDetailItemID").Value);
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.GetString("OPIItemID") == null
? 0
: oReader.GetInt32("OPIItemID").Value; //; oReader.GetInt32("OPIItemID").Value);
oOPIProcessDetailItem.OPIProcessDetailID = oReader.GetString("OPIProcessDetailID") == null
? 0
: oReader.GetInt32("OPIProcessDetailID").Value; // oReader.GetID("OPIProcessDetailID");
oOPIProcessDetailItem.OPIType = (EnumOpiType)oReader.GetInt32("OPIType").Value;
oOPIProcessDetailItem.CreatedBy =
oReader.GetString("CreatedBy") == null
? 0
: oReader.GetInt32("CreatedBy").Value; //; oReader.GetInt32("CreatedBy").Value);
oOPIProcessDetailItem.CreatedDate = oReader.GetDateTime("CreationDate").Value;
oOPIProcessDetailItem.ModifiedBy =
oReader.GetString("ModifiedBy") == null ? 0 : oReader.GetInt32("ModifiedBy").Value;
oOPIProcessDetailItem.ModifiedDate = oReader.GetDateTime("ModifiedDate");
oOPIProcessDetailItem.PayrollTypeID = oReader.GetString("PayrollTypeID") == null
? 0
: oReader.GetInt32("PayrollTypeID").Value;
this.SetObjectState(oOPIProcessDetailItem, Ease.Core.ObjectState.Saved);
}
protected List<OPIProcessDetailItem> CreateProcessDetailItemObject(DataReader oReader)
{
List<OPIProcessDetailItem> oProcessDetailItems = new List<OPIProcessDetailItem>();
while (oReader.Read())
{
OPIProcessDetailItem oProcessDetailItem = new OPIProcessDetailItem();
MapProcessDetailItemObject(oProcessDetailItem, oReader);
oProcessDetailItems.Add(oProcessDetailItem);
}
return oProcessDetailItems;
}
#endregion
#endregion
#region Service implementation
public OPIProcess Get(int id, int payrollTypeID)
{
OPIProcess oOPIProcess = new OPIProcess();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oReader = new DataReader(OPIProcessDA.Get(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
}
return oOPIProcess;
}
public OPIProcess Get(DateTime fromdate, int empiD)
{
OPIProcess oOPIProcess = new OPIProcess();
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
}
return oOPIProcess;
}
public List<OPIProcess> Get(int payrollTypeID)
{
List<OPIProcess> oOPIProcesss = new List<OPIProcess>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(OPIProcessDA.Get(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
}
return oOPIProcesss;
}
public List<OPIProcess> GetbyMonthAndPayrollTypeId(DateTime dOPIMonth, int payrollTypeID)
{
List<OPIProcess> oProcesss = new List<OPIProcess>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(OPIProcessDA.Get(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
}
return oProcesss;
}
public List<OPIProcessDetail> GetProcessDetails(int opiProcessID, int payrollTypeID)
{
List<OPIProcessDetail> oProcessDetails = new List<OPIProcessDetail>();
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
}
return oProcessDetails;
}
public OPIProcessDetail GetDetail(int employeeID, DateTime processMonth, int payrollTypeID)
{
List<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)
{
List<OPIProcessDetailItem> oItems = new List<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 List<OPIProcessDetail> GetProcessDetails(DateTime processMonth, int payrollTypeID)
{
List<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));
List<OPIProcessDetailItem> detialItems = this.CreateProcessDetailItemObject(drItems);
foreach (OPIProcessDetail pro in oProcessDetails)
{
foreach (OPIProcessDetailItem detail in detialItems)
{
if (pro.ID == detail.OPIProcessDetailID)
{
pro.opiProcessDetailItems.Add(detail);
}
}
}
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 List<OPIProcessDetail> GetProcessDetailWithItems(int opiProcessID, int payrollTypeID)
{
List<OPIProcessDetail> oProcessDetails = new List<OPIProcessDetail>();
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)
{
List<OPIProcessDetailItem> oItems = new List<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
}
return oProcessDetails;
}
public List<OPIProcessDetailItem> GetProcessDetailItems(int nProcessDetailID, int payrollTypeID)
{
List<OPIProcessDetailItem> oProcessDetailItems = new List<OPIProcessDetailItem>();
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
}
return oProcessDetailItems;
}
public List<OPIProcessDetailItem> GetOPiProcessItems(DateTime dateTime, int payrollTypeID)
{
List<OPIProcessDetailItem> oProcessDetailItems = new List<OPIProcessDetailItem>();
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
}
return oProcessDetailItems;
}
public double GetProvisionAmountByEmpID(int 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(int nEmpID, int 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;
}
//public int Save(OPIProcess oProcess)
//{
// TransactionContext tc = null;
// try
// {
// tc = TransactionContext.Begin(true);
// if (oProcess.IsNew)
// {
// int id = tc.GenerateID("OPIProcess", "OPIProcessID");
// base.SetObjectID(oProcess, id);
// OPIProcessDA.InsertProcess(tc, oProcess);
// }
// else
// {
// OPIProcessDA.UpdateProcess(tc, oProcess);
// }
// 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 int SaveProcess(TransactionContext tc, OPIProcess oOPIProcess)
{
string tableName = "OPIProcess";
try
{
if (oOPIProcess.IsNew)
{
int id = tc.GenerateID("OPIProcess", "OPIProcessID");
base.SetObjectID(oOPIProcess, id);
OPIProcessDA.InsertProcess(tc, oOPIProcess);
}
else
{
OPIProcessDA.UpdateProcess(tc, oOPIProcess);
}
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, List<OPIProcessDetail> oPDetails)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
int processId = this.SaveProcess(tc, oProcess);
int id = tc.GenerateID("OPIProcessDetail", "OPIProcessDetailID");
int opiProcessDetailItemid = tc.GenerateID("OPIProcessDetailItem", "OPIProcessDetailItemID");
foreach (OPIProcessDetail oPDetail in oPDetails)
{
id = id + 1;
base.SetObjectID(oPDetail, id);
oPDetail.OPIProcessID = processId;
OPIProcessDA.InsertProcessDetail(tc, oPDetail);
foreach (OPIProcessDetailItem oPDItem in oPDetail.opiProcessDetailItems)
{
opiProcessDetailItemid = opiProcessDetailItemid + 1;
oPDItem.OPIProcessDetailID = oPDetail.ID;
base.SetObjectID(oPDItem, opiProcessDetailItemid);
OPIProcessDA.InsertProcessDetailItem(tc, oPDItem);
}
}
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(int id, int 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, int 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(List<OPIProcessDetailItem> oOPIDetails)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
foreach (OPIProcessDetailItem odetail in oOPIDetails)
{
OPIProcessDA.UpdateSalaryDetail(tc, odetail);
}
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public double GetAmountOnRange(Employee employee, DateTime fromDate, DateTime toDate,
int opiID, OpiParameter op)
{
double fractionMonthAmount = 0;
double amount = 0;
if (Ease.Core.Utility.Global.DateFunctions.DateDiff("m", GlobalFunctions.FirstDateOfMonth(fromDate),
GlobalFunctions.LastDateOfMonth(toDate)) > 2)
{
amount = new OPIProcessService().GetPrevMonthAmount(employee.ID, opiID,
GlobalFunctions.FirstDateOfMonth(fromDate.AddMonths(1)),
GlobalFunctions.LastDateOfMonth(toDate.AddMonths(-1)));
}
bool dataNotFound = false;
if (fromDate != Global.DateFunctions.FirstDateOfMonth(fromDate))
{
EmployeeGradeSalary oge = new EmployeeGradeSalaryService().Get(employee.ID, fromDate, EnumArrearType.NotPresent);
if (oge != null)
{
if (op != null)
{
oge.FractionofFromTo = GlobalFunctions.GetFractinalOfMonth(fromDate); //PayrollPayrollGlobalFunctions.GetFraction(oge.EffectDate, (DateTime)oge.TillDate);
fractionMonthAmount = new OpiParameterService().GetGradeDefinedAmount(employee, oge.BasicSalary,
oge.GrossSalary, oge.FractionofFromTo, op);
fractionMonthAmount = fractionMonthAmount * GlobalFunctions.GetFractinalOfMonth(fromDate);
dataNotFound = true;
}
}
}
if (dataNotFound == false)
{
fractionMonthAmount = new OPIProcessService().GetPrevMonthAmount(employee.ID, opiID,
GlobalFunctions.FirstDateOfMonth(fromDate), GlobalFunctions.LastDateOfMonth(fromDate));
}
if (Global.DateFunctions.FirstDateOfMonth(fromDate) != GlobalFunctions.FirstDateOfMonth(toDate)) // if cross two month
{
fractionMonthAmount = fractionMonthAmount + new OPIProcessService().GetPrevMonthAmount(employee.ID, opiID,
GlobalFunctions.FirstDateOfMonth(toDate), GlobalFunctions.LastDateOfMonth(toDate)) * GlobalFunctions.GetFractinalOfTillDate(toDate);
}
return amount = amount + fractionMonthAmount;
}
public List<OPIProcessDetailItem> GetLastMonthItems(int nID, int payrollTypeID)
{
List<OPIProcessDetailItem> oProcessDetailItems = new List<OPIProcessDetailItem>();
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
}
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 int UpdateOnlyProcess(OPIProcess oProcess)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (!oProcess.IsNew)
{
OPIProcessDA.UpdateProcess(tc, oProcess);
}
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
}
}
List<OPIProcess> IOPIProcessService.GetUnApprovedProcess(DateTime dOPIMonth, int payrollTypeID)
{
List<OPIProcess> oOPIProcesss = new List<OPIProcess>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(OPIProcessDA.GetUnApprovedProcess(tc, dOPIMonth, 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
}
return oOPIProcesss;
}
List<OPIProcess> IOPIProcessService.Get(DateTime dOPIMonth, int payrollTypeID)
{
throw new NotImplementedException();
}
#endregion
}
#endregion
}