Enhance financial invoice handling by adding InvoiceNumber property and increasing DescriptionOption max length; implement SetPendingWorkflow method

This commit is contained in:
2025-11-17 20:51:21 +03:30
parent ed746cb60a
commit f238b5af6b
16 changed files with 33978 additions and 33 deletions

View File

@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Net.Http.Json;
using System.Threading;
@@ -20,6 +21,7 @@ public class SepehrPaymentGateway:IPaymentGateway
public async Task<PaymentGatewayResponse> Create(CreatePaymentGatewayRequest command, CancellationToken cancellationToken = default)
{
command.ExtraData ??= new Dictionary<string, object>();
command.ExtraData.Add("financialInvoiceId", command.FinancialInvoiceId);
var extraData = JsonConvert.SerializeObject(command.ExtraData);
var res = await _httpClient.PostAsJsonAsync("GetToken", new

View File

@@ -251,6 +251,8 @@ public interface IInstitutionContractApplication
/// <param name="id"></param>
/// <returns></returns>
Task<InstitutionContractPrintViewModel> PrintOneAsync(long id);
Task<OperationResult> SetPendingWorkflow(long entityId);
}
public class InstitutionContractPrintViewModel

View File

@@ -1304,7 +1304,7 @@ public class InstitutionContractApplication : IInstitutionContractApplication
financialInvoiceItemType = FinancialInvoiceItemType.BuyInstitutionContract;
}
var financialInvoice = _financialInvoiceRepository.GetUnPaidByEntityId(entityId, financialInvoiceItemType);
var financialInvoice =await _financialInvoiceRepository.GetUnPaidByEntityId(entityId, financialInvoiceItemType);
var amount = financialInvoice.Amount;
var transaction = new PaymentTransaction(institutionContract.ContractingPartyId, amount,
@@ -1456,6 +1456,24 @@ public class InstitutionContractApplication : IInstitutionContractApplication
return (await _institutionContractRepository.PrintAllAsync([id])).FirstOrDefault();
}
public async Task<OperationResult> SetPendingWorkflow(long entityId)
{
var op = new OperationResult();
var institutionContract = _institutionContractRepository.Get(entityId);
if (institutionContract == null)
{
return op.Failed("قرارداد مالی یافت نشد");
}
if (institutionContract.VerificationStatus != InstitutionContractVerificationStatus.PendingForVerify)
{
return op.Failed("وضعیت قرارداد مالی برای این عملیات مناسب نمی باشد");
}
institutionContract.SetPendingWorkflow();
await _institutionContractRepository.SaveChangesAsync();
return op.Succcedded();
}
private async Task<OperationResult<PersonalContractingParty>> CreateLegalContractingPartyEntity(
CreateInstitutionContractLegalPartyRequest request, long representativeId, string address, string city,

View File

@@ -13,7 +13,8 @@ public class FinancialInvoiceMapping:IEntityTypeConfiguration<FinancialInvoice>
builder.Property(x => x.Status).HasConversion<string>().HasMaxLength(20);
builder.Property(x => x.PaidAt).IsRequired(false);
builder.Property(x => x.Description).HasMaxLength(800);
builder.Property(x => x.InvoiceNumber).HasMaxLength(22);
builder.HasMany(x => x.Items).WithOne(x => x.FinancialInvoice)
.HasForeignKey(x => x.FinancialInvoiceId).IsRequired().OnDelete(DeleteBehavior.Cascade);
builder.HasMany(x => x.PaymentTransactions).WithOne(x => x.FinancialInvoice)

View File

@@ -14,7 +14,7 @@ public class FinancialTransactionMapping : IEntityTypeConfiguration<FinancialTra
builder.Property(x => x.TdateFa);
builder.Property(x => x.TdateFa).HasMaxLength(10);
builder.Property(x => x.TypeOfTransaction).HasMaxLength(10);
builder.Property(x => x.DescriptionOption).HasMaxLength(50);
builder.Property(x => x.DescriptionOption).HasMaxLength(100);
builder.Property(x => x.Description).HasMaxLength(600);
builder.Property(x => x.Deptor);
builder.Property(x => x.Creditor);

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,59 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace CompanyManagment.EFCore.Migrations
{
/// <inheritdoc />
public partial class addinvoicenumber : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_FinancialInvoices_FinancialStatments_FinancialStatmentid",
table: "FinancialInvoices");
migrationBuilder.DropIndex(
name: "IX_FinancialInvoices_FinancialStatmentid",
table: "FinancialInvoices");
migrationBuilder.DropColumn(
name: "FinancialStatmentid",
table: "FinancialInvoices");
migrationBuilder.AddColumn<string>(
name: "InvoiceNumber",
table: "FinancialInvoices",
type: "nvarchar(18)",
maxLength: 18,
nullable: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "InvoiceNumber",
table: "FinancialInvoices");
migrationBuilder.AddColumn<long>(
name: "FinancialStatmentid",
table: "FinancialInvoices",
type: "bigint",
nullable: true);
migrationBuilder.CreateIndex(
name: "IX_FinancialInvoices_FinancialStatmentid",
table: "FinancialInvoices",
column: "FinancialStatmentid");
migrationBuilder.AddForeignKey(
name: "FK_FinancialInvoices_FinancialStatments_FinancialStatmentid",
table: "FinancialInvoices",
column: "FinancialStatmentid",
principalTable: "FinancialStatments",
principalColumn: "id");
}
}
}

