HRM-10/HRM.DA/DA/Attendance/AttnRawDataDA.cs
Mohaimen Hasan 838b8d4480 first commit
2026-11-03 13:06:00 +06:00

237 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 AttnRawDataDA
internal class AttnRawDataDA
{
#region Insert function
internal static void Insert(TransactionContext tc, AttnRawData item)
{
tc.ExecuteNonQuery(
"INSERT INTO AttnRawData(CardID, EmployeeID, CardNo, PunchTime,EntryMode,DeviceIPAddress,DeviceNo)" +
" VALUES(%n, %n, %s, %D, %n,%s,%s)", DataReader.GetNullValue((item.CardID), 0), item.EmployeeID,
item.CardNo, item.PunchTime, (int)item.EntryMode, item.DeviceIPAddress, item.DeviceNo);
}
#endregion
internal static IDataReader Get(TransactionContext tc, DateTime fromDate, DateTime toDate, int payrollTypeID)
{
//string sql = SQLParser.MakeSQL(
// "SELECT a.* FROM AttnRawData a Inner join Employee e on e.employeeID=a.employeeID WHERE a.PunchTime between %D AND %D and e.payrollTypeID=%n ORDER BY a.EmployeeID, a.PunchTime asc",
// fromDate, toDate, payrollTypeID);
//string sql = SQLParser.MakeSQL(
// "SELECT a.* FROM AttnRawData a Inner join Employee e on e.employeeID = a.employeeID"
// + " WHERE a.PunchTime between %D AND %D and e.payrollTypeID = %n"
// + " Union"
// + " SELECT null CardID, a.EmpID as EmployeeID, '' CardNo, a.PunchTime PunchTime, a.PunchType EntryMode, '' DeviceIPAddress, '' DeviceNo FROM AttnMobileRawData a "
// + " Inner join Employee e on e.employeeID = a.EmpID "
// + " WHERE a.PunchTime between %D AND %D ORDER BY EmployeeID, PunchTime asc",
// fromDate, toDate, payrollTypeID, fromDate, toDate);
//string sql = SQLParser.MakeSQL(
// "SELECT a.* FROM AttnRawData a "
// + " WHERE a.PunchTime between %D AND %D "
// + " Union"
// + " SELECT null CardID, a.EmpID as EmployeeID, '' CardNo, a.PunchTime PunchTime, a.PunchType EntryMode, '' DeviceIPAddress, '' DeviceNo FROM AttnMobileRawData a "
// + " Inner join Employee e on e.employeeID = a.EmpID "
// + " WHERE a.PunchTime between %D AND %D ORDER BY EmployeeID, PunchTime",
// fromDate, toDate, fromDate, toDate);
string sql = SQLParser.MakeSQL(
"SELECT a.* FROM AttnRawData a Inner join Employee e on e.employeeID = a.EmployeeID WHERE a.PunchTime between "
+ " %D AND %D ", fromDate, toDate);
tc.CommandTimeOut = 6000;
return tc.ExecuteReader(sql);
}
internal static IDataReader GetWithoutMobileRawData(TransactionContext tc, DateTime fromDate, DateTime toDate, int payrollTypeID)
{
string sql = SQLParser.MakeSQL("SELECT * FROM AttnRawData WHERE PunchTime between %D AND %D ORDER BY EmployeeID,PunchTime", fromDate, toDate);
return tc.ExecuteReader(sql);
}
internal static IDataReader Get(TransactionContext tc, DateTime fromDate, DateTime toDate, string empIDs,
int payrollTypeID)
{
string sql = string.Empty;
if (!string.IsNullOrEmpty(empIDs))
{
sql = SQLParser.MakeSQL(
"SELECT a.* FROM AttnRawData a Inner join Employee e on e.employeeID=a.employeeID WHERE a.PunchTime between %D AND %D and e.payrollTypeID=%n and a.employeeID in (%q) ORDER BY a.EmployeeID, a.PunchTime asc",
fromDate, toDate, payrollTypeID, empIDs);
}
else
{
sql = SQLParser.MakeSQL(
"SELECT a.* FROM AttnRawData a Inner join Employee e on e.employeeID=a.employeeID WHERE a.PunchTime between %D AND %D and e.payrollTypeID=%n ORDER BY a.EmployeeID, a.PunchTime asc",
fromDate, toDate, payrollTypeID, empIDs);
}
return tc.ExecuteReader(sql);
}
//internal static IDataReader Get(TransactionContext tc, DateTime fromDate, DateTime toDate, int payrollTypeID)
//{
// //string sql = SQLParser.MakeSQL("SELECT a.* FROM AttnRawData a Inner join Employee e on e.employeeID=a.employeeID Where e.payrollTypeID=%n and a.PunchTime between %D AND %D ORDER BY a.employeeID, a.PunchTime asc", payrollTypeID, fromDate, toDate);
// string sql = SQLParser.MakeSQL("SELECT e.EmployeeID, a.* FROM DAILYATTNRAWDATA a Inner join Employee e on e.employeeNo=a.employeeNo WHERE a.PunchTime between %D AND %D and e.payrollTypeID=%n ORDER BY a.employeeNo, a.PunchTime asc", fromDate, toDate, payrollTypeID);
// return tc.ExecuteReader(sql);
//}
internal static DataSet GetDataFromClientSqlDB(TransactionContext tc, DateTime maxPunchDate)
{
DataSet rawData = new DataSet();
try
{
string sql = string.Empty;
if (maxPunchDate == DateTime.MinValue)
{
maxPunchDate = new DateTime(2017, 5, 20);
}
sql = SQLParser.MakeSQL(
@"Select bd.punch_date PunchTime, bd.card_no CardNo, bd.terminal MachineNo, bd.reader EntryMode from Badge_Data bd where bd.punch_date > %D and bd.card_no <> '' and bd.card_no is not null order by punch_date asc",
maxPunchDate);
rawData = tc.ExecuteDataSet(sql);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
return rawData;
}
internal static void Delete(TransactionContext tc, DateTime fromTime, string empIDs)
{
tc.ExecuteNonQuery("DELETE FROM AttnRawData WHERE PunchTime>=%D and EmployeeID in (%q)", fromTime, empIDs);
}
internal static DataSet GetInOutData(TransactionContext tc, DateTime startDate, DateTime endDate,
int employeeID)
{
DataSet rawData = new DataSet();
try
{
string sql = SQLParser.MakeSQL(
@"SELECT COALESCE(InTable.EmployeeID,OutTable.EmployeeID) EmployeeID,COALESCE(InTable.WorkingDate,OutTable.WorkingDate) AttnDate,InTime,OutTime from
(SELECT ard.EmployeeID,Max(CAST(ard.PunchTime AS DATE)) WorkingDate, MIN(ard.PunchTime) InTime
FROM AttnRawData ard WHERE ard.EmployeeID=%n AND entryMode=1 AND CAST(ard.PunchTime AS DATE) BETWEEN %d AND %d GROUP BY CAST(ard.PunchTime AS DATE),EmployeeID) as InTable
Full OUTER JOIN
( SELECT ard.EmployeeID,Max(CAST(ard.PunchTime AS DATE)) WorkingDate, MAX(ard.PunchTime) OutTime
FROM AttnRawData ard WHERE ard.EmployeeID=%n AND entryMode=2 AND CAST(ard.PunchTime AS DATE) BETWEEN %d AND %d GROUP BY CAST(ard.PunchTime AS DATE),EmployeeID) as OutTable
ON
InTable.WorkingDate=OutTable.WorkingDate", employeeID, startDate, endDate, employeeID, startDate,
endDate);
rawData = tc.ExecuteDataSet(sql);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
return rawData;
}
internal static DataSet GetWorkHourData(TransactionContext tc, DateTime startDate, DateTime endDate, string empIDs)
{
DataSet rawData = new DataSet();
try
{
string sql = SQLParser.MakeSQL(@"SELECT * FROM vw_AttnRawDataWorkHour where EmployeeID in (%q) and PunchDate >= %d AND PunchDate <= %d", empIDs, startDate, endDate);
rawData = tc.ExecuteDataSet(sql);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
return rawData;
}
internal static DataSet GetAttnProcessWorkHourData(TransactionContext tc, string attnDate)
{
DataSet rawData = new DataSet();
try
{
string sql = SQLParser.MakeSQL(@"SELECT dap.*, e.EMPLOYEENO, e.NAME EmployeeName FROM DailyAttnProcess dap
inner join Employee e on e.employeeid=dap.employeeid
WHERE dap.AttnDate = %D
--AND workhour <=5
--AND attenType != 2
and e.payrolltypeid = 1
Order by e.employeeNo", attnDate);
rawData = tc.ExecuteDataSet(sql);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
return rawData;
}
internal static IDataReader GetDailyAttnByAttnTypeAndDateRange(TransactionContext tc, DateTime fromdate, DateTime todate, EnumAttendanceType enumAttendanceType)
{
try
{
string sql = SQLParser.MakeSQL(
"Select * from DailyAttnProcess where AttnDate BETWEEN %d AND %d AND (AttenType=%n or ISLATE=1)",
fromdate, todate, enumAttendanceType);
return tc.ExecuteReader(sql);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
internal static DataSet GetWorkHourSummeryByDateRangeData(TransactionContext tc, string fromDate, string toDate)
{
DataSet rawData = new DataSet();
try
{
string sql = SQLParser.MakeSQL(@"SELECT
dap.EMPLOYEEID,
e.EMPLOYEENO,
e.NAME AS EmployeeName,
COUNT(CASE WHEN dap.workhour <= 5 THEN 1 END) AS LateDays,
(COUNT(CASE WHEN dap.workhour <= 5 THEN 1 END)/3) AS LeaveDeducts
FROM DailyAttnProcess dap
INNER JOIN Employee e
ON e.employeeid = dap.employeeid
WHERE dap.AttnDate BETWEEN %d AND %d
and WorkDayType =3
and attenType in (1,3,11,12)
AND e.payrolltypeid = 1
GROUP BY
dap.EMPLOYEEID,
e.EMPLOYEENO,
e.NAME
ORDER BY
e.employeeNo", fromDate, toDate);
rawData = tc.ExecuteDataSet(sql);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
return rawData;
}
}
#endregion
}