2077 lines
78 KiB
C#
2077 lines
78 KiB
C#
using System;
|
|
using System.Data;
|
|
using Ease.Core.Model;
|
|
using Ease.Core.DataAccess;
|
|
using Ease.Core;
|
|
using System.Collections.Generic;
|
|
using Ease.Core.Utility;
|
|
using HRM.BO;
|
|
using System.Linq;
|
|
using Microsoft.Data.SqlClient;
|
|
|
|
namespace HRM.DA
|
|
{
|
|
#region BonusProcess Service
|
|
|
|
public class BonusProcessService : ServiceTemplate, IBonusProcessService
|
|
{
|
|
#region Private functions and declaration
|
|
|
|
private int _crgSerialId;
|
|
|
|
#endregion
|
|
|
|
public BonusProcessService()
|
|
{
|
|
_crgSerialId = 0;
|
|
}
|
|
|
|
private void MapObject(BonusProcess oBonusProcess, DataReader oReader)
|
|
{
|
|
base.SetObjectID(oBonusProcess, oReader.GetInt32("BonusProcessID" ).Value);
|
|
oBonusProcess.BonusID = oReader.GetInt32("bonusID").Value;
|
|
oBonusProcess.BonusMonth = oReader.GetDateTime("bonusMonth").Value;
|
|
oBonusProcess.BasicOnMonth = oReader.GetDateTime("basicOnMonth").Value;
|
|
oBonusProcess.DisburseDate = oReader.GetDateTime("disburseDate");
|
|
oBonusProcess.Remarks = oReader.GetString("remarks");
|
|
oBonusProcess.ShowInWeb = oReader.GetBoolean("showInWeb").Value;
|
|
oBonusProcess.IsDisburseWithSalary = oReader.GetBoolean("ISDISBURSEWITHSALARY").Value;
|
|
oBonusProcess.IsTaxProcess = oReader.GetBoolean("IsTaxProcess").Value;
|
|
oBonusProcess.CreatedBy = oReader.GetInt32("CreatedBy").Value;
|
|
oBonusProcess.CreatedDate = oReader.GetDateTime("CreationDate").HasValue
|
|
? oReader.GetDateTime("CreationDate").Value
|
|
: DateTime.MinValue;
|
|
oBonusProcess.ModifiedBy = oReader.GetInt32("ModifiedBy");
|
|
oBonusProcess.ModifiedDate = oReader.GetDateTime("ModifiedDate");
|
|
oBonusProcess.UsedProcess = oReader.GetInt32("UsedProcess").Value;
|
|
oBonusProcess.PayrollTypeID = oReader.GetInt32("PayrollTypeID").Value;
|
|
oBonusProcess.IsApprove = oReader.GetBoolean("IsApprove").Value;
|
|
oBonusProcess.wfstatus = oReader.GetInt32("WFStatus") == null ? null : (enumwfStatus)oReader.GetInt32("WFStatus").Value;
|
|
this.SetObjectState(oBonusProcess, Ease.Core.ObjectState.Saved);
|
|
}
|
|
|
|
protected override T CreateObject<T>(DataReader oReader)
|
|
{
|
|
BonusProcess oBonusProcess = new BonusProcess();
|
|
MapObject(oBonusProcess, oReader);
|
|
return oBonusProcess as T;
|
|
}
|
|
|
|
protected BonusProcess CreateObject(DataReader oReader)
|
|
{
|
|
BonusProcess oBonusProcess = new BonusProcess();
|
|
MapObject(oBonusProcess, oReader);
|
|
return oBonusProcess;
|
|
}
|
|
|
|
private void MapBonusProDetailObject(BonusProcess.BonusProcessDetail oBonusPDetail, DataReader oReader)
|
|
{
|
|
base.SetObjectID(oBonusPDetail, oReader.GetInt32("BonusProcessDetailID").Value);
|
|
oBonusPDetail.BonusProcessID = oReader.GetInt32("bonusProcessID").Value;
|
|
oBonusPDetail.BonusID = oReader.GetInt32("bonusID").Value;
|
|
oBonusPDetail.EmployeeID = oReader.GetInt32("EmployeeID").Value;
|
|
oBonusPDetail.BonusMonth = oReader.GetDateTime("disburseDate").Value;
|
|
oBonusPDetail.BonusAmount = oReader.GetDouble("BonusAmount").Value;
|
|
oBonusPDetail.BasicSalary = oReader.GetDouble("BasicSalary").Value;
|
|
oBonusPDetail.GrossSalary = oReader.GetDouble("GrossSalary",true , 0);
|
|
oBonusPDetail.ChangeBonusAmount = oReader.GetDouble("ChangeBonusAmount").Value;
|
|
oBonusPDetail.ChangeTaxAmount = oReader.GetDouble("ChangeTaxAmount").Value;
|
|
oBonusPDetail.ChangeAdjustAmount = oReader.GetDouble("ChangeAdjustAmount").Value;
|
|
oBonusPDetail.ChangeSalaryItemAmount = oReader.GetDouble("ChangeSalaryItemAmount").Value;
|
|
oBonusPDetail.CalculatedAdjustAmount = oReader.GetDouble("CalculatedAdjustAmount").Value;
|
|
oBonusPDetail.CalculatedSalaryItemAmount = oReader.GetDouble("CalculatedSalaryItemAmount").Value;
|
|
oBonusPDetail.TaxAmount = oReader.GetDouble("taxAmount").Value;
|
|
oBonusPDetail.ModifiedBy = oReader.GetInt32("ModifiedBy");
|
|
oBonusPDetail.ModifiedDate = oReader.GetDateTime("ModifiedDate").HasValue
|
|
? oReader.GetDateTime("ModifiedDate").Value
|
|
: (DateTime?)null;
|
|
this.SetObjectState(oBonusPDetail, Ease.Core.ObjectState.Saved);
|
|
}
|
|
|
|
protected List<BonusProcess.BonusProcessDetail> CreateBonusProcessDetailObject(DataReader oReader)
|
|
{
|
|
List<BonusProcess.BonusProcessDetail> oBonusProDetails = new List<BonusProcess.BonusProcessDetail>();
|
|
while (oReader.Read())
|
|
{
|
|
BonusProcess.BonusProcessDetail oBonusPDetail = new BonusProcess.BonusProcessDetail();
|
|
MapBonusProDetailObject(oBonusPDetail, oReader);
|
|
oBonusProDetails.Add(oBonusPDetail);
|
|
}
|
|
|
|
return oBonusProDetails;
|
|
}
|
|
|
|
private void MapBonusProDetailCumalativeObject(BonusProcess.BonusProcessDetail oBonusPDetail,
|
|
DataReader oReader)
|
|
{
|
|
oBonusPDetail.BonusID = oReader.GetInt32("bonusID", 0);
|
|
oBonusPDetail.EmployeeID = oReader.GetInt32("EmployeeID", 0);
|
|
oBonusPDetail.ChangeBonusAmount = oReader.GetDouble("BonusAmount").Value;
|
|
oBonusPDetail.ChangeSalaryItemAmount = oReader.GetDouble("Count").Value;
|
|
|
|
this.SetObjectState(oBonusPDetail, Ease.Core.ObjectState.Saved);
|
|
}
|
|
|
|
protected List<BonusProcess.BonusProcessDetail> CreateBonusProcessDetailCumalativeObject(DataReader oReader)
|
|
{
|
|
List<BonusProcess.BonusProcessDetail> oBonusProDetails = new List<BonusProcess.BonusProcessDetail>();
|
|
while (oReader.Read())
|
|
{
|
|
BonusProcess.BonusProcessDetail oBonusPDetail = new BonusProcess.BonusProcessDetail();
|
|
MapBonusProDetailCumalativeObject(oBonusPDetail, oReader);
|
|
oBonusProDetails.Add(oBonusPDetail);
|
|
}
|
|
|
|
return oBonusProDetails;
|
|
}
|
|
|
|
|
|
#region Service implementation
|
|
|
|
public double GetBonusAmount(DateTime bonusMonthFirstDate, int employeeID, int bonusID, int payrolltypeid)
|
|
{
|
|
double bonusAmount = 0;
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
bonusAmount =
|
|
BonusProcessDA.GetBonusAmount(tc, bonusMonthFirstDate, employeeID, bonusID, 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 bonusAmount;
|
|
}
|
|
|
|
public List<BonusProcess> GetProcess(int nBonusID, DateTime dBonusMonth, int payrolltypeid)
|
|
{
|
|
List<BonusProcess> bonusProcesss = null;
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(BonusProcessDA.GetProcess(tc, nBonusID, dBonusMonth, payrolltypeid));
|
|
bonusProcesss = this.CreateObjects<BonusProcess>(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 bonusProcesss;
|
|
}
|
|
|
|
public List<BonusProcess> GetAllBonusProcess(int payrolltypeid)
|
|
{
|
|
List<BonusProcess> bonusProcesss = null;
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(BonusProcessDA.GetAllbonusProcess(tc, payrolltypeid));
|
|
bonusProcesss = this.CreateObjects<BonusProcess>(dr);
|
|
dr.Close();
|
|
bonusProcesss = bonusProcesss.GroupBy(obj => obj.ID).Select(group => group.First()).ToList();
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
|
|
return bonusProcesss;
|
|
}
|
|
|
|
public double GetUsedBonusWithinYear(DateTime bonusMonthFirstDate, int bonusID, int payrolltypeid)
|
|
{
|
|
double usedBonus = 0;
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
usedBonus = BonusProcessDA.GetUsedBonusWithinYear(tc, bonusMonthFirstDate, bonusID, 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 usedBonus;
|
|
}
|
|
|
|
public double GetBonusAmountWithinYear(DateTime bonusYearDate, int employeeID, int bonusID, int payrolltypeid)
|
|
{
|
|
double bonusAmount = 0;
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
bonusAmount =
|
|
BonusProcessDA.GetBonusAmountWithinYear(tc, bonusYearDate, employeeID, bonusID, 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 bonusAmount;
|
|
}
|
|
|
|
public BonusProcess Get(int id)
|
|
{
|
|
BonusProcess oBonusProcess = new BonusProcess();
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oreader = new DataReader(BonusProcessDA.Get(tc, id));
|
|
if (oreader.Read())
|
|
{
|
|
oBonusProcess = this.CreateObject<BonusProcess>(oreader);
|
|
}
|
|
oreader.Close();
|
|
if (oBonusProcess != null)
|
|
{
|
|
DataReader ddetail = new DataReader(BonusProcessDA.GetBonusDetails(tc, id));
|
|
oBonusProcess.BonusProcessDetails = this.CreateBonusProcessDetailObject(ddetail);
|
|
ddetail.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 oBonusProcess;
|
|
}
|
|
|
|
public BonusProcess Get(TransactionContext tc,int id)
|
|
{
|
|
BonusProcess oBonusProcess = new BonusProcess();
|
|
|
|
try
|
|
{
|
|
DataReader oreader = new DataReader(BonusProcessDA.Get(tc, id));
|
|
if (oreader.Read())
|
|
{
|
|
oBonusProcess = this.CreateObject<BonusProcess>(oreader);
|
|
}
|
|
oreader.Close();
|
|
if (oBonusProcess != null)
|
|
{
|
|
DataReader ddetail = new DataReader(BonusProcessDA.GetBonusDetails(tc, id));
|
|
oBonusProcess.BonusProcessDetails = this.CreateBonusProcessDetailObject(ddetail);
|
|
ddetail.Close();
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
#endregion
|
|
}
|
|
|
|
return oBonusProcess;
|
|
}
|
|
|
|
public List<BonusProcess> Get(EnumStatus status, int payrolltypeid)
|
|
{
|
|
List<BonusProcess> bonusProcesss = null;
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(BonusProcessDA.Get(tc, status, payrolltypeid));
|
|
bonusProcesss = this.CreateObjects<BonusProcess>(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 bonusProcesss;
|
|
}
|
|
|
|
public int GetForNoOfPaidForEmp(DateTime bonusMonthFirstDate, int bonusID, int empid, int payrolltypeid)
|
|
{
|
|
int bonusAmount = 0;
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
bonusAmount =
|
|
BonusProcessDA.GetForNoOfPaidForEmp(tc, bonusMonthFirstDate, bonusID, empid, 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 bonusAmount;
|
|
}
|
|
|
|
public int GetForNoOfPaid(DateTime bonusMonthFirstDate, int bonusID, int payrolltypeid)
|
|
{
|
|
int bonusAmount = 0;
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
bonusAmount = BonusProcessDA.GetForNoOfPaid(tc, bonusMonthFirstDate, bonusID, 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 bonusAmount;
|
|
}
|
|
|
|
public List<BonusProcess.BonusProcessDetail> GetBonusDetails(int processID)
|
|
{
|
|
List<BonusProcess.BonusProcessDetail> bonusProcessDetails = null;
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(BonusProcessDA.GetBonusDetails(tc, processID));
|
|
bonusProcessDetails = this.CreateBonusProcessDetailObject(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 bonusProcessDetails;
|
|
}
|
|
public List<BonusProcess.BonusProcessDetail> GetBonusDetailsByEmps(string empsIDs, DateTime fromDate, DateTime toDate, int payrollTypeID)
|
|
{
|
|
List<BonusProcess.BonusProcessDetail> bonusProcessDetails = new List<BonusProcess.BonusProcessDetail>();
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(BonusProcessDA.GetBonusDetailsbyEmps(tc, empsIDs, fromDate, toDate, payrollTypeID));
|
|
bonusProcessDetails = this.CreateBonusProcessDetailObject(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 bonusProcessDetails;
|
|
}
|
|
public BonusProcess Get(int bonusID, DateTime dBonusMonth, int payrolltypeid)
|
|
{
|
|
BonusProcess oProcess = null;
|
|
//bjectsTemplate<BonusProcess.BonusProcessDetail.BonusProcessAdjustItem> oBonusProcessAdjustItems = null;
|
|
//List<BonusProcess.BonusProcessDetail.BonusProcessSalaryItem> oBonusProcessSalaryItems = null;
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(BonusProcessDA.Get(tc, bonusID, dBonusMonth, payrolltypeid));
|
|
if (dr.Read())
|
|
{
|
|
oProcess = this.CreateObject<BonusProcess>(dr);
|
|
}
|
|
|
|
dr.Close();
|
|
if (oProcess != null)
|
|
{
|
|
dr = new DataReader(BonusProcessDA.GetBonusDetails(tc, oProcess.ID));
|
|
oProcess.BonusProcessDetails = this.CreateBonusProcessDetailObject(dr);
|
|
dr.Close();
|
|
//if(oProcess.BonusProcessDetails!=null && oProcess.BonusProcessDetails.Count>0)
|
|
//{
|
|
// dr = new DataReader(BonusProcessDA.GetBProcessSalaryItem(tc, oProcess.ID));
|
|
// if(dr.Read())
|
|
// {
|
|
// oBonusProcessSalaryItems = this.CreateBonusPSItemObject(dr);
|
|
// }
|
|
// dr.Close();
|
|
// dr = new DataReader(BonusProcessDA.GetBProcessAdjust(tc, oProcess.ID));
|
|
// if(dr.Read())
|
|
// {
|
|
// oBonusProcessAdjustItems=this.CreateBonusProcessAItemObject(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 oProcess;
|
|
}
|
|
|
|
public BonusProcess Get(TransactionContext tc,int bonusID, DateTime dBonusMonth, int payrolltypeid)
|
|
{
|
|
BonusProcess oProcess = null;
|
|
//bjectsTemplate<BonusProcess.BonusProcessDetail.BonusProcessAdjustItem> oBonusProcessAdjustItems = null;
|
|
//List<BonusProcess.BonusProcessDetail.BonusProcessSalaryItem> oBonusProcessSalaryItems = null;
|
|
try
|
|
{
|
|
DataReader dr = new DataReader(BonusProcessDA.Get(tc, bonusID, dBonusMonth, payrolltypeid));
|
|
if (dr.Read())
|
|
{
|
|
oProcess = this.CreateObject<BonusProcess>(dr);
|
|
}
|
|
dr.Close();
|
|
if (oProcess != null)
|
|
{
|
|
dr = new DataReader(BonusProcessDA.GetBonusDetails(tc, oProcess.ID));
|
|
oProcess.BonusProcessDetails = this.CreateBonusProcessDetailObject(dr);
|
|
dr.Close();
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
|
|
|
|
return oProcess;
|
|
}
|
|
|
|
public List<BonusProcess> GetProcess(DateTime dBonusMonth, int payrolltypeid)
|
|
{
|
|
List<BonusProcess> bonusProcesss = null;
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(BonusProcessDA.GetProcess(tc, dBonusMonth, payrolltypeid));
|
|
bonusProcesss = this.CreateObjects<BonusProcess>(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 bonusProcesss;
|
|
}
|
|
|
|
public List<BonusProcess.BonusProcessDetail> GetSumOfBonusDetails(DateTime fromMonth, DateTime toMonth,
|
|
int payrolltypeid)
|
|
{
|
|
List<BonusProcess.BonusProcessDetail> bonusProcessDetails = null;
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr =
|
|
new DataReader(BonusProcessDA.GetSumOfBonusDetails(tc, fromMonth, toMonth, payrolltypeid));
|
|
bonusProcessDetails = this.CreateBonusProcessDetailCumalativeObject(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 bonusProcessDetails;
|
|
}
|
|
|
|
public List<BonusProcess.BonusProcessDetail> GetBonusDetails(DateTime dMonth, bool bPayWithalary,
|
|
int payrolltypeid)
|
|
{
|
|
List<BonusProcess.BonusProcessDetail> bonusProcessDetails = null;
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr =
|
|
new DataReader(BonusProcessDA.GetBonusDetails(tc, dMonth, bPayWithalary, payrolltypeid));
|
|
bonusProcessDetails = this.CreateBonusProcessDetailObject(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 bonusProcessDetails;
|
|
}
|
|
|
|
//public List<BonusProcess.BonusProcessDetail.BonusProcessAdjustItem> GetBProcessAdjust(int processDetailID)
|
|
//{
|
|
// #region Cache Header
|
|
|
|
// List<BonusProcess.BonusProcessDetail.BonusProcessAdjustItem> bonusProcessAdjustItems = _cache["GetBProcessAdjust", processDetailID] as List<BonusProcess.BonusProcessDetail.BonusProcessAdjustItem>;
|
|
// if (bonusProcessAdjustItems != null)
|
|
// return bonusProcessAdjustItems;
|
|
|
|
// #endregion
|
|
|
|
// TransactionContext tc = null;
|
|
// try
|
|
// {
|
|
// tc = TransactionContext.Begin();
|
|
|
|
// DataReader dr = new DataReader(BonusProcessDA.GetBProcessAdjust(tc, processDetailID));
|
|
// bonusProcessAdjustItems = this.CreateBonusProcessAItemObject(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(bonusProcessAdjustItems, "GetBProcessAdjust", processDetailID);
|
|
|
|
// #endregion
|
|
|
|
// return bonusProcessAdjustItems;
|
|
//}
|
|
|
|
public DataSet GetBonusRegister(int bonusID, DateTime dBonusMonth, string sEmpID, int payrolltypeid)
|
|
{
|
|
DataSet oBonusRegisters = new DataSet();
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
oBonusRegisters = BonusProcessDA.GetBonusRegister(tc, bonusID, dBonusMonth, sEmpID, 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 oBonusRegisters;
|
|
}
|
|
|
|
public DataSet GetBonusBankAdvice(int bonusID, DateTime dBonusMonth, string sEmpID, int payrolltypeid)
|
|
{
|
|
DataSet oBonusRegisters = new DataSet();
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
oBonusRegisters = BonusProcessDA.GetBonusBankAdvice(tc, bonusID, dBonusMonth, sEmpID, 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 oBonusRegisters;
|
|
}
|
|
public DataSet GetBonusBankAdvice(Bonus bonus, DateTime dBonusMonth, string sEmpID, int payrolltypeid)
|
|
{
|
|
DataSet oBonusRegisters = new DataSet();
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
oBonusRegisters = BonusProcessDA.GetBonusBankAdvice(tc, bonus, dBonusMonth, sEmpID, 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 oBonusRegisters;
|
|
}
|
|
|
|
public DataSet GetBonusPaySlip(int bonusID, DateTime dBonusMonth, string sEmpID, int payrolltypeid)
|
|
{
|
|
DataSet oBonusBankSlip = new DataSet();
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
oBonusBankSlip = BonusProcessDA.GetBonusPaySlip(tc, bonusID, dBonusMonth, sEmpID, 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 oBonusBankSlip;
|
|
}
|
|
|
|
public DataTable GetBonusItemsForESSBonusPayslip(int EmployeeID)
|
|
{
|
|
DataTable dSet = null;
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
dSet = BonusProcessDA.GetBonusItemsForESSBonusPayslip(tc, EmployeeID);
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
|
|
}
|
|
return dSet;
|
|
}
|
|
|
|
public int Save(BonusProcess oBonusProcess)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
if (oBonusProcess.IsNew)
|
|
{
|
|
int id = tc.GenerateID("BONUSPROCESS", "BONUSPROCESSID");
|
|
base.SetObjectID(oBonusProcess, (id));
|
|
BonusProcessDA.Insert(tc, oBonusProcess);
|
|
}
|
|
else
|
|
{
|
|
BonusProcessDA.Update(tc, oBonusProcess);
|
|
BonusProcessDA.DeleteProcessDetailByProcessID(tc, oBonusProcess.BonusID, oBonusProcess.ID, oBonusProcess.PayrollTypeID);
|
|
BonusProcessDA.DeleteEmpCostCenter(tc, oBonusProcess.ID);
|
|
}
|
|
List<IncomeTax> incometaxes = new List<IncomeTax>();
|
|
foreach (BonusProcess.BonusProcessDetail oBonusProcessDetail in oBonusProcess.BonusProcessDetails)
|
|
{
|
|
int id = tc.GenerateID("BONUSPROCESSDETAIL", "BonusProcessDetailID");
|
|
base.SetObjectID(oBonusProcessDetail, (id));
|
|
oBonusProcessDetail.BonusProcessID = oBonusProcess.ID;
|
|
BonusProcessDA.Insert(tc, oBonusProcessDetail);
|
|
IncomeTaxService osvr = new IncomeTaxService();
|
|
// IncomeTaxcoll null mean tax process not required
|
|
if (oBonusProcessDetail.IncomeTaxcoll != null && oBonusProcessDetail.IncomeTaxcoll.Count > 0)
|
|
{
|
|
foreach(IncomeTax tx in oBonusProcessDetail.IncomeTaxcoll)
|
|
{
|
|
incometaxes.Add(tx);
|
|
}
|
|
}
|
|
}
|
|
if(incometaxes.Count >0)
|
|
{
|
|
new IncomeTaxService().SaveBulk(tc, incometaxes, EnumIncomeTaxDataFrom.BonusITTempData);
|
|
}
|
|
|
|
SaveBonusEmpCostCenter(tc, oBonusProcess);
|
|
|
|
tc.End();
|
|
return oBonusProcess.ID;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Bonus Process screen, "Process" button: calculate the bonus (and tax) of the given employees and
|
|
/// save it in the same call — there is no separate Save step any more. Does on the server what the
|
|
/// screen used to do in three requests (BonusProcess, the tax-merge step of save(), saveBonusProcess):
|
|
/// 1. checks: bonus not approved, inputs present; employees this bonus was already processed for this
|
|
/// month are left out (the screen already leaves them out and lists them);
|
|
/// 2. CalculateBonus — the same BonusCalculator.CalCulate the old Process button called;
|
|
/// 3. tax merge — the same rule save() applied in the browser, now for every row;
|
|
/// 4. save — the same rows Save(BonusProcess) writes, in ONE transaction (all or nothing), with the
|
|
/// detail rows inserted by one bulk copy instead of one INSERT each;
|
|
/// 5. returns the saved rows, read back from the database.
|
|
/// </summary>
|
|
public BonusProcessAndSaveResult ProcessAndSave(BonusProcessAndSaveRequest request, int payrolltypeid, int userID)
|
|
{
|
|
if (request == null)
|
|
throw new ServiceException("Nothing to process.");
|
|
if (request.BonusID <= 0)
|
|
throw new ServiceException("Please select a bonus.");
|
|
if (request.EmployeeIDs == null || request.EmployeeIDs.Count == 0)
|
|
throw new ServiceException("Please select employee for the proces");
|
|
if (request.CurrProcess <= 0)
|
|
throw new ServiceException("Currently Process For Basic must be greater than zero.");
|
|
|
|
PayrollType payrollType = new PayrollTypeService().Get(payrolltypeid);
|
|
if (payrollType == null)
|
|
throw new ServiceException("Payroll type not found.");
|
|
DateTime bonusMonth = payrollType.NextPayProcessDate;
|
|
|
|
// 1. checks
|
|
if (this.IsApproved(request.BonusID, bonusMonth, payrolltypeid))
|
|
throw new ServiceException("selected Bonus is already process and Approved");
|
|
|
|
BonusProcessAndSaveResult result = new BonusProcessAndSaveResult();
|
|
HashSet<int> alreadyProcessed = new HashSet<int>(
|
|
(this.GetBonusDetails(payrolltypeid, request.BonusID, bonusMonth) ?? new List<BonusProcess.BonusProcessDetail>())
|
|
.Select(x => x.EmployeeID));
|
|
List<int> empIDs = new List<int>();
|
|
foreach (int id in request.EmployeeIDs.Distinct())
|
|
{
|
|
if (alreadyProcessed.Contains(id)) result.AlreadyProcessedEmployeeIDs.Add(id);
|
|
else empIDs.Add(id);
|
|
}
|
|
if (empIDs.Count == 0)
|
|
throw new ServiceException("The selected bonus is already processed for all the selected employees.");
|
|
|
|
List<Employee> employees = new EmployeeService().GetByEmpIDList(empIDs, payrolltypeid);
|
|
if (employees.Count == 0)
|
|
throw new ServiceException("Selected employees not found in the current payroll type.");
|
|
|
|
// 2. calculate (bonus, and tax when IsTaxProcess and not disbursed with salary)
|
|
BonusProcess oProcess = this.CalculateBonus(payrolltypeid, employees, request.BonusID, request.BasicMonth,
|
|
request.PayDate, request.CuttOfDate, request.CurrProcess, request.IsDisburseWithSalary, request.IsTaxProcess);
|
|
if (oProcess == null || oProcess.BonusProcessDetails == null || oProcess.BonusProcessDetails.Count == 0)
|
|
throw new ServiceException("There are no data to save");
|
|
|
|
// 3. tax merge: the bonus head's tax line carries the bonus amount, the Tax Deducted line the tax
|
|
if (request.IsTaxProcess)
|
|
ApplyTaxMerge(oProcess, employees, payrollType, request.BonusID);
|
|
|
|
// 4. save — header as saveBonusProcess set it, then the same rows Save(BonusProcess) writes
|
|
oProcess.PayrollTypeID = payrolltypeid;
|
|
oProcess.DisburseDate = request.PayDate;
|
|
oProcess.IsTaxProcess = request.IsTaxProcess;
|
|
oProcess.IsDisburseWithSalary = request.IsDisburseWithSalary;
|
|
oProcess.CreatedBy = userID;
|
|
oProcess.CreatedDate = DateTime.Today;
|
|
SaveNewProcess(oProcess);
|
|
|
|
// 5. what was saved
|
|
result.BonusProcessID = oProcess.ID;
|
|
result.Rows = this.GetGridRows(oProcess.ID);
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Bonus Process screen, "Upload Data": the rows read from the bonus Excel file (employee + amount,
|
|
/// RegularDataUploadService.GetBonusData) are saved in the same request — what used to be upload →
|
|
/// (Tax Re-calculate) → Save, now on the server in one go:
|
|
/// 1. checks: bonus selected, pay date, not approved; every employee in the current payroll type and
|
|
/// only once in the file; employees this bonus was already processed for this month are left out;
|
|
/// 2. with IsTaxProcess, the tax of every row (the same CalculateTax "Tax Re-calculate" ran) and the
|
|
/// save() tax merge; without it the amounts are saved as they are in the file;
|
|
/// 3. the same save as the Process button (one transaction, all or nothing);
|
|
/// 4. returns the saved rows, read back from the database.
|
|
/// The header is filled the way the screen filled it after an upload (bonus month and basic month =
|
|
/// the next pay process month, disburse date = pay date).
|
|
/// </summary>
|
|
public BonusProcessAndSaveResult UploadAndSave(List<BonusProcess.BonusProcessDetail> uploadedRows,
|
|
BonusProcessAndSaveRequest request, int payrolltypeid, int userID)
|
|
{
|
|
if (request == null || request.BonusID <= 0)
|
|
throw new ServiceException("Please select a bonus.");
|
|
if (request.PayDate == DateTime.MinValue)
|
|
throw new ServiceException("Please select the pay date.");
|
|
if (uploadedRows == null || uploadedRows.Count == 0)
|
|
throw new ServiceException("No employee found in the uploaded file.");
|
|
|
|
PayrollType payrollType = new PayrollTypeService().Get(payrolltypeid);
|
|
if (payrollType == null)
|
|
throw new ServiceException("Payroll type not found.");
|
|
DateTime bonusMonth = payrollType.NextPayProcessDate;
|
|
|
|
// 1. checks
|
|
if (this.IsApproved(request.BonusID, bonusMonth, payrolltypeid))
|
|
throw new ServiceException("selected Bonus is already process and Approved");
|
|
|
|
List<string> problems = new List<string>();
|
|
var otherPayroll = uploadedRows.Where(x => x.Employee != null && x.Employee.PayrollTypeID != payrolltypeid)
|
|
.Select(x => x.Employee.EmployeeNo).Distinct().ToList();
|
|
if (otherPayroll.Count > 0)
|
|
problems.Add("Not in the current payroll type: " + string.Join(", ", otherPayroll));
|
|
var duplicates = uploadedRows.GroupBy(x => x.EmployeeID).Where(g => g.Count() > 1)
|
|
.Select(g => g.First().Employee?.EmployeeNo ?? g.Key.ToString()).ToList();
|
|
if (duplicates.Count > 0)
|
|
problems.Add("More than once in the file: " + string.Join(", ", duplicates));
|
|
var negative = uploadedRows.Where(x => x.BonusAmount < 0).Select(x => x.Employee?.EmployeeNo ?? x.EmployeeID.ToString()).ToList();
|
|
if (negative.Count > 0)
|
|
problems.Add("Negative amount: " + string.Join(", ", negative));
|
|
if (problems.Count > 0)
|
|
throw new ServiceException("Nothing was saved. " + string.Join(" | ", problems));
|
|
|
|
BonusProcessAndSaveResult result = new BonusProcessAndSaveResult();
|
|
HashSet<int> alreadyProcessed = new HashSet<int>(
|
|
(this.GetBonusDetails(payrolltypeid, request.BonusID, bonusMonth) ?? new List<BonusProcess.BonusProcessDetail>())
|
|
.Select(x => x.EmployeeID));
|
|
|
|
BonusProcess oProcess = new BonusProcess();
|
|
oProcess.BonusProcessDetails = new List<BonusProcess.BonusProcessDetail>();
|
|
oProcess.BonusID = request.BonusID;
|
|
oProcess.BonusMonth = bonusMonth;
|
|
oProcess.BasicOnMonth = bonusMonth;
|
|
oProcess.DisburseDate = request.PayDate;
|
|
oProcess.IsTaxProcess = request.IsTaxProcess;
|
|
oProcess.IsDisburseWithSalary = request.IsDisburseWithSalary;
|
|
oProcess.PayrollTypeID = payrolltypeid;
|
|
oProcess.CreatedBy = userID;
|
|
oProcess.CreatedDate = DateTime.Today;
|
|
|
|
List<Employee> employees = new List<Employee>();
|
|
foreach (BonusProcess.BonusProcessDetail row in uploadedRows)
|
|
{
|
|
if (alreadyProcessed.Contains(row.EmployeeID))
|
|
{
|
|
result.AlreadyProcessedEmployeeIDs.Add(row.EmployeeID);
|
|
continue;
|
|
}
|
|
row.BonusID = request.BonusID;
|
|
row.BonusMonth = bonusMonth;
|
|
oProcess.BonusProcessDetails.Add(row);
|
|
if (row.Employee != null) employees.Add(row.Employee);
|
|
}
|
|
if (oProcess.BonusProcessDetails.Count == 0)
|
|
throw new ServiceException("The selected bonus is already processed for all the employees in the file.");
|
|
|
|
// 2. tax (as "Tax Re-calculate" did) and the save() merge
|
|
if (request.IsTaxProcess)
|
|
{
|
|
Bonus obonus = new BonusService().Get(request.BonusID);
|
|
new BonusCalculator().CalculateTax(oProcess.BonusProcessDetails, employees, obonus, payrolltypeid);
|
|
ApplyTaxMerge(oProcess, employees, payrollType, request.BonusID);
|
|
}
|
|
|
|
// 3. save
|
|
SaveNewProcess(oProcess);
|
|
|
|
// 4. what was saved
|
|
result.BonusProcessID = oProcess.ID;
|
|
result.Rows = this.GetGridRows(oProcess.ID);
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// The tax-merge rule the screen's save() applied: on every row the bonus head's tax line
|
|
/// (TaxMergeMaster of this bonus) carries the bonus amount and the Tax Deducted line the tax.
|
|
/// </summary>
|
|
private void ApplyTaxMerge(BonusProcess oProcess, List<Employee> employees, PayrollType payrollType, int bonusID)
|
|
{
|
|
// a row with no bonus gets no tax lines (CalculateTax skips it), so only rows with a bonus need them
|
|
if (oProcess.BonusProcessDetails.Any(x => x.ChangeBonusAmount > 0 && (x.IncomeTaxcoll == null || x.IncomeTaxcoll.Count == 0)))
|
|
throw new ServiceException("Tax Calculation not yet done");
|
|
if (payrollType.TaxParamID == null)
|
|
throw new ServiceException("Current year Tax paramter setup not found.");
|
|
|
|
TaxMergeMaster mitem = new TaxMergeMasterService().Get(payrollType.ID, (int)payrollType.TaxParamID,
|
|
EnumTaxMergeType.Bonus, bonusID);
|
|
if (mitem == null)
|
|
throw new ServiceException("Bonus head not found in the income tax Grouping");
|
|
|
|
Dictionary<int, Employee> empByID = employees.GroupBy(x => x.ID).ToDictionary(g => g.Key, g => g.First());
|
|
foreach (BonusProcess.BonusProcessDetail detail in oProcess.BonusProcessDetails)
|
|
{
|
|
if (detail.IncomeTaxcoll == null || detail.IncomeTaxcoll.Count == 0)
|
|
continue; // no bonus, no tax lines
|
|
IncomeTax bonusLine = detail.IncomeTaxcoll.Find(y => y.ItemGroup == mitem.ItemGroup && y.ItemID == mitem.ItemID);
|
|
if (bonusLine == null)
|
|
{
|
|
Employee emp;
|
|
empByID.TryGetValue(detail.EmployeeID, out emp);
|
|
throw new ServiceException("Income tax amount not found in the collection"
|
|
+ (emp != null ? " (" + emp.EmployeeNo + " " + emp.Name + ")" : ""));
|
|
}
|
|
bonusLine.ThisMonthAmount = detail.ChangeBonusAmount;
|
|
|
|
IncomeTax taxLine = detail.IncomeTaxcoll.Find(y => y.ItemGroup == EnumIncomeTaxItemGroup.Tax_Deducted);
|
|
if (taxLine != null)
|
|
taxLine.ThisMonthAmount = detail.ChangeTaxAmount;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Saves a new bonus process in ONE transaction: the header, every detail row (one bulk copy), the
|
|
/// bonus tax data (BonusITTempData) and the employee cost-center split — the rows Save(BonusProcess)
|
|
/// writes for a new process. Sets the IDs on oProcess and its details.
|
|
/// </summary>
|
|
private void SaveNewProcess(BonusProcess oProcess)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
|
|
int processID = tc.GenerateID("BONUSPROCESS", "BONUSPROCESSID");
|
|
base.SetObjectID(oProcess, processID);
|
|
BonusProcessDA.Insert(tc, oProcess);
|
|
|
|
int detailID = tc.GenerateID("BONUSPROCESSDETAIL", "BonusProcessDetailID");
|
|
List<IncomeTax> incometaxes = new List<IncomeTax>();
|
|
foreach (BonusProcess.BonusProcessDetail detail in oProcess.BonusProcessDetails)
|
|
{
|
|
base.SetObjectID(detail, detailID++);
|
|
detail.BonusProcessID = oProcess.ID;
|
|
// IncomeTaxcoll null means tax process not required
|
|
if (detail.IncomeTaxcoll != null && detail.IncomeTaxcoll.Count > 0)
|
|
incometaxes.AddRange(detail.IncomeTaxcoll);
|
|
}
|
|
BonusProcessDA.InsertBulk(tc, oProcess.BonusProcessDetails);
|
|
|
|
if (incometaxes.Count > 0)
|
|
new IncomeTaxService().SaveBulk(tc, incometaxes, EnumIncomeTaxDataFrom.BonusITTempData);
|
|
|
|
SaveBonusEmpCostCenter(tc, oProcess);
|
|
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
}
|
|
|
|
/// <summary>The saved rows of one bonus process, as the Bonus Process grid shows them.</summary>
|
|
public List<BonusProcessGridRow> GetGridRows(int bonusProcessID)
|
|
{
|
|
List<BonusProcessGridRow> rows = new List<BonusProcessGridRow>();
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(BonusProcessDA.GetGridRows(tc, bonusProcessID));
|
|
while (dr.Read())
|
|
rows.Add(MapGridRow(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 rows;
|
|
}
|
|
|
|
private static BonusProcessGridRow MapGridRow(DataReader dr)
|
|
{
|
|
return new BonusProcessGridRow
|
|
{
|
|
BonusProcessDetailID = dr.GetInt32("BONUSPROCESSDETAILID", 0),
|
|
BonusProcessID = dr.GetInt32("BONUSPROCESSID", 0),
|
|
BonusID = dr.GetInt32("BONUSID", 0),
|
|
EmployeeID = dr.GetInt32("EMPLOYEEID", 0),
|
|
EmployeeNo = dr.GetString("EMPLOYEENO", string.Empty),
|
|
Name = dr.GetString("NAME", string.Empty),
|
|
JoiningDate = dr.GetDateTime("JOININGDATE"),
|
|
IsConfirmed = dr.GetBoolean("ISCONFIRMED", false),
|
|
GrossSalary = dr.GetDouble("GROSSSALARY", 0),
|
|
BasicSalary = dr.GetDouble("BASICSALARY", 0),
|
|
BonusAmount = dr.GetDouble("BONUSAMOUNT", 0),
|
|
ChangeBonusAmount = dr.GetDouble("CHANGEBONUSAMOUNT", 0),
|
|
TaxAmount = dr.GetDouble("TAXAMOUNT", 0),
|
|
ChangeTaxAmount = dr.GetDouble("CHANGETAXAMOUNT", 0),
|
|
};
|
|
}
|
|
|
|
/// <summary>One saved row of the Bonus Process grid (after a Modify-dialog save).</summary>
|
|
public BonusProcessGridRow GetGridRow(int bonusProcessDetailID)
|
|
{
|
|
BonusProcessGridRow row = null;
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(BonusProcessDA.GetGridRow(tc, bonusProcessDetailID));
|
|
if (dr.Read())
|
|
row = MapGridRow(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 row;
|
|
}
|
|
|
|
#region Modify dialog (one row at a time)
|
|
|
|
/// <summary>A saved bonus row and the header fields the Modify dialog needs.</summary>
|
|
private class ModifyRow
|
|
{
|
|
public int BonusProcessDetailID;
|
|
public int BonusProcessID;
|
|
public int BonusID;
|
|
public int EmployeeID;
|
|
public double TaxAmount;
|
|
public DateTime BonusMonth;
|
|
public int PayrollTypeID;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Loads a saved row for the Modify dialog and refuses it when it is not the current payroll type's
|
|
/// or the bonus is already approved (the same rule as the Process button).
|
|
/// </summary>
|
|
private ModifyRow GetRowForModify(int bonusProcessDetailID, int payrolltypeid)
|
|
{
|
|
ModifyRow row = null;
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(BonusProcessDA.GetRowWithHeader(tc, bonusProcessDetailID));
|
|
if (dr.Read())
|
|
{
|
|
row = new ModifyRow
|
|
{
|
|
BonusProcessDetailID = dr.GetInt32("BONUSPROCESSDETAILID", 0),
|
|
BonusProcessID = dr.GetInt32("BONUSPROCESSID", 0),
|
|
BonusID = dr.GetInt32("BONUSID", 0),
|
|
EmployeeID = dr.GetInt32("EMPLOYEEID", 0),
|
|
TaxAmount = dr.GetDouble("TAXAMOUNT", 0),
|
|
BonusMonth = dr.GetDateTime("BONUSMONTH", DateTime.MinValue),
|
|
PayrollTypeID = dr.GetInt32("PAYROLLTYPEID", 0),
|
|
};
|
|
}
|
|
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
|
|
}
|
|
|
|
if (row == null)
|
|
throw new ServiceException("Bonus row not found. Please process the bonus again.");
|
|
if (row.PayrollTypeID != payrolltypeid)
|
|
throw new ServiceException("This bonus row does not belong to the current payroll type.");
|
|
if (this.IsApproved(row.BonusID, row.BonusMonth, payrolltypeid))
|
|
throw new ServiceException("selected Bonus is already process and Approved");
|
|
return row;
|
|
}
|
|
|
|
/// <summary>
|
|
/// The tax of one row for this bonus amount — the same BonusCalculator.CalculateTax that
|
|
/// "Tax Re-calculate" (CalculateBonusTax) runs, for one employee. Returns the detail with TaxAmount,
|
|
/// ChangeTaxAmount and IncomeTaxcoll filled in.
|
|
/// </summary>
|
|
private BonusProcess.BonusProcessDetail CalculateTaxFor(ModifyRow row, double bonusAmount, int payrolltypeid)
|
|
{
|
|
Employee emp = new EmployeeService().Get(row.EmployeeID);
|
|
if (emp == null)
|
|
throw new ServiceException("Employee not found.");
|
|
|
|
BonusProcess.BonusProcessDetail detail = new BonusProcess.BonusProcessDetail();
|
|
detail.BonusID = row.BonusID;
|
|
detail.EmployeeID = row.EmployeeID;
|
|
detail.BonusMonth = row.BonusMonth;
|
|
detail.ChangeBonusAmount = bonusAmount;
|
|
detail.Employee = emp;
|
|
|
|
Bonus obonus = new BonusService().Get(row.BonusID);
|
|
// CalculateTaxForModify: CalculateTax, except that this employee's own (already saved) bonus tax rows
|
|
// do not block it — only an unfinalized salary does
|
|
new BonusCalculator().CalculateTaxForModify(new List<BonusProcess.BonusProcessDetail> { detail },
|
|
new List<Employee> { emp }, obonus, payrolltypeid);
|
|
return detail;
|
|
}
|
|
|
|
/// <summary>Modify dialog, "Calculate": the tax for this bonus amount. Nothing is saved.</summary>
|
|
public BonusProcessRowTaxResult CalculateRowTax(BonusProcessRowTaxRequest request, int payrolltypeid)
|
|
{
|
|
if (request == null || request.BonusProcessDetailID <= 0)
|
|
throw new ServiceException("Please select a bonus row.");
|
|
if (request.BonusAmount < 0)
|
|
throw new ServiceException("Bonus amount can not be negative.");
|
|
|
|
ModifyRow row = GetRowForModify(request.BonusProcessDetailID, payrolltypeid);
|
|
BonusProcess.BonusProcessDetail detail = CalculateTaxFor(row, request.BonusAmount, payrolltypeid);
|
|
return new BonusProcessRowTaxResult
|
|
{
|
|
BonusProcessDetailID = row.BonusProcessDetailID,
|
|
BonusAmount = request.BonusAmount,
|
|
TaxAmount = detail.ChangeTaxAmount,
|
|
};
|
|
}
|
|
|
|
/// <summary>
|
|
/// Modify dialog, "Save": saves ONE row — what Save(BonusProcess) did for every row after
|
|
/// "Tax Re-calculate", now for one employee, in one transaction:
|
|
/// - BONUSPROCESSDETAIL: ChangeBonusAmount, ChangeTaxAmount (and TaxAmount when the tax is calculated);
|
|
/// - this employee's BonusITTempData (BONUSTEMPIT) rows: deleted and written again, with the bonus
|
|
/// head's line carrying the bonus amount and the Tax Deducted line the tax (the save() merge rule).
|
|
/// With CalculateTax the tax is worked out again here (the amount the browser sent is not trusted);
|
|
/// without it the typed tax is used and the employee's existing tax rows are updated, as the old
|
|
/// screen did when a tax was typed into the grid and saved without recalculating.
|
|
/// </summary>
|
|
public BonusProcessGridRow SaveRow(BonusProcessRowSaveRequest request, int payrolltypeid, int userID)
|
|
{
|
|
if (request == null || request.BonusProcessDetailID <= 0)
|
|
throw new ServiceException("Please select a bonus row.");
|
|
if (request.BonusAmount < 0)
|
|
throw new ServiceException("Bonus amount can not be negative.");
|
|
if (!request.CalculateTax && request.TaxAmount < 0)
|
|
throw new ServiceException("Tax amount can not be negative.");
|
|
if (request.CalculateTax && request.EditedTaxAmount.HasValue && request.EditedTaxAmount.Value < 0)
|
|
throw new ServiceException("Edited tax amount can not be negative.");
|
|
|
|
ModifyRow row = GetRowForModify(request.BonusProcessDetailID, payrolltypeid);
|
|
|
|
double bonusAmount = request.BonusAmount;
|
|
double changeTaxAmount;
|
|
double taxAmount = row.TaxAmount; // the calculated tax; kept when a tax is typed in
|
|
List<IncomeTax> taxLines = null;
|
|
|
|
if (request.CalculateTax)
|
|
{
|
|
BonusProcess.BonusProcessDetail detail = CalculateTaxFor(row, bonusAmount, payrolltypeid);
|
|
// the user's "Edited Tax Amount" wins over the calculated one; TAXAMOUNT keeps the calculated tax
|
|
changeTaxAmount = request.EditedTaxAmount.HasValue ? request.EditedTaxAmount.Value : detail.ChangeTaxAmount;
|
|
taxAmount = detail.TaxAmount;
|
|
taxLines = detail.IncomeTaxcoll;
|
|
}
|
|
else
|
|
{
|
|
changeTaxAmount = request.TaxAmount;
|
|
List<IncomeTax> existing = new IncomeTaxService().Get(row.EmployeeID, EnumIncomeTaxDataFrom.BonusITTempData);
|
|
if (existing != null && existing.Count > 0)
|
|
taxLines = existing;
|
|
}
|
|
|
|
if (taxLines != null && taxLines.Count > 0)
|
|
{
|
|
PayrollType payrollType = new PayrollTypeService().Get(payrolltypeid);
|
|
if (payrollType == null || payrollType.TaxParamID == null)
|
|
throw new ServiceException("Current year Tax paramter setup not found.");
|
|
TaxMergeMaster mitem = new TaxMergeMasterService().Get(payrolltypeid, (int)payrollType.TaxParamID,
|
|
EnumTaxMergeType.Bonus, row.BonusID);
|
|
if (mitem == null)
|
|
throw new ServiceException("Bonus head not found in the income tax Grouping");
|
|
|
|
IncomeTax bonusLine = taxLines.Find(y => y.ItemGroup == mitem.ItemGroup && y.ItemID == mitem.ItemID);
|
|
if (bonusLine == null)
|
|
throw new ServiceException("Income tax amount not found in the collection");
|
|
bonusLine.ThisMonthAmount = bonusAmount;
|
|
|
|
IncomeTax taxLine = taxLines.Find(y => y.ItemGroup == EnumIncomeTaxItemGroup.Tax_Deducted);
|
|
if (taxLine != null)
|
|
taxLine.ThisMonthAmount = changeTaxAmount;
|
|
}
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
|
|
BonusProcessDA.UpdateRowAmounts(tc, row.BonusProcessDetailID, bonusAmount, changeTaxAmount, taxAmount,
|
|
userID, DateTime.Now);
|
|
|
|
if (taxLines != null && taxLines.Count > 0)
|
|
{
|
|
IncomeTaxService taxService = new IncomeTaxService();
|
|
taxService.Delete(tc, row.EmployeeID.ToString(), EnumIncomeTaxDataFrom.BonusITTempData);
|
|
taxService.SaveBulk(tc, taxLines, EnumIncomeTaxDataFrom.BonusITTempData);
|
|
}
|
|
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
|
|
return this.GetGridRow(row.BonusProcessDetailID);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Remove (one saved row, deleted straight away)
|
|
|
|
/// <summary>
|
|
/// Remove button on a saved row: what the old Remove + Save left in the database (the employee simply
|
|
/// not saved), now deleted at once since Process already saved it — in one transaction:
|
|
/// - BONUSTEMPIT: this employee's rows (only when the process was saved with Calculate Tax);
|
|
/// - BonusEmpCostCenter: this employee's rows in this process;
|
|
/// - BONUSPROCESSDETAIL: the row;
|
|
/// - BONUSPROCESS: the header too, when that was the process's last employee.
|
|
/// Refused when the row is not found, not the current payroll type's, or the bonus is already approved
|
|
/// (the same checks as the Modify dialog). Rows not saved yet are removed in the browser only, as before.
|
|
/// </summary>
|
|
public BonusProcessRowRemoveResult RemoveRow(int bonusProcessDetailID, int payrolltypeid)
|
|
{
|
|
if (bonusProcessDetailID <= 0)
|
|
throw new ServiceException("Please select a bonus row.");
|
|
|
|
ModifyRow row = GetRowForModify(bonusProcessDetailID, payrolltypeid);
|
|
BonusProcessRowRemoveResult result = new BonusProcessRowRemoveResult
|
|
{
|
|
BonusProcessDetailID = row.BonusProcessDetailID,
|
|
BonusProcessID = row.BonusProcessID,
|
|
};
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
|
|
BonusProcessDA.DeleteRowBonusTempTax(tc, row.BonusProcessID, row.EmployeeID);
|
|
BonusProcessDA.DeleteRowCostCenter(tc, row.BonusProcessID, row.EmployeeID);
|
|
BonusProcessDA.DeleteRow(tc, row.BonusProcessDetailID);
|
|
|
|
if (BonusProcessDA.CountRows(tc, row.BonusProcessID) == 0)
|
|
{
|
|
BonusProcessDA.DeleteEmptyProcess(tc, row.BonusProcessID);
|
|
result.ProcessDeleted = true;
|
|
}
|
|
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Clear Tax (whole process, saved straight away)
|
|
|
|
/// <summary>
|
|
/// Bonus Process screen, "Clear Tax": what the old Clear Tax + Save did, now saved at once (there is no
|
|
/// Save button any more), for every employee of the process on the screen, in one transaction:
|
|
/// - BONUSPROCESSDETAIL: CHANGETAXAMOUNT = 0 (TAXAMOUNT, the calculated tax, is kept);
|
|
/// - BONUSTEMPIT: THISMONTHAMOUNT = 0 on the Tax Deducted line (-212) of those employees.
|
|
/// Refused when the process is not the current payroll type's or the bonus is already approved.
|
|
/// The old clearTax() (browser only) is kept as it was.
|
|
/// </summary>
|
|
public List<BonusProcessGridRow> ClearTaxAndSave(int bonusProcessID, int payrolltypeid, int userID)
|
|
{
|
|
if (bonusProcessID <= 0)
|
|
throw new ServiceException("Please process the bonus first.");
|
|
|
|
int bonusID = 0;
|
|
int processPayrollTypeID = 0;
|
|
DateTime bonusMonth = DateTime.MinValue;
|
|
bool found = false;
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader dr = new DataReader(BonusProcessDA.GetProcessHeaderForClearTax(tc, bonusProcessID));
|
|
if (dr.Read())
|
|
{
|
|
found = true;
|
|
bonusID = dr.GetInt32("BONUSID", 0);
|
|
bonusMonth = dr.GetDateTime("BONUSMONTH", DateTime.MinValue);
|
|
processPayrollTypeID = dr.GetInt32("PAYROLLTYPEID", 0);
|
|
}
|
|
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
|
|
}
|
|
|
|
if (!found)
|
|
throw new ServiceException("Bonus process not found. Please process the bonus again.");
|
|
if (processPayrollTypeID != payrolltypeid)
|
|
throw new ServiceException("This bonus process does not belong to the current payroll type.");
|
|
if (this.IsApproved(bonusID, bonusMonth, payrolltypeid))
|
|
throw new ServiceException("selected Bonus is already process and Approved");
|
|
|
|
tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
|
|
BonusProcessDA.ClearTaxOfProcess(tc, bonusProcessID, userID, DateTime.Now);
|
|
BonusProcessDA.ClearBonusTempTaxOfProcess(tc, bonusProcessID, (int)EnumIncomeTaxItemGroup.Tax_Deducted);
|
|
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
|
|
return this.GetGridRows(bonusProcessID);
|
|
}
|
|
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// Builds the employee cost-center split for every employee in the bonus process and
|
|
/// bulk-inserts it into BonusEmpCostCenter (mirrors the SalaryEmpCostCenter handling in
|
|
/// SalaryMonthlyService.SaveBulk). Runs inside the caller's transaction.
|
|
/// </summary>
|
|
private void SaveBonusEmpCostCenter(TransactionContext tc, BonusProcess oBonusProcess)
|
|
{
|
|
if (oBonusProcess.BonusProcessDetails == null || oBonusProcess.BonusProcessDetails.Count == 0)
|
|
return;
|
|
|
|
List<EmployeeCostCenter> allEmpCostCenters = new EmployeeCostCenterService().Get();
|
|
|
|
// Column names must match the BonusEmpCostCenter table exactly (case included) -
|
|
// SqlBulkCopy mapping is case-sensitive when the target DB collation is case-sensitive.
|
|
DataTable bonusCostCenterTable = new DataTable("BonusEmpCostCenter");
|
|
bonusCostCenterTable.Columns.Add(new DataColumn("BonusProcessID", typeof(int)));
|
|
bonusCostCenterTable.Columns.Add(new DataColumn("CostCenterID", typeof(int)));
|
|
bonusCostCenterTable.Columns.Add(new DataColumn("Percentage", typeof(double)));
|
|
bonusCostCenterTable.Columns.Add(new DataColumn("EmployeeID", typeof(int)));
|
|
|
|
foreach (BonusProcess.BonusProcessDetail oBonusProcessDetail in oBonusProcess.BonusProcessDetails)
|
|
{
|
|
List<EmployeeCostCenter> empInvolvements =
|
|
allEmpCostCenters.FindAll(x => x.EmployeeID == oBonusProcessDetail.EmployeeID);
|
|
|
|
foreach (EmployeeCostCenter oEmpCostCenter in empInvolvements)
|
|
{
|
|
bonusCostCenterTable.Rows.Add(
|
|
oBonusProcess.ID,
|
|
oEmpCostCenter.CostCenterID,
|
|
oEmpCostCenter.Percentage,
|
|
oBonusProcessDetail.EmployeeID);
|
|
}
|
|
}
|
|
|
|
if (bonusCostCenterTable.Rows.Count == 0)
|
|
return;
|
|
|
|
using (SqlBulkCopy bulkCopy = new SqlBulkCopy((SqlConnection)tc.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)tc.Transaction))
|
|
{
|
|
bulkCopy.BulkCopyTimeout = 6000; // in seconds
|
|
bulkCopy.ColumnMappings.Add("BonusProcessID", "BonusProcessID");
|
|
bulkCopy.ColumnMappings.Add("CostCenterID", "CostCenterID");
|
|
bulkCopy.ColumnMappings.Add("Percentage", "Percentage");
|
|
bulkCopy.ColumnMappings.Add("EmployeeID", "EmployeeID");
|
|
|
|
bulkCopy.DestinationTableName = "BonusEmpCostCenter";
|
|
bulkCopy.WriteToServer(bonusCostCenterTable);
|
|
}
|
|
}
|
|
|
|
public void Delete(BonusProcess oProcess)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
BonusProcessDA.UndoProcess(tc, oProcess);
|
|
if (oProcess.IsTaxProcess == true)
|
|
new IncomeTaxService().Delete(tc, oProcess.getEmpID(), EnumIncomeTaxDataFrom.BonusITTempData);
|
|
|
|
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 ApproveBonus(int bonusID, DateTime bonusMonth, int payrolltypeid)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
BonusProcessDA.ApproveBonus(tc, bonusID, bonusMonth);
|
|
List<IncomeTax> intx = new IncomeTaxService().Get(EnumIncomeTaxDataFrom.BonusITTempData, payrolltypeid);
|
|
if(intx != null && intx.Count >0)
|
|
{
|
|
new IncomeTaxService().Delete(tc, new IncomeTax().getEmpID(intx), EnumIncomeTaxDataFrom.ProcessTempData);
|
|
new IncomeTaxService().Delete(tc, new IncomeTax().getEmpID(intx), EnumIncomeTaxDataFrom.BonusITTempData);
|
|
new IncomeTaxService().SaveBulk(tc, intx, EnumIncomeTaxDataFrom.ProcessTempData);
|
|
}
|
|
|
|
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 ApproveBonusNew(int bonusID, DateTime bonusMonth, int payrolltypeid, int currentEmployeeID)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
BonusProcess oBonusProcess = Get(tc, bonusID, bonusMonth, payrolltypeid);
|
|
if (oBonusProcess != null && oBonusProcess.wfstatus == null )
|
|
{
|
|
oBonusProcess.wfstatus = enumwfStatus.Not_yet_Initiated;
|
|
BonusProcessDA.ApproveBonusNew(tc, oBonusProcess);
|
|
}
|
|
if (oBonusProcess != null && oBonusProcess.wfstatus != null && oBonusProcess.wfstatus == enumwfStatus.Not_yet_Initiated)
|
|
{
|
|
Bonus oBonus = new BonusService().Get(tc, oBonusProcess.BonusID);
|
|
string bonusMonthString = oBonusProcess.BonusMonth != null ? oBonusProcess.BonusMonth.Value.ToString("MMMM yyyy") : "";
|
|
string subject = "Bonus process (" + oBonus.Name + ") for month - " + bonusMonthString + ". Your Approval is required.";
|
|
WFManager<IworkflowInterface> om = new WFManager<IworkflowInterface>(oBonusProcess);
|
|
om.InitiateProcess(tc, currentEmployeeID, oBonusProcess.SetupID, oBonusProcess.ID, "", subject);
|
|
}
|
|
//BonusProcessDA.ApproveBonus(tc, bonusID, bonusMonth);
|
|
//List<IncomeTax> intx = new IncomeTaxService().Get(EnumIncomeTaxDataFrom.BonusITTempData, payrolltypeid);
|
|
//if (intx != null && intx.Count > 0)
|
|
//{
|
|
// new IncomeTaxService().Delete(tc, new IncomeTax().getEmpID(intx), EnumIncomeTaxDataFrom.ProcessTempData);
|
|
// new IncomeTaxService().Delete(tc, new IncomeTax().getEmpID(intx), EnumIncomeTaxDataFrom.BonusITTempData);
|
|
// new IncomeTaxService().SaveBulk(tc, intx, EnumIncomeTaxDataFrom.ProcessTempData);
|
|
//}
|
|
|
|
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 ApproveBonusNew(WFMovementTran WFMovementTran)
|
|
{
|
|
TransactionContext tc = null;
|
|
BonusProcess oBonusProcess = new BonusProcess();
|
|
Bonus oBonus = new Bonus(); ;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
oBonusProcess = Get(tc,WFMovementTran.ObjectID);
|
|
oBonus = new BonusService().Get(tc, oBonusProcess.BonusID);
|
|
|
|
string bonusMonthString = oBonusProcess.BonusMonth != null ? oBonusProcess.BonusMonth.Value.ToString("MMMM yyyy") : "";
|
|
string approveString = "Bonus process (" + oBonus.Name + ") for month - " + bonusMonthString + " has approved.";
|
|
WFMovementTran newTran = new WFManager<IworkflowInterface>().Approve(tc, WFMovementTran.ID, WFMovementTran.FromEmployeeID, WFMovementTran.Remarks, approveString);
|
|
|
|
if (newTran.Status == EnumwfStatus.End)
|
|
{
|
|
oBonusProcess.wfstatus = enumwfStatus.Approve;
|
|
oBonusProcess.IsApprove = true;
|
|
BonusProcessDA.ApproveBonusNew(tc, oBonusProcess);
|
|
List<IncomeTax> intx = new IncomeTaxService().Get(EnumIncomeTaxDataFrom.BonusITTempData, oBonusProcess.PayrollTypeID);
|
|
if (intx != null && intx.Count > 0)
|
|
{
|
|
new IncomeTaxService().Delete(tc, new IncomeTax().getEmpID(intx), EnumIncomeTaxDataFrom.ProcessTempData);
|
|
new IncomeTaxService().Delete(tc, new IncomeTax().getEmpID(intx), EnumIncomeTaxDataFrom.BonusITTempData);
|
|
new IncomeTaxService().SaveBulk(tc, intx, EnumIncomeTaxDataFrom.ProcessTempData);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
oBonusProcess.wfstatus = enumwfStatus.Not_yet_Initiated;
|
|
BonusProcessDA.ApproveBonusNew(tc, oBonusProcess);
|
|
}
|
|
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 BonusProcessRevert(WFMovementTran revertTran, string remarks)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
Employee oFromEmployee = new EmployeeService().Get(revertTran.FromEmployeeID);
|
|
|
|
tc = TransactionContext.Begin(true);
|
|
BonusProcess oBonusProcess = Get(tc, revertTran.ObjectID);
|
|
Bonus oBonus = new BonusService().Get(tc, oBonusProcess.BonusID);
|
|
|
|
string bonusMonthString = oBonusProcess.BonusMonth != null ? oBonusProcess.BonusMonth.Value.ToString("MMMM yyyy") : "";
|
|
string revertString = "(" + oFromEmployee.EmployeeNo + ")-" + oFromEmployee.Name + ", has revert bonus process (" + oBonus.Name + ") for month - " + bonusMonthString;
|
|
|
|
revertTran.Remarks = !string.IsNullOrEmpty(remarks) ? remarks : "";
|
|
new WFManager<IworkflowInterface>().RevertNew(tc, revertTran.ID, revertTran.FromEmployeeID, revertTran.Remarks, revertString);
|
|
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 IsApproved(int bonusID, DateTime bonusMonth, int payrolltypeid)
|
|
{
|
|
TransactionContext tc = null;
|
|
bool isApproved = false;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
isApproved =BonusProcessDA.IsApproved(tc, payrolltypeid, bonusID, bonusMonth);
|
|
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
return isApproved;
|
|
}
|
|
|
|
|
|
public DataTable GetUnApprovedBonuses(DateTime dMonthDate, int payrollTypeID)
|
|
{
|
|
DataTable ot = null;
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
ot = BonusProcessDA.GetUnApprovedBonuses(tc, dMonthDate, 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 ot;
|
|
}
|
|
|
|
public DataTable GetUnApprovedBonuses(int bonusProcessID)
|
|
{
|
|
DataTable ot = null;
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
ot = BonusProcessDA.GetUnApprovedBonuses(tc, bonusProcessID);
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
return ot;
|
|
}
|
|
|
|
public DataTable GetAllBonuses(int bonusProcessID)
|
|
{
|
|
DataTable ot = null;
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
ot = BonusProcessDA.GetAllBonuses(tc, bonusProcessID);
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
return ot;
|
|
}
|
|
|
|
public double GetBonusAmount(DateTime bonusMonthFirstDate, int employeeID, int bonusID)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public double GetBonusAmountWithinYear(DateTime bonusYearDate, int employeeID, int bonusID)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public double GetUsedBonusWithinYear(DateTime bonusYearDate, int bonusID)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public BonusProcess CalculateBonus(int payrolltypeid, List<Employee> employees, int bonusid, DateTime dBasicMonth,
|
|
DateTime dPayDate, DateTime dCuttOfDate, double CurrProcess, bool IsDisburseWithSalary, bool IsTaxProcess)
|
|
{
|
|
return new BonusCalculator().CalCulate(payrolltypeid, employees, bonusid, dBasicMonth,
|
|
dPayDate, dCuttOfDate, CurrProcess, IsDisburseWithSalary, IsTaxProcess);
|
|
}
|
|
|
|
|
|
public List< BonusProcess.BonusProcessDetail> CalculateBonusTax(List<BonusProcess.BonusProcessDetail> bonusDetails,
|
|
List<Employee> employees, int bonusid, int payrolltypeid)
|
|
{
|
|
|
|
Bonus obonus = new BonusService().Get(bonusid);
|
|
new BonusCalculator().CalculateTax(bonusDetails, employees, obonus, payrolltypeid);
|
|
|
|
return bonusDetails;
|
|
}
|
|
|
|
public void UndoBonusProcess(BonusProcess bonusProcess)
|
|
{
|
|
try
|
|
{
|
|
bonusProcess = new BonusProcessService().Get(bonusProcess.ID);
|
|
if(bonusProcess.IsApprove ==true)
|
|
{
|
|
throw new Exception("Approved Bonus is not allowed to delete.");
|
|
}
|
|
|
|
this.Delete(bonusProcess);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new Exception(ex.Message);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
public int GetForNoOfPaid(DateTime bonusYear, int bonusID)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public BonusProcess Get(int bonusID, DateTime bonusMonth)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public List<BonusProcess.BonusProcessDetail> GetBonusDetails(int payrolltypeid, int bonusid, DateTime dMonth)
|
|
{
|
|
List<BonusProcess.BonusProcessDetail> bonusProcessDetails = null;
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(BonusProcessDA.GetBonusDetails(tc, payrolltypeid, bonusid, dMonth));
|
|
bonusProcessDetails = this.CreateBonusProcessDetailObject(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 bonusProcessDetails;
|
|
}
|
|
|
|
public List<BonusProcess.BonusProcessDetail> GetSumOfBonusDetails(DateTime fromMonth, DateTime toDate)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public DataSet GetBonusRegisterNew(int BonusID, DateTime dBonusMonth, string sEmpID, int payrolltypeid)
|
|
{
|
|
DataSet oBonusRegisters = new DataSet();
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
oBonusRegisters = BonusProcessDA.GetBonusRegisterNew(tc, BonusID, dBonusMonth, sEmpID, 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 oBonusRegisters;
|
|
}
|
|
|
|
public DataSet GetBonusBankAdvice(int BonusID, DateTime dBonusMonth, string sEmpID)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public DataSet GetBonusPaySlip(int BonusID, DateTime dBonusMonth, string sEmpID)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public List<BonusProcess> GetProcess(int bonusID, DateTime bonusMonth)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public List<BonusProcess> GetProcess(DateTime bonusMonth)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public int GetForNoOfPaidForEmp(DateTime bonusYearDate, int bonusID, int empId)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
|
|
#endregion
|
|
} |