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

693 lines
24 KiB
C#

using System;
using System.Data;
using Ease.Core.Model;
using Ease.Core.DataAccess;
using Ease.Core;
using System.Collections.Generic;
using Ease.Core.Utility;
using HRM.BO;
namespace HRM.DA
{
public class BudgetProcessMonthlyService : ServiceTemplate, IBudgetProcessMonthlyService
{
#region Object Mapping
#region Parent Object Mapping
private void MapObject(BudgetProcessMonthly oBudgetProcessMonthly, DataReader oReader)
{
SetObjectID(oBudgetProcessMonthly, (oReader.GetInt32("BudgetProcessMonthlyID").Value));
oBudgetProcessMonthly.BudgetID = oReader.GetInt32("BudgetID", 0);
oBudgetProcessMonthly.DepartmentID = oReader.GetInt32("DepartmentID", 0);
oBudgetProcessMonthly.EmployeeID = oReader.GetInt32("EmployeeID", 0);
oBudgetProcessMonthly.GradeID = oReader.GetInt32("GradeID", 0);
oBudgetProcessMonthly.IsConfirm = oReader.GetInt32("LocationID").Value;
oBudgetProcessMonthly.Month = oReader.GetDateTime("Month").Value;
oBudgetProcessMonthly.NewJoinerID = oReader.GetInt32("NewJoinerID", 0);
oBudgetProcessMonthly.NewJoinerName = oReader.GetString("NewJoinerName");
oBudgetProcessMonthly.PayrollTypeID = oReader.GetInt32("PayrollTypeID", 0);
SetObjectState(oBudgetProcessMonthly, ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader dr)
{
BudgetProcessMonthly oBudgetProcessMonthly = new BudgetProcessMonthly();
MapObject(oBudgetProcessMonthly, dr);
return oBudgetProcessMonthly as T;
}
#endregion
#region Child Object Mapping
#region BudgetProcessMonthlyDetail Mapping
private void MapBudgetProcessMonthlyDetail(BudgetProcessMonthlyDetail oBudgetProcessMonthlyDetail,
DataReader oReader)
{
SetObjectID(oBudgetProcessMonthlyDetail, (oReader.GetInt32("BudgetProcessMonthlyDetailID").Value));
oBudgetProcessMonthlyDetail.Calculatedamount = oReader.GetDouble("Amount").Value;
oBudgetProcessMonthlyDetail.Changedamount = oReader.GetDouble("Changedamount").Value;
oBudgetProcessMonthlyDetail.BudgetComponentID = oReader.GetInt32("BudgetComponentID", 0);
oBudgetProcessMonthlyDetail.BudgetProcessMonthlyID = oReader.GetInt32("BudgetProcessMonthlyID", 0);
oBudgetProcessMonthlyDetail.EmployeeID = oReader.GetInt32("EmployeeID", 0);
oBudgetProcessMonthlyDetail.Month = oReader.GetDateTime("Month").Value;
oBudgetProcessMonthlyDetail.Name = oReader.GetString("Name");
oBudgetProcessMonthlyDetail.BudgetGroup = (EnumBudgetGroup)oReader.GetInt32("BudgetGroup");
oBudgetProcessMonthlyDetail.BudgetCode = (EnumBudgetCode)oReader.GetInt32("BudgetCode");
oBudgetProcessMonthlyDetail.Position = oReader.GetInt16("Position").Value;
oBudgetProcessMonthlyDetail.OriginID = oReader.GetInt32("OriginID", 0);
this.SetObjectState(oBudgetProcessMonthlyDetail, ObjectState.Saved);
}
private void MapBudgetProcessMonthlyDetail2(BudgetProcessMonthlyDetail oBudgetProcessMonthlyDetail,
DataReader oReader)
{
oBudgetProcessMonthlyDetail.EmployeeID = oReader.GetInt32("EmpID", 0);
oBudgetProcessMonthlyDetail.Name = oReader.GetString("ItemName");
oBudgetProcessMonthlyDetail.Calculatedamount = oReader.GetDouble("Amount").Value;
oBudgetProcessMonthlyDetail.OriginID = oReader.GetInt32("OriginID", 0);
oBudgetProcessMonthlyDetail.BudgetCode = (EnumBudgetCode)oReader.GetInt32("BudgetCode");
oBudgetProcessMonthlyDetail.Position = oReader.GetInt16("Position").GetValueOrDefault();
this.SetObjectState(oBudgetProcessMonthlyDetail, ObjectState.Saved);
}
private void MapBudgetProcessMonthlyDetail3(BudgetProcessMonthlyDetail oBudgetProcessMonthlyDetail,
DataReader oReader)
{
oBudgetProcessMonthlyDetail.EmployeeID = oReader.GetInt32("EmpID", 0);
oBudgetProcessMonthlyDetail.Name = oReader.GetString("ItemName");
oBudgetProcessMonthlyDetail.Calculatedamount = oReader.GetDouble("Amount").Value;
oBudgetProcessMonthlyDetail.OriginID = oReader.GetInt32("OriginID", 0);
oBudgetProcessMonthlyDetail.BudgetCode = (EnumBudgetCode)oReader.GetInt32("BudgetCode");
oBudgetProcessMonthlyDetail.Position = oReader.GetInt16("Position").GetValueOrDefault();
oBudgetProcessMonthlyDetail.BudgetProcessMonthlyID = oReader.GetInt32("BudgetProcessMonthlyID", 0);
this.SetObjectState(oBudgetProcessMonthlyDetail, ObjectState.Saved);
}
private BudgetProcessMonthlyDetail CreateBudgetDetailObject(DataReader oReader)
{
BudgetProcessMonthlyDetail oBudgetDetail = new BudgetProcessMonthlyDetail();
MapBudgetProcessMonthlyDetail(oBudgetDetail, oReader);
return oBudgetDetail;
}
private BudgetProcessMonthlyDetail CreateBudgetDetailObject2(DataReader oReader)
{
BudgetProcessMonthlyDetail oBudgetDetail = new BudgetProcessMonthlyDetail();
MapBudgetProcessMonthlyDetail2(oBudgetDetail, oReader);
return oBudgetDetail;
}
private BudgetProcessMonthlyDetail CreateBudgetDetailObject3(DataReader oReader)
{
BudgetProcessMonthlyDetail oBudgetDetail = new BudgetProcessMonthlyDetail();
MapBudgetProcessMonthlyDetail3(oBudgetDetail, oReader);
return oBudgetDetail;
}
protected List<BudgetProcessMonthlyDetail> CreateBudgetDetailObjects(DataReader oReader)
{
List<BudgetProcessMonthlyDetail> oBudgetDetails = new List<BudgetProcessMonthlyDetail>();
while (oReader.Read())
{
BudgetProcessMonthlyDetail item = CreateBudgetDetailObject(oReader);
oBudgetDetails.Add(item);
}
return oBudgetDetails;
}
protected List<BudgetProcessMonthlyDetail> CreateBudgetDetailObjects2(DataReader oReader)
{
List<BudgetProcessMonthlyDetail> oBudgetDetails = new List<BudgetProcessMonthlyDetail>();
while (oReader.Read())
{
BudgetProcessMonthlyDetail item = CreateBudgetDetailObject2(oReader);
oBudgetDetails.Add(item);
}
return oBudgetDetails;
}
protected List<BudgetProcessMonthlyDetail> CreateBudgetDetailObjects3(DataReader oReader)
{
List<BudgetProcessMonthlyDetail> oBudgetDetails = new List<BudgetProcessMonthlyDetail>();
while (oReader.Read())
{
BudgetProcessMonthlyDetail item = CreateBudgetDetailObject3(oReader);
oBudgetDetails.Add(item);
}
return oBudgetDetails;
}
#endregion
#region BudgetMonthlyCC Mapping
private void MapBudgetMonthlyCC(BudgetMonthlyCC oBudgetMonthlyCC, DataReader oReader)
{
SetObjectID(oBudgetMonthlyCC, (oReader.GetInt32("BudgetMonthlyCCID").Value));
oBudgetMonthlyCC.BudgetProcessMonthlyID = oReader.GetInt32("BudgetProcessMonthlyID", 0);
oBudgetMonthlyCC.CCID = oReader.GetInt32("CCID", 0);
oBudgetMonthlyCC.EmployeeID = oReader.GetInt32("EmployeeID", 0);
oBudgetMonthlyCC.Month = oReader.GetDateTime("Month").Value;
oBudgetMonthlyCC.Percentage = oReader.GetDouble("Percentage").Value;
this.SetObjectState(oBudgetMonthlyCC, ObjectState.Saved);
}
private BudgetMonthlyCC CreateBudgetMonthlyCCObject(DataReader oReader)
{
BudgetMonthlyCC oBudgetMonthlyCC = new BudgetMonthlyCC();
MapBudgetMonthlyCC(oBudgetMonthlyCC, oReader);
return oBudgetMonthlyCC;
}
protected List<BudgetMonthlyCC> CreateBudgetMonthlyCCObjects(DataReader oReader)
{
List<BudgetMonthlyCC> oBudgetMonthlyCCs = new List<BudgetMonthlyCC>();
while (oReader.Read())
{
BudgetMonthlyCC item = CreateBudgetMonthlyCCObject(oReader);
oBudgetMonthlyCCs.Add(item);
}
return oBudgetMonthlyCCs;
}
#endregion
#endregion
#endregion
#region Service Implementation
#region Parent's Service Implementation
public BudgetProcessMonthly Get(int nID, int payrollTypeID)
{
BudgetProcessMonthly oBudgetProcessMonthly = new BudgetProcessMonthly();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(BudgetProcessMonthlyDA.Get(tc, nID, payrollTypeID));
if (oreader.Read())
{
oBudgetProcessMonthly = CreateObject<BudgetProcessMonthly>(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 oBudgetProcessMonthly;
}
public List<BudgetProcessMonthly> Get(int payrollTypeID)
{
List<BudgetProcessMonthly> oBudgetProcessMonthlies = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(BudgetProcessMonthlyDA.Get(tc, payrollTypeID));
// if (oreader.Read())
//{
oBudgetProcessMonthlies = this.CreateObjects<BudgetProcessMonthly>(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 oBudgetProcessMonthlies;
}
public List<BudgetProcessMonthly> GetWithBudgetID(int nBudID, int payrollTypeID)
{
List<BudgetProcessMonthly> oBudgetProcessMonthlies = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(BudgetProcessMonthlyDA.Get(tc, nBudID, payrollTypeID));
// if (oreader.Read())
//{
oBudgetProcessMonthlies = this.CreateObjects<BudgetProcessMonthly>(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 oBudgetProcessMonthlies;
}
public int Save(BudgetProcessMonthly item)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (item.IsNew)
{
int id = tc.GenerateID("BudgetProcessMonthly", "BudgetProcessMonthlyID");
SetObjectID(item, (id));
BudgetProcessMonthlyDA.Insert(tc, item);
}
else
{
BudgetProcessMonthlyDA.Update(tc, item);
#region delete childrern
BudgetProcessMonthlyDA.Delete(tc, "BudgetProcessMonthlyDetail", "BudgetProcessMonthlyID", item.ID);
BudgetProcessMonthlyDA.Delete(tc, "BudgetMonthlyCC", "BudgetProcessMonthlyID", item.ID);
#endregion
}
#region Insert Children
#region BudgetProcessMonthlyDetails
foreach (BudgetProcessMonthlyDetail oBudgetProcessMonthlyDetail in item.OBudgetProcessMonthlyDetails)
{
oBudgetProcessMonthlyDetail.BudgetProcessMonthlyID = item.ID;
this.SetObjectID(oBudgetProcessMonthlyDetail,
(tc.GenerateID("BudgetProcessMonthlyDetail", "BudgetProcessMonthlyDetailID")));
BudgetProcessMonthlyDA.Insert(tc, oBudgetProcessMonthlyDetail);
}
#endregion
#region BudgetMonthlyCCs
foreach (BudgetMonthlyCC oBBudgetMonthlyCC in item.OBudgetMonthlyCCs)
{
oBBudgetMonthlyCC.BudgetProcessMonthlyID = item.ID;
this.SetObjectID(oBBudgetMonthlyCC, (tc.GenerateID("BudgetMonthlyCC", "BudgetMonthlyCCID")));
BudgetProcessMonthlyDA.Insert(tc, oBBudgetMonthlyCC);
}
#endregion
#endregion
tc.End();
return item.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(BudgetProcessMonthly item, TransactionContext tc)
{
try
{
//if (item.IsNew)
//{
int id = tc.GenerateID("BudgetProcessMonthly", "BudgetProcessMonthlyID");
SetObjectID(item, (id));
BudgetProcessMonthlyDA.Insert(tc, item);
//}
//else
//{
// BudgetProcessMonthlyDA.Update(tc, item);
// #region delete childrern
// BudgetProcessMonthlyDA.Delete(tc, "BudgetProcessMonthlyDetail", "BudgetProcessMonthlyID", item.ID);
// BudgetProcessMonthlyDA.Delete(tc, "BudgetMonthlyCC", "BudgetProcessMonthlyID", item.ID);
// #endregion
//}
#region Insert Children
#region BudgetProcessMonthlyDetails
int nPos = tc.GenerateID("BudgetProcessMonthlyDetail", "Position");
foreach (BudgetProcessMonthlyDetail oBudgetProcessMonthlyDetail in item.OBudgetProcessMonthlyDetails)
{
oBudgetProcessMonthlyDetail.BudgetProcessMonthlyID = item.ID;
if (oBudgetProcessMonthlyDetail.BugetComponent != null)
oBudgetProcessMonthlyDetail.BudgetComponentID = oBudgetProcessMonthlyDetail.BugetComponent.ID;
oBudgetProcessMonthlyDetail.Position = SetPosition(oBudgetProcessMonthlyDetail.BudgetCode,
oBudgetProcessMonthlyDetail.OriginID);
this.SetObjectID(oBudgetProcessMonthlyDetail,
(tc.GenerateID("BudgetProcessMonthlyDetail", "BudgetProcessMonthlyDetailID")));
BudgetProcessMonthlyDA.Insert(tc, oBudgetProcessMonthlyDetail);
nPos++;
}
#endregion
#region BudgetMonthlyCCs
foreach (BudgetMonthlyCC oBBudgetMonthlyCC in item.OBudgetMonthlyCCs)
{
oBBudgetMonthlyCC.BudgetProcessMonthlyID = item.ID;
this.SetObjectID(oBBudgetMonthlyCC, (tc.GenerateID("BudgetMonthlyCC", "BudgetMonthlyCCID")));
BudgetProcessMonthlyDA.Insert(tc, oBBudgetMonthlyCC);
}
#endregion
#endregion
return item.ID;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public int SetPosition(EnumBudgetCode eCode, int nOriginID)
{
int nPos = 0;
//foreach (BudgetTempCollection item in PayrollGlobalFunctions.GetBudetPositions())
//{
// if (nOriginID == 0)
// {
// if (eCode == item.enumBudgetCode)
// {
// nPos = item.position;
// break;
// }
// }
// else
// {
// if (eCode == item.enumBudgetCode && nOriginID==item.OriginID)
// {
// nPos = item.position;
// break;
// }
// }
//}
return nPos;
}
public void Delete(int nID, int payrollTypeID)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
#region delete childrern
BudgetProcessMonthlyDA.Delete(tc, "BudgetProcessMonthlyDetail", "BudgetProcessMonthlyID", nID);
BudgetProcessMonthlyDA.Delete(tc, "BudgetMonthlyCC", "BudgetProcessMonthlyID", nID);
#endregion
BudgetProcessMonthlyDA.Delete(tc, nID, payrollTypeID);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
#endregion
#region Child's Service Implementation
public List<BudgetProcessMonthlyDetail> GetBudgetDetails(int id)
{
List<BudgetProcessMonthlyDetail> oBudgetProcessMonthlyDetails;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(BudgetProcessMonthlyDA.GetBudgetDetails(tc, id));
oBudgetProcessMonthlyDetails = CreateBudgetDetailObjects(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 oBudgetProcessMonthlyDetails;
}
public List<BudgetMonthlyCC> GetBudgetMonthlyCCs(int id)
{
List<BudgetMonthlyCC> oBudgetMonthlyCCs;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(BudgetProcessMonthlyDA.GetBudgetMonthlyCCs(tc, id));
oBudgetMonthlyCCs = this.CreateBudgetMonthlyCCObjects(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 oBudgetMonthlyCCs;
}
public List<BudgetMonthlyCC> GetBudgetMonthlyCCs(int BudgetID, DateTime fromdate, DateTime todate)
{
List<BudgetMonthlyCC> oBudgetMonthlyCCs = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader =
new DataReader(BudgetProcessMonthlyDA.GetBudgetMonthlyCCs(tc, BudgetID, fromdate, todate));
oBudgetMonthlyCCs = this.CreateBudgetMonthlyCCObjects(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 oBudgetMonthlyCCs;
}
public List<BudgetProcessMonthlyDetail> Get(DateTime dtFrom, DateTime dtTo, int nBudID, int payrollTypeID)
{
List<BudgetProcessMonthlyDetail> oBudgetProcessMonthlyDetails = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader =
new DataReader(BudgetProcessMonthlyDA.Get(tc, dtFrom, dtTo, nBudID, payrollTypeID));
// if (oreader.Read())
//{
oBudgetProcessMonthlyDetails = CreateBudgetDetailObjects2(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 oBudgetProcessMonthlyDetails;
}
public List<BudgetProcessMonthlyDetail> Get2(DateTime dtFrom, DateTime dtTo, int nBudID, int payrollTypeID)
{
List<BudgetProcessMonthlyDetail> oBudgetProcessMonthlyDetails = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader =
new DataReader(BudgetProcessMonthlyDA.Get2(tc, dtFrom, dtTo, nBudID, payrollTypeID));
// if (oreader.Read())
//{
oBudgetProcessMonthlyDetails = CreateBudgetDetailObjects3(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 oBudgetProcessMonthlyDetails;
}
public List<BudgetProcessMonthlyDetail> GetCTC(DateTime dtFrom, DateTime dtTo, int nBudID, int payrollTypeID)
{
List<BudgetProcessMonthlyDetail> oBudgetProcessMonthlyDetails = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader =
new DataReader(BudgetProcessMonthlyDA.GetCTC(tc, dtFrom, dtTo, nBudID, payrollTypeID));
// if (oreader.Read())
//{
oBudgetProcessMonthlyDetails = CreateBudgetDetailObjects2(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 oBudgetProcessMonthlyDetails;
}
#endregion
#endregion
}
}