View File

@@ -0,0 +1,40 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace CompanyManagment.EFCore.Migrations
{
/// <inheritdoc />
public partial class changemaxlengthforfinancialinvoicenumber : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "InvoiceNumber",
table: "FinancialInvoices",
type: "nvarchar(22)",
maxLength: 22,
nullable: true,
oldClrType: typeof(string),
oldType: "nvarchar(18)",
oldMaxLength: 18,
oldNullable: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "InvoiceNumber",
table: "FinancialInvoices",
type: "nvarchar(18)",
maxLength: 18,
nullable: true,
oldClrType: typeof(string),
oldType: "nvarchar(22)",
oldMaxLength: 22,
oldNullable: true);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,40 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace CompanyManagment.EFCore.Migrations
{
/// <inheritdoc />
public partial class changedescriptionOptionmaxlength : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "DescriptionOption",
table: "FinancialTransactions",
type: "nvarchar(100)",
maxLength: 100,
nullable: true,
oldClrType: typeof(string),
oldType: "nvarchar(50)",
oldMaxLength: 50,
oldNullable: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "DescriptionOption",
table: "FinancialTransactions",
type: "nvarchar(50)",
maxLength: 50,
nullable: true,
oldClrType: typeof(string),
oldType: "nvarchar(100)",
oldMaxLength: 100,
oldNullable: true);
}
}
}

View File

