Compare commits
5 Commits
master
...
Feature/Ex
| Author | SHA1 | Date | |
|---|---|---|---|
| 25120ff9c7 | |||
|
|
e0129b089b | ||
|
|
fd2522e507 | ||
| ca55ee9aef | |||
|
|
16c00cbd0e |
@@ -0,0 +1,170 @@
|
||||
using CompanyManagment.App.Contracts.InstitutionContract;
|
||||
using OfficeOpenXml;
|
||||
using OfficeOpenXml.Style;
|
||||
using System.Drawing;
|
||||
|
||||
namespace CompanyManagement.Infrastructure.Excel.Temp;
|
||||
|
||||
public class GetAllContractingPartyExcelGenerator
|
||||
{
|
||||
public static byte[] GenerateExcel(List<DataExcelResult> dataList)
|
||||
{
|
||||
ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
|
||||
using var package = new ExcelPackage();
|
||||
var archive99Sheet = package.Workbook.Worksheets.Add("کارگاه های 99");
|
||||
|
||||
var rollCallSheet = package.Workbook.Worksheets.Add("حضورغیابی");
|
||||
|
||||
var archive99Data = dataList.Where(x => x.Workshops.Any(a => a.ArchiveCode == "99")).ToList();
|
||||
CreateSheet(archive99Data, archive99Sheet);
|
||||
|
||||
CreateSheet(dataList.Where(x=>x.Workshops.Any(w=>w.HasRollCall)).ToList(), rollCallSheet);
|
||||
|
||||
|
||||
|
||||
return package.GetAsByteArray();
|
||||
}
|
||||
|
||||
private static void CreateSheet(List<DataExcelResult> dataList, ExcelWorksheet ws)
|
||||
{
|
||||
string[] headers = new[]
|
||||
{
|
||||
"ContractingPartyId", "نام طرف حساب", "EmployerId", "نام کارفرما", "WorkshopId", "کد کارگاه", "نام کارگاه",
|
||||
"خدمات قرارداد", "خدمات قرارداد حضوری", "خدمات بیمه", "خدمات بیمه حضوری",
|
||||
"خدمات حضورغیاب", "فیش حقوقی غیر رسمی", "تعداد استند", "تعداد ماه های بدهی قبلی برای حضورغیاب"
|
||||
};
|
||||
|
||||
for (int i = 0; i < headers.Length; i++)
|
||||
{
|
||||
var cell = ws.Cells[1, i + 1];
|
||||
cell.Value = headers[i];
|
||||
cell.Style.Font.Bold = true;
|
||||
cell.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
|
||||
cell.Style.VerticalAlignment = ExcelVerticalAlignment.Center;
|
||||
cell.Style.Fill.PatternType = ExcelFillStyle.Solid;
|
||||
cell.Style.Fill.BackgroundColor.SetColor(Color.LightGray);
|
||||
cell.Style.Border.BorderAround(ExcelBorderStyle.Thin);
|
||||
}
|
||||
|
||||
int row = 2;
|
||||
|
||||
foreach (var data in dataList)
|
||||
{
|
||||
int partyStartRow = row;
|
||||
|
||||
foreach (var workshop in data.Workshops)
|
||||
{
|
||||
int workshopStartRow = row;
|
||||
|
||||
var employers = workshop.Employers.Any()
|
||||
? workshop.Employers
|
||||
: new List<EmployerExcelResultData> { new() };
|
||||
|
||||
foreach (var employer in employers)
|
||||
{
|
||||
ws.Cells[row, 1].Value = data.ContractingPartyId;
|
||||
ws.Cells[row, 2].Value = data.ContractingPartyName;
|
||||
ws.Cells[row, 3].Value = employer?.Id;
|
||||
ws.Cells[row, 4].Value = employer?.EmployerName;
|
||||
ws.Cells[row, 5].Value = workshop.Id;
|
||||
ws.Cells[row, 6].Value = workshop.ArchiveCode;
|
||||
ws.Cells[row, 7].Value = workshop.WorkshopName;
|
||||
ws.Cells[row, 8].Value = Convert.ToInt32(workshop.HasContract);
|
||||
ws.Cells[row, 9].Value = 0; // فرضی
|
||||
ws.Cells[row, 10].Value = Convert.ToInt32(workshop.HasInsurance);
|
||||
ws.Cells[row, 11].Value = 0; // فرضی
|
||||
ws.Cells[row, 12].Value = Convert.ToInt32(workshop.HasRollCall);
|
||||
ws.Cells[row, 13].Value = Convert.ToInt32(workshop.HasCustomizeCheckout);
|
||||
ws.Cells[row, 14].Value = 0;
|
||||
ws.Cells[row, 15].Value = workshop.DebtRollCallMonth;
|
||||
|
||||
// 🌿 رنگ سبز برای سلولهایی که مقدارشان 1 است (True)
|
||||
int[] boolCols = new[] { 8, 10, 12, 13, 14, 15 };
|
||||
foreach (var col in boolCols)
|
||||
{
|
||||
var cell = ws.Cells[row, col];
|
||||
if (Convert.ToInt32(cell.Value) > 0)
|
||||
{
|
||||
cell.Style.Fill.PatternType = ExcelFillStyle.Solid;
|
||||
cell.Style.Fill.BackgroundColor.SetColor(Color.FromArgb(198, 239, 206)); // سبز اکسل
|
||||
}
|
||||
}
|
||||
|
||||
// Style: وسطچین + بوردر نازک برای همه سلولها
|
||||
for (int col = 1; col <= 15; col++)
|
||||
{
|
||||
var cell = ws.Cells[row, col];
|
||||
cell.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
|
||||
cell.Style.VerticalAlignment = ExcelVerticalAlignment.Center;
|
||||
cell.Style.Border.Top.Style = ExcelBorderStyle.Thin;
|
||||
cell.Style.Border.Bottom.Style = ExcelBorderStyle.Thin;
|
||||
cell.Style.Border.Left.Style = ExcelBorderStyle.Thin;
|
||||
cell.Style.Border.Right.Style = ExcelBorderStyle.Thin;
|
||||
}
|
||||
|
||||
row++;
|
||||
}
|
||||
|
||||
// Merge Workshop Columns
|
||||
if (employers.Count > 1)
|
||||
{
|
||||
for (int col = 5; col <= 15; col++)
|
||||
{
|
||||
ws.Cells[workshopStartRow, col, row - 1, col].Merge = true;
|
||||
var merged = ws.Cells[workshopStartRow, col, row - 1, col];
|
||||
merged.Style.VerticalAlignment = ExcelVerticalAlignment.Center;
|
||||
merged.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Merge Contracting Party Columns
|
||||
if (row - partyStartRow > 1)
|
||||
{
|
||||
for (int col = 1; col <= 2; col++)
|
||||
{
|
||||
ws.Cells[partyStartRow, col, row - 1, col].Merge = true;
|
||||
var merged = ws.Cells[partyStartRow, col, row - 1, col];
|
||||
merged.Style.VerticalAlignment = ExcelVerticalAlignment.Center;
|
||||
merged.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
|
||||
}
|
||||
}
|
||||
|
||||
// میتونی در صورت نیاز خط بالا و پایین ضخیم برای گروهها رو هم فعال کنی اینجا
|
||||
// for (int col = 1; col <= 15; col++)
|
||||
// {
|
||||
// ws.Cells[partyStartRow, col].Style.Border.Top.Style = ExcelBorderStyle.Medium;
|
||||
// ws.Cells[row - 1, col].Style.Border.Bottom.Style = ExcelBorderStyle.Medium;
|
||||
// }
|
||||
}
|
||||
|
||||
ws.Cells.AutoFitColumns();
|
||||
ws.View.RightToLeft = true;
|
||||
}
|
||||
}
|
||||
|
||||
public class DataExcelResult
|
||||
{
|
||||
public long ContractingPartyId { get; set; }
|
||||
public string ContractingPartyName { get; set; }
|
||||
public List<WorkshopExcelResultData> Workshops { get; set; }
|
||||
}
|
||||
|
||||
public class EmployerExcelResultData
|
||||
{
|
||||
public long Id { get; set; }
|
||||
public string EmployerName { get; set; }
|
||||
}
|
||||
|
||||
public class WorkshopExcelResultData
|
||||
{
|
||||
public long Id { get; set; }
|
||||
public string WorkshopName { get; set; }
|
||||
public bool HasContract { get; set; }
|
||||
public bool HasInsurance { get; set; }
|
||||
public bool HasRollCall { get; set; }
|
||||
public bool HasCustomizeCheckout { get; set; }
|
||||
public List<EmployerExcelResultData> Employers { get; set; }
|
||||
public int DebtRollCallMonth { get; set; }
|
||||
public string ArchiveCode { get; set; }
|
||||
}
|
||||
@@ -6,6 +6,7 @@ using Company.Domain.CustomizeCheckoutAgg.ValueObjects;
|
||||
using Company.Domain.CustomizeCheckoutTempAgg.ValueObjects;
|
||||
using Company.Domain.RewardAgg;
|
||||
using Company.Domain.RollCallAgg.DomainService;
|
||||
using CompanyManagement.Infrastructure.Excel.Temp;
|
||||
using CompanyManagment.App.Contracts.AndroidApkVersion;
|
||||
using CompanyManagment.EFCore;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
@@ -13,8 +14,8 @@ using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace ServiceHost.Areas.AdminNew.Pages.Company.AndroidApk
|
||||
{
|
||||
namespace ServiceHost.Areas.AdminNew.Pages.Company.AndroidApk;
|
||||
|
||||
[Authorize]
|
||||
public class IndexModel : PageModel
|
||||
{
|
||||
@@ -90,9 +91,12 @@ namespace ServiceHost.Areas.AdminNew.Pages.Company.AndroidApk
|
||||
//Console.WriteLine("endStep 1 ============");
|
||||
//SetRollCall(r1);
|
||||
|
||||
await ChangeFridayWorkToWeeklyDayOfWeek();
|
||||
ViewData["message"] = "تومام دو";
|
||||
return Page();
|
||||
//await ChangeFridayWorkToWeeklyDayOfWeek();
|
||||
var bytes = await GetExcelPricingData();
|
||||
return File(bytes,
|
||||
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
||||
$"اطلاعات کارگاه ها.xlsx");
|
||||
|
||||
}
|
||||
|
||||
private async System.Threading.Tasks.Task SetWorkshopRoleSubAccount()
|
||||
@@ -561,5 +565,86 @@ namespace ServiceHost.Areas.AdminNew.Pages.Company.AndroidApk
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
}
|
||||
|
||||
#region GetDataForExcel
|
||||
|
||||
private async Task<byte[]> GetExcelPricingData()
|
||||
{
|
||||
var now = DateTime.Today;
|
||||
var contractingPartyIds = _context.InstitutionContractSet.AsNoTracking()
|
||||
.Where(c => c.ContractStartGr <= now && c.ContractEndGr >= now)
|
||||
.Select(c => c.ContractingPartyId);
|
||||
|
||||
var data = await _context.PersonalContractingParties.Where(x=>contractingPartyIds.Contains(x.id))
|
||||
.Include(x => x.Employers)
|
||||
.ThenInclude(x => x.WorkshopEmployers)
|
||||
.ThenInclude(x => x.Workshop).ThenInclude(x => x.LeftWorks)
|
||||
.Include(x => x.Employers)
|
||||
.ThenInclude(x => x.WorkshopEmployers)
|
||||
.AsSplitQuery().Select(x => new DataExcelResult()
|
||||
{
|
||||
ContractingPartyId = x.id,
|
||||
ContractingPartyName = x.FName + " " + x.LName,
|
||||
//Workshops = x.Employers.SelectMany(e => e.WorkshopEmployers.Select(we => new WorkshopExcelResultData()
|
||||
// {
|
||||
// Id = we.Workshop.id,
|
||||
// HasContract = we.Workshop.LeftWorks.Any(l => l.StartWorkDate >= now && l.LeftWorkDate <= now),
|
||||
// HasRollCall =
|
||||
// we.Workshop.RollCallServicesList.Any(a => a.StartService >= now && a.EndService <= now),
|
||||
// HasInsurance = we.Workshop.InsuranceCode != null,
|
||||
// HasCustomizeCheckout = we.Workshop.RollCallServicesList.Any(a =>
|
||||
// a.StartService >= now & a.EndService <= now && a.HasCustomizeCheckoutService == "true"),
|
||||
// WorkshopName = we.Workshop.WorkshopFullName,
|
||||
// Employers = we.Workshop.WorkshopEmployers.Select(em => new EmployerExcelResultData()
|
||||
// {
|
||||
// EmployerName = em.Employer.FullName,
|
||||
// Id = em.EmployerId
|
||||
// }).ToList(),
|
||||
// }).ToList()
|
||||
Workshops = _context.Workshops
|
||||
.Include(w => w.WorkshopEmployers)
|
||||
.ThenInclude(we => we.Employer)
|
||||
.Where(w => x.Employers
|
||||
.SelectMany(e => e.WorkshopEmployers.Select(we => we.WorkshopId)).Contains(w.id)).Select(w =>
|
||||
new WorkshopExcelResultData()
|
||||
{
|
||||
Id = w.id,
|
||||
HasContract = w.LeftWorks.Any(l => l.StartWorkDate <= now && l.LeftWorkDate >= now),
|
||||
HasRollCall =
|
||||
w.RollCallServicesList.Any(a => a.StartService <= now && a.EndService >= now),
|
||||
HasInsurance = w.LeftWorkInsurances.Any(l=>l.StartWorkDate <= now && l.LeftWorkDate == null),
|
||||
HasCustomizeCheckout = w.RollCallServicesList.Any(a =>
|
||||
a.StartService >= now & a.EndService <= now && a.HasCustomizeCheckoutService == "true"),
|
||||
WorkshopName = w.WorkshopFullName,
|
||||
ArchiveCode = w.ArchiveCode,
|
||||
Employers = w.WorkshopEmployers.Select(em => new EmployerExcelResultData()
|
||||
{
|
||||
EmployerName = em.Employer.FullName,
|
||||
Id = em.EmployerId
|
||||
}).ToList(),
|
||||
|
||||
}).ToList()
|
||||
|
||||
}).ToListAsync();
|
||||
data.ForEach(x =>
|
||||
{
|
||||
x.Workshops.ForEach(w =>
|
||||
{
|
||||
if (w.HasRollCall)
|
||||
{
|
||||
var rollCallService = _context.RollCallServices.First(a => a.StartService <= now && a.EndService >= now);
|
||||
var elapsed = now - rollCallService.StartService;
|
||||
var approxMonths = elapsed.TotalDays / 30.0;
|
||||
var spentMonth = approxMonths >= 2 ? 2 : (int)Math.Floor(approxMonths);
|
||||
w.DebtRollCallMonth = spentMonth;
|
||||
|
||||
}
|
||||
});
|
||||
});
|
||||
var bytes = GetAllContractingPartyExcelGenerator.GenerateExcel(data);
|
||||
return bytes;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user