From 5afe91ce38363f2dfeeb7475ec69f77df6cf719e Mon Sep 17 00:00:00 2001 From: SamSys Date: Sun, 9 Feb 2025 20:36:53 +0330 Subject: [PATCH] EBI Excel generator --- .../EmployeeBankInfoExcelGenerator.cs | 227 ++++++++++++++++++ .../EmployeeBankInfoExcelViewModel.cs | 19 ++ .../IEmployeeBankInformationRepository.cs | 1 + .../EmployeeBankInformationSearchModel.cs | 7 +- ...mployeeBankInformationViewModelForExcel.cs | 17 ++ .../IEmployeeBankInformationApplication.cs | 4 +- .../EmployeeBankInformationApplication.cs | 6 + .../PersonalContractingPartyApplication.cs | 4 +- .../EmployeeBankInformationRepository.cs | 49 ++++ .../CreateBankInfoModal.cshtml | 3 +- .../Company/EmployeesBankInfo/Index.cshtml | 31 ++- .../Company/EmployeesBankInfo/Index.cshtml.cs | 37 ++- .../pages/EmployeesBankInfo/css/Index.css | 17 ++ .../js/CreateBankInfoModal.js | 37 +-- .../pages/EmployeesBankInfo/js/Index.js | 67 +++++- 15 files changed, 478 insertions(+), 48 deletions(-) create mode 100644 0_Framework/Excel/EmployeeBankInfo/EmployeeBankInfoExcelGenerator.cs create mode 100644 0_Framework/Excel/EmployeeBankInfo/EmployeeBankInfoExcelViewModel.cs create mode 100644 CompanyManagment.App.Contracts/EmployeeBankInformation/EmployeeBankInformationViewModelForExcel.cs diff --git a/0_Framework/Excel/EmployeeBankInfo/EmployeeBankInfoExcelGenerator.cs b/0_Framework/Excel/EmployeeBankInfo/EmployeeBankInfoExcelGenerator.cs new file mode 100644 index 00000000..5639c523 --- /dev/null +++ b/0_Framework/Excel/EmployeeBankInfo/EmployeeBankInfoExcelGenerator.cs @@ -0,0 +1,227 @@ +using System.Collections.Generic; +using System.Drawing; +using OfficeOpenXml; +using OfficeOpenXml.Style; +using System.Linq; +using OfficeOpenXml.Table.PivotTable; + +namespace _0_Framework.Excel.EmployeeBankInfo; + +public class EmployeeBankInfoExcelGenerator +{ + public static byte[] Generate(List list) + { + ExcelPackage.LicenseContext = LicenseContext.NonCommercial; + using var package = new ExcelPackage(); + var worksheet = package.Workbook.Worksheets.Add("EmployeeBankInfo"); + + worksheet.Cells[1, 1].Value = "نام پرسنل"; + + // پیدا کردن بیشترین تعداد حساب بانکی در بین افراد + int maxAccounts = list.Max(p => p.BankAccounts.Count); + + for (int i = 0; i < maxAccounts; i++) + { + worksheet.Cells[1, 2 + i * 3].Value = $"نام بانک"; + worksheet.Cells[1, 3 + i * 3].Value = $"مشخصات حساب"; + worksheet.Cells[1, 3 + i * 3, 1, 4 + i * 3].Merge = true; + } + + // تنظیم رنگ خاکستری برای هدر + using (var range = worksheet.Cells[1, 1, 1, 1 + maxAccounts * 3]) + { + range.Style.Font.Bold = true; + range.Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid; + range.Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.LightGray); + range.Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Center; + range.Style.Border.Right.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thick; + range.Style.Border.Left.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thick; + range.Style.Border.Bottom.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thick; + range.Style.Border.Top.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thick; + } + for (int i = 0; i < maxAccounts; i++) + { + worksheet.Cells[1, 2 + i * 3].Style.Border.Left.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thin; + worksheet.Cells[1, 2 + i * 3].Style.Border.Right.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thin; + worksheet.Cells[1, 3 + i * 3].Style.Border.Right.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thin; + worksheet.Cells[1, 3 + i * 3].Style.Border.Left.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thin; + } + + int row = 2; + + foreach (var personnel in list) + { + int startRow = row; + int endRow = row + 2; + + var personnelNameCell = worksheet.Cells[startRow, 1, endRow, 1]; + personnelNameCell.Merge = true; + personnelNameCell.Value = personnel.Name; + personnelNameCell.Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Center; + personnelNameCell.Style.VerticalAlignment = OfficeOpenXml.Style.ExcelVerticalAlignment.Center; + personnelNameCell.Style.Border.BorderAround(ExcelBorderStyle.Thick); + + int bankNameCol = 2; + for (int j = 0; j < maxAccounts; j++) + { + var bankCell = worksheet.Cells[row, bankNameCol, row + 2, bankNameCol]; + bankCell.Merge = true; + bankCell.Style.Border.BorderAround(ExcelBorderStyle.Thick); + bankCell.Style.Border.Right.Style = ExcelBorderStyle.Thin; + bankCell.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; + bankCell.Style.VerticalAlignment = ExcelVerticalAlignment.Center; + + + + worksheet.Cells[row, bankNameCol + 1].Style.Border.BorderAround(ExcelBorderStyle.Thin); + worksheet.Cells[row, bankNameCol + 1].Style.HorizontalAlignment = ExcelHorizontalAlignment.Right; + + + worksheet.Cells[row + 1, bankNameCol + 1].Style.Border.BorderAround(ExcelBorderStyle.Thin); + worksheet.Cells[row + 1, bankNameCol + 1].Style.HorizontalAlignment = ExcelHorizontalAlignment.Right; + + + + worksheet.Cells[row + 2, bankNameCol + 1].Style.Border.BorderAround(ExcelBorderStyle.Thin); + worksheet.Cells[row + 2, bankNameCol + 1].Style.Border.Bottom.Style = ExcelBorderStyle.Thick; + worksheet.Cells[row + 2, bankNameCol + 1].Style.HorizontalAlignment = ExcelHorizontalAlignment.Right; + + + + + worksheet.Cells[row, bankNameCol + 2].Style.Border.BorderAround(ExcelBorderStyle.Thin); + worksheet.Cells[row, bankNameCol + 2].Style.Border.Right.Style = ExcelBorderStyle.Thick; + + worksheet.Cells[row + 1, bankNameCol + 2].Style.Border.BorderAround(ExcelBorderStyle.Thin); + worksheet.Cells[row + 1, bankNameCol + 2].Style.Border.Right.Style = ExcelBorderStyle.Thick; + + + worksheet.Cells[row + 2, bankNameCol + 2].Style.Border.BorderAround(ExcelBorderStyle.Thin); + worksheet.Cells[row + 2, bankNameCol + 2].Style.Border.Right.Style = ExcelBorderStyle.Thick; + worksheet.Cells[row + 2, bankNameCol + 2].Style.Border.Bottom.Style = ExcelBorderStyle.Thick; + + + + var bankAccountsCount = personnel.BankAccounts.Count; + if (j < bankAccountsCount) + { + worksheet.Cells[row, bankNameCol + 1].Value = "کارت"; + + worksheet.Cells[row + 1, bankNameCol + 1].Value = "شبا"; + + worksheet.Cells[row + 2, bankNameCol + 1].Value = "حساب"; + + var bankInfo = personnel.BankAccounts.OrderByDescending(x => x.IsDefault).ToList()[j]; + + bankCell.Value = string.IsNullOrWhiteSpace(bankInfo.BankName) ? "-" : bankInfo.BankName; + + worksheet.Cells[row , bankNameCol + 2].Style.HorizontalAlignment = string.IsNullOrWhiteSpace(bankInfo.CardNumber)? ExcelHorizontalAlignment.Center:ExcelHorizontalAlignment.General; + worksheet.Cells[row + 1, bankNameCol + 2].Style.HorizontalAlignment = string.IsNullOrWhiteSpace(bankInfo.ShebaNumber) ? ExcelHorizontalAlignment.Center : ExcelHorizontalAlignment.General; + worksheet.Cells[row + 2, bankNameCol + 2].Style.HorizontalAlignment = string.IsNullOrWhiteSpace(bankInfo.AccountNumber) ? ExcelHorizontalAlignment.Center : ExcelHorizontalAlignment.General; + + + worksheet.Cells[row, bankNameCol + 2].Value = string.IsNullOrWhiteSpace(bankInfo.CardNumber) ? "-" : bankInfo.CardNumber; + worksheet.Cells[row + 1, bankNameCol + 2].Value = string.IsNullOrWhiteSpace(bankInfo.ShebaNumber) ? "-" : bankInfo.ShebaNumber; + worksheet.Cells[row + 2, bankNameCol + 2].Value = string.IsNullOrWhiteSpace(bankInfo.AccountNumber) ? "-" : bankInfo.AccountNumber; + + + + if (bankInfo.IsDefault) + { + worksheet.Cells[row, bankNameCol, row + 2, bankNameCol + 2].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid; + worksheet.Cells[row, bankNameCol, row + 2, bankNameCol + 2].Style.Fill.BackgroundColor.SetColor(1, 198, 224, 180); + } + + + } + else + { + bankCell.Value = "-"; + + worksheet.Cells[row, bankNameCol + 1].Value = "-"; + + worksheet.Cells[row + 1, bankNameCol + 1].Value = "-"; + + worksheet.Cells[row + 2, bankNameCol + 1].Value = "-"; + } + + worksheet.Columns[bankNameCol].Width = 15; + worksheet.Columns[bankNameCol + 2].Width = 16; + worksheet.Columns[1].Width = 16; + + + bankNameCol += 3; + } + + row += 3; + } + + // Adjust column widths + //worksheet.Cells[worksheet.Dimension.Address].AutoFitColumns(); + + + + worksheet.View.RightToLeft = true; + + return package.GetAsByteArray(); + } + + + + public static byte[] Generate2(List list) + { + ExcelPackage.LicenseContext = LicenseContext.NonCommercial; + using var package = new ExcelPackage(); + foreach (var employee in list) + { + var worksheet = package.Workbook.Worksheets.Add(employee.Name); + + // تنظیم هدر ستون‌ها + worksheet.Cells[1, 1].Value = "Bank Name"; + worksheet.Cells[1, 2].Value = "Card Number"; + worksheet.Cells[1, 3].Value = "Account Number"; + worksheet.Cells[1, 4].Value = "Sheba Number"; + worksheet.Cells[1, 5].Value = "Is Default"; + + for (int i = 0; i < employee.BankAccounts.Count; i++) + { + var account = employee.BankAccounts[i]; + int row = i + 2; + + worksheet.Cells[row, 1].Value = account.BankName; + worksheet.Cells[row, 2].Value = account.CardNumber; + worksheet.Cells[row, 3].Value = account.AccountNumber; + worksheet.Cells[row, 4].Value = account.ShebaNumber; + worksheet.Cells[row, 5].Value = account.IsDefault ? "Yes" : "No"; + + // استایل‌دهی به سطرها + worksheet.Cells[row, 1, row, 5].Style.Fill.PatternType = ExcelFillStyle.Solid; + worksheet.Cells[row, 1, row, 5].Style.Fill.BackgroundColor + .SetColor(account.IsDefault ? System.Drawing.Color.Green : System.Drawing.Color.White); + + // استایل‌دهی به متن + worksheet.Cells[row, 1, row, 5].Style.Font.Color + .SetColor(account.IsDefault ? System.Drawing.Color.White : System.Drawing.Color.Black); + } + } + + return package.GetAsByteArray(); + } + + private static void ApplyHeaderStyle(ExcelRange cell) + { + cell.Style.Font.Bold = true; + cell.Style.Fill.PatternType = ExcelFillStyle.Solid; + cell.Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.LightGray); + cell.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; + cell.Style.Border.BorderAround(ExcelBorderStyle.Thin); + } + + private static void ApplyGeneralDataStyle(ExcelRange cell) + { + cell.Style.Border.BorderAround(ExcelBorderStyle.Thin); + cell.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; + cell.Style.VerticalAlignment = ExcelVerticalAlignment.Center; + cell.Style.Fill.PatternType = ExcelFillStyle.Solid; + } +} \ No newline at end of file diff --git a/0_Framework/Excel/EmployeeBankInfo/EmployeeBankInfoExcelViewModel.cs b/0_Framework/Excel/EmployeeBankInfo/EmployeeBankInfoExcelViewModel.cs new file mode 100644 index 00000000..6b332ea9 --- /dev/null +++ b/0_Framework/Excel/EmployeeBankInfo/EmployeeBankInfoExcelViewModel.cs @@ -0,0 +1,19 @@ + +using System.Collections.Generic; + +namespace _0_Framework.Excel.EmployeeBankInfo; + +public class EmployeeBankInfoExcelViewModel +{ + public string Name { get; set; } + public List BankAccounts { get; set; } +} + +public class BankInfoExcelViewModel +{ + public string BankName { get; set; } + public string CardNumber { get; set; } + public string AccountNumber { get; set; } + public string ShebaNumber { get; set; } + public bool IsDefault { get; set; } // تعیین حساب پیش‌فرض +} \ No newline at end of file diff --git a/Company.Domain/EmployeeBankInformationAgg/IEmployeeBankInformationRepository.cs b/Company.Domain/EmployeeBankInformationAgg/IEmployeeBankInformationRepository.cs index b5fa80a1..6eae8bf8 100644 --- a/Company.Domain/EmployeeBankInformationAgg/IEmployeeBankInformationRepository.cs +++ b/Company.Domain/EmployeeBankInformationAgg/IEmployeeBankInformationRepository.cs @@ -19,5 +19,6 @@ namespace Company.Domain.EmployeeBankInformationAgg List GetAllByWorkshopId(long workshopId); + List SearchForExcel(long workshopId, EmployeeBankInformationSearchModel searchParams); } } diff --git a/CompanyManagment.App.Contracts/EmployeeBankInformation/EmployeeBankInformationSearchModel.cs b/CompanyManagment.App.Contracts/EmployeeBankInformation/EmployeeBankInformationSearchModel.cs index cac6b907..baaecd44 100644 --- a/CompanyManagment.App.Contracts/EmployeeBankInformation/EmployeeBankInformationSearchModel.cs +++ b/CompanyManagment.App.Contracts/EmployeeBankInformation/EmployeeBankInformationSearchModel.cs @@ -1,7 +1,10 @@ -namespace CompanyManagment.App.Contracts.EmployeeBankInformation; +using System.Collections.Generic; + +namespace CompanyManagment.App.Contracts.EmployeeBankInformation; public class EmployeeBankInformationSearchModel { - public long EmployeeId { get; set; } + public List EmployeeBankInfoIds { get; set; } = new(); + public long EmployeeId { get; set; } public long BankId { get; set; } } \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/EmployeeBankInformation/EmployeeBankInformationViewModelForExcel.cs b/CompanyManagment.App.Contracts/EmployeeBankInformation/EmployeeBankInformationViewModelForExcel.cs new file mode 100644 index 00000000..bda5d6a7 --- /dev/null +++ b/CompanyManagment.App.Contracts/EmployeeBankInformation/EmployeeBankInformationViewModelForExcel.cs @@ -0,0 +1,17 @@ +using System.Collections.Generic; + +namespace CompanyManagment.App.Contracts.EmployeeBankInformation; + +public class EmployeeBankInformationViewModelForExcel +{ + public string EmployeeName { get; set; } + public List BankInformationList { get; set; } +} +public class BankInformationDtoForExcel +{ + public string BankName { get; set; } + public string CardNumber { get; set; } + public string ShebaNumber { get; set; } + public string BankAccountNumber { get; set; } + public bool IsDefault { get; set; } +} \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/EmployeeBankInformation/IEmployeeBankInformationApplication.cs b/CompanyManagment.App.Contracts/EmployeeBankInformation/IEmployeeBankInformationApplication.cs index 6b2b791a..f052fb5f 100644 --- a/CompanyManagment.App.Contracts/EmployeeBankInformation/IEmployeeBankInformationApplication.cs +++ b/CompanyManagment.App.Contracts/EmployeeBankInformation/IEmployeeBankInformationApplication.cs @@ -9,7 +9,9 @@ namespace CompanyManagment.App.Contracts.EmployeeBankInformation OperationResult GroupCreate(long workshopId, List command); OperationResult Edit(EditEmployeeInformation command); List Search(long workshopId, EmployeeBankInformationSearchModel searchParams); - GroupedEmployeeBankInformationViewModel GetByEmployeeId(long workshopId, long employeeId); + List SearchForExcel(long workshopId, + EmployeeBankInformationSearchModel searchParams); + GroupedEmployeeBankInformationViewModel GetByEmployeeId(long workshopId, long employeeId); EmployeeBankInformationViewModel GetDetails(long id); OperationResult Remove(long id); OperationResult RemoveByEmployeeId(long workshopId, long employeeId); diff --git a/CompanyManagment.Application/EmployeeBankInformationApplication.cs b/CompanyManagment.Application/EmployeeBankInformationApplication.cs index 842dec47..81d71500 100644 --- a/CompanyManagment.Application/EmployeeBankInformationApplication.cs +++ b/CompanyManagment.Application/EmployeeBankInformationApplication.cs @@ -149,6 +149,12 @@ namespace CompanyManagment.Application { return _employeeBankInformationRepository.Search(workshopId, searchParams); } + + public List SearchForExcel(long workshopId, EmployeeBankInformationSearchModel searchParams) + { + return _employeeBankInformationRepository.SearchForExcel(workshopId, searchParams); + } + public List GetAllByWorkshopId(long workshopId, EmployeeBankInformationSearchModel searchParams) { return _employeeBankInformationRepository.GetAllByWorkshopId(workshopId); diff --git a/CompanyManagment.Application/PersonalContractingPartyApplication.cs b/CompanyManagment.Application/PersonalContractingPartyApplication.cs index 6aa564db..df060edf 100644 --- a/CompanyManagment.Application/PersonalContractingPartyApplication.cs +++ b/CompanyManagment.Application/PersonalContractingPartyApplication.cs @@ -80,8 +80,8 @@ public class PersonalContractingPartyApplication : IPersonalContractingPartyApp { case "0000000000": case "1111111111": - case "22222222222": - case "33333333333": + case "2222222222": + case "3333333333": case "4444444444": case "5555555555": case "6666666666": diff --git a/CompanyManagment.EFCore/Repository/EmployeeBankInformationRepository.cs b/CompanyManagment.EFCore/Repository/EmployeeBankInformationRepository.cs index 41dc0e2b..a6d3c8a4 100644 --- a/CompanyManagment.EFCore/Repository/EmployeeBankInformationRepository.cs +++ b/CompanyManagment.EFCore/Repository/EmployeeBankInformationRepository.cs @@ -216,5 +216,54 @@ namespace CompanyManagment.EFCore.Repository } + + public List SearchForExcel(long workshopId, EmployeeBankInformationSearchModel searchParams) + { + var bankInfoQuery = _companyContext.EmployeeBankInformationSet.Where(x => x.WorkshopId == workshopId) + .Include(x => x.Employee).Include(x => x.Bank) + .Select(x => new + { + x.Bank.BankName, + x.BankId, + FullName = (x.Employee.FName + " " + x.Employee.LName), + x.EmployeeId, + x.WorkshopId, + Id = x.id, + x.CardNumber, + x.ShebaNumber, + x.BankAccountNumber, + x.IsDefault + }); + + if (searchParams.BankId > 0) + bankInfoQuery = bankInfoQuery.Where(x => x.BankId == searchParams.BankId); + + if (searchParams.EmployeeId > 0) + bankInfoQuery = bankInfoQuery.Where(x => x.EmployeeId == searchParams.EmployeeId); + + if (searchParams.EmployeeBankInfoIds.Any()) + bankInfoQuery = bankInfoQuery.Where(x => searchParams.EmployeeBankInfoIds.Contains(x.Id)); + + var bankInfoList = bankInfoQuery.ToList(); + + + + + return bankInfoList.GroupBy(x => x.EmployeeId).Select(x => + { + return new EmployeeBankInformationViewModelForExcel() + { + EmployeeName = x.FirstOrDefault()?.FullName ?? "", + BankInformationList = x.Select(y => new BankInformationDtoForExcel() + { + BankName = y.BankName, + CardNumber = y.CardNumber, + BankAccountNumber = y.BankAccountNumber, + ShebaNumber = y.ShebaNumber, + IsDefault = y.IsDefault + }).ToList() + }; + }).ToList(); + } } } diff --git a/ServiceHost/Areas/Client/Pages/Company/EmployeesBankInfo/CreateBankInfoModal.cshtml b/ServiceHost/Areas/Client/Pages/Company/EmployeesBankInfo/CreateBankInfoModal.cshtml index 5163bcf5..bb647d76 100644 --- a/ServiceHost/Areas/Client/Pages/Company/EmployeesBankInfo/CreateBankInfoModal.cshtml +++ b/ServiceHost/Areas/Client/Pages/Company/EmployeesBankInfo/CreateBankInfoModal.cshtml @@ -118,7 +118,8 @@ - +@* *@ + diff --git a/ServiceHost/Areas/Client/Pages/Company/EmployeesBankInfo/Index.cshtml.cs b/ServiceHost/Areas/Client/Pages/Company/EmployeesBankInfo/Index.cshtml.cs index 75905ca1..1d081da1 100644 --- a/ServiceHost/Areas/Client/Pages/Company/EmployeesBankInfo/Index.cshtml.cs +++ b/ServiceHost/Areas/Client/Pages/Company/EmployeesBankInfo/Index.cshtml.cs @@ -1,4 +1,5 @@ using _0_Framework.Application; +using _0_Framework.Excel.EmployeeBankInfo; using CompanyManagment.App.Contracts.Bank; using CompanyManagment.App.Contracts.Employee; using CompanyManagment.App.Contracts.EmployeeBankInformation; @@ -166,9 +167,13 @@ namespace ServiceHost.Areas.Client.Pages.Company.EmployeesBankInfo public IActionResult OnPostEdit(EditEmployeeInformation command) { command.WorkshopId = _workshopId; - command.CardNumber = command.CardNumber.Replace("-", ""); - command.ShebaNumber = command.ShebaNumber.Replace("-", ""); - var result = _employeeBankInformationApplication.Edit(command); + if (!string.IsNullOrWhiteSpace(command.CardNumber)) + command.CardNumber = command.CardNumber.Replace("-", ""); + + if (!string.IsNullOrWhiteSpace(command.ShebaNumber)) + command.ShebaNumber = command.ShebaNumber.Replace("-", ""); + + var result = _employeeBankInformationApplication.Edit(command); return new JsonResult(new { success = result.IsSuccedded, @@ -210,5 +215,31 @@ namespace ServiceHost.Areas.Client.Pages.Company.EmployeesBankInfo var contentType = Tools.GetContentTypeImage(Path.GetExtension(path)); return PhysicalFile(path, contentType); } + + public IActionResult OnGetDownloadExcelAll(string idList) + { + var ids = idList.ExtractNumbers(); + + var employeeBankInformationViewModelForExcels = _employeeBankInformationApplication.SearchForExcel(_workshopId, + new EmployeeBankInformationSearchModel() { EmployeeBankInfoIds = ids }); + + var resultViewModel = employeeBankInformationViewModelForExcels.Select(x=>new EmployeeBankInfoExcelViewModel + { + Name = x.EmployeeName, + BankAccounts = x.BankInformationList.Select(b=>new BankInfoExcelViewModel() + { + IsDefault = b.IsDefault, + ShebaNumber = b.ShebaNumber, + AccountNumber = b.BankAccountNumber, + BankName = b.BankName, + CardNumber = b.CardNumber + }).ToList() + }).ToList(); + + var bytes = EmployeeBankInfoExcelGenerator.Generate(resultViewModel); + return File(bytes, + "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", + $"اطلاعات بانکی پرسنل.xlsx"); + } } } diff --git a/ServiceHost/wwwroot/AssetsClient/pages/EmployeesBankInfo/css/Index.css b/ServiceHost/wwwroot/AssetsClient/pages/EmployeesBankInfo/css/Index.css index a8d8dc1d..dc9a0740 100644 --- a/ServiceHost/wwwroot/AssetsClient/pages/EmployeesBankInfo/css/Index.css +++ b/ServiceHost/wwwroot/AssetsClient/pages/EmployeesBankInfo/css/Index.css @@ -193,7 +193,24 @@ /************************ Radio Button Input (Like Checkbox appearance) ************************/ +.btn-excel { + border-radius: 7px; + padding: 3px 7px; + color: #000000; + background-color: #afffcc +} +.btn-excel span { + color: #1E293B; + font-size: 12px; + font-style: normal; + font-weight: 400; + line-height: 24px; +} + +.btn-excel:hover { + background-color: #a8ebc1; +} @media (max-width: 1366px) { .fineListModal-width { diff --git a/ServiceHost/wwwroot/AssetsClient/pages/EmployeesBankInfo/js/CreateBankInfoModal.js b/ServiceHost/wwwroot/AssetsClient/pages/EmployeesBankInfo/js/CreateBankInfoModal.js index ec410d8a..c235dd8e 100644 --- a/ServiceHost/wwwroot/AssetsClient/pages/EmployeesBankInfo/js/CreateBankInfoModal.js +++ b/ServiceHost/wwwroot/AssetsClient/pages/EmployeesBankInfo/js/CreateBankInfoModal.js @@ -126,7 +126,7 @@ $(document).on('change', '#employeeSelectCreate', function () { if (item.shebaNumber !== null) resultBankCount++; html += ` -
+
-
- - -
+
`; @@ -464,8 +447,8 @@ function removeBank(id) { $('.alert-success-msg').hide(); $('.alert-success-msg p').text(''); }, 2000); - - $(`[data-employee-id="${id}"]`).remove(); + + $(`[data-bank-id="${id}"]`).remove(); updateRows(); $('#EmployeeBankListAjax').html(''); loadEmployeeBankList(); @@ -527,14 +510,12 @@ function removeRecordAfterAddNewItem(id) { function editNewItem(newId) { $('#addNewItemBtn').hide(); - $('#editNewItemBtn').show(); + $('#editNewItemBtn').show().attr('onclick', `saveEditNewItem(${newId})`); $('#createData').addClass("disable"); let employeeBankInfo = command.find(employee => employee.newItemId === newId); - $('#editNewItemBtn').attr('onclick', 'saveEditNewItem(' + newId + ')'); - $('#bankSelectCreate').val(employeeBankInfo.BankId).trigger('change'); $('#CardNumber').val(employeeBankInfo.CardNumber); $('#ShebaNumber').val(employeeBankInfo.ShebaNumber); @@ -543,13 +524,13 @@ function editNewItem(newId) { $('#CardNumber').mask("0000-0000-0000-0000", { placeholder: "XXXX-XXXX-XXXX-XXXX" }); - $('#CardNumber').val(cardNumber).keyup(); + $('#CardNumber').val(employeeBankInfo.CardNumber).keyup(); $('#ShebaNumber').mask("IR-00-0000-0000-0000-0000-0000-00", { placeholder: "IR-XX-XXXX-XXXX-XXXX-XXXX-XXXX-XX" }); - $('#ShebaNumber').val(shebaNumber).keyup(); + $('#ShebaNumber').val(employeeBankInfo.ShebaNumber).keyup(); } function saveEditNewItem(newId) { @@ -675,7 +656,7 @@ function saveEditNewItem(newId) { } function updateRows() { - $('.load-create-row.width1').each(function (index) { - $(this).find('span.row-number').text(index + 1); + $('.load-create-row .width1').each(function (index) { + $(this).find('label span.row-number').text(index + 1); }); } \ No newline at end of file diff --git a/ServiceHost/wwwroot/AssetsClient/pages/EmployeesBankInfo/js/Index.js b/ServiceHost/wwwroot/AssetsClient/pages/EmployeesBankInfo/js/Index.js index a1d19844..e42c7bee 100644 --- a/ServiceHost/wwwroot/AssetsClient/pages/EmployeesBankInfo/js/Index.js +++ b/ServiceHost/wwwroot/AssetsClient/pages/EmployeesBankInfo/js/Index.js @@ -1,4 +1,21 @@ -var searchName = ''; +$(document).ready(function () { + let $checkAll = $("#checkAll2"); + let $checkboxes = $(".foo"); + + $checkAll.on("change", function () { + $checkboxes.prop("checked", this.checked); + }); + + $checkboxes.on("change", function () { + let allChecked = $checkboxes.length === $checkboxes.filter(":checked").length; + let someChecked = $checkboxes.filter(":checked").length > 0; + $checkAll.prop("checked", allChecked); + $checkAll.prop("indeterminate", !allChecked && someChecked); + }); +}); + + +var searchName = ''; var searchBank = ''; $(document).ready(function () { @@ -142,10 +159,11 @@ function loadEmployeeBankList() { }" id="Employees">
@@ -375,4 +393,43 @@ function removeByEmployeeId(id) { console.log(err); } }); +} + +function downloadExcelAll() { + if (!($('.foo:checkbox').is(":checked"))) { + $('.alert-msg').show(); + $('.alert-msg p').text('هیچ موردی انتخاب نشده است.'); + setTimeout(function () { + $('.alert-msg').hide(); + $('.alert-msg p').text(''); + }, 3500); + return; + } + + var idlist = ""; + $('.foo').each(function () { + if ($(this).is(":checked")) { + + var a = $(this).val(); + var b = a + "+"; + idlist += b; + + } + }); + + var filterArray = []; + $("input[name='filter[]']:checked").each(function () { + filterArray.push($(this).val()); + }); + + + if (idlist !== "") { + //var url = CheckoutExcelAllUrl + "&idList=" + idlist; + var url = CheckoutExcelAllUrl + "&idList=" + encodeURIComponent(idlist); + + filterArray.forEach(function (filter) { + url += "&filter=" + encodeURIComponent(filter); + }); + window.open(url, "_blank"); + } } \ No newline at end of file