merge from financial client api branch
This commit is contained in:
@@ -23,9 +23,5 @@ public class ClientFinancialStatementSearchModel
|
||||
/// </summary>
|
||||
public FinancialTransactionType? Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// صفحه بندی
|
||||
/// </summary>
|
||||
public int PageIndex { get; set; }
|
||||
|
||||
}
|
||||
@@ -4,7 +4,6 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using _0_Framework.Application;
|
||||
using CompanyManagment.App.Contracts.FinancilTransaction;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace CompanyManagment.App.Contracts.FinancialStatment;
|
||||
|
||||
@@ -23,34 +22,4 @@ public interface IFinancialStatmentApplication
|
||||
/// <returns>مدل صورت حساب مالی کلاینت</returns>
|
||||
Task<ClientFinancialStatementViewModel> GetClientFinancialStatement(ClientFinancialStatementSearchModel searchModel,
|
||||
long accountId);
|
||||
|
||||
/// <summary>
|
||||
/// نمایش اطلاعات صورت حساب مالی کلاینت بر اساس کد هش
|
||||
/// </summary>
|
||||
/// <param name="hashCode"></param>
|
||||
/// <returns></returns>
|
||||
Task<ActionResult<OperationResult<ClientFinancialStatementViewModel>>> GetDetailsByHashCode(string hashCode);
|
||||
|
||||
/// <summary>
|
||||
/// مقدار مانده صورت حساب مالی را برمی گرداند
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
Task<GetFinancialStatementBalanceAmount> GetBalanceAmount(long id);
|
||||
|
||||
/// <summary>
|
||||
/// مقدار بدهی کلاینت را برمی گرداند
|
||||
/// </summary>
|
||||
/// <param name="accountId"></param>
|
||||
/// <returns></returns>
|
||||
Task<double> GetClientDebtAmount(long accountId);
|
||||
}
|
||||
|
||||
public class GetFinancialStatementBalanceAmount
|
||||
{
|
||||
/// <summary>
|
||||
/// مبلغ
|
||||
/// </summary>
|
||||
public double Amount { get; set; }
|
||||
public long ContractingPartyId { get; set; }
|
||||
}
|
||||
@@ -10,7 +10,6 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using AccountManagement.Application.Contracts.SubAccount;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
|
||||
|
||||
namespace CompanyManagment.EFCore.Repository;
|
||||
@@ -78,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)
|
||||
@@ -88,27 +87,27 @@ public class FinancialStatmentRepository : RepositoryBase<long, FinancialStatmen
|
||||
|
||||
#region Search
|
||||
|
||||
//if (searchModel.FromAmount > 0 || searchModel.ToAmount > 0)
|
||||
//{
|
||||
// if (searchModel.FromAmount > 0 && searchModel.ToAmount > 0)
|
||||
// {
|
||||
// resTransaction = resTransaction.Where(x => x.>= searchModel.FromAmount && x.Amount <= searchModel);
|
||||
// }
|
||||
// else if (searchModel.FromAmount > 0)
|
||||
// {
|
||||
// query = query.Where(x => x.Amount >= searchModel.FromAmount);
|
||||
// }
|
||||
// else if (searchModel.ToAmount > 0)
|
||||
// {
|
||||
// query = query.Where(x => x.Amount <= searchModel.ToAmount);
|
||||
// }
|
||||
//}
|
||||
if (searchModel.FromAmount > 0 || searchModel.ToAmount > 0)
|
||||
{
|
||||
if (searchModel.FromAmount > 0 && searchModel.ToAmount > 0)
|
||||
{
|
||||
resTransaction = resTransaction.Where(x => (x.Deptor >= searchModel.FromAmount && x.Deptor <= searchModel.FromAmount) || (x.Creditor >= searchModel.FromAmount && x.Creditor <= searchModel.FromAmount)).ToList();
|
||||
}
|
||||
else if (searchModel.FromAmount > 0)
|
||||
{
|
||||
resTransaction = resTransaction.Where(x => x.Deptor >= searchModel.FromAmount || x.Creditor >= searchModel.FromAmount).ToList();
|
||||
}
|
||||
else if (searchModel.ToAmount > 0)
|
||||
{
|
||||
resTransaction = resTransaction.Where(x => x.Deptor <= searchModel.ToAmount || x.Creditor <= searchModel.ToAmount).ToList();
|
||||
}
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(searchModel.FromDate) && !string.IsNullOrWhiteSpace(searchModel.ToDate))
|
||||
{
|
||||
if (searchModel.FromDate.TryToGeorgianDateTime(out var fromDate) == false)
|
||||
throw new BadRequestException("تاریخ وارد شده نامعتبر است");
|
||||
|
||||
if (searchModel.ToDate.TryToGeorgianDateTime(out var toDate) == false)
|
||||
if (searchModel.FromDate.TryToGeorgianDateTime(out var toDate) == false)
|
||||
throw new BadRequestException("تاریخ وارد شده نامعتبر است");
|
||||
|
||||
resTransaction = resTransaction.Where(x => x.TdateGr >= fromDate && x.TdateGr <= toDate).ToList();
|
||||
@@ -125,25 +124,39 @@ public class FinancialStatmentRepository : RepositoryBase<long, FinancialStatmen
|
||||
resTransaction = resTransaction.Where(x => x.TypeOfTransaction == type).ToList();
|
||||
}
|
||||
#endregion
|
||||
|
||||
double balance = 0;
|
||||
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),
|
||||
Transactions = resTransaction.Select(t => new ClientFinancialTransactionViewModel()
|
||||
Transactions = resTransaction.OrderBy(t => t.TdateGr).Select(t =>
|
||||
{
|
||||
DateTimeGr = t.TdateGr,
|
||||
DateFa = t.TdateGr.ToFarsi(),
|
||||
TimeFa = $"{t.TdateGr:HH:mm}",
|
||||
Description = t.DescriptionOption + " " + t.Description,
|
||||
Debtor = t.Deptor,
|
||||
Creditor = t.Creditor,
|
||||
Balance = t.Balance,
|
||||
Type = t.TypeOfTransaction == "debt" ? FinancialTransactionType.Debt : FinancialTransactionType.Credit,
|
||||
TypeStr = t.TypeOfTransaction == "debt" ? "ایجاد درآمد" : "دریافت درآمد"
|
||||
}).OrderByDescending(t => t.DateTimeGr).ToList(),
|
||||
|
||||
if (t.TypeOfTransaction == "debt")
|
||||
{
|
||||
balance += t.Deptor;
|
||||
}
|
||||
else
|
||||
{
|
||||
balance -= t.Creditor;
|
||||
}
|
||||
return new ClientFinancialTransactionViewModel()
|
||||
{
|
||||
DateTimeGr = t.TdateGr,
|
||||
DateFa = t.TdateGr.ToFarsi(),
|
||||
TimeFa = $"{t.TdateGr:HH:mm}",
|
||||
Description = t.DescriptionOption + " " + t.Description,
|
||||
Debtor = t.Deptor,
|
||||
Creditor = t.Creditor,
|
||||
Balance = balance,
|
||||
Type = t.TypeOfTransaction == "debt"
|
||||
? FinancialTransactionType.Debt
|
||||
: FinancialTransactionType.Credit,
|
||||
TypeStr = t.TypeOfTransaction == "debt" ? "ایجاد درآمد" : "دریافت درآمد"
|
||||
};
|
||||
}).OrderByDescending(x=>x.DateTimeGr).ToList(),
|
||||
};
|
||||
|
||||
}
|
||||
@@ -155,14 +168,14 @@ public class FinancialStatmentRepository : RepositoryBase<long, FinancialStatmen
|
||||
|
||||
public async Task<GetFinancialStatementBalanceAmount> GetBalanceAmount(long id)
|
||||
{
|
||||
var financialTransactions = _context.FinancialTransactions.Where(x=>x.FinancialStatementId == id);
|
||||
var financialTransactions = _context.FinancialTransactions.Where(x => x.FinancialStatementId == id);
|
||||
|
||||
if (!financialTransactions.Any())
|
||||
throw new BadRequestException("تراکنش مالی یافت نشد");
|
||||
var totalCredit = await financialTransactions.SumAsync(x => x.Creditor);
|
||||
var totalDebt = await financialTransactions.SumAsync(x => x.Deptor);
|
||||
var balance = totalDebt - totalCredit;
|
||||
|
||||
|
||||
var contractingPartyId = await _context.FinancialStatments
|
||||
.Where(x => x.id == id)
|
||||
.Select(x => x.ContractingPartyId)
|
||||
@@ -189,4 +202,6 @@ public class FinancialStatmentRepository : RepositoryBase<long, FinancialStatmen
|
||||
resStatement.FinancialTransactionList.Sum(x => x.Creditor);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user