Files
Backend-Api/ServiceHost/Areas/AdminNew/Pages/Company/AndroidApk/Index.cshtml.cs

651 lines
28 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using _0_Framework.Application;
using _0_Framework.Domain.CustomizeCheckoutShared.Enums;
using AccountManagement.Domain.AccountLeftWorkAgg;
using AccountMangement.Infrastructure.EFCore;
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;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.EntityFrameworkCore;
namespace ServiceHost.Areas.AdminNew.Pages.Company.AndroidApk;
[Authorize]
public class IndexModel : PageModel
{
private readonly IAndroidApkVersionApplication _application;
private readonly IRollCallDomainService _rollCallDomainService;
private readonly CompanyContext _context;
private readonly AccountContext _accountContext;
[BindProperty]
public IFormFile File { get; set; }
public IndexModel(IAndroidApkVersionApplication application, IRollCallDomainService rollCallDomainService, CompanyContext context, AccountContext accountContext)
{
_application = application;
_rollCallDomainService = rollCallDomainService;
_context = context;
_accountContext = accountContext;
}
public void OnGet()
{
}
public async Task<IActionResult> OnPostUpload()
{
var result = await _application.CreateAndActive(File);
ViewData["message"] = result.Message;
return Page();
}
public IActionResult OnPostShiftDate()
{
//var startRollCall = new DateTime(2025, 2, 19);
//var rollCalls = _context.RollCalls.Where(x => x.ShiftDate >= startRollCall);
//var endedRollCalls = rollCalls.Where(x => x.EndDate != null).ToList();
//var notEndedRollCalls = rollCalls.Where(x => x.EndDate == null).ToList();
//RefactorAllTheRollCallsOnEsfand(endedRollCalls, notEndedRollCalls);
//CreateRewardForKebabMahdi().GetAwaiter().GetResult();
SetEntityIdForCheckoutValues();
SetEntityIdForCheckoutValuesTemp();
ViewData["message"] = "ایجاد شد";
return Page();
}
public IActionResult OnPostShiftDateNew()
{
var startRollCall = new DateTime(2025, 4, 21);
//var employees = _context.CustomizeWorkshopEmployeeSettings
// .Where(x => x.WorkshopShiftStatus == WorkshopShiftStatus.Rotating).Select(x => x.EmployeeId).ToList();
var rollCalls = _context.RollCalls.Where(x => x.ShiftDate >= startRollCall && x.EndDate != null).ToList();
var r1 = rollCalls.ToList();
Console.ForegroundColor = ConsoleColor.DarkRed;
Console.WriteLine("endStep 1 ============");
SetBreakTime(r1);
ViewData["message"] = "تومام یک";
return Page();
}
public async Task<IActionResult> OnPostShiftDateNew2()
{
//var startRollCall = new DateTime(2025, 3, 21);
//var rollCalls = _context.RollCalls.Where(x => x.StartDate >= startRollCall && x.EndDate != null ).ToList();
//var r1 = rollCalls.Skip(10000).Take(10000).ToList();
//Console.ForegroundColor = ConsoleColor.DarkRed;
//Console.WriteLine("endStep 1 ============");
//SetRollCall(r1);
//await ChangeFridayWorkToWeeklyDayOfWeek();
var bytes = await GetExcelPricingData();
return File(bytes,
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
$"اطلاعات کارگاه ها.xlsx");
}
private async System.Threading.Tasks.Task SetWorkshopRoleSubAccount()
{
var subAccountRoles = _accountContext.SubAccountRoles.Include(x => x.SubAccounts).ToList();
subAccountRoles.ForEach(role =>
{
var getSubAccount = role.SubAccounts.FirstOrDefault();
if (getSubAccount != null)
{
var subAccount = getSubAccount.id;
var workshopIds = _context.WorkshopSubAccounts.Where(x => x.SubAccountId == subAccount).Select(x => x.WorkshopId).ToList();
role.Edit(role.Title, role.RolePermissions.Select(x => x.PermissionCode).ToList(), workshopIds);
}
});
await _accountContext.SaveChangesAsync();
}
private void SetEntityIdForCheckoutValuesTemp()
{
var customizeCheckouts = _context.CustomizeCheckoutTemps.ToList();
foreach (var customizeCheckout in customizeCheckouts)
{
var newRewards = new List<CustomizeCheckoutTempReward>();
foreach (var customizeCheckoutReward in customizeCheckout.CustomizeCheckoutRewards)
{
var reward = _context.Rewards.FirstOrDefault(x => x.GrantDate == customizeCheckoutReward.GrantDate && x.Title == customizeCheckoutReward.Title && x.EmployeeId == customizeCheckout.EmployeeId && x.WorkshopId == customizeCheckout.WorkshopId);
if (reward != null)
{
newRewards.Add(new CustomizeCheckoutTempReward(reward.Amount.ToMoney(), reward.Description, reward.GrantDate, reward.GrantDate.ToFarsi(), reward.IsActive, reward.Title, reward.id));
}
}
var newSalary = new List<CustomizeCheckoutTempSalaryAid>();
foreach (var customizeCheckoutSalaryAid in customizeCheckout.CustomizeCheckoutSalaryAids)
{
var salary = _context.SalaryAids.FirstOrDefault(x => x.SalaryAidDateTime == customizeCheckoutSalaryAid.SalaryAidDateTime &&
x.Amount == customizeCheckoutSalaryAid.Amount.MoneyToDouble() &&
x.EmployeeId == customizeCheckout.EmployeeId && x.WorkshopId == customizeCheckout.WorkshopId);
if (salary != null)
{
newSalary.Add(new CustomizeCheckoutTempSalaryAid(salary.Amount.ToMoney(), salary.SalaryAidDateTime,
salary.SalaryAidDateTime.ToFarsi(), salary.CalculationDate, salary.CalculationDate.ToFarsi(), salary.id));
}
}
var newFines = new List<CustomizeCheckoutTempFine>();
foreach (var checkoutFine in customizeCheckout.CheckoutFines)
{
var fines = _context.Fines.FirstOrDefault(x => x.Amount == checkoutFine.Amount.MoneyToDouble() && x.FineDate == checkoutFine.FineDateGr &&
x.Title == checkoutFine.Title && x.EmployeeId == customizeCheckout.EmployeeId && x.WorkshopId == customizeCheckout.WorkshopId);
if (fines != null)
{
newFines.Add(new CustomizeCheckoutTempFine(fines.Title, fines.Amount.ToMoney(), fines.FineDate.ToFarsi(), fines.FineDate, fines.IsActive, fines.CreationDate, fines.id));
}
}
var newInstallments = new List<CustomizeCheckoutTempLoanInstallments>();
foreach (var customizeCheckoutLoanInstallment in customizeCheckout.CustomizeCheckoutLoanInstallments)
{
var installments = _context.Loans.SelectMany(x => x.LoanInstallments).AsNoTracking().Where(x => x.Month == customizeCheckoutLoanInstallment.Month && x.Year == customizeCheckoutLoanInstallment.Year && x.AmountForMonth == customizeCheckoutLoanInstallment.AmountForMonth.MoneyToDouble()).ToList();
var loans = _context.Loans
.Where(x => x.Amount == customizeCheckoutLoanInstallment.LoanAmount.MoneyToDouble() && x.EmployeeId == customizeCheckout.EmployeeId && x.WorkshopId == customizeCheckout.WorkshopId).ToList();
var installment = installments.First(x => loans.Any(l => l.id == x.LoanId));
if (installment != null)
{
newInstallments.Add(new CustomizeCheckoutTempLoanInstallments(installment.AmountForMonth.ToMoney(),
installment.Month, installment.Year, installment.IsActive,
customizeCheckoutLoanInstallment.LoanRemaining, customizeCheckoutLoanInstallment.LoanAmount,
installment.Id));
}
}
customizeCheckout.SetValueObjects(newFines, newInstallments, newSalary, newRewards);
_context.SaveChanges();
}
}
private void SetEntityIdForCheckoutValues()
{
var customizeCheckouts = _context.CustomizeCheckouts.ToList();
foreach (var customizeCheckout in customizeCheckouts)
{
var newRewards = new List<CustomizeCheckoutReward>();
foreach (var customizeCheckoutReward in customizeCheckout.CustomizeCheckoutRewards)
{
var reward = _context.Rewards.FirstOrDefault(x => x.GrantDate == customizeCheckoutReward.GrantDate && x.Title == customizeCheckoutReward.Title && x.EmployeeId == customizeCheckout.EmployeeId && x.WorkshopId == customizeCheckout.WorkshopId);
if (reward != null)
{
newRewards.Add(new CustomizeCheckoutReward(reward.Amount.ToMoney(), reward.Description, reward.GrantDate, reward.GrantDate.ToFarsi(), reward.IsActive, reward.Title, reward.id));
}
}
var newSalary = new List<CustomizeCheckoutSalaryAid>();
foreach (var customizeCheckoutSalaryAid in customizeCheckout.CustomizeCheckoutSalaryAids)
{
var salary = _context.SalaryAids.FirstOrDefault(x => x.SalaryAidDateTime == customizeCheckoutSalaryAid.SalaryAidDateTime &&
x.Amount == customizeCheckoutSalaryAid.Amount.MoneyToDouble() &&
x.EmployeeId == customizeCheckout.EmployeeId && x.WorkshopId == customizeCheckout.WorkshopId);
if (salary != null)
{
newSalary.Add(new CustomizeCheckoutSalaryAid(salary.Amount.ToMoney(), salary.SalaryAidDateTime,
salary.SalaryAidDateTime.ToFarsi(), salary.CalculationDate, salary.CalculationDate.ToFarsi(), salary.id));
}
}
var newFines = new List<CustomizeCheckoutFine>();
foreach (var checkoutFine in customizeCheckout.CheckoutFines)
{
var fines = _context.Fines.FirstOrDefault(x => x.Amount == checkoutFine.Amount.MoneyToDouble() && x.FineDate == checkoutFine.FineDateGr &&
x.Title == checkoutFine.Title && x.EmployeeId == customizeCheckout.EmployeeId && x.WorkshopId == customizeCheckout.WorkshopId);
if (fines != null)
{
newFines.Add(new CustomizeCheckoutFine(fines.Title, fines.Amount.ToMoney(), fines.FineDate.ToFarsi(), fines.FineDate, fines.IsActive, fines.CreationDate, fines.id));
}
}
var newInstallments = new List<CustomizeCheckoutLoanInstallments>();
foreach (var customizeCheckoutLoanInstallment in customizeCheckout.CustomizeCheckoutLoanInstallments)
{
var installments = _context.Loans.SelectMany(x => x.LoanInstallments).AsNoTracking().Where(x => x.Month == customizeCheckoutLoanInstallment.Month && x.Year == customizeCheckoutLoanInstallment.Year && x.AmountForMonth == customizeCheckoutLoanInstallment.AmountForMonth.MoneyToDouble()).ToList();
var loans = _context.Loans
.Where(x => x.Amount == customizeCheckoutLoanInstallment.LoanAmount.MoneyToDouble() && x.EmployeeId == customizeCheckout.EmployeeId && x.WorkshopId == customizeCheckout.WorkshopId).ToList();
var installment = installments.First(x => loans.Any(l => l.id == x.LoanId));
if (installment != null)
{
newInstallments.Add(new CustomizeCheckoutLoanInstallments(installment.AmountForMonth.ToMoney(),
installment.Month, installment.Year, installment.IsActive,
customizeCheckoutLoanInstallment.LoanRemaining, customizeCheckoutLoanInstallment.LoanAmount,
installment.Id));
}
}
customizeCheckout.SetValueObjects(newFines, newInstallments, newSalary, newRewards);
_context.SaveChanges();
}
}
private async System.Threading.Tasks.Task SetCalculationDateInSalaryAid()
{
var salaryAids = await _context.SalaryAids.ToListAsync();
foreach (var salaryAid in salaryAids)
{
var calculationDate = salaryAid.SalaryAidDateTime;
var calculationMonth = Convert.ToInt32(calculationDate.ToFarsiMonth());
var calculationYear = Convert.ToInt32(calculationDate.ToFarsiYear());
salaryAid.Edit(salaryAid.Amount, salaryAid.SalaryAidDateTime, 0, UserType.Anonymous, calculationMonth, calculationYear);
}
await _context.SaveChangesAsync();
}
private async System.Threading.Tasks.Task RemoveEmployeeClientTemps()
{
var employeeDocuments = _context.EmployeeDocuments
.Include(x => x.EmployeeDocumentItemCollection)
.Where(x => x.IsConfirmed);
var employeeClientTemps = await _context.EmployeeClientTemps.Where(x => employeeDocuments.Any(a => a.WorkshopId == x.WorkshopId && a.EmployeeId == x.EmployeeId)).ToListAsync();
foreach (var employeeClientTemp in employeeClientTemps)
{
_context.EmployeeClientTemps.Remove(employeeClientTemp);
}
await _context.SaveChangesAsync();
}
private async System.Threading.Tasks.Task ChangeIsConfirmed()
{
var employeeDocuments = await _context.EmployeeDocuments.Include(x => x.EmployeeDocumentItemCollection).ToListAsync();
foreach (var employeeDocument in employeeDocuments)
{
employeeDocument.UpdateRequiredItemsSubmittedByClient();
employeeDocument.UpdateHasRejectedItems();
employeeDocument.UpdateIsSentToChecker();
employeeDocument.UpdateIsConfirmed();
}
await _context.SaveChangesAsync();
}
public async System.Threading.Tasks.Task RefactorEmployeeDocumentItem()
{
var employeeDocumentItems = await _context.EmployeeDocumentItems.Where(x => x.UploaderType == UserType.Admin).ToListAsync();
foreach (var employeeDocumentItem in employeeDocumentItems)
{
var roleId = _accountContext.Accounts.FirstOrDefault(x => x.id == employeeDocumentItem.UploaderId)?.RoleId ?? 0;
employeeDocumentItem.SetRoleId(roleId);
}
await _context.SaveChangesAsync();
}
#region Create reward for kebab mahdi
public async System.Threading.Tasks.Task CreateRewardForKebabMahdi()
{
//var esfandCustomizeCheckouts = _context.CustomizeCheckouts
// .Where(x => x.WorkshopId == 170 && x.MonthInt == 12 && x.YearInt == 1403);
//var sinzdahBedarDate = new DateTime(2025, 04, 2);
//var chahardah = sinzdahBedarDate.AddDays(1);
//var workingEmp = _context.LeftWorkList.Where(x => x.WorkshopId == 170 && x.StartWorkDate <= sinzdahBedarDate && x.LeftWorkDate >= sinzdahBedarDate)
// .GroupBy(x => x.EmployeeId).Select(x=>x.Key);
//var employeesHaveRollCall = _context.RollCallEmployees
// .Where(x => workingEmp.Contains(x.EmployeeId) && x.WorkshopId == 170)
// .Include(x => x.EmployeesStatus)
// .Where(x => x.EmployeesStatus.Any(s => s.StartDate <= sinzdahBedarDate && s.EndDate >= sinzdahBedarDate)).Select(x=>x.EmployeeId);
//var employeeSettings = _context.CustomizeWorkshopEmployeeSettings
// .Where(x => x.WorkshopId == 170 &&
// employeesHaveRollCall.Any(c => c == x.EmployeeId));
//var absentEmployeesInSinzdah = employeeSettings.Where(x => !_context.RollCalls
// .Any(a => a.EmployeeId == x.EmployeeId && a.ShiftDate == sinzdahBedarDate))
// .ToList();
//var absentEmployeesInChahardah = employeeSettings.Where(x => !_context.RollCalls
// .Any(a => a.EmployeeId == x.EmployeeId && a.ShiftDate == chahardah))
// .ToList();
//foreach (var employeeSetting in absentEmployeesInSinzdah)
//{
// var amount = (int)employeeSetting.Salary / 30;
// var reward = new Reward(employeeSetting.EmployeeId, 170, amount, "", 0, sinzdahBedarDate,
// "بابت تعطیلی روز 13 فروردین");
// _context.Rewards.Add(reward);
//}
//foreach (var employeeSetting in absentEmployeesInChahardah)
//{
// var amount = (int)employeeSetting.Salary / 30;
// var reward = new Reward(employeeSetting.EmployeeId, 170, amount, "", 0, sinzdahBedarDate.AddDays(1),
// "بابت تعطیلی روز 14 فروردین");
// _context.Rewards.Add(reward);
//}
//await _context.SaveChangesAsync();
}
#endregion
#region AccountLeftwork
private void AddToAccountLeftWork()
{
List<long> roleIds = [3, 5, 7, 8, 23, 24];
var accounts = _accountContext.Accounts
.Where(x => roleIds.Contains(x.RoleId)).Where(x => x.AdminAreaPermission == "true");
var accountsIds = accounts.Select(x => x.id).ToList();
var workshopAccount = _context.WorkshopAccounts
.Where(x => accountsIds.Contains(x.AccountId))
.GroupBy(x => x.AccountId);
List<long> oldAccountleftworkActiveNow = [300, 332, 333, 334, 18, 25, 14];
List<long> oldAccountleftworkDeActivedNow = [50, 49, 15];
var continueWorking = _0_Framework.Application.StaticWorkshopAccounts.ContinuesWorkingDate;
foreach (var item in workshopAccount)
{
var oldActive = item.FirstOrDefault(x => oldAccountleftworkActiveNow.Contains(x.AccountId));
if (oldActive != null)
{
var roleId = accounts.FirstOrDefault(x => x.id == oldActive.AccountId)!.RoleId;
var startGr = item.Key != 25 ? new DateTime(2024, 07, 22) : new DateTime(2024, 08, 22);
//if (item.Key is 380 or 381)
// startGr = new DateTime(2025, 02, 19);
if (item.Key is 14 or 18)
startGr = new DateTime(2020, 05, 21);
if (item.Key is 300)
startGr = new DateTime(2024, 05, 22);
foreach (var workshop in item)
{
_accountContext.AccountLeftWorks.Add(new AccountLeftWork(startGr, continueWorking, workshop.AccountId, workshop.WorkshopId, roleId, true));
}
_accountContext.SaveChanges();
}
var oldDeActive = item.FirstOrDefault(x => oldAccountleftworkDeActivedNow.Contains(x.AccountId));
if (oldDeActive != null)
{
var roleId = accounts.FirstOrDefault(x => x.id == oldDeActive.AccountId)!.RoleId;
var startGr = new DateTime(2022, 03, 21);
if (item.Key == 49)
startGr = new DateTime(2023, 04, 21);
if (item.Key == 50)
startGr = new DateTime(2023, 03, 21);
foreach (var workshop in item)
{
_accountContext.Add(new AccountLeftWork(startGr, new DateTime(2024, 07, 21), workshop.AccountId, workshop.WorkshopId, roleId, false));
}
_accountContext.SaveChanges();
}
}
Console.WriteLine("finished");
}
#endregion
#region RefactorRollcall
private void RefactorAllTheRollCallsOnEsfand(List<global::Company.Domain.RollCallAgg.RollCall> endedRollCalls, List<global::Company.Domain.RollCallAgg.RollCall> notEndedRollCalls)
{
var countEndedRollCalls = endedRollCalls.Count;
var countNotEndedRollCalls = notEndedRollCalls.Count;
var step1 = 1;
foreach (var rollCall in endedRollCalls)
{
rollCall.setStartAndEnd(rollCall.StartDate.Value, rollCall.EndDate.Value, _rollCallDomainService);
Console.WriteLine($"{step1} - {countEndedRollCalls} ended Edit {rollCall.id}");
step1 += 1;
}
var step2 = 1;
foreach (var notEndedRollCall in notEndedRollCalls)
{
notEndedRollCall.SetStartAgain(notEndedRollCall.StartDate.Value);
Console.WriteLine($"{step2} - {countNotEndedRollCalls} not ended startAgain {notEndedRollCall.id}");
step2 += 1;
}
_context.SaveChanges();
}
private void SetBreakTime(List<global::Company.Domain.RollCallAgg.RollCall> r1)
{
foreach (var rollCall in r1)
{
}
_context.SaveChanges();
}
private void SetRollCall(List<global::Company.Domain.RollCallAgg.RollCall> r1)
{
var endedRollCalls2 = r1.Where(x => x.EndDate != null).ToList();
var countSetTDRollCall = endedRollCalls2.Count;
var stepSetTDRollCal = 1;
foreach (var rollCall in endedRollCalls2)
{
rollCall.ClearTimeDiff();
}
_context.SaveChanges();
foreach (var endedRollCall in endedRollCalls2)
{
endedRollCall.Edit(endedRollCall.StartDate.Value, endedRollCall.EndDate.Value, _rollCallDomainService);
Console.WriteLine($"{stepSetTDRollCal} - {countSetTDRollCall} ended Set Time Differences{endedRollCall.id}");
stepSetTDRollCal += 1;
}
_context.SaveChanges();
}
private void SetRollCall2(List<global::Company.Domain.RollCallAgg.RollCall> r2)
{
var endedRollCalls2 = r2.Where(x => x.EndDate != null).ToList();
var countSetTDRollCall = endedRollCalls2.Count;
var stepSetTDRollCal = 1;
foreach (var endedRollCall in endedRollCalls2)
{
endedRollCall.SetEndDateTime(endedRollCall.EndDate.Value, _rollCallDomainService);
Console.WriteLine($"{stepSetTDRollCal} - {countSetTDRollCall} ended Set Time Differences{endedRollCall.id}");
stepSetTDRollCal += 1;
}
//_context.SaveChanges();
}
#endregion
//public async Task<IActionResult> OnPostShiftDate()
//{
// var customizeWorkshopSettings = _context.CustomizeWorkshopSettings.AsSplitQuery();
// customizeWorkshopSettings = customizeWorkshopSettings.Where(x => x.WorkshopId == 499);
// var rollCalls =
// _context.RollCalls.Where(x => customizeWorkshopSettings.Any(a => a.WorkshopId == x.WorkshopId))
// .ToList();
// foreach (var rollCall in rollCalls)
// {
// rollCall.SetShiftDate(_rollCallDomainService);
// Console.WriteLine(rollCall.id);
// }
// await _context.SaveChangesAsync();
// ViewData["message"] = "تومام";
// return Page();
//}
private async System.Threading.Tasks.Task ChangeFridayWorkToWeeklyDayOfWeek()
{
var employeeSettingsEnumerable = await _context.CustomizeWorkshopEmployeeSettings.Where(x => x.FridayWork == FridayWork.Default).ToListAsync();
foreach (var employeeSetting in employeeSettingsEnumerable)
{
employeeSetting.FridayWorkToWeeklyDayOfWeek();
}
var groupSettings = await _context.CustomizeWorkshopGroupSettings
.Where(x => x.FridayWork == FridayWork.Default).ToListAsync();
foreach (var groupSetting in groupSettings)
{
groupSetting.FridayWorkToWeeklyDayOfWeek();
}
var workshopSettings = await _context.CustomizeWorkshopSettings
.Where(x => x.FridayWork == FridayWork.Default).ToListAsync();
foreach (var workshopSetting in workshopSettings)
{
workshopSetting.FridayWorkToWeeklyDayOfWeek();
}
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
}