refactor:update get financial for client
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
namespace CompanyManagment.App.Contracts.FinancialStatment;
|
||||
|
||||
public class ClientFinancialStatementSearchModel
|
||||
{
|
||||
/// <summary>
|
||||
/// از تاریخ
|
||||
/// </summary>
|
||||
public string FromDate { get; set; }
|
||||
/// <summary>
|
||||
/// تا تاریخ
|
||||
/// </summary>
|
||||
public string ToDate { get; set; }
|
||||
/// <summary>
|
||||
/// از مبلغ
|
||||
/// </summary>
|
||||
public double FromAmount { get; set; }
|
||||
/// <summary>
|
||||
/// تا مبلغ
|
||||
/// </summary>
|
||||
public double ToAmount { get; set; }
|
||||
/// <summary>
|
||||
/// نوع عملیات تراکنش
|
||||
/// </summary>
|
||||
public FinancialTransactionType? Type { get; set; }
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace CompanyManagment.App.Contracts.FinancialStatment;
|
||||
|
||||
public class ClientFinancialStatementViewModel
|
||||
{
|
||||
/// <summary>
|
||||
/// آیدی FinancialStatement
|
||||
/// </summary>
|
||||
public long Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// جمع بدهکاری
|
||||
/// </summary>
|
||||
public double TotalDebt { get; set; }
|
||||
/// <summary>
|
||||
/// جمع بستانکاری
|
||||
/// </summary>
|
||||
public double TotalCredit { get; set; }
|
||||
/// <summary>
|
||||
/// مبلغ قابل پرداخت
|
||||
/// </summary>
|
||||
public double TotalAmountPayable { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// تراکنش ها
|
||||
/// </summary>
|
||||
public List<ClientFinancialTransactionViewModel> Transactions { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
|
||||
namespace CompanyManagment.App.Contracts.FinancialStatment;
|
||||
|
||||
public class ClientFinancialTransactionViewModel
|
||||
{
|
||||
/// <summary>
|
||||
/// زمان و تاریخ میلادی
|
||||
/// </summary>
|
||||
public DateTime DateTimeGr { get; set; }
|
||||
/// <summary>
|
||||
/// تاریخ
|
||||
/// </summary>
|
||||
public string DateFa { get; set; }
|
||||
/// <summary>
|
||||
/// زمان
|
||||
/// </summary>
|
||||
public string TimeFa { get; set; }
|
||||
/// <summary>
|
||||
/// شرح
|
||||
/// </summary>
|
||||
public string Description { get; set; }
|
||||
/// <summary>
|
||||
/// نوع عملیات پرداخت
|
||||
/// </summary>
|
||||
public FinancialTransactionType Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// نوع عملیات پرداخت به صورت استرینگ
|
||||
/// </summary>
|
||||
public string TypeStr { get; set; }
|
||||
/// <summary>
|
||||
/// بدهکار
|
||||
/// </summary>
|
||||
public double Debtor { get; set; }
|
||||
/// <summary>
|
||||
/// بستانکار
|
||||
/// </summary>
|
||||
public double Creditor { get; set; }
|
||||
/// <summary>
|
||||
/// باقی مانده
|
||||
/// </summary>
|
||||
public double Balance { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
namespace CompanyManagment.App.Contracts.FinancialStatment;
|
||||
|
||||
public enum FinancialTransactionType
|
||||
{
|
||||
/// <summary>
|
||||
/// ایجاد درآمد
|
||||
/// </summary>
|
||||
Debt,
|
||||
/// <summary>
|
||||
/// دریافت درآمد
|
||||
/// </summary>
|
||||
Credit
|
||||
}
|
||||
@@ -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
|
||||
/// <returns>مدل صورت حساب مالی کلاینت</returns>
|
||||
Task<ClientFinancialStatementViewModel> GetClientFinancialStatement(ClientFinancialStatementSearchModel searchModel,
|
||||
long accountId);
|
||||
}
|
||||
|
||||
public class ClientFinancialStatementSearchModel
|
||||
{
|
||||
/// <summary>
|
||||
/// از تاریخ
|
||||
/// </summary>
|
||||
public string FromDate { get; set; }
|
||||
/// <summary>
|
||||
/// تا تاریخ
|
||||
/// </summary>
|
||||
public string ToDate { get; set; }
|
||||
/// <summary>
|
||||
/// از مبلغ
|
||||
/// </summary>
|
||||
public double FromAmount { get; set; }
|
||||
/// <summary>
|
||||
/// تا مبلغ
|
||||
/// </summary>
|
||||
public double ToAmount { get; set; }
|
||||
/// <summary>
|
||||
/// نوع عملیات تراکنش
|
||||
/// </summary>
|
||||
public FinancialTransactionType? Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// صفحه بندی
|
||||
/// </summary>
|
||||
public int PageIndex { get; set; }
|
||||
|
||||
}
|
||||
|
||||
public enum FinancialTransactionType
|
||||
{
|
||||
/// <summary>
|
||||
/// ایجاد درآمد
|
||||
/// </summary>
|
||||
Debt,
|
||||
/// <summary>
|
||||
/// دریافت درآمد
|
||||
/// </summary>
|
||||
Credit
|
||||
}
|
||||
|
||||
public class ClientFinancialStatementViewModel
|
||||
{
|
||||
/// <summary>
|
||||
/// آیدی FinancialStatement
|
||||
/// </summary>
|
||||
public long Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// جمع بدهکاری
|
||||
/// </summary>
|
||||
public double TotalDebt { get; set; }
|
||||
/// <summary>
|
||||
/// جمع بستانکاری
|
||||
/// </summary>
|
||||
public double TotalCredit { get; set; }
|
||||
/// <summary>
|
||||
/// مبلغ قابل پرداخت
|
||||
/// </summary>
|
||||
public double TotalAmountPayable { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// تراکنش ها
|
||||
/// </summary>
|
||||
public List<ClientFinancialTransactionViewModel> Transactions { get; set; }
|
||||
}
|
||||
|
||||
public class ClientFinancialTransactionViewModel
|
||||
{
|
||||
/// <summary>
|
||||
/// زمان و تاریخ میلادی
|
||||
/// </summary>
|
||||
public DateTime DateTimeGr { get; set; }
|
||||
/// <summary>
|
||||
/// تاریخ
|
||||
/// </summary>
|
||||
public string DateFa { get; set; }
|
||||
/// <summary>
|
||||
/// زمان
|
||||
/// </summary>
|
||||
public string TimeFa { get; set; }
|
||||
/// <summary>
|
||||
/// شرح
|
||||
/// </summary>
|
||||
public string Description { get; set; }
|
||||
/// <summary>
|
||||
/// نوع عملیات پرداخت
|
||||
/// </summary>
|
||||
public FinancialTransactionType Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// نوع عملیات پرداخت به صورت استرینگ
|
||||
/// </summary>
|
||||
public string TypeStr { get; set; }
|
||||
/// <summary>
|
||||
/// بدهکار
|
||||
/// </summary>
|
||||
public double Debtor { get; set; }
|
||||
/// <summary>
|
||||
/// بستانکار
|
||||
/// </summary>
|
||||
public double Creditor { get; set; }
|
||||
/// <summary>
|
||||
/// باقی مانده
|
||||
/// </summary>
|
||||
public double Balance { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -87,21 +87,21 @@ 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)
|
||||
@@ -124,26 +124,84 @@ 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()
|
||||
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<ActionResult<OperationResult<ClientFinancialStatementViewModel>>> GetDetailsByHashCode(string hashCode)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public async Task<GetFinancialStatementBalanceAmount> 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<double> 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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user