Reports для роли Поставщик. Фикс GetFilteredList() в CurrencyPurchaseStorage. Добавление DateFrom и DateTo в соответствующую SearchModel.

This commit is contained in:
ksenianeva 2023-04-07 22:32:57 +04:00
parent b89974dd9f
commit 56ebf0902a
6 changed files with 125 additions and 4 deletions

View File

@ -106,6 +106,61 @@ namespace BankBusinessLogic.BusinessLogics
return list;
}
public List<ReportCurrencyTransferViewModel> GetCurrencyTransfers(List<CurrencyBindingModel> currencies)
{
var list = new List<ReportCurrencyTransferViewModel>();
var payments = _paymentStorage.GetFullList();
var transfers = _transferStorage.GetFullList();
foreach(var currency in currencies)
{
var record = new ReportCurrencyTransferViewModel
{
CurrencyId = currency.Id,
CurrencyName = currency.Name,
Transfers = new List<(int TransferId, float Amount)>(),
};
var paymentsId = new List<int>();
foreach(var payment in payments)
{
if (payment.CurrencyPayments.ContainsKey(currency.Id)) paymentsId.Add(payment.Id);
}
foreach(var transfer in transfers)
{
foreach(int paymentId in paymentsId)
{
if (paymentId == transfer.PaymentId)
{
record.Transfers.Add(new(transfer.Id, transfer.Amount));
}
}
}
list.Add(record);
}
return list;
}
public List<ReportCurrencyPurchasePaymentViewModel> GetPurchasePayment(ReportBindingModel model)
{
var purchases = _currencyPurchaseStorage.GetFilteredList(new CurrencyPurchaseSearchModel { DateFrom = model.DateFrom, DateTo = model.DateTo });
var list = new List<ReportCurrencyPurchasePaymentViewModel>();
var payments = _paymentStorage.GetFullList();
foreach (var purchase in purchases)
{
var record = new ReportCurrencyPurchasePaymentViewModel
{
CurrencyPurchaseId = purchase.Id,
PurchaseDate = purchase.PurchaseDate,
Payments = new List<(int PaymentId, string PaymentDate)>(),
};
var paymentsId = new List<int>();
foreach (var payment in payments)
{
if (payment.CurrencyPayments.ContainsKey(purchase.CurrencyId)) record.Payments.Add(new(payment.Id, payment.PaymentDate.ToString()));
}
list.Add(record);
}
return list;
}
public void SavePaymentPurchaseToExcel(List<PaymentBindingModel> payments)
{
var result = GetPaymentPurchase(payments);
@ -126,5 +181,22 @@ namespace BankBusinessLogic.BusinessLogics
//создание файла будет реализовано в будующих версиях
throw new NotImplementedException();
}
public void SaveCurrencyTransfersToExcel(List<CurrencyBindingModel> currencies)
{
var report = GetCurrencyTransfers(currencies);
throw new NotImplementedException();
}
public void SaveCurrencyTransfersToWord(List<CurrencyBindingModel> currencies)
{
var report = GetCurrencyTransfers(currencies);
throw new NotImplementedException();
}
public void SavePurchasePaymentToPDF(ReportBindingModel model)
{
var report = GetPurchasePayment(model);
throw new NotImplementedException();
}
}
}

View File

@ -15,5 +15,11 @@ namespace BankContracts.BusinessLogicsContracts
void SavePaymentPurchaseToWord(List<PaymentBindingModel> payments);
void SavePaymentPurchaseToExcel(List<PaymentBindingModel> payments);
void SaveTransferPurchaseToPDF(ReportBindingModel model);
List<ReportCurrencyTransferViewModel> GetCurrencyTransfers(List<CurrencyBindingModel> currencies);
List<ReportCurrencyPurchasePaymentViewModel> GetPurchasePayment(ReportBindingModel model);
void SaveCurrencyTransfersToWord(List<CurrencyBindingModel> currencies);
void SaveCurrencyTransfersToExcel(List<CurrencyBindingModel> currencies);
void SavePurchasePaymentToPDF(ReportBindingModel model);
}
}

View File

@ -10,5 +10,7 @@ namespace BankContracts.SearchModels
{
public int? Id { get; set; }
public int? BankOperatorId { get; set; }
public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; }
}
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BankContracts.ViewModels
{
public class ReportCurrencyPurchasePaymentViewModel
{
public int CurrencyPurchaseId { get; set; }
public DateTime PurchaseDate { get; set; }
public List<(int PaymentId, string PaymentDate)> Payments { get; set; } = new();
}
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BankContracts.ViewModels
{
public class ReportCurrencyTransferViewModel
{
public int CurrencyId { get; set; }
public string CurrencyName { get; set; } = string.Empty;
public List<(int TransferId, float Amount)> Transfers { get; set; } = new();
}
}

View File

@ -41,16 +41,27 @@ namespace BankDatabaseImplement.Implements
public List<CurrencyPurchaseViewModel> GetFilteredList(CurrencyPurchaseSearchModel model)
{
if (!model.Id.HasValue)
if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue)
{
return new();
}
if (model.DateFrom.HasValue && model.DateTo.HasValue)
{
using var context = new BankDatabase();
return context.CurrencyPurchases.Include(x => x.BankOperator).Include(x=>x.Currency)
return context.CurrencyPurchases.Include(x => x.BankOperator).Include(x => x.Currency)
.Where(x => x.PurchaseDate >= model.DateFrom && x.PurchaseDate <= model.DateTo)
.Select(x => x.GetViewModel)
.ToList();
}
else
{
using var context = new BankDatabase();
return context.CurrencyPurchases.Include(x => x.BankOperator).Include(x => x.Currency)
.Where(x => x.Id == model.Id)
.Select(x => x.GetViewModel)
.ToList();
}
}
public List<CurrencyPurchaseViewModel> GetFullList()
{