EchoTex_Payroll/HRM.DA/DA/Leave/LeaveYearDA.cs

202 lines
8.8 KiB
C#
Raw Permalink Normal View History

2024-10-14 10:01:49 +06:00
using HRM.BO;
using Ease.Core.DataAccess;
using System;
using System.Data;
namespace HRM.DA
{
class LeaveYearDA
{
#region Constructor
public LeaveYearDA()
{
}
#endregion
#region Insert function
public static void Insert(TransactionContext tc, LeaveYear oItem)
{
tc.ExecuteNonQuery(
"INSERT INTO LeaveYear(LeaveYearID, Name, StartDate,EndDate,IsCurrent, IsEnded,CreatedBy, CreatedDate, SequenceNo, Status, payrollTypeId, EncashmentStartDate, EncashmentEndDate, IsEncashmentActive)" +
" VALUES(%n, %s, %d, %d, %b, %b, %n, %d,%n, %n, %n, %d, %d,%b)", oItem.ID, oItem.Name, oItem.StartDate, oItem.EndDate,
oItem.IsCurrent, oItem.IsEnded, DataReader.GetNullValue(oItem.CreatedBy),
DataReader.GetNullValue(oItem.CreatedDate), oItem.Sequence, oItem.Status, oItem.PayrollTypeId, oItem.EncashmentStartDate, oItem.EncashmentEndDate, oItem.IsEncashmentActive);
}
#endregion
#region Update function
public static void Update(TransactionContext tc, LeaveYear oItem)
{
var x = DataReader.GetNullValue(oItem.IsEncashmentActive);
tc.ExecuteNonQuery(
"UPDATE LeaveYear SET Name=%s, StartDate=%d, EndDate=%d, IsCurrent=%n, IsEnded=%n, ModifiedBy=%n, ModifiedDate=%d, SequenceNo=%n, Status=%n, payrollTypeId = %n, EncashmentStartDate =%d, EncashmentEndDate=%d, IsEncashmentActive=%n" +
" WHERE LeaveYearID=%n", oItem.Name, oItem.StartDate, oItem.EndDate, oItem.IsCurrent, oItem.IsEnded,
DataReader.GetNullValue(oItem.ModifiedBy), DataReader.GetNullValue(oItem.ModifiedDate), oItem.Sequence,
oItem.Status, oItem.PayrollTypeId, oItem.EncashmentStartDate, oItem.EncashmentEndDate, oItem.IsEncashmentActive, oItem.ID);
}
//public static void UpdateYearEndValue(TransactionContext tc)
//{
// bool status = true;
// bool newStatus = false;
// //nProcessYear = LeaveEntry.getJulyJuneLeaveYear(nProcessYear);
// tc.ExecuteReader("Update LeaveYear set ISCURRENT=%b,ISENDED=%b WHERE ISCURRENT=%b AND ISENDED=%b", newStatus, status, status,newStatus);
//}
public static void UpdateCurrYearStatus(TransactionContext tc, LeaveYear leaveYear)
{
tc.ExecuteNonQuery("Update LeaveYear set ISCURRENT=%b,ISENDED=%b WHERE LeaveYearID=%n",
leaveYear.IsCurrent, false, leaveYear.ID);
}
public static void UpdateYearEndStatus(TransactionContext tc, LeaveYear leaveYear)
{
tc.ExecuteNonQuery("Update LeaveYear set ISENDED=%b WHERE LeaveYearID=%n", leaveYear.IsEnded,
leaveYear.ID);
}
internal static void UpdateLeaveStatusID(TransactionContext tc, LeaveYear lFirstPayPrev, LeaveYear lSecPayPrev, LeaveYear oFirstL, LeaveYear oSecondL, int employeeID, int payrollTypeID, int currentPayrollId)
{
string sViewName = "vw_LeaveIDMapping" + employeeID.ToString();
tc.ExecuteNonQuery(@"CREATE OR REPLACE VIEW %q as
select st.LeaveiD fromLeaveID, l2.Leaveid ToLeaveId
from EmpLeaveStatus st
inner join Leave l1 on st.LeaveID = l1.LeaveID
inner join Leave l2 on L1.DESCRIPTION = L2.DESCRIPTION
where l1.PayrollTypeID = %n And L2.PAYROLLTYPEID = %n
group by st.LeaveiD, l2.Leaveid", sViewName, currentPayrollId);
tc.ExecuteNonQuery(@"UPDATE EMPLEAVESTATUS SET leaveid = (SELECT ToLeaveId FROM %q WHERE fromLeaveID = leaveid),leaveyeariD = %n
WHERE LeaveiD IN(SELECT fromLeaveID FROM %q)
AND EmpID = %n And LeaveYearID = %n", sViewName, lSecPayPrev.ID, sViewName, employeeID, lFirstPayPrev.ID);
tc.ExecuteNonQuery("DROP VIEW %q", sViewName);
tc.ExecuteNonQuery(@"CREATE OR REPLACE VIEW %q as
select st.LeaveiD fromLeaveID, l2.Leaveid ToLeaveId
from LEAVEENTRY st
inner join Leave l1 on st.LeaveID = l1.LeaveID
inner join Leave l2 on L1.DESCRIPTION = L2.DESCRIPTION
where l1.PayrollTypeID = %n And L2.PAYROLLTYPEID = %n
group by st.LeaveiD,l2.Leaveid", sViewName, currentPayrollId, payrollTypeID);
tc.ExecuteNonQuery(@"UPDATE LEAVEENTRY SET leaveid = (SELECT ToLeaveId FROM %q WHERE fromLeaveID = leaveid),leaveyear = %n
WHERE LeaveiD IN(SELECT fromLeaveID FROM %q)
AND EmpID = %n And LeaveYear = %n", sViewName, oSecondL.ID, sViewName, employeeID, oFirstL.ID);
tc.ExecuteNonQuery("DROP VIEW %q", sViewName);
}
#endregion
#region ID Generation function
public static int GetNewID(TransactionContext tc)
{
return tc.GenerateID("LeaveYear", "LeaveYearID");
}
#endregion
#region Get Function
internal static IDataReader Get(TransactionContext tc, EnumStatus status)
{
if (EnumStatus.Active == status || EnumStatus.Inactive == status)
{
return tc.ExecuteReader("SELECT * FROM LeaveYear Where Status=%n Order By SequenceNo", status);
}
else
{
return tc.ExecuteReader("SELECT * FROM LeaveYear Order By SequenceNo");
}
}
internal static IDataReader Get(TransactionContext tc, EnumStatus status, int payrollType)
{
if (EnumStatus.Active == status || EnumStatus.Inactive == status)
{
return tc.ExecuteReader("SELECT * FROM LeaveYear Where Status=%n and payrollTypeId = %n Order By SequenceNo", status, payrollType);
}
else
{
return tc.ExecuteReader("SELECT * FROM LeaveYear where payrollTypeId = %n Order By SequenceNo", payrollType);
}
}
public static IDataReader Get(TransactionContext tc, int leaveYearID)
{
return tc.ExecuteReader("SELECT * FROM LeaveYear where LeaveYearID=%n", leaveYearID);
}
public static IDataReader Get(TransactionContext tc)
{
return tc.ExecuteReader("SELECT * FROM LeaveYear order by StartDate DESC");
}
public static IDataReader GetByPayrollType(TransactionContext tc, int PayrollTypeID)
{
return tc.ExecuteReader("SELECT * FROM LeaveYear WHERE PAYROLLTYPEID = %n order by StartDate DESC", PayrollTypeID);;
}
public static int CountCurrentYear(TransactionContext tc)
{
object obj = new object();
obj = tc.ExecuteScalar("SELECT count(*) FROM LeaveYear WHERE ISCURRENT=%n", 1);
return (Convert.ToInt32(obj));
}
public static IDataReader GetCurrentYear(TransactionContext tc, int payrolltypeid)
{
//nProcessYear = LeaveEntry.getJulyJuneLeaveYear(nProcessYear);
return tc.ExecuteReader("SELECT * FROM LeaveYear WHERE ISCURRENT=%b and payrolltypeid =%n", true, payrolltypeid);
}
public static IDataReader GetCurrentYear(TransactionContext tc, string year)
{
return tc.ExecuteReader("SELECT * FROM LeaveYear WHERE NAME=%s", year);
}
public static IDataReader GetIDByName(TransactionContext tc, string sLeaveYear)
{
return tc.ExecuteReader("SELECT * FROM LeaveYear WHERE NAME=%s", sLeaveYear);
}
#endregion
#region Delete function
public static void Delete(TransactionContext tc, int leaveYearID)
{
tc.ExecuteNonQuery("DELETE FROM LeaveYear WHERE LeaveYearID=%n", leaveYearID);
}
internal static IDataReader LastLeaveYear(TransactionContext tc, LeaveYear oCurrYear)
{
throw new NotImplementedException();
}
internal static IDataReader GetLastLeaveYear(TransactionContext tc, LeaveYear oCurrYear, int payrollTypeId)
{
string sql = SQLParser.MakeSQL(@"
SELECT TOP 1 ply.*
FROM LEAVEYEAR ply, LEAVEYEAR cly
WHERE
cly.ISCURRENT = %n AND
cly.LEAVEYEARID = %n AND
ply.PAYROLLTYPEID = %n AND
cly.PAYROLLTYPEID = %n AND
ply.ENDDATE < cly.STARTDATE
ORDER BY ply.STARTDATE DESC",
oCurrYear.IsCurrent, oCurrYear.ID, payrollTypeId, payrollTypeId);
return tc.ExecuteReader(sql);
}
#endregion
}
}