EchoTex_Payroll/HRM.DA/DA/Leave/LeaveParameterDA.cs
2024-10-14 10:01:49 +06:00

298 lines
13 KiB
C#

using HRM.BO;
using Ease.Core.DataAccess;
using System;
using System.Data;
namespace HRM.DA
{
#region LeaveParameter DA
public class LeaveParameterDA
{
#region Constructor
public LeaveParameterDA()
{
}
#endregion
#region Insert function
public static void Insert(TransactionContext tc, LeaveParameter oItem)
{
tc.ExecuteNonQuery(
"INSERT INTO LEAVEPARAMETER(LEAVEPARAMID, LEAVEID, ACCUMULATEDLEAVE, ISACTIVE, FortifiedMonth, AllowAdvance, IgnoreHolidays, MonthlyBalance, IsForfited, ApplicableFor,CreatedBy,CreationDate,PayrollTypeID)" +
" VALUES(%n, %n, %n, %n, %n, %n, %n, %n, %n, %n,%n,%d,%n)", oItem.ID, oItem.LeaveId,
oItem.MaxAccumulatedDays, oItem.IsActive, oItem.ForfitedMonth, oItem.AllowAdvance,
oItem.IgnoreHoliday, (int)oItem.CalculationType, oItem.IsForfited, (int)oItem.ApplicableFor,
oItem.CreatedBy, oItem.CreatedDate, oItem.PayrollTypeID);
}
public static void InsertChildren(TransactionContext tc, LeaveParameterDetail oItem)
{
tc.ExecuteNonQuery(
"INSERT INTO LEAVEPARAMDETAIL(LEAVEPARAMID, MAXDAYS,MaxGrndDays, MAXCF, MAXENCASH, ID, YEAR)" +
" VALUES(%n, %n, %n,%n, %n, %n, %n)", oItem.LeaveParamId, oItem.MaxDays, oItem.MaxGrndDays, oItem.MaxCF,
oItem.MaxEncash, oItem.ID, oItem.Year);
}
public static void InsertParamItem(TransactionContext tc, LeaveParameter.paramItem oItem)
{
tc.ExecuteNonQuery("INSERT INTO LeaveParameterItem(LEAVEPARAMID, ItemID, ItemType)" +
" VALUES( %n, %n, %n)", oItem.paramid, oItem.itemID, oItem.ParamOnType);
}
public static void DeleteParamItem(TransactionContext tc, int paramid)
{
tc.ExecuteNonQuery("Delete from LeaveParameterItem where LEAVEPARAMID=%n", paramid);
}
#endregion
#region Update function
public static void Update(TransactionContext tc, LeaveParameter oItem)
{
tc.ExecuteNonQuery("UPDATE LEAVEPARAMETER SET LEAVEID=%n, ACCUMULATEDLEAVE=%n, ISACTIVE=%n," +
" FortifiedMonth=%n, AllowAdvance=%n, IgnoreHolidays=%n, MonthlyBalance=%n, IsForfited=%n," +
" ApplicableFor=%n,ModifiedBy=%n,ModifiedDate=%d WHERE LEAVEPARAMID=%n",
oItem.LeaveId, oItem.MaxAccumulatedDays, oItem.IsActive, oItem.ForfitedMonth,
oItem.AllowAdvance, oItem.IgnoreHoliday, (int)oItem.CalculationType, oItem.IsForfited,
(int)oItem.ApplicableFor, oItem.ModifiedBy, oItem.ModifiedDate,
oItem.ID);
}
#endregion
#region ID Generation function
public static int GetNewID(TransactionContext tc)
{
return tc.GenerateID("LeaveParameter", "LeaveParamId");
}
public static int GetNewDetailID(TransactionContext tc)
{
return tc.GenerateID("LEAVEPARAMDETAIL", "ID");
}
#endregion
#region Get Function
public static IDataReader Get(TransactionContext tc, int payrollTypeID)
{
return tc.ExecuteReader("SELECT * FROM LeaveParameter WHERE Payrolltypeid=%n", payrollTypeID);
}
public static IDataReader GetByParamId(TransactionContext tc, int paramId)
{
return tc.ExecuteReader("SELECT * FROM LeaveParameter where LEAVEPARAMID=%n", paramId);
}
//public static IDataReader GetLeaveDetail(TransactionContext tc, int leaveID)
//{
// return tc.ExecuteReader("SELECT * FROM LeaveParamDetail where LEAVEID=%n", leaveID);
//}
public static IDataReader GetByLeaveID(TransactionContext tc, int leaveID)
{
return tc.ExecuteReader("SELECT * FROM LeaveParameter where LEAVEID=%n", leaveID);
}
public static IDataReader Get(TransactionContext tc, EnumStatus status, int payrollTypeID, int? leaveID)
{
string sqlClause = string.Empty;
sqlClause = SQLParser.TagSQL(sqlClause) + SQLParser.MakeSQL("PayrollTypeID = %n", payrollTypeID);
if (EnumStatus.Active == status || EnumStatus.Inactive == status)
{
sqlClause = SQLParser.TagSQL(sqlClause) + SQLParser.MakeSQL("ISACTIVE = %n", status);
}
if (leaveID != null)
{
sqlClause = SQLParser.TagSQL(sqlClause) + SQLParser.MakeSQL("LeaveID=%n", leaveID);
}
return tc.ExecuteReader("SELECT * FROM LeaveParameter %q", sqlClause);
}
public static IDataReader GetLeaveParam(TransactionContext tc, int nLeaveParamId)
{
return tc.ExecuteReader("SELECT * FROM LeaveParameter WHERE LeaveParamId=%n", nLeaveParamId);
}
public static IDataReader GetLeaveParam(TransactionContext tc)
{
return tc.ExecuteReader("SELECT * FROM LeaveParameter");
}
public static IDataReader Get(TransactionContext tc, int nLeaveId, int nGradeId)
{
return tc.ExecuteReader(
"SELECT * FROM LeaveParameter WHERE LeaveParamId in(select LeaveParamId from LeaveGrade where GradeId=%n) and LeaveId=%n",
nGradeId, nLeaveId);
}
public static IDataReader Get(TransactionContext tc, int sbuId, int locationId, int functionId, bool Isactive)
{
return tc.ExecuteReader(
"select * from LeaveParameter P where P.IsActive=%b and P.LeaveParamId in (select LeaveParamId from LeaveFunction where functionId =%n " +
" and LeaveParamId in(select LeaveParamId from LeaveLocation where LocationId =%n " +
" and LeaveParamId in (select LeaveParamId from LeaveSBU where SBUId =%n)))", Isactive, functionId,
locationId, sbuId);
}
public static IDataReader Get(TransactionContext tc, int sbuId, int locationId, int functionId)
{
return tc.ExecuteReader(
"select * from LeaveParameter P where P.LeaveParamId in (select LeaveParamId from LeaveFunction where functionId =%n " +
" and LeaveParamId in(select LeaveParamId from LeaveLocation where LocationId =%n " +
" and LeaveParamId in (select LeaveParamId from LeaveSBU where SBUId =%n)))", functionId, locationId,
sbuId);
}
public static IDataReader Get(TransactionContext tc, int sbuId, int locationId, int functionId, int nLeaveID)
{
return tc.ExecuteReader(
"select * from LeaveParameter P where P.LeaveParamId in (select LeaveParamId from LeaveFunction where FunctionId =%n AND LeaveID=%n " +
" and LeaveParamId in(select LeaveParamId from LeaveLocation where LocationId =%n " +
" and LeaveParamId in (select LeaveParamId from LeaveSBU where SBUId =%n)))", functionId, nLeaveID,
locationId, sbuId);
}
public static IDataReader GetParameter(TransactionContext tc, int sbuId, int locationId, int functionId,
int nLeaveID)
{
return tc.ExecuteReader("select P.* from LeaveParameter P, LeaveFunction LF, LeaveLocation LL, LeaveSBU LB "
+ " WHERE P.LeaveParamId = LF.LeaveParamId AND P.LeaveParamId = LL.LeaveParamId AND P.LeaveParamId = LB.LeaveParamId "
+ " AND P.LeaveID=%n AND LF.FunctionId =%n AND LL.LocationId=%n AND LB.SBUId=%n "
, nLeaveID, functionId, locationId, sbuId);
}
public static IDataReader GetByLeaveId(TransactionContext tc, int leaveId)
{
return tc.ExecuteReader("SELECT * FROM LeaveParameter where leaveId=%n", leaveId);
}
public static IDataReader GetLeaveSBUs(TransactionContext tc, int nParamId)
{
return tc.ExecuteReader("SELECT * FROM LeaveSBU WHERE LeaveParamId=%n", nParamId);
}
public static IDataReader GetLeaveLocations(TransactionContext tc, int nParamId)
{
return tc.ExecuteReader("SELECT * FROM LeaveLocation WHERE LeaveParamId=%n", nParamId);
}
public static IDataReader GetLeaveFunctions(TransactionContext tc, int nParamId)
{
return tc.ExecuteReader("SELECT * FROM LeaveFunction WHERE LeaveParamId=%n", nParamId);
}
internal static IDataReader GetAllByPayrollTypeID(TransactionContext tc, int payrollTypeID)
{
return tc.ExecuteReader("SELECT * FROM LeaveParameter WHERE Payrolltypeid=%n", payrollTypeID);
}
public static IDataReader GetDetails(TransactionContext tc, int nLeaveParamId)
{
return tc.ExecuteReader("SELECT * FROM LeaveParamDetail WHERE LEAVEPARAMID=%n", nLeaveParamId);
}
public static IDataReader GetParamItems(TransactionContext tc, int nLeaveParamId)
{
return tc.ExecuteReader("SELECT * FROM LeaveParameterItem WHERE LEAVEPARAMID=%n", nLeaveParamId);
}
public static IDataReader GetAllParamItems(TransactionContext tc)
{
return tc.ExecuteReader("SELECT * FROM LeaveParameterItem ");
}
internal static IDataReader GetUsedParamItem(TransactionContext tc, int leaveid, int payrolltypeid)
{
return tc.ExecuteReader(@"select *from LeaveParameterItem where LEAVEPARAMID in (
select LEAVEPARAMID from LeaveParameter where leaveid = %n and payrolltypeid=%n) ", leaveid, payrolltypeid);
}
public static IDataReader Get(TransactionContext tc, bool isActive, int payrollTypeID)
{
return tc.ExecuteReader("SELECT * FROM LeaveParameter where IsActive=%b AND Payrolltypeid=%n", isActive, payrollTypeID);
}
internal static IDataReader GetApplicableParams(TransactionContext tc, int itemid,
EnumLeaveparamOn paramItemType, int? leaveID)
{
if (leaveID == null)
return tc.ExecuteReader(
@"select distinct l.* from LeaveParameterItem i,LeaveParameter l where i.LEAVEPARAMID = l.LEAVEPARAMID
and i.ItemID=%n and i.ItemType=%n ", itemid, paramItemType);
else
return tc.ExecuteReader(
@"select distinct l.* from LeaveParameterItem i,LeaveParameter l where i.LEAVEPARAMID = l.LEAVEPARAMID
and i.ItemID=%n and ItemType=%n and l.LeaveID=%n", itemid, paramItemType, leaveID);
}
public static IDataReader GetDetails(TransactionContext tc)
{
return tc.ExecuteReader("SELECT * FROM LeaveParamDetail");
}
//public static IDataReader GetDetail(TransactionContext tc, int paramID)
//{
// return tc.ExecuteReader("SELECT * FROM LeaveParamDetail WHERE LeaveParamId=%n", paramID);
//}
#endregion
#region Delete function
public static void Delete(TransactionContext tc, int nLeaveParamId)
{
tc.ExecuteNonQuery("DELETE FROM LeaveParameter WHERE LeaveParamId=%n", nLeaveParamId);
}
public static void DeleteLeaveSBU(TransactionContext tc, int nParamId)
{
tc.ExecuteNonQuery("DELETE FROM LeaveSBU WHERE LeaveParamId=%n", nParamId);
}
public static void DeleteLeaveLocation(TransactionContext tc, int nParamId)
{
tc.ExecuteNonQuery("DELETE FROM LeaveLocation WHERE LeaveParamId=%n", nParamId);
}
public static void DeleteLeaveFunction(TransactionContext tc, int nParamId)
{
tc.ExecuteNonQuery("DELETE FROM LeaveFunction WHERE LeaveParamId=%n", nParamId);
}
public static void DeleteDetails(TransactionContext tc, int nLeaveParamId)
{
tc.ExecuteNonQuery("DELETE FROM LeaveParamDetail WHERE LeaveParamId=%n", nLeaveParamId);
}
public static void DeleteParamItems(TransactionContext tc, int nLeaveParamId)
{
tc.ExecuteNonQuery("DELETE FROM LeaveParameterItem WHERE LeaveParamId=%n", nLeaveParamId);
}
internal static IDataReader Get(TransactionContext tc, Employee oEmp, int leaveID)
{
string query = SQLParser.MakeSQL(@"
SELECT * FROM LEAVEPARAMETER lp
WHERE lp.LEAVEPARAMID IN (SELECT DISTINCT SETUPID FROM LEAVESETUPDETAIL
WHERE TRANID IN (%n) AND
TRANTYPE IN (SELECT DISTINCT TRANTYPE FROM LEAVESETUPDETAIL)) AND
lp.leaveid = %n",
oEmp.GradeID, leaveID);
return tc.ExecuteReader(query);
}
#endregion
}
#endregion
}