1022 lines
38 KiB
C#
1022 lines
38 KiB
C#
using System;
|
|
using Ease.Core.Model;
|
|
using Ease.Core.DataAccess;
|
|
using System.Collections.Generic;
|
|
using Ease.Core.Utility;
|
|
using HRM.BO;
|
|
using HRM.DA;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using Microsoft.AspNetCore.Mvc.ModelBinding.Binders;
|
|
using Microsoft.Data.SqlClient;
|
|
|
|
namespace HRM.DA
|
|
{
|
|
#region SalaryProcess Service
|
|
|
|
public class SalaryProcessService : ServiceTemplate, ISalaryProcessService
|
|
{
|
|
#region Mapping
|
|
|
|
private void MapObject(SalaryProcess oSalaryProcess, DataReader oReader)
|
|
{
|
|
base.SetObjectID(oSalaryProcess, (oReader.GetInt32("SalaryProcessID").Value));
|
|
oSalaryProcess.SalaryMonth = oReader.GetDateTime("SalaryMonth").Value;
|
|
oSalaryProcess.ProcessDate = oReader.GetDateTime("ProcessDate").Value;
|
|
oSalaryProcess.ProcessCode = oReader.GetString("ProcessCode");
|
|
oSalaryProcess.Remarks = oReader.GetString("Remarks");
|
|
oSalaryProcess.PaymentDate = oReader.GetDateTime("PaymentDate");
|
|
|
|
oSalaryProcess.WorkDays = oReader.GetInt32("WorkDays").Value;
|
|
oSalaryProcess.IsFinalized = oReader.GetBoolean("IsFinalized").Value;
|
|
oSalaryProcess.PayrollTypeID = oReader.GetInt32("PayrollTypeID").Value;
|
|
oSalaryProcess.ShowInDesktops = oReader.GetBoolean("SHOWINDESKTOP") != null
|
|
? oReader.GetBoolean("SHOWINDESKTOP").Value
|
|
: false;
|
|
oSalaryProcess.CreatedBy = oReader.GetInt32("CreatedBy").Value;
|
|
oSalaryProcess.CreatedDate = oReader.GetDateTime("CreationDate").Value;
|
|
|
|
oSalaryProcess.headCount = oReader.GetInt32("Count", true, 0);
|
|
//oSalaryProcess.ModifiedBy = oReader.GetInt32("ModifiedBy").Value;
|
|
//oSalaryProcess.ModifiedDate = oReader.GetDateTime("ModifiedDate");
|
|
oSalaryProcess.ShowInDesktopDate = oReader.GetDateTime("ShowInDesktopDate").HasValue
|
|
? oReader.GetDateTime("ShowInDesktopDate").Value
|
|
: DateTime.MinValue;
|
|
oSalaryProcess.MonthEndDate = oReader.GetDateTime("MonthEndDate").HasValue
|
|
? oReader.GetDateTime("MonthEndDate").Value
|
|
: DateTime.MinValue;
|
|
|
|
this.SetObjectState(oSalaryProcess, Ease.Core.ObjectState.Saved);
|
|
}
|
|
|
|
protected override T CreateObject<T>(DataReader oReader)
|
|
{
|
|
SalaryProcess oSalaryProcess = new SalaryProcess();
|
|
MapObject(oSalaryProcess, oReader);
|
|
return oSalaryProcess as T;
|
|
}
|
|
|
|
protected SalaryProcess CreateObject(DataReader oReader)
|
|
{
|
|
SalaryProcess oSalaryProcess = new SalaryProcess();
|
|
MapObject(oSalaryProcess, oReader);
|
|
return oSalaryProcess;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Service implementation
|
|
|
|
/*public SalaryProcess Get(int id)
|
|
{
|
|
SalaryProcess oSalaryProcess = new SalaryProcess();
|
|
/*#region Cache Header
|
|
oSalaryProcess = _cache["Get", id] as SalaryProcess;
|
|
if (oSalaryProcess != null)
|
|
return oSalaryProcess;
|
|
#endregion#1#
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oreader = new DataReader(SalaryProcessDA.Get(tc, id));
|
|
if (oreader.Read())
|
|
{
|
|
oSalaryProcess = this.CreateObject<SalaryProcess>(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(oSalaryProcess, "Get", id);
|
|
#endregion*/
|
|
|
|
|
|
public List<SalaryProcess> Get(DateTime dMonthDate, int payrollTypeID)
|
|
{
|
|
List<SalaryProcess> salaryProcesss = new List<SalaryProcess>();
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(SalaryProcessDA.Get(tc, dMonthDate, payrollTypeID));
|
|
salaryProcesss = this.CreateObjects<SalaryProcess>(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 salaryProcesss;
|
|
}
|
|
|
|
|
|
public List<SalaryProcess> GetUnApprovedSalaries(DateTime dMonthDate, int payrollTypeID)
|
|
{
|
|
List<SalaryProcess> salaryProcesss = new List<SalaryProcess>();
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(SalaryProcessDA.GetUnApprovedSalaries(tc, dMonthDate, payrollTypeID));
|
|
salaryProcesss = this.CreateObjects<SalaryProcess>(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 salaryProcesss;
|
|
}
|
|
|
|
|
|
|
|
public List<SalaryProcess> Get(int payrollTypeID)
|
|
{
|
|
/*#region Cache Header
|
|
|
|
List<SalaryProcess> salaryProcesss = _cache["Get"] as List<SalaryProcess>;
|
|
if (salaryProcesss != null)
|
|
return salaryProcesss;
|
|
|
|
#endregion*/
|
|
|
|
List<SalaryProcess> salaryProcesss = new List<SalaryProcess>();
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(SalaryMonthlyDA.Get(tc, payrollTypeID));
|
|
salaryProcesss = this.CreateObjects<SalaryProcess>(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
|
|
}
|
|
|
|
/*#region Cache Footer
|
|
|
|
_cache.Add(salaryProcesss, "Get");
|
|
|
|
#endregion*/
|
|
|
|
return salaryProcesss;
|
|
}
|
|
|
|
public List<SalaryProcess> GetSP()
|
|
{
|
|
/*#region Cache Header
|
|
|
|
List<SalaryProcess> salaryProcesss = _cache["GetSP"] as List<SalaryProcess>;
|
|
if (salaryProcesss != null)
|
|
return salaryProcesss;
|
|
|
|
#endregion*/
|
|
|
|
List<SalaryProcess> salaryProcesss = new List<SalaryProcess>();
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(SalaryProcessDA.Get(tc));
|
|
salaryProcesss = this.CreateObjects<SalaryProcess>(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
|
|
}
|
|
|
|
/*#region Cache Footer
|
|
|
|
_cache.Add(salaryProcesss, "Get");
|
|
|
|
#endregion
|
|
*/
|
|
|
|
return salaryProcesss;
|
|
}
|
|
|
|
public int Save(TransactionContext tc, SalaryProcess oSalaryProcess)
|
|
{
|
|
try
|
|
{
|
|
if (oSalaryProcess.IsNew)
|
|
{
|
|
int id = tc.GenerateID("SalaryProcess", "SalaryProcessID");
|
|
//int id = tc.GenerateID("SalaryMonthly", "SalaryMonthlyID");
|
|
base.SetObjectID(oSalaryProcess, (id));
|
|
SalaryProcessDA.Insert(tc, oSalaryProcess);
|
|
}
|
|
else
|
|
{
|
|
SalaryProcessDA.Update(tc, oSalaryProcess);
|
|
}
|
|
|
|
return oSalaryProcess.ID;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
}
|
|
|
|
private List<SalaryProcessStatus> SalaryValidation(SalaryProcess item, List<Employee> employees)
|
|
{
|
|
List<SalaryProcessStatus> errorList = new List<SalaryProcessStatus>();
|
|
DataSet GradeSalary = new EmployeeGradeSalaryService().GetmultipleTilldatedemp(item.PayrollTypeID);
|
|
int nCount = 0;
|
|
if (GradeSalary.Tables[0].Rows.Count > 0)
|
|
{
|
|
string smsg = string.Empty;
|
|
|
|
foreach (DataRow oRow in GradeSalary.Tables[0].Rows)
|
|
{
|
|
nCount = nCount + 1;
|
|
var emp = employees.FirstOrDefault(x => x.ID == Convert.ToInt32(oRow["EmployeeId"]));
|
|
if (emp != null)
|
|
{
|
|
errorList.Add(new SalaryProcessStatus(emp.EmployeeNo, emp.Name,
|
|
"Salary Entry Error, please see the Life-cycle-salary information"));
|
|
}
|
|
}
|
|
}
|
|
|
|
DataTable bonuses= this.NotApprovedBonuses(item.PayrollTypeID);
|
|
nCount = 0;
|
|
if (bonuses != null && bonuses.Rows.Count > 0)
|
|
{
|
|
foreach (DataRow oRow in bonuses.Rows)
|
|
{
|
|
nCount = nCount + 1;
|
|
errorList.Add(new SalaryProcessStatus(oRow["EMPLOYEENO"].ToString(), oRow["NAME"].ToString(),
|
|
oRow["BONUS"].ToString() + " Bonus not yet Approved."));
|
|
}
|
|
}
|
|
return errorList;
|
|
}
|
|
public List<SalaryProcessStatus> SalaryProcess(SalaryProcess item, List<Employee> employees)
|
|
{
|
|
try
|
|
{
|
|
string msg = String.Empty;
|
|
List<SalaryProcessStatus> salaryProcessStatusList = new List<SalaryProcessStatus>();
|
|
var items = this.SalaryValidation(item, employees);
|
|
if (items.Count != 0) return items;
|
|
|
|
SalaryCalculator calculator = new SalaryCalculator();
|
|
//salaryProcessStatusList = CheckForApprove(employees, item.SalaryMonth, item.PayrollTypeID);
|
|
if (msg != string.Empty)
|
|
{
|
|
throw new Exception("Salary can not be processed..");
|
|
}
|
|
|
|
calculator.Process(employees, item.SalaryMonth, item.PayrollTypeID, item.EuroRate);
|
|
if (calculator.ErrorList.Count == 0)
|
|
new SalaryMonthlyService().Save(item, calculator.SalaryMonthlies);
|
|
//salaryProcessStatusList.ForEach(item => calculator.ErrorList.Add(item));
|
|
return calculator.ErrorList;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
}
|
|
|
|
public DataTable NotApprovedBonuses(int payrollTypeID)
|
|
{
|
|
DataTable oEmpBasicGrades = new DataTable();
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
oEmpBasicGrades = SalaryMonthlyDA.NotApprovedBonus(tc, 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 oEmpBasicGrades;
|
|
}
|
|
|
|
private List<SalaryProcessStatus> CheckForApprove(List<Employee> _employees, DateTime dtpSalaryMonth, int payrollTypeId)
|
|
{
|
|
List<AllowanceDeduction> _oLAllowDeducts = new AllowanceDeductionService().Get(EnumStatus.Regardless);
|
|
List<SalaryProcessStatus> salaryProcessStatusList = new List<SalaryProcessStatus>();
|
|
ADParameterEmployeeService adParameterEmployeeService = new ADParameterEmployeeService();
|
|
ApproveFinantialDataService approveFinantialDataService = new ApproveFinantialDataService();
|
|
EmpLifeCycleService empLifeCycleService = new EmpLifeCycleService();
|
|
EmployeeBankAccountService employeeBankAccountService = new EmployeeBankAccountService();
|
|
string msg = string.Empty;
|
|
bool isApprove1 = true;
|
|
bool isApprove2 = true;
|
|
bool isApprove3 = true;
|
|
bool isApprove4 = true;
|
|
//bool noData = false;
|
|
DateTime dtFrom = Global.DateFunctions.FirstDateOfMonth(dtpSalaryMonth);
|
|
DateTime dtTo = Global.DateFunctions.LastDateOfMonth(dtpSalaryMonth);
|
|
List<ApproveFinantialData> oDatas = approveFinantialDataService.GetByMonth(dtFrom, dtTo);
|
|
List<ADParameterEmployee> oADEmployeeAllownaces = adParameterEmployeeService.GetForApproval(1, dtFrom, dtTo, payrollTypeId);
|
|
List<ADParameterEmployee> oADEmployeeDeductions = adParameterEmployeeService.GetForApproval(2, dtFrom, dtTo, payrollTypeId);
|
|
List<EmpLifeCycle> _oLifeCycles = empLifeCycleService.GetByDate(dtFrom, dtTo, payrollTypeId);
|
|
List<EmployeeBankAccount> _oEmployeeBankAccounts = employeeBankAccountService.GetByDate(dtFrom, dtTo, payrollTypeId);
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
foreach (Employee emp in _employees)
|
|
{
|
|
if (oADEmployeeAllownaces.Count > 0 && oDatas.Count > 0)
|
|
{
|
|
ADParameterEmployee itemAD = oADEmployeeAllownaces.Find(delegate (ADParameterEmployee oData) { return oData.EmployeeID == emp.ID; });
|
|
ApproveFinantialData item = null;
|
|
if (itemAD != null)
|
|
item = oDatas.Find(delegate (ApproveFinantialData oData)
|
|
{
|
|
return oData.EmployeeID == emp.ID &&
|
|
oData.FinantialDataType == EnumApprovalFinancialData.Allowance &&
|
|
oData.ObjectID == itemAD.ID;
|
|
});
|
|
|
|
if (itemAD != null && item == null)
|
|
{
|
|
isApprove1 = false;
|
|
SalaryProcessStatus temp = new SalaryProcessStatus();
|
|
temp.EmployeeNo = emp.EmployeeNo;
|
|
temp.Name = emp.Name;
|
|
AllowanceDeduction ad = _oLAllowDeducts.Where(x => x.ID == itemAD.AllowDeductID).FirstOrDefault();
|
|
temp.Remarks = ad != null ? ad.Name + " -Allowance" : "Allowance";
|
|
salaryProcessStatusList.Add(temp);
|
|
}
|
|
else
|
|
isApprove1 = true;
|
|
}
|
|
else
|
|
{
|
|
ADParameterEmployee itemAD = oADEmployeeAllownaces.Find(delegate (ADParameterEmployee oData) { return oData.EmployeeID == emp.ID; });
|
|
if (itemAD != null)
|
|
{
|
|
isApprove1 = false;
|
|
SalaryProcessStatus temp = new SalaryProcessStatus();
|
|
temp.EmployeeNo = emp.EmployeeNo;
|
|
temp.Name = emp.Name;
|
|
AllowanceDeduction ad = _oLAllowDeducts.Where(x => x.ID == itemAD.AllowDeductID).FirstOrDefault();
|
|
temp.Remarks = ad != null ? ad.Name + " -Allowance" : "Allowance";
|
|
salaryProcessStatusList.Add(temp);
|
|
}
|
|
else
|
|
isApprove1 = true;
|
|
}
|
|
if (oADEmployeeDeductions.Count > 0 && oDatas.Count > 0)
|
|
{
|
|
ADParameterEmployee itemAD = oADEmployeeDeductions.Find(delegate (ADParameterEmployee oData) { return oData.EmployeeID == emp.ID; });
|
|
ApproveFinantialData item = null;
|
|
if (itemAD != null)
|
|
item = oDatas.Find(delegate (ApproveFinantialData oData) { return oData.EmployeeID == emp.ID && oData.FinantialDataType == EnumApprovalFinancialData.Deduction && oData.ObjectID == itemAD.ID; });
|
|
|
|
if (itemAD != null && item == null)
|
|
{
|
|
isApprove2 = false;
|
|
SalaryProcessStatus temp = new SalaryProcessStatus();
|
|
temp.EmployeeNo = emp.EmployeeNo;
|
|
temp.Name = emp.Name;
|
|
AllowanceDeduction ad = _oLAllowDeducts.Where(x => x.ID == itemAD.AllowDeductID).FirstOrDefault();
|
|
temp.Remarks = ad != null ? ad.Name + " -Deduction" : "Deduction";
|
|
salaryProcessStatusList.Add(temp);
|
|
}
|
|
else
|
|
isApprove2 = true;
|
|
}
|
|
else
|
|
{
|
|
ADParameterEmployee itemAD = oADEmployeeDeductions.Find(delegate (ADParameterEmployee oData) { return oData.EmployeeID == emp.ID; });
|
|
if (itemAD != null)
|
|
{
|
|
isApprove2 = false;
|
|
SalaryProcessStatus temp = new SalaryProcessStatus();
|
|
temp.EmployeeNo = emp.EmployeeNo;
|
|
temp.Name = emp.Name;
|
|
AllowanceDeduction ad = _oLAllowDeducts.Where(x => x.ID == itemAD.AllowDeductID).FirstOrDefault();
|
|
temp.Remarks = ad != null ? ad.Name + " -Deduction" : "Deduction";
|
|
salaryProcessStatusList.Add(temp);
|
|
}
|
|
else
|
|
isApprove2 = true;
|
|
}
|
|
|
|
if (_oLifeCycles.Count > 0 && oDatas.Count > 0)
|
|
{
|
|
EmpLifeCycle empLC = _oLifeCycles.Find(delegate (EmpLifeCycle oData) { return oData.EmployeeID == emp.ID; });
|
|
ApproveFinantialData item = null;
|
|
if (empLC != null)
|
|
item = oDatas.Find(delegate (ApproveFinantialData oData) { return oData.EmployeeID == emp.ID && oData.FinantialDataType == EnumApprovalFinancialData.Lifecycle && oData.ObjectID == empLC.ID; });
|
|
|
|
if (empLC != null && item == null)
|
|
{
|
|
isApprove3 = false;
|
|
SalaryProcessStatus temp = new SalaryProcessStatus();
|
|
temp.EmployeeNo = emp.EmployeeNo;
|
|
temp.Name = emp.Name;
|
|
temp.Remarks = "Employee Life Cycle";
|
|
salaryProcessStatusList.Add(temp);
|
|
}
|
|
else
|
|
isApprove3 = true;
|
|
}
|
|
else
|
|
{
|
|
EmpLifeCycle empLC = _oLifeCycles.Find(delegate (EmpLifeCycle oData) { return oData.EmployeeID == emp.ID; });
|
|
if (empLC != null)
|
|
{
|
|
isApprove3 = false;
|
|
SalaryProcessStatus temp = new SalaryProcessStatus();
|
|
temp.EmployeeNo = emp.EmployeeNo;
|
|
temp.Name = emp.Name;
|
|
temp.Remarks = "Employee Life Cycle";
|
|
salaryProcessStatusList.Add(temp);
|
|
}
|
|
else
|
|
isApprove3 = true;
|
|
}
|
|
if (_oEmployeeBankAccounts.Count > 0 && oDatas.Count > 0)
|
|
{
|
|
EmployeeBankAccount empLC = _oEmployeeBankAccounts.Find(delegate (EmployeeBankAccount oData) { return oData.EmployeeID == emp.ID; });
|
|
ApproveFinantialData item = null;
|
|
if (empLC != null)
|
|
item = oDatas.Find(delegate (ApproveFinantialData oData) { return oData.EmployeeID == emp.ID && oData.FinantialDataType == EnumApprovalFinancialData.BankAccountHistory && oData.ObjectID == empLC.ID; });
|
|
|
|
if (empLC != null && item == null)
|
|
{
|
|
isApprove4 = false;
|
|
SalaryProcessStatus temp = new SalaryProcessStatus();
|
|
temp.EmployeeNo = emp.EmployeeNo;
|
|
temp.Name = emp.Name;
|
|
temp.Remarks = "Employee Bank Accounts";
|
|
salaryProcessStatusList.Add(temp);
|
|
}
|
|
else
|
|
isApprove4 = true;
|
|
}
|
|
else
|
|
{
|
|
EmployeeBankAccount empLC = _oEmployeeBankAccounts.Find(delegate (EmployeeBankAccount oData) { return oData.EmployeeID == emp.ID; });
|
|
if (empLC != null)
|
|
{
|
|
isApprove4 = false;
|
|
SalaryProcessStatus temp = new SalaryProcessStatus();
|
|
temp.EmployeeNo = emp.EmployeeNo;
|
|
temp.Name = emp.Name;
|
|
temp.Remarks = "Employee Bank Accounts";
|
|
salaryProcessStatusList.Add(temp);
|
|
}
|
|
else
|
|
isApprove4 = true;
|
|
}
|
|
if (!isApprove1 || !isApprove2 || !isApprove3 || !isApprove4)
|
|
{
|
|
//if (!noData)
|
|
//{
|
|
sb.Append("Employee ID : " + emp.EmployeeNo);
|
|
sb.Append(Environment.NewLine);
|
|
//}
|
|
}
|
|
|
|
}
|
|
//if (!isApprove1 || !isApprove2 || !isApprove3)
|
|
//{
|
|
// msg = "Some financial data is not approved yet for following employees :\n" + sb.ToString();
|
|
//}
|
|
if (sb.ToString().Length > 5)
|
|
{
|
|
msg = "Some financial data is not approved yet for following employees :\n" + sb.ToString();
|
|
}
|
|
return salaryProcessStatusList;
|
|
}
|
|
public int Save(SalaryProcess oSalaryProcess)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
if (oSalaryProcess.IsNew)
|
|
{
|
|
int id = tc.GenerateID("SalaryProcess", "SalaryProcessID");
|
|
//int id = tc.GenerateID("SalaryMonthly", "SalaryMonthlyID");
|
|
base.SetObjectID(oSalaryProcess, (id));
|
|
SalaryProcessDA.Insert(tc, oSalaryProcess);
|
|
}
|
|
else
|
|
{
|
|
SalaryProcessDA.Update(tc, oSalaryProcess);
|
|
}
|
|
|
|
tc.End();
|
|
return oSalaryProcess.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);
|
|
SalaryProcessDA.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 UndoSalary(int id)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
int employeeCount = 0; // SalaryMonthlyDA.GetTotalEmp(tc, id);
|
|
SalaryProcessDA.UndoSalary(tc, id, employeeCount);
|
|
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 UndoMonthlySalaryByIDs(string ids)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
SalaryProcessDA.UndoMonthlySalaryByIDs(tc, ids);
|
|
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 UndoMonthlySalaryByEmpIDs(string ids, DateTime salaryMonth)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
SalaryProcessDA.UndoMonthlySalaryByEmpIDs(tc, ids, salaryMonth);
|
|
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 ApproveSalary(DateTime salaryMonth, int payrollTypeID)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
DataTable headCount = SalaryProcessDA.SalaryHeadCount(tc, salaryMonth, payrollTypeID);
|
|
|
|
//if (Convert.ToInt32(headCount.Rows[0][0]) == 0 ||
|
|
// Convert.ToInt32(headCount.Rows[0][0]) != Convert.ToInt32(headCount.Rows[0][1]))
|
|
//{
|
|
// throw new Exception(" Salary head Count and Live Employee Count must be same");
|
|
//}
|
|
SalaryProcessDA.ApproveSalary(tc, salaryMonth, payrollTypeID);
|
|
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 Update(SalaryProcess oSProcess)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
SalaryProcessDA.Update(tc, oSProcess);
|
|
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 SPApprove(SalaryProcess oSProcess)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
SalaryProcessDA.SPApprove(tc, oSProcess);
|
|
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 MonthEnd(int userid, DateTime salaryMonth, int payrollTypeID, DateTime paymentDate)
|
|
{
|
|
TransactionContext tc = null;
|
|
List<PFTransaction> pftransactions = new List<PFTransaction>();
|
|
List<LoanSchedule> loanshedules = new List<LoanSchedule>();
|
|
List<ESBProvision> oESBProvisions = new List<ESBProvision>();
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
|
|
bool approved = SalaryProcessDA.GetBySMonth(tc, salaryMonth, payrollTypeID);
|
|
if (approved == false)
|
|
{
|
|
throw new Exception("Salary is not yet approved, please approve the salary first to close salary-month");
|
|
}
|
|
|
|
bool monthEndStatus = SalaryProcessDA.MonthEndStatus(tc, salaryMonth, payrollTypeID);
|
|
if (monthEndStatus == true)
|
|
{
|
|
throw new Exception("Payroll-Month-End is already done for this month");
|
|
}
|
|
|
|
|
|
PFTransactionService pfservice = new PFTransactionService();
|
|
foreach (PFTransaction pftran in pftransactions)
|
|
{
|
|
int id = tc.GenerateID("PFTransaction", "PfTranID");
|
|
base.SetObjectID(pftran, (id));
|
|
pfservice.Save(tc, pftran);
|
|
id = id + 1;
|
|
}
|
|
|
|
|
|
if (loanshedules.Count > 0)
|
|
{
|
|
LoanScheduleService ls = new LoanScheduleService();
|
|
foreach (LoanSchedule shedule in loanshedules)
|
|
{
|
|
ls.UpdatePaymentDate(tc, shedule.ID, (DateTime)shedule.PaymentDate, EnumLoanPaymentMode.Salary);
|
|
}
|
|
}
|
|
//if (oESBProvisions.Count > 0)
|
|
//{
|
|
// foreach (ESBProvision oItem in oESBProvisions)
|
|
// {
|
|
|
|
// oItem.Insert();
|
|
// }
|
|
//}
|
|
|
|
List<EnumSalaryItemCode> itemCodes = new List<EnumSalaryItemCode>();
|
|
itemCodes.Add(EnumSalaryItemCode.PF_Contribution);
|
|
|
|
List<salaryHistory> salaryDetails = new SalaryMonthlyService().getbyItemCode(itemCodes, payrollTypeID,
|
|
GlobalFunctions.LastDateOfMonth(salaryMonth));
|
|
|
|
foreach(salaryHistory item in salaryDetails)
|
|
{
|
|
PFTransaction ptran = new PFTransaction();
|
|
ptran.MonthDate = salaryMonth;
|
|
ptran.EmployeeID = item.empid;
|
|
ptran.TranType = EnumPFTranType.PFAmount;
|
|
ptran.TranAmount = item.amount;
|
|
pftransactions.Add(ptran);
|
|
|
|
PFTransaction ctran = new PFTransaction();
|
|
ctran.MonthDate = salaryMonth;
|
|
ctran.EmployeeID = item.empid;
|
|
ctran.TranType = EnumPFTranType.CPFAmount;
|
|
ctran.TranAmount = item.amount;
|
|
pftransactions.Add(ctran);
|
|
|
|
}
|
|
|
|
|
|
|
|
List<PFException> oPfExceptions = new PFExceptionService().Get();
|
|
foreach (PFException oEmpPFException in oPfExceptions)
|
|
{
|
|
PFTransaction ptran = pftransactions.FirstOrDefault(x => x.EmployeeID == oEmpPFException.EmployeeID); // check the live employee
|
|
|
|
if (ptran != null)
|
|
continue;
|
|
#region EPF
|
|
|
|
var oEmp = new EmployeeService().Get(oEmpPFException.EmployeeID);
|
|
PFTransaction epf = new PFTransaction();
|
|
epf.EmployeeID = oEmpPFException.EmployeeID;
|
|
epf.MonthDate = salaryMonth;
|
|
epf.TranAmount = oEmpPFException.EPFAmount;
|
|
epf.TranType = EnumPFTranType.PFAmount;
|
|
pftransactions.Add(epf);
|
|
|
|
#endregion
|
|
|
|
#region CPF
|
|
|
|
PFTransaction cpf = new PFTransaction();
|
|
cpf.EmployeeID = oEmpPFException.EmployeeID;
|
|
cpf.MonthDate = salaryMonth;
|
|
cpf.TranAmount = oEmpPFException.CPFAmount;
|
|
cpf.TranType = EnumPFTranType.CPFAmount;
|
|
pftransactions.Add(cpf);
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
int nDetailID = tc.GenerateID("PFTRANSACTION", "PFTRanID");
|
|
DataTable detailtable = new DataTable("PFTRANSACTION");
|
|
detailtable.Columns.Add(new DataColumn("PFTRANID", typeof(int)));
|
|
detailtable.Columns.Add(new DataColumn("EMPLOYEEID", typeof(int)));
|
|
detailtable.Columns.Add(new DataColumn("TRANDATE", typeof(DateTime)));
|
|
detailtable.Columns.Add(new DataColumn("TRANAMOUNT", typeof(int)));
|
|
detailtable.Columns.Add(new DataColumn("TRANTYPE", typeof(int))); // NULL
|
|
detailtable.Columns.Add(new DataColumn("CREATEDBY", typeof(int))); // NULL
|
|
detailtable.Columns.Add(new DataColumn("CREATIONDATE", typeof(DateTime))); // NULL
|
|
detailtable.Columns.Add(new DataColumn("USERID", typeof(int)));
|
|
detailtable.Columns.Add(new DataColumn("SEQUENCENO", typeof(int)));
|
|
detailtable.Columns.Add(new DataColumn("STATUS", typeof(int)));
|
|
detailtable.Columns.Add(new DataColumn("MODIFIEDBY", typeof(int)));
|
|
detailtable.Columns.Add(new DataColumn("MODIFIEDDATE", typeof(int)));
|
|
foreach (PFTransaction detail in pftransactions)
|
|
{
|
|
|
|
nDetailID = nDetailID + 1;
|
|
detailtable.Rows.Add(
|
|
nDetailID,
|
|
detail.EmployeeID,
|
|
detail.MonthDate,
|
|
detail.TranAmount,
|
|
detail.TranType,
|
|
userid,
|
|
DateTime.Now,
|
|
userid,
|
|
1,
|
|
1,
|
|
detail.ModifiedBy,
|
|
detail.ModifiedDate);
|
|
|
|
}
|
|
|
|
using (SqlBulkCopy bulkCopy = new SqlBulkCopy((SqlConnection)tc.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)tc.Transaction))
|
|
{
|
|
bulkCopy.BulkCopyTimeout = 6000; // in seconds
|
|
bulkCopy.DestinationTableName = "PFTRANSACTION";
|
|
|
|
bulkCopy.ColumnMappings.Add("PFTRANID", "PFTRANID");
|
|
bulkCopy.ColumnMappings.Add("EMPLOYEEID", "EMPLOYEEID");
|
|
bulkCopy.ColumnMappings.Add("TRANDATE", "TRANDATE");
|
|
bulkCopy.ColumnMappings.Add("TRANAMOUNT", "TRANAMOUNT");
|
|
bulkCopy.ColumnMappings.Add("TRANTYPE", "TRANTYPE");
|
|
bulkCopy.ColumnMappings.Add("CREATEDBY", "CREATEDBY");
|
|
bulkCopy.ColumnMappings.Add("CREATIONDATE", "CREATIONDATE");
|
|
bulkCopy.ColumnMappings.Add("USERID", "USERID");
|
|
bulkCopy.ColumnMappings.Add("SEQUENCENO", "SEQUENCENO");
|
|
bulkCopy.ColumnMappings.Add("STATUS", "STATUS");
|
|
bulkCopy.ColumnMappings.Add("MODIFIEDBY", "MODIFIEDBY");
|
|
bulkCopy.ColumnMappings.Add("MODIFIEDDATE", "MODIFIEDDATE");
|
|
|
|
|
|
|
|
bulkCopy.WriteToServer(detailtable);
|
|
}
|
|
|
|
|
|
|
|
SalaryProcessDA.MonthEnd(tc, salaryMonth, payrollTypeID, userid);
|
|
|
|
|
|
|
|
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
}
|
|
|
|
public bool GetBySMonth(DateTime dSalaryMonth, int payrollTypeID)
|
|
{
|
|
TransactionContext tc = null;
|
|
bool bShowInDesktop;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
bShowInDesktop = SalaryProcessDA.GetBySMonth(tc, dSalaryMonth, 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 bShowInDesktop;
|
|
}
|
|
|
|
public List<SalaryProcess> GetAllProcess(int payrollTypeID, DateTime nextPayProcessDate)
|
|
{
|
|
List<SalaryProcess> salaryProcesss = new List<SalaryProcess>();
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader dr = new DataReader(SalaryProcessDA.GetAllProcess(tc, payrollTypeID, nextPayProcessDate));
|
|
salaryProcesss = this.CreateObjects<SalaryProcess>(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 salaryProcesss;
|
|
}
|
|
|
|
public List<SalaryProcess> GetWithPayrollType(int payrollTypeID)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
}
|
|
|
|
#endregion
|
|
} |