diff --git a/CompanyManagment.App.Contracts/FinancialStatment/ClientFinancialStatementSearchModel.cs b/CompanyManagment.App.Contracts/FinancialStatment/ClientFinancialStatementSearchModel.cs index 1ca226e7..d97e017b 100644 --- a/CompanyManagment.App.Contracts/FinancialStatment/ClientFinancialStatementSearchModel.cs +++ b/CompanyManagment.App.Contracts/FinancialStatment/ClientFinancialStatementSearchModel.cs @@ -23,9 +23,5 @@ public class ClientFinancialStatementSearchModel /// public FinancialTransactionType? Type { get; set; } - /// - /// صفحه بندی - /// - public int PageIndex { get; set; } } \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/FinancialStatment/IFinancialStatmentApplication.cs b/CompanyManagment.App.Contracts/FinancialStatment/IFinancialStatmentApplication.cs index c7216b3d..485afb7c 100644 --- a/CompanyManagment.App.Contracts/FinancialStatment/IFinancialStatmentApplication.cs +++ b/CompanyManagment.App.Contracts/FinancialStatment/IFinancialStatmentApplication.cs @@ -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 /// مدل صورت حساب مالی کلاینت Task GetClientFinancialStatement(ClientFinancialStatementSearchModel searchModel, long accountId); - - /// - /// نمایش اطلاعات صورت حساب مالی کلاینت بر اساس کد هش - /// - /// - /// - Task>> GetDetailsByHashCode(string hashCode); - - /// - /// مقدار مانده صورت حساب مالی را برمی گرداند - /// - /// - /// - Task GetBalanceAmount(long id); - - /// - /// مقدار بدهی کلاینت را برمی گرداند - /// - /// - /// - Task GetClientDebtAmount(long accountId); -} - -public class GetFinancialStatementBalanceAmount -{ - /// - /// مبلغ - /// - public double Amount { get; set; } - public long ContractingPartyId { get; set; } } \ No newline at end of file diff --git a/CompanyManagment.EFCore/Repository/FinancialStatmentRepository.cs b/CompanyManagment.EFCore/Repository/FinancialStatmentRepository.cs index 6402799d..8622f044 100644 --- a/CompanyManagment.EFCore/Repository/FinancialStatmentRepository.cs +++ b/CompanyManagment.EFCore/Repository/FinancialStatmentRepository.cs @@ -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 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 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 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 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 x.Creditor); } + + } \ No newline at end of file