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

192 lines
8.4 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ease.CoreV35.DataAccess;
using System.Data;
using HRM.BO;
using Ease.Core.DataAccess;
namespace HRM.DA
{
#region MonthlyWorkPlanDA
internal class MonthlyWorkPlanDA
{
#region Constructor
private MonthlyWorkPlanDA()
{
}
#endregion
#region Insert function
internal static void Insert(TransactionContext tc, MonthlyWorkPlan item)
{
tc.ExecuteNonQuery(
"INSERT INTO MonthlyWorkPlan(MonthlyWorkPlanID, DaySerial, WorkDate, ShiftID, HolidayID, CreatedBy, CreatedDate,Type,WorkPlanGroupID, PayrollTypeID)" +
" VALUES(%n, %n, %d, %n, %n, %n, %d, %n, %n, %n)", item.ID, item.DaySerial, item.WorkDate, item.ShiftID,
DataReader.GetNullValue(item.HolidayID, 0), item.CreatedBy, item.CreatedDate, item.Type,
DataReader.GetNullValue(item.WorkPlanGroupID, 0), item.payrollTypeID);
}
#endregion
#region Update function
internal static void Update(TransactionContext tc, MonthlyWorkPlan item)
{
tc.ExecuteNonQuery(
"UPDATE MonthlyWorkPlan SET DaySerial=%n, WorkDate=%d, ShiftID=%n, HolidayID=%n, ModifiedBy=%n, ModifiedDate=%d, Type=%n, WorkPlanGroupID=%n" +
" WHERE MonthlyWorkPlanID=%n", item.DaySerial, item.WorkDate, DataReader.GetNullValue(item.ShiftID),
DataReader.GetNullValue(item.HolidayID, 0), item.ModifiedBy, item.ModifiedDate, item.Type,
DataReader.GetNullValue(item.WorkPlanGroupID), item.ID);
}
internal static void UpdateShiftAndRoster(TransactionContext tc, MonthlyWorkPlan item)
{
tc.ExecuteNonQuery(
"UPDATE MonthlyWorkPlan SET ShiftID=%n, ModifiedBy=%n, ModifiedDate=%D" +
" WHERE WorkPlanGroupID=%n AND WorkDate=%d and PayrollTypeID=%n", DataReader.GetNullValue(item.ShiftID),
item.ModifiedBy, item.ModifiedDate,
DataReader.GetNullValue(item.WorkPlanGroupID), item.WorkDate, item.payrollTypeID);
}
#endregion
#region Get Function
//internal static IDataReader GetMonthlyDataByEmp(TransactionContext tc, DateTime dAssDate,
// EnumWorkPlanGroup type, int nEmpiD)
//{
// return tc.ExecuteReader(
// "SELECT * FROM MonthlyWorkPlan Where WorkDate BETWEEN %d AND %d and Type=%n And EmployeeID=%n",
// GlobalFunctions.AttendanceMonthStart(dAssDate), GlobalFunctions.AttendanceMonthEnd(dAssDate), type,
// nEmpiD);
//}
internal static IDataReader GetMonthlyDataByEmp(TransactionContext tc, DateTime fromDate, DateTime toDate,
EnumWorkPlanGroup type, int nEmpiD, int workPlanGroupID)
{
return tc.ExecuteReader(
"SELECT * FROM MonthlyWorkPlan Where WorkDate BETWEEN %d AND %d and Type=%n And EmployeeID=%n and workPlanGroupID=%n ORDER BY workdate desc",
fromDate, toDate, type, nEmpiD, workPlanGroupID);
}
internal static IDataReader Get(TransactionContext tc, DateTime fromDate, DateTime todate, int PayrollTypeID)
{
DateTime firstDate = GlobalFunctions.FirstDateOfMonth(fromDate);
DateTime lastDate = GlobalFunctions.LastDateOfMonth(todate);
return tc.ExecuteReader(
"SELECT * FROM MonthlyWorkPlan WHERE WorkDate BETWEEN %d and %d AND PAYROLLTYPEID=%n", firstDate,
lastDate, PayrollTypeID);
}
internal static IDataReader GetByDate(TransactionContext tc, DateTime attnDate, int payrolltypeid)
{
return tc.ExecuteReader("SELECT * FROM MonthlyWorkPlan WHERE WorkDate =%d and payrollTypeID=%n", attnDate, payrolltypeid);
}
internal static IDataReader Get(TransactionContext tc, DateTime attnMonth, int payrolltypeID)
{
return tc.ExecuteReader("SELECT * FROM MonthlyWorkPlan WHERE WorkDate between %d and %d and payrollTypeID=%n",
attnMonth.FirstDateOfMonth(), attnMonth.LastDateOfMonth(), payrolltypeID);
}
internal static DateTime GetLastSavedWorkDate(TransactionContext tc, int payrollTypeID)
{
var obj = tc.ExecuteScalar("SELECT Max(WorkDate) FROM MonthlyWorkPlan where payrollTypeID=%n", payrollTypeID);
return obj == DBNull.Value ? DateTime.MinValue : (DateTime)obj;
}
internal static IDataReader GetByDateAndGroupID(TransactionContext tc, DateTime dAssDate, int groupID)
{
return tc.ExecuteReader(
"SELECT * FROM MonthlyWorkPlan Where WorkDate BETWEEN %d AND %d and WorkPlanGroupID=%n",
GlobalFunctions.FirstDateOfMonth(dAssDate), GlobalFunctions.LastDateOfMonth(dAssDate), groupID);
}
internal static IDataReader Get(TransactionContext tc, int PayrollTypeID)
{
return tc.ExecuteReader("SELECT * FROM MonthlyWorkPlan Where PayrollTypeID=%n Order by Workdate asc",
PayrollTypeID);
}
internal static IDataReader GetByEmpID(TransactionContext tc, int nEmpID, DateTime assDate,
EnumWorkPlanGroup type)
{
if (type == EnumWorkPlanGroup.Counter_Clock_1 || type == EnumWorkPlanGroup.Fixed)
{
return tc.ExecuteReader("SELECT * FROM MonthlyWorkPlan WHERE EmployeeID=%n AND WorkDate=%d AND Type=%n",
nEmpID, assDate, type);
}
else
{
return tc.ExecuteReader(
"SELECT * FROM MonthlyWorkPlan WHERE EmployeeID=%n AND WorkDate=%d AND Type Not in(%n,%n)", nEmpID,
assDate, EnumWorkPlanGroup.Counter_Clock_1, EnumWorkPlanGroup.Fixed);
}
}
internal static IDataReader GetByEmpID(TransactionContext tc, int nEmpID, DateTime workDate)
{
return tc.ExecuteReader("SELECT * FROM MonthlyWorkPlan WHERE EmployeeID=%n AND WorkDate=%d ", nEmpID,
workDate);
}
#endregion
internal static IDataReader GetByPayrollTypeID(TransactionContext tc, DateTime fromDate, DateTime todate,
int payrollTypeID)
{
DateTime firstDate = GlobalFunctions.FirstDateOfMonth(fromDate);
DateTime lastDate = GlobalFunctions.LastDateOfMonth(todate);
return tc.ExecuteReader(
"SELECT * FROM MonthlyWorkPlan WHERE WorkDate BETWEEN %d and %d AND PAYROLLTYPEID=%n", firstDate,
lastDate, payrollTypeID);
}
internal static IDataReader GetByDateAndPayrollType(TransactionContext tc, DateTime attnDate, int payrollTypeID)
{
return tc.ExecuteReader("SELECT * FROM MonthlyWorkPlan WHERE WorkDate =%d AND PAYROLLTYPEID=%n", attnDate,
payrollTypeID);
}
internal static void Delete(TransactionContext tc, DateTime fromDate, int payrolltypeid)
{
tc.ExecuteNonQuery("DELETE FROM MonthlyWorkPlan WHERE WorkDate >=%d and payrolltypeid=%n", fromDate, payrolltypeid);
}
internal static void Delete(TransactionContext tc, DateTime startDate, DateTime endDate, int payrollTypeID)
{
tc.ExecuteNonQuery("DELETE FROM MonthlyWorkPlan WHERE WorkDate>= %d and WorkDate <= %d and payrollTypeID=%n", startDate,
endDate, payrollTypeID);
}
//internal static void Delete(TransactionContext tc, DateTime assignDate, string empIDs)
//{
// tc.ExecuteNonQuery("DELETE FROM MonthlyWorkPlan WHERE WorkDate BETWEEN %d AND %d AND EmployeeID IN(%q)",
// GlobalFunctions.AttendanceMonthStart(assignDate), GlobalFunctions.AttendanceMonthEnd(assignDate),
// empIDs);
//}
internal static bool IsExist(TransactionContext tc, DateTime dAssDate, int groupID)
{
bool isExist = false;
string sql =
SQLParser.MakeSQL(
@"SELECT Count(*) from MonthlyWorkPlan Where WorkDate BETWEEN %d AND %d and WorkPlanGroupID=%n ",
GlobalFunctions.FirstDateOfMonth(dAssDate), GlobalFunctions.LastDateOfMonth(dAssDate), groupID);
object obj = tc.ExecuteScalar(sql);
if (obj == DBNull.Value) return false;
isExist = Convert.ToInt32(obj) > 0 ? true : false;
return isExist;
}
}
#endregion
}