Правки по части доступа и начало создания отчётов.

This commit is contained in:
Programmist73 2023-05-18 00:04:33 +04:00
parent a1742e2ec0
commit 06bbe74214
13 changed files with 209 additions and 45 deletions

View File

@ -41,8 +41,8 @@ namespace BankYouBankruptBusinessLogic.BusinessLogics
DateTo = model.DateTo,
}).Select(x => new ReportClientViewModel
{
CardId = x.CardId,
SumOperation = x.Sum,
CardNumber = x.CardNumber,
SumOperation = x.Sum,
DateComplite = x.DateOpen
}).ToList();
}
@ -55,7 +55,7 @@ namespace BankYouBankruptBusinessLogic.BusinessLogics
DateFrom = model.DateTo,
}).Select(x => new ReportClientViewModel
{
CardId = x.CardId,
CardNumber = x.CardNumber,
SumOperation = x.Sum,
DateComplite = x.DateClose
}).ToList();
@ -66,11 +66,6 @@ namespace BankYouBankruptBusinessLogic.BusinessLogics
throw new NotImplementedException();
}
public void SaveCreditingToPdfFile(ReportBindingModel model)
{
throw new NotImplementedException();
}
public void SaveCreditingToWordFile(ReportBindingModel model)
{
throw new NotImplementedException();
@ -81,14 +76,23 @@ namespace BankYouBankruptBusinessLogic.BusinessLogics
throw new NotImplementedException();
}
public void SaveDebitingToPdfFile(ReportBindingModel model)
{
throw new NotImplementedException();
}
public void SaveDebitingToWordFile(ReportBindingModel model)
{
throw new NotImplementedException();
}
}
//отчёт в формате PDF для клиента
public void SaveClientReportToPdfFile(ReportBindingModel model)
{
_saveToPdf.CreateDoc(new PdfInfoClient
{
FileName = model.FileName,
Title = "Отчёт по операциям с картой",
DateFrom = model.DateFrom!.Value,
DateTo = model.DateTo!.Value,
ReportCrediting = GetCrediting(model),
ReportDebiting = GetDebiting(model)
});
}
}
}

View File

@ -11,7 +11,7 @@ namespace BankYouBankruptBusinessLogic.OfficePackage
public abstract class AbstractSaveToPdfCashier
{
//публичный метод создания документа. Описание методов ниже
public void CreateDoc(PdfInfo info)
public void CreateDoc(PdfInfoClient info)
{
CreatePdf(info);
@ -29,13 +29,32 @@ namespace BankYouBankruptBusinessLogic.OfficePackage
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
//TODO
CreateTable(new List<string> { "2cm", "3cm", "6cm", "3cm", "3cm" });
SavePdf(info);
}
CreateRow(new PdfRowParameters
{
Texts = new List<string> { "Номер", "Дата заказа", "Изделие", "Статус заказа", "Сумма" },
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
foreach (var report in info.ReportAccounts)
{
CreateRow(new PdfRowParameters
{
Texts = new List<string> { report.AccountSenderId.ToString(), report.AccountPayeeId.ToString(), report.DateComplite.ToShortDateString(), report.SumOperation.ToString() },
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Left
});
}
//CreateParagraph(new PdfParagraph { Text = $"Итого: {info.Orders.Sum(x => x.Sum)}\t", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Right });
SavePdf(info);
}
/// Создание pdf-файла
protected abstract void CreatePdf(PdfInfo info);
protected abstract void CreatePdf(PdfInfoClient info);
/// Создание параграфа с текстом
protected abstract void CreateParagraph(PdfParagraph paragraph);
@ -47,6 +66,6 @@ namespace BankYouBankruptBusinessLogic.OfficePackage
protected abstract void CreateRow(PdfRowParameters rowParameters);
/// Сохранение файла
protected abstract void SavePdf(PdfInfo info);
protected abstract void SavePdf(PdfInfoClient info);
}
}

View File

