453 lines
13 KiB
C#
453 lines
13 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
|
|
{
|
|
#region Bonus Service
|
|
|
|
public class BonusService : ServiceTemplate, IBonusService
|
|
{
|
|
public BonusService()
|
|
{
|
|
}
|
|
|
|
private void MapObject(Bonus oBonus, DataReader oReader)
|
|
{
|
|
base.SetObjectID(oBonus, (oReader.GetInt32("BonusID").Value));
|
|
oBonus.Code = oReader.GetString("code");
|
|
oBonus.Name = oReader.GetString("name");
|
|
oBonus.NameInBangla = oReader.GetString("nameinbangla", true, null);
|
|
oBonus.Sequence = oReader.GetInt32("SequenceNo").Value;
|
|
oBonus.Status = (EnumStatus)oReader.GetInt32("Status").Value;
|
|
oBonus.CreatedBy = oReader.GetInt32("CreatedBy", 0);
|
|
oBonus.CreatedDate = oReader.GetDateTime("CreatedDate").HasValue
|
|
? oReader.GetDateTime("CreatedDate").Value
|
|
: DateTime.MinValue;
|
|
oBonus.ModifiedBy = oReader.GetInt32("ModifiedBy", 0);
|
|
oBonus.ModifiedDate = oReader.GetDateTime("ModifiedDate").HasValue
|
|
? oReader.GetDateTime("ModifiedDate").Value
|
|
: (DateTime?)null;
|
|
oBonus.PayrollTypeID = oReader.GetInt32("payrollTypeID", 0);
|
|
this.SetObjectState(oBonus, Ease.Core.ObjectState.Saved);
|
|
}
|
|
|
|
protected override T CreateObject<T>(DataReader oReader)
|
|
{
|
|
Bonus oBonus = new Bonus();
|
|
MapObject(oBonus, oReader);
|
|
return oBonus as T;
|
|
}
|
|
|
|
protected Bonus CreateObject(DataReader oReader)
|
|
{
|
|
Bonus oBonus = new Bonus();
|
|
MapObject(oBonus, oReader);
|
|
return oBonus;
|
|
}
|
|
|
|
#region BonusReligion
|
|
|
|
// Replaces the bonus's BonusReligion rows with oBonus.ReligionIDs ("1,3"; "" = none).
|
|
private void SaveReligions(TransactionContext tc, Bonus oBonus)
|
|
{
|
|
BonusDA.DeleteReligions(tc, oBonus.ID);
|
|
|
|
List<int> religionIDs = new List<int>();
|
|
foreach (string part in oBonus.ReligionIDs.Split(','))
|
|
{
|
|
int religionID;
|
|
if (int.TryParse(part.Trim(), out religionID) && religionID > 0 && !religionIDs.Contains(religionID))
|
|
religionIDs.Add(religionID);
|
|
}
|
|
|
|
foreach (int religionID in religionIDs)
|
|
{
|
|
int id = tc.GenerateID("BonusReligion", "BonusReligionID");
|
|
BonusDA.InsertReligion(tc, id, oBonus.ID, religionID);
|
|
}
|
|
|
|
FillReligions(tc, oBonus);
|
|
}
|
|
|
|
private void FillReligions(TransactionContext tc, Bonus oBonus)
|
|
{
|
|
List<string> ids = new List<string>();
|
|
List<string> names = new List<string>();
|
|
DataReader dr = new DataReader(BonusDA.GetReligions(tc, oBonus.ID));
|
|
while (dr.Read())
|
|
{
|
|
ids.Add(dr.GetInt32("ReligionID").Value.ToString());
|
|
names.Add(dr.GetString("Name"));
|
|
}
|
|
dr.Close();
|
|
|
|
oBonus.ReligionIDs = string.Join(",", ids);
|
|
oBonus.ReligionNames = string.Join(", ", names);
|
|
}
|
|
|
|
private void FillReligions(TransactionContext tc, List<Bonus> bonuses, int payrollTypeID)
|
|
{
|
|
if (bonuses == null || bonuses.Count == 0)
|
|
return;
|
|
|
|
Dictionary<int, List<string>> ids = new Dictionary<int, List<string>>();
|
|
Dictionary<int, List<string>> names = new Dictionary<int, List<string>>();
|
|
DataReader dr = new DataReader(BonusDA.GetReligionsByPayrollType(tc, payrollTypeID));
|
|
while (dr.Read())
|
|
{
|
|
int bonusID = dr.GetInt32("BonusID").Value;
|
|
if (!ids.ContainsKey(bonusID))
|
|
{
|
|
ids.Add(bonusID, new List<string>());
|
|
names.Add(bonusID, new List<string>());
|
|
}
|
|
ids[bonusID].Add(dr.GetInt32("ReligionID").Value.ToString());
|
|
names[bonusID].Add(dr.GetString("Name"));
|
|
}
|
|
dr.Close();
|
|
|
|
foreach (Bonus oBonus in bonuses)
|
|
{
|
|
oBonus.ReligionIDs = ids.ContainsKey(oBonus.ID) ? string.Join(",", ids[oBonus.ID]) : string.Empty;
|
|
oBonus.ReligionNames = names.ContainsKey(oBonus.ID) ? string.Join(", ", names[oBonus.ID]) : string.Empty;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Service implementation
|
|
|
|
public Bonus Get(int id)
|
|
{
|
|
Bonus oBonus = new Bonus();
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oreader = new DataReader(BonusDA.Get(tc, id));
|
|
if (oreader.Read())
|
|
{
|
|
oBonus = this.CreateObject<Bonus>(oreader);
|
|
}
|
|
|
|
oreader.Close();
|
|
if (!oBonus.IsNew)
|
|
FillReligions(tc, oBonus);
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
|
|
return oBonus;
|
|
}
|
|
public Bonus Get(TransactionContext tc,int id)
|
|
{
|
|
Bonus oBonus = new Bonus();
|
|
|
|
try
|
|
{
|
|
DataReader oreader = new DataReader(BonusDA.Get(tc, id));
|
|
if (oreader.Read())
|
|
{
|
|
oBonus = this.CreateObject<Bonus>(oreader);
|
|
}
|
|
|
|
oreader.Close();
|
|
if (!oBonus.IsNew)
|
|
FillReligions(tc, oBonus);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
|
|
return oBonus;
|
|
}
|
|
|
|
public List<Bonus> Get(EnumStatus status, int payrollTypeID)
|
|
{
|
|
List<Bonus> bonuss = null;
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(BonusDA.Get(tc, status, payrollTypeID));
|
|
bonuss = this.CreateObjects<Bonus>(dr);
|
|
dr.Close();
|
|
FillReligions(tc, bonuss, 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 bonuss;
|
|
}
|
|
|
|
public List<Bonus> GetParameterizedBonus(EnumStatus status, int payrollTypeID)
|
|
{
|
|
List<Bonus> bonuss = null;
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(BonusDA.GetParameterizedBonus(tc, status, payrollTypeID));
|
|
bonuss = this.CreateObjects<Bonus>(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 bonuss;
|
|
}
|
|
|
|
public List<Bonus> GetActiveProccessedBonus(int payrollTypeID, DateTime bonusMonth)
|
|
{
|
|
List<Bonus> bonuses = new List<Bonus>();
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(BonusDA.GetActiveProccessedBonus(tc, payrollTypeID, bonusMonth));
|
|
bonuses = this.CreateObjects<Bonus>(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 bonuses;
|
|
}
|
|
|
|
public int Save(Bonus oBonus)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
if (oBonus.IsNew)
|
|
{
|
|
int id = tc.GenerateID("Bonus", "BonusID");
|
|
base.SetObjectID(oBonus, (id));
|
|
int seqNo = tc.GenerateID("Bonus", "SequenceNo");
|
|
oBonus.Sequence = seqNo;
|
|
BonusDA.Insert(tc, oBonus);
|
|
}
|
|
else
|
|
{
|
|
BonusDA.Update(tc, oBonus);
|
|
}
|
|
|
|
if (oBonus.ReligionIDs != null)
|
|
SaveReligions(tc, oBonus);
|
|
|
|
tc.End();
|
|
return oBonus.ID;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
}
|
|
|
|
public void Delete(int id)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
BonusDA.DeleteReligions(tc, id);
|
|
BonusDA.Delete(tc, id);
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
}
|
|
|
|
public List<Bonus> GetAllBonus(int payrollTypeID, EnumStatus status, string code, string name)
|
|
{
|
|
List<Bonus> bonus = new List<Bonus>();
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(BonusDA.GetAllBonus(tc, payrollTypeID, status, code, name));
|
|
bonus = this.CreateObjects<Bonus>(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 bonus;
|
|
}
|
|
// The religions set on this bonus (BonusReligion), as ID + Name.
|
|
public List<Religion> GetReligions(int bonusID)
|
|
{
|
|
List<Religion> religions = new List<Religion>();
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader dr = new DataReader(BonusDA.GetReligions(tc, bonusID));
|
|
while (dr.Read())
|
|
{
|
|
Religion oReligion = new Religion();
|
|
base.SetObjectID(oReligion, dr.GetInt32("ReligionID").Value);
|
|
oReligion.Name = dr.GetString("Name");
|
|
religions.Add(oReligion);
|
|
}
|
|
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 religions;
|
|
}
|
|
|
|
public DataSet GetCCWiseBonusSummary(DateTime bMonthDate, string bonus)
|
|
{
|
|
DataSet obonus = new DataSet();
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
obonus = BonusDA.GetCCWiseBonusSummary(tc, bMonthDate, bonus);
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
#endregion
|
|
}
|
|
return obonus;
|
|
}
|
|
|
|
public DataSet GetCCWiseBonus(DateTime bMonthDate, string bonus)
|
|
{
|
|
DataSet obonus = new DataSet();
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
obonus = BonusDA.GetCCWiseBonus(tc, bMonthDate, bonus);
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
#endregion
|
|
}
|
|
return obonus;
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
|
|
#endregion
|
|
} |