EchoTex_Payroll/HRM.DA/Service/OverTime/OTProcessService.cs

924 lines
34 KiB
C#
Raw Normal View History

2024-10-14 10:01:49 +06:00
using HRM.BO;
using Ease.Core.DataAccess;
using Ease.Core.Model;
using Ease.Core.Utility;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using Microsoft.Data.SqlClient;
namespace HRM.DA
{
#region OTProcess Service
public class OTProcessService : ServiceTemplate, IOTProcessService
{
#region Private functions and declaration
#endregion
private List<EmployeeOverTime> _EmpOvertimes = null;
private List<OTProcess> _OtProcess = null;
private List<TermParameter> _termParameters = null;
private int _hoursInMonth = 0;
public OTProcessService()
{
}
private void MapObject(OTProcess oOTProcess, DataReader oReader)
{
base.SetObjectID(oOTProcess, oReader.GetInt32("ProcessId").Value);
oOTProcess.MonthDate = oReader.GetDateTime("ProcessMonth").Value;
oOTProcess.EmployeeID = oReader.GetString("empID") == null ? 0 : oReader.GetInt32("empID").Value;
oOTProcess.Amount = oReader.GetDouble("amount").Value;
oOTProcess.ArrearAmount = oReader.GetDouble("ArrearAmount").Value;
oOTProcess.TermID = oReader.GetString("termID") == null ? 0 : oReader.GetInt32("termID").Value;
oOTProcess.TermParameterID = oReader.GetString("TermParameterID") == null
? 0
: oReader.GetInt32("TermParameterID").Value;
oOTProcess.EmpOverTimeID =
oReader.GetString("EmpOverTimeID") == null ? 0 : oReader.GetInt32("EmpOverTimeID").Value;
oOTProcess.TotalHour = oReader.GetDouble("Hours").Value;
oOTProcess.CreatedBy = oReader.GetString("CreatedBy") == null ? 0 : oReader.GetInt32("CreatedBy").Value;
oOTProcess.CreatedDate = oReader.GetDateTime("CreationDate").Value;
oOTProcess.ModifiedBy = oReader.GetString("ModifiedBy") == null ? 0 : oReader.GetInt32("ModifiedBy").Value;
oOTProcess.ModifiedDate = oReader.GetDateTime("ModifiedDate");
oOTProcess.OTMonth = oReader.GetDateTime("OTMonth").Value;
this.SetObjectState(oOTProcess, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
OTProcess oOTProcess = new OTProcess();
MapObject(oOTProcess, oReader);
return oOTProcess as T;
}
protected OTProcess CreateObject(DataReader oReader)
{
OTProcess oOTProcess = new OTProcess();
MapObject(oOTProcess, oReader);
return oOTProcess;
}
#region Service implementation
public List<OTProcess> Get(DateTime dMonthDate)
{
List<OTProcess> oTProcess = new List<OTProcess>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(OTProcessDA.Get(tc, dMonthDate));
oTProcess = this.CreateObjects<OTProcess>(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 oTProcess;
}
public List<OTProcess> GetOTProcessDataByMonthAndDeptID(DateTime Month, string deptID)
{
List<OTProcess> oTProcess = new List<OTProcess>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(OTProcessDA.GetOTProcessDataByMonthAndDeptID(tc, Month, deptID));
oTProcess = this.CreateObjects<OTProcess>(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 oTProcess;
}
public OTProcess Get(int id)
{
OTProcess oOTProcess = new OTProcess();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(OTProcessDA.Get(tc, id));
if (oreader.Read())
{
oOTProcess = this.CreateObject<OTProcess>(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 oOTProcess;
}
public bool IsProcessed(DateTime dMonthDate, int payrollTypeID)
{
bool isProcessed = false;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(OTProcessDA.IsProcessed(tc, dMonthDate, payrollTypeID));
if (dr.Read())
{
isProcessed = Convert.ToBoolean(dr.GetInt32(0));
}
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 isProcessed;
}
public List<OTProcess> Get()
{
List<OTProcess> oTProcess = new List<OTProcess>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(OTProcessDA.Get(tc));
oTProcess = this.CreateObjects<OTProcess>(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 oTProcess;
}
public DataSet GetOTProcessData(DateTime Month, string sEmpID)
{
DataSet oTProcess = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
oTProcess = OTProcessDA.GetOTProcessData(tc, Month, sEmpID);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return oTProcess;
}
public DataSet GetOTMonthRangeData(DateTime FDate, DateTime TDate)
{
DataSet oTProcess = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
oTProcess = OTProcessDA.GetOTMonthRangeData(tc, FDate, TDate);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return oTProcess;
}
public DataSet GetBranchWiseOT(DateTime Month)
{
DataSet oTProcess = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
oTProcess = OTProcessDA.GetBranchWiseOT(tc, Month);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return oTProcess;
}
public DataSet GetCostCenterWiseOT(DateTime dateTime, string sEmpID)
{
DataSet oTProcess = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
oTProcess = OTProcessDA.GetCostCenterWiseOT(tc, dateTime, sEmpID);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return oTProcess;
}
public DataSet GetLocationWiseOT(DateTime FDate, DateTime TDate)
{
DataSet oTProcess = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
oTProcess = OTProcessDA.GetLocationWiseOT(tc, FDate, TDate);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return oTProcess;
}
public List<OTProcess> GetbyOtMonth(string sEmpIDs, string sMonths)
{
List<OTProcess> oTProcess = new List<OTProcess>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(OTProcessDA.GetbyOtMonth(tc, sEmpIDs, sMonths));
oTProcess = this.CreateObjects<OTProcess>(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 oTProcess;
}
public int Save(OTProcess oOTProcess)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oOTProcess.IsNew)
{
int id = tc.GenerateID("OTProcess", "ProcessId");
base.SetObjectID(oOTProcess, id);
OTProcessDA.Insert(tc, oOTProcess);
}
else
{
OTProcessDA.Update(tc, oOTProcess);
}
tc.End();
return oOTProcess.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(TransactionContext tc, OTProcess oOTProcess)
{
try
{
if (oOTProcess.IsNew)
{
int id = tc.GenerateID("OTProcess", "ProcessId");
base.SetObjectID(oOTProcess, id);
OTProcessDA.Insert(tc, oOTProcess);
}
else
{
OTProcessDA.Update(tc, oOTProcess);
}
return oOTProcess.ID;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public void Save(List<OTProcess> oOTProcesss)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
foreach (OTProcess process in oOTProcesss)
{
Save(tc, process);
}
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 BulkSave(List<OTProcess> items)
{
int id = 0;
List<ADParameterEmployee> newitems = new List<ADParameterEmployee>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
id = tc.GenerateID("OTProcess", "ProcessId");
DataTable attnProcessEntryTable = new DataTable("OTProcess");
attnProcessEntryTable.Columns.Add(new DataColumn("PROCESSID", typeof(int)));
attnProcessEntryTable.Columns.Add(new DataColumn("PROCESSMONTH", typeof(DateTime)));
attnProcessEntryTable.Columns.Add(new DataColumn("EMPID", typeof(int)));
attnProcessEntryTable.Columns.Add(new DataColumn("AMOUNT", typeof(double))); // NULL
attnProcessEntryTable.Columns.Add(new DataColumn("TERMID", typeof(int))); // NULL
attnProcessEntryTable.Columns.Add(new DataColumn("HOURS", typeof(double))); // NULL
attnProcessEntryTable.Columns.Add(new DataColumn("CREATEDBY", typeof(int)));
attnProcessEntryTable.Columns.Add(new DataColumn("CREATIONDATE", typeof(DateTime)));
attnProcessEntryTable.Columns.Add(new DataColumn("MODIFIEDBY", typeof(int)));
attnProcessEntryTable.Columns.Add(new DataColumn("MODIFIEDDATE", typeof(DateTime)));
attnProcessEntryTable.Columns.Add(new DataColumn("TERMPARAMETERID", typeof(int)));
attnProcessEntryTable.Columns.Add(new DataColumn("EMPOVERTIMEID", typeof(int)));
attnProcessEntryTable.Columns.Add(new DataColumn("ARREARAMOUNT", typeof(double))); // NULL
attnProcessEntryTable.Columns.Add(new DataColumn("OTMONTH", typeof(DateTime))); // NULL,
attnProcessEntryTable.Columns.Add(new DataColumn("PAYROLLTYPEID", typeof(int))); // NULL,
foreach (OTProcess item in items)
{
id = id + 1;
attnProcessEntryTable.Rows.Add(
id,
item.MonthDate,
item.EmployeeID,
item.Amount,
item.TermID,
item.TotalHour,
item.CreatedBy,
item.CreatedDate,
item.ModifiedBy,
item.ModifiedDate,
item.TermParameterID,
item.EmpOverTimeID,
item.ArrearAmount,
item.OTMonth,
item.PayrollTypeID
);
}
using (SqlBulkCopy bulkCopy = new SqlBulkCopy((SqlConnection)tc.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)tc.Transaction))
{
bulkCopy.BulkCopyTimeout = 6000; // in seconds
bulkCopy.ColumnMappings.Add("PROCESSID", "PROCESSID");
bulkCopy.ColumnMappings.Add("PROCESSMONTH", "PROCESSMONTH");
bulkCopy.ColumnMappings.Add("EMPID", "EMPID");
bulkCopy.ColumnMappings.Add("AMOUNT", "AMOUNT");
bulkCopy.ColumnMappings.Add("TERMID", "TERMID");
bulkCopy.ColumnMappings.Add("HOURS", "HOURS");
bulkCopy.ColumnMappings.Add("CREATEDBY", "CREATEDBY");
bulkCopy.ColumnMappings.Add("CREATIONDATE", "CREATIONDATE");
bulkCopy.ColumnMappings.Add("MODIFIEDBY", "MODIFIEDBY");
bulkCopy.ColumnMappings.Add("MODIFIEDDATE", "MODIFIEDDATE");
bulkCopy.ColumnMappings.Add("TERMPARAMETERID", "TERMPARAMETERID");
bulkCopy.ColumnMappings.Add("EMPOVERTIMEID", "EMPOVERTIMEID");
bulkCopy.ColumnMappings.Add("ARREARAMOUNT", "ARREARAMOUNT");
bulkCopy.ColumnMappings.Add("OTMONTH", "OTMONTH");
bulkCopy.ColumnMappings.Add("PAYROLLTYPEID", "PAYROLLTYPEID");
bulkCopy.DestinationTableName = "OTProcess";
bulkCopy.WriteToServer(attnProcessEntryTable);
}
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 Delete(DateTime dMonthDate, int nPayrollTypeID)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
OTProcessDA.Delete(tc, dMonthDate, nPayrollTypeID);
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 Delete(int id)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
OTProcessDA.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
}
}
#endregion
#region OT Process/Calculator
public void Process(List<Employee> emps, int userid, int payrolltypeid)
{
// TermParameter.EntryType = ConfigurationManager.GetStringValue("overtime", "entrytype", EnumConfigurationType.Logic);
bool calOnEarnedBasic = new SystemConfigarationService().GetconfigBooleanValue(EnumConfigurationType.Logic, "overtime", "earnedbasic");
int basicOnMonth = Convert.ToInt32(new SystemConfigarationService().GetconfigValue(EnumConfigurationType.Logic, "overtime", "basicondate"));
bool fixedotmonth = new SystemConfigarationService().GetconfigBooleanValue(EnumConfigurationType.Logic, "overtime", "fixedotmonth");
if (basicOnMonth == 0) basicOnMonth = 1;
_hoursInMonth = Convert.ToInt32(new SystemConfigarationService().GetconfigValue(EnumConfigurationType.Logic, "overtime", "hoursonmonth"));
PayrollType ptype = new PayrollTypeService().Get(payrolltypeid);
List<Employee> omployees = emps;
if (emps == null) omployees = new EmployeeService().Get(EnumEmployeeStatus.Live, payrolltypeid);
_OtProcess = new List<OTProcess>();
_EmpOvertimes = new EmployeeOverTimeService().Get(ptype.NextPayProcessDate, payrolltypeid);
double basicSalary = 0;
_termParameters = new TermParameterService().GetwithDetail(payrolltypeid);
if (_EmpOvertimes != null && _EmpOvertimes.Count > 0)
{
////ForTest
//_EmpOvertimes = _EmpOvertimes.Where(e => e.EmployeeID == 599).ToList();//March to apr salary change
foreach (EmployeeOverTime ot in _EmpOvertimes)
{
basicSalary = 0;
ot.PayrollTypeID = payrolltypeid;
DateTime basicDate = new DateTime(ot.OTMonth.Year, ot.OTMonth.Month, basicOnMonth);
if (calOnEarnedBasic == false)
{
Employee omp = omployees.FirstOrDefault(x => x.ID == ot.EmployeeID);
ot.Employee = omp;
if (omp != null)
basicSalary = omp.BasicSalary;
if(omp == null || omp.GradeID ==null)
{
//Employee oemp = new EmployeeService().Get(ot.EmployeeID);
//throw new Exception("Employee: " + oemp.EmployeeNo + " is not live or Grade not yet assiged");
continue;
}
#region Old
//EmployeeGradeSalary gs = EmployeeGradeSalary.Get(ot.EmployeeID,
// basicDate, EnumArrearType.NotPresent);
//if (gs == null) gs = EmployeeGradeSalary.Get(ot.EmployeeID,
// PayrollPayrollGlobalFunctions.PayrollLastDateOfMonth(ot.OTMonth), EnumArrearType.ToCalculate);
//if (gs == null)
//{
// if (ot.Employee.BasicSalary == 0)
// {
// throw new ServiceException(" Basic salary not found for the employee:" + ot.Employee.Name
// + "( " + ot.Employee.EmployeeNo + ") on month" + ot.OTMonth.ToString("MMM yyyy"));
// }
// else
// {
// //DateTime dMonth = SystemInformation.CurrentSysInfo.NextPayProcessDate;
// //if(ot.Employee.JoiningDate.Month == SystemInformation.CurrentSysInfo.NextPayProcessDate.Month &&
// // ot.Employee.JoiningDate.Month == SystemInformation.CurrentSysInfo.NextPayProcessDate.Month)
// // dMonth =ot.Employee.JoiningDate;
// basicSalary = ot.Employee.BasicSalary;
// }
//}
////else basicSalary = gs.BasicSalary * PayrollPayrollGlobalFunctions.GetFractinalOfMonth(gs.EffectDate);
//// doesn't need to fractionate, cause it is not base on earned basic;
//else basicSalary = gs.BasicSalary ;
//else basicSalary = ot.Employee.BasicSalary; // for redisha back process
#endregion Old
if (!fixedotmonth)
{
EmployeeGradeSalary gs = new EmployeeGradeSalaryService().Get(ot.EmployeeID,
GlobalFunctions.LastDateOfMonth(ot.OTMonth), EnumArrearType.NotPresent);
if (gs == null) gs = new EmployeeGradeSalaryService().Get(ot.EmployeeID,
GlobalFunctions.LastDateOfMonth(ot.OTMonth), EnumArrearType.ToCalculate);
if (gs == null)
{
if (ot.Employee.BasicSalary == 0)
{
throw new ServiceException(" Basic salary not found for the employee:" + ot.Employee.Name
+ "( " + ot.Employee.EmployeeNo + ") on month" + ot.OTMonth.ToString("MMM yyyy"));
}
else basicSalary = ot.Employee.BasicSalary;//* PayrollPayrollGlobalFunctions.GetFractinalOfMonth(ot.Employee.JoiningDate);
}
else basicSalary = gs.BasicSalary * GlobalFunctions.GetFractinalOfMonth(gs.EffectDate);
}
}
else
{
SalaryMonthly salary = new SalaryMonthlyService().Get(ot.EmployeeID, GlobalFunctions.LastDateOfMonth(ot.OTMonth));
if (salary == null)
{
EmployeeGradeSalary gs = new EmployeeGradeSalaryService().Get(ot.EmployeeID,
GlobalFunctions.LastDateOfMonth(ot.OTMonth), EnumArrearType.NotPresent);
if (gs == null) gs = new EmployeeGradeSalaryService().Get(ot.EmployeeID,
GlobalFunctions.LastDateOfMonth(ot.OTMonth), EnumArrearType.ToCalculate);
if (gs == null)
{
if (ot.Employee.BasicSalary == 0)
{
throw new ServiceException(" Basic salary not found for the employee:" + ot.Employee.Name
+ "( " + ot.Employee.EmployeeNo + ") on month" + ot.OTMonth.ToString("MMM yyyy"));
}
else basicSalary = ot.Employee.BasicSalary;//* PayrollPayrollGlobalFunctions.GetFractinalOfMonth(ot.Employee.JoiningDate);
}
else basicSalary = gs.BasicSalary * GlobalFunctions.GetFractinalOfMonth(gs.EffectDate);
}
else
{
basicSalary = salary.GetGrossAmount(EnumSalaryItemCode.Basic_Salary, (int)EnumSalaryItemCode.Basic_Salary);
}
}
_OtProcess.Add(CreateObject(ot, basicSalary));
}
}
_OtProcess.ForEach(x =>
{
x.CreatedBy = userid;
x.CreatedDate = DateTime.Today;
});
new OTProcessService().BulkSave(_OtProcess);
}
public double ConvertToDailyRate(double nBasic, DateTime dMonthDate)
{
double amount = 0;
amount = nBasic / Convert.ToDouble(DateTime.DaysInMonth(dMonthDate.Year, dMonthDate.Month));
return amount;
}
public DataSet GetCCWiseOTSummary(DateTime dateTime, string sEmpID)
{
DataSet oTProcess = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
oTProcess = OTProcessDA.GetCCWiseOTSummary(tc, dateTime, sEmpID);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return oTProcess;
}
public double ConvertToHourlyRate(double nBasic, DateTime dMonthDate, int hoursinMonth)
{
double amount = 0;
double hours = Convert.ToDouble( hoursinMonth);
// if (hours <= 0) hours = GlobalFunctions.defaultConfigVal.roundOfDigit;
double doubleHOur = Convert.ToDouble(hours);
amount = nBasic / doubleHOur;
return amount;
}
public double Calculate(TermParameter param, double nHour, double nBasic, DateTime month)
{
switch (TermParameter.EntryType.ToUpper())
{
case "MINUTE":
nHour = Math.Floor(nHour);
nHour += (nHour - nHour) * 100 / 60;
break;
}
switch (param.Type)
{
case EnumOverTimeType.AnyAmount:
return nHour;
case EnumOverTimeType.DailyBasicPercent:
return (GlobalFunctions.ConvertToDailyRate(nBasic, month) * nHour * param.Amount / 100);
case EnumOverTimeType.DailyFlatAmount:
return nHour;
case EnumOverTimeType.FixedAmount:
return nHour;
case EnumOverTimeType.HourlyBasicPercent:
return this.ConvertToHourlyRate(nBasic, month, param.housInMonth) * nHour * param.Amount / 100;
case EnumOverTimeType.HourlyFlatAmount:
return nHour * param.Amount;
case EnumOverTimeType.HoursOfMonth:
break;
//case EnumOverTimeType.Slab:
// ObjectsTemplate<OTSlab> slabs = OTSlab.GetByTermID(this.TermID);
// double amount = 0;
// if (slabs != null)
// {
// for (int i = 1; i < slabs.Count; i++)
// {
// amount = slabs[i].Amount;
// if (slabs[i].Hours > Math.Round(nHour, 0))
// {
// amount = slabs[i - 1].Amount;
// break;
// }
// }
// }
// return amount;
}
return 0;
}
public double GetPayableAmount(EmployeeOverTime ot, double nBasic)
{
TermParameter tparam = TermParameter.GetParameter(this._termParameters, (int)ot.Employee.GradeID, ot.TermID);
if (tparam == null) throw new Exception("OT parameter/Policy not found for the employee:"
+ ot.Employee.EmployeeNo + " " + ot.Employee.Name);
double nHour = ot.OTHours;
//if ((ot.OTHours - nHour) == 0)
//{
// throw new Exception("Monthly OT hours can be zero");
//}
nHour = Math.Floor(ot.OTHours);
nHour += (ot.OTHours - nHour) * 100 / 60;
switch (tparam.Type)
{
case EnumOverTimeType.AnyAmount:
return ot.OTHours;
case EnumOverTimeType.DailyBasicPercent:
return (this.ConvertToDailyRate(nBasic, ot.OTMonth) * ot.OTHours ) * (tparam.Amount / 100);
case EnumOverTimeType.DailyFlatAmount:
return ot.OTHours * tparam.Amount;
case EnumOverTimeType.FixedAmount:
return ot.OTHours ;
case EnumOverTimeType.HourlyBasicPercent:
return this.ConvertToHourlyRate(nBasic, ot.OTMonth, tparam.housInMonth) * ot.OTHours * (tparam.Amount/100);
case EnumOverTimeType.HourlyFlatAmount:
return ot.OTHours * tparam.Amount;
case EnumOverTimeType.HoursOfMonth:
break;
//case EnumOverTimeType.Slab:
// List<OTSlab> slabs = OTSlab.GetByTermID(ot.TermID);
// double amount = 0;
// if (slabs != null)
// {
// for (int i = 1; i < slabs.Count; i++)
// {
// amount = slabs[i].Amount;
// if (slabs[i].Hours > Math.Round(ot.OTHours, 0))
// {
// amount = slabs[i - 1].Amount;
// break;
// }
// }
// }
// return amount;
}
return 0;
}
//public List<OTProcess> Process(Employee oEmp)
//{
// _OtProcess = new List<OTProcess>();
// _EmpOvertimes = EmployeeOverTime.GetByEmpID(oEmp.ID, SystemInformation.CurrentSysInfo.NextPayProcessDate);
// if (_EmpOvertimes != null && _EmpOvertimes.Count > 0)
// {
// foreach (EmployeeOverTime ot in _EmpOvertimes)
// {
// _OtProcess.Add(CreateObject(ot, ot.Employee.BasicSalary));
// }
// OTProcess.Insert(_OtProcess);
// }
// return _OtProcess;
//}
public OTProcess ProcessArrear(OTProcess process, Double nBasic)
{
OTProcess oNewProcess = CreateObject(process.EmpOverTime, nBasic);
process.Amount = oNewProcess.Amount - process.Amount;
return process;
}
private OTProcess CreateObject(EmployeeOverTime ot, Double nBasic)
{
OTProcess process = new OTProcess();
process.EmployeeID = ot.EmployeeID;
process.EmpOverTimeID = ot.ID;
process.MonthDate = GlobalFunctions.LastDateOfMonth(ot.MonthDate);
process.OTMonth = GlobalFunctions.LastDateOfMonth(ot.OTMonth);
process.TermID = ot.TermID;
process.TermParameterID = ot.TermParameterID;
process.TotalHour = ot.OTHours;
process.Amount = this.GetPayableAmount(ot, nBasic);
process.PayrollTypeID = ot.PayrollTypeID;
return process;
}
#endregion OT Process/Calculator
}
#endregion
}