fix: calculate balance correctly in financial transaction details
This commit is contained in:
@@ -171,7 +171,9 @@ public class FinancialStatmentRepository : RepositoryBase<long, FinancialStatmen
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
double balance = 0;
|
||||
public async Task<OperationResult<ClientFinancialStatementViewModel>> GetDetailsByPublicId(string publicId)
|
||||
{
|
||||
var op = new OperationResult<ClientFinancialStatementViewModel>();
|
||||
@@ -194,17 +196,30 @@ public class FinancialStatmentRepository : RepositoryBase<long, FinancialStatmen
|
||||
TotalCredit = financialStatement.FinancialTransactionList.Sum(x => x.Creditor),
|
||||
TotalDebt = financialStatement.FinancialTransactionList.Sum(x => x.Deptor),
|
||||
ContractingPartyName = financialStatement.ContractingPartyName,
|
||||
Transactions = financialStatement.FinancialTransactionList.Select(t => new FinancialTransactionDetailViewModel()
|
||||
Transactions = financialStatement.FinancialTransactionList.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" ? "ایجاد درآمد" : "دریافت درآمد"
|
||||
if (t.TypeOfTransaction == "debt")
|
||||
{
|
||||
balance += t.Deptor;
|
||||
}
|
||||
else
|
||||
{
|
||||
balance -= t.Creditor;
|
||||
}
|
||||
return new FinancialTransactionDetailViewModel()
|
||||
{
|
||||
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(t => t.DateTimeGr).ToList(),
|
||||
};
|
||||
return op.Succcedded(res);
|
||||
|
||||
Reference in New Issue
Block a user