@ -11,7 +11,7 @@ namespace BankYouBankruptBusinessLogic.OfficePackage
public abstract class AbstractSaveToPdfClient
{
//публичный метод создания документа. Описание методов ниже
public void CreateDoc(PdfInfo info)
public void CreateDoc(PdfInfoClient info)
{
CreatePdf(info);
@ -29,13 +29,44 @@ namespace BankYouBankruptBusinessLogic.OfficePackage
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
//TODO
CreateRow(new PdfRowParameters
{
Texts = new List<string> { "Номер карты", "Сумма операции", "Дата операции" },
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
SavePdf(info);
}
CreateParagraph(new PdfParagraph { Text = "Отчёт по пополнениям", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Center });
foreach (var report in info.ReportCrediting)
{
CreateRow(new PdfRowParameters
{
Texts = new List<string> { report.CardNumber, report.SumOperation.ToString(), report.DateComplite.ToString() },
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Left
});
}
CreateParagraph(new PdfParagraph { Text = "Отчёт по снятиям", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Center });
foreach (var report in info.ReportDebiting)
{
CreateRow(new PdfRowParameters
{
Texts = new List<string> { report.CardNumber, report.SumOperation.ToString(), report.DateComplite.ToString() },
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Left
});
}
//CreateParagraph(new PdfParagraph { Text = $"Итого: {info.Orders.Sum(x => x.Sum)}\t", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Right });
SavePdf(info);
}
/// Создание pdf-файла
protected abstract void CreatePdf(PdfInfo info);
protected abstract void CreatePdf(PdfInfoClient info);
/// Создание параграфа с текстом
protected abstract void CreateParagraph(PdfParagraph paragraph);
@ -47,6 +78,6 @@ namespace BankYouBankruptBusinessLogic.OfficePackage
protected abstract void CreateRow(PdfRowParameters rowParameters);
/// Сохранение файла
protected abstract void SavePdf(PdfInfo info);
protected abstract void SavePdf(PdfInfoClient info);
}
}

View File

@ -8,7 +8,7 @@ using System.Threading.Tasks;
namespace BankYouBankruptBusinessLogic.OfficePackage.HelperModels
{
//общая информация по pdf файлу
public class PdfInfo
public class PdfInfoClient
{
public string FileName { get; set; } = string.Empty;
@ -19,6 +19,9 @@ namespace BankYouBankruptBusinessLogic.OfficePackage.HelperModels
public DateTime DateTo { get; set; }
//перечень заказов за указанный период для вывода/сохранения
public List<ReportCashierViewModel> ReportAccounts { get; set; } = new();
}
public List<ReportClientViewModel> ReportCrediting { get; set; } = new();
//перечень заказов за указанный период для вывода/сохранения
public List<ReportClientViewModel> ReportDebiting { get; set; } = new();
}
}

View File

