diff --git a/HRM.BO/SearchReport/SearchEmployee.cs b/HRM.BO/SearchReport/SearchEmployee.cs index 60294a5..713dc02 100644 --- a/HRM.BO/SearchReport/SearchEmployee.cs +++ b/HRM.BO/SearchReport/SearchEmployee.cs @@ -369,6 +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); 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 1981e04..a493351 100644 --- a/HRM.DA/DA/SearchReport/SearchEmployeeDA.cs +++ b/HRM.DA/DA/SearchReport/SearchEmployeeDA.cs @@ -231,11 +231,8 @@ END;"; { string orderby = "name"; string sqlClause = ""; - //Previous Code For only Live Employee - //sqlClause = SQLParser.TagSQL(sqlClause) + SQLParser.MakeSQL("PayrollTypeID =%n AND Status = %n", payrollTypeID, EnumStatus.Active); - - //New Code For live And Waitiong for join Employee - sqlClause = SQLParser.TagSQL(sqlClause) + SQLParser.MakeSQL("PayrollTypeID =%n AND Status = %n OR Status = %n", payrollTypeID, EnumEmployeeStatus.Live, EnumEmployeeStatus.Waitingforjoin); + string top = ""; + sqlClause = SQLParser.TagSQL(sqlClause) + SQLParser.MakeSQL("PayrollTypeID =%n AND Status = %n", payrollTypeID, EnumStatus.Active); if (code != string.Empty) { sqlClause = SQLParser.TagSQL(sqlClause) + SQLParser.MakeSQL("EmployeeNo LIKE %s", ("%" + code + "%")); @@ -246,8 +243,41 @@ END;"; sqlClause = SQLParser.TagSQL(sqlClause) + SQLParser.MakeSQL("Name LIKE %s", ("%" + name + "%")); return tc.ExecuteReader( - "Select EmployeeID, EmployeeNo, Name, categoryID, GradeID, LocationID, designationid, DepartmentID From Employee %q Order by %s", - sqlClause, orderby); + "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) + { + string orderby = "name"; + string sqlClause = ""; + string top = ""; + //Previous Code For only Live Employee + //sqlClause = SQLParser.TagSQL(sqlClause) + SQLParser.MakeSQL("PayrollTypeID =%n AND Status = %n", payrollTypeID, EnumStatus.Active); + + //New Code For live And Waitiong for join Employee + sqlClause = SQLParser.TagSQL(sqlClause) + SQLParser.MakeSQL("PayrollTypeID =%n AND (Status = %n OR Status = %n)", payrollTypeID, EnumEmployeeStatus.Live, EnumEmployeeStatus.Waitingforjoin); + if (code != string.Empty) + { + //Previous with suggestion + //sqlClause = SQLParser.TagSQL(sqlClause) + SQLParser.MakeSQL("EmployeeNo LIKE %s", ("%" + code + "%")); + //orderby = "EmployeeNo"; + + //Using TOP + sqlClause = SQLParser.TagSQL(sqlClause) + SQLParser.MakeSQL("EmployeeNo LIKE %s", ( code + "%")); + orderby = "EmployeeNo"; + top = "TOP 50"; + + //Without suggestion + //sqlClause = SQLParser.TagSQL(sqlClause) + SQLParser.MakeSQL("EmployeeNo = %s", code ); + //orderby = "EmployeeNo"; + } + + if (name != string.Empty) + sqlClause = SQLParser.TagSQL(sqlClause) + SQLParser.MakeSQL("Name LIKE %s", ("%" + name + "%")); + + return tc.ExecuteReader( + "Select %q EmployeeID, EmployeeNo, Name, categoryID, GradeID, LocationID, designationid, DepartmentID From Employee %q Order by %s", + top, sqlClause, orderby); } #endregion diff --git a/HRM.DA/Service/SearchReport/SearchEmployeeService.cs b/HRM.DA/Service/SearchReport/SearchEmployeeService.cs index cf8469d..256c69d 100644 --- a/HRM.DA/Service/SearchReport/SearchEmployeeService.cs +++ b/HRM.DA/Service/SearchReport/SearchEmployeeService.cs @@ -288,6 +288,43 @@ namespace HRM.DA return searchEmployees; } + public List FindEmpCodeNameForEmployeePicker(int payrollTypeID, string code, string name) + { + List searchEmployees = new List(); + + TransactionContext tc = null; + try + { + tc = TransactionContext.Begin(); + + DataReader dr = new DataReader(SearchEmployeeDA.SearchForEmployeePicker(tc, payrollTypeID, code, name)); + searchEmployees = this.CreateObjects(dr); + //while (dr.Read()) + //{ + // SearchEmployee item = new SearchEmployee(); + // item.Name = dr.GetString("name"); + // item.EmployeeNo = dr.GetString("employeeNo"); + + // searchEmployees.Add(item); + //} + dr.Close(); + tc.End(); + } + catch (Exception e) + { + #region Handle Exception + + if (tc != null) + tc.HandleError(); + ExceptionLog.Write(e); + + throw new ServiceException(e.Message, e); + + #endregion + } + + return searchEmployees; + } public List GetEmployeeNotYetUser(int payrollTypeID) diff --git a/HRM.UI/ClientApp/src/app/_services/employee/employee.service.ts b/HRM.UI/ClientApp/src/app/_services/employee/employee.service.ts index 226d8bc..b8d2294 100644 --- a/HRM.UI/ClientApp/src/app/_services/employee/employee.service.ts +++ b/HRM.UI/ClientApp/src/app/_services/employee/employee.service.ts @@ -99,6 +99,13 @@ export class EmployeeServices { return this.apiService.httpGet('/Employee/getEmpCodeName' + '/' + ncode + '/' + nname); } + getEmpCodeNameForEmployeePickerInput(code?: string, name?: string) { + let nname = this.apiService.getApiDefaultData(name); + let ncode = this.apiService.getApiDefaultData(code); + + return this.apiService.httpGet('/Employee/getEmpCodeNameForEmployeePickerInput' + '/' + ncode + '/' + nname); + } + getEmployees() { return this.apiService.httpGet(this.apiService.base_url + 'getemployees'); } diff --git a/HRM.UI/ClientApp/src/app/picker/employee-picker.component.ts b/HRM.UI/ClientApp/src/app/picker/employee-picker.component.ts index fe87d77..44ea4b5 100644 --- a/HRM.UI/ClientApp/src/app/picker/employee-picker.component.ts +++ b/HRM.UI/ClientApp/src/app/picker/employee-picker.component.ts @@ -260,7 +260,8 @@ export class EmployeePickerComponent implements OnInit { ]; public loadData(): void { this.gridView = { - data: orderBy(this.data.slice(this.skip, this.skip + this.pageSize), this.sort), + // data: orderBy(this.data.slice(this.skip, this.skip + this.pageSize), this.sort), + data: this.data.slice(this.skip, this.skip + this.pageSize), total: this.data.length, }; this.selectedItems = []; @@ -438,13 +439,12 @@ export class EmployeePickerComponent implements OnInit { } handleFilter(value) { - debugger const str: string = value; if (value.length === 0 || this.empCodeNameList === undefined) { this.empCodeNameList = []; this.empCodeNameListSource = []; } - if (str !== '' && str.length > 2) { + if (str !== '') { this.empCodeNameList = []; /*if (this.empCodeNameList.length === 0) {*/ let code = ''; @@ -455,7 +455,8 @@ export class EmployeePickerComponent implements OnInit { name = value; } this.loadingEmployee = true; - this.empSrvc.getEmpCodeName(code, name) + // this.empSrvc.getEmpCodeName(code, name) + this.empSrvc.getEmpCodeNameForEmployeePickerInput(code, name) .subscribe( (resp: any) => { this.searchEmployees = resp; diff --git a/HRM.UI/Controllers/Employee/EmployeeController.cs b/HRM.UI/Controllers/Employee/EmployeeController.cs index a74efa6..f41ab41 100644 --- a/HRM.UI/Controllers/Employee/EmployeeController.cs +++ b/HRM.UI/Controllers/Employee/EmployeeController.cs @@ -132,9 +132,12 @@ namespace HRM.UI.Controllers { omanager.checkDataPermission = currentUser.hasDataPermission; omanager.userid = currentUser.UserID; - - olist = _serachManager.Find(omanager); + List unOrderedList = _serachManager.Find(omanager); + olist = unOrderedList + .OrderBy(num => num.EmployeeNo.Length) // Order by length (smallest to largest) + .ThenBy(num => Convert.ToInt32(num.EmployeeNo)).ToList(); + //omanager.checkDataPermission = false; #region data permission //List datapermissions = new DataPermissionService().Get(currentUser.UserID, @@ -771,6 +774,53 @@ namespace HRM.UI.Controllers return Ok(olist); } + [HttpGet("getEmpCodeNameForEmployeePickerInput/{code}/{name}")] + public ActionResult getEmpCodeNameForEmployeePicker(string code, string name) + { + code = GlobalFunctions.GetApiDefaultData(code); + name = GlobalFunctions.GetApiDefaultData(name); + + CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); + List olist = new List(); + try + { + //olist = _serachManager.FindEmpCodeName((int) currentUser.PayrollTypeID, code, name); + if(code != "") + { + List unorderedList = _serachManager.FindEmpCodeNameForEmployeePicker((int)currentUser.PayrollTypeID, code, name); + + olist = unorderedList + .OrderBy(item => item.EmployeeNo != code) // False (0) for priority value, True (1) for others + .ThenBy(item => item.EmployeeNo).ToList(); + } + else + { + olist = _serachManager.FindEmpCodeNameForEmployeePicker((int)currentUser.PayrollTypeID, code, name); + } + + //List grades = new GradeService().Get(EnumStatus.Regardless, (int)currentUser.PayrollTypeID); + //List designations = new DesignationService().Get(EnumStatus.Regardless, (int)currentUser.PayrollTypeID); + //List departments = new DepartmentService().Get(EnumStatus.Regardless, (int)currentUser.PayrollTypeID); + //olist.ForEach(x=> + //{ + // var grd = grades.FirstOrDefault(d => d.ID == x.GradeID); + // if(grd != null) x.gradeName = grd.Name; + + // var designation = designations.FirstOrDefault(d => d.ID == x.designationID); + // if (designation != null) x.designationName = designation.Name; + // var department = departments.FirstOrDefault(d => d.ID == x.DepartmentID); + // if (department != null) x.departmentName = department.Name; + //}); // Secondary ordering (alphabetical) + + } + catch (Exception ex) + { + return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); + } + + return Ok(olist); + } + [HttpGet("getEmployeeAttachments/{empId}")] public ActionResult GetEmployeeAttachments(int empId) {