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

243 lines
11 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using HRM.BO;
using Ease.Core.DataAccess;
namespace HRM.DA
{
#region EmployeeWorkPlanSetupDA
internal class EmployeeWorkPlanSetupDA
{
#region Constructor
private EmployeeWorkPlanSetupDA()
{
}
#endregion
#region Insert function
internal static void Insert(TransactionContext tc, EmployeeWorkPlanSetup item, int PayrollTypeID)
{
string sql = SQLParser.MakeSQL(@"INSERT INTO EmployeeWorkPlanSetup(EmployeeWorkPlanSetupID,
EmployeeID, StartDate, WorkPlanGroupID, CreatedBy, CreatedDate, PayrolltypeID, WeekEndOn)
VALUES(%n, %n, %d, %n, %n, %d, %n, %n)",
item.ID, item.EmployeeID, DataReader.GetNullValue(item.StartDate),
item.WorkPlanGroupID,
item.CreatedBy, item.CreatedDate, PayrollTypeID, item.WeekEndOn);
/*string sql = SQLParser.MakeSQL(@"INSERT INTO EmployeeWorkPlanSetup(EmployeeWorkPlanSetupID,
EmployeeID, StartDate, CreatedBy, CreatedDate, PayrolltypeID)
VALUES(%n, %n, %d, %n, %d, %n)",
item.ID, item.EmployeeID, DataReader.GetNullValue(item.StartDate),
item.CreatedBy, item.CreatedDate, PayrollTypeID);*/
tc.ExecuteNonQuery(sql);
}
#endregion
#region Update function
internal static void Update(TransactionContext tc, EmployeeWorkPlanSetup item)
{
tc.ExecuteNonQuery(@"UPDATE EmployeeWorkPlanSetup SET EmployeeID=%n, StartDate=%d,
WorkPlanGroupID=%n, ModifiedBy=%n, ModifiedDate=%d" +
" WHERE EmployeeWorkPlanSetupID=%n", item.EmployeeID,
DataReader.GetNullValue(item.StartDate), item.WorkPlanGroupID,
item.ModifiedBy, item.ModifiedDate, item.ID);
}
#endregion
#region Get Function
internal static IDataReader Get(TransactionContext tc)
{
/*return tc.ExecuteReader("SELECT * FROM EmployeeWorkPlanSetup");*/
return tc.ExecuteReader(@"SELECT emp.*, e.NAME, e.employeeNO, w.name AS workPlanGroupName FROM
EmployeeWorkPlanSetup emp inner JOIN EMPLOYEE e
ON e.EMPLOYEEID = emp.EMPLOYEEID
inner join WorkPlanGroup w
On w.WORKPLANGROUPID = emp.WORKPLANGROUPID");
}
internal static IDataReader Get(TransactionContext tc, int 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, int nEmpID)
{
return tc.ExecuteReader("SELECT * FROM EmployeeWorkPlanSetup WHERE EmployeeID=%n", nEmpID);
}
internal static IDataReader GetForFixedWP(TransactionContext tc, int nGroupID, DayOfWeek nHoliDay)
{
string sql =
SQLParser.MakeSQL(
"SELECT * FROM EmployeeWorkPlanSetup WHERE WorkPlanGroupID=%n and (WeekEndOn=%n OR WeekEndOn2 = %n)",
nGroupID, 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, int wpGroupID)
{
return tc.ExecuteReader(@"SELECT emp.*, e.name, e.employeeNo, W.name as workPlanGroupName
FROM EMPLOYEEWORKPLANSETUP emp
inner JOIN WorkPlanGroup w ON emp.WORKPLANGROUPID = w.WorkPlanGroupID
inner JOIN EMPLOYEE e ON e.EMPLOYEEID = emp.EMPLOYEEID
WHERE e.STATUS = %n AND emp.WORKPLANGROUPID = %n; ", EnumEmployeeStatus.Live, wpGroupID);
}
internal static IDataReader GetMissingEmps(TransactionContext tc, int 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, EnumEmployeeStatus.Live, GlobalFunctions.FirstDateOfMonth(assignDate),
GlobalFunctions.LastDateOfMonth(assignDate), wpGroupID);
return tc.ExecuteReader(sql);
}
internal static IDataReader NotYetAssigned(TransactionContext tc, int payrollTypeID)
{
//string sql = SQLParser.MakeSQL("SELECT * FROM EmployeeWorkPlanSetup WHERE "
// + "EmployeeID NOT IN(select EmployeeID FROM EMPLOYEE WHERE EMPLOYEE.STATUS =%n and EMPLOYEE.payrolltypeid=%n) "
// + " AND PayrollTypeID=%n"
// + ""
// , payrollTypeID, EnumEmployeeStatus.Live, payrollTypeID);
string sql = SQLParser.MakeSQL("SELECT * FROM EMPLOYEE WHERE "
+ "EmployeeID NOT IN(select EmployeeID FROM EmployeeWorkPlanSetup ewp WHERE ewp.payrolltypeid=%n) "
+ "AND EMPLOYEE.STATUS=%n AND EMPLOYEE.PayrollTypeID=%n"
+ ""
, payrollTypeID, EnumEmployeeStatus.Live, payrollTypeID);
return tc.ExecuteReader(sql);
}
internal static IDataReader getEmployeeWorkPlan(TransactionContext tc, string empID)
{
string sql = SQLParser.MakeSQL("SELECT * FROM EmployeeWorkPlanSetup WHERE EmployeeID IN (%q) ", empID);
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, int groupID, DayOfWeek weekEndOn)
{
bool isExist = false;
object obj =
tc.ExecuteScalar(
"SELECT Count(*) from EmployeeWorkPlanSetup Where WorkPlanGroupID=%n and (WeekEndOn=%n OR WeekEndOn2 = %n)",
groupID, weekEndOn, weekEndOn);
isExist = Convert.ToInt32(obj) > 0 ? true : false;
return isExist;
}
#endregion
#region Delete function
internal static void Delete(TransactionContext tc, int nID)
{
tc.ExecuteNonQuery("DELETE FROM [EmployeeWorkPlanSetup] WHERE EmployeeWorkPlanSetupID=%n", nID);
}
internal static void DeleteExistingData(TransactionContext tc, int employeeID)
{
tc.ExecuteNonQuery("DELETE FROM [EmployeeWorkPlanSetup] WHERE EmployeeID=%n", employeeID);
}
internal static void DeleteExistingData(TransactionContext tc, string employeeIDs)
{
tc.ExecuteNonQuery("DELETE FROM [EmployeeWorkPlanSetup] WHERE EmployeeID IN (%q)", employeeIDs);
}
internal static void Delete(TransactionContext tc, int groupID, DayOfWeek weekEndOn)
{
tc.ExecuteNonQuery(
"DELETE FROM [EmployeeWorkPlanSetup] WHERE WorkPlanGroupID=%n and (WeekEndOn=%n OR WeekEndOn2 = %n)",
groupID, weekEndOn, weekEndOn);
}
internal static void Delete(int groupID, TransactionContext tc)
{
tc.ExecuteNonQuery("DELETE FROM [EmployeeWorkPlanSetup] WHERE WorkPlanGroupID=%n", groupID);
}
internal static void DeleteByEmpID(TransactionContext tc, int employeeID)
{
tc.ExecuteNonQuery("DELETE FROM EmployeeWorkPlanSetup WHERE EMPLOYEEID = %n", employeeID);
}
#endregion
internal static IDataReader GetAll(TransactionContext tc)
{
return tc.ExecuteReader("SELECT * FROM EmployeeWorkPlanSetup");
}
internal static IDataReader GetUsingPayrollType(TransactionContext tc, int payrollTypeId)
{
return tc.ExecuteReader("SELECT * FROM EmployeeWorkPlanSetup Where PayrollTypeID=%n", payrollTypeId);
}
internal static IDataReader IsEmployeeExistIntheWrokPlan(TransactionContext tc, string empIn, int payrollTypeId)
{
return tc.ExecuteReader(@"SELECT emp.*, e.NAME, e.employeeNO, w.name AS workPlanGroupName FROM
EmployeeWorkPlanSetup emp Inner JOIN EMPLOYEE e
ON e.EMPLOYEEID = emp.EMPLOYEEID
Inner join WorkPlanGroup w
On w.WORKPLANGROUPID = emp.WORKPLANGROUPID
where emp.EmployeeID in(%q) and e.PayrollTypeID=%n", empIn, payrollTypeId);
}
internal static bool IsEmployeeExistInWorkplan(TransactionContext tc, int employeeid)
{
bool isExist = false;
object obj = tc.ExecuteScalar("SELECT Count(*) from EmployeeWorkPlanSetup Where EmployeeID=%n ",
employeeid);
isExist = Convert.ToInt32(obj) > 0 ? true : false;
return isExist;
}
}
#endregion
}