289 lines
15 KiB
C#
289 lines
15 KiB
C#
|
using System;
|
|||
|
using System.Data;
|
|||
|
using Ease.Core.DataAccess;
|
|||
|
using HRM.BO;
|
|||
|
|
|||
|
namespace HRM.DA
|
|||
|
{
|
|||
|
internal class ADParameterEmployeeDA
|
|||
|
{
|
|||
|
#region Constructor
|
|||
|
|
|||
|
private ADParameterEmployeeDA()
|
|||
|
{
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Insert function
|
|||
|
|
|||
|
internal static void Insert(TransactionContext tc, ADParameterEmployee item)
|
|||
|
{
|
|||
|
//, ModifiedBy, ModifiedDate
|
|||
|
//,%n,%d
|
|||
|
//, item.CreatedBy, DataReader.GetNullValue(item.CreatedDate)
|
|||
|
string sql = SQLParser.MakeSQL(
|
|||
|
"INSERT INTO ADParameterEmployee(ADPARAMETEREMPID, ADParameterID, AllowDeductID, Periodicity, EmployeeID, FROMDATE, TillDate, MonthlyAmount, TotalAmount, ARREARINFO, ADEMPTYPE, ValueType, DISBURSEDAMOUNT, ENTRYDATE,TracNo,ModifiedBy,ModifiedDate)" +
|
|||
|
" VALUES(%n, %n, %n, %n, %n, %d, %d, %n, %n, %n, %n, %n, %n, %d,%s,%n,%D)", item.ID,
|
|||
|
DataReader.GetNullValue(item.ADParameterID, 0), DataReader.GetNullValue(item.AllowDeductID, 0),
|
|||
|
item.Periodicity, item.EmployeeID, item.FormDate, DataReader.GetNullValue(item.TillDate),
|
|||
|
item.MonthlyAmount, item.TotalAmount, item.Arreartype, item.ADEmpType, item.ValueType,
|
|||
|
item.DisburseAmount, DateTime.Now, item.TracNo,
|
|||
|
item.ModifiedBy == null
|
|||
|
? DataReader.GetNullValue(item.CreatedBy, 0)
|
|||
|
: DataReader.GetNullValue(item.ModifiedBy),
|
|||
|
item.ModifiedDate == null ? item.CreatedDate : item.ModifiedDate);
|
|||
|
tc.ExecuteNonQuery(sql);
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Update function
|
|||
|
|
|||
|
internal static void Update(TransactionContext tc, ADParameterEmployee item)
|
|||
|
{
|
|||
|
tc.ExecuteNonQuery(
|
|||
|
"UPDATE ADParameterEmployee SET aDParameterID=%n, allowDeductID=%n, periodicity=%n, employeeID=%n, FROMDATE=%d, tillDate=%d, monthlyAmount=%n, totalAmount=%n, ARREARINFO=%n, ModifiedBy=%n, ModifiedDate=%D, ADEMPTYPE=%n, ValueType=%n, DISBURSEDAMOUNT=%n,TracNo=%s" +
|
|||
|
" WHERE ADPARAMETEREMPID=%n", item.ADParameterID, item.AllowDeductID, item.Periodicity, item.EmployeeID,
|
|||
|
item.FormDate, DataReader.GetNullValue(item.TillDate), item.MonthlyAmount, item.TotalAmount,
|
|||
|
item.Arreartype, item.ModifiedBy, item.ModifiedDate, item.ADEmpType, item.ValueType,
|
|||
|
item.DisburseAmount, item.TracNo, item.ID);
|
|||
|
}
|
|||
|
|
|||
|
internal static void UpdateAmountAndDate(TransactionContext tc, ADParameterEmployee item)
|
|||
|
{
|
|||
|
tc.ExecuteNonQuery(
|
|||
|
"UPDATE ADParameterEmployee SET FROMDATE=%d, tillDate=%d, monthlyAmount=%n, totalAmount=%n, ModifiedBy=%n, ModifiedDate=%D" +
|
|||
|
" WHERE ADPARAMETEREMPID=%n", item.FormDate, DataReader.GetNullValue(item.TillDate), item.MonthlyAmount, item.TotalAmount,
|
|||
|
item.ModifiedBy, item.ModifiedDate, item.ID);
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Get Function
|
|||
|
|
|||
|
internal static IDataReader GetByEmployee(TransactionContext tc, int nEmpID, EnumAllowOrDeduct adType,
|
|||
|
EnumADEmpType adEmpType, int payrollTypeId, DateTime nextPayProcessDate)
|
|||
|
{
|
|||
|
return tc.ExecuteReader("SELECT * FROM ADParameterEmployee Where EmployeeID = %n AND ADEMPTYPE = %n " +
|
|||
|
" AND ADPARAMETERID IN (SELECT ADPARAMETERID FROM ADParameterBasic WHERE PayrollTypeID=%n AND AllowORDeduct = %n AND IsCurrentlyActive <> 0)"
|
|||
|
+ " AND ( (TillDate >= %d OR TillDate IS Null) AND "
|
|||
|
+ " (FromDate <= %d) OR ArrearInfo =%n )", nEmpID, adEmpType, payrollTypeId, adType,
|
|||
|
PayrollGlobalFunctions.PayrollFirstDateOfMonth(nextPayProcessDate), nextPayProcessDate,
|
|||
|
EnumArrearType.ToCalculate);
|
|||
|
}
|
|||
|
|
|||
|
internal static IDataReader GetByEmployee(TransactionContext tc, int nEmpID, int nAllowDeductID,
|
|||
|
int payrollTypeId)
|
|||
|
{
|
|||
|
return tc.ExecuteReader(
|
|||
|
"Select AD.* from ADPARAMETEREMPLOYEE AD, ADParameterBasic AB WHERE AB.PayrollTypeID=%n AND AB.ADParameterID=AD.ADParameterID AND AD.EMPLOYEEID=%n AND AD.ALLOWDEDUCTID=%n",
|
|||
|
payrollTypeId, nEmpID, nAllowDeductID);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
internal static IDataReader Get(TransactionContext tc, DateTime fromDate, DateTime toDate, int payrollTypeID)
|
|||
|
{
|
|||
|
return tc.ExecuteReader("SELECT ADE.* FROM ADParameterBasic ADB, ADParameterEmployee ADE "
|
|||
|
+ " WHERE ADB.PayrollTypeID=%n AND ADB.ADParameterID=ADE.ADParameterID AND ADE.ADEMPType=%n AND ADB.IsCurrentlyActive <> 0 "
|
|||
|
+ " AND ( (ADE.TillDate >= %d OR ADE.TillDate IS Null) AND "
|
|||
|
+ " (ADE.FromDate <= %d) OR ADE.ArrearInfo =%n )", payrollTypeID,
|
|||
|
EnumADEmpType.AppliedToIndividual, fromDate, toDate, EnumArrearType.ToCalculate);
|
|||
|
}
|
|||
|
|
|||
|
internal static IDataReader Get(TransactionContext tc, int AllowDeductID, DateTime fromDate, DateTime toDate,
|
|||
|
int payrollTypeID)
|
|||
|
{
|
|||
|
string sql =
|
|||
|
SQLParser.MakeSQL(
|
|||
|
@"Select * from ADPARAMETEREMPLOYEE where FROMDATE between %d and %d
|
|||
|
AND ADPARAMETERID IN(Select ADPARAMETERID from ADPARAMETERBASIC where PAYROLLTYPEID=%n and ALLOWDEDUCTID=%n)",
|
|||
|
fromDate, PayrollGlobalFunctions.PayrollLastDateOfMonth(toDate), payrollTypeID, AllowDeductID);
|
|||
|
return tc.ExecuteReader(@"Select * from ADPARAMETEREMPLOYEE where FROMDATE between %d and %d
|
|||
|
AND ADPARAMETERID IN(Select ADPARAMETERID from ADPARAMETERBASIC where PAYROLLTYPEID=%n and ALLOWDEDUCTID=%n)",
|
|||
|
fromDate, PayrollGlobalFunctions.PayrollLastDateOfMonth(toDate), payrollTypeID, AllowDeductID);
|
|||
|
}
|
|||
|
|
|||
|
internal static IDataReader GetForApproval(TransactionContext tc, int AllowDeductID, DateTime fromDate,
|
|||
|
DateTime toDate, int payrollTypeID)
|
|||
|
{
|
|||
|
string sql = SQLParser.MakeSQL(
|
|||
|
@"Select * from ADPARAMETEREMPLOYEE where FROMDATE between %d and %d AND ADPARAMETERID IN(Select ADPARAMETERID from ADPARAMETERBASIC where ALLOWDEDUCTID in
|
|||
|
(Select ALLOWDEDUCTID from ADPARAMETERBASIC where PAYROLLTYPEID=%n and ALLOWDEDUCTID in(select ALLOWDEDUCTID from ALLOWANCEDEDUCTION where ALLOWORDEDUCT=%n))) ORDER BY Modifieddate",
|
|||
|
fromDate, PayrollGlobalFunctions.PayrollLastDateOfMonth(toDate), payrollTypeID, AllowDeductID);
|
|||
|
|
|||
|
return tc.ExecuteReader(sql);
|
|||
|
}
|
|||
|
|
|||
|
internal static IDataReader Get(TransactionContext tc, int nEmpID, int AllowDeductID, DateTime fromDate,
|
|||
|
DateTime toDate)
|
|||
|
{
|
|||
|
return tc.ExecuteReader(
|
|||
|
@"Select * from ADPARAMETEREMPLOYEE where EMPLOYEEID=%n AND FROMDATE between %d and %d AND ALLOWDEDUCTID=%n",
|
|||
|
nEmpID, fromDate, PayrollGlobalFunctions.PayrollLastDateOfMonth(toDate), AllowDeductID);
|
|||
|
}
|
|||
|
|
|||
|
internal static IDataReader GetbyParameter(TransactionContext tc, int nADPAramID, EnumADEmpType type)
|
|||
|
{
|
|||
|
return tc.ExecuteReader("SELECT * FROM ADParameterEmployee WHERE ADPARAMETERID=%n AND ADEMPTYPE=%n",
|
|||
|
nADPAramID, type);
|
|||
|
}
|
|||
|
|
|||
|
//internal static IDataReader GetByEmployee(TransactionContext tc, int nEmpID, EnumAllowOrDeduct adType, string sTypes)
|
|||
|
//{
|
|||
|
// return tc.ExecuteReader("SELECT * FROM ADParameterEmployee Where EmployeeID = %n AND ADEMPTYPE IN (%q) " +
|
|||
|
// " AND ADPARAMETERID IN (SELECT ADPARAMETERID FROM ADParameterBasic WHERE AllowORDeduct = %n AND AND ADB.IsCurrentlyActive <> 0)"
|
|||
|
// + " AND ( (TillDate >= %d OR TillDate IS Null) AND (FromDate <= %d) OR ArrearInfo =%b )",
|
|||
|
// nEmpID, sTypes, adType);
|
|||
|
//}
|
|||
|
|
|||
|
internal static IDataReader Get(TransactionContext tc, EnumADEmpType status)
|
|||
|
{
|
|||
|
return tc.ExecuteReader("SELECT * FROM ADParameterEmployee where ADEMPTYPE=%n ",
|
|||
|
status);
|
|||
|
}
|
|||
|
internal static IDataReader Get(TransactionContext tc, EnumADEmpType status, EnumAllowOrDeduct allowOrDeduct)
|
|||
|
{
|
|||
|
return tc.ExecuteReader("SELECT * FROM ADParameterEmployee where ADEMPTYPE=%n and AllowDeductID IN (" +
|
|||
|
" Select AllowDeductID from ALLOWANCEDEDUCTION where AllowOrDeduct=%n",
|
|||
|
status, allowOrDeduct);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
internal static IDataReader Get(TransactionContext tc, int nID)
|
|||
|
{
|
|||
|
return tc.ExecuteReader("SELECT * FROM ADParameterEmployee WHERE ADPARAMETEREMPID=%n", nID);
|
|||
|
}
|
|||
|
|
|||
|
internal static IDataReader GetbyParameter(TransactionContext tc, int nID, DateTime nextPayProcessDate)
|
|||
|
{
|
|||
|
return tc.ExecuteReader(
|
|||
|
"SELECT * FROM ADParameterEmployee WHERE ADPARAMETERID=%n AND ((TillDate >= %d OR TillDate IS NULL) AND (FromDate <= %d) OR ArrearInfo=%n)",
|
|||
|
nID,
|
|||
|
PayrollGlobalFunctions.PayrollFirstDateOfMonth(nextPayProcessDate), nextPayProcessDate,
|
|||
|
EnumArrearType.ToCalculate);
|
|||
|
}
|
|||
|
|
|||
|
internal static IDataReader GetbyParameterID(TransactionContext tc, int nID)
|
|||
|
{
|
|||
|
return tc.ExecuteReader("SELECT ade.*,e.Name, e.EmployeeNo FROM ADParameterEmployee ade, employee e" +
|
|||
|
" WHERE ade.ADPARAMETERID=%n and ade.employeeid=e.employeeid ", nID);
|
|||
|
}
|
|||
|
|
|||
|
internal static IDataReader GetNextSalaryMonthItems(TransactionContext tc, int nID, int payrolltypeid)
|
|||
|
{
|
|||
|
return tc.ExecuteReader(
|
|||
|
"SELECT ade.*,e.Name, e.EmployeeNo FROM ADParameterEmployee ade, employee e, payrolltype p " +
|
|||
|
"WHERE ade.ADPARAMETERID=%n and p.payrolltypeid= %n and ade.employeeid=e.employeeid " +
|
|||
|
"AND ((ade.TillDate >= DATEADD(month, DATEDIFF(month, 0, p.nextPayProcessDate), 0) OR ade.TillDate IS NULL) " +
|
|||
|
"AND (ade.FromDate <= p.nextPayProcessDate) OR ade.ArrearInfo=%n) AND e.Status =%n",
|
|||
|
nID, payrolltypeid, EnumArrearType.ToCalculate, EnumEmployeeStatus.Live);
|
|||
|
}
|
|||
|
|
|||
|
internal static IDataReader GetByAllow(TransactionContext tc, int nID)
|
|||
|
{
|
|||
|
return tc.ExecuteReader("SELECT * FROM ADParameterEmployee WHERE AllowDeductID=%n", nID);
|
|||
|
}
|
|||
|
|
|||
|
internal static IDataReader GetByAllowForApproval(TransactionContext tc, int nID, int payrollTypeID)
|
|||
|
{
|
|||
|
return tc.ExecuteReader(
|
|||
|
@"Select * from ADPARAMETEREMPLOYEE where ADPARAMETERID IN(Select ADPARAMETERID from ADPARAMETERBASIC where ALLOWDEDUCTID in
|
|||
|
(Select ALLOWDEDUCTID from ADPARAMETERBASIC where PAYROLLTYPEID=%n and ALLOWDEDUCTID in(select ALLOWDEDUCTID from ALLOWANCEDEDUCTION where ALLOWORDEDUCT=%n))) ORDER BY Modifieddate",
|
|||
|
payrollTypeID, nID);
|
|||
|
}
|
|||
|
|
|||
|
internal static IDataReader Get(TransactionContext tc, int nEmpID, int nAllowDeductID, int nADParamID)
|
|||
|
{
|
|||
|
return tc.ExecuteReader(
|
|||
|
"SELECT * FROM ADParameterEmployee WHERE EMPLOYEEID=%n AND ADPARAMETERID = %n AND ALLOWDEDUCTID =%n ",
|
|||
|
nEmpID, nADParamID, nAllowDeductID);
|
|||
|
}
|
|||
|
|
|||
|
internal static IDataReader Get(TransactionContext tc, int nEmpID, int nAllowDeductID, int nADParamID,
|
|||
|
EnumArrearType nArrearType)
|
|||
|
{
|
|||
|
return tc.ExecuteReader(
|
|||
|
"SELECT * FROM ADParameterEmployee WHERE EMPLOYEEID=%n AND ADPARAMETERID = %n AND ALLOWDEDUCTID =%n AND ARREARINFO=%n",
|
|||
|
nEmpID, nADParamID, nAllowDeductID, (int)nArrearType);
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Delete function
|
|||
|
|
|||
|
internal static void Delete(TransactionContext tc, int nID)
|
|||
|
{
|
|||
|
tc.ExecuteNonQuery("DELETE FROM ADParameterEmployee WHERE ADPARAMETEREMPID=%n", nID);
|
|||
|
}
|
|||
|
|
|||
|
internal static void Delete(TransactionContext tc, ADParameterEmployee adParamEmp)
|
|||
|
{
|
|||
|
//ADPARAMETEREMPID
|
|||
|
//tc.ExecuteNonQuery("DELETE FROM ADParameterEmployee WHERE ADPARAMETEREMPID=%n", adParamEmp.ID);
|
|||
|
tc.ExecuteNonQuery(
|
|||
|
"DELETE FROM ADParameterEmployee WHERE EMPLOYEEID=%n AND AllowDeductID=%n AND TillDate= %d AND Periodicity=%n",
|
|||
|
adParamEmp.EmployeeID, adParamEmp.AllowDeductID, adParamEmp.TillDate, adParamEmp.Periodicity);
|
|||
|
}
|
|||
|
|
|||
|
internal static void DeletebyAdParamid(TransactionContext tc, int nID)
|
|||
|
{
|
|||
|
tc.ExecuteNonQuery("DELETE FROM ADParameterEmployee WHERE ADParameterID=%n", nID);
|
|||
|
}
|
|||
|
|
|||
|
internal static void DeleteByAllo(TransactionContext tc, int nAllowDeductID)
|
|||
|
{
|
|||
|
tc.ExecuteNonQuery("DELETE FROM ADParameterEmployee WHERE AllowDeductID=%n", nAllowDeductID);
|
|||
|
}
|
|||
|
|
|||
|
internal static void DeleteByEmpID(TransactionContext tc, int nEmpID, int nADParameterID)
|
|||
|
{
|
|||
|
tc.ExecuteNonQuery("DELETE FROM ADParameterEmployee WHERE EmployeeID=%n AND ADParameterID=%n", nEmpID,
|
|||
|
nADParameterID);
|
|||
|
}
|
|||
|
|
|||
|
internal static void DeleteByAllowDeductMonth(TransactionContext tc, int nEmpID, int nAllowDeductID,
|
|||
|
DateTime dAllowDeductMonht)
|
|||
|
{
|
|||
|
tc.ExecuteNonQuery(
|
|||
|
"Delete from ADPARAMETEREMPLOYEE where FromDate between %d and %d and EmployeeID=%n and AllowDeductID=%n",
|
|||
|
PayrollGlobalFunctions.PayrollFirstDateOfMonth(dAllowDeductMonht),
|
|||
|
PayrollGlobalFunctions.PayrollLastDateOfMonth(dAllowDeductMonht), nEmpID, nAllowDeductID);
|
|||
|
}
|
|||
|
internal static void DeleteByAllowDeductMonth(TransactionContext tc, string nEmpIDs, int nAllowDeductID,
|
|||
|
DateTime dAllowDeductMonht)
|
|||
|
{
|
|||
|
string sql =SQLParser.MakeSQL(
|
|||
|
"Delete from ADPARAMETEREMPLOYEE where FromDate between %d and %d and EmployeeID in (%q) and AllowDeductID=%n",
|
|||
|
PayrollGlobalFunctions.PayrollFirstDateOfMonth(dAllowDeductMonht),
|
|||
|
PayrollGlobalFunctions.PayrollLastDateOfMonth(dAllowDeductMonht), nEmpIDs, nAllowDeductID);
|
|||
|
tc.ExecuteNonQuery(sql);
|
|||
|
|
|||
|
}
|
|||
|
internal static void DeleteByMonth(TransactionContext tc, int nAllowDeductID,
|
|||
|
DateTime dAllowDeductMonht)
|
|||
|
{
|
|||
|
tc.ExecuteNonQuery(
|
|||
|
"Delete from ADPARAMETEREMPLOYEE where FromDate between %d and %d and AllowDeductID=%n",
|
|||
|
PayrollGlobalFunctions.PayrollFirstDateOfMonth(dAllowDeductMonht),
|
|||
|
PayrollGlobalFunctions.PayrollLastDateOfMonth(dAllowDeductMonht), nAllowDeductID);
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Other function
|
|||
|
|
|||
|
public static bool IsExist(TransactionContext tc, int empId, int allowDeduct, int adParamid, DateTime? tillDate,
|
|||
|
EnumPeriodicity status)
|
|||
|
{
|
|||
|
bool Exist = false;
|
|||
|
Object obj =
|
|||
|
tc.ExecuteScalar(
|
|||
|
"Select Count(*) FROM ADParameterEmployee WHERE EMPLOYEEID=%n AND AllowDeductID=%n AND ADPARAMETERID=%n AND TillDate= %d AND Periodicity=%n",
|
|||
|
empId, allowDeduct, adParamid, tillDate, EnumPeriodicity.Monthly);
|
|||
|
Exist = Convert.ToInt32(obj) > 0 ? true : false;
|
|||
|
return Exist;
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|