@ -12,7 +12,7 @@ using System.Threading.Tasks;
namespace BankYouBankruptBusinessLogic.OfficePackage.Implements
{
//реализация астрактного класса создания pdf документа
public class SaveToPdf : AbstractSaveToPdfCashier
public class SaveToPdf : AbstractSaveToPdfClient
{
private Document? _document;
@ -44,7 +44,7 @@ namespace BankYouBankruptBusinessLogic.OfficePackage.Implements
style.Font.Bold = true;
}
protected override void CreatePdf(PdfInfo info)
protected override void CreatePdf(PdfInfoClient info)
{
//создаём документ
_document = new Document();
@ -117,7 +117,7 @@ namespace BankYouBankruptBusinessLogic.OfficePackage.Implements
}
}
protected override void SavePdf(PdfInfo info)
protected override void SavePdf(PdfInfoClient info)
{
var renderer = new PdfDocumentRenderer(true)
{

View File

@ -150,8 +150,13 @@ namespace BankYouBankruptCashierApp.Controllers
[HttpGet]
public IActionResult CreateAccount()
{
//запрашиваем список в формате вспомогательной вьюшки из-за работы select в asp net
ViewBag.Clients = APICashier.GetRequest<List<ClientViewModel>>($"/api/Client/GetAllClients").Select(x => new ClientSelectViewModel
if (APICashier.Cashier == null)
{
return Redirect("~/Home/Enter");
}
//запрашиваем список в формате вспомогательной вьюшки из-за работы select в asp net
ViewBag.Clients = APICashier.GetRequest<List<ClientViewModel>>($"/api/Client/GetAllClients").Select(x => new ClientSelectViewModel
{
Id = x.Id,
FullName = x.Surname + " " + x.Name + " " + x.Patronymic
@ -201,7 +206,12 @@ namespace BankYouBankruptCashierApp.Controllers
[HttpGet]
public IActionResult CreateReport()
{
ViewBag.Accountes = APICashier.GetRequest<List<AccountViewModel>>("api/main/getaccountlist");
if (APICashier.Cashier == null)
{
return Redirect("~/Home/Enter");
}
ViewBag.Accountes = APICashier.GetRequest<List<AccountViewModel>>("api/main/getaccountlist");
return View();
}
@ -258,7 +268,12 @@ namespace BankYouBankruptCashierApp.Controllers
[HttpGet]
public IActionResult CloseCrediting()
{
ViewBag.Creditings = APICashier.GetRequest<List<CreditingViewModel>>("/api/Account/FindOpenCrediting");
if (APICashier.Cashier == null)
{
return Redirect("~/Home/Enter");
}
ViewBag.Creditings = APICashier.GetRequest<List<CreditingViewModel>>("/api/Account/FindOpenCrediting");
ViewBag.Accounts = APICashier.GetRequest<List<AccountViewModel>>("/api/Account/GetAllAccounts");
@ -308,7 +323,12 @@ namespace BankYouBankruptCashierApp.Controllers
[HttpGet]
public IActionResult CloseDebiting()
{
ViewBag.Debitings = APICashier.GetRequest<List<DebitingViewModel>>("/api/Account/FindOpenDebiting");
if (APICashier.Cashier == null)
{
return Redirect("~/Home/Enter");
}
ViewBag.Debitings = APICashier.GetRequest<List<DebitingViewModel>>("/api/Account/FindOpenDebiting");
ViewBag.Accounts = APICashier.GetRequest<List<AccountViewModel>>("/api/Account/GetAllAccounts");
@ -357,6 +377,11 @@ namespace BankYouBankruptCashierApp.Controllers
[HttpPost]
public string GetAccountNumber(int id)
{
if (APICashier.Cashier == null)
{
throw new Exception("Вы как сюда попали? Суда вход только авторизованным");
}
APICashier.Debiting = APICashier.GetRequest<DebitingViewModel>($"/api/Account/FindDebiting?id={id}");
APICashier.Crediting = APICashier.GetRequest<CreditingViewModel>($"/api/Account/FindDebiting?id={id}");
@ -384,7 +409,12 @@ namespace BankYouBankruptCashierApp.Controllers
[HttpGet]
public IActionResult MoneyTransfers()
{
ViewBag.Accounts = APICashier.GetRequest<List<AccountViewModel>>("/api/Account/GetAllAccounts");
if (APICashier.Cashier == null)
{
return Redirect("~/Home/Enter");
}
ViewBag.Accounts = APICashier.GetRequest<List<AccountViewModel>>("/api/Account/GetAllAccounts");
return View();
}

View File

@ -239,5 +239,21 @@ namespace BankYouBankruptClientApp.Controllers
}
#endregion
#region Получение отчёта
[HttpGet]
public IActionResult CreateReport()
{
return View();
}
[HttpPost]
public void CreateReport(DateTime DateFrom, DateTime DateTo)
{
}
#endregion
}
}

View File

@ -0,0 +1,5 @@
@*
For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
}

View File

@ -26,16 +26,18 @@
@{ if (authenticated) {
<ul class="navbar-nav flex-grow-1">
<li class="nav-item">
<a class="nav-link text-dark" asparea="" asp-controller="Home" asp-action="CardsList">Карты</a>
<a class="nav-link text-dark" asparea="" asp-controller="Home" asp-action="CardsList">Карты</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asparea="" asp-controller="Home" asp-action="DebitingList">Снятие средств</a>
<a class="nav-link text-dark" asparea="" asp-controller="Home" asp-action="DebitingList">Снятие средств</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asparea="" asp-controller="Home" asp-action="CreditingList">Пополнить средства</a>
<a class="nav-link text-dark" asparea="" asp-controller="Home" asp-action="CreditingList">Пополнить средства</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asparea="" asp-controller="Home" asp-action="CreateReport">Отчёт по картам</a>
</li>
</ul>
}
}
</div>

View File

@ -22,8 +22,8 @@ namespace BankYouBankruptContracts.BusinessLogicsContracts
//Сохранение отчёта по картам в файл-Excel
void SaveCreditingToExcelFile(ReportBindingModel model);
void SaveDebitingToExcelFile(ReportBindingModel model);
//Сохранение отчёта по картам в файл-Pdf
void SaveCreditingToPdfFile(ReportBindingModel model);
void SaveDebitingToPdfFile(ReportBindingModel model);
void SaveClientReportToPdfFile(ReportBindingModel model);
}
}

View File

@ -8,7 +8,7 @@ namespace BankYouBankruptContracts.ViewModels
{
public class ReportClientViewModel
{
public int CardId { get; set; }
public string CardNumber { get; set; }
public double SumOperation { get; set; }

View File

@ -0,0 +1,49 @@
using BankYouBankruptBusinessLogic.BusinessLogics;
using BankYouBankruptContracts.BindingModels;
using BankYouBankruptContracts.BusinessLogicsContracts;
using BankYouBankruptContracts.SearchModels;
using BankYouBankruptContracts.ViewModels;
using BankYouBankruptRestApi.Controllers;
using Microsoft.AspNetCore.Mvc;
namespace BankYouBankruptRestAPI.Controllers
{
//указание у контроллера, что Route будет строиться не только по наванию контроллера, но и по названию метода (так как у нас два Post-метода)
[Route("api/[controller]/[action]")]
[ApiController]
public class ReportController : Controller
{
private readonly ILogger _logger;
private readonly IReportCashierLogic _reportCashierLogic;
private readonly IReportClientLogic _reportClientLogic;
public ReportController(ILogger<AccountController> logger, IReportClientLogic reportClientLogic, IReportCashierLogic reportCashierLogic)
{
_logger = logger;
_reportClientLogic = reportClientLogic;
_reportCashierLogic = reportCashierLogic;
}
//метод генерации отчёта за период по картам клиента
[HttpGet]
public void CreateClientReport(DateTime DateFrom, DateTime DateTo)
{
try
{
_reportClientLogic.SaveClientReportToPdfFile(new ReportBindingModel
{
FileName = "Отчёт по картам от " + DateTime.Now.ToShortDateString(),
DateFrom = DateFrom,
DateTo = DateTo
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка входа в систему");
throw;
}
}
}
}

View File

@ -1,4 +1,6 @@
using BankYouBankruptBusinessLogic.BusinessLogics;
using BankYouBankruptBusinessLogic.OfficePackage;
using BankYouBankruptBusinessLogic.OfficePackage.Implements;
using BankYouBankruptContracts.BusinessLogicsContracts;
using BankYouBankruptContracts.StoragesContracts;
using BankYouBankruptDatabaseImplement.Implements;
@ -29,6 +31,9 @@ builder.Services.AddTransient<IMoneyTransferLogic, MoneyTransferLogic>();
builder.Services.AddTransient<IDebitingLogic, DebitingLogic>();
builder.Services.AddTransient<ICashWithdrawalLogic, CashWithdrawalLogic>();
builder.Services.AddTransient<AbstractSaveToPdfClient, SaveToPdf>();
//builder.Services.AddTransient<AbstractSaveToPdfCashier, SaveToPdf>();
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle