531 lines
16 KiB
C#
531 lines
16 KiB
C#
|
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 SalaryProcess Service
|
|||
|
[Serializable]
|
|||
|
public class SalaryProcessService : ServiceTemplate, ISalaryProcessService
|
|||
|
{
|
|||
|
#region Private functions and declaration
|
|||
|
Cache _cache = new Cache(typeof(SalaryProcess));
|
|||
|
|
|||
|
#endregion
|
|||
|
public SalaryProcessService() { }
|
|||
|
|
|||
|
private void MapObject(SalaryProcess oSalaryProcess, DataReader oReader)
|
|||
|
{
|
|||
|
base.SetObjectID(oSalaryProcess, oReader.GetID("SalaryProcessID"));
|
|||
|
oSalaryProcess.SalaryMonth = oReader.GetDateTime("SalaryMonth").Value;
|
|||
|
oSalaryProcess.ProcessDate = oReader.GetDateTime("ProcessDate").Value;
|
|||
|
oSalaryProcess.ProcessCode = oReader.GetString("ProcessCode");
|
|||
|
oSalaryProcess.Remarks = oReader.GetString("Remarks");
|
|||
|
oSalaryProcess.PaymentDate = oReader.GetDateTime("PaymentDate");
|
|||
|
|
|||
|
oSalaryProcess.WorkDays = oReader.GetInt32("WorkDays").Value;
|
|||
|
oSalaryProcess.IsFinalized = oReader.GetBoolean("IsFinalized").Value;
|
|||
|
oSalaryProcess.PayrollTypeID = oReader.GetID("PayrollTypeID");
|
|||
|
oSalaryProcess.ShowInDesktops = oReader.GetBoolean("SHOWINDESKTOP") != null ? oReader.GetBoolean("SHOWINDESKTOP").Value : false;
|
|||
|
oSalaryProcess.CreatedBy = oReader.GetID("CreatedBy");
|
|||
|
oSalaryProcess.CreatedDate = oReader.GetDateTime("CreationDate").Value;
|
|||
|
oSalaryProcess.ModifiedBy = oReader.GetID("ModifiedBy");
|
|||
|
oSalaryProcess.ModifiedDate = oReader.GetDateTime("ModifiedDate");
|
|||
|
oSalaryProcess.ShowInDesktopDate = oReader.GetDateTime("ShowInDesktopDate").HasValue?oReader.GetDateTime("ShowInDesktopDate").Value:DateTime.MinValue;
|
|||
|
oSalaryProcess.MonthEndDate = oReader.GetDateTime("MonthEndDate").HasValue ? oReader.GetDateTime("MonthEndDate").Value : DateTime.MinValue;
|
|||
|
|
|||
|
this.SetObjectState(oSalaryProcess, Ease.CoreV35.ObjectState.Saved);
|
|||
|
}
|
|||
|
protected override T CreateObject<T>(DataReader oReader)
|
|||
|
{
|
|||
|
SalaryProcess oSalaryProcess = new SalaryProcess();
|
|||
|
MapObject(oSalaryProcess, oReader);
|
|||
|
return oSalaryProcess as T;
|
|||
|
}
|
|||
|
protected SalaryProcess CreateObject(DataReader oReader)
|
|||
|
{
|
|||
|
SalaryProcess oSalaryProcess = new SalaryProcess();
|
|||
|
MapObject(oSalaryProcess, oReader);
|
|||
|
return oSalaryProcess;
|
|||
|
}
|
|||
|
|
|||
|
#region Service implementation
|
|||
|
|
|||
|
public SalaryProcess Get(ID id)
|
|||
|
{
|
|||
|
SalaryProcess oSalaryProcess = new SalaryProcess();
|
|||
|
#region Cache Header
|
|||
|
oSalaryProcess = _cache["Get", id] as SalaryProcess;
|
|||
|
if (oSalaryProcess != null)
|
|||
|
return oSalaryProcess;
|
|||
|
#endregion
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
DataReader oreader = new DataReader(SalaryProcessDA.Get(tc, id));
|
|||
|
if (oreader.Read())
|
|||
|
{
|
|||
|
oSalaryProcess = this.CreateObject<SalaryProcess>(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(oSalaryProcess, "Get", id);
|
|||
|
#endregion
|
|||
|
return oSalaryProcess;
|
|||
|
}
|
|||
|
|
|||
|
public ObjectsTemplate<SalaryProcess> Get(DateTime dMonthDate, int payrollTypeID)
|
|||
|
{
|
|||
|
#region Cache Header
|
|||
|
|
|||
|
ObjectsTemplate<SalaryProcess> salaryProcesss = _cache["Get", dMonthDate] as ObjectsTemplate<SalaryProcess>;
|
|||
|
if (salaryProcesss != null)
|
|||
|
return salaryProcesss;
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
|
|||
|
DataReader dr = new DataReader(SalaryProcessDA.Get(tc, dMonthDate, payrollTypeID));
|
|||
|
salaryProcesss = this.CreateObjects<SalaryProcess>(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(salaryProcesss, "Get", dMonthDate);
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
return salaryProcesss;
|
|||
|
}
|
|||
|
|
|||
|
public ObjectsTemplate<SalaryProcess> Get(int payrollTypeID)
|
|||
|
{
|
|||
|
#region Cache Header
|
|||
|
|
|||
|
ObjectsTemplate<SalaryProcess> salaryProcesss = _cache["Get"] as ObjectsTemplate<SalaryProcess>;
|
|||
|
if (salaryProcesss != null)
|
|||
|
return salaryProcesss;
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
|
|||
|
DataReader dr = new DataReader(SalaryMonthlyDA.Get(tc, payrollTypeID));
|
|||
|
salaryProcesss = this.CreateObjects<SalaryProcess>(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(salaryProcesss, "Get");
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
return salaryProcesss;
|
|||
|
}
|
|||
|
|
|||
|
public ObjectsTemplate<SalaryProcess> GetSP()
|
|||
|
{
|
|||
|
#region Cache Header
|
|||
|
|
|||
|
ObjectsTemplate<SalaryProcess> salaryProcesss = _cache["GetSP"] as ObjectsTemplate<SalaryProcess>;
|
|||
|
if (salaryProcesss != null)
|
|||
|
return salaryProcesss;
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
|
|||
|
DataReader dr = new DataReader(SalaryProcessDA.Get(tc));
|
|||
|
salaryProcesss = this.CreateObjects<SalaryProcess>(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(salaryProcesss, "Get");
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
return salaryProcesss;
|
|||
|
}
|
|||
|
|
|||
|
public ID Save(TransactionContext tc, SalaryProcess oSalaryProcess)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
if (oSalaryProcess.IsNew)
|
|||
|
{
|
|||
|
int id = tc.GenerateID("SalaryProcess", "SalaryProcessID");
|
|||
|
base.SetObjectID(oSalaryProcess, ID.FromInteger(id));
|
|||
|
SalaryProcessDA.Insert(tc, oSalaryProcess);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
SalaryProcessDA.Update(tc, oSalaryProcess);
|
|||
|
}
|
|||
|
return oSalaryProcess.ID;
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
#region Handle Exception
|
|||
|
if (tc != null)
|
|||
|
tc.HandleError();
|
|||
|
ExceptionLog.Write(e);
|
|||
|
throw new ServiceException(e.Message, e);
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public ID Save( SalaryProcess oSalaryProcess)
|
|||
|
{
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
if (oSalaryProcess.IsNew)
|
|||
|
{
|
|||
|
int id = tc.GenerateID("SalaryMonthly", "SalaryMonthlyID");
|
|||
|
base.SetObjectID(oSalaryProcess, ID.FromInteger(id));
|
|||
|
SalaryProcessDA.Insert(tc, oSalaryProcess);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
SalaryProcessDA.Update(tc, oSalaryProcess);
|
|||
|
}
|
|||
|
tc.End();
|
|||
|
return oSalaryProcess.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
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin(true);
|
|||
|
SalaryProcessDA.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 UndoSalary(ID id)
|
|||
|
{
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin(true);
|
|||
|
SalaryProcessDA.UndoSalary(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 UndoMonthlySalaryByEmpIDs(string ids, DateTime salaryMonth)
|
|||
|
{
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin(true);
|
|||
|
SalaryProcessDA.UndoMonthlySalaryByEmpIDs(tc, ids, salaryMonth);
|
|||
|
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 Update(SalaryProcess oSProcess)
|
|||
|
{
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin(true);
|
|||
|
SalaryProcessDA.Update(tc, oSProcess);
|
|||
|
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 SPApprove(SalaryProcess oSProcess)
|
|||
|
{
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin(true);
|
|||
|
SalaryProcessDA.SPApprove(tc, oSProcess);
|
|||
|
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 MonthEnd(DateTime month, ObjectsTemplate<PFTransaction> pftransactions,
|
|||
|
ObjectsTemplate<LoanSchedule> loanshedules, ObjectsTemplate<ESBProvision> oESBProvisions, int payrollTypeID)
|
|||
|
{
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin(true);
|
|||
|
PFTransactionService pfservice = new PFTransactionService();
|
|||
|
int id = tc.GenerateID("PFTransaction", "PfTranID");
|
|||
|
//int id = tc.GenerateID("PFTransaction", "PfTranID");
|
|||
|
foreach (PFTransaction pftran in pftransactions)
|
|||
|
{
|
|||
|
//int id = tc.GenerateID("PFTransaction", "PfTranID");
|
|||
|
base.SetObjectID(pftran, ID.FromInteger(id));
|
|||
|
pfservice.Save(tc, pftran);
|
|||
|
id = id + 1;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
if (loanshedules.Count > 0)
|
|||
|
{
|
|||
|
LoanScheduleService ls = new LoanScheduleService();
|
|||
|
foreach (LoanSchedule shedule in loanshedules)
|
|||
|
{
|
|||
|
ls.UpdatePaymentDate(tc, shedule.ID, (DateTime)shedule.PaymentDate, EnumLoanPaymentMode.Salary);
|
|||
|
}
|
|||
|
}
|
|||
|
//if (oESBProvisions.Count > 0)
|
|||
|
//{
|
|||
|
// foreach (ESBProvision oItem in oESBProvisions)
|
|||
|
// {
|
|||
|
|
|||
|
// oItem.Save();
|
|||
|
// }
|
|||
|
//}
|
|||
|
|
|||
|
SalaryProcessDA.MonthEnd(tc, month, 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 bool GetBySMonth(DateTime dSalaryMonth, int payrollTypeID)
|
|||
|
{
|
|||
|
TransactionContext tc = null;
|
|||
|
bool bShowInDesktop;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
bShowInDesktop = SalaryProcessDA.GetBySMonth(tc, dSalaryMonth, 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 bShowInDesktop;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
public int GetProcessID(DateTime nextPayProcessDate, int payrollTypeID)
|
|||
|
{
|
|||
|
int processId = 0;
|
|||
|
TransactionContext tc = null;
|
|||
|
SalaryProcess salaryProcesss = new SalaryProcess();
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
processId = SalaryProcessDA.GetProcessID(tc, nextPayProcessDate, payrollTypeID);
|
|||
|
|
|||
|
tc.End();
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
|
|||
|
|
|||
|
throw new ServiceException(e.Message, e);
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
return processId;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
public ObjectsTemplate<SalaryProcess> GetAllProcess(DateTime nextPayProcessDate, int payrollTypeID)
|
|||
|
{
|
|||
|
|
|||
|
|
|||
|
ObjectsTemplate< SalaryProcess > salaryProcesss = new ObjectsTemplate< SalaryProcess >();
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
DataReader dr = new DataReader(SalaryProcessDA.GetAllProcess(tc, nextPayProcessDate, payrollTypeID));
|
|||
|
salaryProcesss = this.CreateObjects<SalaryProcess>(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 salaryProcesss;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
#endregion
|
|||
|
}
|