using System; using System.Collections.Generic; using System.Linq; using System.Text; using Ease.CoreV35.DataAccess; using Payroll.BO; using Ease.CoreV35.Model; using System.Data; using Payroll.BO; namespace Payroll.Service.Attendence.DA { #region EmployeeWorkPlanSetupDA internal class EmployeeWorkPlanSetupDA { #region Constructor private EmployeeWorkPlanSetupDA() { } #endregion #region Insert function internal static void Insert(TransactionContext tc, EmployeeWorkPlanSetup item) { string sql = SQLParser.MakeSQL(@"INSERT INTO EmployeeWorkPlanSetup(EmployeeWorkPlanSetupID, EmployeeID, ShiftID, StartDate, WorkPlanGroupID, WeekEndOn,WeekEndOn2,SaturdayShift,SundayShift,MondayShift,TuesdayShift,WednesdayShift,ThursdayShift,FridayShift, CreatedBy, CreatedDate) VALUES(%n, %n, %n, %d, %n, %n,%n,%n,%n,%n,%n,%n,%n,%n, %n, %d)", item.ID.Integer, item.EmployeeID.Integer, DataReader.GetNullValue(item.ShiftID, IDType.Integer), DataReader.GetNullValue(item.StartDate), item.WorkPlanGroupID.Integer, item.WeekEndOn, item.WeekEndOn2, item.SaturdayShiftID, item.SundayShiftID, item.MondayShiftID, item.TuesdayShiftID, item.WednesdayShiftID, item.ThursdayShiftID, item.FridayShiftID, item.CreatedBy.Integer, item.CreatedDate); tc.ExecuteNonQuery(sql); } #endregion #region Update function internal static void Update(TransactionContext tc, EmployeeWorkPlanSetup item) { tc.ExecuteNonQuery("UPDATE EmployeeWorkPlanSetup SET EmployeeID=%n, ShiftID=%n, StartDate=%d, WorkPlanGroupID=%n, WeekEndOn=%n,WeekEndOn2=%n,SaturdayShift=%n,SundayShift=%n,MondayShift=%n,TuesdayShift=%n,WednesdayShift=%n,ThursdayShift=%n,FridayShift=%n, ModifiedBy=%n, ModifiedDate=%d" + " WHERE EmployeeWorkPlanSetupID=%n", item.EmployeeID.Integer, DataReader.GetNullValue(item.ShiftID, IDType.Integer), DataReader.GetNullValue(item.StartDate), item.WorkPlanGroupID.Integer, item.WeekEndOn, item.WeekEndOn2, item.SaturdayShiftID, item.SundayShiftID, item.MondayShiftID, item.TuesdayShiftID, item.WednesdayShiftID, item.ThursdayShiftID, item.FridayShiftID, item.ModifiedBy.Integer, item.ModifiedDate, item.ID.Integer); } #endregion #region Get Function internal static IDataReader Get(TransactionContext tc) { return tc.ExecuteReader("SELECT * FROM EmployeeWorkPlanSetup"); } internal static IDataReader Get(TransactionContext tc, ID nID) { return tc.ExecuteReader("SELECT * FROM EmployeeWorkPlanSetup WHERE EmployeeWorkPlanSetupID=%n", nID); } //internal static IDataReader Get(TransactionContext tc, ID empID, DateTime attnDate) //{ // return tc.ExecuteReader("SELECT * FROM EmployeeWorkPlanSetup WHERE EmployeeWorkPlanSetupID=%n", nID); //} internal static IDataReader GetByEmpID(TransactionContext tc, ID nEmpID) { return tc.ExecuteReader("SELECT * FROM EmployeeWorkPlanSetup WHERE EmployeeID=%n", nEmpID.Integer); } internal static IDataReader GetForFixedWP(TransactionContext tc, ID nGroupID, DayOfWeek nHoliDay) { string sql = SQLParser.MakeSQL("SELECT * FROM EmployeeWorkPlanSetup WHERE WorkPlanGroupID=%n and (WeekEndOn=%n OR WeekEndOn2 = %n)", nGroupID.Integer, nHoliDay, nHoliDay); return tc.ExecuteReader(sql); } internal static IDataReader Get(TransactionContext tc, EnumWorkPlanGroup type) { return tc.ExecuteReader("SELECT EmployeeWorkPlanSetup.* FROM EmployeeWorkPlanSetup, WorkPlanGroup WHERE EmployeeWorkPlanSetup.WorkPlanGroupID=WorkPlanGroup.WorkPlanGroupID AND WorkPlanGroup.type=%n", type); } internal static IDataReader GetByWPGroupID(TransactionContext tc, ID wpGroupID) { return tc.ExecuteReader("SELECT EmployeeWorkPlanSetup.* FROM EmployeeWorkPlanSetup, Employee WHERE EmployeeWorkPlanSetup.EmployeeID = Employee.EmployeeID and Employee.Status=%n and WorkPlanGroupID=%n", EnumEmployeeStatus.Live, wpGroupID.Integer); } internal static IDataReader GetMissingEmps(TransactionContext tc, ID wpGroupID, DateTime assignDate) { string sql = SQLParser.MakeSQL("SELECT * FROM EmployeeWorkPlanSetup WHERE WorkPlanGroupID=%n and " + "EmployeeID IN(select EmployeeID FROM EMPLOYEE WHERE STATUS =%n) and " + "EmployeeID not in (select distinct(EmployeeID) from MonthlyWorkPlan " + "where workdate between %d and %d and WorkPlanGroupID=%n)" , wpGroupID.Integer, EnumEmployeeStatus.Live, GlobalFunctions.FirstDateOfMonth(assignDate), GlobalFunctions.LastDateOfMonth(assignDate), wpGroupID.Integer); return tc.ExecuteReader(sql); } internal static DataSet GetEmpNotInWorkPlan(TransactionContext tc, int payrollTypeID) { DataSet empInfo = new DataSet(); try { string sql = SQLParser.MakeSQL("select e.employeeno,e.name,g.DESCRIPTION from employee e,GRADES g " + "where e.gradeID = g.GRADEID and e.status=%n and e.PayrollTypeID =%n and e.employeeid not in " + "(select employeeid from EmployeeWorkPlanSetup)", EnumEmployeeStatus.Live, payrollTypeID); empInfo = tc.ExecuteDataSet(sql); } catch (Exception ex) { throw new Exception(ex.Message); } return empInfo; } internal static bool IsExist(TransactionContext tc, ID groupID, DayOfWeek weekEndOn) { bool isExist = false; object obj = tc.ExecuteScalar("SELECT Count(*) from EmployeeWorkPlanSetup Where WorkPlanGroupID=%n and (WeekEndOn=%n OR WeekEndOn2 = %n)", groupID.Integer, weekEndOn,weekEndOn); isExist = Convert.ToInt32(obj) > 0 ? true : false; return isExist; } #endregion #region Delete function internal static void Delete(TransactionContext tc, ID nID) { tc.ExecuteNonQuery("DELETE FROM [EmployeeWorkPlanSetup] WHERE EmployeeWorkPlanSetupID=%n", nID.Integer); } internal static void DeleteExistingData(TransactionContext tc, ID employeeID) { tc.ExecuteNonQuery("DELETE FROM [EmployeeWorkPlanSetup] WHERE EmployeeID=%n", employeeID.Integer); } internal static void Delete(TransactionContext tc, ID groupID, DayOfWeek weekEndOn) { tc.ExecuteNonQuery("DELETE FROM [EmployeeWorkPlanSetup] WHERE WorkPlanGroupID=%n and (WeekEndOn=%n OR WeekEndOn2 = %n)", groupID.Integer, weekEndOn,weekEndOn); } internal static void Delete(ID groupID,TransactionContext tc) { tc.ExecuteNonQuery("DELETE FROM [EmployeeWorkPlanSetup] WHERE WorkPlanGroupID=%n", groupID.Integer); } #endregion } #endregion }