From 134c0db3d1ef21072054abf96a7ac686ed31edfc Mon Sep 17 00:00:00 2001 From: mashfiq Date: Tue, 17 Dec 2024 18:22:20 +0600 Subject: [PATCH] Single Employee Picker Modified --- HRM.BO/SearchReport/SearchEmployee.cs | 2 +- HRM.DA/DA/SearchReport/SearchEmployeeDA.cs | 120 +++++++++++++++++- .../SearchReport/SearchEmployeeService.cs | 4 +- .../Employee/EmployeeController.cs | 4 +- 4 files changed, 121 insertions(+), 9 deletions(-) diff --git a/HRM.BO/SearchReport/SearchEmployee.cs b/HRM.BO/SearchReport/SearchEmployee.cs index 713dc02..5fd4ee5 100644 --- a/HRM.BO/SearchReport/SearchEmployee.cs +++ b/HRM.BO/SearchReport/SearchEmployee.cs @@ -369,7 +369,7 @@ namespace HRM.BO List Find(SearchManager oManager); List FindCordinator(int? id, int? payrollTypeID); List FindEmpCodeName(int payrolltypeid, string code, string name); - List FindEmpCodeNameForEmployeePicker(int payrolltypeid, string code, string name); + List FindEmpCodeNameForEmployeePicker(int userid, int payrolltypeid, string code, string name); SearchEmployee get(int empid); List GetEmployeeNotYetUser(int payrollTypeID); List GetTeam(int employeeid); diff --git a/HRM.DA/DA/SearchReport/SearchEmployeeDA.cs b/HRM.DA/DA/SearchReport/SearchEmployeeDA.cs index a493351..899fe5d 100644 --- a/HRM.DA/DA/SearchReport/SearchEmployeeDA.cs +++ b/HRM.DA/DA/SearchReport/SearchEmployeeDA.cs @@ -246,11 +246,122 @@ END;"; "Select %q EmployeeID, EmployeeNo, Name, categoryID, GradeID, LocationID, designationid, DepartmentID From Employee %q Order by %s", top, sqlClause, orderby); } - internal static IDataReader SearchForEmployeePicker(TransactionContext tc, int payrollTypeID, string code, string name) + internal static IDataReader SearchForEmployeePicker(TransactionContext tc, int userID, int payrollTypeID, string code, string name) { string orderby = "name"; string sqlClause = ""; string top = ""; + + string recurSqlClause = SQLParser.MakeSQL(@" + DECLARE @userid INT = %n; + DECLARE @payrolltypeid INT = %n; + DECLARE @permissionstatus INT = %n; + WITH RecursiveCategory AS + ( + SELECT + CATEGORYID + FROM + dbo.CATEGORY + WHERE + CATEGORYID IN ( + SELECT REFERENCEID + FROM DATAPERMISSION + WHERE USERID = @userid + AND PAYROLLTYPEID = @payrolltypeid + AND PERMISSIONSTATUS = @permissionstatus + AND PERMISSIONTYPE = %n + ) + ), + RecursiveGrade AS + ( + SELECT + GRADEID + FROM + dbo.GRADES + WHERE + GRADEID IN ( + SELECT REFERENCEID + FROM DATAPERMISSION + WHERE USERID = @userid + AND PAYROLLTYPEID = @payrolltypeid + AND PERMISSIONSTATUS = @permissionstatus + AND PERMISSIONTYPE = %n + ) + ), + RecursiveDepartment AS + ( + SELECT + DEPARTMENTID + FROM + dbo.DEPARTMENT + WHERE + DEPARTMENTID IN ( + SELECT REFERENCEID + FROM DATAPERMISSION + WHERE USERID = @userid + AND PAYROLLTYPEID = @payrolltypeid + AND PERMISSIONSTATUS = @permissionstatus + AND PERMISSIONTYPE = %n + ) + UNION ALL + SELECT + d.DEPARTMENTID + FROM + dbo.DEPARTMENT d + INNER JOIN + RecursiveDepartment rd + ON + d.PARENTID = rd.DEPARTMENTID + ), + RecursiveLocation AS + ( + SELECT + LOCATIONID + FROM + dbo.LOCATION + WHERE + LOCATIONID IN ( + SELECT REFERENCEID + FROM DATAPERMISSION + WHERE USERID = @userid + AND PAYROLLTYPEID = @payrolltypeid + AND PERMISSIONSTATUS = @permissionstatus + AND PERMISSIONTYPE = %n + ) + UNION ALL + SELECT + l.LOCATIONID + FROM + dbo.LOCATION l + INNER JOIN + RecursiveLocation rl + ON + l.PARENTID = rl.LOCATIONID + )", userID, payrollTypeID, EnumMenuPermissionStatus.Approved, EnumDataPermissionType.Cagtegory, EnumDataPermissionType.Grade, EnumDataPermissionType.Department, EnumDataPermissionType.Location); + string recurWhereClause = SQLParser.MakeSQL(@" + AND + ( + ( + EXISTS (SELECT 1 FROM RecursiveCategory) + AND CATEGORYID IN (SELECT CATEGORYID FROM RecursiveCategory) + ) + OR + ( + EXISTS (SELECT 1 FROM RecursiveGrade) + AND GRADEID IN (SELECT GRADEID FROM RecursiveGrade) + ) + OR + ( + EXISTS (SELECT 1 FROM RecursiveDepartment) + AND DEPARTMENTID IN (SELECT DEPARTMENTID FROM RecursiveDepartment) + ) + OR + ( + EXISTS (SELECT 1 FROM RecursiveLocation) + AND LOCATIONID IN (SELECT LOCATIONID FROM RecursiveLocation) + ) + )"); + //Previous Code For only Live Employee //sqlClause = SQLParser.TagSQL(sqlClause) + SQLParser.MakeSQL("PayrollTypeID =%n AND Status = %n", payrollTypeID, EnumStatus.Active); @@ -274,10 +385,11 @@ END;"; if (name != string.Empty) sqlClause = SQLParser.TagSQL(sqlClause) + SQLParser.MakeSQL("Name LIKE %s", ("%" + name + "%")); + string finalSQl = SQLParser.MakeSQL( + "%q Select %q EmployeeID, EmployeeNo, Name, categoryID, GradeID, LocationID, designationid, DepartmentID From Employee %q %q Order by %s", + recurSqlClause, top, sqlClause, recurWhereClause, orderby); - return tc.ExecuteReader( - "Select %q EmployeeID, EmployeeNo, Name, categoryID, GradeID, LocationID, designationid, DepartmentID From Employee %q Order by %s", - top, sqlClause, orderby); + return tc.ExecuteReader(finalSQl); } #endregion diff --git a/HRM.DA/Service/SearchReport/SearchEmployeeService.cs b/HRM.DA/Service/SearchReport/SearchEmployeeService.cs index 256c69d..7af11e0 100644 --- a/HRM.DA/Service/SearchReport/SearchEmployeeService.cs +++ b/HRM.DA/Service/SearchReport/SearchEmployeeService.cs @@ -288,7 +288,7 @@ namespace HRM.DA return searchEmployees; } - public List FindEmpCodeNameForEmployeePicker(int payrollTypeID, string code, string name) + public List FindEmpCodeNameForEmployeePicker(int userID, int payrollTypeID, string code, string name) { List searchEmployees = new List(); @@ -297,7 +297,7 @@ namespace HRM.DA { tc = TransactionContext.Begin(); - DataReader dr = new DataReader(SearchEmployeeDA.SearchForEmployeePicker(tc, payrollTypeID, code, name)); + DataReader dr = new DataReader(SearchEmployeeDA.SearchForEmployeePicker(tc, userID, payrollTypeID, code, name)); searchEmployees = this.CreateObjects(dr); //while (dr.Read()) //{ diff --git a/HRM.UI/Controllers/Employee/EmployeeController.cs b/HRM.UI/Controllers/Employee/EmployeeController.cs index f41ab41..89d9e39 100644 --- a/HRM.UI/Controllers/Employee/EmployeeController.cs +++ b/HRM.UI/Controllers/Employee/EmployeeController.cs @@ -787,7 +787,7 @@ namespace HRM.UI.Controllers //olist = _serachManager.FindEmpCodeName((int) currentUser.PayrollTypeID, code, name); if(code != "") { - List unorderedList = _serachManager.FindEmpCodeNameForEmployeePicker((int)currentUser.PayrollTypeID, code, name); + List unorderedList = _serachManager.FindEmpCodeNameForEmployeePicker((int)currentUser.UserID, (int)currentUser.PayrollTypeID, code, name); olist = unorderedList .OrderBy(item => item.EmployeeNo != code) // False (0) for priority value, True (1) for others @@ -795,7 +795,7 @@ namespace HRM.UI.Controllers } else { - olist = _serachManager.FindEmpCodeNameForEmployeePicker((int)currentUser.PayrollTypeID, code, name); + olist = _serachManager.FindEmpCodeNameForEmployeePicker((int)currentUser.UserID, (int)currentUser.PayrollTypeID, code, name); } //List grades = new GradeService().Get(EnumStatus.Regardless, (int)currentUser.PayrollTypeID);