329 lines
17 KiB
C#
329 lines
17 KiB
C#
using HRM.BO;
|
|
using Ease.Core.DataAccess;
|
|
using System;
|
|
using System.Data;
|
|
using System.Text.RegularExpressions;
|
|
using NPOI.SS.Formula.Functions;
|
|
|
|
|
|
namespace HRM.DA.Fund
|
|
{
|
|
internal class FinalSettlementDA
|
|
{
|
|
public FinalSettlementDA()
|
|
{
|
|
}
|
|
|
|
#region Insert function
|
|
|
|
internal static void Insert(TransactionContext tc, PFFinalSettlement oItem)
|
|
{
|
|
string sql = SQLParser.MakeSQL(@"INSERT INTO FM_FinalSettlement
|
|
(FinalSettlementID, MemberID, EmpCode, SettlementDate,
|
|
TotalPayment, PaymentMode,LastAudCPF,LastAudEPF,
|
|
LastAudCPFInterest,LastAudEPFInterest,LastAudCurrentEPFInterest,LastAudCurrentCPFInterest,
|
|
CurrYearEPF,CurrYearCPF,CurrYearEPFInterest,CurrYearCPFInterest,CurrYearInterestPercent,
|
|
CreatedDate,CreatedBy, LoanAmount, loanPrincipalRecovered,loanInterestRecovered, loanid)
|
|
VALUES(%n,%n,%s,%d,
|
|
%n,%s,%n,%n,
|
|
%n,%n,%n,%n,
|
|
%n,%n,%n,%n,%n,
|
|
%D,%n, %n, %n, %n, %n)",
|
|
oItem.ID, oItem.MemberID, oItem.EmpCode, oItem.SettlementDate,
|
|
oItem.TotalPayment, oItem.PaymentMode, oItem.LastAudCPF, oItem.LastAudEPF,
|
|
oItem.LastAudCPFInterest, oItem.LastAudEPFInterest, oItem.LastAudCurrentEPFInterest,
|
|
oItem.LastAudCurrentCPFInterest,
|
|
oItem.CurrYearEPF, oItem.CurrYearCPF, oItem.CurrYearEPFInterest, oItem.CurrYearCPFInterest,
|
|
oItem.CurrYearInterestPercent,
|
|
oItem.CreatedDate, oItem.CreatedBy, oItem.LoanAmount,
|
|
oItem.loanPrincipalRecovered, oItem.loanInterestRecovered, oItem.loanid);
|
|
tc.ExecuteNonQuery(sql);
|
|
}
|
|
internal static void InsertWithVoluntary(TransactionContext tc, PFFinalSettlement oItem)
|
|
{
|
|
string sql = SQLParser.MakeSQL(@"INSERT INTO FM_FinalSettlement
|
|
(FinalSettlementID, MemberID, EmpCode, SettlementDate,
|
|
TotalPayment, PaymentMode,LastAudCPF,LastAudEPF,
|
|
LastAudCPFInterest,LastAudEPFInterest,LastAudCurrentEPFInterest,LastAudCurrentCPFInterest,
|
|
CurrYearEPF,CurrYearCPF,CurrYearEPFInterest,CurrYearCPFInterest,CurrYearInterestPercent,
|
|
CreatedDate,CreatedBy, LoanAmount, loanPrincipalRecovered,loanInterestRecovered, loanid,
|
|
LastAudVoluntaryEPF, LastAudVoluntaryEPFInterest, LastAudCurrentVoluntaryEPFInterest,
|
|
CurrVoluntaryEPF, CurrVoluntaryEPFInterest)
|
|
VALUES(%n,%n,%s,%d,
|
|
%n,%s,%n,%n,
|
|
%n,%n,%n,%n,
|
|
%n,%n,%n,%n,%n,
|
|
%D,%n, %n, %n, %n, %n,
|
|
%n, %n, %n, %n, %n)",
|
|
oItem.ID, oItem.MemberID, oItem.EmpCode, oItem.SettlementDate,
|
|
oItem.TotalPayment, oItem.PaymentMode, oItem.LastAudCPF, oItem.LastAudEPF,
|
|
oItem.LastAudCPFInterest, oItem.LastAudEPFInterest, oItem.LastAudCurrentEPFInterest,
|
|
oItem.LastAudCurrentCPFInterest,
|
|
oItem.CurrYearEPF, oItem.CurrYearCPF, oItem.CurrYearEPFInterest, oItem.CurrYearCPFInterest,
|
|
oItem.CurrYearInterestPercent,
|
|
oItem.CreatedDate, oItem.CreatedBy, oItem.LoanAmount,
|
|
oItem.loanPrincipalRecovered, oItem.loanInterestRecovered, oItem.loanid,
|
|
oItem.LastAudVoluntaryEPF, oItem.LastAudVoluntaryEPFInterest, oItem.LastAudCurrentVoluntaryEPFInterest,
|
|
oItem.CurrYearVoluntaryEPF, oItem.CurrYearVoluntaryEPFInterest);
|
|
tc.ExecuteNonQuery(sql);
|
|
}
|
|
#endregion
|
|
|
|
#region Update function
|
|
|
|
internal static void Update(TransactionContext tc, PFFinalSettlement oItem)
|
|
{
|
|
//tc.ExecuteNonQuery("UPDATE FinalSettlement SET MemberID=%n, EmpCode=%s, SettlementDate=%d, TotalPayment=%n, PaymenrMode=%s, CreatedDate=%d, CreatedBy=%n, ModifiedDate=%d, ModifiedBy=%n" +
|
|
//" WHERE FinalSettlementID=%n", oItem.MemberID, oItem.EmpCode, oItem.SettlementDate, oItem.TotalPayment, oItem.PaymenrMode, oItem.CreatedDate, oItem.CreatedBy, oItem.ModifiedDate, oItem.ModifiedBy, oItem.FinalSettlementID);
|
|
}
|
|
internal static void UpdateWithVoluntary(TransactionContext tc, PFFinalSettlement oItem)
|
|
{
|
|
string sql = SQLParser.MakeSQL(@"UPDATE FM_FinalSettlement
|
|
SET
|
|
MemberID = %n,
|
|
EmpCode = %s,
|
|
SettlementDate = %d,
|
|
TotalPayment = %n,
|
|
PaymentMode = %s,
|
|
LastAudCPF = %n,
|
|
LastAudEPF = %n,
|
|
LastAudCPFInterest = %n,
|
|
LastAudEPFInterest = %n,
|
|
LastAudCurrentEPFInterest = %n,
|
|
LastAudCurrentCPFInterest = %n,
|
|
CurrYearEPF = %n,
|
|
CurrYearCPF = %n,
|
|
CurrYearEPFInterest = %n,
|
|
CurrYearCPFInterest = %n,
|
|
CurrYearInterestPercent = %n,
|
|
CreatedDate = %d,
|
|
CreatedBy = %n,
|
|
LoanAmount = %n,
|
|
loanPrincipalRecovered = %n,
|
|
loanInterestRecovered = %n,
|
|
loanid = %n,
|
|
LastAudVoluntaryEPF = %n,
|
|
LastAudVoluntaryEPFInterest = %n,
|
|
LastAudCurrentVoluntaryEPFInterest = %n,
|
|
CurrYearVoluntaryEPF = %n,
|
|
CurrYearVoluntaryEPFInterest = %n
|
|
WHERE FinalSettlementID = %n",
|
|
oItem.MemberID, oItem.EmpCode, oItem.SettlementDate,
|
|
oItem.TotalPayment, oItem.PaymentMode, oItem.LastAudCPF, oItem.LastAudEPF,
|
|
oItem.LastAudCPFInterest, oItem.LastAudEPFInterest, oItem.LastAudCurrentEPFInterest,
|
|
oItem.LastAudCurrentCPFInterest,
|
|
oItem.CurrYearEPF, oItem.CurrYearCPF, oItem.CurrYearEPFInterest, oItem.CurrYearCPFInterest,
|
|
oItem.CurrYearInterestPercent,
|
|
oItem.CreatedDate, oItem.CreatedBy, oItem.LoanAmount,
|
|
oItem.loanPrincipalRecovered, oItem.loanInterestRecovered, oItem.loanid,
|
|
oItem.LastAudVoluntaryEPF, oItem.LastAudVoluntaryEPFInterest, oItem.LastAudCurrentVoluntaryEPFInterest,
|
|
oItem.CurrYearVoluntaryEPF, oItem.CurrYearVoluntaryEPFInterest,
|
|
oItem.ID);
|
|
tc.ExecuteNonQuery(sql);
|
|
}
|
|
#endregion
|
|
|
|
#region int Generation function
|
|
|
|
internal static int GetNewID(TransactionContext tc)
|
|
{
|
|
return tc.GenerateID("FM_FinalSettlement", "FinalSettlementID");
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Get Function
|
|
|
|
internal static IDataReader GetbyFundType(TransactionContext tc, int fundtypeid)
|
|
{
|
|
return tc.ExecuteReader("SELECT * FROM FM_FinalSettlement where memberid in (" +
|
|
"select memberid from FM_Memberdetail where fundtypeid=%n)", fundtypeid);
|
|
}
|
|
|
|
internal static IDataReader Get(TransactionContext tc, int nFinalSettlementID)
|
|
{
|
|
return tc.ExecuteReader("SELECT * FROM FM_FinalSettlement WHERE FinalSettlementID=%n", nFinalSettlementID);
|
|
}
|
|
|
|
internal static IDataReader GetClearanceNotifications(TransactionContext tc, int regEmpId)
|
|
{
|
|
string sql = "";
|
|
|
|
object obj = tc.ExecuteScalar("SELECT * FROM SETTLEMENTCLEARANCE WHERE EMPCLERANCEID=%n",
|
|
regEmpId);
|
|
|
|
if (obj != null && obj != DBNull.Value)
|
|
{
|
|
|
|
sql = SQLParser.MakeSQL(@"
|
|
WITH cte AS (
|
|
SELECT
|
|
sc.EmpCleranceID,
|
|
sc.SentDate,
|
|
sc.EmployeeID,
|
|
err.Remarks,
|
|
fst.NetAmount,
|
|
sc.SETTLEMENTCLEARANCEID
|
|
FROM EmpResignationRequest AS err
|
|
INNER JOIN SettlementClearance AS sc ON err.employeeID = sc.EmpCleranceID
|
|
LEFT JOIN FSTRAN AS fst ON fst.EmployeeID = err.EMPLOYEEID
|
|
LEFT JOIN FSTranDetail AS fstd ON fstd.TranID = fst.FSTranID
|
|
WHERE sc.EmpCleranceID = %n
|
|
)
|
|
SELECT DISTINCT f.*,
|
|
e.EMPLOYEEID,
|
|
e.Name AS EmployeeName,
|
|
e.EMPLOYEENO,
|
|
|
|
sc.SentDate,
|
|
--sc.SettlementClearanceStatus,
|
|
--sc.NetAmount AS Amount,
|
|
--sc.FsTranType AS TranType,
|
|
CASE
|
|
WHEN sci.DeductFromEmp > sci.PaytoEmp THEN sci.DeductFromEmp
|
|
WHEN sci.PaytoEmp > sci.DeductFromEmp THEN sci.PaytoEmp
|
|
ELSE 0
|
|
END AS Amount,
|
|
CASE
|
|
WHEN sci.DeductFromEmp > sci.PaytoEmp THEN 1
|
|
WHEN sci.PaytoEmp > sci.DeductFromEmp THEN 2
|
|
ELSE 0
|
|
END AS TranType,
|
|
sci.ClearanceDate,
|
|
CASE
|
|
WHEN sci.ClearanceDone = 0 THEN 1
|
|
WHEN sci.ClearanceDone = 1 THEN 2
|
|
ELSE 0
|
|
END AS SettlementClearanceStatus,
|
|
sci.Remarks,
|
|
sci.PaytoEmp,
|
|
sci.DeductFromEmp
|
|
|
|
FROM (
|
|
SELECT DISTINCT
|
|
NAME,
|
|
FSHeadID,
|
|
EMPID,
|
|
EMPIDTwo,
|
|
DEPARTMENT,
|
|
DepartmentToApproveBefore,
|
|
COMPLETIONWORKINGDAYS,
|
|
ClearanceRequired,
|
|
NeedDepartmentApprove,
|
|
FinalStage
|
|
FROM fshead
|
|
) AS f
|
|
INNER JOIN EMPLOYEE AS e ON f.EMPID = e.EMPLOYEEID --OR f.EMPIDTwo = e.EMPLOYEEID
|
|
LEFT JOIN SETTLEMENTCLEARANCEITEM AS sci ON sci.FSHeadID = f.FSHeadID
|
|
LEFT JOIN cte AS sc ON f.EMPID = sc.EMPLOYEEID AND sc.SETTLEMENTCLEARANCEID = sci.SETTLEMENTCLEARANCEID
|
|
WHERE sci.SETTLEMENTCLEARANCEID = sc.SETTLEMENTCLEARANCEID", regEmpId);
|
|
}
|
|
else
|
|
{
|
|
sql = SQLParser.MakeSQL(@"
|
|
WITH cte AS (
|
|
SELECT
|
|
sc.EmpCleranceID,
|
|
sc.SentDate,
|
|
sc.EmployeeID,
|
|
err.Remarks,
|
|
fst.NetAmount,
|
|
sc.SETTLEMENTCLEARANCEID
|
|
FROM EmpResignationRequest AS err
|
|
INNER JOIN SettlementClearance AS sc ON err.employeeID = sc.EmpCleranceID
|
|
LEFT JOIN FSTRAN AS fst ON fst.EmployeeID = err.EMPLOYEEID
|
|
LEFT JOIN FSTranDetail AS fstd ON fstd.TranID = fst.FSTranID
|
|
WHERE sc.EmpCleranceID = %n
|
|
)
|
|
SELECT DISTINCT f.*,
|
|
e.EMPLOYEEID,
|
|
e.Name AS EmployeeName,
|
|
e.EMPLOYEENO,
|
|
|
|
sc.SentDate,
|
|
NULL ClearanceDate,
|
|
0 SettlementClearanceStatus,
|
|
NULL Amount,
|
|
NULL DeductFromEmp,
|
|
NULL PaytoEmp,
|
|
NULL TranType
|
|
FROM (
|
|
SELECT DISTINCT
|
|
NAME,
|
|
FSHeadID,
|
|
EMPID,
|
|
EMPIDTwo,
|
|
DEPARTMENT,
|
|
DepartmentToApproveBefore,
|
|
COMPLETIONWORKINGDAYS,
|
|
ClearanceRequired,
|
|
NeedDepartmentApprove,
|
|
FinalStage
|
|
FROM fshead
|
|
) AS f
|
|
INNER JOIN EMPLOYEE AS e ON f.EMPID = e.EMPLOYEEID --OR f.EMPIDTwo = e.EMPLOYEEID
|
|
LEFT JOIN cte AS sc ON f.EMPID = sc.EMPLOYEEID", regEmpId);
|
|
}
|
|
|
|
return tc.ExecuteReader(sql);
|
|
}
|
|
|
|
internal static IDataReader GetClearanceNotificationsByDepartment(TransactionContext tc, string departmentString)
|
|
{
|
|
string subQ = "";
|
|
if (departmentString.Contains("'null'"))
|
|
{
|
|
subQ = " or f.DEPARTMENT is null";
|
|
string cleaned = Regex.Replace(departmentString, "'null',", "", RegexOptions.IgnoreCase);
|
|
|
|
departmentString = cleaned;
|
|
}
|
|
string sql = SQLParser.MakeSQL(@";WITH cte AS(
|
|
SELECT sc.EmpCleranceID,sc.SentDate,sci.ClearanceDate,sc.EmployeeID,--sc.SettlementClearanceStatus,
|
|
CASE
|
|
WHEN sci.ClearanceDone = 0 THEN 1
|
|
WHEN sci.ClearanceDone = 1 THEN 2
|
|
ELSE 0
|
|
END AS SettlementClearanceStatus
|
|
FROM EmpResignationRequest AS err
|
|
INNER JOIN SettlementClearance AS sc ON err.employeeID=sc.EmpCleranceID
|
|
LEFT JOIN SETTLEMENTCLEARANCEITEM AS sci ON sci.SETTLEMENTCLEARANCEID = sc.SETTLEMENTCLEARANCEID)
|
|
SELECT distinct e.EMPLOYEEID, e.Name EmployeeName, e.EMPLOYEENO, e.MOBILENO, f.NAME,f.DEPARTMENT, f.CompletionWorkingDays,sc.SentDate,sc.ClearanceDate,sc.SettlementClearanceStatus
|
|
,(select employeeno from employee where employeeid = sc.EmpCleranceID) as ResignedEmployeeNo,
|
|
(select name from employee where employeeid = sc.EmpCleranceID) as ResignedEmployeeName
|
|
FROM FSHEAD AS f
|
|
INNER JOIN EMPLOYEE AS e ON f.EMPID=e.EMPLOYEEID OR f.EMPIDTwo=e.EMPLOYEEID
|
|
LEFT JOIN cte AS sc ON f.EMPID=sc.EMPLOYEEID
|
|
where f.DEPARTMENT in (%q) %q order by f.DEPARTMENT, ResignedEmployeeNo, e.EMPLOYEENO", departmentString, subQ);
|
|
|
|
return tc.ExecuteReader(sql);
|
|
}
|
|
#endregion
|
|
|
|
internal static DataTable GetCPFContributionData(TransactionContext tc)
|
|
{
|
|
return tc.ExecuteDataSet("Select * from CPFContribution").Tables[0];
|
|
}
|
|
internal static DataTable GetBySearch(TransactionContext tc, string sSearch)
|
|
{
|
|
string sql = SQLParser.MakeSQL("SELECT M.MEMBERID, M.EMPCODE, M.NAME, M.DOJ, M.STATUS, F.SETTLEMENTDATE FROM FM_FINALSETTLEMENT F " +
|
|
" JOIN FM_MEMBERDETAIL M ON M.MEMBERID = F.MEMBERID %q ", sSearch);
|
|
return tc.ExecuteDataSet(sql).Tables[0];
|
|
}
|
|
internal static void UpdateGLTranID(TransactionContext tc, int finalSettlementID, int glTranID)
|
|
{
|
|
string sUpdate = SQLParser.MakeSQL("UPDATE FM_FinalSettlement SET GLTranID = %n where FinalSettlementID = %n",
|
|
glTranID, finalSettlementID);
|
|
tc.ExecuteNonQuery(sUpdate);
|
|
}
|
|
internal static IDataReader Get(TransactionContext tc, string sSql)
|
|
{
|
|
return tc.ExecuteReader("SELECT * FROM FM_FinalSettlement %q order by EmpCode", sSql);
|
|
}
|
|
internal static void Delete(TransactionContext tc, int settlementID)
|
|
{
|
|
string sUpdate = SQLParser.MakeSQL("Delete FM_FinalSettlement where FinalSettlementID = %n", settlementID);
|
|
tc.ExecuteNonQuery(sUpdate);
|
|
}
|
|
}
|
|
} |