1260 lines
68 KiB
C#
1260 lines
68 KiB
C#
|
using HRM.BO;
|
||
|
using Ease.Core.DataAccess;
|
||
|
using System;
|
||
|
using System.Data;
|
||
|
using Microsoft.Data.SqlClient;
|
||
|
|
||
|
namespace HRM.DA
|
||
|
{
|
||
|
class LeaveEntryDA
|
||
|
{
|
||
|
#region Constructor
|
||
|
|
||
|
public LeaveEntryDA()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
#region Insert function
|
||
|
|
||
|
public static void Insert(TransactionContext tc, LeaveEntry oItem)
|
||
|
{
|
||
|
oItem.ApprovedLeaveDate = oItem.AppliedLeaveDate;
|
||
|
oItem.ApprovedFromDate = oItem.AppliedFromDate;
|
||
|
oItem.ApprovedToDate = oItem.AppliedToDate;
|
||
|
|
||
|
string sSQL = SQLParser.MakeSQL(@"INSERT INTO LEAVEENTRY
|
||
|
(
|
||
|
LEAVEID, ENTRYDATE, ISDRAFTED, ISAVAILED,
|
||
|
LEAVESTATUS, DAYPERIOD, TRANID, EMPID,
|
||
|
EMPGRADEID, LEAVEYEAR, APPPARAMID, APPLEAVEDATE,
|
||
|
|
||
|
APPFROMDATE, APPTODATE, APPTOTALDAYS, APRPARAMID,
|
||
|
APRLEAVEDATE, APRFROMDATE, APRTODATE, APRTOTALDAYS,
|
||
|
APPROVEDBY, REMARKS, USERID, WORKINGDATE,
|
||
|
|
||
|
ERNLEAVEREMARKS, SBUID, DEPARTMENTID, FUNCTIONID,
|
||
|
LOCATIONID, DESIGNATIONID, AVAILFROMDATE, AVAILTODATE,
|
||
|
AVAILREMARKS, AVAILEDBY, AVAILTOTALDAYS, LFAAMOUNT,
|
||
|
|
||
|
APPLIEDLEAVEID, LFASMOKINGAMOUNT, SALARYMONTH, LEAVEAGAINSTDATE,
|
||
|
COMPENSATORYLEAVEFOR, ITEMID, OTVALUE, LEAVEDAYPERIOD,
|
||
|
ResponsiblePersonID, IsHalfday, FromHalf, ToHalf,
|
||
|
ContactNumber, AddressDuringLeave, IsLFA, SelectedHalf, CompensatoryDate
|
||
|
)
|
||
|
VALUES
|
||
|
(
|
||
|
%n, %d, %b, %b,
|
||
|
%n, %n, %n, %n,
|
||
|
%n, %n, %n, %d,
|
||
|
|
||
|
%d, %d, %n, %n,
|
||
|
%d, %d, %d, %n,
|
||
|
%n, %s, %n, %d,
|
||
|
|
||
|
%s, %n, %n, %n,
|
||
|
%n, %n, %d, %d,
|
||
|
%s, %n, %n, %n,
|
||
|
|
||
|
%n, %n, %d, %d,
|
||
|
%n, %n, %n, %s,
|
||
|
%n, %b, %b, %b,
|
||
|
|
||
|
%s, %s, %b, %n, %d
|
||
|
)",
|
||
|
DataReader.GetNullValue(oItem.LeaveID), DataReader.GetNullValue(oItem.EntryDate),
|
||
|
oItem.IsDrafted, oItem.IsAvailed,
|
||
|
oItem.LeaveStatus, DataReader.GetNullValue(oItem.DayPeriod), oItem.ID, oItem.EmpID,
|
||
|
oItem.EmpGradeId, DataReader.GetNullValue(oItem.LeaveYearId),
|
||
|
DataReader.GetNullValue(oItem.AppliedParamId), DataReader.GetNullValue(oItem.AppliedLeaveDate),
|
||
|
DataReader.GetNullValue(oItem.AppliedFromDate), DataReader.GetNullValue(oItem.AppliedToDate),
|
||
|
DataReader.GetNullValue(oItem.AppliedTotalDays), DataReader.GetNullValue(oItem.ApprovedParamId),
|
||
|
DataReader.GetNullValue(oItem.ApprovedLeaveDate), DataReader.GetNullValue(oItem.ApprovedFromDate),
|
||
|
DataReader.GetNullValue(oItem.ApprovedToDate), DataReader.GetNullValue(oItem.ApprovedTotalDays),
|
||
|
DataReader.GetNullValue(oItem.ApprovedBy), DataReader.GetNullValue(oItem.Remarks),
|
||
|
DataReader.GetNullValue(oItem.CreatedBy), DataReader.GetNullValue(oItem.WorkingDate),
|
||
|
DataReader.GetNullValue(oItem.ErnLeaveRemarks), DataReader.GetNullValue(oItem.SbuID),
|
||
|
DataReader.GetNullValue(oItem.DepartmentID), DataReader.GetNullValue(oItem.FunctionID),
|
||
|
DataReader.GetNullValue(oItem.LocationID), DataReader.GetNullValue(oItem.DesignationID),
|
||
|
DataReader.GetNullValue(oItem.AvailFromDate), DataReader.GetNullValue(oItem.AvailToDate),
|
||
|
DataReader.GetNullValue(oItem.AvailRemarks), DataReader.GetNullValue(oItem.AvailedBy),
|
||
|
DataReader.GetNullValue(oItem.AvailTotalDays), DataReader.GetNullValue(oItem.LFAAmount),
|
||
|
DataReader.GetNullValue(oItem.AppliedLeaveID), DataReader.GetNullValue(oItem.LFASmokingAmount),
|
||
|
DataReader.GetNullValue(oItem.SalaryMonth), DataReader.GetNullValue(oItem.LeaveAgainstDate),
|
||
|
oItem.CompensatoryLeaveFor, DataReader.GetNullValue(oItem.ItemId),
|
||
|
DataReader.GetNullValue(oItem.OtValue), DataReader.GetNullValue(oItem.LeaveDayPeriod),
|
||
|
DataReader.GetNullValue(oItem.ResponsiblePersonID), oItem.IsHalfday, DataReader.GetNullValue(oItem.FromHalf),
|
||
|
DataReader.GetNullValue(oItem.ToHalf),
|
||
|
DataReader.GetNullValue(oItem.ContactNumber), DataReader.GetNullValue(oItem.AddressDuringLeave), oItem.isLFA, (int)oItem.SelectedHalf, oItem.CompensatoryDate);
|
||
|
|
||
|
tc.ExecuteNonQuery(sSQL);
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
public static void Insert(LeaveAttachment item, string connectionString)
|
||
|
{
|
||
|
// string ConnString = ConfigurationSettings.AppSettings["default"];
|
||
|
// var ConnString = System.Configuration.ConfigurationManager.GetSection("dbSettings");
|
||
|
// string ConnString=ConfigurationManager.ConnectionStrings[connectionString].ConnectionString;
|
||
|
using (SqlConnection connection = new SqlConnection(connectionString))
|
||
|
{
|
||
|
connection.Open();
|
||
|
SqlCommand cmd = new SqlCommand();
|
||
|
cmd.Connection = connection;
|
||
|
string commandText = @"INSERT INTO LEAVEATTACHMENT(LEAVEENTRYID, ATTACHMENTPATH, FILEDATA,ORIGINALFILENAME,FILETYPE) Values (@LEAVEENTRYID,@ATTACHMENTPATH,@FILEDATA,@ORIGINALFILENAME,@FILETYPE)";
|
||
|
cmd.CommandText = commandText;
|
||
|
cmd.CommandType = CommandType.Text;
|
||
|
cmd.Parameters.Add("@LEAVEENTRYID", SqlDbType.Int);
|
||
|
cmd.Parameters["@LEAVEENTRYID"].Value = item.LeaveEntryID;
|
||
|
|
||
|
cmd.Parameters.Add("@ORIGINALFILENAME", SqlDbType.VarChar);
|
||
|
cmd.Parameters["@ORIGINALFILENAME"].Value = item.OriginalFileName;
|
||
|
|
||
|
cmd.Parameters.Add("@FILEDATA", SqlDbType.VarBinary);
|
||
|
cmd.Parameters["@FILEDATA"].Value = item.FileAsByteArray;
|
||
|
|
||
|
cmd.Parameters.Add("@FILETYPE", SqlDbType.Int);
|
||
|
cmd.Parameters["@FILETYPE"].Value = (int)item.FileType;
|
||
|
|
||
|
cmd.Parameters.Add("@ATTACHMENTPATH", SqlDbType.VarChar);
|
||
|
cmd.Parameters["@ATTACHMENTPATH"].Value = item.AttachmentPath == null ? string.Empty : item.AttachmentPath;
|
||
|
|
||
|
cmd.ExecuteNonQuery();
|
||
|
cmd.Dispose();
|
||
|
|
||
|
connection.Close();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static DataSet GetPendingJobDetail(TransactionContext tc, int id)
|
||
|
{
|
||
|
DataSet dataSet = null;
|
||
|
string sql = SQLParser.MakeSQL(@"select ISNULL(e.Name, '') Applier, ISNULL(lv.Description, '') Leave,
|
||
|
FORMAT(APPFromDate,'dd MMM yyyy') FromDate,
|
||
|
FORMAT(APPToDate,'dd MMM yyyy') ToDate,
|
||
|
APPTotalDays TotalDays, Remarks
|
||
|
from Leaveentry le
|
||
|
Left Join Employee e
|
||
|
on e.EmployeeID = le.EmpID
|
||
|
Left Join Leave lv
|
||
|
on lv.LeaveID = le.LeaveID
|
||
|
Where TranID = %n ", id);
|
||
|
dataSet = tc.ExecuteDataSet(sql);
|
||
|
return dataSet;
|
||
|
}
|
||
|
|
||
|
internal static void Insert(TransactionContext tc, LeaveAttachment item)
|
||
|
{
|
||
|
string sql = SQLParser.MakeSQL(
|
||
|
@"Insert into LeaveAttachment (LeaveAttachmentID, LeaveEntryID, AttachmentPath)
|
||
|
Values(%n, %n, %s)", item.ID, item.LeaveEntryID, item.AttachmentPath);
|
||
|
tc.ExecuteNonQuery(sql);
|
||
|
}
|
||
|
|
||
|
public static void UpdateLeaveStatusLiFung(TransactionContext tc, LeaveEntry oItem)
|
||
|
{
|
||
|
tc.ExecuteNonQuery(@"
|
||
|
UPDATE LEAVEENTRY SET LEAVESTATUS = 11
|
||
|
WHERE EMPID = %n AND APRFROMDATE = %d AND APRTODATE = %d and leaveid =%n
|
||
|
", oItem.EmpID, DataReader.GetNullValue(oItem.ApprovedFromDate),
|
||
|
DataReader.GetNullValue(oItem.ApprovedToDate), oItem.LeaveID);
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
#region Update function
|
||
|
|
||
|
public static void Update(TransactionContext tc, LeaveEntry oItem)
|
||
|
{
|
||
|
string sql = SQLParser.MakeSQL("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,LocationID=%n,DesignationID=%n,AvailFromDate=%d,AvailToDate=%d,AvailTotalDays=%n,AvailRemarks=%s,AvailedBy=%n,LFAAmount=%n,LFASmokingAmount=%n,SalaryMonth=%d,AppliedLeaveID=%n, leaveAgainstDate =%d, compensatoryLeaveFor =%n, ItemId =%n, otValue =%n, DAYPERIOD =%n, LeaveDayPeriod =%s, ResponsiblePersonID=%n, isLFA=%n, selectedHalf = %n, IsHalfday = %n, CompensatoryDate=%d" +
|
||
|
" WHERE TranId=%n", oItem.EmpID, oItem.EmpGradeId, oItem.LeaveYearId, oItem.AppliedParamId,
|
||
|
oItem.AppliedLeaveDate, oItem.AppliedFromDate, oItem.AppliedToDate, oItem.AppliedTotalDays,
|
||
|
oItem.ApprovedParamId, oItem.ApprovedLeaveDate, oItem.ApprovedFromDate, oItem.ApprovedToDate,
|
||
|
oItem.ApprovedTotalDays, DataReader.GetNullValue(oItem.ApprovedBy), oItem.Remarks, oItem.EntryDate,
|
||
|
oItem.IsDrafted, oItem.IsAvailed, (int)oItem.LeaveStatus,
|
||
|
oItem.ErnLeaveRemarks, DataReader.GetNullValue(oItem.LeaveID),
|
||
|
DataReader.GetNullValue(oItem.DepartmentID), DataReader.GetNullValue(oItem.LocationID),
|
||
|
DataReader.GetNullValue(oItem.DesignationID), DataReader.GetNullValue(oItem.AvailFromDate),
|
||
|
DataReader.GetNullValue(oItem.AvailToDate), oItem.AvailTotalDays, oItem.AvailRemarks.Trim(),
|
||
|
DataReader.GetNullValue(oItem.AvailedBy), oItem.LFAAmount, oItem.LFASmokingAmount,
|
||
|
DataReader.GetNullValue(oItem.SalaryMonth),
|
||
|
DataReader.GetNullValue(oItem.AppliedLeaveID), DataReader.GetNullValue(oItem.LeaveAgainstDate),
|
||
|
oItem.CompensatoryLeaveFor,
|
||
|
oItem.ItemId, oItem.OtValue, oItem.DayPeriod, oItem.LeaveDayPeriod,
|
||
|
DataReader.GetNullValue(oItem.ResponsiblePersonID), oItem.isLFA, (int)oItem.SelectedHalf, oItem.IsHalfday, oItem.CompensatoryDate, oItem.ID);
|
||
|
tc.ExecuteNonQuery(sql);
|
||
|
|
||
|
}
|
||
|
|
||
|
public static void UpdateLeaveStatus(TransactionContext tc, int tranid, EnumLeaveStatus status)
|
||
|
{
|
||
|
tc.ExecuteNonQuery("UPDATE LeaveEntry SET LEAVESTATUS=%n WHERE TranId=%n", status, tranid);
|
||
|
}
|
||
|
|
||
|
#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 GetLeaveEntries(TransactionContext tc, int empId, int leaveYearID)
|
||
|
{
|
||
|
//return tc.ExecuteReader("SELECT * from LeaveEntry where EMPID=%n AND LEAVEYEAR=%n", empId, leaveYearID);
|
||
|
return tc.ExecuteReader("SELECT l.Code description, le.* FROM Leaveentry le Inner Join LEAVE l On le.LEAVEID=l.LEAVEID where EMPID=%n AND LEAVEYEAR=%n", empId, leaveYearID);
|
||
|
}
|
||
|
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, int empId, DateTime fromDate, DateTime toDate, int LeaveStatus)
|
||
|
{
|
||
|
string sql = string.Empty;
|
||
|
sql = SQLParser.MakeSQL(@"SELECT * FROM LEAVEENTRY WHERE LEAVEID = 5 AND EMPID = %n
|
||
|
AND APRFROMDATE BETWEEN %d AND %d
|
||
|
AND APRTODATE BETWEEN %d AND %d AND LEAVESTATUS = 6", empId, fromDate, toDate, fromDate, toDate);
|
||
|
|
||
|
|
||
|
return tc.ExecuteReader(sql);
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
public static IDataReader Get(TransactionContext tc, int? employeeid, string EmpIds, int? leaveYearid,
|
||
|
int? leaveid,
|
||
|
DateTime? fromDate, DateTime? toDate, EnumLeaveStatus? leaveStatus, bool? isLfa)
|
||
|
{
|
||
|
string sqlClause = string.Empty;
|
||
|
|
||
|
if (employeeid == null && EmpIds == string.Empty)
|
||
|
{
|
||
|
throw new Exception("both EmployeeID and EmpIds are empty, please provide one of them");
|
||
|
}
|
||
|
sqlClause = " where le.LeaveID=l.LeaveID ";
|
||
|
if (fromDate != DateTime.MinValue && fromDate != null && toDate != null)
|
||
|
{
|
||
|
sqlClause = SQLParser.TagSQL(sqlClause) + SQLParser.MakeSQL("le.AprFromDate between %d and %d", fromDate, toDate);
|
||
|
}
|
||
|
|
||
|
if (leaveid != null)
|
||
|
{
|
||
|
sqlClause = SQLParser.TagSQL(sqlClause) + SQLParser.MakeSQL("le.leaveid = %n", leaveid);
|
||
|
}
|
||
|
|
||
|
if (leaveYearid != null)
|
||
|
{
|
||
|
sqlClause = SQLParser.TagSQL(sqlClause) + SQLParser.MakeSQL("le.LEAVEYEAR = %n", leaveYearid);
|
||
|
}
|
||
|
|
||
|
if (employeeid != null)
|
||
|
{
|
||
|
sqlClause = SQLParser.TagSQL(sqlClause) + SQLParser.MakeSQL("le.EmpID = %n", employeeid);
|
||
|
}
|
||
|
|
||
|
if (EmpIds != string.Empty)
|
||
|
{
|
||
|
sqlClause = SQLParser.TagSQL(sqlClause) + SQLParser.MakeSQL("le.EmpID in(%s)", EmpIds);
|
||
|
}
|
||
|
|
||
|
if (leaveStatus == EnumLeaveStatus.Regardless)
|
||
|
{
|
||
|
sqlClause = SQLParser.TagSQL(sqlClause) + SQLParser.MakeSQL("le.status = %n", leaveStatus);
|
||
|
}
|
||
|
|
||
|
string sql = SQLParser.MakeSQL(@"SELECT le.*, l.description FROM LeaveEntry le, leave l %q order by AprFromDate desc, --leavestatus desc
|
||
|
CASE
|
||
|
WHEN leavestatus = 1 THEN 1 --OnApproval
|
||
|
WHEN leavestatus = 3 THEN 2 --Reverted
|
||
|
WHEN leavestatus = 4 THEN 3 --Declined
|
||
|
WHEN leavestatus = 9 THEN 4 --Cancel_Request
|
||
|
WHEN leavestatus = 10 THEN 5 --Cancel
|
||
|
WHEN leavestatus = 11 THEN 6 --Cancelled_by_user
|
||
|
WHEN leavestatus = 5 THEN 7 --Availed
|
||
|
WHEN leavestatus = 6 THEN 8 --Approved
|
||
|
ELSE 0
|
||
|
END DESC;", sqlClause);
|
||
|
|
||
|
return tc.ExecuteReader(sql);
|
||
|
}
|
||
|
|
||
|
public static IDataReader Get(TransactionContext tc, string empIds, int leaveYear, int LeaveStatus)
|
||
|
{
|
||
|
string inSQL = "where " +
|
||
|
" LeaveEntry.leaveid= Leave.leaveid";
|
||
|
if (empIds != string.Empty)
|
||
|
{
|
||
|
inSQL = SQLParser.TagSQL(inSQL) + SQLParser.MakeSQL(" EmpId IN ( %q )", empIds);
|
||
|
|
||
|
}
|
||
|
if (LeaveStatus == 0)
|
||
|
return tc.ExecuteReader(
|
||
|
"SELECT LeaveEntry.*, Leave.Description FROM LeaveEntry, Leave where 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 %q and leaveyear=%n" +
|
||
|
" and LeaveStatus=%n AND APPTOTALDAYS<>0 order by AppFromDate DESC",
|
||
|
inSQL, leaveYear, LeaveStatus);
|
||
|
}
|
||
|
|
||
|
public static IDataReader Get(TransactionContext tc, string empIds, int leaveYear, int leaveId, int LeaveStatus, DateTime leaveFromMonth, DateTime leaveToMonth)
|
||
|
{
|
||
|
string inSQL = "";
|
||
|
inSQL = "in (" + empIds + ")";
|
||
|
|
||
|
string sqlClause = " ";
|
||
|
sqlClause = SQLParser.MakeSQL(" LeaveYear=%n", leaveYear);
|
||
|
|
||
|
if(empIds !=string.Empty)
|
||
|
{
|
||
|
sqlClause = SQLParser.TagSQL(sqlClause) + SQLParser.MakeSQL(" EmpId %q", inSQL);
|
||
|
|
||
|
}
|
||
|
|
||
|
if (leaveId != 0)
|
||
|
{
|
||
|
sqlClause = SQLParser.TagSQL(sqlClause) + SQLParser.MakeSQL(" LEAVEID=%n", leaveId);
|
||
|
|
||
|
}
|
||
|
string sql = SQLParser.MakeSQL(@"SELECT * FROM LeaveEntry
|
||
|
where %q
|
||
|
and LeaveStatus=%n AND APPTOTALDAYS<>0
|
||
|
AND (APPFROMDATE BETWEEN %d AND %d OR APPTODATE BETWEEN %d AND %d) order by AppFromDate DESC",
|
||
|
sqlClause, LeaveStatus,
|
||
|
leaveFromMonth.FirstDateOfMonth(), leaveToMonth.LastDateOfMonth(),
|
||
|
leaveFromMonth.FirstDateOfMonth(), leaveToMonth.LastDateOfMonth());
|
||
|
return tc.ExecuteReader(sql);
|
||
|
}
|
||
|
public static double GetLeaveExceptionAmtByType(TransactionContext tc, int empId, int leaveId, LeaveException oLeaveEx, int leaveStatus)
|
||
|
{
|
||
|
|
||
|
object ob = DBNull.Value;
|
||
|
if ((EnumLeaveStatus)leaveStatus == EnumLeaveStatus.Approved)
|
||
|
{
|
||
|
ob = tc.ExecuteScalar("SELECT sum(APPTOTALDAYS) FROM LeaveEntry where EmpId=%n and LeaveID=%n and LeaveStatus =%n AND APRFROMDATE BETWEEN %d AND %d AND APPTOTALDAYS<>0", empId, leaveId, leaveStatus, oLeaveEx.StartDate, oLeaveEx.EndDate);
|
||
|
return ob == DBNull.Value ? 0 : Convert.ToDouble(ob);
|
||
|
}
|
||
|
if (leaveStatus == 0)
|
||
|
{
|
||
|
ob = tc.ExecuteScalar("SELECT sum(APPTOTALDAYS) FROM LeaveEntry where EmpId=%n and LeaveID=%n AND APRFROMDATE BETWEEN %d AND %d AND APPTOTALDAYS<>0", empId, leaveId, oLeaveEx.StartDate, oLeaveEx.EndDate);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
ob = tc.ExecuteScalar("SELECT sum(APPTOTALDAYS) FROM LeaveEntry where EmpId=%n and LeaveID=%n and LeaveStatus =%n AND APRFROMDATE BETWEEN %d AND %d AND APPTOTALDAYS<>0", empId, leaveId, (int)EnumLeaveStatus.Approved, oLeaveEx.StartDate, oLeaveEx.EndDate);
|
||
|
}
|
||
|
return ob == DBNull.Value ? 0 : Convert.ToDouble(ob);
|
||
|
|
||
|
|
||
|
}
|
||
|
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 where LeaveEntry.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 where LeaveEntry.LeaveID= Leave.LeaveID " +
|
||
|
"AND AprFromDate between %d and %d and LeaveStatus =%n AND APPTOTALDAYS<>0 order by AppFromDate DESC",
|
||
|
fromDate, toDate, LeaveStatus);
|
||
|
}
|
||
|
|
||
|
public static DataTable GetSumOfBalance(TransactionContext tc, DateTime fromDate, DateTime toDate, int LeaveStatus)
|
||
|
{
|
||
|
if (LeaveStatus == 0)
|
||
|
return tc.ExecuteDataTable(
|
||
|
@"SELECT LeaveEntry.EMPID, LeaveEntry.LEAVEID, sum(APPTOTALDAYS) totalDays FROM LeaveEntry where
|
||
|
AprFromDate between %d and %d AND APPTOTALDAYS <> 0
|
||
|
group by LeaveEntry.EMPID, LeaveEntry.LEAVEID order by LeaveEntry.EMPID, LeaveEntry.LEAVEID",
|
||
|
fromDate, toDate);
|
||
|
else
|
||
|
return tc.ExecuteDataTable(
|
||
|
@"SELECT LeaveEntry.EMPID, LeaveEntry.LEAVEID, sum(APPTOTALDAYS) totalDays FROM LeaveEntry where
|
||
|
AprFromDate between %d and %d AND APPTOTALDAYS <> 0
|
||
|
group by LeaveEntry.EMPID, LeaveEntry.LEAVEID order by LeaveEntry.EMPID, LeaveEntry.LEAVEID",
|
||
|
fromDate, toDate, LeaveStatus);
|
||
|
}
|
||
|
|
||
|
|
||
|
public static IDataReader Get(TransactionContext tc, DateTime attnDate)
|
||
|
{
|
||
|
tc.CommandTimeOut =6000;
|
||
|
return tc.ExecuteReader("SELECT * FROM LeaveEntry where %d Between APRFROMDATE AND APRTODATE ", attnDate);
|
||
|
}
|
||
|
|
||
|
public static IDataReader GetAll(TransactionContext tc)
|
||
|
{
|
||
|
return tc.ExecuteReader("SELECT * FROM LeaveEntry ");
|
||
|
}
|
||
|
|
||
|
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)
|
||
|
{
|
||
|
string str = SQLParser.MakeSQL(
|
||
|
"SELECT LeaveEntry.*, Leave.Description FROM LeaveEntry, Leave, LeaveParameter "
|
||
|
+ " where LeaveEntry.AprParamID=LeaveParameter.LeaveParamId AND LeaveEntry.LeaveID= Leave.LeaveID AND AprFromDate between %d and %d and EmpId %q AND APPTOTALDAYS<>0 order by AprFromDate DESC",
|
||
|
fromDate, toDate, inSQL);
|
||
|
return tc.ExecuteReader(str);
|
||
|
}
|
||
|
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 LeaveEntry.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 ln.*, Leave.Description FROM LeaveEntry ln, Leave WHERE ln.LeaveID= Leave.LeaveID AND ln.TranId=%n ",
|
||
|
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 OrgId,OrganizationHierarchy.Description 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);
|
||
|
}
|
||
|
|
||
|
internal static IDataReader GetSumOfAvailedLeave(TransactionContext tc, int LeavYearID)
|
||
|
{
|
||
|
string str = SQLParser.MakeSQL(
|
||
|
@"select LeaveYear, LeaveID,EmpId, Sum(APPTOTALDAYS) AprTotalDays, LEAVESTATUS from LeaveEntry
|
||
|
where LeaveYear=%n AND LeaveStatus=%n group by LeaveYear, LeaveID, EmpId, LEAVESTATUS", LeavYearID, (int)EnumLeaveStatus.Approved);
|
||
|
// sSql = @"select LeaveYear, LeaveID,EmpId, Sum(APPTOTALDAYS) AprTotalDays, LEAVESTATUS from LeaveEntry
|
||
|
// where LeaveYear=%n group by LeaveYear, LeaveID, EmpId, LEAVESTATUS";
|
||
|
|
||
|
return tc.ExecuteReader(str);
|
||
|
}
|
||
|
|
||
|
public static IDataReader GetSumOfAvailedLeave(TransactionContext tc, int LeavYearID, int employeeid)
|
||
|
{
|
||
|
string sSql = SQLParser.MakeSQL(
|
||
|
@"select LeaveYear, LeaveID,EmpId, Sum(APPTOTALDAYS) APRTOTALDAYS, LEAVESTATUS from LeaveEntry
|
||
|
where LeaveYear=%n and EmpId=%n AND LeaveStatus=%n group by LeaveYear, EmpId, LeaveID, LEAVESTATUS",
|
||
|
LeavYearID, employeeid, (int)EnumLeaveStatus.Approved);
|
||
|
// sSql = @"select LeaveYear, LeaveID,EmpId, Sum(APPTOTALDAYS) APRTOTALDAYS, LEAVESTATUS from LeaveEntry
|
||
|
// where LeaveYear=%n and EmpId=%n group by LeaveYear, EmpId, LeaveID, LEAVESTATUS";
|
||
|
// sSql = @"select * from LeaveEntry
|
||
|
// where LeaveYear=%n and EmpId=%n group by LeaveYear, EmpId, LeaveID, LEAVESTATUS";
|
||
|
return tc.ExecuteReader(sSql);
|
||
|
//return tc.ExecuteReader(sSql,LeavYearID, employeeid);
|
||
|
}
|
||
|
|
||
|
public static IDataReader GetEmployeeWiseLeaveDetailReport(TransactionContext tc, int empId, DateTime fromDate,
|
||
|
DateTime toDate, int leaveType)
|
||
|
{
|
||
|
string query = string.Empty;
|
||
|
LeaveYearService lys = new LeaveYearService();
|
||
|
// LeaveYear ly = lys.GetCurrentYear();
|
||
|
if (leaveType == 0)
|
||
|
{
|
||
|
query = "SELECT * " +
|
||
|
" FROM LeaveEntry" +
|
||
|
" WHERE EmpId = %n AND LeaveEntry.AprFromDate >= %d AND LeaveEntry.AprToDate <= %d " +
|
||
|
" AND LEAVESTATUS=%n AND LeaveEntry.APPTOTALDAYS<>0 order by LEAVEID";
|
||
|
return tc.ExecuteReader(query, empId, fromDate, toDate, EnumLeaveStatus.Approved);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
query = "SELECT * " +
|
||
|
" FROM LeaveEntry" +
|
||
|
" WHERE EmpId = %n AND LEAVEID=%n AND LeaveEntry.AprFromDate >= %d AND LeaveEntry.AprToDate <= %d " +
|
||
|
" AND LEAVESTATUS=%n AND LeaveEntry.APPTOTALDAYS<>0";
|
||
|
return tc.ExecuteReader(query, empId, leaveType, fromDate, toDate, EnumLeaveStatus.Approved);
|
||
|
}
|
||
|
}
|
||
|
public static IDataReader GetEmployeeWiseLeaveDetailReport(TransactionContext tc, string empIds, DateTime fromDate, DateTime toDate, int leaveType)
|
||
|
{
|
||
|
string query = string.Empty;
|
||
|
/*LeaveYearService leaveYearService = new LeaveYearService();
|
||
|
LeaveYear ly = leaveYearService.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 AND LeaveEntry.APPTOTALDAYS<>0 order by LEAVEID", empIds, fromDate, toDate, EnumLeaveStatus.Approved);
|
||
|
return tc.ExecuteReader(query);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
query = "SELECT * " +
|
||
|
" FROM LeaveEntry" +
|
||
|
" WHERE EmpId in (%q) AND LEAVEID=%n AND LeaveEntry.AprFromDate >= %d AND LeaveEntry.AprToDate <= %d " +
|
||
|
" AND LEAVESTATUS=%n AND LeaveEntry.APPTOTALDAYS<>0";
|
||
|
return tc.ExecuteReader(query, empIds, leaveType, fromDate, toDate, EnumLeaveStatus.Approved);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static IDataReader GetEmployeeWiseLeaveDetailReport(TransactionContext tc, string empIds, int leaveYear, int leaveType)
|
||
|
{
|
||
|
string query = string.Empty;
|
||
|
/*LeaveYearService leaveYearService = new LeaveYearService();
|
||
|
LeaveYear ly = leaveYearService.GetCurrentYear();*/
|
||
|
if (leaveType == 0)
|
||
|
{
|
||
|
query = SQLParser.MakeSQL(@"
|
||
|
SELECT *
|
||
|
FROM LeaveEntry
|
||
|
WHERE EmpId in (%q) AND LeaveEntry.LEAVEYEAR = %n
|
||
|
AND LEAVESTATUS=%n AND LeaveEntry.APPTOTALDAYS<>0 order by LEAVEID", empIds, leaveYear, EnumLeaveStatus.Approved);
|
||
|
return tc.ExecuteReader(query);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
query = "SELECT * " +
|
||
|
" FROM LeaveEntry" +
|
||
|
" WHERE EmpId in (%q) AND LEAVEID=%n AND LeaveEntry.LEAVEYEAR = %n " +
|
||
|
" AND LEAVESTATUS=%n AND LeaveEntry.APPTOTALDAYS<>0";
|
||
|
return tc.ExecuteReader(query, empIds, leaveType, leaveYear, EnumLeaveStatus.Approved);
|
||
|
}
|
||
|
}
|
||
|
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) 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) 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 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 leaveParamId, int leaveYear,
|
||
|
int leaveStatus)
|
||
|
{
|
||
|
object ob;
|
||
|
if ((EnumLeaveStatus)leaveStatus == EnumLeaveStatus.Approved)
|
||
|
{
|
||
|
string sSQL = SQLParser.MakeSQL(
|
||
|
@"SELECT sum(APPTOTALDAYS) FROM LeaveEntry where EmpId=%n and LeaveYear=%n
|
||
|
and AprParamId=%n and LeaveStatus =%n AND APPTOTALDAYS<>0",
|
||
|
empId, leaveYear, leaveParamId, leaveStatus);
|
||
|
|
||
|
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, leaveParamId, 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 AprParamId=%n AND APPTOTALDAYS<>0",
|
||
|
empId, leaveYear, leaveParamId);
|
||
|
else
|
||
|
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, leaveParamId, (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 GetAmountOnFromDate(TransactionContext tc, int empId,
|
||
|
int leaveID, EnumLeaveStatus leaveStatus, DateTime dStartDate, DateTime dTodate)
|
||
|
{
|
||
|
object ob;
|
||
|
ob = tc.ExecuteScalar("SELECT sum(APPTOTALDAYS) FROM LeaveEntry where EmpId=%n "
|
||
|
+ " and AprParamId=%n and LeaveStatus =%n AND "
|
||
|
+ " APPTOTALDAYS <> 0 AND AprFromDate BETWEEN %d AND %d", empId,
|
||
|
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 IDataReader GetLFAOnMonth(TransactionContext tc, DateTime onMonth, int payrolltypeid)
|
||
|
{
|
||
|
return tc.ExecuteReader(@"SELECT * FROM LeaveEntry l Inner join Employee e on e.employeeID=l.empID
|
||
|
where l.SalaryMonth= %d and e.payrollTypeID=%n", onMonth, payrolltypeid);
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
//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 LeaveType, LeaveEntry.APPTOTALDAYS 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, 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);
|
||
|
}
|
||
|
|
||
|
internal static IDataReader GetAttachments(TransactionContext tc, int leaveEntryID)
|
||
|
{
|
||
|
string sql = SQLParser.MakeSQL("Select * from LeaveAttachment Where LeaveEntryID = %n", leaveEntryID);
|
||
|
return tc.ExecuteReader(sql);
|
||
|
}
|
||
|
|
||
|
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
|
||
|
|
||
|
internal static IDataReader GetMaternityLeave(TransactionContext tc, int empID, string code)
|
||
|
{
|
||
|
string sql = SQLParser.MakeSQL(@"SELECT TOP 1 le.* FROM LEAVEENTRY le
|
||
|
LEFT JOIN LEAVE lv ON le.LEAVEID = lv.LEAVEID
|
||
|
WHERE le.EMPID = %n AND lv.CODE = %s
|
||
|
ORDER BY le.TRANID DESC", empID, code);
|
||
|
return tc.ExecuteReader(sql);
|
||
|
}
|
||
|
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, 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 LEAVEATTACHMENT WHERE LEAVEENTRYID=%n", tranId);
|
||
|
tc.ExecuteNonQuery("DELETE FROM LeaveEntry WHERE TranId=%n", tranId);
|
||
|
}
|
||
|
|
||
|
private static void DeleteDummyEntry(TransactionContext tc, LeaveEntry oItem)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
tc.ExecuteNonQuery("DELETE FROM LeaveEntry WHERE EmpID=%n and LeaveID=%n AND APPTOTALDAYS=0",
|
||
|
oItem.EmpID, oItem.LeaveID);
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static void DeleteByLeaveYear(TransactionContext tc, int nYear, int nLeaveid)
|
||
|
{
|
||
|
tc.ExecuteNonQuery("DELETE FROM LeaveEntry WHERE LeaveYear=%n AND LeaveID=%n", nYear, nLeaveid);
|
||
|
}
|
||
|
|
||
|
internal static void DeleteAttachments(TransactionContext tc, int Id)
|
||
|
{
|
||
|
tc.ExecuteNonQuery("DELETE FROM LeaveAttachment WHERE LeaveEntryID = %n", Id);
|
||
|
}
|
||
|
|
||
|
public static void UploadFile(TransactionContext tc, LeaveAttachment item)
|
||
|
{
|
||
|
tc.ExecuteNonQuery("DELETE FROM LeaveAttachment WHERE LeaveEntryID = %n", item.LeaveEntryID);
|
||
|
|
||
|
string strQuery = @"INSERT INTO LEAVEATTACHMENT(LEAVEENTRYID, ATTACHMENTPATH, FILEDATA,ORIGINALFILENAME,FILETYPE) Values (@LEAVEENTRYID,@ATTACHMENTPATH,@FILEDATA,@ORIGINALFILENAME,@FILETYPE)";
|
||
|
|
||
|
SqlCommand cmd = new SqlCommand(strQuery, (SqlConnection)tc.Connection);
|
||
|
|
||
|
cmd.Parameters.Add("@LEAVEENTRYID", SqlDbType.Int);
|
||
|
cmd.Parameters["@LEAVEENTRYID"].Value = item.LeaveEntryID;
|
||
|
|
||
|
cmd.Parameters.Add("@ORIGINALFILENAME", SqlDbType.VarChar);
|
||
|
cmd.Parameters["@ORIGINALFILENAME"].Value = item.OriginalFileName;
|
||
|
|
||
|
cmd.Parameters.Add("@FILEDATA", SqlDbType.VarBinary);
|
||
|
cmd.Parameters["@FILEDATA"].Value = item.FileAsByteArray;
|
||
|
|
||
|
cmd.Parameters.Add("@FILETYPE", SqlDbType.Int);
|
||
|
cmd.Parameters["@FILETYPE"].Value = (int)item.FileType;
|
||
|
|
||
|
cmd.Parameters.Add("@ATTACHMENTPATH", SqlDbType.VarChar);
|
||
|
cmd.Parameters["@ATTACHMENTPATH"].Value = item.AttachmentPath == null ? string.Empty : item.AttachmentPath;
|
||
|
|
||
|
cmd.ExecuteNonQuery();
|
||
|
}
|
||
|
|
||
|
internal static DataTable GetMyTeamLeave(TransactionContext tc, int linemanagerid, DateTime fromdate, DateTime todate)
|
||
|
{
|
||
|
DataTable presentDays = new DataTable();
|
||
|
try
|
||
|
{
|
||
|
string sql = SQLParser.MakeSQL("SELECT e.EMPLOYEEID, le.LEAVEID, e.NAME, le.APPFROMDATE, le.APPTODATE FROM LEAVEENTRY le " +
|
||
|
"LEFT JOIN EMPLOYEE e ON e.EMPLOYEEID = le.EMPID " +
|
||
|
"WHERE (le.APPFROMDATE between %d and %d OR le.APPTODATE between %d and %d) " +
|
||
|
"AND e.linemanagerid =%n and e.status =1 " +
|
||
|
"AND le.LEAVESTATUS not in (%n,%n,%n)", fromdate, todate, fromdate, todate, linemanagerid, (int)EnumLeaveStatus.Declined, (int)EnumLeaveStatus.Cancel, (int)EnumLeaveStatus.Cancelled_by_user);
|
||
|
|
||
|
presentDays = tc.ExecuteDataTable(sql);
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
throw new Exception(ex.Message);
|
||
|
}
|
||
|
return presentDays;
|
||
|
}
|
||
|
|
||
|
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);
|
||
|
// }
|
||
|
// LeaveYear ly = LeaveYear.GetCurrentYear();
|
||
|
{
|
||
|
query = SQLParser.MakeSQL(@"SELECT *
|
||
|
FROM LeaveEntry
|
||
|
WHERE EmpId in (%q) AND LeaveEntry.AprFromDate >= %d AND LeaveEntry.AprToDate <= %d
|
||
|
AND LeaveEntry.APPTOTALDAYS<>0 order by AprFromDate DESC");
|
||
|
return tc.ExecuteReader(query, empIds, fromDate, toDate);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
internal static IDataReader GetPreviousDateApprovedLeaveEntry(TransactionContext tc, DateTime leaveApprovedDate, string salesHeadEmailAddress, EnumLeaveStatus leaveStatus)
|
||
|
{
|
||
|
string sql = SQLParser.MakeSQL(@"
|
||
|
WITH cte AS (
|
||
|
SELECT EMPLOYEEID, EMPLOYEENO, NAME, DEPARTMENTID, DESIGNATIONID, LOCATIONID
|
||
|
FROM EMPLOYEE
|
||
|
WHERE LINEMANAGERID IN (SELECT EMPLOYEEID FROM EMPLOYEE WHERE EMAILADDRESS = %s)
|
||
|
UNION ALL
|
||
|
SELECT e.EMPLOYEEID, e.EMPLOYEENO, e.NAME, e.DEPARTMENTID, e.DESIGNATIONID, e.LOCATIONID
|
||
|
FROM EMPLOYEE e
|
||
|
INNER JOIN cte c
|
||
|
ON e.LINEMANAGERID = c.EMPLOYEEID
|
||
|
)
|
||
|
SELECT c.EMPLOYEEID, c.EMPLOYEENO, c.NAME, des.NAME AS [DESIGNATION], d.DESCRIPTION AS [DEPARTMENT],
|
||
|
l.TRANID AS LeaveEntryID, l.LEAVESTATUS, l.APPFROMDATE, l.APPTODATE, l.APRLEAVEDATE, l.REMARKS AS Reason,
|
||
|
loc.DESCRIPTION AS [LOCATION], lv.DESCRIPTION AS LeaveName
|
||
|
FROM LEAVEENTRY l
|
||
|
JOIN cte c ON l.EMPID = c.EMPLOYEEID
|
||
|
JOIN LEAVE lv ON lv.LEAVEID = l.LEAVEID
|
||
|
LEFT JOIN DESIGNATION des ON des.DESIGNATIONID = c.DESIGNATIONID
|
||
|
LEFT JOIN DEPARTMENT d ON d.DEPARTMENTID = c.DEPARTMENTID
|
||
|
LEFT JOIN LOCATION loc ON loc.LOCATIONID = c.LOCATIONID
|
||
|
WHERE l.LEAVESTATUS = %n AND l.APRLEAVEDATE = %d",
|
||
|
salesHeadEmailAddress, leaveStatus, leaveApprovedDate);
|
||
|
|
||
|
return tc.ExecuteReader(sql);
|
||
|
}
|
||
|
|
||
|
internal static void OnapprovalCancelRequest(TransactionContext tc, int tranId, EnumLeaveStatus leaveStatus, EnumwfStatus wfstatus)
|
||
|
{
|
||
|
string updateWFNext = SQLParser.MakeSQL(@"
|
||
|
UPDATE WFMovementNext
|
||
|
SET Status = %n WHERE WFMovementNextID = (
|
||
|
SELECT max(wn.WFMovementNextID) FROM WFMovementNext wn
|
||
|
JOIN WFMovementTran wt ON wn.WFMovementTranID = wt.WFMovementTranID
|
||
|
WHERE wn.EmployeeID <> (SELECT EMPID FROM LEAVEENTRY WHERE TRANID = %n) AND
|
||
|
wt.ObjectID = %n AND wn.Status <> 0)", wfstatus, tranId, tranId);
|
||
|
|
||
|
string updateleaveEntry = SQLParser.MakeSQL(@"UPDATE LEAVEENTRY SET LEAVESTATUS = %n WHERE TRANID = %n", leaveStatus, tranId);
|
||
|
|
||
|
tc.ExecuteNonQuery(updateWFNext);
|
||
|
tc.ExecuteNonQuery(updateleaveEntry);
|
||
|
}
|
||
|
|
||
|
internal static DataTable AllApproverInfo(TransactionContext tc, int tranId)
|
||
|
{
|
||
|
string sql = SQLParser.MakeSQL(@"
|
||
|
SELECT e.NAME, e.EMAILADDRESS, leaveInfo.*
|
||
|
FROM (
|
||
|
SELECT e.EMPLOYEENO AS EMPNO, e.NAME AS EMPLOYEENAME, l.DESCRIPTION AS LEAVENAME, le.APPFROMDATE AS FROMDATE,
|
||
|
le.APPTODATE AS TODATE, le.APPTOTALDAYS AS TOTALDAYS
|
||
|
FROM LEAVEENTRY le
|
||
|
JOIN LEAVE l ON le.LEAVEID = l.LEAVEID
|
||
|
JOIN EMPLOYEE e ON e.EMPLOYEEID = le.EMPID
|
||
|
WHERE le.TRANID = %n
|
||
|
) leaveInfo,
|
||
|
WFMovementNext wn
|
||
|
JOIN WFMovementTran wt ON wn.WFMovementTranID = wt.WFMovementTranID
|
||
|
JOIN EMPLOYEE e ON e.EMPLOYEEID = wn.EmployeeID
|
||
|
WHERE wn.EmployeeID <> (SELECT EMPID FROM LEAVEENTRY WHERE TRANID = %n) AND
|
||
|
wt.ObjectID = %n AND wn.Status <> 0", tranId, tranId, tranId);
|
||
|
|
||
|
return tc.ExecuteDataTable(sql);
|
||
|
}
|
||
|
|
||
|
//Single Employee Leave Ledger for Mobile App
|
||
|
internal static IDataReader GetEmpleaveLedger(TransactionContext tc, int empId, DateTime fromDate, DateTime toDate)
|
||
|
{
|
||
|
string sql = SQLParser.MakeSQL(@"
|
||
|
SELECT l.DESCRIPTION LeaveName, le.APPFROMDATE FromDate, le.APPTODATE ToDate, le.APPTOTALDAYS TotalDays, le.REMARKS Reason
|
||
|
From LEAVEENTRY le
|
||
|
INNER JOIN LEAVE l ON le.LEAVEID = l.LEAVEID
|
||
|
WHERE le.EMPID=%n
|
||
|
AND le.APPLEAVEDATE BETWEEN %s AND %s", empId, fromDate, toDate);
|
||
|
|
||
|
return tc.ExecuteReader(sql);
|
||
|
}
|
||
|
|
||
|
//My Team Upcoming Leave Mobile App
|
||
|
internal static IDataReader GetMyTeamUpcomingLeave(TransactionContext tc, int empId, DateTime fromDate, DateTime toDate)
|
||
|
{
|
||
|
string sql = SQLParser.MakeSQL(@"
|
||
|
SELECT e.employeeNo, e.Name, l.DESCRIPTION LeaveName, le.APPFROMDATE FromDate, le.APPTODATE ToDate, le.APPTOTALDAYS TotalDays, le.REMARKS Reason
|
||
|
From LEAVEENTRY le
|
||
|
INNER JOIN LEAVE l ON le.LEAVEID = l.LEAVEID
|
||
|
INNER JOIN Employee e ON e.EMPLOYEEID = le.EMPID
|
||
|
WHERE e.Linemanagerid=%n
|
||
|
AND le.APPLEAVEDATE BETWEEN %s AND %s", empId, fromDate, toDate);
|
||
|
|
||
|
return tc.ExecuteReader(sql);
|
||
|
}
|
||
|
|
||
|
internal static DataTable GetMultipleLeaveLedgerData(TransactionContext tc, int leaveYearId, int leaveId, string empIds, DateTime fromDate, DateTime toDate)
|
||
|
{
|
||
|
if(empIds != "")
|
||
|
{
|
||
|
string sql = SQLParser.MakeSQL(
|
||
|
@"SELECT e.employeeNo EmployeeNo, e.NAME Name, deg.NAME Designation, dept.DESCRIPTION Department,
|
||
|
e.DateOfConfirmation, lv.DESCRIPTION LeaveType, le.APRFROMDATE FromDate, le.APRTODATE ToDate,
|
||
|
le.APPTOTALDAYS Days, le.REMARKS Reason, le.leaveStatus Status
|
||
|
FROM LEAVEENTRY le
|
||
|
LEFT JOIN EMPLOYEE e ON le.EMPID = e.EMPLOYEEID
|
||
|
LEFT JOIN DESIGNATION deg ON e.DESIGNATIONID = deg.DESIGNATIONID
|
||
|
LEFT JOIN DEPARTMENT dept ON e.DEPARTMENTID = dept.DEPARTMENTID
|
||
|
LEFT JOIN LEAVE lv ON le.LEAVEID = lv.LEAVEID
|
||
|
WHERE le.LEAVEYEAR = %n AND le.leaveId = %n AND le.APRFROMDATE >= %d AND le.APRTODATE <= %d AND le.EMPID IN (%q);", leaveYearId, leaveId, fromDate, toDate, empIds);
|
||
|
|
||
|
return tc.ExecuteDataTable(sql);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
string sql = SQLParser.MakeSQL(
|
||
|
@"SELECT e.employeeNo EmployeeNo, e.NAME Name, deg.NAME Designation, dept.DESCRIPTION Department,
|
||
|
e.DateOfConfirmation, lv.DESCRIPTION LeaveType, le.APRFROMDATE FromDate, le.APRTODATE ToDate,
|
||
|
le.APPTOTALDAYS Days, le.REMARKS Reason, le.leaveStatus Status
|
||
|
FROM LEAVEENTRY le
|
||
|
LEFT JOIN EMPLOYEE e ON le.EMPID = e.EMPLOYEEID
|
||
|
LEFT JOIN DESIGNATION deg ON e.DESIGNATIONID = deg.DESIGNATIONID
|
||
|
LEFT JOIN DEPARTMENT dept ON e.DEPARTMENTID = dept.DEPARTMENTID
|
||
|
LEFT JOIN LEAVE lv ON le.LEAVEID = lv.LEAVEID
|
||
|
WHERE le.LEAVEYEAR = %n AND le.leaveId = %n AND le.APRFROMDATE >= %d AND le.APRTODATE <= %d;", leaveYearId, leaveId, fromDate, toDate, empIds);
|
||
|
|
||
|
return tc.ExecuteDataTable(sql);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
internal static DataTable GetMultipleLeaveLedgerData(TransactionContext tc, int leaveYearId, string empIds, DateTime fromDate, DateTime toDate)
|
||
|
{
|
||
|
if(empIds != "")
|
||
|
{
|
||
|
string sql = SQLParser.MakeSQL(
|
||
|
@"SELECT e.employeeNo EmployeeNo, e.NAME Name, deg.NAME Designation, dept.DESCRIPTION Department,
|
||
|
e.DateOfConfirmation, lv.DESCRIPTION LeaveType, le.APRFROMDATE FromDate, le.APRTODATE ToDate,
|
||
|
le.APPTOTALDAYS Days, le.REMARKS Reason, le.leaveStatus Status
|
||
|
FROM LEAVEENTRY le
|
||
|
LEFT JOIN EMPLOYEE e ON le.EMPID = e.EMPLOYEEID
|
||
|
LEFT JOIN DESIGNATION deg ON e.DESIGNATIONID = deg.DESIGNATIONID
|
||
|
LEFT JOIN DEPARTMENT dept ON e.DEPARTMENTID = dept.DEPARTMENTID
|
||
|
LEFT JOIN LEAVE lv ON le.LEAVEID = lv.LEAVEID
|
||
|
WHERE le.LEAVEYEAR = %n AND le.APRFROMDATE >= %d AND le.APRTODATE <= %d AND le.EMPID IN (%q);", leaveYearId, fromDate, toDate, empIds);
|
||
|
|
||
|
return tc.ExecuteDataTable(sql);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
string sql = SQLParser.MakeSQL(
|
||
|
@"SELECT e.employeeNo EmployeeNo, e.NAME Name, deg.NAME Designation, dept.DESCRIPTION Department,
|
||
|
e.DateOfConfirmation, lv.DESCRIPTION LeaveType, le.APRFROMDATE FromDate, le.APRTODATE ToDate,
|
||
|
le.APPTOTALDAYS Days, le.REMARKS Reason, le.leaveStatus Status
|
||
|
FROM LEAVEENTRY le
|
||
|
LEFT JOIN EMPLOYEE e ON le.EMPID = e.EMPLOYEEID
|
||
|
LEFT JOIN DESIGNATION deg ON e.DESIGNATIONID = deg.DESIGNATIONID
|
||
|
LEFT JOIN DEPARTMENT dept ON e.DEPARTMENTID = dept.DEPARTMENTID
|
||
|
LEFT JOIN LEAVE lv ON le.LEAVEID = lv.LEAVEID
|
||
|
WHERE le.LEAVEYEAR = %n AND le.APRFROMDATE >= %d AND le.APRTODATE <= %d;", leaveYearId, fromDate, toDate, empIds);
|
||
|
|
||
|
return tc.ExecuteDataTable(sql);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
internal static DataSet GetAnnualLeave(TransactionContext tc, int empId)
|
||
|
{
|
||
|
string sSQL = SQLParser.MakeSQL(@"SELECT APRFROMDATE,APRTODATE,APRTOTALDAYS FROM LeaveEntry WHERE EMPID = %n ORDER BY APRTODATE,APRFROMDATE DESC", empId);
|
||
|
return tc.ExecuteDataSet(sSQL);
|
||
|
}
|
||
|
|
||
|
internal static DataTable GetLeaveTodayAndNextWeek(TransactionContext tc, Employee oEmp, EnumLeaveStatus status)
|
||
|
{
|
||
|
string subSQL = SQLParser.MakeSQL(@"SELECT EMPLOYEEID as EmployeeID FROM EMPLOYEE
|
||
|
WHERE LINEMANAGERID = %n and status = %n", oEmp.ID, EnumEmpStatus.Live);
|
||
|
string sSQL = SQLParser.MakeSQL(@"
|
||
|
Select
|
||
|
(SELECT COUNT(*) AS LeaveToday FROM LEAVEENTRY
|
||
|
WHERE LEAVESTATUS = %n and (GETDATE() between APRFROMDATE and APRTODATE)
|
||
|
AND EMPID IN(%q)) as LeaveToday,
|
||
|
(SELECT COUNT(*) AS LeavesNextWeek FROM LEAVEENTRY
|
||
|
WHERE LEAVESTATUS = %n and APRFROMDATE <= DATEADD(DAY, 7, GETDATE())
|
||
|
AND APRTODATE >= GETDATE()
|
||
|
AND EMPID IN(%q)) as LeavesNextWeek", status, subSQL, status, subSQL) ;
|
||
|
return tc.ExecuteDataTable(sSQL);
|
||
|
}
|
||
|
|
||
|
internal static DataTable getTopLeaveChartData(TransactionContext tc, Employee oEmp, int leaveYearId, EnumLeaveStatus status)
|
||
|
{
|
||
|
string sSQL = SQLParser.MakeSQL(@"SELECT
|
||
|
NAME as EmpName, EMPID as EmpId, EMPLOYEENO as EmpNo, Leavestatus,
|
||
|
sum(APRTOTALDAYS) as TotalDays, LeaveYear
|
||
|
FROM EMPLOYEE
|
||
|
LEFT JOIN LEAVEENTRY ON EMPID = EMPLOYEEID
|
||
|
WHERE LEAVEYEAR = %n AND LEAVESTATUS = %n
|
||
|
AND DATEADD(YEAR, DATEDIFF(YEAR, 0, GETDATE()), 0)<= APRFROMDATE and APRFROMDATE<= DATEADD(DAY, -1, DATEADD(YEAR, DATEDIFF(YEAR, 0, GETDATE()) + 1, 0))
|
||
|
AND DATEADD(YEAR, DATEDIFF(YEAR, 0, GETDATE()), 0)<= APRTODATE and APRTODATE<= DATEADD(DAY, -1, DATEADD(YEAR, DATEDIFF(YEAR, 0, GETDATE()) + 1, 0))
|
||
|
AND LINEMANAGERID = %n and status = %n
|
||
|
group by NAME, EMPID, employeeno, Leavestatus, LeaveYear
|
||
|
order by TotalDays desc", leaveYearId, status, oEmp.ID, EnumEmpStatus.Live);
|
||
|
return tc.ExecuteDataTable(sSQL);
|
||
|
}
|
||
|
internal static DataTable getcorehrLeaveChartData(TransactionContext tc, Employee oEmp, int leaveYearId, EnumLeaveStatus status)
|
||
|
{
|
||
|
string subSQL = "";
|
||
|
if(oEmp!= null && oEmp.LineManagerID != null)
|
||
|
{
|
||
|
subSQL = SQLParser.MakeSQL(@"and employee.DEPARTMENTID = %n ", oEmp.DepartmentID);
|
||
|
}
|
||
|
string sSQL = SQLParser.MakeSQL(@"SELECT
|
||
|
NAME as EmpName, EMPID as EmpId, EMPLOYEENO as EmpNo, Leavestatus,
|
||
|
sum(APRTOTALDAYS) as TotalDays, LeaveYear, EMPLOYEE.DEPARTMENTID
|
||
|
FROM EMPLOYEE
|
||
|
LEFT JOIN LEAVEENTRY ON EMPID = EMPLOYEEID
|
||
|
WHERE LEAVEYEAR = %n AND LEAVESTATUS = %n
|
||
|
AND DATEADD(YEAR, DATEDIFF(YEAR, 0, GETDATE()), 0)<= APRFROMDATE and APRFROMDATE<= DATEADD(DAY, -1, DATEADD(YEAR, DATEDIFF(YEAR, 0, GETDATE()) + 1, 0))
|
||
|
AND DATEADD(YEAR, DATEDIFF(YEAR, 0, GETDATE()), 0)<= APRTODATE and APRTODATE<= DATEADD(DAY, -1, DATEADD(YEAR, DATEDIFF(YEAR, 0, GETDATE()) + 1, 0))
|
||
|
AND status = %n %q
|
||
|
group by NAME, EMPID, employeeno, Leavestatus, LeaveYear, employee.DEPARTMENTID
|
||
|
order by TotalDays desc", leaveYearId, status, EnumEmpStatus.Live, subSQL);
|
||
|
return tc.ExecuteDataTable(sSQL);
|
||
|
}
|
||
|
|
||
|
internal static int GetOnApprovalLeaveCount(TransactionContext tc, int empId, int leaveId, int leaveYear, EnumLeaveStatus leaveStatus)
|
||
|
{
|
||
|
object ob = DBNull.Value;
|
||
|
ob = tc.ExecuteScalar("select SUM(APPTOTALDAYS) from LEAVEENTRY where EMPID = %n and LEAVEID = %n and LEAVEYEAR = %n and LEAVESTATUS = %n", empId, leaveId, leaveYear, leaveStatus);
|
||
|
return ob == DBNull.Value ? 0 : Convert.ToInt32(ob);
|
||
|
}
|
||
|
#endregion
|
||
|
}
|
||
|
}
|
||
|
/*----sbu wise
|
||
|
select Emp.SBUID,L.LeaveID,L.Description, sum(LE.APPTOTALDAYS) 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
|
||
|
*/
|