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

View File

@ -10,33 +10,41 @@ namespace ConfectioneryBusinessLogic.OfficePackage
{ {
public abstract class AbstractSaveToPdf public abstract class AbstractSaveToPdf
{ {
public void CreateOperatorDoc(PdfInfo info) public MemoryStream CreateOperatorDoc(PdfInfo info)
{ {
CreatePdf(info); CreatePdf(info);
CreateParagraph(new PdfParagraph { Text = info.Title, Style = "NormalTitle", ParagraphAlignment = PdfParagraphAlignmentType.Center }); 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 }); 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 CreateRow(new PdfRowParameters
{ {
Texts = new List<string> { "Номер", "Дата заказа", "Изделие", "Статус", "Сумма" }, Texts = new List<string> { "Номер зачисления", "Дата зачисления", "Номер закупки", "Сумма", "Валюта", "Дата закупки" },
Style = "NormalTitle", Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center ParagraphAlignment = PdfParagraphAlignmentType.Center
}); });
//foreach (var order in info.Orders) foreach (var transfer in info.Transfers)
//{ {
// CreateRow(new PdfRowParameters CreateRow(new PdfRowParameters
// { {
// Texts = new List<string> { order.Id.ToString(), order.DateCreate.ToShortDateString(), order.PastryName, order.Status, order.Sum.ToString() }, Texts = new List<string> { "Зачисление №" + transfer.TransferId, transfer.TransferDate.ToShortDateString(), "", "", "", "" },
// Style = "Normal", Style = "Normal",
// ParagraphAlignment = PdfParagraphAlignmentType.Left ParagraphAlignment = PdfParagraphAlignmentType.Left
// }); });
//} foreach(var purchase in transfer.Purchases)
//CreateParagraph(new PdfParagraph { Text = $"Итого: {info.Orders.Sum(x => x.Sum)}\t", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Rigth }); {
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> /// <summary>
@ -69,6 +77,6 @@ namespace ConfectioneryBusinessLogic.OfficePackage
/// Сохранение файла /// Сохранение файла
/// </summary> /// </summary>
/// <param name="info"></param> /// <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) var renderer = new PdfDocumentRenderer(true)
{ {
Document = _document Document = _document
}; };
renderer.RenderDocument(); 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); List<ReportTransferCurrencyPurchaseViewModel> GetTransferPurchase(ReportBindingModel model);
MemoryStream SavePaymentPurchaseToWord(ReportBindingModel model, List<PaymentBindingModel> payments); MemoryStream SavePaymentPurchaseToWord(ReportBindingModel model, List<PaymentBindingModel> payments);
MemoryStream SavePaymentPurchaseToExcel(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<ReportCurrencyTransferViewModel> GetCurrencyTransfers(List<CurrencyBindingModel> currencies);
List<ReportCurrencyPurchasePaymentViewModel> GetPurchasePayment(ReportBindingModel model); List<ReportCurrencyPurchasePaymentViewModel> GetPurchasePayment(ReportBindingModel model);

View File

@ -10,6 +10,6 @@ namespace BankContracts.ViewModels
{ {
public int TransferId { get; set; } public int TransferId { get; set; }
public DateTime TransferDate { 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 Redirect("~/Home/Enter");
} }
return View(_dealLogic.ReadList(new DealSearchModel { OperatorId = APIClient.Operator.Id})); return View(_dealLogic.ReadList(new DealSearchModel { OperatorId = APIClient.Operator.Id }));
} }
[HttpGet] [HttpGet]
@ -97,7 +97,7 @@ namespace OperatorApp.Controllers
{ {
throw new Exception("Введите логин и пароль"); 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) if (APIClient.Operator == null)
{ {
throw new Exception("Неверный логин/пароль"); throw new Exception("Неверный логин/пароль");
@ -155,12 +155,12 @@ namespace OperatorApp.Controllers
{ {
return Redirect("~/Home/Enter"); 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] [HttpGet]
public IActionResult CreatePayment() 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(); return View();
} }
[HttpPost] [HttpPost]
@ -173,7 +173,7 @@ namespace OperatorApp.Controllers
Dictionary<int, IDealModel> DealPayments = new(); Dictionary<int, IDealModel> DealPayments = new();
foreach (int id in deals) 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); if (deal != null) DealPayments.Add(deal.Id, deal);
} }
_paymentLogic.Create(new PaymentBindingModel { OperatorId = APIClient.Operator.Id, DealPayments = DealPayments, }); _paymentLogic.Create(new PaymentBindingModel { OperatorId = APIClient.Operator.Id, DealPayments = DealPayments, });
@ -182,7 +182,7 @@ namespace OperatorApp.Controllers
[HttpGet] [HttpGet]
public IActionResult Payment(int id) public IActionResult Payment(int id)
{ {
return View(_paymentLogic.ReadElement(new PaymentSearchModel { Id = id})); return View(_paymentLogic.ReadElement(new PaymentSearchModel { Id = id }));
} }
[HttpGet] [HttpGet]
public IActionResult Transfers() public IActionResult Transfers()
@ -211,9 +211,18 @@ namespace OperatorApp.Controllers
throw new Exception("Вы как суда попали? Суда вход только авторизованным"); 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"); 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] [HttpGet]
public IActionResult PaymentsReport() public IActionResult PaymentsReport()
@ -253,5 +262,17 @@ namespace OperatorApp.Controllers
// return File(list, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "testExcel.xlsx"); // 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>
<th>
</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -55,6 +57,9 @@
<td> <td>
@Html.DisplayFor(modelItem => item.PaymentId) @Html.DisplayFor(modelItem => item.PaymentId)
</td> </td>
<td>
<a asp-action="DeleteTransfer" asp-route-id="@item.Id">Удалить</a>
</td>
</tr> </tr>
} }
</tbody> </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="~/css/site.css" asp-append-version="true" />
<link rel="stylesheet" href="~/AbstractShowClientApp.styles.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> <script src="~/lib/jquery/dist/jquery.min.js"></script>
</head> </head>
<body> <body>
<header> <header>
@ -39,7 +41,10 @@
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Register">Регистрация</a> <a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Register">Регистрация</a>
</li> </li>
<li class="nav-item"> <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> </li>
</ul> </ul>
</div> </div>