Compare commits
1 Commits
Feature/in
...
Feature/Ex
| Author | SHA1 | Date | |
|---|---|---|---|
| 49c88e68d2 |
@@ -0,0 +1,142 @@
|
||||
using _0_Framework.Application;
|
||||
using OfficeOpenXml;
|
||||
using OfficeOpenXml.Style;
|
||||
|
||||
namespace CompanyManagement.Infrastructure.Excel.Checkout;
|
||||
|
||||
public class YektaTejaratCheckout
|
||||
{
|
||||
private static readonly Dictionary<string, string> Header = new()
|
||||
{
|
||||
{ "FullName", "نام و نام خانوادگی" },
|
||||
{ "NationalCode", "کد ملی" },
|
||||
{ "StaticPayableAmount", "مبلغ قابل پرداخت استاتیک" },
|
||||
{ "AttendancePayableAmount", "مبلغ قابل پرداخت حضور غیاب" }
|
||||
};
|
||||
|
||||
public static byte[] GenerateYektaTejaratCheckoutExcel(List<YektaTejaratCheckoutViewModel> data)
|
||||
{
|
||||
ExcelPackage.License.SetNonCommercialOrganization("Gozareshgir Noncommercial organization");
|
||||
using var package = new ExcelPackage();
|
||||
var worksheet = package.Workbook.Worksheets.Add("Sheet1");
|
||||
|
||||
// Add row index header
|
||||
var indexCell = worksheet.Cells[1, 1];
|
||||
indexCell.Value = "ردیف";
|
||||
ApplyHeaderStyle(indexCell);
|
||||
|
||||
// Add headers to worksheet
|
||||
for (int i = 0; i < Header.Count; i++)
|
||||
{
|
||||
worksheet.Cells[1, i + 2].Value = Header.ElementAt(i).Value;
|
||||
ApplyHeaderStyle(worksheet.Cells[1, i + 2]);
|
||||
}
|
||||
|
||||
// Add data rows
|
||||
var dataRow = 2;
|
||||
foreach (var item in data)
|
||||
{
|
||||
// Row number
|
||||
var rowCounter = worksheet.Cells[dataRow, 1];
|
||||
rowCounter.Value = dataRow - 1;
|
||||
ApplyGeneralDataStyle(rowCounter);
|
||||
ApplySpecificStyle(rowCounter, 1);
|
||||
|
||||
var column = 2;
|
||||
foreach (var header in Header)
|
||||
{
|
||||
var property = item.GetType().GetProperty(header.Key);
|
||||
var value = property?.GetValue(item, null)?.ToString();
|
||||
|
||||
// Check if the property requires MoneyToDouble()
|
||||
if (RequiresMoneyToDouble(property?.Name))
|
||||
{
|
||||
worksheet.Cells[dataRow, column].Value = MoneyToDouble(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
worksheet.Cells[dataRow, column].Value = value;
|
||||
}
|
||||
|
||||
ApplyGeneralDataStyle(worksheet.Cells[dataRow, column]);
|
||||
ApplySpecificStyle(worksheet.Cells[dataRow, column], column);
|
||||
|
||||
column++;
|
||||
}
|
||||
|
||||
dataRow++;
|
||||
}
|
||||
|
||||
// Auto-fit columns and set print settings
|
||||
worksheet.Cells[worksheet.Dimension.Address].AutoFitColumns();
|
||||
worksheet.PrinterSettings.PaperSize = ePaperSize.A4;
|
||||
worksheet.PrinterSettings.Orientation = eOrientation.Portrait;
|
||||
worksheet.PrinterSettings.FitToPage = true;
|
||||
worksheet.PrinterSettings.FitToWidth = 1;
|
||||
worksheet.PrinterSettings.FitToHeight = 0;
|
||||
worksheet.View.RightToLeft = true;
|
||||
|
||||
return package.GetAsByteArray();
|
||||
}
|
||||
|
||||
// Method to check if a property requires MoneyToDouble()
|
||||
private static bool RequiresMoneyToDouble(string propertyName)
|
||||
{
|
||||
var propertiesRequiringConversion = new HashSet<string>
|
||||
{
|
||||
"StaticPayableAmount", "AttendancePayableAmount"
|
||||
};
|
||||
return propertiesRequiringConversion.Contains(propertyName);
|
||||
}
|
||||
|
||||
// Convert money string to double
|
||||
private static double MoneyToDouble(string value)
|
||||
{
|
||||
if (string.IsNullOrEmpty(value))
|
||||
return 0;
|
||||
|
||||
var min = value.Length > 1 ? value.Substring(0, 2) : "";
|
||||
var result = min == "\u200e\u2212" ? value.MoneyToDouble() * -1 : value.MoneyToDouble();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
private static void ApplySpecificStyle(ExcelRange cell, int columnIndex)
|
||||
{
|
||||
switch (columnIndex)
|
||||
{
|
||||
case 1: // ردیف
|
||||
cell.Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.LightGray);
|
||||
break;
|
||||
case 2: // نام و نام خانوادگی
|
||||
case 3: // کد ملی
|
||||
cell.Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.LightYellow);
|
||||
break;
|
||||
case 4: // مبلغ قابل پرداخت استاتیک
|
||||
cell.Style.Fill.BackgroundColor.SetColor(1, 208, 248, 208); // Light green
|
||||
cell.Style.Numberformat.Format = "#,##0";
|
||||
break;
|
||||
case 5: // مبلغ قابل پرداخت حضور غیاب
|
||||
cell.Style.Fill.BackgroundColor.SetColor(1, 168, 186, 254); // Light blue
|
||||
cell.Style.Numberformat.Format = "#,##0";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace CompanyManagement.Infrastructure.Excel.Checkout;
|
||||
|
||||
public class YektaTejaratCheckoutViewModel
|
||||
{
|
||||
public required string FullName { get; set; }
|
||||
public required string NationalCode { get; set; }
|
||||
public required string StaticPayableAmount { get; set; }
|
||||
public required string AttendancePayableAmount { get; set; }
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ using System.Net.Http;
|
||||
using System.Security.Cryptography.Xml;
|
||||
using System.Text;
|
||||
using System.Text.Json.Serialization;
|
||||
using CompanyManagement.Infrastructure.Excel.Checkout;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using static ServiceHost.Areas.AdminNew.Pages.Company.AndroidApk.IndexModel2;
|
||||
|
||||
@@ -152,8 +153,14 @@ namespace ServiceHost.Areas.AdminNew.Pages.Company.AndroidApk
|
||||
{
|
||||
//await UpdateInstitutionContract();
|
||||
//await UpdateFaceEmbeddingNames();
|
||||
await SetInstitutionContractSigningType();
|
||||
//await SetInstitutionContractSigningType();
|
||||
var bytes= GetYektaCheckout();
|
||||
|
||||
return File(bytes, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
||||
"YektaCheckout.xlsx");
|
||||
|
||||
ViewData["message"] = "تومام یک";
|
||||
|
||||
return Page();
|
||||
}
|
||||
|
||||
@@ -1111,6 +1118,22 @@ namespace ServiceHost.Areas.AdminNew.Pages.Company.AndroidApk
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private byte[] GetYektaCheckout()
|
||||
{
|
||||
var checkouts = _context.CheckoutSet
|
||||
.Where(x => x.WorkshopId == 595
|
||||
&& x.Month == "آذر" && x.Year == "1404").Select(x=>new YektaTejaratCheckoutViewModel()
|
||||
{
|
||||
AttendancePayableAmount = "0",
|
||||
FullName = x.EmployeeFullName,
|
||||
NationalCode = x.NationalCode,
|
||||
StaticPayableAmount = x.TotalPayment.ToMoney()
|
||||
}).ToList();
|
||||
var bytes = YektaTejaratCheckout.GenerateYektaTejaratCheckoutExcel(checkouts);
|
||||
return bytes;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public class IndexModel2 : PageModel
|
||||
|
||||
Reference in New Issue
Block a user