Compare commits

...

9 Commits

11 changed files with 391 additions and 28 deletions

View File

@@ -98,8 +98,10 @@ public class InstitutionContract : EntityBase
// مبلغ قرارداد
public double ContractAmount { get; private set; }
public double ContractAmountWithTax => !IsOldContract && IsInstallment ? ContractAmount + (ContractAmount * 0.10)
public double ContractAmountWithTax => !IsOldContract ? ContractAmount + ContractAmountTax
: ContractAmount;
public double ContractAmountTax => ContractAmount*0.10;
//خسارت روزانه
public double DailyCompenseation { get; private set; }

View File

@@ -316,7 +316,10 @@ public class Workshop : EntityBase
IsStaticCheckout = isStaticCheckout;
}
public void AddContractingPartyId(long contractingPartyId)
{
ContractingPartyId = contractingPartyId;
}
public void Active(string archiveCode)
{
this.IsActive = true;

View File

@@ -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;
}
}
}

View File

@@ -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; }
}

View File

@@ -23,4 +23,6 @@ public class InstitutionContractPrintViewModel
public string VerifierPhoneNumber { get; set; }
public LawViewModel LawViewModel { get; set; }
public string Obligation { get; set; }
public string OneMonthWithoutTax { get; set; }
public string OneMonthTax { get; set; }
}

View File

@@ -52,5 +52,7 @@ public class InstitutionContractMapping : IEntityTypeConfiguration<InstitutionCo
builder.Ignore(x => x.ContractAmountWithTax);
builder.Ignore(x => x.ContractAmountTax);
builder.Ignore(x => x.ContractAmountTax);
}
}

View File

@@ -3199,6 +3199,8 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
TotalPrice = (institution.TotalAmount - institution.ValueAddedTax).ToMoney(),
TaxPrice = institution.ValueAddedTax.ToMoney(),
OneMonthPrice = institution.ContractAmountWithTax.ToMoney(),
OneMonthWithoutTax = institution.ContractAmount.ToMoney(),
OneMonthTax = institution.ContractAmountTax.ToMoney(),
VerifierFullName = institution.VerifierFullName,
VerifierPhoneNumber = institution.VerifierPhoneNumber,
VerifyCode = institution.VerifyCode,

View File

@@ -0,0 +1,15 @@
@page
<h4>Deploy Log</h4>
<pre style="
background:#111;
color:#0f0;
padding:15px;
max-height:600px;
overflow:auto;
font-size:13px;
border-radius:6px;">
</pre>

View File

