Feat: Add Condition For FinancialStatmentRepository.cs to set balance 0 when amount searched

This commit is contained in:
MahanCh
2025-07-27 17:15:20 +03:30
parent 313579cdee
commit 32dbd094e0

View File

@@ -71,6 +71,8 @@ public class FinancialStatmentRepository : RepositoryBase<long, FinancialStatmen
public async Task<ClientFinancialStatementViewModel> GetClientFinancialStatement(long accountId,
ClientFinancialStatementSearchModel searchModel)
{
bool searched = false;
var contractingPartyId = _context.ContractingPartyAccounts.Any(x => x.AccountId == accountId) ?
_context.ContractingPartyAccounts.FirstOrDefault(x => x.AccountId == accountId)!.PersonalContractingPartyId : 0;
@@ -86,9 +88,11 @@ public class FinancialStatmentRepository : RepositoryBase<long, FinancialStatmen
var resTransaction = resStatement.FinancialTransactionList.ToList();
#region Search
if (searchModel.FromAmount > 0 || searchModel.ToAmount > 0)
{
searched = true;
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();
@@ -104,6 +108,8 @@ public class FinancialStatmentRepository : RepositoryBase<long, FinancialStatmen
}
if (!string.IsNullOrWhiteSpace(searchModel.FromDate) && !string.IsNullOrWhiteSpace(searchModel.ToDate))
{
searched = true;
if (searchModel.FromDate.TryToGeorgianDateTime(out var fromDate) == false)
throw new BadRequestException("تاریخ وارد شده نامعتبر است");
@@ -115,6 +121,8 @@ public class FinancialStatmentRepository : RepositoryBase<long, FinancialStatmen
if (searchModel.Type != null)
{
searched = true;
var type = searchModel.Type switch
{
FinancialTransactionType.Credit => "credit",
@@ -133,15 +141,18 @@ public class FinancialStatmentRepository : RepositoryBase<long, FinancialStatmen
TotalDebt = resTransaction.Sum(x => x.Deptor),
Transactions = resTransaction.OrderBy(t => t.TdateGr).Select(t =>
{
if (t.TypeOfTransaction == "debt")
if (!searched)
{
balance += t.Deptor;
}
else
{
balance -= t.Creditor;
if (t.TypeOfTransaction == "debt")
{
balance += t.Deptor;
}
else
{
balance -= t.Creditor;
}
}
return new ClientFinancialTransactionViewModel()
{
DateTimeGr = t.TdateGr,