EchoTex_Payroll/HRM.DA/Service/HREmployee/EmpLifeCycleService.cs
2024-10-14 10:01:49 +06:00

1807 lines
81 KiB
C#

using System;
using System.Data;
using System.Linq;
using Ease.Core.Model;
using Ease.Core.DataAccess;
using Ease.Core.Utility;
using System.Collections.Generic;
using HRM.BO;
namespace HRM.DA
{
#region EmpLifeCycle Service
public class EmpLifeCycleService : ServiceTemplate, IEmpLifeCycleService
{
//public event ProgressStatus ProgressStatus;
//public event ProcessStatus ProcessStatus;
public EmpLifeCycleService()
{
}
//private void UpdateProgressStatus(EnumProcessStatus status)
//{
// if (ProgressStatus != null) ProgressStatus(status);
//}
//private void UpdateprocessStatus(string statusString)
//{
// if (ProcessStatus != null) ProcessStatus(statusString);
//}
private void MapObject(EmpLifeCycle oEmpLifeCycle, DataReader oReader)
{
base.SetObjectID(oEmpLifeCycle, oReader.GetInt32("EmpLifeCycleID").Value);
oEmpLifeCycle.EffectDate = oReader.GetDateTime("EffectDate").Value;
oEmpLifeCycle.NodeID = oReader.GetInt32("NodeID");
oEmpLifeCycle.GrossSalary = oReader.GetDouble("GrossSalary");
oEmpLifeCycle.BasicSalary = oReader.GetDouble("BasicSalary");
oEmpLifeCycle.GradeID = oReader.GetInt32("GradeID");
oEmpLifeCycle.CategoryID = oReader.GetInt32("CategoryID");
oEmpLifeCycle.CompanyID = oReader.GetInt32("CompanyID");
oEmpLifeCycle.FunctionID = oReader.GetInt32("FunctionID");
oEmpLifeCycle.DesignationID = oReader.GetInt32("DesignationID");
oEmpLifeCycle.LocationID = oReader.GetInt32("LocationID");
oEmpLifeCycle.DepartmentID = oReader.GetInt32("DepartmentID");
oEmpLifeCycle.CostCenterID = oReader.GetInt32("CostCenterID");
oEmpLifeCycle.IsConfirm = oReader.GetBoolean("IsConfirm");
if (oReader.GetInt32("pFMemberType").HasValue)
oEmpLifeCycle.PFMemberType = (EnumPFMembershipType)oReader.GetInt32("pFMemberType").Value;
else oEmpLifeCycle.PFMemberType = null;
oEmpLifeCycle.IsDiscontinue = oReader.GetBoolean("IsDiscontinue");
oEmpLifeCycle.IsContinue = oReader.GetBoolean("IsContinue");
oEmpLifeCycle.EmployeeID = oReader.GetInt32("EmployeeID").Value;
oEmpLifeCycle.StatusDetailID = oReader.GetInt32("StatusDetailID");
oEmpLifeCycle.Remarks = oReader.GetString("Remarks");
oEmpLifeCycle.Description = oReader.GetString("Description");
if (oReader.GetInt32("Status") != null)
oEmpLifeCycle.EmployeeStatus = (EnumEmployeeStatus)oReader.GetInt32("Status").Value;
oEmpLifeCycle.Sequence = oReader.GetInt32("SequenceNO").Value;
//oEmpLifeCycle.CreatedBy = oReader.GetInt32("CreatedBy").Value;
oEmpLifeCycle.CreatedBy = oReader.GetInt32("CreatedBy", true, 0);
oEmpLifeCycle.CreatedDate = oReader.GetDateTime("CreationDate") == null
? DateTime.MinValue
: oReader.GetDateTime("CreationDate").Value;
oEmpLifeCycle.ModifiedBy = oReader.GetInt32("ModifiedBy");
oEmpLifeCycle.ModifiedDate = oReader.GetDateTime("ModifiedDate");
oEmpLifeCycle.SalaryMonth = oReader.GetDateTime("SalaryMonth").Value;
oEmpLifeCycle.IsCurrentMonthIncluded = oReader.GetBoolean("IsCurrentMonthIncluded").Value;
oEmpLifeCycle.GradeSalaryAssesmentID = oReader.GetInt32("GradeSalaryAssesmentID");
oEmpLifeCycle.EmployeeCCID = oReader.GetInt32("EmployeeCCID");
oEmpLifeCycle.IncrementNo = oReader.GetInt32("IncrementNo");
oEmpLifeCycle.ComplainID = oReader.GetInt32("ComplainID").GetValueOrDefault();
oEmpLifeCycle.PunishmentID = oReader.GetInt32("PunishmentID").GetValueOrDefault();
this.SetObjectState(oEmpLifeCycle, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
EmpLifeCycle oEmpLifeCycle = new EmpLifeCycle();
MapObject(oEmpLifeCycle, oReader);
return oEmpLifeCycle as T;
}
#region Get Related Data
public EmpLifeCycle GetRelatedData(TransactionContext tc, EmpLifeCycle oEmpLifeCycle)
{
oEmpLifeCycle.Employee = (new EmployeeService()).Get(tc, oEmpLifeCycle.EmployeeID);
oEmpLifeCycle.HREmployee = (new HREmployeeService()).Get(tc, oEmpLifeCycle.EmployeeID);
//oEmpLifeCycle.Department = (new DepartmentService()).Get(tc, oEmpLifeCycle.DepartmentID);
//oEmpLifeCycle.Costcenter = (new CostcenterService()).Get(tc, SystemInformation.CurrentSysInfo.PayrollTypeID, oEmpLifeCycle.CostCenterID);
//oEmpLifeCycle.Location = (new LocationService()).Get(tc, oEmpLifeCycle.LocationID);
//oEmpLifeCycle.Category = (new CategoryService()).Get(tc, oEmpLifeCycle.CategoryID);
//oEmpLifeCycle.Designation = (new DesignationService()).Get(tc, oEmpLifeCycle.DesignationID, SystemInformation.CurrentSysInfo.PayrollTypeID);
//oEmpLifeCycle.Grade = (new GradeService()).Get(tc, oEmpLifeCycle.GradeID);
return oEmpLifeCycle;
}
#endregion
#region Service implementation
public int GetPrvGradeId(int nEmpID, int nGradeID)
{
int nGradID = 0;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
nGradID = EmpLifeCycleDA.GetPrvGradeId(tc, nEmpID, nGradeID);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return nGradID;
}
public List<EmpLifeCycle> GetNotYetProcessUptoToday()
{
List<EmpLifeCycle> oEmployees = new List<EmpLifeCycle>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(EmpLifeCycleDA.GetNotYetProcessUptoToday(tc));
oEmployees = this.CreateObjects<EmpLifeCycle>(oreader);
oreader.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return oEmployees;
}
public int GetPrvLocationId(int nEmpID, int nLocID)
{
int nLocationID = 0;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
nLocationID = EmpLifeCycleDA.GetPrvLocationId(tc, nEmpID, nLocID);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return nLocationID;
}
public int GetPrvDesigId(int nEmpID, int nDesigID)
{
int nDesgID = 0;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
nDesgID = EmpLifeCycleDA.GetPrvDesigId(tc, nEmpID, nDesigID);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return nDesgID;
}
public int? EmpPrevDesg(int employeeID)
{
int? nDesgID = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
nDesgID = EmpLifeCycleDA.EmpPrevDesg(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 nDesgID;
}
public int GetPrvRCId(int nEmpID)
{
int nCCID = 0;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
nCCID = EmpLifeCycleDA.GetPrvRCId(tc, nEmpID);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return nCCID;
}
public EmpLifeCycle Get(int lifecycleID)
{
EmpLifeCycle oEmpLifeCycle = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(EmpLifeCycleDA.Get(tc, lifecycleID));
if (oreader.Read())
{
oEmpLifeCycle = this.CreateObject<EmpLifeCycle>(oreader);
// GetRelatedData(tc, oEmpLifeCycle);
}
oreader.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return oEmpLifeCycle;
}
public List<EmpLifeCycle> getByStatus(int p, DateTime startDate, DateTime endDate)
{
List<EmpLifeCycle> oEmployees = new List<EmpLifeCycle>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(EmpLifeCycleDA.Get(tc, p, startDate, endDate));
oEmployees = this.CreateObjects<EmpLifeCycle>(oreader);
oreader.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return oEmployees;
}
public List<EmpLifeCycle> Get(string empIds, int statusID, DateTime fromDate, DateTime toDate,
int PayrollTypeID)
{
List<EmpLifeCycle> oEmployees = new List<EmpLifeCycle>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader =
new DataReader(EmpLifeCycleDA.Get(tc, empIds, statusID, fromDate, toDate, PayrollTypeID));
oEmployees = this.CreateObjects<EmpLifeCycle>(oreader);
oreader.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return oEmployees;
}
public List<EmpLifeCycle> GetByDate(DateTime startDate, DateTime endDate, int payrollTypeID)
{
List<EmpLifeCycle> oEmployees = new List<EmpLifeCycle>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(EmpLifeCycleDA.GetByDate(tc, startDate, endDate, payrollTypeID));
oEmployees = this.CreateObjects<EmpLifeCycle>(oreader);
oreader.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return oEmployees;
}
public List<EmpLifeCycle> GetByCreateDate(DateTime startDate, DateTime endDate, int payrollTypeID)
{
List<EmpLifeCycle> oEmployees = new List<EmpLifeCycle>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader =
new DataReader(EmpLifeCycleDA.GetByCreateDate(tc, startDate, endDate, payrollTypeID));
oEmployees = this.CreateObjects<EmpLifeCycle>(oreader);
oreader.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return oEmployees;
}
public List<EmpLifeCycle> Get(EnumStatus sts, int payrollTypeID)
{
List<EmpLifeCycle> oEmployees = new List<EmpLifeCycle>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(EmpLifeCycleDA.Get(tc, sts, payrollTypeID));
oEmployees = this.CreateObjects<EmpLifeCycle>(oreader);
oreader.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return oEmployees;
}
public List<EmpLifeCycle> GetEmpID(int nEmpID)
{
List<EmpLifeCycle> EmpLifeCycles = new List<EmpLifeCycle>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(EmpLifeCycleDA.GetEmpID(tc, nEmpID));
EmpLifeCycles = this.CreateObjects<EmpLifeCycle>(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 EmpLifeCycles;
}
public DataSet GetDesignationChange(DateTime startDate, DateTime endDate, int payrollTypeID)
{
DataSet allData = new DataSet();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
allData =EmpLifeCycleDA.GetDesignationChange(tc, startDate, endDate, 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 allData;
}
public List<EmpLifeCycle> GetEmpID(int employeeID, DateTime effectDate)
{
List<EmpLifeCycle> EmpLifeCycles = new List<EmpLifeCycle>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(EmpLifeCycleDA.GetEmpID(tc, employeeID, effectDate));
EmpLifeCycles = this.CreateObjects<EmpLifeCycle>(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 EmpLifeCycles;
}
public DataSet GetEmpLifecycleServiceRecord(int empId)
{
DataSet dsetDSB = new DataSet();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
dsetDSB = EmpLifeCycleDA.GetEmpLifecycleServiceRecord(tc, empId);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return dsetDSB;
}
public EmpLifeCycle GetLastPosition(int nEmpID)
{
EmpLifeCycle oEmpLifeCycle = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(EmpLifeCycleDA.GetLastPosition(tc, nEmpID));
if (oreader.Read())
{
oEmpLifeCycle = this.CreateObject<EmpLifeCycle>(oreader);
oEmpLifeCycle = GetRelatedData(tc, oEmpLifeCycle);
}
oreader.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return oEmpLifeCycle;
}
public void ProcessGradeSalary(EmpLifeCycle item)
{
if ((item.BasicSalary != null || item.GrossSalary != null) || (item.GradeID != null))
{
EmployeeGradeSalary ogs = new EmployeeGradeSalary();
ogs.BasicSalary = (item.BasicSalary == null) ? 0 : (double)item.BasicSalary;
ogs.GrossSalary = (item.GrossSalary == null) ? 0 : (double)item.BasicSalary;
if (item.GradeID == null)
{
if (item.Employee.GradeID == null)
throw new ServiceException("Grade not yet assigned of employee.");
ogs.GradeID = (int) item.Employee.GradeID;
}
else ogs.GradeID =(int) item.GradeID;
if (ogs.BasicSalary + ogs.GrossSalary == 0)
{
if (item.Employee.BasicSalary + item.Employee.GrossSalary == 0)
throw new ServiceException("Salary(Basic/Gross) can't be zero.");
else
{
ogs.BasicSalary = item.Employee.BasicSalary;
ogs.GrossSalary = item.Employee.GrossSalary;
}
}
ogs.EmployeeID = item.EmployeeID;
ogs.GradeSalaryTypeID =(int) item.StatusDetailID;
ogs.EffectDate = item.EffectDate;
item.EmployeeGradeSalary = ogs;
}
}
public void Save(List<EmpLifeCycle> lifecycles, DateTime salaryCutoffDate, DateTime nextPayProcessDate)
{
TransactionContext tc = null;
try
{
foreach (EmpLifeCycle item in lifecycles)
{
if (item.EmployeeID != 0 && item.Employee == null)
{
item.Employee = (new EmployeeService()).Get(tc, item.EmployeeID);
}
item.HREmployee = new HREmployee();
item.HREmployee.SetObjectID(item.EmployeeID);
item.HREmployee.GradeID = (item.GradeID == null)
? (item.Employee == null ? null : item.Employee.GradeID)
: item.GradeID;
item.HREmployee.CategoryID = (item.CategoryID == null)
? (item.Employee == null ? 0 : item.Employee.CategoryID)
:(int) item.CategoryID;
item.HREmployee.LocationID = (item.LocationID == null)
? (item.Employee == null ? null : item.Employee.LocationID)
: item.LocationID;
item.HREmployee.DesignationID = (item.DesignationID == null)
? (item.Employee == null ? null : item.Employee.DesignationID)
: item.DesignationID;
item.HREmployee.DepartmentID = (item.DepartmentID == null)
? (item.Employee == null ? null : item.Employee.DepartmentID)
: item.DepartmentID;
item.HREmployee.BasicSalary = item.BasicSalary == null
? (item.Employee == null ? 0.0 : item.Employee.BasicSalary)
: (double)item.BasicSalary;
item.HREmployee.GrossSalary = item.GrossSalary == null
? (item.Employee == null ? 0.0 : item.Employee.GrossSalary)
: (double)item.GrossSalary;
tc = TransactionContext.Begin(true);
this.Save(item, tc, salaryCutoffDate, nextPayProcessDate);
tc.End();
}
}
catch (Exception ex)
{
if (tc != null)
tc.HandleError();
throw new ServiceException(ex.Message);
}
}
public int Save(EmpLifeCycle oEmpLifeCycle, DateTime nextPayProcessDate, int currentPayrollId)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
int id = this.Save(tc, oEmpLifeCycle, nextPayProcessDate, currentPayrollId);
tc.End();
return id;
}
catch (Exception ex)
{
if (tc != null)
tc.HandleError();
throw new ServiceException(ex.Message);
}
}
public int Save(TransactionContext tc, EmpLifeCycle oEmpLifeCycle, DateTime nextPayProcessDate, int currentPayrollId)
{
EmployeeStatus oempStatus = null;
if (oEmpLifeCycle.EmpStatusObject == null)
oempStatus = (new EmployeeStatusService()).Get((int)oEmpLifeCycle.StatusDetailID, tc);
else oempStatus = oEmpLifeCycle.EmpStatusObject;
//find the life cycle contains the 'forcely remove organogram'
EmployeeStatus.EmpStatusComponent comp = oempStatus.EmployeeStatusComponents.Find(
delegate(EmployeeStatus.EmpStatusComponent lcc)
{
return lcc.ComponentType == EnumLifeCycleComponent.Force_Remove_From_Position;
});
try
{
EmployeeHistory oEmpHistory = new EmployeeHistory();
oEmpHistory.EffectDate = oEmpLifeCycle.EffectDate;
oEmpHistory.EmployeeID = oEmpLifeCycle.EmployeeID;
oEmpHistory.EmployeeStatus = oEmpLifeCycle.EmployeeStatus;
oEmpHistory.Remarks = oEmpLifeCycle.EmployeeStatus.ToString();
List<EmployeeGradeSalary> gradeSalaries = null;
if (oEmpLifeCycle.EmployeeGradeSalary != null)
{
EmployeeGradeSalaryService egsSerice = new EmployeeGradeSalaryService();
gradeSalaries = egsSerice.process(tc, oEmpLifeCycle.EmployeeGradeSalary, nextPayProcessDate, oEmpLifeCycle.IsTransferReceived);
}
#region Cost-center update
if (oEmpLifeCycle.CostCenterID != null)
{
EmployeeCostCenterService oEmpCCService = new EmployeeCostCenterService();
EmployeeCostCenter oEmpCC = new EmployeeCostCenter();
List<EmployeeCostCenter> oEmpCCs = new List<EmployeeCostCenter>();
oEmpCC.CostCenterID =(int) oEmpLifeCycle.CostCenterID;
oEmpCC.EmployeeID = oEmpLifeCycle.EmployeeID;
oEmpCC.IsCurrentCC = true;
oEmpCC.Percentage = 100;
oEmpCC.CreatedBy = oEmpLifeCycle.CreatedBy;
oEmpCC.CreatedDate = oEmpLifeCycle.CreatedDate;
oEmpCC.MonthDate = nextPayProcessDate;
oEmpCC.TillDate = oEmpCC.MonthDate;
oEmpCCs.Add(oEmpCC);
oEmpCCService.Save(tc, oEmpCCs);
oEmpLifeCycle.EmployeeCCID = oEmpCCs[0].ID;
oEmpLifeCycle.HREmployee.CrgId = oEmpLifeCycle.CostCenterID;
}
#endregion Cost-center update
#region Grade-Salary & Organogram Node
if (oEmpLifeCycle.EmployeeGradeSalary != null)
{
//EmployeeGradeSalaryService sgs = new EmployeeGradeSalaryService();
//sgs.DeleteFromDate(tc, oEmpLifeCycle.EmployeeID, new DateTime(2001,1,1), EnumArrearType.ToCalculate);
//sgs.DeleteFromDate(tc, oEmpLifeCycle.EmployeeID, PayrollGlobalFunctions.PayrollFirstDateOfMonth(oEmpLifeCycle.SalaryMonth), EnumArrearType.NotPresent);
//sgs.Insert(tc, gradeSalaries);
//// Grade Salary assignment object can be multiple for arrear item and last item
//// arrear not present item.
//oEmpLifeCycle.GradeSalaryAssesmentID = gradeSalaries[gradeSalaries.Count - 1].ID;
EmployeeGradeSalaryService sgs = new EmployeeGradeSalaryService();
sgs.DeleteFromDate(tc, oEmpLifeCycle.EmployeeID, new DateTime(2001, 1, 1),
EnumArrearType.ToCalculate);
// createing problem in middle of the month increment, so it is commented
// sgs.DeleteFromDate(tc, oEmpLifeCycle.EmployeeID, GlobalFunctions.FirstDateOfMonth(oEmpLifeCycle.SalaryMonth),EnumArrearType.NotPresent);
sgs.DeleteFromDate(tc, oEmpLifeCycle.EmployeeID, oEmpLifeCycle.EffectDate, EnumArrearType.NotPresent);
gradeSalaries.ForEach(x =>
{
x.CreatedBy = oEmpLifeCycle.CreatedBy;
x.CreatedDate = oEmpLifeCycle.CreatedDate;
});
sgs.Save(tc, gradeSalaries);
// Grade Salary assignment object can be multiple for arrear item and last item
// arrear not present item.
oEmpLifeCycle.GradeSalaryAssesmentID = gradeSalaries[gradeSalaries.Count - 1].ID;
}
// Insert to Organogram
if (oEmpLifeCycle.NodeID != null && oEmpLifeCycle.NodeID!= 0)
{
OrganogramEmployee oOrg = new OrganogramEmployee();
oOrg.NodeID = (int)oEmpLifeCycle.NodeID;
oOrg.EmployeeID = oEmpLifeCycle.EmployeeID;
oOrg.CreatedBy = oEmpLifeCycle.CreatedBy;
oOrg.CreatedDate = oEmpLifeCycle.CreatedDate;
oOrg.AssignDate = oEmpLifeCycle.EffectDate;
OrganogramEmployeeService oge = new OrganogramEmployeeService();
// Remove existing employee
HREmployeeDA.updateRoceRemoveLineManagerByEmployee(tc, (int)oEmpLifeCycle.EmployeeID);
oge.DeleteByNode(tc,(int) oEmpLifeCycle.NodeID);
OrganogramDA.UpdateFromLifeCycle(tc, oEmpLifeCycle);
// remove current emloyee other posting
oge.DeleteByEmp(tc, oEmpLifeCycle.EmployeeID);
oge.Save(tc, oOrg);
HREmployeeDA.updateLineManagerByOrganogram(tc, oOrg.EmployeeID, oOrg.NodeID);
}
#endregion Grade-Salary & Organogram Node
//}
if (oEmpLifeCycle.IsNew)
{
if (oEmpLifeCycle.EmployeeStatus == EnumEmployeeStatus.Live &&
oempStatus.EmployeeStatusComponents.FindIndex(x => x.ComponentType == EnumLifeCycleComponent.Continue) > -1)
{
oEmpLifeCycle.IsContinue = true;
}
if (oEmpLifeCycle.EmployeeStatus == EnumEmployeeStatus.Discontinued &&
oempStatus.EmployeeStatusComponents.FindIndex(x => x.ComponentType == EnumLifeCycleComponent.Discontinue) > -1)
{
oEmpLifeCycle.IsDiscontinue = true;
}
int id = tc.GenerateID("EmpLifeCycle", "EmpLifeCycleID");
base.SetObjectID(oEmpLifeCycle, id);
int seqNo = tc.GenerateID("EmpLifeCycle", "SequenceNO",
"Where EmployeeID=" + oEmpLifeCycle.EmployeeID.ToString());
oEmpLifeCycle.Sequence = seqNo;
EmpLifeCycleDA.Insert(tc, oEmpLifeCycle);
EmployeeHistoryService oEmployeeHistory = new EmployeeHistoryService();
}
else
{
EmpLifeCycleDA.Update(tc, oEmpLifeCycle);
}
//
if (comp != null)
{
// if forcely remove ogranogram node component exist, remove employee from organogram
OrganogramEmployeeService ogs = new OrganogramEmployeeService();
HREmployeeDA.updateRoceRemoveLineManagerByOrganogram(tc, oEmpLifeCycle.EmployeeID);
ogs.DeleteByEmp(tc, oEmpLifeCycle.EmployeeID);
}
if (oEmpLifeCycle.Employee == null)
oEmpLifeCycle.Employee = new EmployeeService().Get(tc, oEmpLifeCycle.ID);
if (oEmpLifeCycle.HREmployee != null)
{
if (oEmpLifeCycle.HREmployee.DepartmentID == null && oEmpLifeCycle.Employee.DepartmentID != null)
oEmpLifeCycle.HREmployee.DepartmentID = oEmpLifeCycle.Employee.DepartmentID;
if (oEmpLifeCycle.HREmployee.LocationID == null && oEmpLifeCycle.Employee.LocationID != null)
oEmpLifeCycle.HREmployee.LocationID = oEmpLifeCycle.Employee.LocationID;
if (oEmpLifeCycle.HREmployee.GradeID == null && oEmpLifeCycle.Employee.GradeID != null)
oEmpLifeCycle.HREmployee.GradeID = oEmpLifeCycle.Employee.GradeID;
if (oEmpLifeCycle.HREmployee.DesignationID == null && oEmpLifeCycle.Employee.DesignationID != null)
oEmpLifeCycle.HREmployee.DesignationID = oEmpLifeCycle.Employee.DesignationID;
if (oEmpLifeCycle.HREmployee.CrgId == null && oEmpLifeCycle.Employee.CrgId != null)
oEmpLifeCycle.HREmployee.CrgId = oEmpLifeCycle.Employee.CrgId;
//if (oEmpLifeCycle.HREmployee.CategoryID == null && oEmpLifeCycle.Employee.CategoryID != null)
// oEmpLifeCycle.HREmployee.CategoryID = oEmpLifeCycle.Employee.CategoryID;
if (oEmpLifeCycle.HREmployee.GrossSalary == 0 && oEmpLifeCycle.Employee.GrossSalary != 0)
oEmpLifeCycle.HREmployee.GrossSalary = oEmpLifeCycle.Employee.GrossSalary;
if (oEmpLifeCycle.HREmployee.BasicSalary == 0 && oEmpLifeCycle.Employee.BasicSalary != 0)
oEmpLifeCycle.HREmployee.BasicSalary = oEmpLifeCycle.Employee.BasicSalary;
HREmployeeDA.UpdateForEmpLifeCycle(tc, oEmpLifeCycle.HREmployee, oEmpLifeCycle.EmployeeID);
}
switch (oEmpLifeCycle.EmployeeStatus)
{
case EnumEmployeeStatus.Waitingforjoin:
case EnumEmployeeStatus.Live:
if (oEmpLifeCycle.GrossSalary > 0)
EmployeeDA.UpdateGross(tc, oEmpLifeCycle.EmployeeID, oEmpLifeCycle.GrossSalary);
// if component contain 'IsContinue', update employee status
if (oEmpLifeCycle.IsConfirm != null)
//if ((bool)oEmpLifeCycle.IsContinue == true)
{
bool autopf = new SystemConfigarationService().GetconfigBooleanValue(EnumConfigurationType.Logic, "confirmation", "autopfmembership");
EmployeeDA.DoConfirm(tc, oEmpLifeCycle.EmployeeID, oEmpLifeCycle.EffectDate, true);
if(autopf ==true)
{
HREmployeeDA.UpdatePFInfo(tc, oEmpLifeCycle.EmployeeID,
EnumPFMembershipType.Live, oEmpLifeCycle.EffectDate);
}
}
//else
// EmployeeDA.UndoConfirm(tc, oEmpLifeCycle.EmployeeID, false);
// if conponent contain isconfirm, update employee confirm property and confrim date.
if (oEmpLifeCycle.IsContinue != null)
{
//if (oEmpLifeCycle.HREmployee.Status == EnumEmployeeStatus.IA)
// EmployeeDA.DoContinueForLifeCycle(tc, oEmpLifeCycle.EmployeeID,
// oEmpLifeCycle.HREmployee.JoiningDate);
//else
EmployeeDA.DoContinueForLifeCycle(tc, oEmpLifeCycle.EmployeeID,
oEmpLifeCycle.EffectDate);
}
if (oempStatus.EmployeeStatusComponents.FindIndex(x => x.ComponentType == EnumLifeCycleComponent.salary_Withheld) > -1)
{
EmployeeDA.salaryWithHeld(tc, oEmpLifeCycle.EmployeeID, true);
}
if (oempStatus.EmployeeStatusComponents.FindIndex(x => x.ComponentType == EnumLifeCycleComponent.undo_salary_Withheld) > -1)
{
EmployeeDA.salaryWithHeld(tc, oEmpLifeCycle.EmployeeID, false);
}
// if conponent contain pf member, update employee pfMembership property property and pfMembership date.
if (oEmpLifeCycle.PFMemberType != null)
HREmployeeDA.UpdatePFInfo(tc, oEmpLifeCycle.EmployeeID,
(EnumPFMembershipType)oEmpLifeCycle.PFMemberType, oEmpLifeCycle.EffectDate);
break;
case EnumEmployeeStatus.Discontinued:
EmployeeDA.UpdateStatus(tc, oEmpLifeCycle.EmployeeID, oEmpLifeCycle.ID,
oEmpLifeCycle.EffectDate, oEmpLifeCycle.EmployeeStatus);
// update end of contract property of emlpoyee by effect date.
if (oEmpLifeCycle.IsCurrentMonthIncluded == true)
EmployeeDA.UpdatemiddleOfMonthDiscontinue(tc,
oEmpLifeCycle.EmployeeID, oEmpLifeCycle.EmployeeStatus, oEmpLifeCycle.EffectDate);
OrganogramEmployeeService OrgEmpSrv = new OrganogramEmployeeService();
OrgEmpSrv.DeleteByEmp(tc, oEmpLifeCycle.EmployeeID);
break;
case EnumEmployeeStatus.IA:
EmployeeDA.UpdateStatus(tc, oEmpLifeCycle.EmployeeID, oEmpLifeCycle.ID,
oEmpLifeCycle.EffectDate, oEmpLifeCycle.EmployeeStatus);
break;
case EnumEmployeeStatus.Secondy:
case EnumEmployeeStatus.Suspend:
EmployeeDA.UpdateStatus(tc, oEmpLifeCycle.EmployeeID, oEmpLifeCycle.ID,
oEmpLifeCycle.EffectDate, oEmpLifeCycle.EmployeeStatus);
// update end of contract property of emlpoyee by effect date.
if (oEmpLifeCycle.IsCurrentMonthIncluded == true)
EmployeeDA.UpdatemiddleOfMonthDiscontinue(tc,
oEmpLifeCycle.EmployeeID, oEmpLifeCycle.EmployeeStatus, oEmpLifeCycle.EffectDate);
break;
//case EnumEmployeeStatus.Withheld:
break;
default:
break;
}
//}
if (oEmpLifeCycle.IsPayrollTypeChanged == true)
{
EmployeeService oEmpService = new EmployeeService();
oEmpService.UpdatePayrollType(tc, oEmpLifeCycle.EmployeeID, oEmpLifeCycle.PayrollTypeID);
EmployeeWorkPlanSetupService oserveice = new EmployeeWorkPlanSetupService();
oserveice.DeleteByEmpID(tc, oEmpLifeCycle.EmployeeID);
ActingResponsibilitySetupService oResService = new ActingResponsibilitySetupService();
oResService.UpdateTempShiftToDate(tc, oEmpLifeCycle.EmployeeID, oEmpLifeCycle.EffectDate);
LeaveYearService oLeaveYearService = new LeaveYearService();
oLeaveYearService.UpdateLeaveBalance(tc, oEmpLifeCycle.EmployeeID, oEmpLifeCycle.PayrollTypeID, currentPayrollId);
DailyAttnProcessService oAttProcess = new DailyAttnProcessService();
oAttProcess.UpdateAttProcessedShift(tc, oEmpLifeCycle, currentPayrollId);
}
//tc.End();
return oEmpLifeCycle.ID;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public int Save(List<EmpLifeCycle> oEmpLifeCycles, DateTime nextPayProcessDate)
{
EmployeeStatus oempStatus = (new EmployeeStatusService()).Get((int)oEmpLifeCycles[0].StatusDetailID);
EmployeeStatus.EmpStatusComponent comp = oempStatus.EmployeeStatusComponents.Find(
delegate(EmployeeStatus.EmpStatusComponent lcc)
{
return lcc.ComponentType == EnumLifeCycleComponent.Force_Remove_From_Position;
});
TransactionContext tc = null;
tc = TransactionContext.Begin(true);
try
{
foreach (EmpLifeCycle oEmpLifeCycle in oEmpLifeCycles)
{
EmployeeHistory oEmpHistory = new EmployeeHistory();
oEmpHistory.EffectDate = oEmpLifeCycle.EffectDate;
oEmpHistory.EmployeeID = oEmpLifeCycle.EmployeeID;
oEmpHistory.EmployeeStatus = oEmpLifeCycle.EmployeeStatus;
oEmpHistory.Remarks = oEmpLifeCycle.EmployeeStatus.ToString();
List<EmployeeGradeSalary> gradeSalaries = null;
if (oEmpLifeCycle.EmployeeGradeSalary != null)
{
// get the last (max on date) grade salary item grade salary item from the database
EmployeeGradeSalary lastgs = (new EmployeeGradeSalaryService()).GetMax(tc,
oEmpLifeCycle.EmployeeGradeSalary.EmployeeID, EnumArrearType.NotPresent);
gradeSalaries = oEmpLifeCycle.EmployeeGradeSalary.process(lastgs);
}
//if (oEmpLifeCycle.EffectDate <= SystemInformationService.GetServerDate(tc))
//{
#region Cost-center update
if (oEmpLifeCycle.CostCenterID != 0)
{
EmployeeCostCenterService oEmpCCService = new EmployeeCostCenterService();
EmployeeCostCenter oEmpCC = new EmployeeCostCenter();
List<EmployeeCostCenter> oEmpCCs = new List<EmployeeCostCenter>();
oEmpCC.CostCenterID = (int)oEmpLifeCycle.CostCenterID;
oEmpCC.EmployeeID = oEmpLifeCycle.EmployeeID;
oEmpCC.IsCurrentCC = true;
oEmpCC.Percentage = 100;
oEmpCC.CreatedBy = oEmpLifeCycle.CreatedBy;
oEmpCC.CreatedDate = oEmpLifeCycle.CreatedDate;
oEmpCC.MonthDate = nextPayProcessDate;
oEmpCC.TillDate = oEmpCC.MonthDate;
oEmpCCs.Add(oEmpCC);
oEmpCCService.Save(tc, oEmpCCs);
oEmpLifeCycle.EmployeeCCID = oEmpCCs[0].ID;
}
#endregion Cost-center update
#region Grade-Salary & Organogram Node
if (oEmpLifeCycle.EmployeeGradeSalary != null)
{
//EmployeeGradeSalaryService sgs = new EmployeeGradeSalaryService();
//sgs.DeleteFromDate(tc, oEmpLifeCycle.EmployeeID, new DateTime(2001,1,1), EnumArrearType.ToCalculate);
//sgs.DeleteFromDate(tc, oEmpLifeCycle.EmployeeID, PayrollGlobalFunctions.PayrollFirstDateOfMonth(oEmpLifeCycle.SalaryMonth), EnumArrearType.NotPresent);
//sgs.Insert(tc, gradeSalaries);
//// Grade Salary assignment object can be multiple for arrear item and last item
//// arrear not present item.
//oEmpLifeCycle.GradeSalaryAssesmentID = gradeSalaries[gradeSalaries.Count - 1].ID;
EmployeeGradeSalaryService sgs = new EmployeeGradeSalaryService();
sgs.DeleteFromDate(tc, oEmpLifeCycle.EmployeeID, new DateTime(2001, 1, 1),
EnumArrearType.ToCalculate);
sgs.DeleteFromDate(tc, oEmpLifeCycle.EmployeeID,
PayrollGlobalFunctions.PayrollFirstDateOfMonth(oEmpLifeCycle.SalaryMonth),
EnumArrearType.NotPresent);
sgs.Save(tc, gradeSalaries);
// Grade Salary assignment object can be multiple for arrear item and last item
// arrear not present item.
oEmpLifeCycle.GradeSalaryAssesmentID = gradeSalaries[gradeSalaries.Count - 1].ID;
}
// Insert to Organogram
if (oEmpLifeCycle.Orgemployees != null)
{
OrganogramEmployee oOrg = new OrganogramEmployee();
oEmpLifeCycle.Orgemployees[0].CreatedBy = oEmpLifeCycle.CreatedBy;
oEmpLifeCycle.Orgemployees[0].CreatedDate = oEmpLifeCycle.CreatedDate;
OrganogramEmployeeService oge = new OrganogramEmployeeService();
oge.DeleteByEmp(tc, oEmpLifeCycle.EmployeeID);
oge.Save(tc, oEmpLifeCycle.Orgemployees[0]);
}
#endregion Grade-Salary & Organogram Node
//}
if (oEmpLifeCycle.IsNew)
{
int id = tc.GenerateID("EmpLifeCycle", "EmpLifeCycleID");
base.SetObjectID(oEmpLifeCycle, (id));
int seqNo = tc.GenerateID("EmpLifeCycle", "SequenceNO",
"Where EmployeeID=" + oEmpLifeCycle.EmployeeID.ToString());
oEmpLifeCycle.Sequence = seqNo;
EmpLifeCycleDA.Insert(tc, oEmpLifeCycle);
EmployeeHistoryService oEmployeeHistory = new EmployeeHistoryService();
}
else
{
EmpLifeCycleDA.Update(tc, oEmpLifeCycle);
}
//
if (comp != null)
{
// if forcely remove ogranogram node component exist, remove employee from organogram
OrganogramEmployeeService ogs = new OrganogramEmployeeService();
ogs.DeleteByEmp(tc, oEmpLifeCycle.EmployeeID);
}
//if (oEmpLifeCycle.EffectDate <= SystemInformationService.GetServerDate(tc))
//{
HREmployeeDA.UpdateForEmpLifeCycle(tc, oEmpLifeCycle.HREmployee, oEmpLifeCycle.EmployeeID);
switch (oEmpLifeCycle.EmployeeStatus)
{
case EnumEmployeeStatus.Waitingforjoin:
case EnumEmployeeStatus.Live:
if (oEmpLifeCycle.GrossSalary > 0)
EmployeeDA.UpdateGross(tc, oEmpLifeCycle.EmployeeID, oEmpLifeCycle.GrossSalary);
// if component contain 'IsContinue', update employee status
if (oEmpLifeCycle.IsConfirm != null)
//if ((bool)oEmpLifeCycle.IsContinue == true)
EmployeeDA.DoConfirm(tc, oEmpLifeCycle.EmployeeID, oEmpLifeCycle.EffectDate, true);
//else
// EmployeeDA.UndoConfirm(tc, oEmpLifeCycle.EmployeeID, false);
// if conponent contain isconfirm, update employee confirm property and confrim date.
if (oEmpLifeCycle.IsContinue != null)
EmployeeDA.DoContinueForLifeCycle(tc, oEmpLifeCycle.EmployeeID,
oEmpLifeCycle.EffectDate);
// if conponent contain pf member, update employee pfMembership property property and pfMembership date.
if (oEmpLifeCycle.PFMemberType != null)
HREmployeeDA.UpdatePFInfo(tc, oEmpLifeCycle.EmployeeID,
(EnumPFMembershipType)oEmpLifeCycle.PFMemberType, oEmpLifeCycle.EffectDate);
break;
case EnumEmployeeStatus.Discontinued:
case EnumEmployeeStatus.IA:
EmployeeDA.UpdateStatus(tc, oEmpLifeCycle.EmployeeID, oEmpLifeCycle.ID,
oEmpLifeCycle.EffectDate, oEmpLifeCycle.EmployeeStatus);
// update end of contract property of emlpoyee by effect date.
if (oEmpLifeCycle.IsCurrentMonthIncluded == true)
EmployeeDA.UpdatemiddleOfMonthDiscontinue(tc,
oEmpLifeCycle.EmployeeID, oEmpLifeCycle.EmployeeStatus, oEmpLifeCycle.EffectDate);
OrganogramEmployeeService OrgEmpSrv = new OrganogramEmployeeService();
OrgEmpSrv.DeleteByEmp(tc, oEmpLifeCycle.EmployeeID);
break;
case EnumEmployeeStatus.Secondy:
case EnumEmployeeStatus.Suspend:
case EnumEmployeeStatus.Withheld:
EmployeeDA.UpdateStatus(tc, oEmpLifeCycle.EmployeeID, oEmpLifeCycle.ID,
oEmpLifeCycle.EffectDate, oEmpLifeCycle.EmployeeStatus);
// update end of contract property of emlpoyee by effect date.
if (oEmpLifeCycle.IsCurrentMonthIncluded == true)
EmployeeDA.UpdatemiddleOfMonthDiscontinue(tc,
oEmpLifeCycle.EmployeeID, oEmpLifeCycle.EmployeeStatus, oEmpLifeCycle.EffectDate);
break;
default:
break;
}
}
tc.End();
return (1);
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
//Data Integration
public void SaveIntegration(EmpLifeCycle oEmpLifeCycle, TransactionContext tc, Employee oEmp, DateTime NextPayProcessDate, int currentUserId,DateTime LastPayProcessDate)
{
// find the life cycle contains the 'forcely remove organogram'
string ErrMsg = "";
EmpLifeCycle eCycle = new EmpLifeCycle();
//EmployeeStatus oempStatus = EmployeeStatus.Get(oEmpLifeCycle.StatusDetailID);
//EmployeeStatus.EmpStatusComponent comp = oempStatus.EmployeeStatusComponents.Find(delegate(EmployeeStatus.EmpStatusComponent lcc) { return lcc.ComponentType == (int)EnumLifeCycleComponent.Force_Remove_From_Position; });
//TransactionContext tc = null;
try
{
EmployeeHistory oEmpHistory = new EmployeeHistory();
oEmpHistory.EffectDate = oEmpLifeCycle.EffectDate;
oEmpHistory.EmployeeID = oEmpLifeCycle.EmployeeID;
// oEmpHistory.EmployeeStatus = oEmpLifeCycle.Status; // ?? status not found
oEmpHistory.Remarks = oEmpLifeCycle.Status.ToString();
List<EmployeeGradeSalary> gradeSalaries = null;
ErrMsg = "Error during Calculating salary";
if (oEmpLifeCycle.EmployeeGradeSalary != null)
{
EmployeeGradeSalaryService empgradeService = new EmployeeGradeSalaryService();
oEmpLifeCycle.EmployeeGradeSalary.EmployeeID = oEmpLifeCycle.EmployeeID;
// gradeSalaries = oEmpLifeCycle.EmployeeGradeSalary.process(oEmp);
gradeSalaries = empgradeService.process(oEmp, LastPayProcessDate, NextPayProcessDate, currentUserId, oEmpLifeCycle.EmployeeGradeSalary);
}
// tc = TransactionContext.Begin(true);
//if (oEmpLifeCycle.EffectDate <= SystemInformationService.GetServerDate(tc))
//{
ErrMsg = "Error updating Cost-center";
#region Cost-center update
if (oEmpLifeCycle.CostCenterID != null)
{
EmployeeCostCenterService oEmpCCService = new EmployeeCostCenterService();
EmployeeCostCenter oEmpCC = new EmployeeCostCenter();
List<EmployeeCostCenter> oEmpCCs = new List<EmployeeCostCenter>();
oEmpCC.CostCenterID =(int) oEmpLifeCycle.CostCenterID;
oEmpCC.EmployeeID = oEmpLifeCycle.EmployeeID;
oEmpCC.IsCurrentCC = true;
oEmpCC.Percentage = 100;
oEmpCC.CreatedBy = oEmpLifeCycle.CreatedBy;
oEmpCC.CreatedDate = oEmpLifeCycle.CreatedDate;
// oEmpCC.MonthDate = Payroll.BO.SystemInformation.CurrentSysInfo.NextPayProcessDate;
oEmpCC.MonthDate = NextPayProcessDate;
oEmpCC.TillDate = oEmpCC.MonthDate;
oEmpCCs.Add(oEmpCC);
oEmpCCService.Save(tc, oEmpCCs);
oEmpLifeCycle.EmployeeCCID = oEmpCCs[0].ID;
}
#endregion Cost-center update
ErrMsg = "Error updating grade/Salary";
#region Grade-Salary & Organogram Node
if (oEmpLifeCycle.EmployeeGradeSalary != null)
{
EmployeeGradeSalaryService sgs = new EmployeeGradeSalaryService();
sgs.DeleteFromDate(tc, oEmpLifeCycle.EmployeeID, new DateTime(2001, 1, 1), EnumArrearType.ToCalculate);
sgs.DeleteFromDate(tc, oEmpLifeCycle.EmployeeID, GlobalFunctions.FirstDateOfMonth(oEmpLifeCycle.SalaryMonth), EnumArrearType.NotPresent);
sgs.Save(tc, gradeSalaries);
// Grade Salary assignment object can be multiple for arrear item and last item
// arrear not present item.
oEmpLifeCycle.GradeSalaryAssesmentID = gradeSalaries[gradeSalaries.Count - 1].ID;
}
ErrMsg = "Error updating organogram";
// Save to Organogram
if (oEmpLifeCycle.Orgemployees != null)
{
OrganogramEmployee oOrg = new OrganogramEmployee();
oEmpLifeCycle.Orgemployees[0].CreatedBy = oEmpLifeCycle.CreatedBy;
oEmpLifeCycle.Orgemployees[0].CreatedDate = oEmpLifeCycle.CreatedDate;
OrganogramEmployeeService oge = new OrganogramEmployeeService();
oge.DeleteByEmp(tc, oEmpLifeCycle.EmployeeID);
oge.Save(tc, oEmpLifeCycle.Orgemployees[0]);
}
#endregion Grade-Salary & Organogram Node
//}
ErrMsg = "Error updating life-cycle";
if (oEmpLifeCycle.IsNew)
{
int id = tc.GenerateID("EmpLifeCycle", "EmpLifeCycleID");
base.SetObjectID(oEmpLifeCycle, id);
int seqNo = tc.GenerateID("EmpLifeCycle", "SequenceNO", "Where EmployeeID=" + oEmpLifeCycle.EmployeeID.ToString());
oEmpLifeCycle.Sequence = seqNo;
EmpLifeCycleDA.Insert(tc, oEmpLifeCycle);
EmployeeHistoryService oEmployeeHistory = new EmployeeHistoryService();
}
else
{
EmpLifeCycleDA.Update(tc, oEmpLifeCycle);
}
//
//if (comp != null)
//{
// // if forcely remove ogranogram node component exist, remove employee from organogram
// OrganogramEmployeeService ogs = new OrganogramEmployeeService();
// ogs.DeleteByEmp(tc, oEmpLifeCycle.EmployeeID);
//}
//if (oEmpLifeCycle.EffectDate <= SystemInformationService.GetServerDate(tc))
//{
//HREmployeeDA.UpdateForEmpLifeCycle(tc, oEmpLifeCycle.HREmployee, oEmpLifeCycle.EmployeeID);
ErrMsg = "Error updating Status";
/// need to ask shamim bhai
//switch (oEmpLifeCycle.Status)
//{
// case EnumEmployeeStatus.Waitingforjoin:
// case EnumEmployeeStatus.Live:
// if (oEmpLifeCycle.GrossSalary > 0)
// EmployeeDA.UpdateGross(tc, oEmpLifeCycle.EmployeeID, oEmpLifeCycle.GrossSalary);
// // if component contain 'IsContinue', update employee status
// if (oEmpLifeCycle.IsConfirm != null)
// //if ((bool)oEmpLifeCycle.IsContinue == true)
// EmployeeDA.DoConfirm(tc, oEmpLifeCycle.EmployeeID, oEmpLifeCycle.EffectDate, true);
// //else
// // EmployeeDA.UndoConfirm(tc, oEmpLifeCycle.EmployeeID, false);
// // if conponent contain isconfirm, update employee confirm property and confrim date.
// if (oEmpLifeCycle.IsContinue != null)
// {
// if (oEmp.JoiningDate.Date > DateTime.MinValue.Date)
// EmployeeDA.DoContinueForLifeCycleForOldEmployee(tc, oEmpLifeCycle.EmployeeID);
// else
// EmployeeDA.DoContinueForLifeCycle(tc, oEmpLifeCycle.EmployeeID, oEmpLifeCycle.EffectDate);
// }
// // if conponent contain pf member, update employee pfMembership property property and pfMembership date.
// if (oEmpLifeCycle.PFMemberType != null && oEmpLifeCycle.PFMemberType != EnumPFMembershipType.NotYetLive)
// HREmployeeDA.UpdatePFInfo(tc, oEmpLifeCycle.EmployeeID, (EnumPFMembershipType)oEmpLifeCycle.PFMemberType, oEmpLifeCycle.EffectDate);
// break;
// case EnumEmployeeStatus.Discontinued:
// case EnumEmployeeStatus.Mobility:
// EmployeeDA.UpdateStatus(tc, oEmpLifeCycle.EmployeeID, oEmpLifeCycle.ID,
// oEmpLifeCycle.EffectDate, oEmpLifeCycle.Status);
// // update end of contract property of emlpoyee by effect date.
// if (oEmpLifeCycle.IsCurrentMonthIncluded == true)
// EmployeeDA.UpdatemiddleOfMonthDiscontinue(tc,
// oEmpLifeCycle.EmployeeID, oEmpLifeCycle.Status, oEmpLifeCycle.EffectDate);
// OrganogramEmployeeService OrgEmpSrv = new OrganogramEmployeeService();
// OrgEmpSrv.DeleteByEmp(tc, oEmpLifeCycle.EmployeeID);
// break;
// case EnumEmployeeStatus.Secondy:
// case EnumEmployeeStatus.Suspend:
// case EnumEmployeeStatus.Withheld:
// // if (oEmpLifeCycle.Status == EnumEmployeeStatus.Withheld )
// EmployeeDA.UpdateStatus(tc, oEmpLifeCycle.EmployeeID, oEmpLifeCycle.ID,
// oEmpLifeCycle.EffectDate, oEmpLifeCycle.Status);
// // update end of contract property of emlpoyee by effect date.
// if (oEmpLifeCycle.IsCurrentMonthIncluded == true)
// EmployeeDA.UpdatemiddleOfMonthDiscontinue(tc,
// oEmpLifeCycle.EmployeeID, oEmpLifeCycle.Status, oEmpLifeCycle.EffectDate);
// break;
// default:
// break;
//}
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(ErrMsg + " for Emp: " + oEmp.EmployeeNo + " " + e.Message, e);
#endregion
}
}
//public void Insert(List<EmpLifeCycle> lifecycles, DateTime salaryCutoffDate, DateTime nextPayProcessDate,
// TransactionContext tc)
//{
// try
// {
// foreach (EmpLifeCycle item in lifecycles)
// {
// if (item.EmployeeID != 0 && item.Employee == null)
// {
// //item.HREmployee = (new HREmployeeService()).Get(tc, item.EmployeeID);
// item.Employee = (new EmployeeService()).Get(tc, item.EmployeeID);
// }
// //this.ProcessGradeSalary(item);
// item.HREmployee = new HREmployee();
// item.HREmployee.SetObjectID(item.EmployeeID);
// item.HREmployee.GradeID = (item.GradeID == null)
// ? (item.Employee == null ? 0 : item.Employee.GradeID)
// : item.GradeID;
// item.HREmployee.CategoryID = (item.CategoryID == null)
// ? (item.Employee == null ? 0 : item.Employee.CategoryID)
// : (int) item.CategoryID;
// item.HREmployee.LocationID = (item.LocationID == null)
// ? (item.Employee == null ? null : item.Employee.LocationID)
// : item.LocationID;
// item.HREmployee.DesignationID = (item.DesignationID == null)
// ? (item.Employee == null ? null : item.Employee.DesignationID)
// : item.DesignationID;
// item.HREmployee.DepartmentID = (item.DepartmentID == null)
// ? (item.Employee == null ? null : item.Employee.DepartmentID)
// : item.DepartmentID;
// item.HREmployee.BasicSalary = item.BasicSalary == null
// ? (item.Employee == null ? 0.0 : item.Employee.BasicSalary)
// : (double)item.BasicSalary;
// item.HREmployee.GrossSalary = item.GrossSalary == null
// ? (item.Employee == null ? 0.0 : item.Employee.GrossSalary)
// : (double)item.GrossSalary;
// //if (item.Employee == null)
// //{
// // item.HREmployee.GradeID = item.GradeID;
// // item.HREmployee.CategoryID = item.CategoryID;
// //}
// //else
// //{
// // item.HREmployee.GradeID = item.Employee.GradeID;
// // item.HREmployee.CategoryID = item.Employee.CategoryID;
// //}
// //item.HREmployee.DesignationID = item.DesignationID;
// //item.HREmployee.DepartmentID = item.DepartmentID;
// //item.HREmployee.BasicSalary = item.BasicSalary == null ? 0 : (double)item.BasicSalary;
// //item.HREmployee.GrossSalary = item.GrossSalary == null ? 0 : (double)item.GrossSalary;
// this.Insert(item, tc, salaryCutoffDate, nextPayProcessDate);
// }
// }
// catch (Exception ex)
// {
// throw new ServiceException(ex.Message);
// }
//}
public int Save(EmpLifeCycle oEmpLifeCycle, TransactionContext tc, DateTime salaryCutoffDate,
DateTime nextPayProcessDate)
{
oEmpLifeCycle.SalaryMonth = nextPayProcessDate;
// temporary disabled
if (salaryCutoffDate <= DateTime.Today &&
salaryCutoffDate.Month == nextPayProcessDate.Month) //Today is greater of cutoff date and current month
{
//oEmpLifeCycle.IsProcessed = false;
if (!oEmpLifeCycle.IsNew)
return oEmpLifeCycle.ID;
return this.Insert(tc, oEmpLifeCycle);
}
else if (nextPayProcessDate < DateTime.Today) // Last month salary not yet complted monthend
{
//oEmpLifeCycle.IsProcessed = false;
if (!oEmpLifeCycle.IsNew)
return oEmpLifeCycle.ID;
return this.Insert(tc, oEmpLifeCycle);
}
else
{
if (oEmpLifeCycle.EffectDate > DateTime.Today) // future effect data
{
//oEmpLifeCycle.IsProcessed = false;
if (!oEmpLifeCycle.IsNew)
return oEmpLifeCycle.ID;
return this.Insert(tc, oEmpLifeCycle);
}
}
// find the life cycle contains the 'forcely remove organogram'
EmployeeStatus oempStatus = (new EmployeeStatusService()).Get((int)oEmpLifeCycle.StatusDetailID, tc);
EmployeeStatus.EmpStatusComponent comp = null;
if (oempStatus != null)
{
comp = (new EmployeeStatusService()).GetChild((int)oEmpLifeCycle.StatusDetailID, tc)
.Where(o => o.ComponentType == EnumLifeCycleComponent.Force_Remove_From_Position)
.SingleOrDefault();
}
// TransactionContext tc = null;
try
{
EmployeeHistory oEmpHistory = new EmployeeHistory();
oEmpHistory.EffectDate = oEmpLifeCycle.EffectDate;
oEmpHistory.EmployeeID = oEmpLifeCycle.EmployeeID;
oEmpHistory.EmployeeStatus = oEmpLifeCycle.EmployeeStatus;
oEmpHistory.Remarks = oEmpLifeCycle.EmployeeStatus.ToString();
oEmpHistory.CreatedBy = oEmpLifeCycle.CreatedBy;
oEmpHistory.CreatedDate = DateTime.Today;
List<EmployeeGradeSalary> gradeSalaries = null;
gradeSalaries = oEmpLifeCycle.Gradesalaries;
//if (oEmpLifeCycle.EmployeeGradeSalary != null)
// gradeSalaries = oEmpLifeCycle.EmployeeGradeSalary.process();
// tc = TransactionContext.Begin(true);
//if (oEmpLifeCycle.EffectDate <= SystemInformationService.GetServerDate(tc))
//{
#region Cost-center update
if (oEmpLifeCycle.CostCenterID != 0)
{
EmployeeCostCenterService oEmpCCService = new EmployeeCostCenterService();
EmployeeCostCenter oEmpCC = new EmployeeCostCenter();
List<EmployeeCostCenter> oEmpCCs = new List<EmployeeCostCenter>();
oEmpCC.CostCenterID = (int)oEmpLifeCycle.CostCenterID;
oEmpCC.EmployeeID = oEmpLifeCycle.EmployeeID;
oEmpCC.IsCurrentCC = true;
oEmpCC.Percentage = 100;
oEmpCC.CreatedBy = oEmpLifeCycle.CreatedBy;
oEmpCC.CreatedDate = oEmpLifeCycle.CreatedDate;
oEmpCC.MonthDate = nextPayProcessDate;
oEmpCC.TillDate = oEmpCC.MonthDate;
oEmpCCs.Add(oEmpCC);
oEmpCCService.Save(tc, oEmpCCs);
oEmpLifeCycle.EmployeeCCID = oEmpCCs[0].ID;
}
#endregion Cost-center update
#region Grade-Salary & Organogram Node
if (oEmpLifeCycle.EmployeeGradeSalary != null)
{
EmployeeGradeSalaryService sgs = new EmployeeGradeSalaryService();
sgs.DeleteFromDate(tc, oEmpLifeCycle.EmployeeID, new DateTime(2001, 1, 1),
EnumArrearType.ToCalculate);
sgs.DeleteFromDate(tc, oEmpLifeCycle.EmployeeID,
PayrollGlobalFunctions.PayrollFirstDateOfMonth(oEmpLifeCycle.SalaryMonth),
EnumArrearType.NotPresent);
sgs.Save(tc, gradeSalaries);
// Grade Salary assignment object can be multiple for arrear item and last item
// arrear not present item.
oEmpLifeCycle.GradeSalaryAssesmentID = gradeSalaries[gradeSalaries.Count - 1].ID;
}
// Insert to Organogram
if (oEmpLifeCycle.Orgemployees != null)
{
OrganogramEmployee oOrg = new OrganogramEmployee();
oEmpLifeCycle.Orgemployees[0].CreatedBy = oEmpLifeCycle.CreatedBy;
oEmpLifeCycle.Orgemployees[0].CreatedDate = oEmpLifeCycle.CreatedDate;
OrganogramEmployeeService oge = new OrganogramEmployeeService();
oge.DeleteByEmp(tc, oEmpLifeCycle.EmployeeID);
oge.Save(tc, oEmpLifeCycle.Orgemployees[0]);
}
#endregion Grade-Salary & Organogram Node
//}
if (oEmpLifeCycle.IsNew)
{
int id = tc.GenerateID("EmpLifeCycle", "EmpLifeCycleID");
base.SetObjectID(oEmpLifeCycle, id);
int seqNo = tc.GenerateID("EmpLifeCycle", "SequenceNO",
"Where EmployeeID=" + oEmpLifeCycle.EmployeeID.ToString());
oEmpLifeCycle.Sequence = seqNo;
EmpLifeCycleDA.Insert(tc, oEmpLifeCycle);
// EmployeeHistoryService oEmployeeHistory = new EmployeeHistoryService();
}
else
{
EmpLifeCycleDA.Update(tc, oEmpLifeCycle);
}
//
if (comp != null)
{
// if forcely remove ogranogram node component exist, remove employee from organogram
//OrganogramEmployeeService ogs = new OrganogramEmployeeService();
//ogs.DeleteByEmp(tc, oEmpLifeCycle.EmployeeID);
}
//if (oEmpLifeCycle.IsReHire != null && oEmpLifeCycle.IsReHire == true)
//{
// HREmployee hEmp = new HREmployee();
// hEmp.PrevConfirmDate = oEmpLifeCycle.HREmployee.ConfirDate;
// hEmp.PrevEndofContactDate = oEmpLifeCycle.HREmployee.EndOfContractDate;
// hEmp.PrevHireDate = oEmpLifeCycle.HREmployee.JoiningDate;
// if (oEmpLifeCycle.IsConfirm != null && oEmpLifeCycle.IsConfirm == true)
// hEmp.ConfirDate = oEmpLifeCycle.EffectDate;
// else
// hEmp.ConfirDate = DateTime.MinValue;
// hEmp.EndOfContractDate = null;
// hEmp.JoiningDate = oEmpLifeCycle.EffectDate;
// HREmployeeDA.UpdateRehire(tc, hEmp, oEmpLifeCycle.HREmployee.ID);
//}
//if (oEmpLifeCycle.EffectDate <= SystemInformationService.GetServerDate(tc))
//{
HREmployeeDA.UpdateForEmpLifeCycle(tc, oEmpLifeCycle.HREmployee, oEmpLifeCycle.EmployeeID);
switch (oEmpLifeCycle.EmployeeStatus)
{
case EnumEmployeeStatus.Waitingforjoin:
case EnumEmployeeStatus.Live:
EmployeeHistoryService srvemp = new EmployeeHistoryService();
// if component contain 'IsContinue', update employee status
if (oEmpLifeCycle.IsConfirm != null)
//if ((bool)oEmpLifeCycle.IsContinue == true)
EmployeeDA.DoConfirm(tc, oEmpLifeCycle.EmployeeID, oEmpLifeCycle.EffectDate, true);
//else
// EmployeeDA.UndoConfirm(tc, oEmpLifeCycle.EmployeeID, false);
// if conponent contain isconfirm, update employee confirm property and confrim date.
if (oEmpLifeCycle.IsContinue != null)
{
EmployeeDA.DoContinue(tc, oEmpLifeCycle.EmployeeID);
if (oEmpLifeCycle.PFMemberType != null)
srvemp.DoContinue(tc, oEmpHistory, true);
else srvemp.DoContinue(tc, oEmpHistory, false);
}
// if conponent contain pf member, update employee pfMembership property property and pfMembership date.
if (oEmpLifeCycle.PFMemberType != null)
{
HREmployeeDA.UpdatePFInfo(tc, oEmpLifeCycle.EmployeeID,
(EnumPFMembershipType)oEmpLifeCycle.PFMemberType, oEmpLifeCycle.EffectDate);
}
break;
case EnumEmployeeStatus.Discontinued:
// update end of contract property of emlpoyee by effect date.
EmployeeHistoryService srv = new EmployeeHistoryService();
if (oEmpLifeCycle.IsCurrentMonthIncluded == true)
{
srv.Save(tc, oEmpHistory, true);
EmployeeDA.UpdatemiddleOfMonthDiscontinue(tc,
oEmpLifeCycle.EmployeeID, oEmpLifeCycle.EmployeeStatus, oEmpLifeCycle.EffectDate);
}
else srv.Save(tc, oEmpHistory, false);
EmployeeDA.UpdateStatus(tc, oEmpLifeCycle.EmployeeID, oEmpHistory.ID,
oEmpLifeCycle.EffectDate, oEmpLifeCycle.EmployeeStatus);
//OrganogramEmployeeService OrgEmpSrv = new OrganogramEmployeeService();
//OrgEmpSrv.DeleteByEmp(tc, oEmpLifeCycle.EmployeeID);
break;
case EnumEmployeeStatus.Secondy:
case EnumEmployeeStatus.Suspend:
case EnumEmployeeStatus.Withheld:
EmployeeHistoryService srvwithheld = new EmployeeHistoryService();
// update end of contract property of emlpoyee by effect date.
if (oEmpLifeCycle.IsCurrentMonthIncluded == true)
{
EmployeeDA.UpdatemiddleOfMonthDiscontinue(tc,
oEmpLifeCycle.EmployeeID, oEmpLifeCycle.EmployeeStatus, oEmpLifeCycle.EffectDate);
srvwithheld.Save(tc, oEmpHistory, true);
}
srvwithheld.Save(tc, oEmpHistory, false);
EmployeeDA.UpdateStatus(tc, oEmpLifeCycle.EmployeeID, oEmpHistory.ID,
oEmpLifeCycle.EffectDate, oEmpLifeCycle.EmployeeStatus);
break;
default:
break;
}
//}
// tc.End();
// By Hassan
//oEmpLifeCycle.IsProcessed = true;
// EmpLifeCycleDA.UpdateToProcessed(tc, oEmpLifeCycle);
return oEmpLifeCycle.ID;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public int Insert(TransactionContext tc, EmpLifeCycle item)
{
try
{
int id = tc.GenerateID("EmpLifeCycle", "EmpLifeCycleID");
base.SetObjectID(item, id);
int seqNo = tc.GenerateID("EmpLifeCycle", "SequenceNO",
"Where EmployeeID=" + item.EmployeeID.ToString());
item.Sequence = seqNo;
EmpLifeCycleDA.Insert(tc, item);
}
catch (Exception ex)
{
throw new ServiceException(ex.Message);
}
return item.ID;
}
public void Delete(EmpLifeCycle oEmpLifeCycle, DateTime NextPayProcessDate)
{
oEmpLifeCycle = this.Get(oEmpLifeCycle.ID);
if (oEmpLifeCycle.SalaryMonth < NextPayProcessDate)
{
throw new Exception("Delete is not allowed on Last month approved data");
}
TransactionContext tc = null;
try
{
// find the life cycle contains the 'forcely remove organogram'
EmployeeStatus oempStatus = (new EmployeeStatusService()).Get((int)oEmpLifeCycle.StatusDetailID);
EmployeeStatus.EmpStatusComponent comp = oempStatus.EmployeeStatusComponents.Find(
delegate(EmployeeStatus.EmpStatusComponent lcc)
{
return lcc.ComponentType == EnumLifeCycleComponent.Force_Remove_From_Position;
});
tc = TransactionContext.Begin(true);
EmpLifeCycleDA.Delete(tc, oEmpLifeCycle);
//if (oEmpLifeCycle.EffectDate <= SystemInformationService.GetServerDate(tc))
//{
#region Update Grade & salary Information
if (oEmpLifeCycle.GradeSalaryAssesmentID !=null && oEmpLifeCycle.GradeSalaryAssesmentID != 0)
{
EmployeeGradeSalaryService sgs = new EmployeeGradeSalaryService();
oEmpLifeCycle.EmployeeGradeSalary = sgs.GetbyID(tc, (int) oEmpLifeCycle.GradeSalaryAssesmentID);
if (oEmpLifeCycle.EmployeeGradeSalary != null)
{
sgs.DeleteFromDate(tc, oEmpLifeCycle.EmployeeID, oEmpLifeCycle.EffectDate,
EnumArrearType.ToCalculate);
sgs.Delete(tc, oEmpLifeCycle.EmployeeGradeSalary);
}
}
#endregion update Grade & salary Information
#region Update costcenter information
if (oEmpLifeCycle.CostCenterID != null && oEmpLifeCycle.CostCenterID != 0)
{
EmployeeCostCenterService oCCSevice = new EmployeeCostCenterService();
oCCSevice.Delete(tc, (int) oEmpLifeCycle.EmployeeCCID);
//object crgID = EmpLifeCycleDA.GetCrgId(tc, oEmpLifeCycle.EmployeeID);
//if (crgID != null)
//{
// EmployeeCostCenter crg = new EmployeeCostCenter();
// crg.EmployeeID = oEmpLifeCycle.EmployeeID;
// crg.MonthDate = NextPayProcessDate;
// crg.CostCenterID = (Convert.ToInt32(crgID));
// crg.Percentage = 100;
// crg.CreatedBy = oEmpLifeCycle.CreatedBy;
// crg.IsCurrentCC = true;
// crg.CreatedDate = DateTime.Today;
// oEmpLifeCycle.EmployeeCostCenters = new List<EmployeeCostCenter>();
// oEmpLifeCycle.EmployeeCostCenters.Add(crg);
// oCCSevice.Save(tc, oEmpLifeCycle.EmployeeCostCenters);
//}
}
#endregion Update costcenter information
#region Update Organogram information
if (comp != null || (oEmpLifeCycle.NodeID != 0))
{
OrganogramEmployeeService ogs = new OrganogramEmployeeService();
ogs.DeleteByEmp(tc, oEmpLifeCycle.EmployeeID);
object nodeID = EmpLifeCycleDA.GetNodeId(tc, oEmpLifeCycle.EmployeeID);
if (nodeID != null)
{
OrganogramEmployeeService oIsoccupied = new OrganogramEmployeeService();
List<OrganogramEmployee> occupied = oIsoccupied.Get(tc, (Convert.ToInt32(nodeID)));
if (occupied != null && occupied.Count > 0)
throw new ServiceException(
"Delete is not allowed due to previous assigned position is already occupied by another employee.");
object effectDate = EmpLifeCycleDA.GetNodeAssignDate(tc, oEmpLifeCycle.EmployeeID);
OrganogramEmployee ogemp = new OrganogramEmployee();
ogemp.AssignDate = Convert.ToDateTime(effectDate);
ogemp.EmployeeID = oEmpLifeCycle.EmployeeID;
ogemp.NodeID = (Convert.ToInt32(nodeID));
ogemp.CreatedBy = oEmpLifeCycle.CreatedBy;
ogemp.CreatedDate = Convert.ToDateTime(effectDate);
ogs.Save(tc, ogemp);
}
}
#endregion Update Organogram information
EmpLifeCycleDA.UpdateEmployee(tc, oEmpLifeCycle);
//}
tc.End();
}
catch (ServiceException ex)
{
throw new ServiceException(ex.Message);
}
catch (Exception e)
{
#region Handle Exception
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
finally
{
if (tc != null)
tc.HandleError();
}
}
#endregion
}
}
#endregion