1693 lines
81 KiB
C#
1693 lines
81 KiB
C#
using System;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using Ease.CoreV35;
|
|
using Ease.CoreV35.Model;
|
|
using Ease.CoreV35.DataAccess;
|
|
using System.Collections.Generic;
|
|
using Payroll.BO;
|
|
using Ease.CoreV35.Caching;
|
|
|
|
namespace Payroll.Service
|
|
{
|
|
#region EmpLifeCycle Service
|
|
[Serializable]
|
|
public class EmpLifeCycleService : ServiceTemplate, IEmpLifeCycleService
|
|
{
|
|
public event ProgressStatus ProgressStatus;
|
|
public event ProcessStatus ProcessStatus;
|
|
|
|
#region Private functions and declaration
|
|
Cache _cache = new Cache(typeof(EmpLifeCycle));
|
|
|
|
#endregion
|
|
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.GetID("EmpLifeCycleID"));
|
|
oEmpLifeCycle.EffectDate = oReader.GetDateTime("EffectDate").Value;
|
|
oEmpLifeCycle.NodeID = oReader.GetID("NodeID");
|
|
oEmpLifeCycle.GrossSalary = oReader.GetDouble("GrossSalary");
|
|
oEmpLifeCycle.BasicSalary = oReader.GetDouble("BasicSalary");
|
|
oEmpLifeCycle.GradeID = oReader.GetID("GradeID");
|
|
oEmpLifeCycle.CategoryID = oReader.GetID("CategoryID");
|
|
oEmpLifeCycle.CompanyID = oReader.GetID("CompanyID");
|
|
oEmpLifeCycle.FunctionID = oReader.GetID("FunctionID");
|
|
oEmpLifeCycle.DesignationID = oReader.GetID("DesignationID");
|
|
oEmpLifeCycle.LocationID = oReader.GetID("LocationID");
|
|
oEmpLifeCycle.DepartmentID = oReader.GetID("DepartmentID");
|
|
oEmpLifeCycle.CostCenterID = oReader.GetID("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.GetID("EmployeeID");
|
|
oEmpLifeCycle.StatusDetailID = oReader.GetID("StatusDetailID");
|
|
oEmpLifeCycle.Remarks = oReader.GetString("Remarks");
|
|
oEmpLifeCycle.Description = oReader.GetString("Description");
|
|
if(oReader.GetInt32("Status")!=null)
|
|
oEmpLifeCycle.Status = (EnumEmployeeStatus)oReader.GetInt32("Status").Value;
|
|
oEmpLifeCycle.Sequence = oReader.GetInt32("SequenceNO").Value;
|
|
if(oReader.GetID("CreatedBy")!=null)
|
|
oEmpLifeCycle.CreatedBy = oReader.GetID("CreatedBy");
|
|
oEmpLifeCycle.CreatedDate =oReader.GetDateTime("CreationDate")==null?DateTime.MinValue: oReader.GetDateTime("CreationDate").Value;
|
|
oEmpLifeCycle.ModifiedBy = oReader.GetID("ModifiedBy");
|
|
oEmpLifeCycle.ModifiedDate = oReader.GetDateTime("ModifiedDate");
|
|
oEmpLifeCycle.SalaryMonth = oReader.GetDateTime("SalaryMonth").Value;
|
|
oEmpLifeCycle.IsCurrentMonthIncluded = oReader.GetBoolean("IsCurrentMonthIncluded").Value;
|
|
oEmpLifeCycle.GradeSalaryAssesmentID = oReader.GetID("GradeSalaryAssesmentID");
|
|
oEmpLifeCycle.EmployeeCCID = oReader.GetID("EmployeeCCID");
|
|
oEmpLifeCycle.Role = (EnumRole)oReader.GetInt32("Role").Value;
|
|
oEmpLifeCycle.DesignationText = oReader.GetString("DesignationText");
|
|
oEmpLifeCycle.IsProcessed = oReader.GetBoolean("IsProcessed").Value;
|
|
this.SetObjectState(oEmpLifeCycle, Ease.CoreV35.ObjectState.Saved);
|
|
}
|
|
protected override T CreateObject<T>(DataReader oReader)
|
|
{
|
|
EmpLifeCycle oEmpLifeCycle = new EmpLifeCycle();
|
|
MapObject(oEmpLifeCycle, oReader);
|
|
return oEmpLifeCycle as T;
|
|
}
|
|
protected EmpLifeCycle CreateObject(DataReader oReader)
|
|
{
|
|
EmpLifeCycle oEmpLifeCycle = new EmpLifeCycle();
|
|
MapObject(oEmpLifeCycle, oReader);
|
|
return oEmpLifeCycle;
|
|
}
|
|
#region Service implementation
|
|
public int GetPrvGradeId(ID nEmpID, ID 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 int GetPrvLocationId(ID nEmpID, ID 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(ID nEmpID, ID 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(ID 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(ID 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(ID lifecycleID)
|
|
{
|
|
EmpLifeCycle oEmpLifeCycle = new EmpLifeCycle();
|
|
#region Cache Header
|
|
oEmpLifeCycle = _cache["Get", lifecycleID] as EmpLifeCycle;
|
|
if (oEmpLifeCycle != null)
|
|
return oEmpLifeCycle;
|
|
#endregion
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oreader = new DataReader(EmpLifeCycleDA.Get(tc, lifecycleID));
|
|
if (oreader.Read())
|
|
{
|
|
oEmpLifeCycle = this.CreateObject<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
|
|
}
|
|
#region Cache Footer
|
|
_cache.Add(oEmpLifeCycle, "Get", lifecycleID);
|
|
#endregion
|
|
return oEmpLifeCycle;
|
|
}
|
|
|
|
public ObjectsTemplate<EmpLifeCycle> getByStatus(int p, DateTime startDate, DateTime endDate)
|
|
{
|
|
ObjectsTemplate<EmpLifeCycle> oEmployees = new ObjectsTemplate<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 void Save2(ObjectsTemplate<EmpLifeCycle> oEmpLifeCycles)
|
|
{
|
|
int nTotal = oEmpLifeCycles.Count;
|
|
GlobalFunctions.SetProgressbarMaxValue = nTotal;
|
|
UpdateProgressStatus(EnumProcessStatus.Start);
|
|
int nCount = 1;
|
|
TransactionContext tc = null;
|
|
tc = TransactionContext.Begin(true);
|
|
try
|
|
{
|
|
foreach (EmpLifeCycle oEmpLifeCycle in oEmpLifeCycles)
|
|
{
|
|
|
|
UpdateprocessStatus("Saving data " + nCount.ToString() + "/" + nTotal.ToString());
|
|
UpdateProgressStatus(EnumProcessStatus.PerformStep);
|
|
//if (nCount < 10769)
|
|
//{
|
|
// nCount++;
|
|
// continue;
|
|
//}
|
|
// find the life cycle contains the 'forcely remove organogram'
|
|
EmployeeStatus oempStatus = EmployeeStatus.Get(oEmpLifeCycle.StatusDetailID);
|
|
oEmpLifeCycle.Description = oempStatus == null ? "Not Found" : oempStatus.Description;
|
|
//EmployeeStatus.EmpStatusComponent comp = oempStatus.EmployeeStatusComponents.Find(delegate(EmployeeStatus.EmpStatusComponent lcc) { return lcc.ComponentType == (int)EnumLifeCycleComponent.Force_Remove_From_Position; });
|
|
//if (oEmpLifeCycle.EmployeePosting != null)
|
|
//{
|
|
// EmployeePostingService srv = new EmployeePostingService();
|
|
// srv.Save(tc, oEmpLifeCycle.EmployeePosting);
|
|
//}
|
|
|
|
EmployeeHistory oEmpHistory = new EmployeeHistory();
|
|
oEmpHistory.EffectDate = oEmpLifeCycle.EffectDate;
|
|
oEmpHistory.EmployeeID = oEmpLifeCycle.EmployeeID;
|
|
oEmpHistory.EmployeeStatus = oEmpLifeCycle.Status;
|
|
oEmpHistory.Remarks = oEmpLifeCycle.Status.ToString();
|
|
ObjectsTemplate<EmployeeGradeSalary> gradeSalaries = null;
|
|
|
|
gradeSalaries = new ObjectsTemplate<EmployeeGradeSalary>();
|
|
if (oEmpLifeCycle.EmployeeGradeSalary != null)
|
|
{
|
|
oEmpLifeCycle.EmployeeGradeSalary.CreatedBy = ID.FromInteger(1);
|
|
oEmpLifeCycle.EmployeeGradeSalary.CreatedDate = oEmpLifeCycle.CreatedDate;
|
|
gradeSalaries.Add(oEmpLifeCycle.EmployeeGradeSalary);
|
|
}
|
|
//gradeSalaries = oEmpLifeCycle.EmployeeGradeSalary.process();
|
|
|
|
//if (oEmpLifeCycle.EffectDate <= SystemInformationService.GetServerDate(tc))
|
|
//{
|
|
#region Cost-center update
|
|
if (oEmpLifeCycle.CostCenterID != null)
|
|
{
|
|
EmployeeCostCenterService oEmpCCService = new EmployeeCostCenterService();
|
|
EmployeeCostCenter oEmpCC = new EmployeeCostCenter();
|
|
ObjectsTemplate<EmployeeCostCenter> oEmpCCs = new ObjectsTemplate<EmployeeCostCenter>();
|
|
oEmpCC.CostCenterID = 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.TillDate = oEmpCC.MonthDate;
|
|
oEmpCCs.Add(oEmpCC);
|
|
oEmpCC.Save(oEmpCCs);
|
|
//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.Save2(tc, gradeSalaries);
|
|
// Grade Salary assignment object can be multiple for arrear item and last item
|
|
// arrear not present item.
|
|
if (gradeSalaries.Count > 0)
|
|
oEmpLifeCycle.GradeSalaryAssesmentID = gradeSalaries[0].ID;
|
|
//oEmpLifeCycle.GradeSalaryAssesmentID = gradeSalaries[gradeSalaries.Count - 1].ID;
|
|
}
|
|
|
|
// 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
|
|
//}
|
|
|
|
if (oEmpLifeCycle.IsNew)
|
|
{
|
|
int id = tc.GenerateID("EmpLifeCycle", "EmpLifeCycleID");
|
|
base.SetObjectID(oEmpLifeCycle, ID.FromInteger(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.Status)
|
|
{
|
|
case EnumEmployeeStatus.Waitingforjoin:
|
|
case EnumEmployeeStatus.Live:
|
|
|
|
// 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 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.Secondy:
|
|
case EnumEmployeeStatus.Suspend:
|
|
case 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;
|
|
}
|
|
//}
|
|
nCount++;
|
|
}
|
|
UpdateProgressStatus(EnumProcessStatus.End);
|
|
tc.End();
|
|
// return ID.FromInteger(1);
|
|
}
|
|
|
|
catch (Exception e)
|
|
{
|
|
nCount = 0;
|
|
UpdateProgressStatus(EnumProcessStatus.End);
|
|
#region Handle Exception
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
#endregion
|
|
}
|
|
}
|
|
|
|
public ObjectsTemplate<EmpLifeCycle> GetByDate(DateTime startDate, DateTime endDate, ID PayrolltypeID)
|
|
{
|
|
ObjectsTemplate<EmpLifeCycle> oEmployees = new ObjectsTemplate<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 ObjectsTemplate<EmpLifeCycle> GetByDate(DateTime startDate, DateTime endDate, ID PayrolltypeID,bool approveID)
|
|
{
|
|
ObjectsTemplate<EmpLifeCycle> oEmployees = new ObjectsTemplate<EmpLifeCycle>();
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oreader = new DataReader(EmpLifeCycleDA.GetByDate(tc, startDate, endDate, PayrolltypeID, approveID));
|
|
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 ObjectsTemplate<EmpLifeCycle> GetByCreateDate(DateTime startDate, DateTime endDate, int payrollTypeID)
|
|
{
|
|
ObjectsTemplate<EmpLifeCycle> oEmployees = new ObjectsTemplate<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 ObjectsTemplate<EmpLifeCycle> Get(EnumStatus sts, ID PayrolltypeID)
|
|
{
|
|
ObjectsTemplate<EmpLifeCycle> oEmployees = new ObjectsTemplate<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 ObjectsTemplate<EmpLifeCycle> GetEmpID(ID nEmpID)
|
|
{
|
|
#region Cache Header
|
|
ObjectsTemplate<EmpLifeCycle> EmpLifeCycles = _cache["Get", nEmpID] as ObjectsTemplate<EmpLifeCycle>;
|
|
if (EmpLifeCycles != null)
|
|
return EmpLifeCycles;
|
|
#endregion
|
|
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
|
|
}
|
|
#region Cache Footer
|
|
_cache.Add(EmpLifeCycles, "Get", nEmpID);
|
|
#endregion
|
|
return EmpLifeCycles;
|
|
}
|
|
|
|
public ObjectsTemplate<EmpLifeCycle> GetEmpID(ID employeeID, DateTime effectDate)
|
|
{
|
|
#region Cache Header
|
|
ObjectsTemplate<EmpLifeCycle> EmpLifeCycles = _cache["Get", employeeID] as ObjectsTemplate<EmpLifeCycle>;
|
|
if (EmpLifeCycles != null)
|
|
return EmpLifeCycles;
|
|
#endregion
|
|
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
|
|
}
|
|
#region Cache Footer
|
|
_cache.Add(EmpLifeCycles, "Get", employeeID);
|
|
#endregion
|
|
return EmpLifeCycles;
|
|
}
|
|
|
|
public void ProcessGradeSalary(EmpLifeCycle item)
|
|
{
|
|
if ((item.BasicSalary != null || item.GrossSalary != null) || (item.GradeID != null && item.GradeID.IsUnassigned == false))
|
|
{
|
|
|
|
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 || item.GradeID.IsUnassigned == true)
|
|
{
|
|
if (item.Employee.GradeID == null)
|
|
throw new ServiceException("Grade not yet assigned of employee.");
|
|
ogs.GradeID = item.Employee.GradeID;
|
|
}
|
|
else ogs.GradeID = 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 = item.StatusDetailID;
|
|
ogs.EffectDate = item.EffectDate;
|
|
item.EmployeeGradeSalary = ogs;
|
|
}
|
|
}
|
|
public EmpLifeCycle GetLastPosition(int nEmpID)
|
|
{
|
|
EmpLifeCycle oEmpLifeCycle = new EmpLifeCycle();
|
|
#region Cache Header
|
|
oEmpLifeCycle = _cache["GetLastPosition", nEmpID] as EmpLifeCycle;
|
|
if (oEmpLifeCycle != null)
|
|
return oEmpLifeCycle;
|
|
#endregion
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oreader = new DataReader(EmpLifeCycleDA.GetLastPosition(tc, nEmpID));
|
|
if (oreader.Read())
|
|
{
|
|
oEmpLifeCycle = this.CreateObject<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
|
|
}
|
|
#region Cache Footer
|
|
_cache.Add(oEmpLifeCycle, "GetLastPosition", nEmpID);
|
|
#endregion
|
|
return oEmpLifeCycle;
|
|
}
|
|
|
|
public ObjectsTemplate<EmpLifeCycle> GetNotYetProcessUptoToday()
|
|
{
|
|
ObjectsTemplate<EmpLifeCycle> oEmployees = new ObjectsTemplate<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 ID Insert(TransactionContext tc, EmpLifeCycle item)
|
|
{
|
|
try
|
|
{
|
|
int id = tc.GenerateID("EmpLifeCycle", "EmpLifeCycleID");
|
|
base.SetObjectID(item, ID.FromInteger(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 save(EmpLifeCycle oEmpLifeCycle,TransactionContext tc,bool bNeedToDelete)
|
|
{
|
|
try
|
|
{
|
|
if (bNeedToDelete)
|
|
{
|
|
EmpLifeCycleDA.DeleteByGradeSalaryAssesmentID(tc, oEmpLifeCycle);
|
|
}
|
|
int id = tc.GenerateID("EmpLifeCycle", "EmpLifeCycleID");
|
|
base.SetObjectID(oEmpLifeCycle, ID.FromInteger(id));
|
|
int seqNo = tc.GenerateID("EmpLifeCycle", "SequenceNO", "Where EmployeeID=" + oEmpLifeCycle.EmployeeID.ToString());
|
|
oEmpLifeCycle.Sequence = seqNo;
|
|
EmpLifeCycleDA.Insert(tc, oEmpLifeCycle);
|
|
}
|
|
catch (Exception exp)
|
|
{
|
|
throw new Exception(exp.Message);
|
|
}
|
|
|
|
}
|
|
|
|
public void Save(ObjectsTemplate<EmpLifeCycle> lifecycles, DateTime salaryCutoffDate, TransactionContext tc)
|
|
{
|
|
try
|
|
{
|
|
foreach (EmpLifeCycle item in lifecycles)
|
|
{
|
|
if (item.EmployeeID != null && !item.EmployeeID.IsUnassigned && 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.Integer);
|
|
|
|
item.HREmployee.GradeID = (item.GradeID == null || item.GradeID.IsUnassigned) ?
|
|
(item.Employee == null ? null : item.Employee.GradeID) :
|
|
item.GradeID;
|
|
|
|
item.HREmployee.CategoryID = (item.CategoryID == null || item.CategoryID.IsUnassigned) ?
|
|
(item.Employee == null ? null : item.Employee.CategoryID) :
|
|
item.CategoryID;
|
|
item.HREmployee.LocationID = (item.LocationID == null || item.LocationID.IsUnassigned) ?
|
|
(item.Employee == null ? null : item.Employee.LocationID) :
|
|
item.LocationID;
|
|
item.HREmployee.DesignationID = (item.DesignationID == null || item.DesignationID.IsUnassigned) ?
|
|
(item.Employee == null ? null : item.Employee.DesignationID) :
|
|
item.DesignationID;
|
|
|
|
item.HREmployee.DepartmentID = (item.DepartmentID == null || item.DepartmentID.IsUnassigned) ?
|
|
(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.Save(item, tc, salaryCutoffDate);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new ServiceException(ex.Message);
|
|
}
|
|
}
|
|
|
|
|
|
public ID Save(EmpLifeCycle oEmpLifeCycle)
|
|
{
|
|
// find the life cycle contains the 'forcely remove organogram'
|
|
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;
|
|
oEmpHistory.Remarks = oEmpLifeCycle.Status.ToString();
|
|
ObjectsTemplate<EmployeeGradeSalary> gradeSalaries=null;
|
|
|
|
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 != null)
|
|
{
|
|
EmployeeCostCenterService oEmpCCService = new EmployeeCostCenterService();
|
|
EmployeeCostCenter oEmpCC = new EmployeeCostCenter();
|
|
ObjectsTemplate<EmployeeCostCenter> oEmpCCs = new ObjectsTemplate<EmployeeCostCenter>();
|
|
oEmpCC.CostCenterID = 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.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, 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;
|
|
}
|
|
|
|
// 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
|
|
//}
|
|
|
|
if (oEmpLifeCycle.IsNew)
|
|
{
|
|
int id = tc.GenerateID("EmpLifeCycle", "EmpLifeCycleID");
|
|
base.SetObjectID(oEmpLifeCycle, ID.FromInteger(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.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(oEmpLifeCycle.HREmployee.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)
|
|
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;
|
|
}
|
|
//}
|
|
|
|
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 void SaveIntegration(EmpLifeCycle oEmpLifeCycle,TransactionContext tc,Employee oEmp)
|
|
{
|
|
// find the life cycle contains the 'forcely remove organogram'
|
|
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;
|
|
oEmpHistory.Remarks = oEmpLifeCycle.Status.ToString();
|
|
|
|
ObjectsTemplate<EmployeeGradeSalary> gradeSalaries = null;
|
|
|
|
if (oEmpLifeCycle.EmployeeGradeSalary != null)
|
|
{
|
|
oEmpLifeCycle.EmployeeGradeSalary.EmployeeID = oEmpLifeCycle.EmployeeID;
|
|
gradeSalaries = oEmpLifeCycle.EmployeeGradeSalary.process();
|
|
}
|
|
|
|
// tc = TransactionContext.Begin(true);
|
|
|
|
//if (oEmpLifeCycle.EffectDate <= SystemInformationService.GetServerDate(tc))
|
|
//{
|
|
#region Cost-center update
|
|
if (oEmpLifeCycle.CostCenterID != null)
|
|
{
|
|
EmployeeCostCenterService oEmpCCService = new EmployeeCostCenterService();
|
|
EmployeeCostCenter oEmpCC = new EmployeeCostCenter();
|
|
ObjectsTemplate<EmployeeCostCenter> oEmpCCs = new ObjectsTemplate<EmployeeCostCenter>();
|
|
oEmpCC.CostCenterID = 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.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, 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;
|
|
}
|
|
|
|
// 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
|
|
//}
|
|
|
|
if (oEmpLifeCycle.IsNew)
|
|
{
|
|
int id = tc.GenerateID("EmpLifeCycle", "EmpLifeCycleID");
|
|
base.SetObjectID(oEmpLifeCycle, ID.FromInteger(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.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(e.Message, e);
|
|
#endregion
|
|
}
|
|
}
|
|
|
|
public void Save(ObjectsTemplate<EmpLifeCycle> lifecycles, DateTime salaryCutoffDate)
|
|
{
|
|
TransactionContext tc = null;
|
|
|
|
try
|
|
{
|
|
foreach (EmpLifeCycle item in lifecycles)
|
|
{
|
|
if (item.EmployeeID != null && !item.EmployeeID.IsUnassigned && item.Employee == null)
|
|
{
|
|
item.Employee = (new EmployeeService()).Get(tc, item.EmployeeID);
|
|
}
|
|
item.HREmployee = new HREmployee();
|
|
item.HREmployee.SetObjectID(item.EmployeeID.Integer);
|
|
|
|
item.HREmployee.GradeID = (item.GradeID == null || item.GradeID.IsUnassigned) ?
|
|
(item.Employee == null ? null : item.Employee.GradeID) :
|
|
item.GradeID;
|
|
|
|
item.HREmployee.CategoryID = (item.CategoryID == null || item.CategoryID.IsUnassigned) ?
|
|
(item.Employee == null ? null : item.Employee.CategoryID) :
|
|
item.CategoryID;
|
|
item.HREmployee.LocationID = (item.LocationID == null || item.LocationID.IsUnassigned) ?
|
|
(item.Employee == null ? null : item.Employee.LocationID) :
|
|
item.LocationID;
|
|
item.HREmployee.DesignationID = (item.DesignationID == null || item.DesignationID.IsUnassigned) ?
|
|
(item.Employee == null ? null : item.Employee.DesignationID) :
|
|
item.DesignationID;
|
|
|
|
item.HREmployee.DepartmentID = (item.DepartmentID == null || item.DepartmentID.IsUnassigned) ?
|
|
(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);
|
|
|
|
tc.End();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
throw new ServiceException(ex.Message);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public ID Save(EmpLifeCycle oEmpLifeCycle, TransactionContext tc, DateTime salaryCutoffDate)
|
|
{
|
|
|
|
oEmpLifeCycle.SalaryMonth = SystemInformation.CurrentSysInfo.NextPayProcessDate;
|
|
// temporary disabled
|
|
if (salaryCutoffDate <= DateTime.Today &&
|
|
salaryCutoffDate.Month == SystemInformation.CurrentSysInfo.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 (SystemInformation.CurrentSysInfo.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(oEmpLifeCycle.StatusDetailID, tc);
|
|
EmployeeStatus.EmpStatusComponent comp = null;
|
|
if (oempStatus != null)
|
|
{
|
|
comp = (new EmployeeStatusService()).GetChild(oEmpLifeCycle.StatusDetailID, tc)
|
|
.Where(o => o.ComponentType == (int)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.Status;
|
|
oEmpHistory.Remarks = oEmpLifeCycle.Status.ToString();
|
|
oEmpHistory.CreatedBy = User.CurrentUser.ID;
|
|
oEmpHistory.CreatedDate = DateTime.Today;
|
|
ObjectsTemplate<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 != null && oEmpLifeCycle.CostCenterID.IsUnassigned == false)
|
|
{
|
|
EmployeeCostCenterService oEmpCCService = new EmployeeCostCenterService();
|
|
EmployeeCostCenter oEmpCC = new EmployeeCostCenter();
|
|
ObjectsTemplate<EmployeeCostCenter> oEmpCCs = new ObjectsTemplate<EmployeeCostCenter>();
|
|
oEmpCC.CostCenterID = 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.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, 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;
|
|
}
|
|
|
|
// 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
|
|
|
|
//}
|
|
|
|
if (oEmpLifeCycle.IsNew)
|
|
{
|
|
int id = tc.GenerateID("EmpLifeCycle", "EmpLifeCycleID");
|
|
base.SetObjectID(oEmpLifeCycle, ID.FromInteger(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.Status)
|
|
{
|
|
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.Status, oEmpLifeCycle.EffectDate);
|
|
}
|
|
else srv.Save(tc, oEmpHistory, false);
|
|
EmployeeDA.UpdateStatus(tc, oEmpLifeCycle.EmployeeID, oEmpHistory.ID,
|
|
oEmpLifeCycle.EffectDate, oEmpLifeCycle.Status);
|
|
|
|
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.Status, oEmpLifeCycle.EffectDate);
|
|
srvwithheld.Save(tc, oEmpHistory, true);
|
|
|
|
} srvwithheld.Save(tc, oEmpHistory, false);
|
|
EmployeeDA.UpdateStatus(tc, oEmpLifeCycle.EmployeeID, oEmpHistory.ID,
|
|
oEmpLifeCycle.EffectDate, oEmpLifeCycle.Status);
|
|
|
|
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 ID Save(ObjectsTemplate<EmpLifeCycle> oEmpLifeCycles)
|
|
{
|
|
TransactionContext tc = null;
|
|
tc = TransactionContext.Begin(true);
|
|
try
|
|
{
|
|
foreach (EmpLifeCycle oEmpLifeCycle in oEmpLifeCycles)
|
|
{
|
|
// find the life cycle contains the 'forcely remove organogram'
|
|
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; });
|
|
|
|
|
|
EmployeeHistory oEmpHistory = new EmployeeHistory();
|
|
oEmpHistory.EffectDate = oEmpLifeCycle.EffectDate;
|
|
oEmpHistory.EmployeeID = oEmpLifeCycle.EmployeeID;
|
|
oEmpHistory.EmployeeStatus = oEmpLifeCycle.Status;
|
|
oEmpHistory.Remarks = oEmpLifeCycle.Status.ToString();
|
|
ObjectsTemplate<EmployeeGradeSalary> gradeSalaries = null;
|
|
|
|
if (oEmpLifeCycle.EmployeeGradeSalary != null)
|
|
gradeSalaries = oEmpLifeCycle.EmployeeGradeSalary.process();
|
|
|
|
//if (oEmpLifeCycle.EffectDate <= SystemInformationService.GetServerDate(tc))
|
|
//{
|
|
#region Cost-center update
|
|
if (oEmpLifeCycle.CostCenterID != null)
|
|
{
|
|
EmployeeCostCenterService oEmpCCService = new EmployeeCostCenterService();
|
|
EmployeeCostCenter oEmpCC = new EmployeeCostCenter();
|
|
ObjectsTemplate<EmployeeCostCenter> oEmpCCs = new ObjectsTemplate<EmployeeCostCenter>();
|
|
oEmpCC.CostCenterID = 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.TillDate = oEmpCC.MonthDate;
|
|
oEmpCCs.Add(oEmpCC);
|
|
oEmpCC.Save(oEmpCCs);
|
|
//oEmpCCService.Save(tc, oEmpCCs);
|
|
oEmpLifeCycle.EmployeeCCID = oEmpCCs[0].ID;
|
|
}
|
|
#endregion Cost-center update
|
|
#region Grade-Salary & Organogram Node
|
|
if (oEmpLifeCycle.EmployeeGradeSalary != null)
|
|
{
|
|
// First delete today and forwarding date data
|
|
EmployeeGradeSalaryService sgs = new EmployeeGradeSalaryService();
|
|
if(Payroll.BO.SystemInformation.CurrentSysInfo.LastPayProcessDate <oEmpLifeCycle.EffectDate)
|
|
sgs.DeleteFromDate(tc,oEmpLifeCycle.EmployeeID, oEmpLifeCycle.EffectDate, 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;
|
|
}
|
|
|
|
// 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
|
|
//}
|
|
|
|
if (oEmpLifeCycle.IsNew)
|
|
{
|
|
int id = tc.GenerateID("EmpLifeCycle", "EmpLifeCycleID");
|
|
base.SetObjectID(oEmpLifeCycle, ID.FromInteger(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.Status)
|
|
{
|
|
case EnumEmployeeStatus.Waitingforjoin:
|
|
case EnumEmployeeStatus.Live:
|
|
|
|
// 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 conponent contain pf member, update employee pfMembership property property and pfMembership date.
|
|
if (oEmpLifeCycle.PFMemberType != null)
|
|
if (oempStatus.ID != ID.FromInteger(3))
|
|
HREmployeeDA.UpdatePFInfo(tc, oEmpLifeCycle.EmployeeID, (EnumPFMembershipType)oEmpLifeCycle.PFMemberType, oEmpLifeCycle.EffectDate);
|
|
else
|
|
HREmployeeDA.UpdatePFAndConfirmationInfo(tc, oEmpLifeCycle.EmployeeID, (EnumPFMembershipType)oEmpLifeCycle.PFMemberType, oEmpLifeCycle.EffectDate);
|
|
break;
|
|
case EnumEmployeeStatus.Discontinued:
|
|
case EnumEmployeeStatus.Secondy:
|
|
case EnumEmployeeStatus.Suspend:
|
|
case 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;
|
|
}
|
|
//}
|
|
|
|
}
|
|
tc.End();
|
|
return ID.FromInteger(1);
|
|
}
|
|
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
#endregion
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public void Delete(EmpLifeCycle oEmpLifeCycle)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
// find the life cycle contains the 'forcely remove organogram'
|
|
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; });
|
|
|
|
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.IsUnassigned == false)
|
|
{
|
|
EmployeeGradeSalaryService sgs = new EmployeeGradeSalaryService();
|
|
oEmpLifeCycle.EmployeeGradeSalary = sgs.GetbyID(tc, 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.IsUnassigned == false)
|
|
{
|
|
EmployeeCostCenterService oCCSevice = new EmployeeCostCenterService();
|
|
oCCSevice.Delete(tc, oEmpLifeCycle.EmployeeCCID);
|
|
object crgID = EmpLifeCycleDA.GetCrgId(tc, oEmpLifeCycle.EmployeeID);
|
|
if (crgID != null)
|
|
{
|
|
EmployeeCostCenter crg = new EmployeeCostCenter();
|
|
crg.EmployeeID = oEmpLifeCycle.EmployeeID;
|
|
crg.MonthDate = Payroll.BO.SystemInformation.CurrentSysInfo.NextPayProcessDate;
|
|
crg.CostCenterID = ID.FromInteger(Convert.ToInt32(crgID));
|
|
crg.Percentage = 100;
|
|
crg.CreatedBy = User.CurrentUser.ID;
|
|
crg.IsCurrentCC = true;
|
|
crg.CreatedDate = DateTime.Today;
|
|
oEmpLifeCycle.EmployeeCostCenters = new ObjectsTemplate<EmployeeCostCenter>();
|
|
oEmpLifeCycle.EmployeeCostCenters.Add(crg);
|
|
oCCSevice.Save(tc, oEmpLifeCycle.EmployeeCostCenters);
|
|
}
|
|
}
|
|
#endregion Update costcenter information
|
|
#region Update Organogram information
|
|
if (comp!=null || (oEmpLifeCycle.NodeID != null && oEmpLifeCycle.NodeID.IsUnassigned == false))
|
|
{
|
|
OrganogramEmployeeService ogs = new OrganogramEmployeeService();
|
|
ogs.DeleteByEmp(tc, oEmpLifeCycle.EmployeeID);
|
|
object nodeID = EmpLifeCycleDA.GetNodeId(tc, oEmpLifeCycle.EmployeeID);
|
|
if (nodeID != null)
|
|
{
|
|
OrganogramEmployeeService oIsoccupied = new OrganogramEmployeeService();
|
|
ObjectsTemplate<OrganogramEmployee> occupied = oIsoccupied.Get(tc, ID.FromInteger(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 = ID.FromInteger(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
|
|
}
|