@@ -2848,8 +2848,9 @@ namespace CompanyManagment.EFCore.Migrations
.HasMaxLength(800)
.HasColumnType("nvarchar(800)");
b.Property<long?>("FinancialStatmentid")
.HasColumnType("bigint");
b.Property<string>("InvoiceNumber")
.HasMaxLength(22)
.HasColumnType("nvarchar(22)");
b.Property<bool>("IsActive")
.HasColumnType("bit");
@@ -2867,8 +2868,6 @@ namespace CompanyManagment.EFCore.Migrations
b.HasKey("id");
b.HasIndex("FinancialStatmentid");
b.ToTable("FinancialInvoices");
});
@@ -2959,8 +2958,8 @@ namespace CompanyManagment.EFCore.Migrations
.HasColumnType("nvarchar(600)");
b.Property<string>("DescriptionOption")
.HasMaxLength(50)
.HasColumnType("nvarchar(50)");
.HasMaxLength(100)
.HasColumnType("nvarchar(100)");
b.Property<long>("FinancialStatementId")
.HasColumnType("bigint");
@@ -10036,13 +10035,6 @@ namespace CompanyManagment.EFCore.Migrations
b.Navigation("FileTiming");
});
modelBuilder.Entity("Company.Domain.FinancialInvoiceAgg.FinancialInvoice", b =>
{
b.HasOne("Company.Domain.FinancialStatmentAgg.FinancialStatment", null)
.WithMany("FinancialInvoices")
.HasForeignKey("FinancialStatmentid");
});
modelBuilder.Entity("Company.Domain.FinancialInvoiceAgg.FinancialInvoiceItem", b =>
{
b.HasOne("Company.Domain.FinancialInvoiceAgg.FinancialInvoice", "FinancialInvoice")
@@ -11024,8 +11016,6 @@ namespace CompanyManagment.EFCore.Migrations
modelBuilder.Entity("Company.Domain.FinancialStatmentAgg.FinancialStatment", b =>
{
b.Navigation("FinancialInvoices");
b.Navigation("FinancialTransactionList");
});

View File

@@ -14,6 +14,7 @@ using _0_Framework.InfraStructure;
using Company.Domain.ContarctingPartyAgg;
using Company.Domain.ContractingPartyAccountAgg;
using Company.Domain.empolyerAgg;
using Company.Domain.FinancialInvoiceAgg;
using Company.Domain.FinancialStatmentAgg;
using Company.Domain.FinancialTransactionAgg;
using Company.Domain.InstitutionContractAgg;
@@ -23,6 +24,7 @@ using Company.Domain.InstitutionContractExtensionTempAgg;
using Company.Domain.InstitutionPlanAgg;
using Company.Domain.WorkshopAgg;
using CompanyManagment.App.Contracts.Employer;
using CompanyManagment.App.Contracts.FinancialInvoice;
using CompanyManagment.App.Contracts.InstitutionContract;
using CompanyManagment.App.Contracts.InstitutionContractContactinfo;
using CompanyManagment.App.Contracts.Law;
@@ -1839,7 +1841,8 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
public async Task<InstitutionContract> GetByPublicIdAsync(Guid id)
{
return await _context.InstitutionContractSet.Include(x=>x.ContactInfoList)
return await _context.InstitutionContractSet
.Include(x=>x.ContactInfoList)
.Include(x=>x.Installments)
.FirstOrDefaultAsync(x => x.PublicId == id);
}
@@ -2297,6 +2300,10 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
}
var today = DateTime.Today;
double invoiceAmount;
string invoiceItemDescription;
FinancialInvoiceItemType invoiceItemType;
long invoiceItemEntityId;
if (request.IsInstallment && payment is InstitutionContractPaymentMonthlyViewModel monthly)
{
var installments = monthly.Installments.Select(x =>
@@ -2313,23 +2320,40 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
// ایجاد قسط جدید با تاریخ امروز
var todayInstallment = new InstitutionContractInstallment(DateTime.Today, firstInstallmentAmount, "");
var financialTransaction = new FinancialTransaction(0, today, today.ToFarsi(),
"قسط اول سرویس", "debt", "بابت خدمات", firstInstallmentAmount, 0, 0);
financialStatement.AddFinancialTransaction(financialTransaction);
// اضافه کردن قسط جدید به ابتدای لیست
installments.Insert(0, todayInstallment);
entity.SetInstallments(installments);
await SaveChangesAsync();
var financialTransaction = new FinancialTransaction(0, today, today.ToFarsi(),
"قسط اول سرویس", "debt", "بابت خدمات", firstInstallmentAmount, 0, 0);
financialStatement.AddFinancialTransaction(financialTransaction);
invoiceAmount = firstInstallmentAmount;
invoiceItemDescription = $"پرداخت قسط اول قرارداد شماره {entity.ContractNo}";
invoiceItemType = FinancialInvoiceItemType.BuyInstitutionContractInstallment;
invoiceItemEntityId = todayInstallment.Id;
}
else
{
var financialTransaction = new FinancialTransaction(0, today, today.ToFarsi(),
"پرداخت کل سرویس", "debt", "بابت خدمات", totalAmount, 0, 0);
financialStatement.AddFinancialTransaction(financialTransaction);
invoiceAmount = totalAmount;
invoiceItemDescription = $"پرداخت کل قرارداد شماره {entity.ContractNo}";
invoiceItemType = FinancialInvoiceItemType.BuyInstitutionContract;
invoiceItemEntityId = entity.id;
}
var financialInvoice = new FinancialInvoice(invoiceAmount, contractingParty.id, $"خرید قرارداد مالی شماره {entity.ContractNo}");
var financialInvoiceItem = new FinancialInvoiceItem(invoiceItemDescription, invoiceAmount, 0,invoiceItemType, invoiceItemEntityId);
financialInvoice.AddItem(financialInvoiceItem);
await _context.AddAsync(financialInvoice);
await SaveChangesAsync();
foreach (var contactInfo in institutionContractTemp.ContactInfos)
{
if (contactInfo.PhoneNumber != null)

View File

@@ -467,13 +467,37 @@ public class institutionContractController : AdminBaseController
[HttpPost("/api/institutionContract/Verify")]
[AllowAnonymous]
public async Task<IActionResult> Verify([FromForm] InstitutionVerificationRequest command)
public async Task<ActionResult<OperationResult<string>>> Verify([FromBody] InstitutionVerificationRequest command)
{
var callBack = Url.Action("Verify", "General", null, Request.Scheme);
var res = await _institutionContractApplication.VerifyOtpAndMakeGateway(command.Id, command.Code, callBack);
// URL برای redirect به درگاه پرداخت
var paymentRedirectUrl = Url.Action("ProcessPayment", "institutionContract", new { area = "Admin" }, Request.Scheme);
var res = await _institutionContractApplication.VerifyOtpAndMakeGateway(command.Id, command.Code, paymentRedirectUrl);
if (!res.IsSuccedded)
return new OperationResult<string>().Failed(res.Message);
var payUrl = _paymentGateway.GetStartPayUrl(res.Data);
return Redirect(payUrl);
// URL کامل برای redirect شامل paymentUrl به عنوان query parameter
var redirectUrl = $"{paymentRedirectUrl}?paymentUrl={Uri.EscapeDataString(payUrl)}";
return new OperationResult<string>().Succcedded(redirectUrl);
}
[HttpGet("/api/institutionContract/ProcessPayment")]
[AllowAnonymous]
public IActionResult ProcessPayment([FromQuery] string paymentUrl)
{
if (string.IsNullOrEmpty(paymentUrl))
{
return BadRequest("Payment URL is required");
}
// redirect به درگاه پرداخت
return Redirect(paymentUrl);
}
[HttpPost("/api/institutionContract/Verification/{id:guid}/send-otp")]
[AllowAnonymous]

View File

@@ -20,6 +20,7 @@ using System.Net.Http;
using System.Security.Cryptography;
using System.Threading;
using CompanyManagment.App.Contracts.FinancialInvoice;
using CompanyManagment.App.Contracts.InstitutionContract;
namespace ServiceHost.Controllers;
@@ -29,15 +30,18 @@ public class GeneralController : GeneralBaseController
private readonly IPaymentGateway _paymentGateway;
private readonly IFinancialStatmentApplication _financialStatmentApplication;
private readonly IFinancialInvoiceApplication _financialInvoiceApplication;
private readonly IInstitutionContractApplication _institutionContractApplication;
public GeneralController(IPaymentTransactionApplication paymentTransactionApplication,
IHttpClientFactory clientFactory, IFinancialStatmentApplication financialStatmentApplication,
IFinancialInvoiceApplication financialInvoiceApplication)
IFinancialInvoiceApplication financialInvoiceApplication,
IInstitutionContractApplication institutionContractApplication)
{
_paymentTransactionApplication = paymentTransactionApplication;
_paymentGateway = new SepehrPaymentGateway(clientFactory);
_financialStatmentApplication = financialStatmentApplication;
_financialInvoiceApplication = financialInvoiceApplication;
_institutionContractApplication = institutionContractApplication;
}
/// <summary>
@@ -98,29 +102,32 @@ public class GeneralController : GeneralBaseController
var financialInvoice = _financialInvoiceApplication.GetDetails(financialInvoiceId);
if (financialInvoice == null)
{
return BadRequest("فاکتور مالی نامعتبر است");
}
if (financialInvoice.Status != FinancialInvoiceStatus.Unpaid)
{
return BadRequest("فاکتور مالی نامعتبر است");
}
if (financialInvoice.Amount != transaction.Amount)
{
return await HandleFailedTransaction(transaction);
}
var verifyCommand = new VerifyPaymentGateWayRequest()
{
Amount = transaction.Amount,
TransactionId = payResponse.invoiceid,
DigitalReceipt = payResponse.digitalreceipt
};
var verifyRes = await _paymentGateway.Verify(verifyCommand, CancellationToken.None);
_financialInvoiceApplication.SetPaid(financialInvoiceId, DateTime.Now);
if (verifyRes.IsSuccess)
{
var command = new CreateFinancialStatment()
@@ -130,7 +137,7 @@ public class GeneralController : GeneralBaseController
Creditor = transaction.Amount,
DeptorString = "0",
TypeOfTransaction = "credit",
DescriptionOption = financialInvoice.Description +"شماره فاکتور"+financialInvoice.InvoiceNumber,
DescriptionOption = financialInvoice.Description + "شماره فاکتور" + financialInvoice.InvoiceNumber,
Description = "درگاه بانکی",
};
var statementResult = _financialStatmentApplication.CreateFromBankGateway(command);
@@ -143,6 +150,16 @@ public class GeneralController : GeneralBaseController
payResponse.cardnumber, payResponse.issuerbank, payResponse.rrn.ToString(),
payResponse.digitalreceipt);
if (financialInvoice.Items?.Any(x => x.Type == FinancialInvoiceItemType.BuyInstitutionContract) ?? false)
{
var financialItems = financialInvoice.Items
.Where(x => x.Type == FinancialInvoiceItemType.BuyInstitutionContract);
foreach (var editFinancialInvoiceItem in financialItems)
{
await _institutionContractApplication.SetPendingWorkflow(editFinancialInvoiceItem.EntityId);
}
}
if (!setSuccessResult.IsSuccedded)
{
return await HandleFailedTransaction(transaction);

View File

@@ -41,7 +41,9 @@
},
"SmsSettings": {
"IsTestMode": true,
"TestNumbers": [ "09116967898", "09116067106", "09114221321" ]
"TestNumbers": [ "09116967898"
//, "09116067106", "09114221321"
]
},
"SepehrGateWayTerminalId": 99213700