CEL_Payroll/Payroll.BO/CarFuel/CarFuelExceptionCalculator.cs
2024-09-17 14:30:13 +06:00

104 lines
4.6 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ease.CoreV35;
using Ease.CoreV35.Model;
using Ease.CoreV35.Caching;
using System.Data.Linq.Mapping;
using System.Data;
namespace Payroll.BO
{
[Serializable]
public class CarFuelExceptionCalculator
{
private int _CarFuelLFA = 1;
private int _CarFuelUtility = 11;
private int _CarFuelKpi = 4;
private int _CarFuelPTI = 25;
public CarFuelExceptionCalculator()
{
}
/// <summary>
///
// find the employee is applicable for KPI
// if Kpi eligible, find out LFA and unitilty monthlyAmount from CarFuel Process detail Item
// KPI = LFA + Utility + (2100 percent basic)/12
// No_of_paid_month = Jan to Next_Pay_Process_Month
// paidAmount= get cumalative monthlyAmount on month range
// net_Amount= KPI + {(No_of_paid_month * KPI) - paidAmount}
// find the KPI paramter for percent of base/gross
// do percent of Net_amount;
// update CarFuelprocessdetailItem of kpi
/// </summary>
/// <param name="oprocess"></param>
public void CalculationException(ObjectsTemplate<CarFuelProcessDetail> oprocessdetails, DateTime CarFuelMonth, ObjectsTemplate<ITEmpHead> oComCars)
{
ObjectsTemplate<CarFuelParameter> _CarFuelParameters = CarFuelParameter.Get(EnumStatus.Active);
if (_CarFuelParameters == null || _CarFuelParameters.Count == 0) return;
CarFuelParameter paramter = new CarFuelParameter();
ObjectsTemplate<CarFuelParameter> parameters;
CarFuelParameter parameter = null;
double nAmount = 0;
foreach(CarFuelProcessDetail odetail in oprocessdetails)
{
parameters = paramter.ApplicableParameters(odetail.Employee, odetail, _CarFuelParameters, odetail.GradeSalaries);
if (parameters == null || parameters.Count==0) continue;
parameter = parameters[0];
nAmount = 0;
ITEmpHead car = oComCars.Find(x => x.EmployeeID == odetail.EmployeeID && (CarFuelMonth >= x.StartDate && CarFuelMonth <= x.EndDate));
if (car == null) continue;
if (car.IsArrear == 0) continue;
DateTime dtArrearFrom = car.StartDate;
DateTime dtArrearTo = GlobalFunctions.FirstDateOfMonth(Payroll.BO.SystemInformation.CurrentSysInfo.NextPayProcessDate).AddDays(-1);
if (car.StartDate < GlobalFunctions.FirstDateOfMonth(CarFuelMonth))
{
while (GlobalFunctions.FirstDateOfMonth(dtArrearFrom) <= GlobalFunctions.FirstDateOfMonth(dtArrearTo))
{
int nDaysInMonth = DateTime.DaysInMonth(dtArrearFrom.Year, dtArrearFrom.Month);
int nActualDays = 0;
if ((nDaysInMonth - dtArrearFrom.Day) == 0)
nActualDays = nDaysInMonth;
else
nActualDays = nDaysInMonth - (dtArrearFrom.Day-1);
EmployeeGradeSalary egs = EmployeeGradeSalary.GetBasicOnDate(odetail.EmployeeID, dtArrearFrom);
if (egs != null)
{
// nAmount += (((egs.BasicSalary * parameter.PercentOfBasic) / 100) / nDaysInMonth) * nActualDays;
nAmount += (parameter.FlatAmount / nDaysInMonth) * nActualDays;
}
dtArrearFrom = GlobalFunctions.LastDateOfMonth(dtArrearFrom).AddMonths(1);
}
foreach (CarFuelProcessDetailItem odetailitem in odetail.CarFuelProcessDetailItems)
{
odetailitem.ChangeNetAmount += nAmount;
}
}
//if (car != null)
//{
// if (car.StartDate > GlobalFunctions.FirstDateOfMonth(CarFuelMonth))
// {
// TimeSpan ts = car.StartDate - GlobalFunctions.FirstDateOfMonth(CarFuelMonth);
// int days = ts.Days;
// foreach (CarFuelProcessDetailItem odetailitem in odetail.CarFuelProcessDetailItems)
// {
// odetailitem.ChangeNetAmount = (odetailitem.ChangeNetAmount / 30) * 11;
// }
// }
//}
}
}
}
}