CashierDiagram
This commit is contained in:
parent
d0bbf007c4
commit
23e1580c93
@ -3,6 +3,8 @@ using BankYouBankruptContracts.BusinessLogicsContracts;
|
||||
using BankYouBankruptContracts.SearchModels;
|
||||
using BankYouBankruptContracts.StoragesContracts;
|
||||
using BankYouBankruptContracts.ViewModels;
|
||||
using BankYouBankruptContracts.ViewModels.Client.Diagram;
|
||||
using BankYouBankruptDataModels.Enums;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -17,11 +19,16 @@ namespace BankYouBankruptBusinessLogic.BusinessLogics
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly IAccountStorage _accountStorage;
|
||||
private readonly ICashWithdrawalLogic _cashWithdrawalLogic;
|
||||
private readonly IMoneyTransferLogic _moneyTransferLogic;
|
||||
|
||||
public AccountLogic(ILogger<AccountLogic> logger, IAccountStorage accountStorage)
|
||||
public AccountLogic(ILogger<AccountLogic> logger, IAccountStorage accountStorage,
|
||||
ICashWithdrawalLogic cashWithdrawalLogic, IMoneyTransferLogic moneyTransferLogic)
|
||||
{
|
||||
_logger = logger;
|
||||
_accountStorage = accountStorage;
|
||||
_cashWithdrawalLogic = cashWithdrawalLogic;
|
||||
_moneyTransferLogic = moneyTransferLogic;
|
||||
}
|
||||
|
||||
public AccountViewModel? ReadElement(AccountSearchModel model)
|
||||
@ -136,6 +143,36 @@ namespace BankYouBankruptBusinessLogic.BusinessLogics
|
||||
return true;
|
||||
}
|
||||
|
||||
public List<CashierDiagramElementsViewModel> GetMonthInfo(int AccountId)
|
||||
{
|
||||
|
||||
Dictionary<(int, int), int> cashWithdrawals = _cashWithdrawalLogic.ReadList(new CashWithdrawalSearchModel()
|
||||
{
|
||||
AccountId = AccountId,
|
||||
}).GroupBy(x => new { x.DateOperation.Month, x.DateOperation.Year })
|
||||
.Select(x => new { x.Key.Month, x.Key.Year, Sum = x.Select(y => y.Sum).Sum() }).ToDictionary(x => (x.Month, x.Year), x => (x.Sum));
|
||||
Dictionary<(int, int), int> moneyTransfersDebiting = _moneyTransferLogic.ReadList(new MoneyTransferSearchModel()
|
||||
{
|
||||
AccountPayeeId = AccountId,
|
||||
}).GroupBy(x => new { x.DateOperation.Month, x.DateOperation.Year })
|
||||
.Select(x => new { x.Key.Month, x.Key.Year, Sum = x.Select(y => y.Sum).Sum() }).ToDictionary(x => (x.Month, x.Year), x => (x.Sum));
|
||||
Dictionary<(int, int), int> moneyTransfers = _moneyTransferLogic.ReadList(new MoneyTransferSearchModel()
|
||||
{
|
||||
AccountSenderId = AccountId,
|
||||
}).GroupBy(x => new { x.DateOperation.Month, x.DateOperation.Year })
|
||||
.Select(x => new { x.Key.Month, x.Key.Year, Sum = x.Select(y => y.Sum).Sum() }).ToDictionary(x => (x.Month, x.Year), x => (x.Sum));
|
||||
List<CashierDiagramElementsViewModel> result = new();
|
||||
foreach (var key in cashWithdrawals.Keys.Union(moneyTransfersDebiting.Keys).Union(moneyTransfers.Keys))
|
||||
{
|
||||
int sum = 0;
|
||||
if (cashWithdrawals.ContainsKey(key)) sum -= cashWithdrawals.GetValueOrDefault(key);
|
||||
if (moneyTransfersDebiting.ContainsKey(key)) sum += moneyTransfersDebiting.GetValueOrDefault(key);
|
||||
if (moneyTransfersDebiting.ContainsKey(key)) sum -= moneyTransfersDebiting.GetValueOrDefault(key);
|
||||
result.Add(new CashierDiagramElementsViewModel() { Name = Enum.GetName(typeof(Months), key.Item1) + " " + key.Item2.ToString(), Value = sum });
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//проверка входного аргумента для методов Insert, Update и Delete
|
||||
private void CheckModel(AccountBindingModel model, bool withParams = true)
|
||||
{
|
||||
|
@ -19,15 +19,15 @@ namespace BankYouBankruptBusinessLogic.BusinessLogics
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly ICardStorage _cardStorage;
|
||||
private readonly IAccountStorage _accountStorage;
|
||||
private readonly IAccountLogic _accountLogic;
|
||||
private readonly IDebitingLogic _debitingLogic;
|
||||
private readonly ICreditingLogic _creditingLogic;
|
||||
|
||||
public CardLogic(ILogger<CardLogic> logger, ICardStorage cardStorage, IAccountStorage accountStorage,
|
||||
public CardLogic(ILogger<CardLogic> logger, ICardStorage cardStorage, IAccountLogic accountLogic,
|
||||
IDebitingLogic debitingLogic, ICreditingLogic creditingLogic) {
|
||||
_logger = logger;
|
||||
_cardStorage = cardStorage;
|
||||
_accountStorage = accountStorage;
|
||||
_accountLogic = accountLogic;
|
||||
_debitingLogic = debitingLogic;
|
||||
_creditingLogic = creditingLogic;
|
||||
}
|
||||
@ -153,7 +153,7 @@ namespace BankYouBankruptBusinessLogic.BusinessLogics
|
||||
throw new InvalidOperationException("Карта с таким ноиером уже есть");
|
||||
}
|
||||
|
||||
var accountElement = _accountStorage.GetElement(new AccountSearchModel
|
||||
var accountElement = _accountLogic.ReadElement(new AccountSearchModel
|
||||
{
|
||||
Id = model.AccountId,
|
||||
ClientId = model.ClientID
|
||||
|
@ -2,6 +2,7 @@
|
||||
using BankYouBankruptContracts.BindingModels;
|
||||
using BankYouBankruptContracts.ViewModels;
|
||||
using BankYouBankruptContracts.ViewModels.Client.Default;
|
||||
using BankYouBankruptContracts.ViewModels.Client.Diagram;
|
||||
using BankYouBankruptDataModels.Enums;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Diagnostics;
|
||||
@ -497,5 +498,37 @@ namespace BankYouBankruptCashierApp.Controllers
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Diagram()
|
||||
{
|
||||
if (APICashier.Cashier == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
|
||||
ViewBag.Accounts = APICashier.GetRequest<List<AccountViewModel>>($"api/Account/GetAllAccounts");
|
||||
|
||||
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public IActionResult Diagram(int accountId)
|
||||
{
|
||||
if (APICashier.Cashier == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
|
||||
ViewBag.Accounts = APICashier.GetRequest<List<AccountViewModel>>($"api/Account/GetAllAccounts");
|
||||
|
||||
|
||||
return View(new CashierDiagramViewModel()
|
||||
{
|
||||
DiagramName = "Hello World",
|
||||
Elements = APICashier.GetRequest<List<CashierDiagramElementsViewModel>>($"api/Account/getAccountMonthResult?cardId={accountId}")
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
@using BankYouBankruptContracts.ViewModels
|
||||
|
||||
@model CashierDiagramViewModel
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Диаграмма";
|
||||
}
|
||||
|
||||
<div class="text-center">
|
||||
<h1 class="display-4">Диаграмма по месяцам</h1>
|
||||
</div>
|
||||
|
||||
<form method="post">
|
||||
<div class="row">
|
||||
<div class="row">Номер счета:</div>
|
||||
<select id="accountId" name="accountId" class="form-control" asp-items="@(new SelectList( @ViewBag.Accounts, "Id", "AccountNumber"))">
|
||||
<option disabled selected>Выберите счёт</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-8"></div>
|
||||
<div class="col-4">
|
||||
<input type="submit" value="Выбрать" class="btn btn-primary"/>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@if (Model == null) return;
|
||||
|
||||
<div id="Diagrams" class="text-center">
|
||||
<div id="@Model.DiagramName Diagram">
|
||||
<canvas id="Chart"></canvas>
|
||||
<div id="params">
|
||||
@foreach (var info in Model.Elements) {
|
||||
<input type="hidden" id="@info.Name" value="@info.Value" />
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
||||
|
||||
<script>
|
||||
const diagrams = document.getElementById('Diagrams').childNodes;
|
||||
|
||||
let diagram_name = diagrams[1].id;
|
||||
|
||||
console.log(diagram_name);
|
||||
let diagram = document.getElementById(diagram_name).childNodes;
|
||||
console.log(diagram);
|
||||
let labels = [];
|
||||
let data = [];
|
||||
document.getElementById('params').childNodes.forEach(element => {
|
||||
if (element.id != undefined) {
|
||||
labels.push(element.id);
|
||||
}
|
||||
});
|
||||
document.getElementById('params').childNodes.forEach(element => {
|
||||
if (element.id != undefined) {
|
||||
data.push(Number(element.value));
|
||||
}
|
||||
});
|
||||
|
||||
new Chart(diagram.item(1), {
|
||||
type: 'bar',
|
||||
data: {
|
||||
labels: labels,
|
||||
datasets: [{
|
||||
label: 'Денег в этом месяце',
|
||||
data: data,
|
||||
borderWidth: 1
|
||||
}]
|
||||
},
|
||||
options: {
|
||||
plugins: {
|
||||
legend: {
|
||||
display: false
|
||||
}
|
||||
},
|
||||
scales: {
|
||||
y: {
|
||||
suggestedMin: Math.min(data) - Math.min(data) * -0.1,
|
||||
suggestedMax: Math.max(data) + Math.max(data) * 0.1,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
</script>
|
@ -49,6 +49,9 @@
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asparea="" asp-controller="Home" asp-action="CreateReport">Отчёт</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asparea="" asp-controller="Home" asp-action="Diagram">Диаграмма</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asparea="" asp-controller="Home" asp-action="Privacy">Личный кабинет</a>
|
||||
</li>
|
||||
|
@ -22,5 +22,7 @@ namespace BankYouBankruptContracts.BusinessLogicsContracts
|
||||
bool Update(AccountBindingModel model);
|
||||
|
||||
bool Delete(AccountBindingModel model);
|
||||
public List<CashierDiagramElementsViewModel> GetMonthInfo(int AccountId);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,8 @@ namespace BankYouBankruptContracts.SearchModels
|
||||
|
||||
public int? ClientId { get; set; }
|
||||
|
||||
public int? CashierId { get; set; }
|
||||
|
||||
public int? AccountSenderId { get; set; }
|
||||
|
||||
public int? AccountPayeeId { get; set; }
|
||||
|
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BankYouBankruptContracts.ViewModels
|
||||
{
|
||||
public class CashierDiagramElementsViewModel
|
||||
{
|
||||
public string Name { get; set; } = "Column";
|
||||
public int Value { get; set; } = 0;
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using BankYouBankruptContracts.ViewModels.Client.Diagram;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BankYouBankruptContracts.ViewModels
|
||||
{
|
||||
public class CashierDiagramViewModel
|
||||
{
|
||||
public string DiagramName { get; set; } = "Diagram Name";
|
||||
|
||||
public List<CashierDiagramElementsViewModel> Elements { get; set; } = new();
|
||||
}
|
||||
}
|
@ -28,52 +28,27 @@ namespace BankYouBankruptDatabaseImplement.Implements
|
||||
|
||||
public List<CashWithdrawalViewModel> GetFilteredList(CashWithdrawalSearchModel model)
|
||||
{
|
||||
if (model.AccountId < 0)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
|
||||
using var context = new BankYouBancruptDatabase();
|
||||
|
||||
if (model.CashierId.HasValue)
|
||||
{
|
||||
return context.CashWithdrawals
|
||||
.Include(x => x.Cashier)
|
||||
var result = context.CashWithdrawals.Include(x => x.Cashier)
|
||||
.Include(x => x.Debiting)
|
||||
.Include(x => x.Account)
|
||||
.Where(x => x.CashierId == model.CashierId)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
//выборка для заполнения отчёта
|
||||
if(model.DateFrom.HasValue && model.DateTo.HasValue)
|
||||
{
|
||||
return context.CashWithdrawals
|
||||
.Include(x => x.Cashier)
|
||||
.Include(x => x.Debiting)
|
||||
.Include(x => x.Account)
|
||||
.Where(x => x.DateOperation >= model.DateFrom && x.DateOperation <= model.DateTo && x.Account.ClientId == model.ClientId)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
if (model.AccountId.HasValue) result = result.Where(x => x.AccountId == model.AccountId).ToList();
|
||||
|
||||
return context.CashWithdrawals
|
||||
.Include(x => x.Cashier)
|
||||
.Include(x => x.Debiting)
|
||||
.Include(x => x.Account)
|
||||
.Where(x => x.AccountId == model.AccountId)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
if (model.CashierId.HasValue) result = result.Where(x => x.CashierId == model.CashierId).ToList();
|
||||
|
||||
if (model.DateFrom.HasValue) result = result.Where(x => x.DateOperation >= model.DateFrom).ToList();
|
||||
|
||||
if (model.DateTo.HasValue) result = result.Where(x => x.DateOperation <= model.DateTo).ToList();
|
||||
|
||||
if (model.ClientId.HasValue) result = result.Where(x => x.Account.ClientId == model.ClientId).ToList();
|
||||
|
||||
return result.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public CashWithdrawalViewModel? GetElement(CashWithdrawalSearchModel model)
|
||||
{
|
||||
if (model.AccountId < 0 && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
using var context = new BankYouBancruptDatabase();
|
||||
|
||||
return context.CashWithdrawals
|
||||
|
@ -7,6 +7,7 @@ using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.NetworkInformation;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@ -28,32 +29,25 @@ namespace BankYouBankruptDatabaseImplement.Implements
|
||||
|
||||
public List<MoneyTransferViewModel> GetFilteredList(MoneyTransferSearchModel model)
|
||||
{
|
||||
if (model.AccountSenderId < 0)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
|
||||
using var context = new BankYouBancruptDatabase();
|
||||
|
||||
if(model.DateFrom.HasValue && model.DateTo.HasValue)
|
||||
{
|
||||
return context.MoneyTransfers
|
||||
var result = context.MoneyTransfers.Include(x => x.Cashier)
|
||||
.Include(x => x.AccountPayeer)
|
||||
.Include(x => x.AccountSender)
|
||||
.Include(x => x.Cashier)
|
||||
.Where(x => x.DateOperation >= model.DateFrom && x.DateOperation <= model.DateTo && x.AccountSenderId != null
|
||||
&& (x.AccountPayeer.ClientId == model.ClientId || x.AccountSender.Id == model.ClientId))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
return context.MoneyTransfers
|
||||
.Include(x => x.AccountPayeer)
|
||||
.Include(x => x.AccountSender)
|
||||
.Include(x => x.Cashier)
|
||||
.Where(x => x.AccountSenderId == model.AccountSenderId)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
if (model.AccountPayeeId.HasValue) result = result.Where(x => x.AccountPayeeId == model.AccountPayeeId).ToList();
|
||||
|
||||
if (model.AccountSenderId.HasValue) result = result.Where(x => x.AccountSenderId == model.AccountSenderId).ToList();
|
||||
|
||||
if (model.CashierId.HasValue) result = result.Where(x => x.CashierId == model.CashierId).ToList();
|
||||
|
||||
if (model.DateFrom.HasValue) result = result.Where(x => x.DateOperation >= model.DateFrom).ToList();
|
||||
|
||||
if (model.DateTo.HasValue) result = result.Where(x => x.DateOperation <= model.DateTo).ToList();
|
||||
|
||||
if (model.ClientId.HasValue) result = result.Where(x => (x.AccountPayeer.ClientId == model.ClientId || x.AccountSender.ClientId == model.ClientId)).ToList();
|
||||
|
||||
return result.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public MoneyTransferViewModel? GetElement(MoneyTransferSearchModel model)
|
||||
|
@ -4,6 +4,7 @@ using BankYouBankruptContracts.BusinessLogicsContracts;
|
||||
using BankYouBankruptContracts.SearchModels;
|
||||
using BankYouBankruptContracts.ViewModels;
|
||||
using BankYouBankruptContracts.ViewModels.Client.Default;
|
||||
using BankYouBankruptContracts.ViewModels.Client.Diagram;
|
||||
using BankYouBankruptDatabaseImplement.Models;
|
||||
using BankYouBankruptDataModels.Enums;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
@ -315,5 +316,19 @@ namespace BankYouBankruptRestApi.Controllers
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public List<CashierDiagramElementsViewModel> getAccountMonthResult(int cardId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _accountLogic.GetMonthInfo(cardId);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения пользователей");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user