1277 lines
55 KiB
C#
1277 lines
55 KiB
C#
using _0_Framework.Application;
|
|
using _0_Framework.Application.Enums;
|
|
using _0_Framework.Application.FaceEmbedding;
|
|
using _0_Framework.Application.PaymentGateway;
|
|
using _0_Framework.Domain.CustomizeCheckoutShared.Enums;
|
|
using AccountManagement.Domain.AccountLeftWorkAgg;
|
|
using AccountMangement.Infrastructure.EFCore;
|
|
using Company.Domain.AndroidApkVersionAgg;
|
|
using Company.Domain.CustomizeCheckoutAgg.ValueObjects;
|
|
using Company.Domain.CustomizeCheckoutTempAgg.ValueObjects;
|
|
using Company.Domain.InstitutionContractAgg;
|
|
using Company.Domain.InstitutionPlanAgg;
|
|
using Company.Domain.PaymentTransactionAgg;
|
|
using Company.Domain.RewardAgg;
|
|
using Company.Domain.RollCallAgg.DomainService;
|
|
using CompanyManagement.Infrastructure.Excel.WorkshopsRollCall;
|
|
using CompanyManagement.Infrastructure.Excel.Checkout.AsghaeeAzarWorkshops;
|
|
using CompanyManagment.App.Contracts.AndroidApkVersion;
|
|
using CompanyManagment.App.Contracts.InstitutionContract;
|
|
using CompanyManagment.App.Contracts.PaymentTransaction;
|
|
using CompanyManagment.App.Contracts.TemporaryClientRegistration;
|
|
using CompanyManagment.EFCore;
|
|
using Hangfire;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Options;
|
|
using Parbad;
|
|
using Parbad.AspNetCore;
|
|
using Parbad.Gateway.Sepehr;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.Diagnostics;
|
|
using System.Net.Http;
|
|
using System.Security.Cryptography.Xml;
|
|
using System.Text;
|
|
using System.Text.Json.Serialization;
|
|
using Microsoft.AspNetCore.Authentication;
|
|
using static ServiceHost.Areas.AdminNew.Pages.Company.AndroidApk.IndexModel2;
|
|
|
|
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;
|
|
private readonly IPaymentGateway _paymentGateway;
|
|
private readonly ITemporaryClientRegistrationApplication _clientRegistrationApplication;
|
|
private readonly IHttpClientFactory _httpClientFactory;
|
|
private readonly IOnlinePayment _onlinePayment;
|
|
private readonly IFaceEmbeddingService _faceEmbeddingService;
|
|
private readonly IAuthHelper _authHelper;
|
|
|
|
|
|
[BindProperty] public IFormFile File { get; set; }
|
|
|
|
[BindProperty]
|
|
[Required(ErrorMessage = "لطفا نام ورژن را وارد کنید")]
|
|
[Display(Name = "نام ورژن")]
|
|
public string VersionName { get; set; }
|
|
|
|
[BindProperty]
|
|
[Required(ErrorMessage = "لطفا کد ورژن را وارد کنید")]
|
|
[Display(Name = "کد ورژن")]
|
|
public string VersionCode { get; set; }
|
|
|
|
/// <summary>
|
|
/// لاگ آپلود فرانت
|
|
/// </summary>
|
|
public string LogContent { get; set; }
|
|
|
|
[BindProperty] public ApkType SelectedApkType { get; set; }
|
|
[BindProperty] public bool IsForce { get; set; }
|
|
|
|
public IndexModel(IAndroidApkVersionApplication application, IRollCallDomainService rollCallDomainService,
|
|
CompanyContext context, AccountContext accountContext, IHttpClientFactory httpClientFactory,
|
|
IOptions<AppSettingConfiguration> appSetting,
|
|
ITemporaryClientRegistrationApplication clientRegistrationApplication, IOnlinePayment onlinePayment, IFaceEmbeddingService faceEmbeddingService, IAuthHelper authHelper)
|
|
{
|
|
_application = application;
|
|
_rollCallDomainService = rollCallDomainService;
|
|
_context = context;
|
|
_accountContext = accountContext;
|
|
_httpClientFactory = httpClientFactory;
|
|
_clientRegistrationApplication = clientRegistrationApplication;
|
|
_onlinePayment = onlinePayment;
|
|
_faceEmbeddingService = faceEmbeddingService;
|
|
_authHelper = authHelper;
|
|
_paymentGateway = new SepehrPaymentGateway(httpClientFactory);
|
|
}
|
|
|
|
public void OnGet()
|
|
{
|
|
}
|
|
|
|
public async Task<IActionResult> OnPostUpload()
|
|
{
|
|
var result = await _application.CreateAndActive(File, SelectedApkType, VersionName, VersionCode, IsForce);
|
|
ViewData["message"] = result.Message;
|
|
return Page();
|
|
}
|
|
|
|
|
|
public async Task<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();
|
|
|
|
var callBack = Url.Action("Verify", "General", null, Request.Scheme);
|
|
|
|
|
|
var amount = 10000;
|
|
var transaction = new PaymentTransaction(30427, amount, "سید حسن مصباح", "https://client.gozareshgir.ir",
|
|
PaymentTransactionGateWay.SepehrPay);
|
|
|
|
_context.PaymentTransactions.Add(transaction);
|
|
await _context.SaveChangesAsync();
|
|
|
|
var command = new CreatePaymentGatewayRequest()
|
|
{
|
|
TransactionId = transaction.id.ToString(),
|
|
Amount = amount,
|
|
CallBackUrl = callBack
|
|
};
|
|
|
|
var createRes = await _paymentGateway.Create(command);
|
|
|
|
if (createRes.IsSuccess)
|
|
{
|
|
transaction.SetTransactionId(createRes.Token);
|
|
await _context.SaveChangesAsync();
|
|
|
|
var payUrl = _paymentGateway.GetStartPayUrl(createRes.Token);
|
|
return Redirect(payUrl);
|
|
}
|
|
else
|
|
{
|
|
return BadRequest(createRes.Status + "خطا در ارسال به درگاه پرداخت");
|
|
}
|
|
}
|
|
|
|
|
|
public async Task<IActionResult> OnPostShiftDateNew()
|
|
{
|
|
//await UpdateInstitutionContract();
|
|
//await UpdateFaceEmbeddingNames();
|
|
//await SetInstitutionContractSigningType();
|
|
var data = OnGetExportAsghaeeAzarWorkshops();
|
|
return File(data, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
"AsghaeeAzarWorkshops.xlsx");
|
|
ViewData["message"] = "تومام یک";
|
|
return Page();
|
|
}
|
|
|
|
private async System.Threading.Tasks.Task SetInstitutionContractSigningType()
|
|
{
|
|
var query = _context.InstitutionContractSet
|
|
.Where(x=>x.VerificationStatus != InstitutionContractVerificationStatus.PendingForVerify);
|
|
|
|
|
|
var otpSigned = query.Where(x=>x.VerifierFullName != null && x.LawId != 0).ToList();
|
|
foreach (var institutionContract in otpSigned)
|
|
{
|
|
institutionContract.SetSigningType(InstitutionContractSigningType.OtpBased);
|
|
}
|
|
var lagacySigned = query.Where(x=>x.VerifierFullName == null && x.LawId == 0).ToList();
|
|
foreach (var institutionContract in lagacySigned)
|
|
{
|
|
institutionContract.SetSigningType(InstitutionContractSigningType.Legacy);
|
|
}
|
|
|
|
await _context.SaveChangesAsync();
|
|
|
|
|
|
}
|
|
|
|
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();
|
|
//await SetPublicId();
|
|
var now = DateTime.Now;
|
|
var data = _context.RollCallServices
|
|
.Include(x => x.Workshop)
|
|
.ThenInclude(x => x.LeftWorks)
|
|
.Include(x => x.Workshop)
|
|
.ThenInclude(x => x.WorkshopEmployers)
|
|
.ThenInclude(x => x.Employer)
|
|
.Select(x => new WorkshopRollCallExcelViewModel()
|
|
{
|
|
EmployerName = x.Workshop.WorkshopEmployers.First().Employer.FullName,
|
|
IsActive = x.IsActiveString == "true",
|
|
PersonnelCount = x.Workshop.LeftWorks.Count(l => l.StartWorkDate <= now && l.LeftWorkDate >= now),
|
|
WorkshopName = x.Workshop.WorkshopFullName
|
|
}).OrderByDescending(x => x.IsActive).ToList();
|
|
var dataBytes = WorkshopRollCallExcelExporter.Export(data);
|
|
return File(dataBytes, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
"RollCallServices.xlsx");
|
|
ViewData["message"] = "تومام دو";
|
|
return Page();
|
|
}
|
|
|
|
private async System.Threading.Tasks.Task CreateDadmehrWorkshopFaceEmbedding()
|
|
{
|
|
var basePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "faces");
|
|
|
|
if (!Directory.Exists(basePath))
|
|
{
|
|
ViewData["message"] = "مسیر پوشه یافت نشد";
|
|
return;
|
|
}
|
|
|
|
var directories = Directory.GetDirectories(basePath);
|
|
|
|
var client = new HttpClient();
|
|
|
|
foreach (var mainDirectory in directories)
|
|
{
|
|
var subDirectories = Directory.GetDirectories(mainDirectory);
|
|
var workshopName = Path.GetFileName(mainDirectory);
|
|
foreach (var directory in subDirectories)
|
|
{
|
|
var directoryName = Path.GetFileName(directory);
|
|
|
|
var employee = await _context.Employees
|
|
.FirstOrDefaultAsync(x => x.id == Convert.ToInt64(directoryName));
|
|
var fullname = employee != null ? employee.FullName : "نامشخص";
|
|
|
|
var imageFiles = Directory.GetFiles(directory, "*.*")
|
|
.Take(2)
|
|
.ToArray();
|
|
|
|
if (imageFiles.Length < 2)
|
|
{
|
|
Console.WriteLine($"تعداد تصاویر کافی برای {directoryName} وجود ندارد");
|
|
continue;
|
|
}
|
|
|
|
using var formData = new MultipartFormDataContent();
|
|
formData.Add(new StringContent(directoryName), "employee_id");
|
|
formData.Add(new StringContent(workshopName), "workshop_id");
|
|
formData.Add(new StringContent(fullname), "employee_full_name");
|
|
|
|
FileStream file1Stream = null;
|
|
FileStream file2Stream = null;
|
|
|
|
try
|
|
{
|
|
// ارسال فایل اول
|
|
file1Stream = new FileStream(imageFiles[0], FileMode.Open, FileAccess.Read);
|
|
var file1Content = new StreamContent(file1Stream);
|
|
file1Content.Headers.ContentType =
|
|
new System.Net.Http.Headers.MediaTypeHeaderValue("image/jpeg");
|
|
formData.Add(file1Content, "picture1", Path.GetFileName(imageFiles[0]));
|
|
|
|
// ارسال فایل دوم
|
|
file2Stream = new FileStream(imageFiles[1], FileMode.Open, FileAccess.Read);
|
|
var file2Content = new StreamContent(file2Stream);
|
|
file2Content.Headers.ContentType =
|
|
new System.Net.Http.Headers.MediaTypeHeaderValue("image/jpeg");
|
|
formData.Add(file2Content, "picture2", Path.GetFileName(imageFiles[1]));
|
|
|
|
var response = await client.PostAsync("http://127.0.0.1:8000/embeddings", formData);
|
|
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
var result = await response.Content.ReadAsStringAsync();
|
|
Console.WriteLine($"✓ {directoryName}: {result}");
|
|
}
|
|
else
|
|
{
|
|
var error = await response.Content.ReadAsStringAsync();
|
|
Console.WriteLine($"✗ {directoryName}: {response.StatusCode} - {error}");
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
file1Stream?.Dispose();
|
|
file2Stream?.Dispose();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private async System.Threading.Tasks.Task UpdateFaceEmbeddingNames()
|
|
{
|
|
var rollCallEmployees = await _context.RollCallEmployees
|
|
.Where(x => x.HasChangedName)
|
|
.ToListAsync();
|
|
foreach (var rollCallEmployee in rollCallEmployees)
|
|
{
|
|
await _faceEmbeddingService.UpdateEmbeddingFullNameAsync(rollCallEmployee.EmployeeId,
|
|
rollCallEmployee.WorkshopId, rollCallEmployee.EmployeeFullName);
|
|
}
|
|
}
|
|
|
|
public async Task<IActionResult> OnPostPaymentGateWay(CancellationToken cancellationToken)
|
|
{
|
|
var command = new CreatePaymentGatewayRequest()
|
|
{
|
|
Amount = 1000,
|
|
Email = "mahanch83@gmail.com",
|
|
CallBackUrl = Url.Page("/CallBack/Index", null, null, Request.Scheme, Request.Host.Value),
|
|
TransactionId = "{C771E841-B810-413D-9D4C-9F659575B8CC}",
|
|
};
|
|
var createResponse = await _paymentGateway.Create(command, cancellationToken);
|
|
|
|
|
|
if (createResponse.Status == "success")
|
|
{
|
|
return Redirect(_paymentGateway.GetStartPayUrl(createResponse.Token));
|
|
}
|
|
|
|
//TranslateCode(result?.ErrorCode);
|
|
return Page();
|
|
}
|
|
[DisableConcurrentExecution(timeoutInSeconds: 120)]
|
|
public async Task<IActionResult> OnPostUploadFrontEnd(CancellationToken cancellationToken)
|
|
{
|
|
var validAccountId = _authHelper.CurrentAccountId();
|
|
if (validAccountId == 2 || validAccountId == 322)
|
|
{
|
|
var batPath = @"C:\next-ui\deploy-next-ui.bat";
|
|
|
|
var psi = new ProcessStartInfo
|
|
{
|
|
FileName = batPath,
|
|
UseShellExecute = true, // خیلی مهم
|
|
Verb = "runas", // اجرای Administrator
|
|
CreateNoWindow = true,
|
|
WindowStyle = ProcessWindowStyle.Hidden
|
|
};
|
|
|
|
Process.Start(psi);
|
|
|
|
TempData["Message"] = "فرآیند Deploy شروع شد. لاگ را بررسی کنید.";
|
|
return RedirectToPage();
|
|
}
|
|
return Forbid();
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// افزودن آی دی طرف حساب به کارگاه
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[DisableConcurrentExecution(timeoutInSeconds: 120)]
|
|
public async Task<IActionResult> OnPostContractingPartyToWorkshop()
|
|
{
|
|
var workshops = await _context.Workshops.Where(x => x.ContractingPartyId == 0).ToListAsync();
|
|
|
|
var worskhopEmployeer = await _context.WorkshopEmployers.Include(x => x.Employer).ToListAsync();
|
|
|
|
var contractingParties = await _context.PersonalContractingParties.ToListAsync();
|
|
|
|
foreach (var workshop in workshops)
|
|
{
|
|
var employers = worskhopEmployeer.Where(x => x.WorkshopId == workshop.id);
|
|
var contractingPartyIdList = new List<long>();
|
|
foreach (var employer in employers)
|
|
{
|
|
if (contractingParties.Any(x => x.id == employer.Employer.ContractingPartyId))
|
|
{
|
|
contractingPartyIdList.Add(employer.Employer.ContractingPartyId);
|
|
}
|
|
|
|
}
|
|
|
|
if (contractingPartyIdList.Count > 0)
|
|
{
|
|
|
|
|
|
if (contractingPartyIdList.Count == 1)
|
|
{
|
|
workshop.AddContractingPartyId(contractingPartyIdList[0]);
|
|
await _context.SaveChangesAsync();
|
|
}
|
|
else
|
|
{
|
|
var idDistinct = contractingPartyIdList.Distinct().ToList();
|
|
if (idDistinct.Count == 1)
|
|
{
|
|
workshop.AddContractingPartyId(contractingPartyIdList[0]);
|
|
await _context.SaveChangesAsync();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
ViewData["message"] = "آی دی های طرف حساب اضافه شد";
|
|
return Page();
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// دریافت لاگ آپلود فرانت
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public IActionResult OnGetLog()
|
|
{
|
|
var validAccountId = _authHelper.CurrentAccountId();
|
|
if (validAccountId == 2 || validAccountId == 322)
|
|
{
|
|
var logPath = @"C:\next-ui\log.txt";
|
|
if (!System.IO.File.Exists(logPath))
|
|
return Content("Log file not found.");
|
|
|
|
var content = System.IO.File.ReadAllText(logPath, Encoding.UTF8);
|
|
return Content(content);
|
|
}
|
|
return Content("شما مجاز به دیدن لاگ نیستید");
|
|
|
|
}
|
|
|
|
|
|
public async System.Threading.Tasks.Task OnGetCallback(string? transid, string? cardnumber,
|
|
string? tracking_number, string status)
|
|
{
|
|
if (string.IsNullOrEmpty(cardnumber) || string.IsNullOrEmpty(tracking_number))
|
|
{
|
|
ViewData["message"] = "پرداخت ناموفق بوده است";
|
|
return;
|
|
}
|
|
else if (status == "1")
|
|
{
|
|
ViewData["message"] = "پرداخت موفق بوده است";
|
|
return;
|
|
}
|
|
//var client = _httpClientFactory.CreateClient();
|
|
//var response = await client.PostAsJsonAsync("https://panel.aqayepardakht.ir/api/v2/verify", new
|
|
//{
|
|
// pin = "aqayepardakht",
|
|
// amount = 100,
|
|
// transid = transid,
|
|
//});
|
|
|
|
//var result = await response.Content.ReadFromJsonAsync<TokenResponse>();
|
|
}
|
|
|
|
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();
|
|
}
|
|
|
|
private async System.Threading.Tasks.Task SetPublicId()
|
|
{
|
|
var financialStatements =
|
|
await _context.FinancialStatments.Where(x => x.PublicId == Guid.Empty).ToListAsync();
|
|
foreach (var financialStatement in financialStatements)
|
|
{
|
|
financialStatement.SetPublicId();
|
|
}
|
|
|
|
await _context.SaveChangesAsync();
|
|
}
|
|
|
|
#region InstitutionContract
|
|
|
|
private async System.Threading.Tasks.Task UpdateInstitutionContract()
|
|
{
|
|
var today = DateTime.Today;
|
|
var transaction = await _context.Database.BeginTransactionAsync();
|
|
|
|
var query = _context.InstitutionContractSet
|
|
.Where(a => a.VerifyCode == null
|
|
&& a.PublicId == Guid.Empty)
|
|
.Include(x => x.WorkshopGroup)
|
|
.Join(_context.PersonalContractingParties
|
|
.Include(x => x.Employers)
|
|
.ThenInclude(x => x.WorkshopEmployers)
|
|
.ThenInclude(x => x.Workshop)
|
|
.ThenInclude(x => x.LeftWorks),
|
|
contract => contract.ContractingPartyId,
|
|
contractingParty => contractingParty.id,
|
|
(contract, contractingParty) => new { contract, contractingParty });
|
|
|
|
|
|
var remoteContractsQuery = query
|
|
.Where(x => x.contractingParty.Employers
|
|
.Any(e => e.WorkshopEmployers
|
|
.Any(we => we.Workshop.ArchiveCode == "99")));
|
|
|
|
var remoteContracts = remoteContractsQuery.ToList();
|
|
|
|
foreach (var item in remoteContracts)
|
|
{
|
|
item.contract.ClearGroup();
|
|
await _context.SaveChangesAsync();
|
|
//TODO: set data for institution price
|
|
var workshops = item.contractingParty.Employers
|
|
.SelectMany(e => e.WorkshopEmployers.Select(we => we.Workshop)).ToList()
|
|
.DistinctBy(x => x.id).ToList();
|
|
|
|
var initialWorkshop = workshops
|
|
.Select(w =>
|
|
{
|
|
var personnelCount =
|
|
w.LeftWorks.Count(lw => lw.StartWorkDate <= today && lw.LeftWorkDate >= today);
|
|
|
|
var rollCallService = _context.RollCallServices
|
|
.Where(x => x.WorkshopId == w.id)
|
|
.ToList().MaxBy(x => x.StartService);
|
|
|
|
var calculation = _clientRegistrationApplication
|
|
.GetInstitutionPlanForWorkshop(new WorkshopTempViewModel()
|
|
{
|
|
CustomizeCheckout = false,
|
|
Insurance = true,
|
|
InsuranceInPerson = false,
|
|
RollCall = rollCallService != null,
|
|
WorkshopName = "",
|
|
ContractAndCheckout = true,
|
|
ContractAndCheckoutInPerson = false,
|
|
ContractingPartyTempId = 0,
|
|
CountPerson = personnelCount
|
|
});
|
|
var amount = calculation.OnlineAndInPersonSumAmountDouble;
|
|
|
|
var initial = InstitutionContractWorkshopInitial.CreateManual(w.WorkshopFullName, false,
|
|
false, false, true,
|
|
false, true, false, personnelCount, amount,
|
|
w.id, w.WorkshopEmployers.Select(x => x.EmployerId
|
|
).ToList());
|
|
return initial;
|
|
}).ToList();
|
|
|
|
var group = new InstitutionContractWorkshopGroup(item.contract.id, initialWorkshop);
|
|
|
|
var current = initialWorkshop.Select(x =>
|
|
{
|
|
var entity = new InstitutionContractWorkshopCurrent(x.WorkshopName,
|
|
x.Services.RollCall, x.Services.RollCallInPerson, x.Services.CustomizeCheckout,
|
|
x.Services.Contract,
|
|
x.Services.ContractInPerson, x.Services.Insurance, x.Services.InsuranceInPerson,
|
|
x.PersonnelCount,
|
|
x.Price, x.InstitutionContractWorkshopGroupId,
|
|
group,
|
|
x.WorkshopId.Value,x.id);
|
|
entity.SetEmployers(x.Employers.Select(e => e.EmployerId).ToList());
|
|
|
|
return entity;
|
|
}).ToList();
|
|
|
|
group.UpdateCurrentWorkshops(current);
|
|
|
|
await _context.AddAsync(group);
|
|
await _context.SaveChangesAsync();
|
|
|
|
//var oneMonthSum = current.Sum(x => x.Price);
|
|
item.contract.SetWorkshopGroup(group);
|
|
// var totalPaymentAndWorkshopList = await _clientRegistrationApplication.GetTotalPaymentAndWorkshopList(oneMonthSum,duration: InstitutionContractDuration.TwelveMonths,false);
|
|
// item.contract.SetAmount(totalPaymentAndWorkshopList.OneTimeTotalPaymentStr.MoneyToDouble(),
|
|
// totalPaymentAndWorkshopList.OneTimeValueAddedTaxStr.MoneyToDouble(),totalPaymentAndWorkshopList.DiscountedAmountForOneMonth.MoneyToDouble());
|
|
}
|
|
|
|
var remoteIds = remoteContractsQuery.Select(x => x.contract.id);
|
|
var inPersonContracts = await query
|
|
.Where(x => !remoteIds.Contains(x.contractingParty.id)).ToListAsync();
|
|
foreach (var item in inPersonContracts)
|
|
{
|
|
var workshops = item.contractingParty.Employers
|
|
.SelectMany(e => e.WorkshopEmployers.Select(we => we.Workshop)).ToList()
|
|
.DistinctBy(x => x.id).ToList();
|
|
|
|
|
|
var initialWorkshop = workshops
|
|
.Select(w =>
|
|
{
|
|
var personnelCount =
|
|
w.LeftWorks.Count(lw => lw.StartWorkDate <= today && lw.LeftWorkDate >= today);
|
|
|
|
var rollCallService = _context.RollCallServices
|
|
.Where(x => x.WorkshopId == w.id)
|
|
.ToList().MaxBy(x => x.StartService);
|
|
|
|
bool hasRollCallPlan = rollCallService != null;
|
|
bool hasRollCallPlanInPerson = rollCallService != null;
|
|
bool hasCustomizeCheckoutPlan = w.id == 170;
|
|
bool hasContractPlan = true;
|
|
bool hasContractPlanInPerson = true;
|
|
bool hasInsurancePlan = true;
|
|
bool hasInsurancePlanInPerson = true;
|
|
|
|
var initial = InstitutionContractWorkshopInitial.CreateManual(w.WorkshopFullName,
|
|
hasRollCallPlan,
|
|
hasRollCallPlanInPerson, hasCustomizeCheckoutPlan,
|
|
hasContractPlan, hasContractPlanInPerson,
|
|
hasInsurancePlan, hasInsurancePlanInPerson, personnelCount, 0,
|
|
w.id, w.WorkshopEmployers.Select(x => x.EmployerId
|
|
).ToList());
|
|
return initial;
|
|
}).ToList();
|
|
|
|
var group = new InstitutionContractWorkshopGroup(item.contract.id, initialWorkshop);
|
|
|
|
await _context.AddAsync(group);
|
|
await _context.SaveChangesAsync();
|
|
|
|
initialWorkshop.ForEach(x =>
|
|
{
|
|
var workshopId = workshops.First(w => x.WorkshopId.Value == w.id).id;
|
|
x.SetWorkshopId(workshopId);
|
|
});
|
|
|
|
item.contract.SetWorkshopGroup(group);
|
|
}
|
|
|
|
await _context.SaveChangesAsync();
|
|
|
|
await transaction.CommitAsync();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Excel
|
|
|
|
/// <summary>
|
|
/// خروجی اکسل آقایی آذر ورکشاپ
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private byte[] OnGetExportAsghaeeAzarWorkshops()
|
|
{
|
|
var data = _context.CheckoutSet
|
|
.Where(x => x.WorkshopId == 768 && x.Month =="آذر" && x.Year =="1404")
|
|
.Select(x => new AsghaeeAzarWorkshopsExcelViewModel()
|
|
{
|
|
FinalAmount = x.TotalPayment.ToMoney(),
|
|
FullName = x.EmployeeFullName,
|
|
NationalCode = x.NationalCode
|
|
}).ToList();
|
|
|
|
return AsghaeeAzarWorkshopsExcelGenerator.Generate(data);
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
|
|
public class IndexModel2 : PageModel
|
|
{
|
|
private readonly ILogger<IndexModel2> logger;
|
|
private readonly IHttpClientFactory httpClientFactory;
|
|
|
|
public IndexModel2(ILogger<IndexModel2> logger, IHttpClientFactory httpClientFactory)
|
|
{
|
|
this.logger = logger;
|
|
this.httpClientFactory = httpClientFactory;
|
|
}
|
|
|
|
[BindProperty] public string? Message { get; set; }
|
|
|
|
public void OnGet()
|
|
{
|
|
}
|
|
|
|
public async Task<IActionResult> OnPostAsync()
|
|
{
|
|
Message = null;
|
|
|
|
var client = httpClientFactory.CreateClient();
|
|
var response = await client.PostAsJsonAsync("https://panel.aqayepardakht.ir/api/v2/create", new
|
|
{
|
|
pin = "aqayepardakht",
|
|
amount = 100,
|
|
callback = System.Web.HttpUtility.UrlEncode(Url.Page("./Index", "Callback", null, Request.Scheme,
|
|
Request.Host.Value)),
|
|
card_number = "1111111111111111",
|
|
invoice_id = "{C771E841-B810-413D-9D4C-9F659575B8CC}",
|
|
mobile = "09121111111",
|
|
email = "test@test.com",
|
|
description = "توضیحات تست",
|
|
});
|
|
|
|
var result = await response.Content.ReadFromJsonAsync<TokenResponse>();
|
|
if (response.StatusCode == System.Net.HttpStatusCode.OK)
|
|
{
|
|
return Redirect($"https://panel.aqayepardakht.ir/startpay/{result?.TransactionId}");
|
|
}
|
|
|
|
TranslateCode(result?.ErrorCode);
|
|
return Page();
|
|
}
|
|
|
|
public async System.Threading.Tasks.Task OnGetCallbackAsync(string? transid, string? cardnumber,
|
|
string? tracking_number)
|
|
{
|
|
Message = null;
|
|
|
|
if (string.IsNullOrEmpty(cardnumber) || string.IsNullOrEmpty(tracking_number))
|
|
{
|
|
Message = "پرداخت ناموفق بوده است";
|
|
return;
|
|
}
|
|
|
|
var client = httpClientFactory.CreateClient();
|
|
var response = await client.PostAsJsonAsync("https://panel.aqayepardakht.ir/api/v2/verify", new
|
|
{
|
|
pin = "aqayepardakht",
|
|
amount = 100,
|
|
transid = transid,
|
|
});
|
|
|
|
var result = await response.Content.ReadFromJsonAsync<TokenResponse>();
|
|
TranslateCode(result?.ErrorCode);
|
|
}
|
|
|
|
private void TranslateCode(int? code)
|
|
{
|
|
switch (code)
|
|
{
|
|
case 0:
|
|
Message = "پرداخت انجام نشد";
|
|
break;
|
|
case 1:
|
|
Message = "پرداخت با موفقیت انجام شد";
|
|
break;
|
|
case 2:
|
|
Message = "تراکنش قبلا وریفای شده است";
|
|
break;
|
|
case -1:
|
|
Message = "amount نمی تواند خالی باشد";
|
|
break;
|
|
case -2:
|
|
Message = "کد پین درگاه نمی تواند خالی باشد";
|
|
break;
|
|
case -3:
|
|
Message = "callback نمی تواند خالی باشد";
|
|
break;
|
|
case -4:
|
|
Message = "amount باید عددی باشد";
|
|
break;
|
|
case -5:
|
|
Message = "amount باید بین 100 تا 50,000,000 تومان باشد";
|
|
break;
|
|
case -6:
|
|
Message = "کد پین درگاه اشتباه هست";
|
|
break;
|
|
case -7:
|
|
Message = "transid نمی تواند خالی باشد";
|
|
break;
|
|
case -8:
|
|
Message = "تراکنش مورد نظر وجود ندارد";
|
|
break;
|
|
case -9:
|
|
Message = "کد پین درگاه با درگاه تراکنش مطابقت ندارد";
|
|
break;
|
|
case -10:
|
|
Message = "مبلغ با مبلغ تراکنش مطابقت ندارد";
|
|
break;
|
|
case -11:
|
|
Message = "درگاه درانتظار تایید و یا غیر فعال است";
|
|
break;
|
|
case -12:
|
|
Message = "امکان ارسال درخواست برای این پذیرنده وجود ندارد";
|
|
break;
|
|
case -13:
|
|
Message = "شماره کارت باید 16 رقم چسبیده بهم باشد";
|
|
break;
|
|
default:
|
|
Message = "خطای نامشخص";
|
|
break;
|
|
}
|
|
}
|
|
|
|
public class TokenResponse
|
|
{
|
|
[JsonPropertyName("status")] public string? Status { get; set; }
|
|
|
|
[JsonPropertyName("code")] public int? ErrorCode { get; set; }
|
|
|
|
[JsonPropertyName("transid")] public string? TransactionId { get; set; }
|
|
}
|
|
}
|
|
} |