EchoTex_Payroll/HRM.DA/DA/Employee/EmployeeGradeSalaryDA.cs

344 lines
18 KiB
C#
Raw Permalink Normal View History

2024-10-14 10:01:49 +06:00
using Ease.Core.DataAccess;
using System;
using System.Data;
using HRM.BO;
namespace HRM.DA
{
internal class EmployeeGradeSalaryDA
{
#region Constructor
private EmployeeGradeSalaryDA()
{
}
#endregion
#region Insert function
internal static void Insert(TransactionContext tc, EmployeeGradeSalary item)
{
string sSQL = SQLParser.MakeSQL(
"INSERT INTO GRADESALARYASSIGNMENT(EmpGradeSalaryID, GradeSalaryID, userid, status,sequenceno,"
+ " employeeID, tillDate, effectDate, basicSalary, gradeID, grossSalary,"
+ " payScaleID, arrearInfo, gradeSalaryTypeID, CreatedBy, CreatedDate, INCREMENTNO)" +
" VALUES(%n, %n, %n,%n,%n, "
+ " %n, %d, %d, %n, %n, %n,"
+ " %n, %n, %n, %n, %D, %n)",
item.ID, item.EmployeeSerial, item.CreatedBy, 1, 0,
item.EmployeeID, DataReader.GetNullValue(item.TillDate), DataReader.GetNullValue(item.EffectDate),
item.BasicSalary, DataReader.GetNullValue(item.GradeID, 0),
item.GrossSalary, DataReader.GetNullValue(item.PayScaleDetailID, 0), item.ArrearType,
DataReader.GetNullValue(item.GradeSalaryTypeID, 0), item.CreatedBy, item.CreatedDate, item.Increment);
tc.ExecuteNonQuery(sSQL);
}
#endregion
#region Update function
internal static void Update(TransactionContext tc, EmployeeGradeSalary item)
{
tc.ExecuteNonQuery(
"UPDATE GRADESALARYASSIGNMENT SET tillDate=%d, effectDate=%d, basicSalary=%n, gradeID=%n, grossSalary=%n, payScaleID=%n, arrearInfo=%n, gradeSalaryTypeID=%n, ModifiedBy=%n, ModifiedDate=%d, INCREMENTNO=%n" +
" WHERE EmployeeID=%n AND GradeSalaryID=%n", item.TillDate,
item.EffectDate, item.BasicSalary, item.GradeID, item.GrossSalary,
DataReader.GetNullValue(item.PayScaleDetailID, 0), item.ArrearType, item.GradeSalaryTypeID,
item.ModifiedBy, item.ModifiedDate, item.Increment, item.EmployeeID, item.EmployeeSerial);
}
#endregion
#region Get Function
internal static IDataReader Get(TransactionContext tc, int employeeID)
{
return tc.ExecuteReader("SELECT * FROM GradeSalaryAssignment WHERE EmployeeID=%n Order by GradeSalaryID desc",
employeeID);
}
internal static DataTable GetSalaryHistory(TransactionContext tc, int employeeID)
{
return tc.ExecuteDataTable(@"SELECT eg.*, g.Description GradeName FROM GradeSalaryAssignment eg, Grades g WHERE
EmployeeID=%n and eg.GradeId =g.GradeID Order by GradeSalaryID desc",
employeeID);
}
internal static IDataReader GetbyID(TransactionContext tc, int empgradeSalaryID)
{
return tc.ExecuteReader("SELECT * FROM GradeSalaryAssignment WHERE EmpGradeSalaryID=%n ", empgradeSalaryID);
}
internal static IDataReader GetPeviousSalary(TransactionContext tc, int employeeid, int gradesalaryid)
{
string sql = SQLParser.MakeSQL(
@"SELECT GRADESALARYASSIGNMENT.* FROM GRADESALARYASSIGNMENT WHERE EMPLOYEEID =%n
AND GRADESALARYID = (SELECT MAX( G.GRADESALARYID ) FROM GRADESALARYASSIGNMENT G
WHERE G.EMPLOYEEID =%n AND G.GRADESALARYID<%n AND G.ARREARinfo IN (0,1) )", employeeid,
employeeid, gradesalaryid);
return tc.ExecuteReader(sql);
}
internal static IDataReader Get(TransactionContext tc)
{
return tc.ExecuteReader("SELECT * FROM GradeSalaryAssignment Order by GradeSalaryID");
}
internal static IDataReader GetBasicOnDateBAT(TransactionContext tc, int employeeid, DateTime effectdate)
{
return tc.ExecuteReader("SELECT * FROM GRADESALARYASSIGNMENT WHERE employeeid=%n AND GradeSalaryID ="
+ " (SELECT MAX(GradeSalaryID) FROM GradeSalaryAssignment "
+ "WHERE EmployeeID=%n AND effectDate<=%d) ",
employeeid, employeeid, effectdate);
}
internal static IDataReader GetBasicOnDate(TransactionContext tc, DateTime effectdate)
{
return tc.ExecuteReader(@"SELECT g.* FROM GRADESALARYASSIGNMENT g
where g.empGradeSalaryid = (select Max(mx.empGradeSalaryid) from GRADESALARYASSIGNMENT mx
where g.EMPLOYEEID = mx.EMPLOYEEID and mx.EFFECTDATE < %d )
order by g.EMPLOYEEID ",
effectdate);
}
internal static IDataReader Get(TransactionContext tc, int employeeid, DateTime effectdate, EnumArrearType type)
{
return tc.ExecuteReader("SELECT * FROM GRADESALARYASSIGNMENT WHERE employeeid=%n AND GradeSalaryID ="
+ " (SELECT MAX(GradeSalaryID) FROM GradeSalaryAssignment "
+ "WHERE EmployeeID=%n AND effectDate<=%d AND ArrearInfo=%n ) AND ArrearInfo=%n ",
employeeid, employeeid, effectdate, type, type);
}
internal static IDataReader Get(TransactionContext tc, DateTime effectdate, EnumArrearType type)
{
return tc.ExecuteReader(@"SELECT GRADESALARYASSIGNMENT.* FROM GRADESALARYASSIGNMENT ,
(SELECT employeeid,MAX(GradeSalaryID)GradeSalaryID FROM GradeSalaryAssignment
WHERE effectDate<=%d AND ArrearInfo=%n GROUP BY employeeid) tab2
WHERE GRADESALARYASSIGNMENT.GradeSalaryID =tab2.GradeSalaryID
AND GRADESALARYASSIGNMENT.employeeid =tab2.employeeid
AND ArrearInfo=%n",
effectdate, type, type);
}
internal static IDataReader Get(TransactionContext tc, int employeeid, DateTime effectdate, int payrollTypeID)
{
string Ssql = SQLParser.MakeSQL(@"Select * from GRADESALARYASSIGNMENT where
EFFECTDATE= (Select MAX(EffectDate) from GRADESALARYASSIGNMENT where EMPLOYEEID=%n and EFFECTDATE<%d)
AND EMPLOYEEID=(Select EMPLOYEEID from Employee where EMPLOYEEID=%n and PAYROLLTYPEID=%n) ",
employeeid, effectdate, employeeid, payrollTypeID);
return tc.ExecuteReader(@"Select * from GRADESALARYASSIGNMENT where
EFFECTDATE= (Select MAX(EffectDate) from GRADESALARYASSIGNMENT where EMPLOYEEID=%n and EFFECTDATE<%d)
AND EMPLOYEEID=(Select EMPLOYEEID from Employee where EMPLOYEEID=%n and PAYROLLTYPEID=%n) ",
employeeid, effectdate, employeeid, payrollTypeID);
}
internal static IDataReader GetMax(TransactionContext tc, int employeeID, EnumArrearType type)
{
return tc.ExecuteReader("SELECT * FROM GradeSalaryAssignment WHERE EmployeeID=%n AND GradeSalaryID="
+ "(SELECT MAX(GradeSalaryID) FROM GradeSalaryAssignment "
+ "WHERE EmployeeID=%n AND ArrearInfo=%n AND TillDate IS NULL)", employeeID,
employeeID, type);
}
internal static IDataReader GetbyTillDate(TransactionContext tc, int employeeID, DateTime tillDatefrom,
DateTime tillDateTo)
{
return tc.ExecuteReader(
"SELECT * FROM GradeSalaryAssignment WHERE EmployeeID=%n AND ((TillDate BETWEEN %d AND %d) OR TillDate IS NULL)",
employeeID, tillDatefrom, tillDateTo);
}
internal static IDataReader GetbyEffectDate(TransactionContext tc, int employeeID, DateTime effectDatefrom,
DateTime effectDateTo)
{
return tc.ExecuteReader(
"SELECT * FROM GradeSalaryAssignment WHERE EmployeeID=%n AND (EffectDate BETWEEN %d AND %d)",
employeeID, effectDatefrom, effectDateTo);
}
internal static IDataReader GetArrearItems(TransactionContext tc, int payrollTypeID)
{
return tc.ExecuteReader(@"SELECT g.* FROM GradeSalaryAssignment g, Employee e WHERE g.arrearInfo=%n
and g.employeeid=e.employeeid and e.payrolltypeid=%n order by effectdate ",
EnumArrearType.ToCalculate, payrollTypeID);
}
internal static IDataReader GetArrearPaidItems(TransactionContext tc, int employeeId, DateTime tilldateFrom,
int payrollTypeID)
{
return tc.ExecuteReader(
"SELECT g.* FROM GradeSalaryAssignment g, Employee e WHERE g.EmployeeId=%n AND g.arrearInfo=%n "
+ " AND TillDate >=%d and g.employeeid=e.employeeid and e.payrolltypeid=%n order by effectdate",
employeeId, EnumArrearType.Paid, tilldateFrom, payrollTypeID);
}
//
internal static IDataReader GetCurrMonthSalaryItems(TransactionContext tc, DateTime nextPayProcessDate,
int payrollTypeID)
{
DateTime fromDate = PayrollGlobalFunctions.PayrollFirstDateOfMonth(nextPayProcessDate);
//DateTime fromDate = new DateTime(2011, 3, 31); // for redisha back process
string sSQL = SQLParser.MakeSQL("select DISTINCT * from ( "
+ " select G.* from GradeSalaryAssignment G, Employee E where G.EmployeeID=E.EmployeeID and E.PayrollTypeID=%n and tilldate >= %d and effectdate <%d "
+ " union "
+ " select G.* from GradeSalaryAssignment G, Employee E where G.EmployeeID=E.EmployeeID and E.PayrollTypeID=%n and effectdate >= %d"
+ " union "
+ " select G.* from GradeSalaryAssignment G, Employee E where G.EmployeeID=E.EmployeeID and E.PayrollTypeID=%n and tilldate is null )"
+ " A order by A.employeeid, A.effectDate ",
payrollTypeID, fromDate, fromDate, payrollTypeID, fromDate, payrollTypeID);
return tc.ExecuteReader(sSQL);
}
internal static DataSet GetEmpPromotion(TransactionContext tc, DateTime dEffectDate, DateTime dEffectDate2,
int payrollTypeID)
{
DataSet oEmpBasicGrades = new DataSet();
try
{
string sSQL = SQLParser.MakeSQL(@"SELECT distinct GSA.EMPGRADESALARYID,e.employeeid,e.EMPLOYEENO,e.NAME,GSA.EFFECTDATE,G.DESCRIPTION PresentGrade,GSA.BASICSALARY PresentBasic,u.LogInID CommitedBy,GSA.CreatedDate, uf.LOGINID AuthorizeBy,f.APPROVEDDATE,GSC.NAME ChangeType
FROM GRADESALARYASSIGNMENT GSA
INNER JOIN EMPLOYEE e ON e.EMPLOYEEID = GSA.EMPLOYEEID
Left JOIN GRADESALARYCHANGETYPE GSC on GSC.GRADESALARYCHANGETYPEID=GSA.gradesalarytypeid
LEFT JOIN GRADES G ON GSA.GRADEID=G.GRADEID
LEFT JOIN USERS u ON u.USERID=GSA.CreatedBy
LEFT JOIN emplifecycle elg ON elg.GradeSalaryAssesmentID = GSA.EMPGradeSalaryID
LEFT JOIN ApproveFinantialData f ON e.EMPLOYEEID=f.EMPLOYEEID AND elg.EMPLIFECYCLEID=f.OBJECTID AND f.FINANATIALDATATYPE=3 AND Year(f.SALARYMONTH)=Year(elg.EFFECTDATE) AND MONTH(f.SALARYMONTH)=MONTH(elg.EFFECTDATE)
LEFT JOIN Users uf ON uf.USERID = f.Approvedby
INNER JOIN(SELECT DISTINCT ec.EMPLOYEEID, effectdate FROM emplifecycle ec,EMPLOYEESTATUS es where ec.STATUSDETAILID=es.STATUSID AND es.isPromotion=1 AND ec.EFFECTDATE between %d and %d
) A ON A.Employeeid = GSA.EMPLOYEEID
WHERE e.payrollTypeId=%n
ORDER BY e.EMPLOYEENO, GSA.EFFECTDATE desc", dEffectDate,
dEffectDate2, payrollTypeID);
oEmpBasicGrades = tc.ExecuteDataSet(sSQL);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
return oEmpBasicGrades;
}
internal static DataSet GetEmpBasicGrade(TransactionContext tc, DateTime dEffectDate, DateTime dEffectDate2,
int payrollTypeID)
{
DataSet oEmpBasicGrades = new DataSet();
try
{
string sSQL = SQLParser.MakeSQL(@"Select GSA.EMPGRADESALARYID,emp.employeeid,Emp.EMPLOYEENO,Emp.NAME,GSA.EFFECTDATE,G.DESCRIPTION PresentGrade,GSA.BASICSALARY PresentBasic,US.LogInID CommitedBy,GSA.CreatedDate,GSC.NAME ChangeType
from GRADESALARYASSIGNMENT GSA,GRADES G,EMPLOYEE Emp,USERS US,GRADESALARYCHANGETYPE GSC
where GSA.EFFECTDATE between %d and %d
AND GSA.EMPLOYEEID=Emp.EMPLOYEEID
AND GSC.GRADESALARYCHANGETYPEID=GSA.gradesalarytypeid
AND US.USERID=GSA.CreatedBy
AND Emp.GRADEID=G.GRADEID AND Emp.PayrollTypeId=%n
order by Emp.EMPLOYEENO", dEffectDate,
dEffectDate2, payrollTypeID);
oEmpBasicGrades = tc.ExecuteDataSet(
"Select GSA.EMPGRADESALARYID,emp.employeeid,Emp.EMPLOYEENO,Emp.NAME,GSA.EFFECTDATE,G.DESCRIPTION PresentGrade,GSA.BASICSALARY PresentBasic,US.LogInID CommitedBy,GSA.CreatedDate,GSC.NAME ChangeType "
+ " from GRADESALARYASSIGNMENT GSA,GRADES G,EMPLOYEE Emp,USERS US,GRADESALARYCHANGETYPE GSC"
+ " where GSA.EFFECTDATE between %d and %d"
+ " AND GSA.EMPLOYEEID=Emp.EMPLOYEEID"
+ " AND GSC.GRADESALARYCHANGETYPEID=GSA.gradesalarytypeid"
+ " AND US.USERID=GSA.CreatedBy"
+ " AND Emp.GRADEID=G.GRADEID AND Emp.PayrollTypeId=%n"
+ " order by Emp.EMPLOYEENO", dEffectDate,
dEffectDate2, payrollTypeID);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
return oEmpBasicGrades;
}
internal static DataSet GetEmpPrvBasicGrade(TransactionContext tc, DateTime dEffectDate, int payrollTypeID)
{
DataSet oEmpBasicGrades = new DataSet();
try
{
oEmpBasicGrades = tc.ExecuteDataSet(
"Select Emp.EMPLOYEENO,Emp.NAME,GSA.EFFECTDATE,G.DESCRIPTION PreviousGrade,GSA.BASICSALARY PreviousBasic,US.USERNAME CommitedBy,GSA.CreatedDate,GSC.NAME SChangeType "
+ " from GRADESALARYASSIGNMENT GSA,GRADES G,EMPLOYEE Emp,USERS US,GRADESALARYCHANGETYPE GSC"
+ " where GSA.EFFECTDATE < %d"
+ " AND GSA.EMPLOYEEID=Emp.EMPLOYEEID"
+ " AND GSC.GRADESALARYCHANGETYPEID=GSA.gradesalarytypeid"
+ " AND US.USERID=GSA.CreatedBy"
+ " AND GSA.GRADEID=G.GRADEID And Emp.PayrollTypeID=%n"
+ " order by Emp.EMPLOYEENO", PayrollGlobalFunctions.PayrollFirstDateOfMonth(dEffectDate)
, payrollTypeID);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
return oEmpBasicGrades;
}
internal static DataSet GetmultipleTilldatedemp(TransactionContext tc, int payrollTypeID)
{
DataSet oEmpBasicGrades = new DataSet();
try
{
oEmpBasicGrades = tc.ExecuteDataSet(
@"select employeeid from GradeSalaryAssignment where tilldate is null and employeeid in(select employeeid from employee where
payrolltypeid=%n and status=%n ) group by employeeid having count(*)>1",
payrollTypeID, (int)EnumEmployeeStatus.Live);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
return oEmpBasicGrades;
}
#endregion
#region Delete function
internal static void Delete(TransactionContext tc, int pkid)
{
tc.ExecuteNonQuery("DELETE FROM GRADESALARYASSIGNMENT WHERE EmpGradeSalaryID=%n" ,pkid);
}
internal static void Delete(TransactionContext tc, int employeeId, int employeeSerial)
{
tc.ExecuteNonQuery("DELETE FROM GRADESALARYASSIGNMENT WHERE EMPLOYEEID=%n AND GRADESALARYID= %n",
employeeId, employeeSerial);
}
internal static void DeleteOnDate(TransactionContext tc, int employeeId, DateTime effectdate,
EnumArrearType arrtype)
{
tc.ExecuteNonQuery(
"DELETE FROM GRADESALARYASSIGNMENT WHERE EMPLOYEEID=%n AND effectDate>= %d and arrearInfo=%n",
employeeId, effectdate, arrtype);
}
internal static void DeleteFrom(TransactionContext tc, int emloyeeID, DateTime fromDate)
{
tc.ExecuteNonQuery("DELETE FROM GRADESALARYASSIGNMENT WHERE EmployeeID=%n and EffectDate>=%d", emloyeeID,
fromDate);
}
internal static void DeleteArrearItem(TransactionContext tc, int emloyeeID)
{
tc.ExecuteNonQuery("DELETE FROM GRADESALARYASSIGNMENT WHERE EmployeeID=%n and arrearInfo=%n", emloyeeID,
EnumArrearType.ToCalculate);
}
internal static void DeleteAll(TransactionContext tc)
{
tc.ExecuteNonQuery("DELETE FROM GRADESALARYASSIGNMENT");
}
#endregion
}
}