2026-11-03 13:06:00 +06:00
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 ;
using NPOI.SS.Formula.Functions ;
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 ;
oSalaryProcess . WFStatus = oReader . GetInt32 ( "WFStatus" ) = = null ? null : ( enumwfStatus ) oReader . GetInt32 ( "WFStatus" ) . Value ;
oSalaryProcess . NotifyEmail = oReader . GetString ( "NotifyEmail" , "" ) ;
oSalaryProcess . IsBankTransfer = oReader . GetBoolean ( "IsBankTransfer" , false ) ;
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." ) ) ;
}
}
List < TaxParameter > tps = new TaxParameterService ( ) . Get ( true , item . PayrollTypeID ) ;
if ( tps ! = null & & tps . Count > 0 )
{
//DataSet taxdeducted = new IncomeTaxService().EmployeeWiseTaxDeductedRecon(EnumIncomeTaxDataFrom.ProcessTempData, employees.CommaSeparatedIDs(), tps[0].FiscalyearDatefrom, tps[0].FiscalyearDateTo);
//nCount = 0;
//if (taxdeducted != null && taxdeducted.Tables[0].Rows.Count > 0)
//{
// foreach (DataRow oRow in taxdeducted.Tables[0].Rows)
// {
// nCount = nCount + 1;
// if (Convert.ToDouble(oRow["SalaryData"].ToString())!= Convert.ToDouble(oRow["TaxData"].ToString()))
// errorList.Add(new SalaryProcessStatus(oRow["EMPLOYEENO"].ToString(), oRow["Name"].ToString(),
// "Tax data not align with salary data."));
// }
//}
}
return errorList ;
}
2026-11-29 18:51:10 +06:00
// Salary Process screen, no employee selected but a Category: the Live employees of the payroll type in
// that category whose salary of the month is not processed yet (the employee picker leaves those out too)
public List < int > GetCategoryEmployeeIDs ( int categoryID , int payrollTypeID , DateTime salaryMonth )
{
List < int > employeeIDs = new List < int > ( ) ;
TransactionContext tc = null ;
try
{
tc = TransactionContext . Begin ( ) ;
DataReader dr = new DataReader ( SalaryProcessDA . GetCategoryEmployeeIDs ( tc , categoryID , payrollTypeID , salaryMonth ) ) ;
while ( dr . Read ( ) )
{
employeeIDs . Add ( dr . GetInt32 ( "EmployeeID" ) . Value ) ;
}
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 employeeIDs ;
}
2026-11-03 13:06:00 +06:00
public List < SalaryProcessStatus > SalaryProcess ( SalaryProcess item , List < Employee > employees )
2026-11-30 13:35:21 +06:00
{
return this . SalaryProcess ( item , employees , null ) ;
}
/// <summary>
/// The salary process, reporting real progress to <paramref name="progress"/> (null = nobody listens, which is
/// exactly the original behaviour). Only listeners are added; the calculation and the save are untouched.
/// </summary>
public List < SalaryProcessStatus > SalaryProcess ( SalaryProcess item , List < Employee > employees , IJobProgress progress )
2026-11-03 13:06:00 +06:00
{
try
{
2026-11-30 13:35:21 +06:00
// Progress only watches (see SalaryProcessProgress); with progress == null none of these lines do anything.
SalaryProcessProgress tracker = progress ! = null
? new SalaryProcessProgress ( progress , item . PayrollTypeID , employees ! = null ? employees . Count : 0 )
: null ;
if ( tracker ! = null ) tracker . Validating ( ) ;
2026-11-03 13:06:00 +06:00
bool IsFinantialAprovalRequired = new SystemConfigarationService ( ) . GetconfigBooleanValue ( EnumConfigurationType . Logic , "finantialaproval" , "finantialaprovalrequired" ) ;
string msg = String . Empty ;
var items = this . SalaryValidation ( item , employees ) ;
if ( items . Count ! = 0 ) return items ;
2026-11-30 13:35:21 +06:00
if ( tracker ! = null ) tracker . Preparing ( ) ;
2026-11-03 13:06:00 +06:00
SalaryCalculator calculator = new SalaryCalculator ( ) ;
2026-11-30 13:35:21 +06:00
if ( tracker ! = null ) tracker . Attach ( calculator ) ;
2026-11-03 13:06:00 +06:00
if ( IsFinantialAprovalRequired )
{
List < SalaryProcessStatus > salaryProcessStatusList = new List < SalaryProcessStatus > ( ) ;
salaryProcessStatusList = CheckForApprove ( employees , item . SalaryMonth , item . PayrollTypeID , out msg ) ;
}
if ( msg ! = string . Empty )
{
throw new Exception ( "Salary can not be processed. " + msg ) ;
}
calculator . Process ( employees , item . SalaryMonth , item . PayrollTypeID , item . EuroRate ) ;
if ( calculator . ErrorList . Count = = 0 )
2026-11-30 13:35:21 +06:00
{
IJobProgress saveProgress = tracker ! = null ? tracker . Saving ( ) : null ;
new SalaryMonthlyService ( ) . Save ( item , calculator . SalaryMonthlies , saveProgress ) ;
if ( tracker ! = null ) tracker . Completed ( ) ;
}
2026-11-03 13:06:00 +06:00
//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 DataSet GetProcessSummary ( DateTime salaryMonth , int payrollTypeID , int taxParamID )
{
DataSet oSummary = new DataSet ( ) ;
TransactionContext tc = null ;
try
{
tc = TransactionContext . Begin ( ) ;
oSummary = SalaryProcessDA . GetProcessSummary ( tc , salaryMonth , payrollTypeID , taxParamID ) ;
tc . End ( ) ;
}
catch ( Exception e )
{
#region Handle Exception
if ( tc ! = null )
tc . HandleError ( ) ;
ExceptionLog . Write ( e ) ;
throw new ServiceException ( e . Message , e ) ;
#endregion
}
return oSummary ;
}
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 , out string msg )
{
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 ( ) ;
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 . GetForPending ( 1 , payrollTypeId ) ;
List < ADParameterEmployee > oADEmployeeDeductions = adParameterEmployeeService . GetForPending ( 2 , payrollTypeId ) ;
List < EmpLifeCycle > _oLifeCycles = empLifeCycleService . GetForPending ( payrollTypeId ) ;
List < EmployeeBankAccount > _oEmployeeBankAccounts = employeeBankAccountService . getBankAccountForPending ( payrollTypeId ) ;
StringBuilder sb = new StringBuilder ( ) ;
foreach ( Employee emp in _employees )
{
if ( oADEmployeeAllownaces . 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 & & ( itemAD . ApprovalStatus = = EnumAuthStatus . NewNotYetApprove | | itemAD . ApprovalStatus = = EnumAuthStatus . Reverted ) )
{
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 )
{
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 & & ( itemAD . ApprovalStatus = = EnumAuthStatus . NewNotYetApprove | | itemAD . ApprovalStatus = = EnumAuthStatus . Reverted ) )
{
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 )
{
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 & & ( empLC . ApprovalStatus = = EnumAuthStatus . NewNotYetApprove | | empLC . ApprovalStatus = = EnumAuthStatus . Reverted ) )
{
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 )
{
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 & & ( empLC . ApprovalStatus = = EnumAuthStatus . NewNotYetApprove | | empLC . ApprovalStatus = = EnumAuthStatus . Reverted ) )
{
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 ;
}
//private List<SalaryProcessStatus> CheckForApprove(List<Employee> _employees, DateTime dtpSalaryMonth, int payrollTypeId, out string msg)
//{
// 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();
// 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 DeleteSalaryApprovalAttachment ( int id )
{
TransactionContext tc = null ;
try
{
tc = TransactionContext . Begin ( true ) ;
SalaryProcessDA . DeleteSalaryApprovalAttachment ( 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 SalaryProcess GetSalaryProcess ( int ID )
{
SalaryProcess salaryProcesss = new SalaryProcess ( ) ;
TransactionContext tc = null ;
try
{
tc = TransactionContext . Begin ( ) ;
DataReader dr = new DataReader ( SalaryProcessDA . GetSalaryProcess ( tc , ID ) ) ;
if ( dr . Read ( ) )
{
salaryProcesss = this . CreateObject < 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 SalaryProcess GetSalaryProcess ( DateTime dMonthDate , int payrollTypeID )
{
SalaryProcess salaryProcesss = new SalaryProcess ( ) ;
TransactionContext tc = null ;
try
{
tc = TransactionContext . Begin ( ) ;
DataReader dr = new DataReader ( SalaryProcessDA . GetSalaryProcess ( tc , dMonthDate , payrollTypeID ) ) ;
if ( dr . Read ( ) )
{
salaryProcesss = this . CreateObject < 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 void ApproveSalaryNew ( SalaryProcess oSalaryProcess , int currentEmpID )
{
TransactionContext tc = null ;
try
{
tc = TransactionContext . Begin ( true ) ;
if ( oSalaryProcess . WFStatus = = null )
{
oSalaryProcess . WFStatus = enumwfStatus . Not_yet_Initiated ;
SalaryProcessDA . SubmitSalaryFromAdmin ( tc , oSalaryProcess ) ;
}
if ( oSalaryProcess . WFStatus ! = null & & oSalaryProcess . WFStatus = = enumwfStatus . Not_yet_Initiated )
{
string subject = "Salary process for month - " + oSalaryProcess . SalaryMonth . ToString ( "MMMM yyyy" ) + ". Your Approval is required." ;
WFManager < IworkflowInterface > om = new WFManager < IworkflowInterface > ( oSalaryProcess ) ;
om . InitiateProcess ( tc , currentEmpID , oSalaryProcess . SetupID , oSalaryProcess . ID , "" , subject ) ;
}
else
{
SalaryProcessDA . ApproveSalaryFromESS ( tc , oSalaryProcess ) ;
}
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 SalaryProcessRevertRevert ( WFMovementTran revertTran , string remarks )
{
TransactionContext tc = null ;
try
{
Employee oFromEmployee = new EmployeeService ( ) . Get ( revertTran . FromEmployeeID ) ;
SalaryProcess oSalaryProcess = new SalaryProcessService ( ) . GetSalaryProcess ( revertTran . ObjectID ) ;
tc = TransactionContext . Begin ( true ) ;
string revertString = $"({oFromEmployee.EmployeeNo})-{oFromEmployee.Name}, has revert salary process for month-({oSalaryProcess.SalaryMonth.ToString(" MMMM yyyy ")})" ;
revertTran . Remarks = ! string . IsNullOrEmpty ( remarks ) ? remarks : "" ;
new WFManager < IworkflowInterface > ( ) . RevertNew ( tc , revertTran . ID , revertTran . FromEmployeeID , revertTran . Remarks , revertString ) ;
tc . End ( ) ;
}
catch ( Exception e )
{
#region Handle Exception
if ( tc ! = null )
tc . HandleError ( ) ;
ExceptionLog . Write ( e ) ;
throw new ServiceException ( e . Message , e ) ;
#endregion
}
}
public enumwfStatus ApproveSalaryNew ( WFMovementTran WFMovementTran )
{
TransactionContext tc = null ;
SalaryProcess oSalaryProcess = new SalaryProcess ( ) ;
enumwfStatus status ;
try
{
tc = TransactionContext . Begin ( true ) ;
oSalaryProcess = GetSalaryProcess ( WFMovementTran . ObjectID ) ;
string approveString = "Salary process for month - " + oSalaryProcess . SalaryMonth . ToString ( "MMMM yyyy" ) + " has approved" ;
WFMovementTran newTran = new WFManager < IworkflowInterface > ( ) . Approve ( tc , WFMovementTran . ID , WFMovementTran . FromEmployeeID , WFMovementTran . Remarks , approveString ) ;
if ( newTran . Status = = EnumwfStatus . End )
{
oSalaryProcess . WFStatus = enumwfStatus . Approve ;
status = enumwfStatus . Approve ;
SalaryProcessDA . ApproveSalaryNew ( tc , oSalaryProcess ) ;
}
else
{
oSalaryProcess . WFStatus = enumwfStatus . Not_yet_Initiated ;
status = enumwfStatus . Not_yet_Initiated ;
SalaryProcessDA . ApproveSalaryFromESS ( tc , oSalaryProcess ) ;
}
tc . End ( ) ;
}
catch ( Exception e )
{
#region Handle Exception
if ( tc ! = null )
tc . HandleError ( ) ;
ExceptionLog . Write ( e ) ;
throw new ServiceException ( e . Message , e ) ;
#endregion
}
return status ;
}
public void SalryBankTransfer ( SalaryProcess oSalaryProcess )
{
TransactionContext tc = null ;
try
{
tc = TransactionContext . Begin ( true ) ;
SalaryProcessDA . SalryBankTransfer ( tc , oSalaryProcess ) ;
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 SalaryApprovalAttachment ( List < SalaryApprovalAttachment > allSalaryApprovalAttachment )
{
TransactionContext tc = null ;
try
{
foreach ( SalaryApprovalAttachment attachment in allSalaryApprovalAttachment )
{
string [ ] items = attachment . FileData . Split ( new char [ ] { ',' , ' ' } , StringSplitOptions . None ) ;
byte [ ] newBytes = Convert . FromBase64String ( items [ 1 ] ) ;
attachment . FileAsByteArray = newBytes ;
SalaryProcessDA . SaveSalaryApprovalAttachment ( attachment ) ;
}
}
catch ( Exception e )
{
#region Handle Exception
if ( tc ! = null )
tc . HandleError ( ) ;
ExceptionLog . Write ( e ) ;
throw new ServiceException ( e . Message , e ) ;
#endregion
}
}
public List < SalaryApprovalAttachment > GetSalaryApprovalAttachment ( DateTime salaryMonth , int payrolltypeID , EnumFileType type , int referenceID = 0 )
{
List < SalaryApprovalAttachment > allAttachment = new List < SalaryApprovalAttachment > ( ) ;
TransactionContext tc = null ;
try
{
tc = TransactionContext . Begin ( true ) ;
DataReader oreader = new DataReader ( SalaryProcessDA . GetSalaryApprovalAttachment ( tc , salaryMonth , payrolltypeID , type , referenceID ) ) ;
while ( oreader . Read ( ) )
{
SalaryApprovalAttachment oAttachment = new SalaryApprovalAttachment ( ) ;
oAttachment . ApprovalAttachmentID = oreader . GetInt32 ( "ApprovalAttachmentID" ) . Value ;
oAttachment . PayrolltypeID = oreader . GetInt32 ( "PayrolltypeID" ) . Value ;
oAttachment . SalaryMonth = oreader . GetDateTime ( "SalaryMonth" ) . Value ;
oAttachment . Remarks = oreader . GetString ( "Remarks" , "" ) ;
oAttachment . FileAsByteArray = oreader . GetLob ( "FileData" ) ;
oAttachment . FileName = oreader . GetString ( "FileName" ) ;
oAttachment . FileType = ( EnumFileType ) oreader . GetInt32 ( "FileType" ) . GetValueOrDefault ( ) ;
oAttachment . ReferenceID = oreader . GetInt32 ( "ReferenceID" ) ;
allAttachment . Add ( oAttachment ) ;
}
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 allAttachment ;
}
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 > GetAllProcess ( int payrollTypeID )
{
List < SalaryProcess > salaryProcesss = new List < SalaryProcess > ( ) ;
TransactionContext tc = null ;
try
{
tc = TransactionContext . Begin ( ) ;
DataReader dr = new DataReader ( SalaryProcessDA . GetAllProcess ( tc , payrollTypeID ) ) ;
salaryProcesss = this . CreateObjects < SalaryProcess > ( dr ) ;
dr . Close ( ) ;
salaryProcesss = salaryProcesss . GroupBy ( obj = > obj . ID ) . Select ( group = > group . First ( ) ) . ToList ( ) ;
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 ( ) ;
}
public void UndoSalaryForInitiator ( int id )
{
TransactionContext tc = null ;
try
{
tc = TransactionContext . Begin ( true ) ;
int employeeCount = 0 ; // SalaryMonthlyDA.GetTotalEmp(tc, id);
SalaryProcessDA . UndoSalaryForInitiator ( 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
}
}
#endregion
public SalaryProcess GetSalaryProcessForRunningWorkflow ( DateTime dMonthDate , int payrollTypeID )
{
SalaryProcess salaryProcesss = new SalaryProcess ( ) ;
TransactionContext tc = null ;
try
{
tc = TransactionContext . Begin ( ) ;
DataReader dr = new DataReader ( SalaryProcessDA . GetSalaryProcessForRunningWorkflow ( tc , dMonthDate , payrollTypeID ) ) ;
if ( dr . Read ( ) )
{
salaryProcesss = this . CreateObject < 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 SalaryProcess GetSalaryProcessByUniqueID ( int uniqueID )
{
SalaryProcess salaryProcesss = new SalaryProcess ( ) ;
TransactionContext tc = null ;
try
{
tc = TransactionContext . Begin ( ) ;
DataReader dr = new DataReader ( SalaryProcessDA . GetSalaryProcessByUniqueID ( tc , uniqueID ) ) ;
if ( dr . Read ( ) )
{
salaryProcesss = this . CreateObject < 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 void UpdateMessValue ( DateTime salaryMonth , int payrollTypeID , string documentNoSAP , int jvtypeID )
{
TransactionContext tc = null ;
try
{
tc = TransactionContext . Begin ( true ) ;
SalaryProcessDA . UpdateMessValue ( tc , salaryMonth , payrollTypeID , documentNoSAP , jvtypeID ) ;
tc . End ( ) ;
}
catch ( Exception e )
{
#region Handle Exception
if ( tc ! = null )
tc . HandleError ( ) ;
ExceptionLog . Write ( e ) ;
throw new ServiceException ( e . Message , e ) ;
#endregion
}
}
public string GetDocumentNoSAPValue ( DateTime dSMonth , int payrollTypeID )
{
string messValue = null ;
TransactionContext tc = null ;
try
{
tc = TransactionContext . Begin ( ) ;
messValue = SalaryProcessDA . GetDocumentNoSAPValue ( tc , dSMonth , 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 messValue ;
}
public void deleteDocmentNo ( DateTime dSMonth , int payrollTypeID , int jvTypeId )
{
TransactionContext tc = null ;
try
{
tc = TransactionContext . Begin ( true ) ;
SalaryProcessDA . deleteDocmentNo ( tc , dSMonth , payrollTypeID , jvTypeId ) ;
tc . End ( ) ;
}
catch ( Exception e )
{
#region Handle Exception
if ( tc ! = null )
tc . HandleError ( ) ;
ExceptionLog . Write ( e ) ;
throw new ServiceException ( e . Message , e ) ;
#endregion
}
}
}
#endregion
}