diff --git a/CompanyManagement.Infrastructure.Excel/InstitutionContract/InstitutionContractExcelGenerator.cs b/CompanyManagement.Infrastructure.Excel/InstitutionContract/InstitutionContractExcelGenerator.cs index e17f21df..24f5ce8a 100644 --- a/CompanyManagement.Infrastructure.Excel/InstitutionContract/InstitutionContractExcelGenerator.cs +++ b/CompanyManagement.Infrastructure.Excel/InstitutionContract/InstitutionContractExcelGenerator.cs @@ -8,86 +8,130 @@ using System.Text.RegularExpressions; namespace CompanyManagement.Infrastructure.Excel.InstitutionContract; +// Enum برای تعریف ستون‌های موجود +public enum ExcelColumnType +{ + RowNumber, // ردیف + PhysicalContract, // قرارداد فیزیکی + ContractNo, // شماره قرارداد + Representative, // معرف + ContractingPartyName, // طرف حساب + ArchiveCode, // شماره کارفرما + EmployerName, // کارفرما + WorkshopName, // کارگاه‌ها (چندخطی) + WorkshopCount, // تعداد کارگاه + EmployeeCount, // مجموع پرسنل + ContractStartDate, // شروع قرارداد + ContractEndDate, // پایان قرارداد + InstallmentAmount, // مبلغ قسط + ContractAmount, // مبلغ قرارداد + FinancialStatus // وضعیت مالی +} + +// کلاس کانفیگ برای تنظیم ستون‌های نمایشی +public class ExcelColumnConfig +{ + public List VisibleColumns { get; set; } + + public ExcelColumnConfig() + { + // فعلاً تمام ستون‌ها فعال هستند + VisibleColumns = new List + { + ExcelColumnType.RowNumber, + ExcelColumnType.PhysicalContract, + ExcelColumnType.ContractNo, + ExcelColumnType.Representative, + ExcelColumnType.ContractingPartyName, + ExcelColumnType.ArchiveCode, + ExcelColumnType.EmployerName, + ExcelColumnType.WorkshopName, + ExcelColumnType.WorkshopCount, + ExcelColumnType.EmployeeCount, + ExcelColumnType.ContractStartDate, + ExcelColumnType.ContractEndDate, + ExcelColumnType.InstallmentAmount, + ExcelColumnType.ContractAmount, + ExcelColumnType.FinancialStatus + }; + } +} + public class InstitutionContractExcelGenerator { + private static ExcelColumnConfig _columnConfig = new ExcelColumnConfig(); - public static byte[] GenerateExcel(List institutionContractViewModels) + public static byte[] GenerateExcel(List contractViewModels) { ExcelPackage.License.SetNonCommercialOrganization("Gozareshgir Noncommercial organization"); using var package = new ExcelPackage(); - var allWorksheet = package.Workbook.Worksheets.Add("همه"); - - var blueWorksheet = package.Workbook.Worksheets.Add("آبی"); - blueWorksheet.TabColor = Color.LightBlue; - - var grayWorksheet = package.Workbook.Worksheets.Add("خاکستری"); - grayWorksheet.TabColor = Color.LightGray; - - var redWorksheet = package.Workbook.Worksheets.Add("قرمز"); - redWorksheet.TabColor = Color.LightCoral; - - var purpleWorksheet = package.Workbook.Worksheets.Add("بنفش"); - purpleWorksheet.TabColor = Color.MediumPurple; - - var blackWorksheet = package.Workbook.Worksheets.Add("مشکی"); - blackWorksheet.TabColor = Color.DimGray; - - var yellowWorksheet = package.Workbook.Worksheets.Add("زرد"); - yellowWorksheet.TabColor = Color.Yellow; - - var whiteWorksheet = package.Workbook.Worksheets.Add("سفید"); - whiteWorksheet.TabColor = Color.White; - - - CreateExcelSheet(institutionContractViewModels, allWorksheet); - - var blueContracts = institutionContractViewModels.Where(x=>x.ExpireColor == "blue").ToList(); - CreateExcelSheet(blueContracts, blueWorksheet); - institutionContractViewModels = institutionContractViewModels.Except(blueContracts).ToList(); - - var grayContracts = institutionContractViewModels.Where(x => x.IsContractingPartyBlock == "true").ToList(); - CreateExcelSheet(grayContracts, grayWorksheet); - institutionContractViewModels = institutionContractViewModels.Except(grayContracts).ToList(); - - var redContracts = institutionContractViewModels.Where(x=>x.ExpireColor == "red").ToList(); - CreateExcelSheet(redContracts, redWorksheet); - institutionContractViewModels = institutionContractViewModels.Except(redContracts).ToList(); - - var purpleContracts = institutionContractViewModels.Where(x=>x.ExpireColor == "purple").ToList(); - CreateExcelSheet(purpleContracts, purpleWorksheet); - institutionContractViewModels = institutionContractViewModels.Except(purpleContracts).ToList(); - var blackContracts = institutionContractViewModels.Where(x=>x.ExpireColor == "black").ToList(); - CreateExcelSheet(blackContracts, blackWorksheet); - institutionContractViewModels = institutionContractViewModels.Except(blackContracts).ToList(); - - var yellowContracts = institutionContractViewModels - .Where(x => string.IsNullOrWhiteSpace(x.ExpireColor) && x.WorkshopCount == "0").ToList(); - CreateExcelSheet(yellowContracts, yellowWorksheet); - institutionContractViewModels = institutionContractViewModels.Except(yellowContracts).ToList(); - - var otherContracts = institutionContractViewModels; - CreateExcelSheet(otherContracts, whiteWorksheet); + // ایجاد شیت برای هر تب با داده‌های مربوطه + foreach (var viewModel in contractViewModels) + { + var worksheet = CreateWorksheet(package, viewModel.Tab); + CreateExcelSheet(viewModel.GetInstitutionContractListItemsViewModels ?? new List(), worksheet); + } return package.GetAsByteArray(); } - private static void CreateExcelSheet(List institutionContractViewModels, ExcelWorksheet worksheet) + /// + /// ایجاد شیت بر اساس نوع تب + /// + private static ExcelWorksheet CreateWorksheet(ExcelPackage package, InstitutionContractListStatus? status) { - // Headers - worksheet.Cells[1, 1].Value = "شماره قرارداد"; - worksheet.Cells[1, 2].Value = "طرف حساب"; - worksheet.Cells[1, 3].Value = "شماره کارفرما"; - worksheet.Cells[1, 4].Value = "کارفرما ها"; - worksheet.Cells[1, 5].Value = "کارگاه ها"; - worksheet.Cells[1, 6].Value = "مجبوع پرسنل"; - worksheet.Cells[1, 7].Value = "شروع قرارداد"; - worksheet.Cells[1, 8].Value = "پایان قرارداد"; - worksheet.Cells[1, 9].Value = "مبلغ قرارداد (بدون کارگاه)"; - worksheet.Cells[1, 10].Value = "مبلغ قرارداد"; - worksheet.Cells[1, 11].Value = "وضعیت مالی"; + return status switch + { + InstitutionContractListStatus.DeactiveWithDebt => + CreateColoredWorksheet(package, "غیرفعال دارای بدهی", Color.LightBlue), + + InstitutionContractListStatus.Deactive => + CreateColoredWorksheet(package, "غیرفعال", Color.LightGray), + + InstitutionContractListStatus.PendingForRenewal => + CreateColoredWorksheet(package, "در انتظار تمدید", Color.LightCoral), + + InstitutionContractListStatus.Free => + CreateColoredWorksheet(package, "بنفش", Color.MediumPurple), + + InstitutionContractListStatus.Block => + CreateColoredWorksheet(package, "بلاک", Color.DimGray), + + InstitutionContractListStatus.WithoutWorkshop => + CreateColoredWorksheet(package, "بدون کارگاه", Color.Yellow), + + InstitutionContractListStatus.Active => + CreateColoredWorksheet(package, "فعال", Color.White), + + InstitutionContractListStatus.PendingForVerify => + CreateColoredWorksheet(package, "در انتظار تایید", Color.OrangeRed), + + null => CreateColoredWorksheet(package, "کل قرارداد ها", Color.White), + _ => throw new ArgumentOutOfRangeException(nameof(status), status, null) + }; + } - using (var range = worksheet.Cells[1, 1, 1, 11]) + /// + /// ایجاد شیت با رنگ تب + /// + private static ExcelWorksheet CreateColoredWorksheet(ExcelPackage package, string sheetName, Color tabColor) + { + var worksheet = package.Workbook.Worksheets.Add(sheetName); + worksheet.TabColor = tabColor; + return worksheet; + } + + private static void CreateExcelSheet(List contractItems, ExcelWorksheet worksheet) + { + // دریافت نقشه ستون‌های مرئی + var visibleColumnIndices = GetVisibleColumnIndices(); + int columnCount = visibleColumnIndices.Count; + + // تنظیم Headers + SetupHeaders(worksheet, visibleColumnIndices, columnCount); + + using (var range = worksheet.Cells[1, 1, 1, columnCount]) { range.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; range.Style.VerticalAlignment = ExcelVerticalAlignment.Center; @@ -110,30 +154,35 @@ public class InstitutionContractExcelGenerator int row = 2; - for (int i = 0; i < institutionContractViewModels.Count; i++) + for (int i = 0; i < contractItems.Count; i++) { - var contract = institutionContractViewModels[i]; - var employers = contract.EmployerViewModels?.ToList() ?? new(); - var workshops = contract.WorkshopViewModels?.ToList() ?? new(); + var contract = contractItems[i]; + var employers = contract.EmployerNames?.ToList() ?? new(); + var workshops = contract.WorkshopNames?.ToList() ?? new(); - int maxRows = Math.Max(employers.Count, workshops.Count); - maxRows = Math.Max(1, maxRows); + int maxRows = 1; // هر قرارداد فقط یک ردیف؛ نیازی به مرج عمودی نیست int startRow = row; int endRow = row + maxRows - 1; - // 🎨 دریافت رنگ پس‌زمینه از مقدار رنگ موجود در داده - string colorName = contract.ExpireColor.ToLower(); - var fillColor = GetColorByName(colorName, contract.WorkshopCount, contract.IsContractingPartyBlock); + // 🎨 دریافت رنگ پس‌زمینه بر اساس وضعیت قرارداد + var fillColor = GetColorByStatus(contract.ListStatus, contract.WorkshopsCount); for (int j = 0; j < maxRows; j++) { int currentRow = row + j; - worksheet.Cells[currentRow, 4].Value = j < employers.Count ? employers[j].FullName : null; - worksheet.Cells[currentRow, 5].Value = j < workshops.Count ? workshops[j].WorkshopFullName : null; + // پر کردن ستون‌های employer و workshop + var employerColIndex = GetColumnIndexForType(ExcelColumnType.EmployerName, visibleColumnIndices); + var workshopColIndex = GetColumnIndexForType(ExcelColumnType.WorkshopName, visibleColumnIndices); - for (int col = 1; col <= 11; col++) + if (employerColIndex > 0) + worksheet.Cells[currentRow, employerColIndex].Value = j < employers.Count ? employers[j] : null; + + if (workshopColIndex > 0) + worksheet.Cells[currentRow, workshopColIndex].Value = j < workshops.Count ? workshops[j] : null; + + for (int col = 1; col <= columnCount; col++) { var cell = worksheet.Cells[currentRow, col]; @@ -154,109 +203,226 @@ public class InstitutionContractExcelGenerator } // 🧱 مرج و مقداردهی ستون‌های اصلی - worksheet.Cells[startRow, 1, endRow, 1].Merge = true; - worksheet.Cells[startRow, 1].Value = contract.ContractNo; - - worksheet.Cells[startRow, 2, endRow, 2].Merge = true; - worksheet.Cells[startRow, 2].Value = contract.ContractingPartyName; - - worksheet.Cells[startRow, 3, endRow, 3].Merge = true; - worksheet.Cells[startRow, 3].Value = contract.ArchiveCode; - - worksheet.Cells[startRow, 6, endRow, 6].Merge = true; - worksheet.Cells[startRow, 6].Value = contract.EmployeeCount; - - worksheet.Cells[startRow, 7, endRow, 7].Merge = true; - worksheet.Cells[startRow, 7].Value = contract.ContractStartFa; - - worksheet.Cells[startRow, 8, endRow, 8].Merge = true; - worksheet.Cells[startRow, 8].Value = contract.ContractEndFa; - - worksheet.Cells[startRow, 9, endRow, 9].Merge = true; - var contractWithoutWorkshopAmountCell = worksheet.Cells[startRow, 9]; - contractWithoutWorkshopAmountCell.Value = contract.WorkshopCount == "0" ? MoneyToDouble(contract.ContractAmount) : ""; - contractWithoutWorkshopAmountCell.Style.Numberformat.Format = "#,##0"; - - - worksheet.Cells[startRow, 10, endRow, 10].Merge = true; - var contractAmountCell = worksheet.Cells[startRow, 10]; - contractAmountCell.Value = contract.WorkshopCount != "0" ? MoneyToDouble(contract.ContractAmount) : ""; - contractAmountCell.Style.Numberformat.Format = "#,##0"; - - - worksheet.Cells[startRow, 11, endRow, 11].Merge = true; - var balance = MoneyToDouble(contract.BalanceStr); - var balanceCell = worksheet.Cells[startRow, 11]; - balanceCell.Value = balance; - balanceCell.Style.Numberformat.Format = "#,##0"; - - if (balance > 0) - balanceCell.Style.Font.Color.SetColor(Color.Red); - else if (balance < 0) - balanceCell.Style.Font.Color.SetColor(Color.Green); + FillColumnData(worksheet, contract, startRow, endRow, visibleColumnIndices); // 📦 بوردر ضخیم خارجی برای هر سطر - var boldRange = worksheet.Cells[startRow, 1, endRow, 11]; + var boldRange = worksheet.Cells[startRow, 1, endRow, columnCount]; boldRange.Style.Border.BorderAround(ExcelBorderStyle.Medium); row += maxRows; } + SetupPrintSettings(worksheet, visibleColumnIndices, columnCount); + } + /// + /// دریافت فهرست ستون‌های مرئی بر اساس کانفیگ + /// + private static List GetVisibleColumnIndices() + { + return _columnConfig.VisibleColumns; + } + /// + /// دریافت شماره ستون برای یک نوع ستون خاص + /// + private static int GetColumnIndexForType(ExcelColumnType columnType, List visibleColumns) + { + var index = visibleColumns.IndexOf(columnType); + return index >= 0 ? index + 1 : 0; // 1-based indexing + } + + /// + /// دریافت متن header برای یک نوع ستون + /// + private static string GetColumnHeader(ExcelColumnType columnType) + { + return columnType switch + { + ExcelColumnType.RowNumber => "ردیف", + ExcelColumnType.PhysicalContract => "قرارداد فیزیکی", + ExcelColumnType.ContractNo => "شماره قرارداد", + ExcelColumnType.Representative => "معرف", + ExcelColumnType.ContractingPartyName => "طرف حساب", + ExcelColumnType.ArchiveCode => "شماره کارفرما", + ExcelColumnType.EmployerName => "کارفرما", + ExcelColumnType.WorkshopName => "کارگاه‌ها", + ExcelColumnType.WorkshopCount => "تعداد کارگاه", + ExcelColumnType.EmployeeCount => "مجموع پرسنل", + ExcelColumnType.ContractStartDate => "شروع قرارداد", + ExcelColumnType.ContractEndDate => "پایان قرارداد", + ExcelColumnType.InstallmentAmount => "مبلغ قسط", + ExcelColumnType.ContractAmount => "مبلغ قرارداد", + ExcelColumnType.FinancialStatus => "وضعیت مالی", + _ => "" + }; + } + + /// + /// تنظیم Header‌های ستون‌ها + /// + private static void SetupHeaders(ExcelWorksheet worksheet, List visibleColumns, int columnCount) + { + for (int i = 0; i < visibleColumns.Count; i++) + { + worksheet.Cells[1, i + 1].Value = GetColumnHeader(visibleColumns[i]); + } + } + + /// + /// پر کردن داده‌های ستون‌ها برای یک قرارداد + /// + private static void FillColumnData(ExcelWorksheet worksheet, GetInstitutionContractListItemsViewModel contract, int startRow, int endRow, List visibleColumns) + { + for (int i = 0; i < visibleColumns.Count; i++) + { + int columnIndex = i + 1; // 1-based indexing + var columnType = visibleColumns[i]; + + // Merge cells for non-repeating columns + worksheet.Cells[startRow, columnIndex, endRow, columnIndex].Merge = true; + + var cell = worksheet.Cells[startRow, columnIndex]; + + switch (columnType) + { + case ExcelColumnType.RowNumber: + // TODO: مقدار ردیف رو از user input دریافت کن + break; + case ExcelColumnType.PhysicalContract: + // TODO: مقدار قرارداد فیزیکی رو دریافت کن + break; + case ExcelColumnType.ContractNo: + cell.Value = contract.ContractNo; + break; + case ExcelColumnType.Representative: + cell.Value = contract.RepresentativeName; + break; + case ExcelColumnType.ContractingPartyName: + cell.Value = contract.ContractingPartyName; + break; + case ExcelColumnType.ArchiveCode: + cell.Value = contract.ArchiveNo; + break; + case ExcelColumnType.EmployerName: + // این ستون چندخطی است و داخل loop پر می‌شود + break; + case ExcelColumnType.WorkshopName: + // این ستون چندخطی است و داخل loop پر می‌شود + break; + case ExcelColumnType.WorkshopCount: + cell.Value = contract.WorkshopsCount; + break; + case ExcelColumnType.EmployeeCount: + cell.Value = contract.EmployeesCount; + break; + case ExcelColumnType.ContractStartDate: + cell.Value = contract.ContractStartFa; + break; + case ExcelColumnType.ContractEndDate: + cell.Value = contract.ContractEndFa; + break; + case ExcelColumnType.InstallmentAmount: + cell.Value = contract.InstallmentAmount; + cell.Style.Numberformat.Format = "#,##0"; + break; + case ExcelColumnType.ContractAmount: + cell.Value = contract.ContractAmount; + cell.Style.Numberformat.Format = "#,##0"; + break; + case ExcelColumnType.FinancialStatus: + cell.Value = contract.Balance; + cell.Style.Numberformat.Format = "#,##0"; + + if (contract.Balance > 0) + cell.Style.Font.Color.SetColor(Color.Red); + else if (contract.Balance < 0) + cell.Style.Font.Color.SetColor(Color.Green); + break; + } + } + } + + /// + /// تنظیم تنظیمات چاپ و عرض ستون‌ها + /// + private static void SetupPrintSettings(ExcelWorksheet worksheet, List visibleColumns, int columnCount) + { worksheet.PrinterSettings.PaperSize = ePaperSize.A4; worksheet.PrinterSettings.Orientation = eOrientation.Landscape; worksheet.PrinterSettings.FitToPage = true; worksheet.PrinterSettings.FitToWidth = 1; worksheet.PrinterSettings.FitToHeight = 0; worksheet.PrinterSettings.Scale = 85; - int contractNoCol = 1; - int contractingPartyNameCol = 2; - int archiveNoCol = 3; - int employersCol = 4; - int workshopsCol = 5; - int employeeCountCol = 6; - int startContractCol = 7; - int endContractCol = 8; - int contractWithoutWorkshopAmountCol = 9; - int contractAmountCol = 10; - int balanceCol = 11; - worksheet.Columns[contractNoCol].Width = 17; - worksheet.Columns[contractingPartyNameCol].Width = 40; - worksheet.Columns[archiveNoCol].Width = 10; - worksheet.Columns[employersCol].Width = 40; - worksheet.Columns[workshopsCol].Width = 45; - worksheet.Columns[employeeCountCol].Width = 12; - worksheet.Columns[startContractCol].Width = 12; - worksheet.Columns[endContractCol].Width = 12; - worksheet.Columns[contractWithoutWorkshopAmountCol].Width = 18; - worksheet.Columns[contractAmountCol].Width = 12; - worksheet.Columns[balanceCol].Width = 12; + + // تنظیم عرض ستون‌ها بر اساس نوع ستون + for (int i = 0; i < visibleColumns.Count; i++) + { + int columnIndex = i + 1; + worksheet.Columns[columnIndex].Width = GetColumnWidth(visibleColumns[i]); + } + worksheet.View.RightToLeft = true; // فارسی - //worksheet.Cells[worksheet.Dimension.Address].AutoFitColumns(); + } + + /// + /// دریافت عرض ستون پیش‌فرض برای هر نوع ستون + /// + private static double GetColumnWidth(ExcelColumnType columnType) + { + return columnType switch + { + ExcelColumnType.RowNumber => 8, + ExcelColumnType.PhysicalContract => 15, + ExcelColumnType.ContractNo => 17, + ExcelColumnType.Representative => 15, + ExcelColumnType.ContractingPartyName => 40, + ExcelColumnType.ArchiveCode => 10, + ExcelColumnType.EmployerName => 40, + ExcelColumnType.WorkshopName => 45, + ExcelColumnType.WorkshopCount => 12, + ExcelColumnType.EmployeeCount => 12, + ExcelColumnType.ContractStartDate => 12, + ExcelColumnType.ContractEndDate => 12, + ExcelColumnType.InstallmentAmount => 15, + ExcelColumnType.ContractAmount => 15, + ExcelColumnType.FinancialStatus => 12, + _ => 12 + }; } private static double MoneyToDouble(string value) { - Console.WriteLine(value); + if (string.IsNullOrEmpty(value)) + return 0; + var min = value.Length > 1 ? value.Substring(0, 2) : ""; var test = min == "\u200e\u2212" ? value.MoneyToDouble() * -1 : value.MoneyToDouble(); - - Console.WriteLine(test); return test; } - private static Color GetColorByName(string name, string workshopCount, string IsContractingPartyBlock) + + /// + /// دریافت رنگ بر اساس وضعیت قرارداد + /// + private static Color GetColorByStatus(InstitutionContractListStatus status, int workshopsCount) { - return name switch + return status switch { - "blue" => Color.LightBlue, - _ when IsContractingPartyBlock == "true" => Color.LightGray, - "red" => Color.LightCoral, - "purple" => Color.MediumPurple, - "black" => Color.DimGray, - var n when string.IsNullOrWhiteSpace(n) && workshopCount == "0" => Color.Yellow, + InstitutionContractListStatus.DeactiveWithDebt => Color.LightBlue, + InstitutionContractListStatus.Deactive => Color.LightGray, + InstitutionContractListStatus.PendingForRenewal => Color.LightCoral, + InstitutionContractListStatus.Free => Color.MediumPurple, + InstitutionContractListStatus.Block => Color.DimGray, + InstitutionContractListStatus.WithoutWorkshop => Color.Yellow, + InstitutionContractListStatus.Active => Color.White, _ => Color.White }; } -} \ No newline at end of file +} + +public class InstitutionContractExcelViewModel +{ + public InstitutionContractListStatus? Tab { get; set; } + public List GetInstitutionContractListItemsViewModels { get; set; } +} diff --git a/CompanyManagment.EFCore/Repository/InsuranceListRepository.cs b/CompanyManagment.EFCore/Repository/InsuranceListRepository.cs index 108b8124..3f2eb9ac 100644 --- a/CompanyManagment.EFCore/Repository/InsuranceListRepository.cs +++ b/CompanyManagment.EFCore/Repository/InsuranceListRepository.cs @@ -757,9 +757,7 @@ public class InsuranceListRepository : RepositoryBase, IIns if (item.InsuranceShare.ToMoney() != checkout.InsuranceDeduction.ToMoney()) { checkout.SetUpdateNeeded(); - if (!_context.CheckoutWarningMessages.Any(x => - x.CheckoutId == checkout.id && x.TypeOfCheckoutWarning != - TypeOfCheckoutWarning.InsuranceEmployeeShare)) + if (!_context.CheckoutWarningMessages.Any(x => x.CheckoutId == checkout.id && x.TypeOfCheckoutWarning == TypeOfCheckoutWarning.InsuranceEmployeeShare)) { var createWarrning = new CheckoutWarningMessage( @@ -1816,7 +1814,17 @@ public class InsuranceListRepository : RepositoryBase, IIns Count = g.Count(x=>x.LeftWorkDate != null) }).ToListAsync(); - + query = searchModel.Sorting switch + { + "CreationDate-Max" => query.OrderByDescending(x => x.id), + "CreationDate-Min" => query.OrderBy(x => x.id), + "Month-Max" => query.OrderByDescending(x => x.Month), + "Month-Min" => query.OrderBy(x => x.Month), + "Year-Max" => query.OrderByDescending(x => x.Year), + "Year-Min" => query.OrderBy(x => x.Year), + _ => query.OrderByDescending(x => x.id), + }; + var resList = list .Select(x => new InsuranceClientListViewModel { @@ -1837,17 +1845,7 @@ public class InsuranceListRepository : RepositoryBase, IIns LeftWorkCount =employeeData.FirstOrDefault(e=>e.Key == x.id)?.Count ?? 0, }).ToList(); - resList = searchModel.Sorting switch - { - "CreationDate-Max" => resList.OrderByDescending(x => x.Id).ToList(), - "CreationDate-Min" => resList.OrderBy(x => x.Id).ToList(), - "Month-Max" => resList.OrderByDescending(x => x.MonthInt).ToList(), - "Month-Min" => resList.OrderBy(x => x.MonthInt).ToList(), - "Year-Max" => resList.OrderByDescending(x => x.YearInt).ToList(), - "Year-Min" => resList.OrderBy(x => x.YearInt).ToList(), - _ => resList.OrderByDescending(x => x.Id).ToList(), - }; - + res.List = resList; return res; @@ -1963,37 +1961,37 @@ public class InsuranceListRepository : RepositoryBase, IIns var workshopList = await query.Skip(searchModel.PageIndex).Take(30).ToListAsync(); - var workshopIds = workshopList.Select(x => x.WorkShopId); - - var employers = await _context.WorkshopEmployers - .Where(x => workshopIds.Contains(x.WorkshopId)) - .GroupBy(x => x.WorkshopId) - .Select(x => x.First()).ToListAsync(); - - var res = workshopList.Select(x => - { - var employer = employers.FirstOrDefault(e => e.WorkshopId == x.WorkShopId)?.Employer; - - return new InsuranceListViewModel - { - WorkShopId = x.WorkShopId, - WorkShopCode = x.WorkShopCode, - WorkShopName = x.WorkShopName, - EmployerName = employer != null - ? employer.FullName - : (x.EmployerName), - Year = searchModel.Year, - Month = searchModel.Month, - TypeOfInsuranceSend = x.TypeOfInsuranceSend == "NormalList" ? "عادی" : - x.TypeOfInsuranceSend == "Govermentlist" ? "کمک دولت" : - x.TypeOfInsuranceSend == "Familylist" ? "خانوادگی" : "", - FixedSalary = (bool)x.FixedSalary, - StrFixedSalary = (bool)x.FixedSalary ? "دارد" : "ندارد", - EmployerId = employer?.id ?? 0, - ArchiveCode = x.ArchiveCode, - City = x.City, - }; - }).ToList(); + var workshopIds = workshopList.Select(x=>x.WorkShopId); + + var employers =await _context.WorkshopEmployers + .Where(x=>workshopIds.Contains(x.WorkshopId)) + .GroupBy(x=>x.WorkshopId) + .Select(x=>x.First()).ToListAsync(); + + var res = workshopList.Select(x => + { + var employer = employers.FirstOrDefault(e => e.WorkshopId ==x.WorkShopId)?.Employer; + + return new InsuranceListViewModel + { + WorkShopId = x.WorkShopId, + WorkShopCode = x.WorkShopCode, + WorkShopName = x.WorkShopName, + EmployerName = employer != null + ? employer.FullName + : (x.EmployerName), + Year = searchModel.Year, + Month = searchModel.Month, + TypeOfInsuranceSend = x.TypeOfInsuranceSend == "NormalList" ? "عادی" : + x.TypeOfInsuranceSend == "Govermentlist" ? "کمک دولت" : + x.TypeOfInsuranceSend == "Familylist" ? "خانوادگی" : "", + FixedSalary = (bool)x.FixedSalary, + StrFixedSalary = (bool)x.FixedSalary ? "دارد" : "ندارد", + EmployerId = employer?.id ?? 0, + ArchiveCode = x.ArchiveCode, + City = x.City, + }; + }).ToList(); return res; } diff --git a/ServiceHost/Areas/Admin/Controllers/institutionContractController.cs b/ServiceHost/Areas/Admin/Controllers/institutionContractController.cs index 64586ae5..e24372f3 100644 --- a/ServiceHost/Areas/Admin/Controllers/institutionContractController.cs +++ b/ServiceHost/Areas/Admin/Controllers/institutionContractController.cs @@ -348,7 +348,7 @@ public class institutionContractController : AdminBaseController { var institutionContractViewModels = _institutionContractApplication.NewSearch(new() { IsActiveString = "both", TypeOfContract = "both" }); - var bytes = InstitutionContractExcelGenerator.GenerateExcel(institutionContractViewModels); + var bytes = InstitutionContractExcelGenerator.GenerateExcel(new List()); return File(bytes, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", $"قرارداد های مالی.xlsx"); @@ -855,6 +855,34 @@ public class institutionContractController : AdminBaseController var res= await _institutionContractApplication.VerifyInstitutionContractManually(id); return res; } + + [HttpGet("excel-download")] + public async Task ExcelDownload() + { + + var searchModel = new InstitutionContractListSearchModel(); + + var dataVm=new List(); + + foreach (var name in typeof(InstitutionContractListStatus).GetEnumNames()) + { + var @enum = Enum.Parse(name); + searchModel.Status = @enum; + searchModel.PageSize = 99999; + var data =( await(_institutionContractApplication.GetList(searchModel))).List; + dataVm.Add(new InstitutionContractExcelViewModel(){Tab = @enum, GetInstitutionContractListItemsViewModels = data}); + } + + searchModel.Status = null; + + var nullData = ( await(_institutionContractApplication.GetList(searchModel))).List; + dataVm.Add(new InstitutionContractExcelViewModel(){Tab = null, GetInstitutionContractListItemsViewModels = nullData}); + + var bytes = InstitutionContractExcelGenerator.GenerateExcel(dataVm); + return File(bytes, + "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", + $"قرارداد های مالی.xlsx"); + } } diff --git a/ServiceHost/Areas/Admin/Pages/Company/InstitutionContracts/Index.cshtml.cs b/ServiceHost/Areas/Admin/Pages/Company/InstitutionContracts/Index.cshtml.cs index 24586065..bda169a5 100644 --- a/ServiceHost/Areas/Admin/Pages/Company/InstitutionContracts/Index.cshtml.cs +++ b/ServiceHost/Areas/Admin/Pages/Company/InstitutionContracts/Index.cshtml.cs @@ -2,6 +2,7 @@ using System.Drawing; using _0_Framework.Application; using AccountManagement.Application.Contracts.Account; +using Company.Domain.InstitutionContractAgg; using CompanyManagement.Infrastructure.Excel.InstitutionContract; using CompanyManagment.App.Contracts.Employer; using CompanyManagment.App.Contracts.InstitutionContract; @@ -38,6 +39,7 @@ public class IndexModel : PageModel private readonly IInstitutionContractApplication _institutionContract; private readonly ILeftWorkApplication _leftWorkApplication; private readonly IRepresentativeApplication _representativeApplication; + private readonly IInstitutionContractRepository _institutionContractRepository; private readonly string _viewName; @@ -60,7 +62,7 @@ public class IndexModel : PageModel IPersonalContractingPartyApp contractingPartyApplication, IRepresentativeApplication representativeApplication, IInstitutionContractApplication institutionContract, ILeftWorkApplication leftWorkApplication - , IContactInfoApplication contactInfoApplication, IAccountApplication accountApplication) + , IContactInfoApplication contactInfoApplication, IAccountApplication accountApplication, IInstitutionContractRepository institutionContractRepository) { _workshopApplication = workshopApplication; @@ -71,6 +73,7 @@ public class IndexModel : PageModel _leftWorkApplication = leftWorkApplication; _contactInfoApplication = contactInfoApplication; _accountApplication = accountApplication; + _institutionContractRepository = institutionContractRepository; } public string Message { get; set; } @@ -920,12 +923,27 @@ public class IndexModel : PageModel }); } - public IActionResult OnGetDownloadExcel() + public async Task OnGetDownloadExcel() { - var institutionContractViewModels = _institutionContract.NewSearch(new() {IsActiveString = "both", TypeOfContract = "both" }); - - institutionContractViewModels= institutionContractViewModels.GroupBy(x=>x.ContractingPartyId).Select(g=>g.MaxBy(x=>x.ContractStartGr)).ToList(); - var bytes = InstitutionContractExcelGenerator.GenerateExcel(institutionContractViewModels); + var searchModel = new InstitutionContractListSearchModel(); + + var dataVm=new List(); + + foreach (var name in typeof(InstitutionContractListStatus).GetEnumNames()) + { + var @enum = Enum.Parse(name); + searchModel.Status = @enum; + searchModel.PageSize = 99999; + var data =( await(_institutionContractRepository.GetList(searchModel))).List; + dataVm.Add(new InstitutionContractExcelViewModel(){Tab = @enum, GetInstitutionContractListItemsViewModels = data}); + } + + searchModel.Status = null; + + var nullData = ( await(_institutionContractRepository.GetList(searchModel))).List; + dataVm.Add(new InstitutionContractExcelViewModel(){Tab = null, GetInstitutionContractListItemsViewModels = nullData}); + + var bytes = InstitutionContractExcelGenerator.GenerateExcel(dataVm); return File(bytes, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", $"قرارداد های مالی.xlsx"); diff --git a/ServiceHost/Areas/Client/Pages/Shared/_Menu.cshtml b/ServiceHost/Areas/Client/Pages/Shared/_Menu.cshtml index 3887dd82..b1e830a2 100644 --- a/ServiceHost/Areas/Client/Pages/Shared/_Menu.cshtml +++ b/ServiceHost/Areas/Client/Pages/Shared/_Menu.cshtml @@ -91,9 +91,9 @@ diff --git a/ServiceHost/Program.cs b/ServiceHost/Program.cs index d5fdc458..cc950cf4 100644 --- a/ServiceHost/Program.cs +++ b/ServiceHost/Program.cs @@ -289,6 +289,7 @@ builder.Services.AddCors(options => "http://localhost:3000", "http://localhost:4000", "http://localhost:4001", + "http://localhost:4002", "http://localhost:3001", "https://gozareshgir.ir", "https://dad-mehr.ir", diff --git a/ServiceHost/Properties/launchSettings.json b/ServiceHost/Properties/launchSettings.json index d7381591..1e604c6c 100644 --- a/ServiceHost/Properties/launchSettings.json +++ b/ServiceHost/Properties/launchSettings.json @@ -11,7 +11,7 @@ }, "ServiceHost": { "commandName": "Project", - "launchBrowser": true, + "launchBrowser": false, "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development", "ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation"