Compare commits

...

2 Commits

9 changed files with 118 additions and 36 deletions

View File

@ -22,8 +22,9 @@ namespace BankBusinessLogic.BusinessLogics
private readonly AbstractSaveToWord _saveToWord;
private readonly AbstractSaveToExcel _saveToExcel;
private readonly AbstractSaveToPdf _saveToPdf;
public ReportLogic(ITransferStorage transferStorage, IPaymentStorage paymentStorage, ICurrencyStorage currencyStorage, ICurrencyPurchaseStorage currencyPurchaseStorage, AbstractSaveToWord saveToWord, AbstractSaveToExcel saveToExcel)
public ReportLogic(ITransferStorage transferStorage, IPaymentStorage paymentStorage, ICurrencyStorage currencyStorage, ICurrencyPurchaseStorage currencyPurchaseStorage, AbstractSaveToWord saveToWord, AbstractSaveToExcel saveToExcel, AbstractSaveToPdf saveToPdf)
{
_transferStorage = transferStorage;
_paymentStorage = paymentStorage;
@ -31,6 +32,7 @@ namespace BankBusinessLogic.BusinessLogics
_currencyPurchaseStorage = currencyPurchaseStorage;
_saveToWord = saveToWord;
_saveToExcel = saveToExcel;
_saveToPdf = saveToPdf;
}
public List<ReportPaymentCurrencyPurchaseViewModel> GetPaymentPurchase(List<PaymentBindingModel> payments)
@ -84,9 +86,9 @@ namespace BankBusinessLogic.BusinessLogics
{
TransferId = transfer.Id,
TransferDate = transfer.TransferDateTime,
Purchases = new List<(int, float)>()
Purchases = new List<CurrencyPurchaseViewModel>()
};
var payment = _paymentStorage.GetElement(new PaymentSearchModel { Id = transfer.Id});
var payment = _paymentStorage.GetElement(new PaymentSearchModel { Id = transfer.PaymentId});
if (payment == null)
{
throw new InvalidOperationException("Платеж не был найден!");
@ -104,7 +106,7 @@ namespace BankBusinessLogic.BusinessLogics
{
if (currencyPurchase.CurrencyId == currencyId)
{
record.Purchases.Add(new(currencyPurchase.Id, currencyPurchase.Amount));
record.Purchases.Add(currencyPurchase);
break;
}
}
@ -192,11 +194,20 @@ namespace BankBusinessLogic.BusinessLogics
});
}
public void SaveTransferPurchaseToPDF(ReportBindingModel model)
public MemoryStream SaveTransferPurchaseToPDF(ReportBindingModel model)
{
if (!model.DateFrom.HasValue || !model.DateTo.HasValue)
{
throw new InvalidOperationException("Отсутствуют даты для отчёта!");
}
var result = GetTransferPurchase(model);
//создание файла будет реализовано в будующих версиях
throw new NotImplementedException();
return _saveToPdf.CreateOperatorDoc(new PdfInfo
{
Title = "Отчёт о зачислениях",
DateFrom = model.DateFrom.Value,
DateTo = model.DateTo.Value,
Transfers = result
});
}
public void SaveCurrencyTransfersToExcel(List<CurrencyBindingModel> currencies)

View File

@ -10,33 +10,41 @@ namespace ConfectioneryBusinessLogic.OfficePackage
{
public abstract class AbstractSaveToPdf
{
public void CreateOperatorDoc(PdfInfo info)
public MemoryStream CreateOperatorDoc(PdfInfo info)
{
CreatePdf(info);
CreateParagraph(new PdfParagraph { Text = info.Title, Style = "NormalTitle", ParagraphAlignment = PdfParagraphAlignmentType.Center });
CreateParagraph(new PdfParagraph { Text = $"с {info.DateFrom.ToShortDateString()} по {info.DateTo.ToShortDateString()}", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Center });
CreateTable(new List<string> { "2cm", "3cm", "6cm", "3cm", "3cm" });
CreateTable(new List<string> { "4cm", "3cm", "3cm", "2cm", "3cm", "3cm" });
CreateRow(new PdfRowParameters
{
Texts = new List<string> { "Номер", "Дата заказа", "Изделие", "Статус", "Сумма" },
Texts = new List<string> { "Номер зачисления", "Дата зачисления", "Номер закупки", "Сумма", "Валюта", "Дата закупки" },
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
//foreach (var order in info.Orders)
//{
// CreateRow(new PdfRowParameters
// {
// Texts = new List<string> { order.Id.ToString(), order.DateCreate.ToShortDateString(), order.PastryName, order.Status, order.Sum.ToString() },
// Style = "Normal",
// ParagraphAlignment = PdfParagraphAlignmentType.Left
// });
//}
//CreateParagraph(new PdfParagraph { Text = $"Итого: {info.Orders.Sum(x => x.Sum)}\t", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Rigth });
foreach (var transfer in info.Transfers)
{
CreateRow(new PdfRowParameters
{
Texts = new List<string> { "Зачисление №" + transfer.TransferId, transfer.TransferDate.ToShortDateString(), "", "", "", "" },
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Left
});
foreach(var purchase in transfer.Purchases)
{
CreateRow(new PdfRowParameters
{
Texts = new List<string> { "", "", "Закупка №" + purchase.Id, purchase.Amount.ToString(), purchase.CurrencyName.ToString(), purchase.PurchaseDate.ToShortDateString()},
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Left
});
}
}
//SavePdf(info);
return SavePdf();
}
/// <summary>
@ -69,6 +77,6 @@ namespace ConfectioneryBusinessLogic.OfficePackage
/// Сохранение файла
/// </summary>
/// <param name="info"></param>
protected abstract void SavePdf(PdfInfo info);
protected abstract MemoryStream SavePdf();
}
}

View File

@ -106,14 +106,21 @@ namespace ConfectioneryBusinessLogic.OfficePackage.Implements
}
}
protected override void SavePdf(PdfInfo info)
protected override MemoryStream SavePdf()
{
var renderer = new PdfDocumentRenderer(true)
{
Document = _document
};
renderer.RenderDocument();
renderer.PdfDocument.Save(info.FileName);
MemoryStream stream = new MemoryStream();
renderer.PdfDocument.Save(stream, false);
stream.Seek(0, SeekOrigin.Begin);
return stream;
}
}
}

View File

@ -14,7 +14,7 @@ namespace BankContracts.BusinessLogicsContracts
List<ReportTransferCurrencyPurchaseViewModel> GetTransferPurchase(ReportBindingModel model);
MemoryStream SavePaymentPurchaseToWord(ReportBindingModel model, List<PaymentBindingModel> payments);
MemoryStream SavePaymentPurchaseToExcel(ReportBindingModel model, List<PaymentBindingModel> payments);
void SaveTransferPurchaseToPDF(ReportBindingModel model);
MemoryStream SaveTransferPurchaseToPDF(ReportBindingModel model);
List<ReportCurrencyTransferViewModel> GetCurrencyTransfers(List<CurrencyBindingModel> currencies);
List<ReportCurrencyPurchasePaymentViewModel> GetPurchasePayment(ReportBindingModel model);

View File

@ -10,6 +10,6 @@ namespace BankContracts.ViewModels
{
public int TransferId { get; set; }
public DateTime TransferDate { get; set; }
public List<(int PurchaseId, float Amount)> Purchases { get; set; } = new();
public List<CurrencyPurchaseViewModel> Purchases { get; set; } = new();
}
}

View File

@ -36,7 +36,7 @@ namespace OperatorApp.Controllers
{
return Redirect("~/Home/Enter");
}
return View(_dealLogic.ReadList(new DealSearchModel { OperatorId = APIClient.Operator.Id}));
return View(_dealLogic.ReadList(new DealSearchModel { OperatorId = APIClient.Operator.Id }));
}
[HttpGet]
@ -97,7 +97,7 @@ namespace OperatorApp.Controllers
{
throw new Exception("Введите логин и пароль");
}
APIClient.Operator = _operatorLogic.ReadElement(new OperatorSearchModel { Login = login, Password = password});
APIClient.Operator = _operatorLogic.ReadElement(new OperatorSearchModel { Login = login, Password = password });
if (APIClient.Operator == null)
{
throw new Exception("Неверный логин/пароль");
@ -155,12 +155,12 @@ namespace OperatorApp.Controllers
{
return Redirect("~/Home/Enter");
}
return View(_paymentLogic.ReadList(new PaymentSearchModel { OperatorId = APIClient.Operator.Id}));
return View(_paymentLogic.ReadList(new PaymentSearchModel { OperatorId = APIClient.Operator.Id }));
}
[HttpGet]
public IActionResult CreatePayment()
{
ViewBag.Deals = _dealLogic.ReadList(new DealSearchModel { OperatorId = APIClient.Operator.Id});
ViewBag.Deals = _dealLogic.ReadList(new DealSearchModel { OperatorId = APIClient.Operator.Id });
return View();
}
[HttpPost]
@ -173,7 +173,7 @@ namespace OperatorApp.Controllers
Dictionary<int, IDealModel> DealPayments = new();
foreach (int id in deals)
{
var deal = _dealLogic.ReadElement(new DealSearchModel { Id = id});
var deal = _dealLogic.ReadElement(new DealSearchModel { Id = id });
if (deal != null) DealPayments.Add(deal.Id, deal);
}
_paymentLogic.Create(new PaymentBindingModel { OperatorId = APIClient.Operator.Id, DealPayments = DealPayments, });
@ -182,7 +182,7 @@ namespace OperatorApp.Controllers
[HttpGet]
public IActionResult Payment(int id)
{
return View(_paymentLogic.ReadElement(new PaymentSearchModel { Id = id}));
return View(_paymentLogic.ReadElement(new PaymentSearchModel { Id = id }));
}
[HttpGet]
public IActionResult Transfers()
@ -211,9 +211,18 @@ namespace OperatorApp.Controllers
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
_transferLogic.Create(new TransferBindingModel { OperatorId = APIClient.Operator.Id, Amount = (float)Convert.ToDouble(amount), PaymentId = payment});
_transferLogic.Create(new TransferBindingModel { OperatorId = APIClient.Operator.Id, Amount = (float)Convert.ToDouble(amount), PaymentId = payment });
Response.Redirect("Transfers");
}
public void DeleteTransfer(int id)
{
if (APIClient.Operator == null)
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
_transferLogic.Delete(new TransferBindingModel { Id = id });
Response.Redirect("/Home/Transfers");
}
[HttpGet]
public IActionResult PaymentsReport()
@ -253,5 +262,17 @@ namespace OperatorApp.Controllers
// return File(list, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "testExcel.xlsx");
//}
}
[HttpGet]
public IActionResult TransfersReport()
{
return View(new ReportBindingModel());
}
[HttpPost]
public IActionResult TransfersReport(DateTime dateFrom, DateTime dateTo)
{
MemoryStream report = _reportLogic.SaveTransferPurchaseToPDF(new ReportBindingModel { DateFrom = dateFrom, DateTo = dateTo });
return File(report, "application/pdf", "test.pdf");
}
}
}

View File

@ -37,6 +37,8 @@
<th>
Номер выплаты
</th>
<th>
</th>
</tr>
</thead>
<tbody>
@ -55,6 +57,9 @@
<td>
@Html.DisplayFor(modelItem => item.PaymentId)
</td>
<td>
<a asp-action="DeleteTransfer" asp-route-id="@item.Id">Удалить</a>
</td>
</tr>
}
</tbody>

View File

@ -0,0 +1,25 @@
@using BankContracts.BindingModels
@model ReportBindingModel
@{
ViewData["Title"] = "TransfersReport";
}
<div class="text-center">
<h2 class="display-4">Создание отчёта</h2>
</div>
<form method="post">
<div class="row">
<div class="col-4">C:</div>
<div class="col-8">
@Html.EditorFor(x => x.DateFrom, new { htmlAttributes = new { @class = "form-control my-3", @type = "date", @name="DateFrom", @required="true", @id="DateFrom" } })
</div>
<div class="col-4">По:</div>
<div class="col-8">
@Html.EditorFor(x => x.DateTo, new { htmlAttributes = new { @class = "form-control my-3", @type = "date", @name="DateTo", @required="true", @id="DateTo" } })
</div>
</div>
<div class="row">
<div class="col-8"></div>
<div class="col-4"><input type="submit" value="Создать" class="btn btn-primary" /></div>
</div>
</form>

View File

@ -8,6 +8,8 @@
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
<link rel="stylesheet" href="~/AbstractShowClientApp.styles.css" asp-append-version="true" />
<script src="~/lib/jquery/dist/jquery.min.js"></script>
</head>
<body>
<header>
@ -39,7 +41,10 @@
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Register">Регистрация</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="PaymentsReport">Регистрация</a>
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="PaymentsReport">Списки по выплатам</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="TransfersReport">Отчёт по зачислениям</a>
</li>
</ul>
</div>