feat: add debt amount in client profile
This commit is contained in:
@@ -15,4 +15,6 @@ public interface IFinancialStatmentRepository : IRepository<long, FinancialStatm
|
||||
List<FinancialStatmentViewModel> Search(FinancialStatmentSearchModel searchModel);
|
||||
Task<ClientFinancialStatementViewModel> GetClientFinancialStatement(long accountId,
|
||||
ClientFinancialStatementSearchModel searchModel);
|
||||
|
||||
Task<double> GetClientDebtAmount(long accountId);
|
||||
}
|
||||
@@ -23,6 +23,13 @@ public interface IFinancialStatmentApplication
|
||||
/// <returns>مدل صورت حساب مالی کلاینت</returns>
|
||||
Task<ClientFinancialStatementViewModel> GetClientFinancialStatement(ClientFinancialStatementSearchModel searchModel,
|
||||
long accountId);
|
||||
|
||||
/// <summary>
|
||||
/// مقدار بدهی کلاینت را برمی گرداند
|
||||
/// </summary>
|
||||
/// <param name="AccountId"></param>
|
||||
/// <returns></returns>
|
||||
Task<double> GetClientDebtAmount(long AccountId);
|
||||
}
|
||||
|
||||
public class ClientFinancialStatementSearchModel
|
||||
|
||||
@@ -117,4 +117,9 @@ public class FinancialStatmentApplication : IFinancialStatmentApplication
|
||||
{
|
||||
return await _financialStatmentRepository.GetClientFinancialStatement(accountId, searchModel);
|
||||
}
|
||||
|
||||
public async Task<double> GetClientDebtAmount(long accountId)
|
||||
{
|
||||
return await _financialStatmentRepository.GetClientDebtAmount(accountId);
|
||||
}
|
||||
}
|
||||
@@ -77,7 +77,7 @@ public class FinancialStatmentRepository : RepositoryBase<long, FinancialStatmen
|
||||
if (contractingPartyId == 0)
|
||||
throw new BadRequestException("طرف حساب مورد نظر یافت نشد");
|
||||
|
||||
var resStatement = await _context.FinancialStatments.Include(x=>x.FinancialTransactionList)
|
||||
var resStatement = await _context.FinancialStatments.Include(x => x.FinancialTransactionList)
|
||||
.FirstOrDefaultAsync(x => x.ContractingPartyId == contractingPartyId);
|
||||
|
||||
if (resStatement == null)
|
||||
@@ -128,9 +128,9 @@ public class FinancialStatmentRepository : RepositoryBase<long, FinancialStatmen
|
||||
return new ClientFinancialStatementViewModel()
|
||||
{
|
||||
Id = resStatement.id,
|
||||
TotalAmountPayable = resStatement.FinancialTransactionList.Sum(x=>x.Deptor) - resStatement.FinancialTransactionList.Sum(x=>x.Creditor),
|
||||
TotalCredit = resTransaction.Sum(x=>x.Creditor),
|
||||
TotalDebt = resTransaction.Sum(x=>x.Deptor),
|
||||
TotalAmountPayable = resStatement.FinancialTransactionList.Sum(x => x.Deptor) - resStatement.FinancialTransactionList.Sum(x => x.Creditor),
|
||||
TotalCredit = resTransaction.Sum(x => x.Creditor),
|
||||
TotalDebt = resTransaction.Sum(x => x.Deptor),
|
||||
Transactions = resTransaction.Select(t => new ClientFinancialTransactionViewModel()
|
||||
{
|
||||
DateTimeGr = t.TdateGr,
|
||||
@@ -140,10 +140,25 @@ public class FinancialStatmentRepository : RepositoryBase<long, FinancialStatmen
|
||||
Debtor = t.Deptor,
|
||||
Creditor = t.Creditor,
|
||||
Balance = t.Balance,
|
||||
Type = t.TypeOfTransaction =="debt"? FinancialTransactionType.Debt :FinancialTransactionType.Credit,
|
||||
TypeStr = t.TypeOfTransaction =="debt"? "ایجاد درآمد" : "دریافت درآمد"
|
||||
Type = t.TypeOfTransaction == "debt" ? FinancialTransactionType.Debt : FinancialTransactionType.Credit,
|
||||
TypeStr = t.TypeOfTransaction == "debt" ? "ایجاد درآمد" : "دریافت درآمد"
|
||||
}).OrderByDescending(t => t.DateTimeGr).ToList(),
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
public async Task<double> GetClientDebtAmount(long accountId)
|
||||
{
|
||||
var contractingPartyId = (await _context.ContractingPartyAccounts.FirstOrDefaultAsync(x => x.AccountId == accountId))?.PersonalContractingPartyId ?? 0;
|
||||
|
||||
var resStatement = await _context.FinancialStatments.Include(x => x.FinancialTransactionList)
|
||||
.FirstOrDefaultAsync(x => x.ContractingPartyId == contractingPartyId);
|
||||
|
||||
if (resStatement == null)
|
||||
return 0;
|
||||
|
||||
return resStatement.FinancialTransactionList.Sum(x => x.Deptor) -
|
||||
resStatement.FinancialTransactionList.Sum(x => x.Creditor);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,25 +1,28 @@
|
||||
using _0_Framework.Application;
|
||||
using CompanyManagment.App.Contracts.FinancialStatment;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using ServiceHost.BaseControllers;
|
||||
|
||||
namespace ServiceHost.Areas.Client.Controllers;
|
||||
|
||||
public record GetClientProfileDetails(long Id, string Fullname, string Mobile, List<int> Permissions,List<WorkshopClaim> Workshops,string WorkshopSlug);
|
||||
public record GetClientProfileDetails(long Id, string Fullname, string Mobile, List<int> Permissions,List<WorkshopClaim> Workshops,string WorkshopSlug,double DebtAmount);
|
||||
|
||||
public class LoginController: ClientBaseController
|
||||
{
|
||||
private readonly IAuthHelper _authHelper;
|
||||
private readonly IFinancialStatmentApplication _financialStatmentApplication;
|
||||
|
||||
public LoginController(IAuthHelper authHelper)
|
||||
public LoginController(IAuthHelper authHelper, IFinancialStatmentApplication financialStatmentApplication)
|
||||
{
|
||||
_authHelper = authHelper;
|
||||
_financialStatmentApplication = financialStatmentApplication;
|
||||
}
|
||||
/// <summary>
|
||||
/// جزئیات پروفایل کاربر کلاینت را برمی گرداند
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("Profile")]
|
||||
public ActionResult<GetClientProfileDetails> GetProfile()
|
||||
public async Task<ActionResult<GetClientProfileDetails>> GetProfile()
|
||||
{
|
||||
if (!_authHelper.IsAuthenticated())
|
||||
return Unauthorized();
|
||||
@@ -31,14 +34,15 @@ public class LoginController: ClientBaseController
|
||||
if (_authHelper.GetUserTypeWithId().userType is not UserType.Client and not UserType.SubAccount)
|
||||
return Unauthorized();
|
||||
|
||||
|
||||
var debtAmount = await _financialStatmentApplication.GetClientDebtAmount(data.Id);
|
||||
var details = new GetClientProfileDetails(
|
||||
data.Id,
|
||||
data.Fullname,
|
||||
data.Mobile,
|
||||
data.Permissions,
|
||||
data.WorkshopList,
|
||||
data.WorkshopSlug
|
||||
data.WorkshopSlug,
|
||||
debtAmount
|
||||
);
|
||||
return details;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
using _0_Framework.Application;
|
||||
using _0_Framework.Application.PaymentGateway;
|
||||
using CompanyManagment.App.Contracts.PaymentTransaction;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System.Net.Http;
|
||||
|
||||
namespace ServiceHost.Pages.CallBack
|
||||
{
|
||||
@@ -9,10 +12,13 @@ namespace ServiceHost.Pages.CallBack
|
||||
public class IndexModel : PageModel
|
||||
{
|
||||
private readonly IPaymentTransactionApplication _paymentTransactionApplication;
|
||||
private readonly IPaymentGateway _paymentGateway;
|
||||
|
||||
public IndexModel(IPaymentTransactionApplication paymentTransactionApplication)
|
||||
|
||||
public IndexModel(IPaymentTransactionApplication paymentTransactionApplication, IHttpClientFactory httpClientFactory, IOptions<AppSettingConfiguration> appSetting)
|
||||
{
|
||||
_paymentTransactionApplication = paymentTransactionApplication;
|
||||
_paymentGateway = new AqayePardakhtPaymentGateway(httpClientFactory, appSetting);
|
||||
}
|
||||
|
||||
public void OnGet(string? transid, string? cardnumber, string? tracking_number, string status)
|
||||
@@ -29,8 +35,9 @@ namespace ServiceHost.Pages.CallBack
|
||||
|
||||
}
|
||||
}
|
||||
public void OnPost(string? transid, string? cardnumber, string? tracking_number, string bank, string invoice_id, string? status)
|
||||
public async Task OnPost(string? transid, string? cardnumber, string? tracking_number, string bank, string invoice_id, string? status)
|
||||
{
|
||||
//var verify =await _paymentGateway.Verify(new VerifyPaymentGateWayRequest { Amount = 1000, TransactionId = transid });
|
||||
var command = new CreatePaymentTransaction()
|
||||
{
|
||||
CardNumber = cardnumber,
|
||||
@@ -58,7 +65,7 @@ namespace ServiceHost.Pages.CallBack
|
||||
command.Status = PaymentTransactionStatus.Failed;
|
||||
}
|
||||
|
||||
_paymentTransactionApplication.Create(command);
|
||||
await _paymentTransactionApplication.Create(command);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user