diff --git a/CompanyManagment.App.Contracts/FinancialStatment/ClientFinancialStatementSearchModel.cs b/CompanyManagment.App.Contracts/FinancialStatment/ClientFinancialStatementSearchModel.cs
new file mode 100644
index 00000000..d97e017b
--- /dev/null
+++ b/CompanyManagment.App.Contracts/FinancialStatment/ClientFinancialStatementSearchModel.cs
@@ -0,0 +1,27 @@
+namespace CompanyManagment.App.Contracts.FinancialStatment;
+
+public class ClientFinancialStatementSearchModel
+{
+ ///
+ /// از تاریخ
+ ///
+ public string FromDate { get; set; }
+ ///
+ /// تا تاریخ
+ ///
+ public string ToDate { get; set; }
+ ///
+ /// از مبلغ
+ ///
+ public double FromAmount { get; set; }
+ ///
+ /// تا مبلغ
+ ///
+ public double ToAmount { get; set; }
+ ///
+ /// نوع عملیات تراکنش
+ ///
+ public FinancialTransactionType? Type { get; set; }
+
+
+}
\ No newline at end of file
diff --git a/CompanyManagment.App.Contracts/FinancialStatment/ClientFinancialStatementViewModel.cs b/CompanyManagment.App.Contracts/FinancialStatment/ClientFinancialStatementViewModel.cs
new file mode 100644
index 00000000..906b1f21
--- /dev/null
+++ b/CompanyManagment.App.Contracts/FinancialStatment/ClientFinancialStatementViewModel.cs
@@ -0,0 +1,29 @@
+using System.Collections.Generic;
+
+namespace CompanyManagment.App.Contracts.FinancialStatment;
+
+public class ClientFinancialStatementViewModel
+{
+ ///
+ /// آیدی FinancialStatement
+ ///
+ public long Id { get; set; }
+
+ ///
+ /// جمع بدهکاری
+ ///
+ public double TotalDebt { get; set; }
+ ///
+ /// جمع بستانکاری
+ ///
+ public double TotalCredit { get; set; }
+ ///
+ /// مبلغ قابل پرداخت
+ ///
+ public double TotalAmountPayable { get; set; }
+
+ ///
+ /// تراکنش ها
+ ///
+ public List Transactions { get; set; }
+}
\ No newline at end of file
diff --git a/CompanyManagment.App.Contracts/FinancialStatment/ClientFinancialTransactionViewModel.cs b/CompanyManagment.App.Contracts/FinancialStatment/ClientFinancialTransactionViewModel.cs
new file mode 100644
index 00000000..172ad8cb
--- /dev/null
+++ b/CompanyManagment.App.Contracts/FinancialStatment/ClientFinancialTransactionViewModel.cs
@@ -0,0 +1,44 @@
+using System;
+
+namespace CompanyManagment.App.Contracts.FinancialStatment;
+
+public class ClientFinancialTransactionViewModel
+{
+ ///
+ /// زمان و تاریخ میلادی
+ ///
+ public DateTime DateTimeGr { get; set; }
+ ///
+ /// تاریخ
+ ///
+ public string DateFa { get; set; }
+ ///
+ /// زمان
+ ///
+ public string TimeFa { get; set; }
+ ///
+ /// شرح
+ ///
+ public string Description { get; set; }
+ ///
+ /// نوع عملیات پرداخت
+ ///
+ public FinancialTransactionType Type { get; set; }
+
+ ///
+ /// نوع عملیات پرداخت به صورت استرینگ
+ ///
+ public string TypeStr { get; set; }
+ ///
+ /// بدهکار
+ ///
+ public double Debtor { get; set; }
+ ///
+ /// بستانکار
+ ///
+ public double Creditor { get; set; }
+ ///
+ /// باقی مانده
+ ///
+ public double Balance { get; set; }
+}
\ No newline at end of file
diff --git a/CompanyManagment.App.Contracts/FinancialStatment/FinancialTransactionType.cs b/CompanyManagment.App.Contracts/FinancialStatment/FinancialTransactionType.cs
new file mode 100644
index 00000000..a07cc5a7
--- /dev/null
+++ b/CompanyManagment.App.Contracts/FinancialStatment/FinancialTransactionType.cs
@@ -0,0 +1,13 @@
+namespace CompanyManagment.App.Contracts.FinancialStatment;
+
+public enum FinancialTransactionType
+{
+ ///
+ /// ایجاد درآمد
+ ///
+ Debt,
+ ///
+ /// دریافت درآمد
+ ///
+ Credit
+}
\ No newline at end of file
diff --git a/CompanyManagment.App.Contracts/FinancialStatment/IFinancialStatmentApplication.cs b/CompanyManagment.App.Contracts/FinancialStatment/IFinancialStatmentApplication.cs
index 45e18826..485afb7c 100644
--- a/CompanyManagment.App.Contracts/FinancialStatment/IFinancialStatmentApplication.cs
+++ b/CompanyManagment.App.Contracts/FinancialStatment/IFinancialStatmentApplication.cs
@@ -1,5 +1,4 @@
-using System;
-using System.Collections.Generic;
+using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -23,114 +22,4 @@ public interface IFinancialStatmentApplication
/// مدل صورت حساب مالی کلاینت
Task GetClientFinancialStatement(ClientFinancialStatementSearchModel searchModel,
long accountId);
-}
-
-public class ClientFinancialStatementSearchModel
-{
- ///
- /// از تاریخ
- ///
- public string FromDate { get; set; }
- ///
- /// تا تاریخ
- ///
- public string ToDate { get; set; }
- ///
- /// از مبلغ
- ///
- public double FromAmount { get; set; }
- ///
- /// تا مبلغ
- ///
- public double ToAmount { get; set; }
- ///
- /// نوع عملیات تراکنش
- ///
- public FinancialTransactionType? Type { get; set; }
-
- ///
- /// صفحه بندی
- ///
- public int PageIndex { get; set; }
-
-}
-
-public enum FinancialTransactionType
-{
- ///
- /// ایجاد درآمد
- ///
- Debt,
- ///
- /// دریافت درآمد
- ///
- Credit
-}
-
-public class ClientFinancialStatementViewModel
-{
- ///
- /// آیدی FinancialStatement
- ///
- public long Id { get; set; }
-
- ///
- /// جمع بدهکاری
- ///
- public double TotalDebt { get; set; }
- ///
- /// جمع بستانکاری
- ///
- public double TotalCredit { get; set; }
- ///
- /// مبلغ قابل پرداخت
- ///
- public double TotalAmountPayable { get; set; }
-
- ///
- /// تراکنش ها
- ///
- public List Transactions { get; set; }
-}
-
-public class ClientFinancialTransactionViewModel
-{
- ///
- /// زمان و تاریخ میلادی
- ///
- public DateTime DateTimeGr { get; set; }
- ///
- /// تاریخ
- ///
- public string DateFa { get; set; }
- ///
- /// زمان
- ///
- public string TimeFa { get; set; }
- ///
- /// شرح
- ///
- public string Description { get; set; }
- ///
- /// نوع عملیات پرداخت
- ///
- public FinancialTransactionType Type { get; set; }
-
- ///
- /// نوع عملیات پرداخت به صورت استرینگ
- ///
- public string TypeStr { get; set; }
- ///
- /// بدهکار
- ///
- public double Debtor { get; set; }
- ///
- /// بستانکار
- ///
- public double Creditor { get; set; }
- ///
- /// باقی مانده
- ///
- public double Balance { get; set; }
-}
-
+}
\ No newline at end of file
diff --git a/CompanyManagment.EFCore/Repository/FinancialStatmentRepository.cs b/CompanyManagment.EFCore/Repository/FinancialStatmentRepository.cs
index 15c5a475..8622f044 100644
--- a/CompanyManagment.EFCore/Repository/FinancialStatmentRepository.cs
+++ b/CompanyManagment.EFCore/Repository/FinancialStatmentRepository.cs
@@ -87,21 +87,21 @@ 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)
@@ -124,26 +124,84 @@ 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()
+ 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.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(),
};
}
+
+ public Task>> GetDetailsByHashCode(string hashCode)
+ {
+ throw new NotImplementedException();
+ }
+
+ public async Task GetBalanceAmount(long 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)
+ .FirstOrDefaultAsync();
+
+ return new GetFinancialStatementBalanceAmount
+ {
+ Amount = balance,
+ ContractingPartyId = contractingPartyId
+ };
+ }
+
+ public async Task 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);
+
+ }
+
+
}
\ No newline at end of file