CEL_Payroll/Payroll.BO/Salary/MonthEnd.cs

205 lines
8.1 KiB
C#
Raw Normal View History

2024-09-17 14:30:13 +06:00
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;
using System.Collections;
namespace Payroll.BO
{
[Serializable]
public class MonthEnd:BasicBaseObject
{
private DateTime _month;
private DateTime _dPaymentDate;
private ObjectsTemplate<SalaryMonthly> _salaryMonthlys;
private ObjectsTemplate<PFTransaction> _pfTransactions;
private ObjectsTemplate<LoanSchedule> _loanShedules;
private ObjectsTemplate<IncomeTax> _incometaxes;
private ObjectsTemplate<ESBDefinition> _oESBDefinitions = null;
private ObjectsTemplate<ESBProvision> _oESBProvisions = null;
ObjectsTemplate<SalaryProcess> _oSProcess = null;
public MonthEnd()
{
}
private bool Validation()
{
return false;
}
public void DoMonthEnd(DateTime month, ObjectsTemplate<SalaryMonthly> salaries,DateTime dPaymentDate)
{
_dPaymentDate = dPaymentDate;
_salaryMonthlys = salaries;
_loanShedules = new ObjectsTemplate<LoanSchedule>();
_month = month;
_oSProcess = SalaryProcess.Get(month);
Process();
SalaryProcess sprocess = new SalaryProcess();
SalaryProcess.Service.MonthEnd(month,_pfTransactions,_loanShedules,_oESBProvisions,Payroll.BO.SystemInformation.CurrentSysInfo.PayrollTypeID.Integer);
SystemInformation sinfo = SystemInformation.Get();
sinfo.NextPayProcessDate = month;
SystemInformation.Service.Update(sinfo);
}
private void Process()
{
_oESBDefinitions = new ObjectsTemplate<ESBDefinition>();
_oESBProvisions = new ObjectsTemplate<ESBProvision>();
List<PFException> oPfExceptions = PFException.Get();
List<Employee> oEmployees = Employee.GetAllEmps();
ESBProvision oESBProvision = null;
ESBDefinition oESBDefinition = null;
DataSet oDS=null;
bool doProvision = ConfigurationManager.GetBoolValue("gratuity", "doprovision", EnumConfigurationType.Logic);
if (doProvision)
{
oDS = new DataSet();
//oDS = ESBProvision.GetCumulativeProv(_month);
_oESBDefinitions = ESBDefinition.Get();
}
_pfTransactions = new ObjectsTemplate<PFTransaction>();
foreach(SalaryProcess oSP in _oSProcess)
{
oSP.PaymentDate = _dPaymentDate;
oSP.MonthEndDate = Payroll.BO.SystemInformation.CurrentSysInfo.NextPayProcessDate;
oSP.Update(oSP);
}
foreach (SalaryMonthly item in _salaryMonthlys)
{
Employee oEmp = oEmployees.FirstOrDefault(x => x.ID == item.EmployeeID);
if (oEmp != null && oEmp.PFMemberType == EnumPFMembershipType.Live)
{
//_pfTransactions = new ObjectsTemplate<PFTransaction>();
#region PF transaction
#region EPF
PFTransaction epf = new PFTransaction();
epf.EmployeeID = item.EmployeeID;
epf.MonthDate = _month;
epf.TranAmount = item.GetDeductAmount(EnumSalaryItemCode.PF_Contribution, (int)EnumSalaryItemCode.PF_Contribution);
epf.TranType = EnumPFTranType.PFAmount;
epf.SetAuditTrail();
_pfTransactions.Add(epf);
#endregion
#region CPF
PFException oEmpPFException = oPfExceptions.FirstOrDefault(x => x.EmployeeID == item.Employee.ID);
PFTransaction cpf = new PFTransaction();
cpf.EmployeeID = item.EmployeeID;
cpf.MonthDate = _month;
if (oEmpPFException != null) // && oEmpPFException.StartDate <= item.SalaryMonth) // Dont open this
{
cpf.TranAmount = oEmpPFException.CPFPercent == 0 ? oEmpPFException.CPFAmount : GlobalFunctions.Round(item.ThisMonthBasic * (oEmpPFException.CPFPercent / 100));
}
else
{
cpf.TranAmount = item.GetDeductAmount(EnumSalaryItemCode.PF_Contribution, (int)EnumSalaryItemCode.PF_Contribution);
}
cpf.TranType = EnumPFTranType.CPFAmount;
cpf.SetAuditTrail();
_pfTransactions.Add(cpf);
#endregion
#endregion PF transaction
}
#region Loan Installment payment update
List<SalaryMonthlyDetail> loans = item.Details.FindAll(delegate(SalaryMonthlyDetail detail)
{
return detail.ItemCode == EnumSalaryItemCode.Loan_Monthly_Installment;
});
if (loans != null)
{
foreach (SalaryMonthlyDetail loan in loans)
{
LoanSchedule laonshedule = new LoanSchedule();
laonshedule.PaymentDate = _month;
laonshedule.setId(loan.SupportID);
_loanShedules.Add(laonshedule);
}
}
#endregion Loan Installment payment update
#region Gratuity Provision
if (doProvision)
{
oESBDefinition = ESBDefinition.Get(_oESBDefinitions, item.Employee);
if (oESBDefinition == null) throw new ServiceException("gratuity rule not found for the employee"); // add employee NO and Name
oESBProvision = new ESBProvision();
oESBDefinition.CalculateProvisionAmount(item.Employee, item.Details, oESBProvision, oDS);
oESBProvision.EmployeeID = item.EmployeeID;
oESBProvision.SalaryMonthlyID = item.ID;
oESBProvision.ProcessMonthDate = item.SalaryMonth;
oESBProvision.UserID = Payroll.BO.User.CurrentUser.UserAccessTypes[0].PayrollTypeObj.ID;
_oESBProvisions.Add(oESBProvision);
}
#endregion
}
#region PF Exception
foreach (PFException oEmpPFException in oPfExceptions)
{
Employee oEmp = oEmployees.FirstOrDefault(x => x.ID == oEmpPFException.EmployeeID);
if (oEmp == null)
continue;
if (_salaryMonthlys.Any(x => x.EmployeeID == oEmpPFException.EmployeeID))
{
if (oEmp.PFMemberType == EnumPFMembershipType.Live)
continue;
}
//if (oEmpPFException.StartDate > _month)
// continue;
#region EPF
PFTransaction epf = new PFTransaction();
epf.EmployeeID = oEmpPFException.EmployeeID;
epf.MonthDate = _month;
epf.TranAmount = oEmpPFException.EPFPercent == 0 ? oEmpPFException.EPFAmount : GlobalFunctions.Round(oEmp.BasicSalary * (oEmpPFException.EPFPercent / 100));
epf.TranType = EnumPFTranType.PFAmount;
epf.SetAuditTrail();
_pfTransactions.Add(epf);
#endregion
#region CPF
PFTransaction cpf = new PFTransaction();
cpf.EmployeeID = oEmpPFException.EmployeeID;
cpf.MonthDate = _month;
cpf.TranAmount = oEmpPFException.CPFPercent == 0 ? oEmpPFException.CPFAmount : GlobalFunctions.Round(oEmp.BasicSalary * (oEmpPFException.CPFPercent / 100));
cpf.TranType = EnumPFTranType.CPFAmount;
cpf.SetAuditTrail();
_pfTransactions.Add(cpf);
#endregion
}
#endregion
}
}
}