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 { class LeaveEntryDA { #region Constructor public LeaveEntryDA() { } #endregion #region Insert function public static void Insert(TransactionContext tc, LeaveEntry oItem) { string sSQL = SQLParser.MakeSQL("INSERT INTO LeaveEntry(TranId, EmpId, EmpGradeId,LeaveYear, AppParamId, AppLeaveDate, AppFromDate, AppToDate, AppTotalDays, AprParamId, AprLeaveDate, AprFromDate, AprToDate, APRTOTALDAYS, ApprovedBy, Remarks, EntryDate,IsDrafted,IsAvailed,LeaveStatus,ErnLeaveRemarks,LeaveID,DepartmentID,DesignationID,AvailFromDate,AvailToDate,AvailTotalDays,AvailRemarks,AvailedBy,DayPeriod,WorkingDate)" + " VALUES(%n, %n, %n, %n, %n, %d, %d, %d, %n, %n, %d, %d, %d, %n, %n, %s, %d, %n,%n,%n,%s,%n,%n,%n,%d,%d,%n,%s,%n,%s,%d)", oItem.ID.Integer, oItem.EmpID, DataReader.GetNullValue(oItem.EmpGradeId), oItem.LeaveYear, oItem.AppliedParamId, oItem.AppliedLeaveDate, oItem.AppliedFromDate, oItem.AppliedToDate, oItem.AppliedTotalDays, oItem.ApprovedParamId, oItem.ApprovedLeaveDate, oItem.ApprovedFromDate, oItem.ApprovedToDate, oItem.ApprovedTotalDays, DataReader.GetNullValue(oItem.ApprovedBy, IDType.Integer), oItem.Remarks, oItem.EntryDate, oItem.IsDrafted, oItem.IsAvailed, (int)oItem.LeaveStatus, oItem.ErnLeaveRemarks, DataReader.GetNullValue(oItem.LeaveID, IDType.Integer), //DataReader.GetNullValue(oItem.SbuID, IDType.Integer), DataReader.GetNullValue(oItem.DepartmentID, IDType.Integer), //DataReader.GetNullValue(oItem.FunctionID, IDType.Integer), //DataReader.GetNullValue(oItem.LocationID, IDType.Integer), DataReader.GetNullValue(oItem.DesignationID, IDType.Integer), DataReader.GetNullValue(oItem.AvailFromDate), DataReader.GetNullValue(oItem.AvailToDate), oItem.AvailTotalDays, oItem.AvailRemarks.Trim(), DataReader.GetNullValue(oItem.AvailedBy, IDType.Integer), oItem.LeaveDayPeriod, DataReader.GetNullValue(oItem.WorkingDate)); tc.ExecuteNonQuery(sSQL); } #endregion #region Update function public static void Update(TransactionContext tc, LeaveEntry oItem) { tc.ExecuteNonQuery("UPDATE LeaveEntry SET EmpId=%n, EmpGradeId=%n, LeaveYear=%n, AppParamId=%n, AppLeaveDate=%d, AppFromDate=%d, AppToDate=%d, AppTotalDays=%n, AprParamId=%n, AprLeaveDate=%d, AprFromDate=%d, AprToDate=%d, APrTOTALDAYS=%n, ApprovedBy=%n, Remarks=%s, EntryDate=%d, IsDrafted=%n, IsAvailed=%n,LeaveStatus=%n, " + "ErnLeaveRemarks=%s,LeaveID=%n,DepartmentID=%n,DesignationID=%n,AvailFromDate=%d,AvailToDate=%d,AvailTotalDays=%n,AvailRemarks=%s,AvailedBy=%n,DayPeriod=%s,WorkingDate=%d, SBUID=%n" + " WHERE TranId=%n", oItem.EmpID, oItem.EmpGradeId, oItem.LeaveYear, oItem.AppliedParamId, oItem.AppliedLeaveDate, oItem.AppliedFromDate, oItem.AppliedToDate, oItem.AppliedTotalDays, oItem.ApprovedParamId, oItem.ApprovedLeaveDate, oItem.ApprovedFromDate, oItem.ApprovedToDate, oItem.ApprovedTotalDays, DataReader.GetNullValue(oItem.ApprovedBy, IDType.Integer), oItem.Remarks, oItem.EntryDate, oItem.IsDrafted, oItem.IsAvailed, (int)oItem.LeaveStatus, oItem.ErnLeaveRemarks, DataReader.GetNullValue(oItem.LeaveID, IDType.Integer), //DataReader.GetNullValue(oItem.SbuID.Integer), DataReader.GetNullValue(oItem.DepartmentID, IDType.Integer), //DataReader.GetNullValue(oItem.FunctionID.Integer), //DataReader.GetNullValue(oItem.LocationID.Integer), DataReader.GetNullValue(oItem.DesignationID, IDType.Integer), DataReader.GetNullValue(oItem.AvailFromDate), DataReader.GetNullValue(oItem.AvailToDate), oItem.AvailTotalDays, oItem.AvailRemarks.Trim(), DataReader.GetNullValue(oItem.AvailedBy, IDType.Integer),oItem.LeaveDayPeriod,DataReader.GetNullValue(oItem.WorkingDate),1, oItem.ID.Integer); } public static void UpdateLeaveStatus(TransactionContext tc, LeaveEntry oItem) { tc.ExecuteNonQuery("UPDATE LeaveEntry SET LEAVESTATUS=%n WHERE TranId=%n", oItem.LeaveStatus, oItem.ID.Integer); } #endregion #region ID Generation function public static int GetNewID(TransactionContext tc) { return tc.GenerateID("LeaveEntry", "TranId"); } #endregion #region Get Function public static IDataReader GetByLeaveID(TransactionContext tc, int nLeaveID, int nEmpID, DateTime fromDate, DateTime toDate) { return tc.ExecuteReader("SELECT LeaveEntry.* FROM LeaveEntry where LEAVEID=%n AND EmpId=%n AND AprFromDate between %d and %d AND APPTOTALDAYS<>0 AND LEAVESTATUS=%n order by AppFromDate DESC", nLeaveID, nEmpID, fromDate, toDate, (int) EnumLeaveStatus.OnApproval); } public static IDataReader Get(TransactionContext tc, int empId, int leaveYear, int LeaveStatus) { if (LeaveStatus == 0) return tc.ExecuteReader("SELECT LeaveEntry.*, Leave.Description FROM LeaveEntry, Leave, LeaveParameter where LeaveEntry.AprParamID=LeaveParameter.LeaveParamId AND LeaveParameter.LeaveID= Leave.LeaveID AND EmpId=%n and LeaveYear=%n AND APPTOTALDAYS<>0 order by AppFromDate DESC", empId, leaveYear); else return tc.ExecuteReader("SELECT LeaveEntry.*, Leave.Description FROM LeaveEntry, Leave, LeaveParameter where LeaveEntry.AprParamID=LeaveParameter.LeaveParamId AND LeaveParameter.LeaveID= Leave.LeaveID AND EmpId=%n and LeaveYear=%n and LeaveStatus=%n AND APPTOTALDAYS<>0 order by AppFromDate DESC", empId, leaveYear, LeaveStatus); } public static IDataReader Get(TransactionContext tc, string empIds, int leaveYear, int LeaveStatus) { string inSQL = ""; inSQL = "in (" + empIds + ")"; if (LeaveStatus == 0) return tc.ExecuteReader("SELECT LeaveEntry.*, Leave.Description FROM LeaveEntry, Leave, LeaveParameter where LeaveEntry.AprParamID=LeaveParameter.LeaveParamId AND LeaveParameter.LeaveID= Leave.LeaveID AND EmpId %q and LeaveYear=%n AND APPTOTALDAYS<>0 order by AppFromDate DESC", inSQL, leaveYear); else return tc.ExecuteReader("SELECT LeaveEntry.*, Leave.Description FROM LeaveEntry, Leave, LeaveParameter where LeaveEntry.AprParamID=LeaveParameter.LeaveParamId AND LeaveParameter.LeaveID= Leave.LeaveID AND EmpId %q and LeaveYear=%n and LeaveStatus=%n AND APPTOTALDAYS<>0 order by AppFromDate DESC", inSQL, leaveYear, LeaveStatus); } public static IDataReader Get(TransactionContext tc, DateTime fromDate, DateTime toDate, int LeaveStatus) { if (LeaveStatus == 0) return tc.ExecuteReader("SELECT LeaveEntry.*, Leave.Description FROM LeaveEntry, Leave, LeaveParameter where LeaveEntry.AprParamID=LeaveParameter.LeaveParamId AND LeaveParameter.LeaveID= Leave.LeaveID AND AprFromDate between %d and %d AND APPTOTALDAYS<>0 order by AppFromDate DESC", fromDate, toDate); else return tc.ExecuteReader("SELECT LeaveEntry.*, Leave.Description FROM LeaveEntry, Leave, LeaveParameter where LeaveEntry.AprParamID=LeaveParameter.LeaveParamId AND LeaveParameter.LeaveID= Leave.LeaveID AND AprFromDate between %d and %d and LeaveStatus =%n AND APPTOTALDAYS<>0 order by AppFromDate DESC", fromDate, toDate, LeaveStatus); } public static IDataReader Get(TransactionContext tc, DateTime attnDate) { string sql = SQLParser.MakeSQL("SELECT * FROM LeaveEntry where %d Between APRFROMDATE AND APRTODATE ", attnDate); return tc.ExecuteReader(sql); } public static IDataReader Get(TransactionContext tc, string empIds, DateTime fromDate, DateTime toDate, int LeaveStatus) { string inSQL = string.Empty; string sql = string.Empty; inSQL = "in (" + empIds + ")"; //if (LeaveStatus == 0) // sql = SQLParser.MakeSQL("SELECT LeaveEntry.*, Leave.Description FROM LeaveEntry, Leave, LeaveParameter " // + " where LeaveEntry.AprParamID=LeaveParameter.LeaveParamId AND LeaveParameter.LeaveID= Leave.LeaveID AND AprFromDate between %d and %d and EmpId %q AND APPTOTALDAYS<>0 order by EmpId ASC", fromDate, toDate, inSQL); //else // sql = SQLParser.MakeSQL("SELECT LeaveEntry.*, Leave.Description FROM LeaveEntry, Leave, LeaveParameter " // + " where LeaveEntry.AprParamID=LeaveParameter.LeaveParamId AND LeaveParameter.LeaveID= Leave.LeaveID AND AprFromDate between %d AND %d and LeaveStatus =%n and EmpId %q AND APPTOTALDAYS<>0 order by EmpId ASC", fromDate, toDate, LeaveStatus, inSQL); if (LeaveStatus == 0) sql = SQLParser.MakeSQL("SELECT LeaveEntry.*, Leave.Description FROM LeaveEntry, Leave, LeaveParameter " + " where LeaveEntry.AprParamID=LeaveParameter.LeaveParamId AND LeaveParameter.LeaveID= Leave.LeaveID AND (AprFromDate between %d and %d OR AprToDate between %d and %d OR %d BETWEEN AprFromDate AND AprToDate) and EmpId %q AND APPTOTALDAYS<>0 order by EmpId ASC", fromDate, toDate, fromDate, toDate, fromDate, inSQL); else sql = SQLParser.MakeSQL("SELECT LeaveEntry.*, Leave.Description FROM LeaveEntry, Leave, LeaveParameter " + " where LeaveEntry.AprParamID=LeaveParameter.LeaveParamId AND LeaveParameter.LeaveID= Leave.LeaveID AND AprFromDate between %d AND %d and LeaveStatus =%n and EmpId %q AND APPTOTALDAYS<>0 order by EmpId ASC", fromDate, toDate, LeaveStatus, inSQL); return tc.ExecuteReader(sql); } public static IDataReader GetPending(TransactionContext tc, int empId, int leaveID, int LeaveStatus) { string sql = string.Empty; sql = SQLParser.MakeSQL("SELECT LeaveEntry.* FROM LeaveEntry Where EmpId=%n AND LeaveID=%n AND LeaveStatus=%n ", empId, leaveID, LeaveStatus); return tc.ExecuteReader(sql); } public static IDataReader GetRecord(TransactionContext tc, string empIds, DateTime fromDate, DateTime toDate, int LeaveStatus) { string inSQL = string.Empty; string sql = string.Empty; inSQL = "in (" + empIds + ")"; if (LeaveStatus == 0) return tc.ExecuteReader("SELECT LeaveEntry.*, Leave.Description FROM LeaveEntry, Leave, LeaveParameter " + " where LeaveEntry.AprParamID=LeaveParameter.LeaveParamId AND LeaveParameter.LeaveID= Leave.LeaveID AND AprFromDate between %d and %d and EmpId %q AND APPTOTALDAYS<>0 order by AprFromDate DESC", fromDate, toDate, inSQL); else return tc.ExecuteReader("SELECT LeaveEntry.TranID,LeaveEntry.Remarks,LeaveEntry.AprFromDate,LeaveEntry.AprToDate,LeaveEntry.AprTotalDays,LeaveEntry.LeaveStatus,Leave.Description,LeaveEntry.AppLeaveDate FROM LeaveEntry, Leave, LeaveParameter " + " where LeaveEntry.AprParamID=LeaveParameter.LeaveParamId AND LeaveParameter.LeaveID= Leave.LeaveID AND AprFromDate between %d and %d and EmpId %q AND APPTOTALDAYS<>0 order by AprFromDate DESC", fromDate, toDate, inSQL); } public static IDataReader Get(TransactionContext tc, int empId, int leaveYearID) { return tc.ExecuteReader("SELECT * from LeaveEntry where EMPID=%n AND LEAVEYEAR=%n", empId, leaveYearID); } public static IDataReader GetByLeaveYear(TransactionContext tc, int nLeaveYear) { return tc.ExecuteReader("SELECT * from LeaveEntry where LeaveYear=%n", nLeaveYear); } public static IDataReader Get(TransactionContext tc, string empIds, DateTime fromDate, DateTime toDate, string LeaveStatus) { string inSQL = ""; inSQL = "in (" + empIds + ")"; if (!(LeaveStatus.Trim().Length > 0)) return tc.ExecuteReader("SELECT LeaveEntry.*, Leave.Description FROM LeaveEntry, Leave, LeaveParameter " + " where LeaveEntry.AprParamID=LeaveParameter.LeaveParamId AND LeaveParameter.LeaveID= Leave.LeaveID AND AprFromDate between %d and %d and EmpId %q AND APPTOTALDAYS<>0 Order by EmpId ASC", fromDate, toDate, inSQL); else { string str = SQLParser.MakeSQL("SELECT LeaveEntry.*, Leave.Description FROM LeaveEntry, Leave, LeaveParameter " + " where LeaveEntry.AprParamID=LeaveParameter.LeaveParamId AND LeaveParameter.LeaveID= Leave.LeaveID AND AprFromDate between %d and %d and LeaveStatus in (%q) and EmpId %q AND APPTOTALDAYS<>0 Order by EmpId ASC", fromDate, toDate, LeaveStatus, inSQL); return tc.ExecuteReader(str); } } public static IDataReader Get(TransactionContext tc, int tranId) { string sSQL = SQLParser.MakeSQL("SELECT LeaveEntry.*, Leave.Description FROM LeaveEntry, Leave, LeaveParameter WHERE LeaveEntry.AprParamID=LeaveParameter.LeaveParamId AND LeaveParameter.LeaveID= Leave.LeaveID AND TranId=%n AND APPTOTALDAYS<>0", tranId); return tc.ExecuteReader(sSQL); } public static IDataReader GetForAdminPanel(TransactionContext tc, int employeeID) { string str = SQLParser.MakeSQL("Select LeaveEntry.*, Leave.Description FROM LeaveEntry, Leave, LeaveParameter where LeaveEntry.AprParamID=LeaveParameter.LeaveParamId AND LeaveParameter.LeaveID= Leave.LeaveID and empID=%n and LeaveStatus in( %n, %n, %n, %n) AND APPTOTALDAYS<>0", employeeID, (int)EnumLeaveStatus.Drafted, (int)EnumLeaveStatus.OnApproval, (int)EnumLeaveStatus.OnApproval, (int)EnumLeaveStatus.Approved); return tc.ExecuteReader(str); } public static IDataReader GetYearEndData(TransactionContext tc, int leaveYear) { string sSql = ""; sSql = "Select A.LeaveId,B.EmpId,sum(B.TotalDays)as TotalDays from " + "LeaveParameter A inner join " + "(SELECT AppParamId,EmpId,sum(AppTotalDays)as TotalDays FROM " + "LeaveEntry where LeaveYear= " + leaveYear + " and LeaveStatus =5 AND APPTOTALDAYS<>0 group by AppParamId,EmpId " + ")B " + "on A.LeaveParamId=B.AppParamId " + " group by LeaveId,EmpId " + " order by LeaveId,EmpId"; return tc.ExecuteReader(sSql); } public static IDataReader GetAvailedLeave(TransactionContext tc, DateTime stDate, DateTime endDate, string empIds) { string sSql = ""; sSql = "select OrganizationHierarchy.OrganizationId as OrgId,OrganizationHierarchy.Description as Organization,X.* from Employee,OrganizationHierarchy,(" + "Select A.LeaveId,B.EmpId,sum(B.TotalDays)as TotalDays from " + "LeaveParameter A inner join " + "(SELECT AppParamId,EmpId,sum(AppTotalDays)as TotalDays FROM " + "LeaveEntry where LeaveStatus =5 and EmpId in (" + empIds + ") and AprLeaveDate between '" + stDate.Date + "' and '" + endDate.Date + "' AND APPTOTALDAYS<>0 group by AppParamId,EmpId " + ")B " + "on A.LeaveParamId=B.AppParamId " + " group by LeaveId,EmpId)X where Employee.EmployeeId=X.EmpId " + " and Employee.OrganizationId=OrganizationHierarchy.OrganizationId " + " order by OrganizationHierarchy.OrganizationId ASC"; return tc.ExecuteReader(sSql); } public static IDataReader GetEmployeeWiseLeaveDetailReport(TransactionContext tc, int empId, DateTime fromDate, DateTime toDate, int leaveType) { string query = string.Empty; LeaveYear ly = LeaveYear.GetCurrentYear(); if (leaveType == 0) { query = "SELECT * " + " FROM LeaveEntry" + " WHERE EmpId = %n AND LeaveEntry.AprFromDate >= %d AND LeaveEntry.AprToDate <= %d " + " AND (LEAVESTATUS=%n OR LEAVESTATUS=%n) AND LeaveYear=%n AND LeaveEntry.APPTOTALDAYS<>0 order by AprFromDate DESC"; return tc.ExecuteReader(query, empId, fromDate, toDate, EnumLeaveStatus.Approved,EnumLeaveStatus.Cancel_Request, ly.ID.Integer); } else { query = "SELECT * " + " FROM LeaveEntry" + " WHERE EmpId = %n AND LEAVEID=%n AND LeaveEntry.AprFromDate >= %d AND LeaveEntry.AprToDate <= %d " + " AND (LEAVESTATUS=%n OR LEAVESTATUS=%n) AND LeaveYear=%n AND LeaveEntry.APPTOTALDAYS<>0 order by AprFromDate DESC"; return tc.ExecuteReader(query, empId, leaveType, fromDate, toDate, EnumLeaveStatus.Approved, EnumLeaveStatus.Cancel_Request, ly.ID.Integer); } } public static IDataReader GetEmployeeWiseLeaveDetailReport(TransactionContext tc, int empId, DateTime fromDate, DateTime toDate) { string query = string.Empty; LeaveYear ly = LeaveYear.GetCurrentYear(); { query = "SELECT * " + " FROM LeaveEntry" + " WHERE EmpId = %n AND LeaveEntry.AprFromDate >= %d AND LeaveEntry.AprToDate <= %d " + " AND LeaveYear=%n AND LeaveEntry.APPTOTALDAYS<>0 order by AprFromDate DESC"; return tc.ExecuteReader(query, empId, fromDate, toDate, ly.ID.Integer); } } public static IDataReader GetEmployeeWiseLeaveDetailReport(TransactionContext tc, string empIds, DateTime fromDate, DateTime toDate, int leaveType) { string query = string.Empty; LeaveYear ly = LeaveYear.GetCurrentYear(); if (leaveType == 0) { query = SQLParser.MakeSQL(@"SELECT * FROM LeaveEntry WHERE EmpId in (%q) AND LeaveEntry.AprFromDate >= %d AND LeaveEntry.AprToDate <= %d AND (LEAVESTATUS=%n OR LEAVESTATUS=%n) AND LeaveYear=%n AND LeaveEntry.APPTOTALDAYS<>0 order by AprFromDate DESC"); return tc.ExecuteReader(query, empIds, fromDate, toDate, EnumLeaveStatus.Approved, EnumLeaveStatus.Cancel_Request, ly.ID.Integer); } else { query = SQLParser.MakeSQL(@"SELECT * FROM LeaveEntry WHERE EmpId in (%q) AND LEAVEID=%n AND LeaveEntry.AprFromDate >= %d AND LeaveEntry.AprToDate <= %d AND (LEAVESTATUS=%n OR LEAVESTATUS=%n) AND LeaveYear=%n AND LeaveEntry.APPTOTALDAYS<>0 order by AprFromDate DESC"); return tc.ExecuteReader(query, empIds, leaveType, fromDate, toDate, EnumLeaveStatus.Approved, EnumLeaveStatus.Cancel_Request, ly.ID.Integer); } } public static IDataReader GetEmployeeWiseLeaveDetailReport(TransactionContext tc, string empIds, DateTime fromDate, DateTime toDate) { string query = string.Empty; LeaveYear ly = LeaveYear.GetCurrentYear(); { query = SQLParser.MakeSQL(@"SELECT * FROM LeaveEntry WHERE EmpId in (%q) AND LeaveEntry.AprFromDate >= %d AND LeaveEntry.AprToDate <= %d AND LeaveYear=%n AND LeaveEntry.APPTOTALDAYS<>0 order by AprFromDate DESC"); return tc.ExecuteReader(query, empIds, fromDate, toDate, ly.ID.Integer); } } public static int GetEmployeeLeaveBalance(TransactionContext tc, int empId, int leaveYear, int leaveType) { string query = string.Empty; object ob; if (leaveType == 0) { ob = tc.ExecuteScalar("SELECT sum(APPTOTALDAYS) AS TOTAL " + " FROM LeaveEntry" + " WHERE EmpId = %n AND LEAVEYEAR=%n AND LEAVESTATUS=%n", empId, leaveYear, EnumLeaveStatus.Approved); return ob == DBNull.Value ? 0 : Convert.ToInt32(ob); } else { ob = tc.ExecuteScalar("SELECT sum(APPTOTALDAYS) AS TOTAL " + " FROM LeaveEntry" + " WHERE EmpId = %n AND LEAVEYEAR=%n AND LEAVEID=%n AND LEAVESTATUS=%n", empId, leaveYear, leaveType, EnumLeaveStatus.Approved); return ob == DBNull.Value ? 0 : Convert.ToInt32(ob); } } public static DataSet GetLeaveReport(TransactionContext tc, int empId, DateTime fromDate, DateTime toDate) { string query = string.Empty; DataSet dataSet = null; query = "Select Leave.description as LeaveType,C.EmpId,C.TotalDays from Leave inner join" + " (Select A.LeaveId, B.EmpId, sum(B.TotalDays)as TotalDays from LeaveParameter A inner join" + " (SELECT AppParamId,EmpId,sum(AppTotalDays)as TotalDays FROM LeaveEntry where ( AprFromDate >= %d AND AprToDate <= %d)and LeaveStatus =5 AND EmpID = %n group by AppParamId,EmpId )B " + " on A.LeaveParamId=B.AppParamId group by A.LeaveId, EmpId)C on Leave.LeaveId=C.LeaveId order by C.LeaveId, C.EmpId"; dataSet = tc.ExecuteDataSet(query, fromDate, toDate, empId); return dataSet; } public static DataSet GetAvailedLeave(TransactionContext tc, int empId, DateTime fromDate, DateTime toDate) { string query = string.Empty; DataSet dataSet = null; query = "Select Leave.LeaveID ,C.EmpId,C.TotalDays from Leave inner join" + " (Select A.LeaveId, B.EmpId, sum(B.TotalDays)as TotalDays from LeaveParameter A inner join" + " (SELECT AppParamId,EmpId,sum(AppTotalDays)as TotalDays FROM LeaveEntry where ( AprFromDate >= %d AND AprToDate <= %d)and LeaveStatus =%n AND EmpID = %n group by AppParamId,EmpId )B " + " on A.LeaveParamId=B.AppParamId group by A.LeaveId, EmpId)C on Leave.LeaveId=C.LeaveId order by C.LeaveId, C.EmpId"; dataSet = tc.ExecuteDataSet(query, fromDate, toDate, EnumLeaveStatus.Approved, empId); return dataSet; } public static DataSet SBUWiseLeaveReport(TransactionContext tc, string SBUIDs, string LeaveIDs, DateTime fromDate, DateTime toDate) { string query = string.Empty; DataSet dataSet = null; return dataSet; } public static double GetLeaveAmtByType(TransactionContext tc, int empId, int leaveId, int leaveYear, int leaveStatus) { object ob; if ((EnumLeaveStatus)leaveStatus == EnumLeaveStatus.Approved) { ob = tc.ExecuteScalar("SELECT sum(APPTOTALDAYS) FROM LeaveEntry where EmpId=%n and LeaveYear=%n and LeaveID=%n and LeaveStatus =%n AND APPTOTALDAYS<>0", empId, leaveYear, leaveId, leaveStatus); return ob == DBNull.Value ? 0 : Convert.ToDouble(ob); } if (leaveStatus == 0) ob = tc.ExecuteScalar("SELECT sum(APPTOTALDAYS) FROM LeaveEntry where EmpId=%n and LeaveYear=%n and LeaveID=%n AND APPTOTALDAYS<>0", empId, leaveYear, leaveId); else ob = tc.ExecuteScalar("SELECT sum(APPTOTALDAYS) FROM LeaveEntry where EmpId=%n and LeaveYear=%n and LeaveID=%n and LeaveStatus =%n AND APPTOTALDAYS<>0", empId, leaveYear, leaveId, (int)EnumLeaveStatus.Approved); return ob == DBNull.Value ? 0 : Convert.ToDouble(ob); } public static double GetAvailedLeave(TransactionContext tc, int empId, int leaveId, int leaveYear, int leaveStatus) { object ob; //if ((EnumLeaveStatus)leaveStatus == EnumLeaveStatus.Availed) //{ // ob = tc.ExecuteScalar("SELECT sum(APPTOTALDAYS) FROM LeaveEntry where EmpId=%n and LeaveYear=%n and LeaveID=%n and LeaveStatus =%n AND APPTOTALDAYS<>0", empId, leaveYear, leaveId, leaveStatus); // return ob == DBNull.Value ? 0 : Convert.ToDouble(ob); //} if (leaveStatus == 0) ob = tc.ExecuteScalar("SELECT sum(APPTOTALDAYS) FROM LeaveEntry where EmpId=%n and LeaveYear=%n and LeaveID=%n AND APPTOTALDAYS<>0", empId, leaveYear, leaveId); else ob = tc.ExecuteScalar("SELECT sum(APPTOTALDAYS) FROM LeaveEntry where EmpId=%n and LeaveYear=%n and LeaveID=%n and LeaveStatus =%n AND APPTOTALDAYS<>0", empId, leaveYear, leaveId, leaveStatus); return ob == DBNull.Value ? 0 : Convert.ToDouble(ob); } public static double GetAmountOnFromDate(TransactionContext tc, int empId, int leaveYear, int leaveID, EnumLeaveStatus leaveStatus, DateTime dStartDate, DateTime dTodate) { object ob; ob = tc.ExecuteScalar("SELECT sum(APPTOTALDAYS) FROM LeaveEntry where EmpId=%n " + " and LeaveYear=%n and AprParamId=%n and LeaveStatus =%n AND " + " APPTOTALDAYS <> 0 AND AprFromDate BETWEEN %d AND %d", empId, leaveYear, leaveID, leaveStatus, dStartDate, dTodate); return ob == DBNull.Value ? 0 : Convert.ToDouble(ob); } public static double GetTotalLeaveAmountInYear(TransactionContext tc, int empId, int leaveYear, int leaveID, EnumLeaveStatus leaveStatus) { object ob; ob = tc.ExecuteScalar("SELECT SUM(APPTOTALDAYS) FROM LeaveEntry where EmpId=%n " + " and LeaveYear=%n and AprParamId=%n and LeaveStatus =%n AND " + " APPTOTALDAYS <> 0 ", empId, leaveYear, leaveID, leaveStatus); return ob == DBNull.Value ? 0 : Convert.ToDouble(ob); } public static IDataReader GetTotalLeaveAmountInYear(TransactionContext tc, int leaveYear, EnumLeaveStatus leaveStatus) { return tc.ExecuteReader("SELECT Empid,LeaveID,SUM(APPTOTALDAYS) Days FROM LeaveEntry where " + " LeaveYear=%n and LeaveStatus =%n AND " + " APPTOTALDAYS <> 0 group by empid,LeaveID order by empid,LeaveID", leaveYear, leaveStatus); } //public static DataSet GetEmployeeWiseLeaveReport(TransactionContext tc, Ease.Core.Framework.ID empId, DateTime fromDate, DateTime toDate) //{ // string query = string.Empty; // DataSet dataSet = null; // query = " SELECT Leave.LeaveID, Leave.Description as LeaveType, LeaveEntry.APPTOTALDAYS as Days " + // " FROM LeaveEntry, Leave, LeaveParameter " + // " WHERE LeaveEntry.AprParamID=LeaveParameter.LeaveParamId " + // " AND LeaveParameter.LeaveID = Leave.LeaveID " + // " AND EmpId = %n AND LeaveEntry.AprFromDate >= %d AND LeaveEntry.AprToDate <= %d " + // " AND LeaveEntry.APPTOTALDAYS<>0 ORDER BY Leave.LeaveID ASC"; // dataSet = tc.ExecuteDataSet(query, empId.Integer, fromDate, toDate); // return dataSet; //} public static DataSet GetReport(TransactionContext tc, string query) { DataSet dataSet = null; dataSet = tc.ExecuteDataSet(query); return dataSet; } public static IDataReader Get(TransactionContext tc, string empIds, DateTime fromDate, DateTime toDate, int LeaveStatus, string sortExpresion) { string inSQL = ""; inSQL = "in (" + empIds + ")"; if (LeaveStatus == 0) { string str = SQLParser.MakeSQL("SELECT LeaveEntry.*, Leave.Description FROM LeaveEntry, Leave, LeaveParameter " + " where LeaveEntry.AprParamID=LeaveParameter.LeaveParamId AND LeaveParameter.LeaveID= Leave.LeaveID AND AprFromDate between %d and %d AND APPTOTALDAYS<>0 and EmpId %q order by " + sortExpresion, fromDate, toDate, inSQL); return tc.ExecuteReader(str); } else return tc.ExecuteReader("SELECT LeaveEntry.*, Leave.Description FROM LeaveEntry, Leave, LeaveParameter " + " where LeaveEntry.AprParamID=LeaveParameter.LeaveParamId AND LeaveParameter.LeaveID= Leave.LeaveID AND AprFromDate between %d and %d and LeaveStatus =%n AND APPTOTALDAYS<>0 and EmpId %q order by %s", fromDate, toDate, LeaveStatus, inSQL, sortExpresion); } public static bool IsEntered(TransactionContext tc, DateTime year) { // nProcessYear = LeaveEntry.getJulyJuneLeaveYear(nProcessYear); object obj = new object(); obj = tc.ExecuteScalar("SELECT * FROM LeaveEntry WHERE AprFromDate=%d", year); return (Convert.ToInt32(obj) != 0); } //public static double GetSubmittedAmt(TransactionContext tc, int empId, int leaveParamId, int leaveYear) //{ // object ob; // ob = tc.ExecuteScalar("SELECT sum(APPTOTALDAYS) FROM LeaveEntry where EmpId=%n and LeaveYear=%n and AprParamId=%n and LeaveStatus =5", empId, leaveYear, leaveParamId); // return ob==DBNull.Value?0:Convert.ToDouble(ob); //} //public static double GetApprovedAmt(TransactionContext tc, int empId, int leaveParamId, int leaveYear) //{ // object ob; // ob = tc.ExecuteScalar("SELECT sum(APPTOTALDAYS) FROM LeaveEntry where EmpId=%n and LeaveYear=%n and AprParamId=%n and IsDrafted=0 and ApprovedBy is not null", empId, leaveYear, leaveParamId); // return ob == DBNull.Value ? 0 : Convert.ToDouble(ob); //} //public static double GetAvailedAmt(TransactionContext tc, int empId, int leaveParamId, int leaveYear) //{ // object ob; // ob = tc.ExecuteScalar("SELECT sum(APPTOTALDAYS) FROM LeaveEntry where EmpId=%n and LeaveYear=%n and AprParamId=%n and IsAvailed=1", empId, leaveYear, leaveParamId); // return ob == DBNull.Value ? 0 : Convert.ToDouble(ob); //} #endregion public static bool IsExist(TransactionContext tc, Employee oEmployee, DateTime fromDate, DateTime toDate) { object obj = new object(); obj = tc.ExecuteScalar("SELECT * FROM LeaveEntry WHERE EMPID=%n AND APPFROMDATE = %d AND APPTODATE = %d", oEmployee.ID.Integer, fromDate, toDate); return Convert.ToInt32(obj) != 0 ? true : false; } #region Delete function public static void Delete(TransactionContext tc, int tranId) { //IDataReader rdr=tc.ExecuteReader("SELECT * FROM LeaveEntry WHERE TranID=%n",tranId); //NullHandler oreader = new NullHandler(rdr); //if(rdr.Read()) //{ // if (oreader.GetInt32("LeaveStatus") == (int)EnumLeaveStatus.Drafted) // { // tc.ExecuteNonQuery("DELETE FROM LeavePlanerEntry WHERE TranId=%n", tranId); // } //} //tc.ExecuteNonQuery("DELETE FROM LeaveEntry WHERE TranId=%n", tranId); tc.ExecuteNonQuery("DELETE FROM LeaveEntry WHERE TranId=%n", tranId); } public static void DeleteDummyEntry(TransactionContext tc, LeaveEntry oItem) { try { tc.ExecuteNonQuery("DELETE FROM LeaveEntry WHERE EmpID=%n and LeaveID=%n AND LeaveYear=%n", oItem.EmpID, oItem.LeaveID.Integer,oItem.LeaveYear); } catch (Exception ex) { } } public static void DeleteByLeaveYear(TransactionContext tc, int nYear) { tc.ExecuteNonQuery("DELETE FROM LeaveEntry WHERE LeaveYear=%n", nYear); } #endregion } } /*----sbu wise select Emp.SBUID,L.LeaveID,L.Description, sum(LE.APPTOTALDAYS) as TotalDays from LeaveEntry LE,Employee Emp,Leave L ,LeaveParameter LP where empid in(select E.EmployeeID from employee E where sbuid in (1,2)) and L.LeaveID=LP.LeaveID and LP.LeaveParamID=LE.AprParamID and Emp.EmployeeID=LE.EmpID group by Emp.SBUID,L.LeaveID,L.Description order by Emp.SBUID */