EchoTex_Payroll/HRM.DA/Service/AllowDeduct/ADParameterService.cs

1099 lines
44 KiB
C#
Raw Normal View History

2024-10-14 10:01:49 +06:00
using System;
using Ease.Core.Model;
using Ease.Core.DataAccess;
using System.Collections.Generic;
using Ease.Core.Utility;
using HRM.BO;
using static HRM.BO.ADParameter;
namespace HRM.DA
{
public class ADParameterService : ServiceTemplate, IADParameterService
{
public ADParameterService()
{
}
private void MapObject(ADParameter oADParameter, DataReader oReader)
{
base.SetObjectID(oADParameter, oReader.GetInt32("ADParameterID").Value);
oADParameter.AllowDeductID = oReader.GetInt32("ALLOWDEDUCTID", 0);
oADParameter.IsForConfirmOnly = oReader.GetBoolean("isForConfirmOnly").Value;
oADParameter.FlatAmount = oReader.GetDouble("flatAmount").Value;
oADParameter.PercentOfBasic = oReader.GetDouble("percentOfBasic").Value;
oADParameter.PercentOfGross = oReader.GetDouble("percentOfGross").Value;
oADParameter.PercentOfEarnedBasic = oReader.GetDouble("percentOfEarnedBasic").Value;
oADParameter.GFFlatAmount =
oReader.GetString("GFFlatAmount") == null ? 0 : oReader.GetDouble("GFFlatAmount").Value;
oADParameter.GFPercentOfBasic = oReader.GetString("GFPercentOfBasic") == null
? 0
: oReader.GetDouble("GFPercentOfBasic").Value;
oADParameter.GFPercentOfGross = oReader.GetString("GFPercentOfGross") == null
? 0
: oReader.GetDouble("GFPercentOfGross").Value;
oADParameter.MinAmount = oReader.GetDouble("minAmount").Value;
oADParameter.MaxAmount = oReader.GetDouble("maxAmount").Value;
oADParameter.IsCurrentlyActive = oReader.GetBoolean("isCurrentlyActive").Value;
oADParameter.PayrollTypeID = oReader.GetInt32("PayrollTypeID", 0);
oADParameter.TaxablePercentage = oReader.GetDouble("taxablePercentage").Value;
oADParameter.IsTaxable = oReader.GetBoolean("isTaxable").Value;
oADParameter.IsTaxProjection = oReader.GetBoolean("isTaxProjection").Value;
oADParameter.IsDependsOnAttendance = oReader.GetBoolean("isDependsOnAttendance").Value;
oADParameter.IsFractionateApplicable = oReader.GetBoolean("IsFractionateApplicable").Value;
oADParameter.IsDependsOnOTHour = oReader.GetBoolean("isDependsOnOTHour").Value;
oADParameter.ISDEPENDSONSPECIALHOUR = oReader.GetBoolean("ISDEPENDSONSPECIALHOUR").Value;
oADParameter.IsWithException = oReader.GetBoolean("isWithException").Value;
oADParameter.Periodicity = (EnumPeriodicity)oReader.GetInt32("periodicity").Value;
oADParameter.AllowOrDeductType = (EnumAllowOrDeduct)oReader.GetInt32("ALLOWORDEDUCT").Value;
oADParameter.Gender = (EnumGender)oReader.GetInt32("gender").Value;
oADParameter.CreatedBy = oReader.GetInt32("CreatedBy", 0);
oADParameter.CreatedDate = oReader.GetDateTime("CreationDate").Value;
oADParameter.ModifiedBy = oReader.GetInt32("ModifiedBy", 0);
oADParameter.ModifiedDate = oReader.GetDateTime("ModifiedDate");
oADParameter.EntitleType = (EnumEntitleType)oReader.GetInt32("EntitleType").Value;
this.SetObjectState(oADParameter, Ease.Core.ObjectState.Saved);
}
private void MapADGradeObject(ADParameter.ADParameterGrade oADGrade, DataReader oReader)
{
base.SetObjectID(oADGrade, oReader.GetInt32("ADPARAMETERID").Value);
oADGrade.ADParameterID = oReader.GetInt32("ADPARAMETERID", 0);
oADGrade.GradeID = oReader.GetInt32("GRADEID", 0);
this.SetObjectState(oADGrade, Ease.Core.ObjectState.Saved);
}
private void MapADShiftObject(ADParameter.ADParameterShift oADShift, DataReader oReader)
{
base.SetObjectID(oADShift, oReader.GetInt32("ADPARAMETERID").Value);
oADShift.ADParameterID = oReader.GetInt32("ADPARAMETERID").Value;
oADShift.ShiftID = oReader.GetInt32("SHIFTID").Value;
this.SetObjectState(oADShift, Ease.Core.ObjectState.Saved);
}
private void MapADDesignationObject(ADParameter.ADParameterDesignation oADGrade, DataReader oReader)
{
base.SetObjectID(oADGrade, oReader.GetInt32("ADPARAMETERDESIGNATINID").Value);
oADGrade.ADParameterID = oReader.GetInt32("ADPARAMETERID", 0);
oADGrade.DesignationID = oReader.GetInt32("DesignationID", 0);
oADGrade.FlatAmount = oReader.GetString("FlatAmount") == null ? 0 : oReader.GetDouble("FlatAmount").Value;
oADGrade.PercentOfBasic = oReader.GetString("PercentOfBasic") == null
? 0
: oReader.GetDouble("PercentOfBasic").Value;
oADGrade.PercentOfGross = oReader.GetString("PercentOfGross") == null
? 0
: oReader.GetDouble("PercentOfGross").Value;
oADGrade.EffectMonth = oReader.GetDateTime("EffectMonth") == null
? PayrollGlobalFunctions.PayrollFirstDateOfMonth(DateTime.Today)
: oReader.GetDateTime("EffectMonth").Value;
oADGrade.ArrearToCalculationMonth = oReader.GetDateTime("ArrearToCalculationMonth") == null
? PayrollGlobalFunctions.PayrollFirstDateOfMonth(DateTime.Today)
: oReader.GetDateTime("ArrearToCalculationMonth").Value;
this.SetObjectState(oADGrade, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
ADParameter oADParameter = new ADParameter();
MapObject(oADParameter, oReader);
return oADParameter as T;
}
protected List<ADParameter.ADParameterGrade> CreateADGradeObject(DataReader oReader)
{
List<ADParameter.ADParameterGrade> oADGrades = new List<ADParameter.ADParameterGrade>();
while (oReader.Read())
{
ADParameter.ADParameterGrade oADGrade = new ADParameter.ADParameterGrade();
MapADGradeObject(oADGrade, oReader);
oADGrades.Add(oADGrade);
}
return oADGrades;
}
protected List<ADParameter.ADParameterShift> CreateADShiftObject(DataReader oReader)
{
List<ADParameter.ADParameterShift> oADShifts = new List<ADParameter.ADParameterShift>();
while (oReader.Read())
{
ADParameter.ADParameterShift oADShift = new ADParameter.ADParameterShift();
MapADShiftObject(oADShift, oReader);
oADShifts.Add(oADShift);
}
return oADShifts;
}
protected List<ADParameter.ADParameterDesignation> CreateADDesignationObject(DataReader oReader)
{
List<ADParameter.ADParameterDesignation> oADGrades = new List<ADParameter.ADParameterDesignation>();
while (oReader.Read())
{
ADParameter.ADParameterDesignation oADGrade = new ADParameter.ADParameterDesignation();
MapADDesignationObject(oADGrade, oReader);
oADGrades.Add(oADGrade);
}
return oADGrades;
}
protected ADParameter CreateObject(DataReader oReader)
{
ADParameter oADParameter = new ADParameter();
MapObject(oADParameter, oReader);
return oADParameter;
}
#region Service implementation
public List<ADParameter> Get(int? gradeID, EnumEntitleType nEntitleType, EnumAllowOrDeduct nType, int payrolltypeid)
{
List<ADParameter> aDParameters = new List<ADParameter>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ADParameterDA.Get(tc, gradeID, nEntitleType, nType, payrolltypeid));
aDParameters = this.CreateObjects<ADParameter>(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 aDParameters;
}
public ADParameter Get(int id, int payrollTypeID)
{
ADParameter oADParameter = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(ADParameterDA.Get(tc, id, payrollTypeID));
if (oreader.Read())
{
oADParameter = this.CreateObject<ADParameter>(oreader);
}
oreader.Close();
ADParameterEmployeeService oademp = new ADParameterEmployeeService();
if (oADParameter != null)
{
List<ADParameterEmployee> adep = oademp.GetNextSalaryMonthItems(tc, oADParameter.ID,payrollTypeID);
oADParameter.Exception = adep.FindAll(x => x.ADEmpType == EnumADEmpType.Exception);
oADParameter.NotApplicable = adep.FindAll(x => x.ADEmpType == EnumADEmpType.NotApplicable);
oADParameter.ADParameterEmployees =
adep.FindAll(x => x.ADEmpType == EnumADEmpType.AppliedToIndividual);
DataReader od = new DataReader(ADParameterDA.GetGrades(tc, id));
oADParameter.ADParameterGrades = this.CreateADGradeObject(od);
od.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 oADParameter;
}
public ADParameter Get(int id)
{
ADParameter oADParameter = new ADParameter();
#region Cache Header
//oADParameter = _cache["Get", id] as ADParameter;
//if (oADParameter != null)
// return oADParameter;
#endregion
TransactionContext tc = null;
try
{
SystemInformation systemInformation = new SystemInformation();
systemInformation.CurrentSysInfo = new SystemInformationService().Get();
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(ADParameterDA.Get(tc, id, systemInformation.CurrentSysInfo.PayrollTypeID));
if (oreader.Read())
{
oADParameter = this.CreateObject<ADParameter>(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(oADParameter, "Get", id);
#endregion
return oADParameter;
}
public List<ADParameter.ADParameterGrade> GetGrades(int nID)
{
List<ADParameter.ADParameterGrade> aDParameterGrade = new List<ADParameter.ADParameterGrade>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ADParameterDA.GetGrades(tc, nID));
aDParameterGrade = this.CreateADGradeObject(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 aDParameterGrade;
}
public List<ADParameter.ADParameterGrade> GetUsedGrades(int alllowdeductid)
{
List<ADParameter.ADParameterGrade> aDParameterGrade = new List<ADParameter.ADParameterGrade>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ADParameterDA.GetUsedGrades(tc, alllowdeductid));
aDParameterGrade = this.CreateADGradeObject(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 aDParameterGrade;
}
public List<ADParameter.ADParameterDesignation> GetDesignaitons(int nID)
{
List<ADParameter.ADParameterDesignation> aDParameterGrade = new List<ADParameter.ADParameterDesignation>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ADParameterDA.GetDesignations(tc, nID));
aDParameterGrade = this.CreateADDesignationObject(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 aDParameterGrade;
}
public List<ADParameter> GetWithPayrollType(EnumStatus status, int payrollTypeID)
{
List<ADParameter> aDParameters = new List<ADParameter>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ADParameterDA.GetWithPayrollType(tc, status, payrollTypeID));
aDParameters = this.CreateObjects<ADParameter>(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 aDParameters;
}
public List<ADParameter> GetWithDetail(EnumStatus status, int payrollTypeID)
{
List<ADParameter> aDParameters = new List<ADParameter>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ADParameterDA.GetWithPayrollType(tc, status, payrollTypeID));
aDParameters = this.CreateObjects<ADParameter>(dr);
dr.Close();
DataReader drtwo = new DataReader(ADParameterDA.GetAllGrades(tc));
List<ADParameter.ADParameterGrade> ogreades = this.CreateADGradeObject(drtwo);
drtwo.Close();
tc.End();
var NotApplicables = new ADParameterEmployeeService().Get(EnumADEmpType.NotApplicable);
var Exceptions = new ADParameterEmployeeService().Get(EnumADEmpType.Exception);
foreach (ADParameter oparam in aDParameters)
{
oparam.ADParameterGrades = ogreades.FindAll(g => g.ADParameterID == oparam.ID);
oparam.NotApplicable = NotApplicables.FindAll(g => g.ADParameterID == oparam.ID);
oparam.Exception = Exceptions.FindAll(g => g.ADParameterID == oparam.ID);
}
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return aDParameters;
}
public List<ADParameter> Get(EnumStatus status, EnumAllowOrDeduct nType, int payrollTypeID)
{
List<ADParameter> aDParameters = new List<ADParameter>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ADParameterDA.Get(tc, status, nType, payrollTypeID));
aDParameters = this.CreateObjects<ADParameter>(dr);
dr.Close();
if (aDParameters != null && aDParameters.Count > 0)
{
DataReader drtwo = new DataReader(ADParameterDA.GetAllGrades(tc));
List<ADParameter.ADParameterGrade> ogreades = this.CreateADGradeObject(drtwo);
aDParameters.ForEach(x =>
{
x.ADParameterGrades = ogreades.FindAll(g => g.ADParameterID == x.ID);
});
}
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return aDParameters;
}
private List<ADParameter.ADParameterShift> _ADParameterShifts = null;
public List<ADParameter.ADParameterShift> ADParameterShifts
{
get
{
if (_ADParameterShifts == null)
{
//_ADParameterShifts = ADParameterService.GetShifts(this._shiftID);
}
return this._ADParameterShifts;
}
set
{
_ADParameterShifts = value;
}
}
public List<ADParameter.ADParameterShift> GetShifts(int adID)
{
List<ADParameter.ADParameterShift> aDParameterShifts = new List<ADParameter.ADParameterShift>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ADParameterDA.GetShifts(tc, adID));
aDParameterShifts = this.CreateObjects<ADParameter.ADParameterShift>(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 aDParameterShifts;
}
public List<ADParameter.ADParameterShift> GetAllShifts()
{
List<ADParameter.ADParameterShift> aDParameterShifts = new List<ADParameter.ADParameterShift>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ADParameterDA.GetAllShifts(tc));
aDParameterShifts = this.CreateADShiftObject(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 aDParameterShifts;
}
public List<ADParameter> GetDistinct(EnumStatus status, EnumAllowOrDeduct nType, int payrollTypeID)
{
List<ADParameter> aDParameters = new List<ADParameter>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ADParameterDA.GetDistinct(tc, status, nType, payrollTypeID));
aDParameters = this.CreateObjects<ADParameter>(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 aDParameters;
}
public List<ADParameter> Get(int gradeID, EnumEntitleType nEntitleType, EnumAllowOrDeduct nType,
int payrollTypeID)
{
List<ADParameter> aDParameters = new List<ADParameter>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ADParameterDA.Get(tc, gradeID, nEntitleType, nType, payrollTypeID));
aDParameters = this.CreateObjects<ADParameter>(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 aDParameters;
}
public int Save(ADParameter oADParameter)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oADParameter.IsNew)
{
int id = tc.GenerateID("ADPARAMETERBASIC", "ADParameterID");
base.SetObjectID(oADParameter, (id));
ADParameterDA.Insert(tc, oADParameter);
}
else
{
ADParameterDA.Update(tc, oADParameter);
ADParameterDA.DeleteGrade(tc, oADParameter.ID);
ADParameterDA.DeletebyAdParamidinDesignation(tc, oADParameter.ID);
ADParameterEmployeeDA.DeletebyAdParamid(tc, oADParameter.ID);
}
int empid = tc.GenerateID("ADPARAMETEREMPLOYEE", "ADPARAMETEREMPID");
List<ADParameterEmployee> adpEmps = new List<ADParameterEmployee>();
if (oADParameter.ADParameterEmployees != null) adpEmps.AddRange(oADParameter.ADParameterEmployees);
if (oADParameter.Exception != null) adpEmps.AddRange(oADParameter.Exception);
if (oADParameter.NotApplicable != null) adpEmps.AddRange(oADParameter.NotApplicable);
foreach (ADParameterEmployee adEmp in adpEmps)
{
adEmp.ADParameterID = oADParameter.ID;
base.SetObjectID(adEmp, (empid));
adEmp.CreatedBy = oADParameter.CreatedBy;
adEmp.CreatedDate = oADParameter.CreatedDate;
adEmp.ModifiedBy = adEmp.ModifiedBy;
adEmp.ModifiedDate = DateTime.Today;
ADParameterEmployeeDA.Insert(tc, adEmp);
empid = empid + 1;
}
foreach (ADParameter.ADParameterGrade adGrade in oADParameter.ADParameterGrades)
{
adGrade.ADParameterID = oADParameter.ID;
ADParameterDA.Insert(tc, adGrade);
}
//foreach (ADParameter.ADParameterDesignation odesig in oADParameter.ADParameterDesignations)
//{
// int id = tc.GenerateID("ADPARAMETERDesignation", "ADPARAMETERDESIGNATINID");
// base.SetObjectID(odesig, (id));
// odesig.ADParameterID = oADParameter.ID;
// odesig.CreatedBy = oADParameter.CreatedBy;
// odesig.CreatedDate = oADParameter.CreatedDate;
// odesig.ModifiedBy = odesig.CreatedBy;
// odesig.ModifiedDate = DateTime.Today;
// ADParameterDA.Insert(tc, odesig);
//}
tc.End();
return oADParameter.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);
ADParameterDA.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 void ChangeStatus(int id, EnumStatus enumStatus)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
ADParameterDA.ChangeStatus(tc, id, enumStatus);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
#endregion
public List<ADParameter> GetApplicableParameters(Employee employee, int graId, List<ADParameter> parameters)
{
List<ADParameter> applicableParams = parameters.FindAll(delegate (ADParameter param) { return IsApplicable(param, graId, employee); });
return applicableParams;
}
public ADParameter GetApplicableParameter(Employee employee, int graId, List<ADParameter> parameters, int allowdeductID)
{
foreach (ADParameter item in parameters)
{
if (item.AllowDeductID == allowdeductID)
{
if (IsApplicable(item, graId, employee) == true)
return item;
}
}
return null;
}
private bool IsApplicable(ADParameter param, int graid, Employee employee)
{
bool isApplicable = false;
foreach (ADParameter.ADParameterGrade adgrade in param.ADParameterGrades)
{
if (adgrade.GradeID == graid)
{
isApplicable = true;
}
}
if (!isApplicable) return false;
if (param.Gender != EnumGender.None
&& param.Gender != employee.Gender)
{
return false;
}
if (param.IsForConfirmOnly && !employee.IsConfirmed)
{
return false;
}
return true;
}
public void ApplicableParameters(Employee emlpoyee, SalaryMonthly salary, List<ADParameter> allAdparameters)
{
foreach (EmployeeGradeSalary gs in salary.GradeSalaries)
{
List<ADParameter> lparameter = this.GetApplicableParameters(emlpoyee, gs.GradeID, allAdparameters);
gs.ADParameters = new List<ADParameter>();
foreach (ADParameter item in lparameter)
gs.ADParameters.Add(item);
}
foreach (EmployeeGradeSalary gs in salary.ArrearGradeSalaries)
{
List<ADParameter> alparameter = this.GetApplicableParameters(emlpoyee, gs.GradeID, allAdparameters);
gs.ADParameters = new List<ADParameter>();
foreach (ADParameter item in alparameter)
gs.ADParameters.Add(item);
}
foreach (EmployeeGradeSalary gs in salary.ArrearPaidGradeSalaries)
{
List<ADParameter> aplparameter = this.GetApplicableParameters(emlpoyee, gs.GradeID, allAdparameters);
gs.ADParameters = new List<ADParameter>();
foreach (ADParameter item in aplparameter)
gs.ADParameters.Add(item);
}
}
public double GetAmount(Employee oEmp, ADParameter adParam)
{
ADParameterEmployee adEmp = null;
double nAmount = 0.0;
switch (adParam.EntitleType)
{
case EnumEntitleType.Grade:
if (adParam.PercentOfBasic > 0)
nAmount = oEmp.BasicSalary * adParam.PercentOfBasic / 100.0 + adParam.FlatAmount;
else if (adParam.PercentOfGross > 0)
nAmount = oEmp.GrossSalary * adParam.PercentOfBasic / 100.0 + adParam.FlatAmount;
else
nAmount = adParam.FlatAmount;
break;
case EnumEntitleType.Individual:
adEmp = new ADParameterEmployeeService().Get(oEmp.ID, adParam.AllowDeductID, adParam.ID);
if (adEmp != null)
nAmount = adEmp.MonthlyAmount;
else
{
if (adParam.PercentOfBasic > 0)
nAmount = oEmp.BasicSalary * adParam.PercentOfBasic / 100.0 + adParam.FlatAmount;
else if (adParam.PercentOfGross > 0)
nAmount = oEmp.GrossSalary * adParam.PercentOfBasic / 100.0 + adParam.FlatAmount;
else
nAmount = adParam.FlatAmount;
}
break;
}
if (adParam.MinAmount != 0 || adParam.MaxAmount != 0)
{
if (nAmount < adParam.MinAmount)
{
nAmount = adParam.MinAmount;
}
if (nAmount > adParam.MaxAmount)
{
nAmount = adParam.MaxAmount;
}
}
return nAmount;
}
public double GetGradeDefinedAmountLikeDesktop(Employee employee, double basicSalary,
double grossSalary, ADParameter param, double FractionofFromTo = 1)
{
ADParameterEmployee adEmp = null;
double nAmount = 0.0;
switch (param.EntitleType)
{
case EnumEntitleType.Grade:
if (param.PercentOfBasic > 0)
nAmount = nAmount + param.FlatAmount * FractionofFromTo +
basicSalary * param.PercentOfBasic / 100.0;
//nAmount = basicSalary * this.PercentOfBasic / 100.0;// + this.FlatAmount;
else if (param.PercentOfGross > 0)
nAmount = nAmount + param.FlatAmount * FractionofFromTo +
grossSalary * param.PercentOfGross / 100.0;
//nAmount = grossSalary * this.PercentOfGross / 100.0;// + this.FlatAmount;
else
nAmount = param.FlatAmount * FractionofFromTo;
//bool IsGradFather = (employee.GrandFather != null && employee.GrandFather.Allowance == true);
//if (IsGradFather == true)
//{
// nAmount = 0;
// if (this.GFPercentOfBasic > 0)
// nAmount = nAmount + this.GFFlatAmount * oEmpGradeSalary.FractionofFromTo + basicSalary * this.GFPercentOfBasic / 100.0;
// //nAmount = basicSalary * this.PercentOfBasic / 100.0;// + this.FlatAmount;
// else if (this.GFPercentOfGross > 0)
// nAmount = nAmount + this.GFFlatAmount * oEmpGradeSalary.FractionofFromTo + grossSalary * this.GFPercentOfGross / 100.0;
// //nAmount = grossSalary * this.PercentOfGross / 100.0;// + this.FlatAmount;
// else
// nAmount = this.GFFlatAmount * oEmpGradeSalary.FractionofFromTo;
//}
if (param.NotApplicable.Exists(x => x.EmployeeID == employee.ID) == true)
{
nAmount = 0;
}
else
{
adEmp = param.Exception.Find(x => x.EmployeeID == employee.ID);
if (adEmp != null)
{
switch (adEmp.ValueType)
{
case EnumValueType.Amount:
nAmount = adEmp.MonthlyAmount * FractionofFromTo;
break;
case EnumValueType.Other:
if (param.PercentOfBasic > 0 || adEmp.MonthlyAmount > 0)
nAmount = basicSalary * adEmp.MonthlyAmount /
100.0; //* oEmpGradeSalary.FractionofFromTo; //+ this.FlatAmount;
else if (param.PercentOfGross > 0 || adEmp.MonthlyAmount > 0)
nAmount = grossSalary * adEmp.MonthlyAmount /
100.0; //* oEmpGradeSalary.FractionofFromTo; //+ this.FlatAmount;
break;
}
}
}
break;
case EnumEntitleType.Individual:
throw new Exception("You have choosed the wrong overloaded function to calculate"
+ " Individual Allowance" + " Employee:(" + employee.EmployeeNo + ")" +
employee.Name + "; Item Name:" + param.AllowanceDeduction.Name);
}
if (param.MinAmount != 0 || param.MaxAmount != 0)
{
if (nAmount < param.MinAmount)
{
nAmount = param.MinAmount;
}
if (nAmount > param.MaxAmount)
{
nAmount = param.MaxAmount;
}
}
return nAmount;
}
public double GetGradeDefinedAmount(Employee employee, double basicSalary,
double grossSalary, EmployeeGradeSalary oEmpGradeSalary, ADParameter param)
{
ADParameterEmployee adEmp = null;
double nAmount = 0.0;
switch (param.EntitleType)
{
case EnumEntitleType.Grade:
if (param.PercentOfBasic > 0)
nAmount = nAmount + param.FlatAmount * oEmpGradeSalary.FractionofFromTo +
basicSalary * param.PercentOfBasic / 100.0;
//nAmount = basicSalary * this.PercentOfBasic / 100.0;// + this.FlatAmount;
else if (param.PercentOfGross > 0)
nAmount = nAmount + param.FlatAmount * oEmpGradeSalary.FractionofFromTo +
grossSalary * param.PercentOfGross / 100.0;
//nAmount = grossSalary * this.PercentOfGross / 100.0;// + this.FlatAmount;
else
nAmount = param.FlatAmount * oEmpGradeSalary.FractionofFromTo;
//bool IsGradFather = (employee.GrandFather != null && employee.GrandFather.Allowance == true);
//if (IsGradFather == true)
//{
// nAmount = 0;
// if (this.GFPercentOfBasic > 0)
// nAmount = nAmount + this.GFFlatAmount * oEmpGradeSalary.FractionofFromTo + basicSalary * this.GFPercentOfBasic / 100.0;
// //nAmount = basicSalary * this.PercentOfBasic / 100.0;// + this.FlatAmount;
// else if (this.GFPercentOfGross > 0)
// nAmount = nAmount + this.GFFlatAmount * oEmpGradeSalary.FractionofFromTo + grossSalary * this.GFPercentOfGross / 100.0;
// //nAmount = grossSalary * this.PercentOfGross / 100.0;// + this.FlatAmount;
// else
// nAmount = this.GFFlatAmount * oEmpGradeSalary.FractionofFromTo;
//}
if (param.NotApplicable.Exists(x=> x.EmployeeID == employee.ID) ==true)
{
nAmount = 0;
}
else
{
adEmp = param.Exception.Find(x=>x.EmployeeID == employee.ID);
if (adEmp != null)
{
switch (adEmp.ValueType)
{
case EnumValueType.Amount:
nAmount = adEmp.MonthlyAmount * oEmpGradeSalary.FractionofFromTo;
break;
case EnumValueType.Other:
if (param.PercentOfBasic > 0 || adEmp.MonthlyAmount > 0)
nAmount = basicSalary * adEmp.MonthlyAmount /
100.0; //* oEmpGradeSalary.FractionofFromTo; //+ this.FlatAmount;
else if (param.PercentOfGross > 0 || adEmp.MonthlyAmount > 0)
nAmount = grossSalary * adEmp.MonthlyAmount /
100.0; //* oEmpGradeSalary.FractionofFromTo; //+ this.FlatAmount;
break;
}
}
}
break;
case EnumEntitleType.Individual:
throw new Exception("You have choosed the wrong overloaded function to calculate"
+ " Individual Allowance" + " Employee:(" + employee.EmployeeNo + ")" +
employee.Name + "; Item Name:" + param.AllowanceDeduction.Name);
}
if (param.MinAmount != 0 || param.MaxAmount != 0)
{
if (nAmount < param.MinAmount)
{
nAmount = param.MinAmount;
}
if (nAmount > param.MaxAmount)
{
nAmount = param.MaxAmount;
}
}
return nAmount;
}
public double GetIndividualAmount(Employee employee, DateTime fortheMonth,
ADParameterEmployee ademployee, double grossSalary,
double basicSalary, ADParameter param, DateTime nextProcessDate)
{
double nAmount = 0.0;
switch (param.EntitleType)
{
case EnumEntitleType.Grade:
throw new ServiceException("You have choosed the wrong overloaded function to calculate"
+ " Grade defined Allowance" + " Employee:(" + employee.EmployeeNo + ")" + employee.Name + "; Item Name:" + param.AllowanceDeduction.Name);
case EnumEntitleType.Individual:
if (param.IsDependsOnAttendance)
{
// nAmount = this.FlatAmount * ademployee.MonthlyAmount;
// above logic are needed when automated attandance not enabled
bool bfixedAmount = new SystemConfigarationService().GetconfigBooleanValue(EnumConfigurationType.Logic, "adparameter", "dependsonattandance");
if (bfixedAmount == false)
nAmount = param.FlatAmount * ademployee.MonthlyAmount;
else nAmount = ademployee.MonthlyAmount;
}
else if (ademployee.Arreartype == EnumArrearType.NotPresent)
{
DateTime fromDate = GlobalFunctions.FirstDateOfMonth(nextProcessDate);
DateTime toDate = nextProcessDate;
if (ademployee.FormDate < GlobalFunctions.FirstDateOfMonth(fortheMonth))
fromDate = GlobalFunctions.FirstDateOfMonth(fortheMonth);
else fromDate = ademployee.FormDate;
if (ademployee.TillDate == null || ademployee.TillDate == DateTime.MinValue)
toDate = GlobalFunctions.LastDateOfMonth(fortheMonth);
else toDate = (DateTime)ademployee.TillDate;
if (toDate > GlobalFunctions.LastDateOfMonth(fortheMonth))
toDate = GlobalFunctions.LastDateOfMonth(fortheMonth);
if (param.Periodicity != EnumPeriodicity.OneOff)
if (employee.EndOfContractDate != null || employee.EndOfContractDate != DateTime.MinValue)
if (employee.EndOfContractDate < toDate)
toDate = (DateTime)employee.EndOfContractDate;
if (ademployee.ValueType == EnumValueType.Other)
{
//while percent of basic then not required to do fractionate of date basis
//if (this.PercentOfBasic > 0 || ademployee.MonthlyAmount >0 )
// nAmount = (basicSalary * ademployee.MonthlyAmount) / 100 * PayrollPayrollGlobalFunctions.GetFraction(ademployee.FormDate, toDate);
//else if (this.PercentOfGross > 0 || ademployee.MonthlyAmount > 0)
// nAmount = (grossSalary * ademployee.MonthlyAmount) / 100 * PayrollPayrollGlobalFunctions.GetFraction(ademployee.FormDate, toDate);
if (param.PercentOfBasic > 0 || ademployee.MonthlyAmount > 0)
nAmount = (employee.BasicSalary * ademployee.MonthlyAmount) / 100 * GlobalFunctions.GetFraction(fromDate, toDate);
else if (param.PercentOfGross > 0 || ademployee.MonthlyAmount > 0)
nAmount = (employee.GrossSalary * ademployee.MonthlyAmount) / 100 * GlobalFunctions.GetFraction(fromDate, toDate);
}
else nAmount = ademployee.MonthlyAmount * GlobalFunctions.GetFraction(fromDate, toDate);
}
else if (ademployee.Arreartype == EnumArrearType.ToCalculate)
{
if (ademployee.ValueType == EnumValueType.Other)
{
if (param.PercentOfBasic > 0 || ademployee.MonthlyAmount > 0)
nAmount = (employee.BasicSalary * ademployee.MonthlyAmount) / 100 * GlobalFunctions.GetFraction(ademployee.FormDate, (DateTime)ademployee.TillDate);
else if (param.PercentOfGross > 0 || ademployee.MonthlyAmount > 0)
nAmount = (employee.GrossSalary * ademployee.MonthlyAmount) / 100 * GlobalFunctions.GetFraction(ademployee.FormDate, (DateTime)ademployee.TillDate);
}
else nAmount = ademployee.MonthlyAmount *
GlobalFunctions.GetFraction(ademployee.FormDate, (DateTime)ademployee.TillDate);
}
break;
}
return nAmount;
}
}
}