@@ -2,6 +2,14 @@
@model ServiceHost.Areas.AdminNew.Pages.Company.AndroidApk.IndexModel
@{
ViewData["Title"] = "File Upload";
<style>
.lineDiv {
width: 100%;
height: 2px;
background-image: linear-gradient(to right, #ffffff, #e5e5e5, #cbcbcb, #b2b2b2, #9a9a9a, #9a9a9a, #9a9a9a, #9a9a9a, #b2b2b2, #cbcbcb, #e5e5e5, #ffffff);
margin: 10px;
}
</style>
}
<h1>Upload APK File</h1>
@@ -60,23 +68,85 @@
</form>
<form style="margin:50px" asp-page-handler="PaymentGateWay" id="11" method="post">
<form style="margin:30px" asp-page-handler="PaymentGateWay" id="11" method="post">
<button type="submit">درگاه پرداخت تستی </button>
</form>
<div class="lineDiv"></div>
<div class="row m-t-20">
<div class="col-4"></div>
<div class="col-2">
<form asp-page-handler="UploadFrontEnd" id="12" method="post">
<button type="submit"
class="btn btn-danger"
onclick="return confirm('آیا از انتشار نسخه جدید فرانت مطمئن هستید؟');">
🚀 Deploy Next UI
</button>
</form>
</div>
<div class="col-2">
<button type="button" class="btn btn-outline-secondary"
data-bs-toggle="modal"
data-bs-target="#logModal">
مشاهده لاگ Deploy
</button>
</div>
<div class="col-4"></div>
</div>
<div class="lineDiv"></div>
<form style="margin:50px" asp-page-handler="UploadFrontEnd" id="12">
<button type="submit"
class="btn btn-danger"
onclick="return confirm('آیا از انتشار نسخه جدید فرانت مطمئن هستید؟');">
🚀 Deploy Next UI
</button>
<div class="modal fade" id="logModal" tabindex="-1">
<div class="modal-dialog modal-xl modal-dialog-scrollable">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Deploy Log</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<pre id="logContent"
style="background: #111;
color: #0f0;
padding: 15px;
font-size: 13px;
text-align: left;
direction: ltr;">
</pre>
</div>
</div>
</div>
</div>
<form style="margin:20px" asp-page-handler="ContractingPartyToWorkshop" id="13" method="post">
<button class="btn btn-outline-secondary" type="submit"> افزودن آی دی طرف حساب به کارگاه </button>
</form>
@if (ViewData["message"] != null)
{
<p>@ViewData["message"]</p>
}
<script>
document.getElementById('logModal')
.addEventListener('show.bs.modal', function () {
fetch('?handler=Log')
.then(r => r.text())
.then(t => {
document.getElementById('logContent').textContent = t;
});
});
</script>
@* <script>

View File

@@ -19,6 +19,7 @@ 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;
@@ -31,7 +32,10 @@ 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 CompanyManagement.Infrastructure.Excel.Checkout;
using Microsoft.AspNetCore.Authentication;
using static ServiceHost.Areas.AdminNew.Pages.Company.AndroidApk.IndexModel2;
namespace ServiceHost.Areas.AdminNew.Pages.Company.AndroidApk
@@ -48,6 +52,7 @@ namespace ServiceHost.Areas.AdminNew.Pages.Company.AndroidApk
private readonly IHttpClientFactory _httpClientFactory;
private readonly IOnlinePayment _onlinePayment;
private readonly IFaceEmbeddingService _faceEmbeddingService;
private readonly IAuthHelper _authHelper;
[BindProperty] public IFormFile File { get; set; }
@@ -62,13 +67,18 @@ namespace ServiceHost.Areas.AdminNew.Pages.Company.AndroidApk
[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)
ITemporaryClientRegistrationApplication clientRegistrationApplication, IOnlinePayment onlinePayment, IFaceEmbeddingService faceEmbeddingService, IAuthHelper authHelper)
{
_application = application;
_rollCallDomainService = rollCallDomainService;
@@ -78,6 +88,7 @@ namespace ServiceHost.Areas.AdminNew.Pages.Company.AndroidApk
_clientRegistrationApplication = clientRegistrationApplication;
_onlinePayment = onlinePayment;
_faceEmbeddingService = faceEmbeddingService;
_authHelper = authHelper;
_paymentGateway = new SepehrPaymentGateway(httpClientFactory);
}
@@ -142,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();
}
@@ -316,26 +333,106 @@ namespace ServiceHost.Areas.AdminNew.Pages.Company.AndroidApk
//TranslateCode(result?.ErrorCode);
return Page();
}
[DisableConcurrentExecution(timeoutInSeconds: 120)]
public async Task<IActionResult> OnPostUploadFrontEnd(CancellationToken cancellationToken)
{
var batPath = @"C:\next-ui\deploy-next-ui.bat";
var psi = new ProcessStartInfo
var validAccountId = _authHelper.CurrentAccountId();
if (validAccountId == 2 || validAccountId == 322)
{
FileName = batPath,
UseShellExecute = true, // خیلی مهم
Verb = "runas", // اجرای Administrator
CreateNoWindow = true,
WindowStyle = ProcessWindowStyle.Normal
};
var batPath = @"C:\next-ui\deploy-next-ui.bat";
Process.Start(psi);
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();
TempData["Message"] = "فرآیند Deploy شروع شد. لاگ را بررسی کنید.";
return RedirectToPage();
}
/// <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)
{
@@ -883,8 +980,8 @@ namespace ServiceHost.Areas.AdminNew.Pages.Company.AndroidApk
contract => contract.ContractingPartyId,
contractingParty => contractingParty.id,
(contract, contractingParty) => new { contract, contractingParty });
var remoteContractsQuery = query
.Where(x => x.contractingParty.Employers
.Any(e => e.WorkshopEmployers
@@ -1021,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

View File

@@ -70,7 +70,8 @@ public class ParameterBindingConvention : IApplicationModelConvention
{
if (selector.AttributeRouteModel?.Template != null)
{
if (selector.AttributeRouteModel.Template.Contains($"{{{parameterName}}}", StringComparison.OrdinalIgnoreCase))
if (selector.AttributeRouteModel.Template.Contains($"{{{parameterName}}}", StringComparison.OrdinalIgnoreCase) ||
selector.AttributeRouteModel.Template.Contains($"{{{parameterName}:", StringComparison.OrdinalIgnoreCase))
return true;
}
}
@@ -80,7 +81,8 @@ public class ParameterBindingConvention : IApplicationModelConvention
{
if (selector.AttributeRouteModel?.Template != null)
{
if (selector.AttributeRouteModel.Template.Contains($"{{{parameterName}}}", StringComparison.OrdinalIgnoreCase))
if (selector.AttributeRouteModel.Template.Contains($"{{{parameterName}}}", StringComparison.OrdinalIgnoreCase) ||
selector.AttributeRouteModel.Template.Contains($"{{{parameterName}:", StringComparison.OrdinalIgnoreCase))
return true;
}
}