CEL_Payroll/Payroll.Service/Leave/DA/LeaveProcessDA.cs

219 lines
11 KiB
C#
Raw Normal View History

2024-09-17 14:30:13 +06:00
using System;
using Payroll.BO;
using System.Data;
using System.Linq;
using Ease.CoreV35.Model;
using System.Data.SqlClient;
using Ease.CoreV35.DataAccess;
using System.Collections.Generic;
using Ease.CoreV35.DataAccess.SQL;
namespace Payroll.Service
{
#region LeaveProcess Data Access
public class LeaveProcessDA
{
#region Constructor
public LeaveProcessDA() { }
#endregion
#region Leave Process
#region Insert function
public static void Insert(TransactionContext tc, LeaveProcess oItem)
{
//oItem.ProcessYear = LeaveEntry.getJulyJuneLeaveYear(oItem.ProcessYear);
tc.ExecuteNonQuery("INSERT INTO LeaveProcess(ProcessId, LEAVEYEARID, ProcessDate, IsYearEnd, ProcessYearDesc, PayrollTypeID)" +
" VALUES(%n, %n, %d,%b, %s, %n)", oItem.ID.Integer, oItem.LeaveYearID,
oItem.ProcessDate, oItem.IsYearEnd, oItem.ProcessYearDescription, User.CurrentUser.LogInPayrollTypeID.Integer);
}
#endregion
#region Update function
public static void Update(TransactionContext tc, LeaveProcess oItem)
{
tc.ExecuteNonQuery("UPDATE LeaveProcess SET LEAVEYEARID=%n, ProcessDate=%d, IsYearEnd=%b, ProcessYearDesc=%s " +
" WHERE ProcessId=%n", oItem.LeaveYearID, oItem.ProcessDate, oItem.IsYearEnd, oItem.ProcessYearDescription, oItem.ID.Integer);
}
public static void DoYearEnd(TransactionContext tc, LeaveProcess oProcess)
{
tc.ExecuteNonQuery("UPDATE LeaveProcess SET IsYearEnd=%b WHERE ProcessId=%n", oProcess.IsYearEnd, oProcess.ID.Integer);
}
#endregion
#region ID Generation function
public static int GetNewID(TransactionContext tc)
{
return tc.GenerateID("LeaveProcess", "ProcessId");
}
#endregion
#region Get Function
public static IDataReader Get(TransactionContext tc)
{
return tc.ExecuteReader("SELECT * FROM LeaveProcess Where PayrollTypeID=%n", User.CurrentUser.LogInPayrollTypeID.Integer);
}
public static IDataReader Get(TransactionContext tc, int nProcessId)
{
return tc.ExecuteReader("SELECT * FROM LeaveProcess WHERE ProcessId=%n", nProcessId);
}
public static IDataReader GetByYearID(TransactionContext tc, int nProcessYear)
{
//nProcessYear = 2010;// LeaveEntry.getJulyJuneLeaveYear(nProcessYear);
return tc.ExecuteReader("SELECT * FROM LeaveProcess WHERE LEAVEYEARID=%n and PayrollTypeID=%n", nProcessYear, User.CurrentUser.LogInPayrollTypeID.Integer);
}
public static IDataReader GetByYearANDPayrollID(TransactionContext tc, int nProcessYear, int nPayrollTypeID)
{
//nProcessYear = 2010;// LeaveEntry.getJulyJuneLeaveYear(nProcessYear);
return tc.ExecuteReader("SELECT * FROM LeaveProcess WHERE LEAVEYEARID=%n and PayrollTypeID=%n", nProcessYear, nPayrollTypeID);
}
public static IDataReader GetLastProcess(TransactionContext tc)
{
bool status = true;
int nProcessYear = 2010;//LeaveEntry.getJulyJuneLeaveYear(nProcessYear);
return tc.ExecuteReader("SELECT * FROM LeaveProcess WHERE LEAVEYEARID=(SELECT max(ProcessYear) FROM LeaveProcess WHERE IsYearEnd=%b and PayrollTypeID=%n)", status, User.CurrentUser.LogInPayrollTypeID.Integer);
}
public static IDataReader GetYearEndValue(TransactionContext tc)
{
bool status = true;
return tc.ExecuteReader("SELECT * FROM LeaveYear WHERE ISCURRENT=%b ", status);
}
#endregion
#region Delete function
public static void Delete(TransactionContext tc, int nProcessId)
{
tc.ExecuteNonQuery("DELETE FROM EmpLeaveStatus where ProcessId =%n", nProcessId);
tc.ExecuteNonQuery("DELETE FROM LeaveProcess WHERE ProcessId=%n", nProcessId);
}
public static void DeleteByLeaveYear(TransactionContext tc, int leaveyearid)
{
tc.ExecuteNonQuery("DELETE FROM EmpLeaveStatus where LeaveYearID=%n ", leaveyearid);
tc.ExecuteNonQuery("DELETE FROM LeaveProcess WHERE LeaveYearID=%n", leaveyearid);
}
public static void DeleteByProcessYear(TransactionContext tc, int nProcessYear)
{
tc.ExecuteNonQuery("DELETE FROM EmpLeaveStatus where ProcessId in(SELECT ProcessId from LeaveProcess where LeaveYearID=%n)", nProcessYear);
tc.ExecuteNonQuery("DELETE FROM LeaveProcess WHERE LeaveYearID=%n", nProcessYear);
}
public static void DeleteByProcessYearANDPayrollType(TransactionContext tc, int nProcessYear, int nPayrollTypeID)
{
tc.ExecuteNonQuery("DELETE FROM EmpLeaveStatus where ProcessId in(SELECT ProcessId from LeaveProcess where LeaveYearID=%n AND PayrollTypeID=%n)", nProcessYear, nPayrollTypeID);
tc.ExecuteNonQuery("DELETE FROM LeaveProcess WHERE LeaveYearID=%n AND PayrollTypeID=%n", nProcessYear, nPayrollTypeID);
}
#endregion
#region Other supporting Functions
public static bool IsProcessed(TransactionContext tc, int nProcessYear)
{
object obj = new object();
obj = tc.ExecuteScalar("SELECT count(*) FROM LeaveProcess WHERE LEAVEYEARID=%n and PayrollType=%n", nProcessYear, User.CurrentUser.LogInPayrollTypeID.Integer);
if (obj == DBNull.Value) return false;
return (Convert.ToInt32(obj) != 0);
}
#endregion
#endregion
#region Leave Process Detail
#region Insert function
public static void Insert(TransactionContext tc, EmpLeaveStatus oItem)
{
//oItem.ForBenifitedYear= LeaveEntry.getJulyJuneLeaveYear(oItem.ForBenifitedYear);
tc.ExecuteNonQuery("INSERT INTO EmpLeaveStatus(TranId, ProcessId, EmpId, LEAVEYEARID, LeaveId, FORBENIFITEDYEAR, CFDays, EncashDays, EncashAmount, NormalLeaveDays, YearEndBalance, LEAVEAVAILED,OPENINGBALANCE,FORFITEDDAYS)" +
" VALUES(%n, %n, %n, %n, %n,%n, %n, %n, %n, %n, %n,%n,%n,%n)", oItem.ID.Integer, oItem.ProcessId, oItem.EmpId, oItem.LeaveYearID, oItem.LeaveId, oItem.CarryFromPrvYear, oItem.CFDays, oItem.EncashDays, oItem.EncashAmount,
oItem.NormalLeaveDays, oItem.YearEndBalance, oItem.LeaveAvailed, oItem.OpeningBalance, oItem.ForfitedDays);
}
#endregion
#region Update function
public static void Update(TransactionContext tc, EmpLeaveStatus oItem)
{
//oItem.ForBenifitedYear = LeaveEntry.getJulyJuneLeaveYear(oItem.ForBenifitedYear);
tc.ExecuteNonQuery("UPDATE EmpLeaveStatus SET ProcessId=%n, EmpId=%n, LEAVEYEARID=%n, LeaveId=%n, CarryFromPrvYear=%n, CFDays=%n, EncashDays=%n, EncashAmount=%n, NormalLeaveDays=%n, YearEndBalance=%n,LEAVEAVAILED=%n,OPENINGBALANCE=%n,FORFITEDDAYS=%n" +
" WHERE TranId=%n", oItem.ProcessId, oItem.EmpId, oItem.LeaveYearID, oItem.LeaveId, oItem.CarryFromPrvYear, oItem.CFDays, oItem.EncashDays, oItem.EncashAmount, oItem.NormalLeaveDays, oItem.YearEndBalance, oItem.LeaveAvailed, oItem.OpeningBalance, oItem.ForfitedDays, oItem.ID.Integer);
}
#endregion
#region ID Generation function
public static int GetNewDetailID(TransactionContext tc)
{
return tc.GenerateID("EmpLeaveStatus", "TranId");
}
#endregion
#region Get Function
//public static IDataReader Get(TransactionContext tc)
//{
// return tc.ExecuteReader("SELECT * FROM EmpLeaveStatus");
//}
public static IDataReader GetStatus(TransactionContext tc, int empid, int leaveID, int leaveYearID)
{
//if(leaveID==0)
// return tc.ExecuteReader("SELECT * FROM EmpLeaveStatus where EMPID=%n AND LEAVEYEARID=%n",empid,leaveYearID);
return tc.ExecuteReader("SELECT * FROM EmpLeaveStatus where EMPID=%n AND LEAVEID=%n AND LEAVEYEARID=%n", empid, leaveID, leaveYearID);
}
public static IDataReader GetProcessDetail(TransactionContext tc, int nTranId)
{
return tc.ExecuteReader("SELECT * FROM EmpLeaveStatus WHERE TranId=%n", nTranId);
}
public static IDataReader GetAllStatus(TransactionContext tc, int empId)
{
return tc.ExecuteReader("SELECT * FROM EmpLeaveStatus WHERE EMPID=%n", empId);
}
public static IDataReader GetByYear(TransactionContext tc, int ProcessYear, int LeaveId, int EmpId)
{
//ProcessYear = LeaveEntry.getJulyJuneLeaveYear(ProcessYear);
return tc.ExecuteReader("SELECT * FROM EmpLeaveStatus WHERE ProcessId in(select ProcessId from LeaveProcess where LEAVEYEARID=%n) and LeaveId=%n and EmpId=%n", ProcessYear, LeaveId, EmpId);
}
public static IDataReader GetByYear(TransactionContext tc, int LeaveYearID)
{
return tc.ExecuteReader("SELECT * FROM EmpLeaveStatus WHERE LEAVEYEARID=%n", LeaveYearID);
}
public static IDataReader GetByProcessId(TransactionContext tc, int nProcessId)
{
return tc.ExecuteReader("SELECT * FROM EmpLeaveStatus WHERE ProcessId=%n", nProcessId);
}
#endregion
#region Delete function
public static void DeleteProcessDetail(TransactionContext tc, int nTranId)
{
tc.ExecuteNonQuery("DELETE FROM EmpLeaveStatus WHERE TranId=%n", nTranId);
}
public static void Delete(TransactionContext tc, EmpLeaveStatus oItem)
{
tc.ExecuteNonQuery("DELETE FROM EmpLeaveStatus WHERE TranId=%n", oItem.ID.Integer);
}
public static void DeleteByProcessId(TransactionContext tc, int nProcessId)
{
tc.ExecuteNonQuery("DELETE FROM EmpLeaveStatus WHERE ProcessId=%n", nProcessId);
}
internal static IDataReader GetByYearType(TransactionContext tc, int leaveYearID, int leaveId)
{
string Ssql = SQLParser.MakeSQL("SELECT * FROM EmpLeaveStatus WHERE LEAVEYEARID=%n And LEAVEID=%n", leaveYearID, leaveId);
return tc.ExecuteReader(Ssql);
}
internal static void UpdateEncashAmount(TransactionContext tc, EmpLeaveStatus oStatus)
{
string sSQL = SQLParser.MakeSQL("UPDATE EmpLeaveStatus SET EncashAmount=%n WHERE TranId=%n", oStatus.EncashAmount, oStatus.ID.Integer);
tc.ExecuteNonQuery(sSQL);
}
public static void DeleteByPayrollType(TransactionContext tc, int nProcessYear, int nPayrollTypeID,int nLeaveID)
{
tc.ExecuteNonQuery("DELETE FROM EmpLeaveStatus where ProcessId in(SELECT ProcessId from LeaveProcess where LeaveYearID=%n AND PayrollTypeID=%n) AND LeaveID=%n", nProcessYear, nPayrollTypeID,nLeaveID);
}
#endregion
#endregion
}
#endregion
}