From d9460f525d4979db251738c44b9a8e40655c95d0 Mon Sep 17 00:00:00 2001 From: mashfiq Date: Thu, 15 Jan 2026 14:17:51 +0600 Subject: [PATCH] department permission and multiple employeeid inputs --- HRM.BO/User/DataPermission.cs | 1 + HRM.DA/DA/Users/DataPermissionDA.cs | 31 ++--- HRM.DA/Service/Users/DataPermissionService.cs | 47 ++++++- .../src/app/_services/auth/auth.service.ts | 3 + .../data-permssion.component.html | 2 +- .../data-permssion.component.ts | 116 +++++++++++++----- .../picker/dynamic-picker/Dynamic-Picker.ts | 2 + .../dynamic-picker.component.ts | 3 +- .../report-viewer.component.html | 3 + .../report-viewer/report-viewer.component.ts | 35 +++++- HRM.UI/Controllers/Auth/AuthController.cs | 68 ++++++---- 11 files changed, 224 insertions(+), 87 deletions(-) diff --git a/HRM.BO/User/DataPermission.cs b/HRM.BO/User/DataPermission.cs index fe5bfe7..214d7d4 100644 --- a/HRM.BO/User/DataPermission.cs +++ b/HRM.BO/User/DataPermission.cs @@ -42,6 +42,7 @@ namespace HRM.BO List getUsersByUserType(EnumUserType userType); void InsertDataPermission(DataPermission item); int Save(DataPermission item); + void Save(List oDataPermissions); void Delete(int id); } diff --git a/HRM.DA/DA/Users/DataPermissionDA.cs b/HRM.DA/DA/Users/DataPermissionDA.cs index b7a7740..31f93f3 100644 --- a/HRM.DA/DA/Users/DataPermissionDA.cs +++ b/HRM.DA/DA/Users/DataPermissionDA.cs @@ -44,24 +44,7 @@ namespace HRM.DA #region Get Function - internal static IDataReader Get(TransactionContext tc, EnumStatus status) - { - if (EnumStatus.Active == status || EnumStatus.Inactive == status) - { - return tc.ExecuteReader("SELECT * FROM Religion Where Status=%n Order By SequenceNo", status); - } - else - { - return tc.ExecuteReader("SELECT * FROM Religion Order By SequenceNo"); - } - } - - internal static IDataReader Get(TransactionContext tc, int ID) - { - return tc.ExecuteReader("SELECT * FROM Religion WHERE ReligionID=%n", ID); - } - - #region + #region GetUsersByUserType internal static IDataReader GetUsersByUserType(TransactionContext tc, EnumUserType type) { return tc.ExecuteReader("SELECT * FROM Users where UserType = %n", type); @@ -81,6 +64,7 @@ namespace HRM.DA } } #endregion + internal static void InsertDataPermission(TransactionContext tc, DataPermission item) { item.CreatedDate = DateTime.Now; @@ -113,6 +97,17 @@ namespace HRM.DA userid, payrolltypeid, userid, payrolltypeid, userid, payrolltypeid); } + + internal static bool PermissionAlreadyExsits(TransactionContext tc, DataPermission item) + { + bool Exist = false; + string sql = SQLParser.MakeSQL("SELECT COUNT(*) FROM DATAPERMISSION WHERE USERID=%n AND REFERENCEID=%n AND PERMISSIONTYPE=%n AND PAYROLLTYPEID=%n", item.UserID, item.ReferenceID, item.PermissionType, item.PayrollTypeID); + + Object obj = + tc.ExecuteScalar(sql); + Exist = Convert.ToInt32(obj) > 0 ? true : false; + return Exist; + } #endregion #region Delete function diff --git a/HRM.DA/Service/Users/DataPermissionService.cs b/HRM.DA/Service/Users/DataPermissionService.cs index 8cb4aca..d473957 100644 --- a/HRM.DA/Service/Users/DataPermissionService.cs +++ b/HRM.DA/Service/Users/DataPermissionService.cs @@ -1,13 +1,14 @@ -using System; +using Ease.Core.DataAccess; +using Ease.Core.Model; +using Ease.Core.Utility; +using HRM.BO; +using HRM.DA; +using HRM.Service; +using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -using HRM.BO; -using HRM.DA; -using Ease.Core.DataAccess; -using Ease.Core.Model; -using Ease.Core.Utility; namespace HRM.DA { @@ -239,6 +240,40 @@ namespace HRM.DA #endregion } } + public void Save(List oDataPermissions) + { + TransactionContext tc = null; + try + { + tc = TransactionContext.Begin(true); + int id = tc.GenerateID("DataPermission", "DataPermissionID"); + foreach (DataPermission oDataPermission in oDataPermissions) + { + bool exists = DataPermissionDA.PermissionAlreadyExsits(tc, oDataPermission); + if (oDataPermission.IsNew && !exists) + { + + base.SetObjectID(oDataPermission, id); + DataPermissionDA.Insert(tc, oDataPermission); + id++; + } + else + { + //DataPermissionDA.Update(tc, oDataPermission); + } + } + tc.End(); + } + catch (Exception e) + { + #region Handle Exception + if (tc != null) + tc.HandleError(); + ExceptionLog.Write(e); + throw new ServiceException("Failed to Save Leave Year: " + e.Message, e); + #endregion + } + } public void Delete(int id) { TransactionContext tc = null; diff --git a/HRM.UI/ClientApp/src/app/_services/auth/auth.service.ts b/HRM.UI/ClientApp/src/app/_services/auth/auth.service.ts index e90d77e..99e5e2d 100644 --- a/HRM.UI/ClientApp/src/app/_services/auth/auth.service.ts +++ b/HRM.UI/ClientApp/src/app/_services/auth/auth.service.ts @@ -266,4 +266,7 @@ export class AuthService { GetOperationDate() { return this.apiService.httpGet('/Authentication/getOperationDate'); } + addPermissions(data: DataPermission[]) { + return this.apiService.httpPost('/Authentication/addPermissions', data); + } } diff --git a/HRM.UI/ClientApp/src/app/authentication/data-permssion/data-permssion.component.html b/HRM.UI/ClientApp/src/app/authentication/data-permssion/data-permssion.component.html index ffb73f3..83af8ae 100644 --- a/HRM.UI/ClientApp/src/app/authentication/data-permssion/data-permssion.component.html +++ b/HRM.UI/ClientApp/src/app/authentication/data-permssion/data-permssion.component.html @@ -72,7 +72,7 @@
- +
{ + // let item = { + // userID: this._selectedUser.id, + // payrollTypeID: this._selectedPayroll, + // permissionTypeID: this._permissionType.value, + // refitemid: selectedID, + // permissionStatus: 2 + // }; + // data.push(item); + let datapermission: DataPermission = new DataPermission(); + datapermission.userID = this._selectedUser.id; + datapermission.payrollTypeID = this._selectedPayroll; + datapermission.permissionType = this._permissionType.value; + datapermission.referenceID = selectedID; + datapermission.permissionStatus = EnumMenuPermissionStatus.Added; + datapermissions.push(datapermission); + }); + this.loadingPanel.ShowLoadingPanel = true; + this.userService.addPermissions(datapermissions).subscribe( + (resp) => { + this.notificationService.showSuccess("Added permission successfully."); + this.loadGridView(); + this.loadingPanel.ShowLoadingPanel = false; + }, + (x) => { + this.loadingPanel.ShowLoadingPanel = false; + this.notificationService.showError(x.error); + } + ); + + } } - const data = { - userID: this._selectedUser.id, - payrollTypeID: this._selectedPayroll, - permissionTypeID: this._permissionType.value, - refitemid: referenceid, - permissionStatus: 2 - }; - this.loadingPanel.ShowLoadingPanel = true; - this.userService.addPermission(data).subscribe( - (resp) => { - this.notificationService.showSuccess("Added permission successfully."); - this.loadGridView(); - }, - (x) => { - this.loadingPanel.ShowLoadingPanel = false; - this.notificationService.showSuccess(x.error); - }, - () => { - this.loadingPanel.ShowLoadingPanel = false; + else { + var referenceid: number = 0; + if (this._permissionType.value == 1) { referenceid = this._categoryPicker.selectedID; } + else if (this._permissionType.value == 4) { referenceid = this._locationPicker.selectedID; } + else if (this._permissionType.value == 2) { referenceid = this._gradePicker.selectedID; } - }, - ); + if (referenceid == 0) { + this.notificationService.showWarning("Please select a Permission item"); + return; + } + const data = { + userID: this._selectedUser.id, + payrollTypeID: this._selectedPayroll, + permissionTypeID: this._permissionType.value, + refitemid: referenceid, + permissionStatus: 2 + }; + this.loadingPanel.ShowLoadingPanel = true; + this.userService.addPermission(data).subscribe( + (resp) => { + this.notificationService.showSuccess("Added permission successfully."); + this.loadGridView(); + }, + (x) => { + this.loadingPanel.ShowLoadingPanel = false; + this.notificationService.showError(x.error); + }, + () => { + this.loadingPanel.ShowLoadingPanel = false; + + }, + ); + } } @@ -211,7 +259,7 @@ export class DataPermssionComponent implements OnInit { }, () => { - this.notificationService.showSuccess("data deleted successfully."); + this.notificationService.showSuccess("Data deleted successfully."); this.loadGridView(); }); } diff --git a/HRM.UI/ClientApp/src/app/picker/dynamic-picker/Dynamic-Picker.ts b/HRM.UI/ClientApp/src/app/picker/dynamic-picker/Dynamic-Picker.ts index eddadd5..25282a1 100644 --- a/HRM.UI/ClientApp/src/app/picker/dynamic-picker/Dynamic-Picker.ts +++ b/HRM.UI/ClientApp/src/app/picker/dynamic-picker/Dynamic-Picker.ts @@ -405,6 +405,7 @@ export class DynamicPicker { selectedIDs: number[]; selectedObjects: Array; multiSelect: boolean; + checkChildren: boolean; selecteditemText: string = ''; pickerType: EnumDynamicpickerType; payrollTypeID?: number; @@ -419,6 +420,7 @@ export class DynamicPicker { this.selectedIDs = []; this.selecteditemText = ''; this.multiSelect = Multiselect; + this.checkChildren = this.multiSelect ? true : false; this.pickerType = PickerType; this.payrollTypeID = undefined; new DynamicPickerTypeDefination(PickerType, this, Multiselect); diff --git a/HRM.UI/ClientApp/src/app/picker/dynamic-picker/dynamic-picker.component.ts b/HRM.UI/ClientApp/src/app/picker/dynamic-picker/dynamic-picker.component.ts index dcb8b03..e7da043 100644 --- a/HRM.UI/ClientApp/src/app/picker/dynamic-picker/dynamic-picker.component.ts +++ b/HRM.UI/ClientApp/src/app/picker/dynamic-picker/dynamic-picker.component.ts @@ -100,7 +100,8 @@ export class DynamicPickerComponent implements OnInit, OnChanges, AfterContentCh this.checkMode = 'single'; } return { - checkChildren: true, + // checkChildren: true, + checkChildren: this.dynamicPickerView.checkChildren, checkParents: false, enabled: this.dynamicPickerView.multiSelect, mode: this.checkMode, diff --git a/HRM.UI/ClientApp/src/app/reports/report-viewer/report-viewer.component.html b/HRM.UI/ClientApp/src/app/reports/report-viewer/report-viewer.component.html index d88848e..7e708aa 100644 --- a/HRM.UI/ClientApp/src/app/reports/report-viewer/report-viewer.component.html +++ b/HRM.UI/ClientApp/src/app/reports/report-viewer/report-viewer.component.html @@ -119,6 +119,9 @@
+
+ +
diff --git a/HRM.UI/ClientApp/src/app/reports/report-viewer/report-viewer.component.ts b/HRM.UI/ClientApp/src/app/reports/report-viewer/report-viewer.component.ts index 9ba414f..a5848ee 100644 --- a/HRM.UI/ClientApp/src/app/reports/report-viewer/report-viewer.component.ts +++ b/HRM.UI/ClientApp/src/app/reports/report-viewer/report-viewer.component.ts @@ -169,6 +169,9 @@ export class ReportViewerComponent implements OnInit { public selectAllState: SelectAllCheckboxState = "unchecked"; multiselect = true; + multiEmpNo: string = ''; + hiddenMultiEmpNo = true; + emps: any[]; ngOnInit() { //debugger @@ -195,7 +198,20 @@ export class ReportViewerComponent implements OnInit { this.loadingPanel.ShowLoadingPanel = false; }); } - + this.employeeService.getAllEmployeeNameAndNo().subscribe( + (x) => { + //console.log(x); + this.emps = x; + }, + (x) => { + // console.log(x); + this.loadingPanel.ShowLoadingPanel = false; + }, + () => { + this.setReportColumns(this.reportType); + this.loadingPanel.ShowLoadingPanel = false; + } + ); this.setSelectableSettings(); this.loadBank(); @@ -1149,7 +1165,7 @@ export class ReportViewerComponent implements OnInit { this.topview = "decade"; this.apiService.selectedMenuName = 'Employee Wise Card Information'; } - else if (this.reportType === '721' ) { + else if (this.reportType === '721') { this.hiddenFromDate = false; this.hiddenToDate = false; this.PDFTitle = 'Employee Basic Information'; @@ -1508,7 +1524,18 @@ export class ReportViewerComponent implements OnInit { if (this.selectedEmp !== undefined) { this.empIds = this.selectedEmp.employeeID.toString(); } - // debugger; + if (this.multiEmpNo != null && this.multiEmpNo != '') { + debugger; + const list = this.multiEmpNo.split(','); + this.empIds = ''; + list.forEach(element => { + if (this.empIds !== '') { + this.empIds += ','; + } + let e = this.emps.find(e => e.employeeNo === element.trim()); + this.empIds += e != undefined ? e.id : ''; + }); + } // console.log(this.empIds); @@ -1564,7 +1591,7 @@ export class ReportViewerComponent implements OnInit { // this.loadGrid(); // } // ); - + const data = { reportid: this.reportType, selectedReport: this.selectedReport, diff --git a/HRM.UI/Controllers/Auth/AuthController.cs b/HRM.UI/Controllers/Auth/AuthController.cs index 51230d9..1c147ed 100644 --- a/HRM.UI/Controllers/Auth/AuthController.cs +++ b/HRM.UI/Controllers/Auth/AuthController.cs @@ -1,32 +1,33 @@ using AutoMapper; -using HRM.DA; -using HRM.UI.DTOs.Auth; -using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Configuration; -using Microsoft.IdentityModel.Tokens; -using System; -using System.Collections.Generic; -using System.IdentityModel.Tokens.Jwt; -using System.Linq; -using System.Security.Claims; -using System.Security.Cryptography; -using System.Threading.Tasks; using HRM.BO; -using System.Net.Http; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Authorization; -using Microsoft.Extensions.Options; -using HRM.UI.Api; -using System.Text; using HRM.BO.Configuration; -using Newtonsoft.Json; -using System.Data; -using System.Net; -using System.Reflection; +using HRM.DA; +using HRM.DA; using HRM.DA.Service; using HRM.Service; -using HRM.DA; +using HRM.UI.Api; +using HRM.UI.DTOs.Auth; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Options; +using Microsoft.IdentityModel.Tokens; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Data; +using System.Data.Common; +using System.IdentityModel.Tokens.Jwt; using System.IO; +using System.Linq; +using System.Net; +using System.Net.Http; +using System.Reflection; +using System.Security.Claims; +using System.Security.Cryptography; +using System.Text; +using System.Threading.Tasks; namespace HRM.UI.Controllers { @@ -1274,6 +1275,27 @@ namespace HRM.UI.Controllers } return Ok(dataPermission.ID); } + [HttpPost("addPermissions")] + public ActionResult addPermissions(List dataPermissions) + { + CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); + try + { + foreach (var item in dataPermissions) + { + item.PermissionStatus = EnumMenuPermissionStatus.Approved; + item.CreatedBy = currentUser.UserID; + item.CreatedDate = DateTime.Now; + } + _dataPermissionService.Save(dataPermissions); + } + catch (Exception e) + { + return StatusCode(StatusCodes.Status500InternalServerError, e.Message); + } + + return Ok(); + } [HttpGet("loadDataPermission/{userid}/{payrolltypeid}")] public ActionResult loadDataPermission(int userid, int payrolltypeid)