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; using System.Data.SqlClient; namespace Payroll.Service { #region BonusProcess Service [Serializable] public class BonusProcessService : ServiceTemplate, IBonusProcessService { #region Private functions and declaration Cache _cache = new Cache(typeof(BonusProcess)); private int _crgSerialId; private int _processID = 0; private int _detailID = 0; string _sConnectionName = ""; #endregion public BonusProcessService() { _crgSerialId = 0; } private void MapObject(BonusProcess oBonusProcess, DataReader oReader) { base.SetObjectID(oBonusProcess, oReader.GetID("BonusProcessID")); oBonusProcess.BonusID = oReader.GetID("bonusID"); oBonusProcess.BonusMonth = oReader.GetDateTime("bonusMonth").Value; oBonusProcess.BasicOnMonth = oReader.GetDateTime("basicOnMonth").Value; oBonusProcess.DisburseDate = oReader.GetDateTime("disburseDate").Value; 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.GetID("CreatedBy"); oBonusProcess.CreatedDate = oReader.GetDateTime("creationDate").Value; oBonusProcess.ModifiedBy = oReader.GetID("ModifiedBy"); oBonusProcess.ModifiedDate = oReader.GetDateTime("ModifiedDate"); oBonusProcess.UsedProcess = oReader.GetInt32("UsedProcess").Value; oBonusProcess.FestivalDate =oReader.GetDateTime("FestivalDate")==null?DateTime.MinValue: oReader.GetDateTime("FestivalDate").Value; oBonusProcess.ReligionID = oReader.GetID("ReligionID"); this.SetObjectState(oBonusProcess, Ease.CoreV35.ObjectState.Saved); } protected override T CreateObject(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.GetID("BonusProcessDetailID")); oBonusPDetail.BonusProcessID = oReader.GetID("bonusProcessID"); oBonusPDetail.BonusID = oReader.GetID("bonusID"); oBonusPDetail.EmployeeID = oReader.GetID("employeeID"); oBonusPDetail.BonusMonth = oReader.GetDateTime("disburseDate").Value; oBonusPDetail.BonusAmount = oReader.GetDouble("BonusAmount").Value; oBonusPDetail.BasicSalary = oReader.GetDouble("BasicSalary").Value; 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.GetID("ModifiedBy"); oBonusPDetail.ModifiedDate = oReader.GetDateTime("ModifiedDate").HasValue ? oReader.GetDateTime("ModifiedDate").Value : (DateTime?)null; this.SetObjectState(oBonusPDetail, Ease.CoreV35.ObjectState.Saved); } private void MapBonusProDetailAdjObject(BonusProcess.BonusProcessDetail.BonusProcessAdjustItem oBonusPAdj, DataReader oReader) { oBonusPAdj.BonusProcessDetailID = oReader.GetID("BonusProcessDetailID"); oBonusPAdj.BonusAdjustID = oReader.GetInt32("BonusAdjustID").Value; //oBonusPAdj.Side = (EnumTranSide)oReader.GetInt32("Side").Value; oBonusPAdj.AdjustAmount = oReader.GetDouble("AdjustAmount").Value; //this.SetObjectState(oBonusPAdj, Ease.CoreV35.ObjectState.Saved); } protected ObjectsTemplate CreateBonusProcessAdj(DataReader oReader) { ObjectsTemplate oBonusProAdjs = new ObjectsTemplate(); while (oReader.Read()) { BonusProcess.BonusProcessDetail.BonusProcessAdjustItem oBonusProAdj = new BonusProcess.BonusProcessDetail.BonusProcessAdjustItem(); MapBonusProDetailAdjObject(oBonusProAdj, oReader); oBonusProAdjs.Add(oBonusProAdj); } return oBonusProAdjs; } protected ObjectsTemplate CreateBonusProcessDetailObject(DataReader oReader) { ObjectsTemplate oBonusProDetails = new ObjectsTemplate(); 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.GetID("bonusID"); oBonusPDetail.EmployeeID = oReader.GetID("employeeID"); oBonusPDetail.ChangeBonusAmount = oReader.GetDouble("BonusAmount").Value; oBonusPDetail.ChangeSalaryItemAmount = oReader.GetDouble("Count").Value; this.SetObjectState(oBonusPDetail, Ease.CoreV35.ObjectState.Saved); } protected ObjectsTemplate CreateBonusProcessDetailCumalativeObject(DataReader oReader) { ObjectsTemplate oBonusProDetails = new ObjectsTemplate(); 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, ID employeeID, int bonusID, ID 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 ObjectsTemplate GetProcess(ID PayrollTypeID) { #region Cache Header ObjectsTemplate bonusProcesss = _cache["GetProcess"] as ObjectsTemplate; if (bonusProcesss != null) return bonusProcesss; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(BonusProcessDA.GetProcess(tc, PayrollTypeID)); bonusProcesss = this.CreateObjects(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(bonusProcesss, "GetProcess"); #endregion return bonusProcesss; } public ObjectsTemplate GetProcess(ID nBonusID, DateTime dBonusMonth, ID PayrollTypeID) { #region Cache Header ObjectsTemplate bonusProcesss = _cache["GetProcess", nBonusID, dBonusMonth] as ObjectsTemplate; if (bonusProcesss != null) return bonusProcesss; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(BonusProcessDA.GetProcess(tc, nBonusID, dBonusMonth, PayrollTypeID)); bonusProcesss = this.CreateObjects(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(bonusProcesss, "GetProcess", dBonusMonth); #endregion return bonusProcesss; } public double GetUsedBonusWithinYear(DateTime bonusMonthFirstDate,int bonusID, ID 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, ID employeeID, int bonusID, ID 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 double GetBonusPaidAmount(DateTime date1, DateTime date2, ID employeeID, int bonusID) { double bonusAmount = 0; TransactionContext tc = null; try { tc = TransactionContext.Begin(); bonusAmount = BonusProcessDA.GetBonusPaidAmount(tc, date1, date2, employeeID, bonusID); 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 double GetBonusAmountWithinYear(DateTime bonusYearDate, ID employeeID, int bonusID, ID PayrollTypeID,int nRelogionID) { double bonusAmount = 0; TransactionContext tc = null; try { tc = TransactionContext.Begin(); bonusAmount = BonusProcessDA.GetBonusAmountWithinYear(tc, bonusYearDate, employeeID, bonusID, PayrollTypeID, nRelogionID); 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 double GetKPIBonusAmountWithinYear(DateTime bonusYearDate, ID employeeID, int bonusID, ID PayrollTypeID, int nRelogionID) { double bonusAmount = 0; TransactionContext tc = null; try { tc = TransactionContext.Begin(); bonusAmount = BonusProcessDA.GetKPIBonusAmountWithinYear(tc, bonusYearDate, employeeID, bonusID, PayrollTypeID, nRelogionID); 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 double GetKPIBonusAmountWithinYearPercent(DateTime bonusYearDate, ID employeeID, int bonusID, ID PayrollTypeID, int nRelogionID) { double bonusAmount = 0; TransactionContext tc = null; try { tc = TransactionContext.Begin(); bonusAmount = BonusProcessDA.GetKPIBonusAmountWithinYearPercent(tc, bonusYearDate, employeeID, bonusID, PayrollTypeID, nRelogionID); 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 double GetPreviousKPIBonusAmount(ID employeeID, int bonusID, string bonusProcessIDs, ID PayrollTypeID) { double bonusAmount = 0; TransactionContext tc = null; try { tc = TransactionContext.Begin(); bonusAmount = BonusProcessDA.GetPreviousKPIBonusAmount(tc, employeeID, bonusID, bonusProcessIDs, 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(ID id, ID PayrollTypeID) { BonusProcess oBonusProcess = new BonusProcess(); #region Cache Header oBonusProcess = _cache["Get", id] as BonusProcess; if (oBonusProcess != null) return oBonusProcess; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(BonusProcessDA.Get(tc, id, PayrollTypeID)); if (oreader.Read()) { oBonusProcess = this.CreateObject(oreader); } oreader.Close(); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } #region Cache Footer _cache.Add(oBonusProcess, "Get", id); #endregion return oBonusProcess; } public ObjectsTemplate Get(EnumStatus status, ID PayrollTypeID) { #region Cache Header ObjectsTemplate bonusProcesss = _cache["Get",status] as ObjectsTemplate; if (bonusProcesss != null) return bonusProcesss; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(BonusProcessDA.Get(tc,status, PayrollTypeID)); bonusProcesss = this.CreateObjects(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(bonusProcesss, "Get",status); #endregion return bonusProcesss; } public int GetForNoOfPaidForEmp(DateTime bonusMonthFirstDate, int bonusID,int empid, ID 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, ID 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 ObjectsTemplate GetBonusDetails(ID processID, ID PayrollTypeID) { #region Cache Header ObjectsTemplate bonusProcessDetails = _cache["GetBonusDetails", processID] as ObjectsTemplate; if (bonusProcessDetails != null) return bonusProcessDetails; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(BonusProcessDA.GetBonusDetails(tc, processID, 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 } #region Cache Footer _cache.Add(bonusProcessDetails, "GetBonusDetails", processID); #endregion return bonusProcessDetails; } public BonusProcess Get(ID bonusID,DateTime dBonusMonth, ID PayrollTypeID) { BonusProcess oProcess=null; //bjectsTemplate oBonusProcessAdjustItems = null; //ObjectsTemplate 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(dr); } dr.Close(); if (oProcess != null) { dr = new DataReader(BonusProcessDA.GetBonusDetails(tc, oProcess.ID, PayrollTypeID)); 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 } #region Cache Footer _cache.Add(oProcess, "GetBonusDetailsByBonID", bonusID); #endregion return oProcess; } public BonusProcess Get(ID bonusID, DateTime dBonusMonth, ID PayrollTypeID,int nQuarterID) { BonusProcess oProcess = null; //bjectsTemplate oBonusProcessAdjustItems = null; //ObjectsTemplate oBonusProcessSalaryItems = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(BonusProcessDA.Get(tc, bonusID, dBonusMonth, PayrollTypeID,nQuarterID)); if (dr.Read()) { oProcess = this.CreateObject(dr); } dr.Close(); if (oProcess != null) { dr = new DataReader(BonusProcessDA.GetBonusDetails(tc, oProcess.ID, PayrollTypeID)); 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 } #region Cache Footer _cache.Add(oProcess, "GetBonusDetailsByBonID", bonusID); #endregion return oProcess; } public ObjectsTemplate GetProcess(DateTime dBonusMonth, ID PayrollTypeId) { #region Cache Header ObjectsTemplate bonusProcesss = _cache["GetProcess", dBonusMonth] as ObjectsTemplate; if (bonusProcesss != null) return bonusProcesss; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(BonusProcessDA.GetProcess(tc, dBonusMonth, PayrollTypeId)); bonusProcesss = this.CreateObjects(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(bonusProcesss, "GetProcess", dBonusMonth); #endregion return bonusProcesss; } public ObjectsTemplate GetProcess(DateTime fromMonth, DateTime toDate, ID religionID, ID bonusID,int payrollTypeID) { #region Cache Header ObjectsTemplate bonusProcesss = new ObjectsTemplate(); if (bonusProcesss != null) return bonusProcesss; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(BonusProcessDA.GetProcess(tc, fromMonth, toDate, religionID, bonusID,payrollTypeID)); bonusProcesss = this.CreateObjects(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 ObjectsTemplate GetBonusDetails(DateTime dMonth, ID PayrollTypeID) { #region Cache Header ObjectsTemplate bonusProcessDetails = _cache["GetBonusDetails", dMonth] as ObjectsTemplate; if (bonusProcessDetails != null) return bonusProcessDetails; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(BonusProcessDA.GetBonusDetails(tc, dMonth, 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 } #region Cache Footer _cache.Add(bonusProcessDetails, "GetBonusDetails", dMonth); #endregion return bonusProcessDetails; } public ObjectsTemplate GetBonusDetails(int nID) { #region Cache Header ObjectsTemplate bonusProcessDetails = _cache["GetBonusDetails", nID] as ObjectsTemplate; if (bonusProcessDetails != null) return bonusProcessDetails; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(BonusProcessDA.GetBonusDetails(tc, nID)); 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 } #region Cache Footer _cache.Add(bonusProcessDetails, "GetBonusDetails", nID); #endregion return bonusProcessDetails; } public ObjectsTemplate GetSumOfBonusDetails(DateTime fromMonth, DateTime toMonth, ID PayRollTypeID) { #region Cache Header ObjectsTemplate bonusProcessDetails = _cache["GetSumOfBonusDetails", fromMonth, toMonth] as ObjectsTemplate; if (bonusProcessDetails != null) return bonusProcessDetails; #endregion 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 } #region Cache Footer _cache.Add(bonusProcessDetails, "GetSumOfBonusDetails", fromMonth, toMonth); #endregion return bonusProcessDetails; } public ObjectsTemplate GetBonusDetails(DateTime dMonth,bool bPayWithalary, ID PayrollTypeID) { #region Cache Header ObjectsTemplate bonusProcessDetails = _cache["GetBonusDetails", dMonth, bPayWithalary] as ObjectsTemplate; if (bonusProcessDetails != null) return bonusProcessDetails; #endregion 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 } #region Cache Footer _cache.Add(bonusProcessDetails, "GetBonusDetails", dMonth, bPayWithalary); #endregion return bonusProcessDetails; } public ObjectsTemplate GetBonusDetails(DateTime dMonth, bool bPayWithalary, ID PayrollTypeID,int nEmpID) { #region Cache Header ObjectsTemplate bonusProcessDetails = _cache["GetBonusDetails", dMonth, bPayWithalary] as ObjectsTemplate; if (bonusProcessDetails != null) return bonusProcessDetails; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(BonusProcessDA.GetBonusDetails(tc, dMonth, bPayWithalary, PayrollTypeID,nEmpID)); 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 } #region Cache Footer _cache.Add(bonusProcessDetails, "GetBonusDetails", dMonth, bPayWithalary); #endregion return bonusProcessDetails; } public ObjectsTemplate GetBonusDetails(DateTime dMonth, int nEmpID, int nBonusID) { #region Cache Header ObjectsTemplate bonusProcessDetails = _cache["GetBonusDetails", dMonth] as ObjectsTemplate; if (bonusProcessDetails != null) return bonusProcessDetails; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(BonusProcessDA.GetBonusDetails(tc, dMonth, nEmpID, nBonusID)); 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 } #region Cache Footer _cache.Add(bonusProcessDetails, "GetBonusDetails", dMonth); #endregion return bonusProcessDetails; } //public ObjectsTemplate GetBProcessAdjust(ID processDetailID) //{ // #region Cache Header // ObjectsTemplate bonusProcessAdjustItems = _cache["GetBProcessAdjust", processDetailID] as ObjectsTemplate; // 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 GetBonusRegisterCarFuel ( DateTime dBonusMonth, string sEmpID) { DataSet oBonusRegisters = new DataSet(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); oBonusRegisters = BonusProcessDA.GetBonusRegisterCarFuel (tc, dBonusMonth, 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 oBonusRegisters; } public DataSet GetBonusRegister(ID bonusID,DateTime dBonusMonth, string sEmpID, ID 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(ID bonusID, DateTime dBonusMonth, string sEmpID, ID 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 GetBonusPaySlip(ID bonusID, DateTime dBonusMonth, string sEmpID, ID 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 DataSet GetOldBonusPaySlip(ID bonusID, DateTime dBonusMonth, string sEmpID, ID PayrollTypeID) { DataSet oBonusBankSlip = new DataSet(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); oBonusBankSlip = BonusProcessDA.GetOldBonusPaySlip(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 DataSet GetOldBonusRegister(ID bonusID, DateTime dBonusMonth, string sEmpID, ID PayrollTypeID) { DataSet oldBonusRegisters = new DataSet(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); oldBonusRegisters = BonusProcessDA.GetOldBonusRegister(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 oldBonusRegisters; } public ID Save(BonusProcess oBonusProcess, ID PayrollTypeID) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oBonusProcess.IsNew) { int id = tc.GenerateID("BONUSPROCESS", "BONUSPROCESSID"); base.SetObjectID(oBonusProcess, ID.FromInteger(id)); BonusProcessDA.Insert(tc, oBonusProcess, PayrollTypeID); } else { BonusProcessDA.Update(tc, oBonusProcess); //BonusProcessDA.DeletePAdjustItemByProcessDetailID(tc,oBonusProcess.ID); //BonusProcessDA.DeletePSalaryItemByProcessDetailID(tc, oBonusProcess.ID); BonusProcessDA.DeleteProcessDetailByProcessID(tc, oBonusProcess.BonusID, oBonusProcess.ID, PayrollTypeID); //BonusProcessDA.DeleteSalaryEmpCC(tc, oBonusProcess.ID); } int id2 = tc.GenerateID("BONUSPROCESSDETAIL", "BonusProcessDetailID"); foreach (BonusProcess.BonusProcessDetail oBonusProcessDetail in oBonusProcess.BonusProcessDetails) { // int id = tc.GenerateID("BONUSPROCESSDETAIL", "BonusProcessDetailID"); id2++; base.SetObjectID(oBonusProcessDetail, ID.FromInteger(id2)); 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) osvr.Save(tc, oBonusProcessDetail.IncomeTaxcoll, EnumIncomeTaxDataFrom.ProcessTempData); #region Bonus Process AdjustItem //if (oBonusProcessDetail.BonusProcessAdjustItems != null) //{ // foreach (BonusProcess.BonusProcessDetail.BonusProcessAdjustItem oBonusAdjustItem in oBonusProcessDetail.BonusProcessAdjustItems) // { // //int adjustid = tc.GenerateID("BonusProcessAdjustItem", "BonusAdjustID"); // //base.SetObjectID(oBonusAdjustItem, ID.FromInteger(adjustid)); // oBonusAdjustItem.BonusProcessDetailID = oBonusProcessDetail.ID; // BonusProcessDA.Insert(tc, oBonusAdjustItem); // } //} #endregion } 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 } } public void BulkSave(BonusProcess process) { TransactionContext tc = null; DataTable processTable = new DataTable("BONUSPROCESS"); processTable.Columns.Add(new DataColumn("BONUSID", typeof(int))); processTable.Columns.Add(new DataColumn("CreatedBy", typeof(int))); processTable.Columns.Add(new DataColumn("BONUSMONTH", typeof(DateTime))); processTable.Columns.Add(new DataColumn("DISBURSEDATE", typeof(DateTime))); processTable.Columns.Add(new DataColumn("BONUSPROCESSID", typeof(int))); processTable.Columns.Add(new DataColumn("CreationDate", typeof(DateTime))); processTable.Columns.Add(new DataColumn("ModifiedBy", typeof(int))); processTable.Columns.Add(new DataColumn("ModifiedDate", typeof(DateTime))); processTable.Columns.Add(new DataColumn("BasicOnMonth", typeof(DateTime))); processTable.Columns.Add(new DataColumn("Remarks", typeof(string))); processTable.Columns.Add(new DataColumn("ShowInWeb", typeof(int))); processTable.Columns.Add(new DataColumn("IsDisbursewithSalary", typeof(int))); processTable.Columns.Add(new DataColumn("IsTaxProcess", typeof(int))); processTable.Columns.Add(new DataColumn("UsedProcess", typeof(double))); processTable.Columns.Add(new DataColumn("PayrollTypeID", typeof(int))); processTable.Columns.Add(new DataColumn("BatchNo", typeof(string))); processTable.Columns.Add(new DataColumn("FestivalDate", typeof(DateTime))); processTable.Columns.Add(new DataColumn("RELIGIONID", typeof(int))); DataTable detailTable = new DataTable("BONUSPROCESSDETAIL"); detailTable.Columns.Add(new DataColumn("BonusProcessID", typeof(int))); detailTable.Columns.Add(new DataColumn("BonusID", typeof(int))); detailTable.Columns.Add(new DataColumn("EmployeeID", typeof(int))); detailTable.Columns.Add(new DataColumn("DisburseDate", typeof(DateTime))); detailTable.Columns.Add(new DataColumn("BonusAmount", typeof(double))); detailTable.Columns.Add(new DataColumn("BasicSalary", typeof(double))); detailTable.Columns.Add(new DataColumn("ChangeBonusAmount", typeof(double))); detailTable.Columns.Add(new DataColumn("TaxAmount", typeof(double))); detailTable.Columns.Add(new DataColumn("ChangeTaxAmount", typeof(double))); detailTable.Columns.Add(new DataColumn("CalculatedAdjustAmount", typeof(double))); detailTable.Columns.Add(new DataColumn("ChangeAdjustAmount", typeof(double))); detailTable.Columns.Add(new DataColumn("calculatedSalaryItemAmount", typeof(double))); detailTable.Columns.Add(new DataColumn("ChangeSalaryItemAmount", typeof(double))); detailTable.Columns.Add(new DataColumn("BonusProcessDetailID", typeof(int))); detailTable.Columns.Add(new DataColumn("ModifiedBy", typeof(int))); detailTable.Columns.Add(new DataColumn("ModifiedDate", typeof(DateTime))); DataTable taxTable = new DataTable("INCOMETAXTEMP"); taxTable.Columns.Add(new DataColumn("EMPLOYEEID", typeof(int))); taxTable.Columns.Add(new DataColumn("ITEMCODE", typeof(int))); taxTable.Columns.Add(new DataColumn("ItemId", typeof(int))); taxTable.Columns.Add(new DataColumn("DESCRIPTION", typeof(string))); taxTable.Columns.Add(new DataColumn("THISYEARTOTAL", typeof(double))); taxTable.Columns.Add(new DataColumn("PREVIOUSAMOUNT", typeof(double))); taxTable.Columns.Add(new DataColumn("THISMONTHAMOUNT", typeof(double))); taxTable.Columns.Add(new DataColumn("PROJECTEDAMOUNT", typeof(double))); taxTable.Columns.Add(new DataColumn("SIDE", typeof(int))); taxTable.Columns.Add(new DataColumn("POSITION", typeof(int))); taxTable.Columns.Add(new DataColumn("ModifiedBy", typeof(int))); taxTable.Columns.Add(new DataColumn("ModifiedDate", typeof(DateTime))); taxTable.Columns.Add(new DataColumn("HeadID", typeof(int))); try { tc = TransactionContext.Begin(); _processID = tc.GenerateID("BONUSPROCESS", "BONUSPROCESSID"); _detailID = tc.GenerateID("BONUSPROCESSDETAIL", "BonusProcessDetailID"); if (process.IsTaxProcess == true) { string sEmpIDs = ""; try { tc.ExecuteNonQuery("IF OBJECT_ID ('incometaxtempbackup_" + _processID.ToString() + "') IS NOT NULL Drop table incometaxtempbackup_" + _processID.ToString()); } catch { } try { tc.ExecuteNonQuery("Select * into incometaxtempbackup_" + _processID.ToString() + " from incometaxtemp "); } catch { } foreach (BonusProcess.BonusProcessDetail item in process.BonusProcessDetails) { sEmpIDs += item.EmployeeID.Integer.ToString() + ","; } if (sEmpIDs.Length > 0) sEmpIDs = sEmpIDs.Trim(','); BonusProcessDA.DeleteTax(tc, sEmpIDs); } _sConnectionName = tc.Connection.ConnectionString; processTable.Rows.Add(process.BonusID.Integer, process.CreatedBy.Integer, process.BonusMonth, process.DisburseDate, _processID, process.CreatedDate, process.ModifiedBy == null ? 1 : process.ModifiedBy.Integer, DateTime.Today, process.BasicOnMonth, process.Remarks, Convert.ToInt16(process.ShowInWeb), Convert.ToInt16(process.IsDisburseWithSalary), Convert.ToInt16(process.IsTaxProcess), process.UsedProcess, Payroll.BO.SystemInformation.CurrentSysInfo.PayrollTypeID.Integer, "",//batch no process.BonusMonth, process.ReligionID == null ? 1 : process.ReligionID.Integer); foreach (BonusProcess.BonusProcessDetail item in process.BonusProcessDetails) { detailTable.Rows.Add(_processID, process.BonusID.Integer, item.EmployeeID.Integer, item.BonusMonth, item.BonusAmount, item.BasicSalary, item.ChangeBonusAmount, item.TaxAmount, item.ChangeTaxAmount, item.CalculatedAdjustAmount, item.ChangeAdjustAmount, item.CalculatedSalaryItemAmount, item.ChangeSalaryItemAmount, _detailID, item.ModifiedBy == null ? 1 : process.ModifiedBy.Integer, DateTime.Today); if (item.IncomeTaxcoll != null) { foreach (IncomeTax tax in item.IncomeTaxcoll) { tax.ModifiedBy = process.CreatedBy;// User.CurrentUser.ID; tax.ModifiedDate = DateTime.Now; taxTable.Rows.Add(tax.EmployeeID.Integer, tax.ItemGroup, tax.ItemID, tax.Description, double.IsNaN(tax.TotalAmount) ? 0 : tax.TotalAmount, double.IsNaN(tax.PreviousAmount) ? 0 : tax.PreviousAmount, double.IsNaN(tax.ThisMonthAmount) ? 0 : tax.ThisMonthAmount, double.IsNaN(tax.ProjectedAmount) ? 0 : tax.ProjectedAmount, (int)tax.Side, tax.Position, tax.ModifiedBy.Integer, tax.ModifiedDate, 1); } } _detailID++; } using (SqlBulkCopy bulkCopy = new SqlBulkCopy((SqlConnection)tc.Connection)) { bulkCopy.BulkCopyTimeout = 600; // in seconds bulkCopy.DestinationTableName = "BONUSPROCESS"; bulkCopy.WriteToServer(processTable); bulkCopy.DestinationTableName = "BONUSPROCESSDetail"; bulkCopy.WriteToServer(detailTable); if (process.IsTaxProcess == true) { bulkCopy.DestinationTableName = "INCOMETAXTEMP"; bulkCopy.WriteToServer(taxTable); } } tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public ObjectsTemplate GetBProcessAdjust(ID processDetailID) { #region Cache Header ObjectsTemplate bonusProcessAdjustItems = _cache["GetBProcessAdjust", processDetailID] as ObjectsTemplate; if (bonusProcessAdjustItems != null) return bonusProcessAdjustItems; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(BonusProcessDA.GetBProcessAdjust(tc, processDetailID)); bonusProcessAdjustItems = this.CreateBonusProcessAdj(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 void Delete(BonusProcess oProcess, ID PayrollTypeID) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); //DataTable taxTable = new DataTable("INCOMETAXTEMP"); //taxTable.Columns.Add(new DataColumn("EMPLOYEEID", typeof(int))); //taxTable.Columns.Add(new DataColumn("ITEMCODE", typeof(int))); //taxTable.Columns.Add(new DataColumn("ItemId", typeof(int))); //taxTable.Columns.Add(new DataColumn("DESCRIPTION", typeof(string))); //taxTable.Columns.Add(new DataColumn("THISYEARTOTAL", typeof(double))); //taxTable.Columns.Add(new DataColumn("PREVIOUSAMOUNT", typeof(double))); //taxTable.Columns.Add(new DataColumn("THISMONTHAMOUNT", typeof(double))); //taxTable.Columns.Add(new DataColumn("PROJECTEDAMOUNT", typeof(double))); //taxTable.Columns.Add(new DataColumn("SIDE", typeof(int))); //taxTable.Columns.Add(new DataColumn("POSITION", typeof(int))); //taxTable.Columns.Add(new DataColumn("ModifiedBy", typeof(int))); //taxTable.Columns.Add(new DataColumn("ModifiedDate", typeof(DateTime))); //taxTable.Columns.Add(new DataColumn("HeadID", typeof(int))); foreach (BonusProcess.BonusProcessDetail oBPDetail in oProcess.BonusProcessDetails) { if (oBPDetail.IncomeTaxcoll != null) { //foreach (IncomeTax tax in oBPDetail.IncomeTaxcoll) //{ // tax.ModifiedBy = oProcess.CreatedBy;// User.CurrentUser.ID; // tax.ModifiedDate = DateTime.Now; // taxTable.Rows.Add(tax.EmployeeID.Integer, // tax.ItemGroup, // tax.ItemID, // tax.Description, // double.IsNaN(tax.TotalAmount) ? 0 : tax.TotalAmount, // double.IsNaN(tax.PreviousAmount) ? 0 : tax.PreviousAmount, // double.IsNaN(tax.ThisMonthAmount) ? 0 : tax.ThisMonthAmount, // double.IsNaN(tax.ProjectedAmount) ? 0 : tax.ProjectedAmount, // (int)tax.Side, // tax.Position, // tax.ModifiedBy.Integer, // tax.ModifiedDate, // 1); //} IncomeTaxService sr = new IncomeTaxService(); sr.Save(tc, oBPDetail.IncomeTaxcoll, EnumIncomeTaxDataFrom.ProcessTempData); } } BonusProcessDA.UndoProcess(tc, oProcess, PayrollTypeID); //string sEmpIDs = ""; //foreach (BonusProcess.BonusProcessDetail item in oProcess.BonusProcessDetails) //{ // sEmpIDs += item.EmployeeID.Integer.ToString() + ","; //} //if (sEmpIDs.Length > 0) // sEmpIDs = sEmpIDs.Trim(','); //BonusProcessDA.DeleteTax(tc, sEmpIDs); //BonusProcessDA.UndoProcess(tc, oProcess, PayrollTypeID); //try //{ // tc.ExecuteNonQuery("IF OBJECT_ID ('incometaxtempbackupUndo_" + oProcess.ToString() + "') IS NOT NULL Drop table incometaxtempbackupUndo_" + oProcess.ID.ToString()); //} //catch { } //try //{ // tc.ExecuteNonQuery("Select * into incometaxtempbackupUndo_" + oProcess.ID.ToString() + " from incometaxtemp "); //} //catch { } //using (SqlBulkCopy bulkCopy = new SqlBulkCopy((SqlConnection)tc.Connection)) //{ // bulkCopy.BulkCopyTimeout = 600; // in seconds // bulkCopy.DestinationTableName = "INCOMETAXTEMP"; // bulkCopy.WriteToServer(taxTable); //} tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } #endregion } #endregion }