348 lines
14 KiB
C#
348 lines
14 KiB
C#
using _0_Framework.Application;
|
|
using AccountManagement.Domain.AccountLeftWorkAgg;
|
|
using AccountMangement.Infrastructure.EFCore;
|
|
using Company.Domain.RewardAgg;
|
|
using Company.Domain.RollCallAgg.DomainService;
|
|
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();
|
|
ViewData["message"] = "ایجاد شد";
|
|
return Page();
|
|
}
|
|
|
|
public IActionResult OnPostShiftDateNew()
|
|
{
|
|
var startRollCall = new DateTime(2025, 3, 21);
|
|
var rollCalls = _context.RollCalls.Where(x => x.ShiftDate >= startRollCall && x.EndDate != null).ToList();
|
|
var r1 = rollCalls.Take(10000).ToList();
|
|
|
|
Console.ForegroundColor = ConsoleColor.DarkRed;
|
|
Console.WriteLine("endStep 1 ============");
|
|
SetRollCall(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 RefactorEmployeeDocumentItem();
|
|
await ChangeIsConfirmed();
|
|
await RemoveEmployeeClientTemps();
|
|
|
|
ViewData["message"] = "تومام دو";
|
|
return Page();
|
|
}
|
|
|
|
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 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 endedRollCall in endedRollCalls2)
|
|
{
|
|
endedRollCall.SetShiftDate(_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();
|
|
//}
|
|
}
|
|
}
|