Отчёт в PDF для "Поставщика".
This commit is contained in:
parent
fc620df38b
commit
d914f59db5
@ -161,12 +161,12 @@ namespace BankBusinessLogic.BusinessLogics
|
|||||||
CurrencyPurchaseId = purchase.Id,
|
CurrencyPurchaseId = purchase.Id,
|
||||||
PurchaseDate = purchase.PurchaseDate,
|
PurchaseDate = purchase.PurchaseDate,
|
||||||
CurrencyName = purchase.CurrencyName,
|
CurrencyName = purchase.CurrencyName,
|
||||||
Payments = new List<(int PaymentId, string PaymentDate)>(),
|
Payments = new List<(int PaymentId, DateTime PaymentDate)>(),
|
||||||
};
|
};
|
||||||
var paymentsId = new List<int>();
|
var paymentsId = new List<int>();
|
||||||
foreach (var payment in payments)
|
foreach (var payment in payments)
|
||||||
{
|
{
|
||||||
if (payment.CurrencyPayments.ContainsKey(purchase.CurrencyId)) record.Payments.Add(new(payment.Id, payment.PaymentDate.ToString()));
|
if (payment.CurrencyPayments.ContainsKey(purchase.CurrencyId)) record.Payments.Add(new(payment.Id, payment.PaymentDate));
|
||||||
}
|
}
|
||||||
list.Add(record);
|
list.Add(record);
|
||||||
}
|
}
|
||||||
@ -211,23 +211,8 @@ namespace BankBusinessLogic.BusinessLogics
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public MemoryStream SaveCurrencyTransferToPDF(ReportBindingModel model)
|
public MemoryStream SaveCurrencyTransfersToExcel(ReportBindingModel model,
|
||||||
{
|
List<CurrencyBindingModel> currencies)
|
||||||
if (!model.DateFrom.HasValue || !model.DateTo.HasValue)
|
|
||||||
{
|
|
||||||
throw new InvalidOperationException("Отсутствуют даты для отчёта!");
|
|
||||||
}
|
|
||||||
var result = GetTransferPurchase(model);
|
|
||||||
return _saveToPdf.CreateBankOperatorDoc(new PdfInfo
|
|
||||||
{
|
|
||||||
Title = "Отчёт по закупкам",
|
|
||||||
DateFrom = model.DateFrom.Value,
|
|
||||||
DateTo = model.DateTo.Value,
|
|
||||||
Transfers = result
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public MemoryStream SaveCurrencyTransfersToExcel(ReportBindingModel model, List<CurrencyBindingModel> currencies)
|
|
||||||
{
|
{
|
||||||
var report = GetCurrencyTransfers(currencies);
|
var report = GetCurrencyTransfers(currencies);
|
||||||
return _saveToExcel.CreateBankOperatorReport(new ExcelInfo
|
return _saveToExcel.CreateBankOperatorReport(new ExcelInfo
|
||||||
@ -250,8 +235,19 @@ namespace BankBusinessLogic.BusinessLogics
|
|||||||
}
|
}
|
||||||
public MemoryStream SavePurchasePaymentToPDF(ReportBindingModel model)
|
public MemoryStream SavePurchasePaymentToPDF(ReportBindingModel model)
|
||||||
{
|
{
|
||||||
|
if (!model.DateFrom.HasValue || !model.DateTo.HasValue)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Отсутствуют даты для отчёта!");
|
||||||
|
}
|
||||||
var report = GetPurchasePayment(model);
|
var report = GetPurchasePayment(model);
|
||||||
throw new NotImplementedException();
|
return _saveToPdf.CreateBankOperatorDoc(new PdfInfo
|
||||||
|
{
|
||||||
|
Title = "Отчёт по закупкам",
|
||||||
|
DateFrom = model.DateFrom.Value,
|
||||||
|
DateTo = model.DateTo.Value,
|
||||||
|
CurrencyPurchases = report
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,6 +52,52 @@ namespace BankBusinessLogic.OfficePackage
|
|||||||
return SavePdf();
|
return SavePdf();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public MemoryStream CreateBankOperatorDoc(PdfInfo info)
|
||||||
|
{
|
||||||
|
if (info.CurrencyPurchases == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Данные для отчёта не найдены!", nameof(info.CurrencyPurchases));
|
||||||
|
}
|
||||||
|
|
||||||
|
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> { "4cm", "3cm", "2cm", "3cm", "3cm"});
|
||||||
|
|
||||||
|
CreateRow(new PdfRowParameters
|
||||||
|
{
|
||||||
|
Texts = new List<string> { "Номер закупки", "Дата выплаты", "Валюта", "Номер выплаты", "Дата закупки" },
|
||||||
|
Style = "NormalTitle",
|
||||||
|
ParagraphAlignment = PdfParagraphAlignmentType.Center
|
||||||
|
});
|
||||||
|
|
||||||
|
foreach (var purchase in info.CurrencyPurchases)
|
||||||
|
{
|
||||||
|
CreateRow(new PdfRowParameters
|
||||||
|
{
|
||||||
|
Texts = new List<string> { "Закупка №" + purchase.CurrencyPurchaseId,
|
||||||
|
purchase.PurchaseDate.ToShortDateString(), purchase.CurrencyName,
|
||||||
|
"",""},
|
||||||
|
Style = "Normal",
|
||||||
|
ParagraphAlignment = PdfParagraphAlignmentType.Left
|
||||||
|
});
|
||||||
|
foreach (var payment in purchase.Payments)
|
||||||
|
{
|
||||||
|
CreateRow(new PdfRowParameters
|
||||||
|
{
|
||||||
|
Texts = new List<string> { "", "", "", "Выплата № " + payment.PaymentId,
|
||||||
|
payment.PaymentDate.ToShortDateString() },
|
||||||
|
Style = "Normal",
|
||||||
|
ParagraphAlignment = PdfParagraphAlignmentType.Left
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return SavePdf();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Создание doc-файла
|
/// Создание doc-файла
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -18,5 +18,6 @@ namespace BankBusinessLogic.OfficePackage.HelperModels
|
|||||||
public DateTime DateTo { get; set; }
|
public DateTime DateTo { get; set; }
|
||||||
|
|
||||||
public List<ReportTransferCurrencyPurchaseViewModel>? Transfers { get; set; } = new();
|
public List<ReportTransferCurrencyPurchaseViewModel>? Transfers { get; set; } = new();
|
||||||
|
public List<ReportCurrencyPurchasePaymentViewModel>? CurrencyPurchases { get; set; } = new();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,6 @@ namespace BankContracts.ViewModels
|
|||||||
public int CurrencyPurchaseId { get; set; }
|
public int CurrencyPurchaseId { get; set; }
|
||||||
public DateTime PurchaseDate { get; set; }
|
public DateTime PurchaseDate { get; set; }
|
||||||
public string CurrencyName { get; set; }
|
public string CurrencyName { get; set; }
|
||||||
public List<(int PaymentId, string PaymentDate)> Payments { get; set; } = new();
|
public List<(int PaymentId, DateTime PaymentDate)> Payments { get; set; } = new();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ using BankContracts.BusinessLogicsContracts;
|
|||||||
using BankContracts.SearchModels;
|
using BankContracts.SearchModels;
|
||||||
using BankDataModels.Models;
|
using BankDataModels.Models;
|
||||||
using BankBusinessLogic.BusinessLogics;
|
using BankBusinessLogic.BusinessLogics;
|
||||||
|
using BankBusinessLogic.MailWorker;
|
||||||
|
|
||||||
namespace BankOperatorApp.Controllers
|
namespace BankOperatorApp.Controllers
|
||||||
{
|
{
|
||||||
@ -18,10 +19,12 @@ namespace BankOperatorApp.Controllers
|
|||||||
private readonly ICurrencyLogic _currencyLogic;
|
private readonly ICurrencyLogic _currencyLogic;
|
||||||
private readonly ICurrencyPurchaseLogic _currencyPurchaseLogic;
|
private readonly ICurrencyPurchaseLogic _currencyPurchaseLogic;
|
||||||
private readonly IReportLogic _reportLogic;
|
private readonly IReportLogic _reportLogic;
|
||||||
|
private readonly AbstractMailWorker _mailWorker;
|
||||||
|
|
||||||
|
|
||||||
public HomeController(ILogger<HomeController> logger, IBankOperatorLogic bankOperatorLogic,
|
public HomeController(ILogger<HomeController> logger, IBankOperatorLogic bankOperatorLogic,
|
||||||
ICreditProgramLogic creditProgramLogic, ICurrencyLogic currencyLogic,
|
ICreditProgramLogic creditProgramLogic, ICurrencyLogic currencyLogic,
|
||||||
ICurrencyPurchaseLogic currencyPurchaseLogic, IReportLogic reportLogic)
|
ICurrencyPurchaseLogic currencyPurchaseLogic, IReportLogic reportLogic, AbstractMailWorker mailWorker)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_bankOperatorLogic = bankOperatorLogic;
|
_bankOperatorLogic = bankOperatorLogic;
|
||||||
@ -29,6 +32,7 @@ namespace BankOperatorApp.Controllers
|
|||||||
_currencyLogic = currencyLogic;
|
_currencyLogic = currencyLogic;
|
||||||
_currencyPurchaseLogic = currencyPurchaseLogic;
|
_currencyPurchaseLogic = currencyPurchaseLogic;
|
||||||
_reportLogic = reportLogic;
|
_reportLogic = reportLogic;
|
||||||
|
_mailWorker = mailWorker;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IActionResult Index()
|
public IActionResult Index()
|
||||||
@ -286,5 +290,59 @@ namespace BankOperatorApp.Controllers
|
|||||||
"spreadsheetml.sheet", "testExcel.xlsx");
|
"spreadsheetml.sheet", "testExcel.xlsx");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public IActionResult CurrencyPurchasePaymentsReport()
|
||||||
|
{
|
||||||
|
if (APIClient.BankOperator == null)
|
||||||
|
{
|
||||||
|
Response.WriteAsync($"<script language=\"javascript\">alert" +
|
||||||
|
$"('You need to login!');window.location.replace('/Home/Enter');</script>");
|
||||||
|
return Redirect("/Home/Enter");
|
||||||
|
}
|
||||||
|
return View(new ReportBindingModel());
|
||||||
|
}
|
||||||
|
[HttpPost]
|
||||||
|
public IActionResult CurrencyPurchasePaymentsReport(DateTime dateFrom,
|
||||||
|
DateTime dateTo, string reptype, string email, string fileName)
|
||||||
|
{
|
||||||
|
if (APIClient.BankOperator == null)
|
||||||
|
{
|
||||||
|
Response.WriteAsync($"<script language=\"javascript\">" +
|
||||||
|
$"alert('You need to login!');window.location.replace('/Home/Enter');</script>");
|
||||||
|
return Redirect("/Home/Enter");
|
||||||
|
}
|
||||||
|
if (reptype.Equals("onForm"))
|
||||||
|
{
|
||||||
|
ViewBag.DateFrom = dateFrom.ToShortDateString();
|
||||||
|
ViewBag.DateTo = dateTo.ToShortDateString();
|
||||||
|
return View("ViewReport", _reportLogic.GetPurchasePayment(new ReportBindingModel { DateFrom = dateFrom, DateTo = dateTo }));
|
||||||
|
}
|
||||||
|
MemoryStream report = _reportLogic.SavePurchasePaymentToPDF(new ReportBindingModel
|
||||||
|
{ DateFrom = dateFrom, DateTo = dateTo });
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(fileName)) fileName = "report";
|
||||||
|
fileName = fileName.Replace(".", string.Empty);
|
||||||
|
if (!fileName.EndsWith(".pdf")) fileName += ".pdf";
|
||||||
|
_mailWorker.MailSendAsync(new MailSendInfoBindingModel
|
||||||
|
{
|
||||||
|
Subject = "Отчёт по закупкам",
|
||||||
|
Text = "Для оператора " + APIClient.BankOperator.LastName + APIClient.BankOperator.FirstName,
|
||||||
|
MailAddress = email,
|
||||||
|
FileName = fileName,
|
||||||
|
Attachment = report
|
||||||
|
});
|
||||||
|
Response.WriteAsync($"<script language=\"javascript\">alert" +
|
||||||
|
$"('Mail sent!');window.location.replace('/');</script>");
|
||||||
|
return Redirect("/");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Response.WriteAsync($"<script language=\"javascript\">alert('{ex.Message}');</script>");
|
||||||
|
return Redirect("/");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -6,6 +6,7 @@ using BankContracts.BindingModels;
|
|||||||
using BankOperatorApp;
|
using BankOperatorApp;
|
||||||
using BankBusinessLogic.OfficePackage.Implements;
|
using BankBusinessLogic.OfficePackage.Implements;
|
||||||
using BankBusinessLogic.OfficePackage;
|
using BankBusinessLogic.OfficePackage;
|
||||||
|
using BankBusinessLogic.MailWorker;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
@ -24,6 +25,7 @@ builder.Services.AddTransient<IPaymentStorage, PaymentStorage>();
|
|||||||
builder.Services.AddTransient<AbstractSaveToWord, SaveToWord>();
|
builder.Services.AddTransient<AbstractSaveToWord, SaveToWord>();
|
||||||
builder.Services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
|
builder.Services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
|
||||||
builder.Services.AddTransient<AbstractSaveToPdf, SaveToPdf>();
|
builder.Services.AddTransient<AbstractSaveToPdf, SaveToPdf>();
|
||||||
|
builder.Services.AddSingleton<AbstractMailWorker, MailKitWorker>();
|
||||||
|
|
||||||
|
|
||||||
builder.Services.AddTransient<ICurrencyPurchaseLogic, CurrencyPurchaseLogic>();
|
builder.Services.AddTransient<ICurrencyPurchaseLogic, CurrencyPurchaseLogic>();
|
||||||
@ -35,6 +37,24 @@ builder.Services.AddTransient<IReportLogic, ReportLogic>();
|
|||||||
builder.Services.AddControllersWithViews();
|
builder.Services.AddControllersWithViews();
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var mailSender = app.Services.GetService<AbstractMailWorker>();
|
||||||
|
mailSender?.MailConfig(new MailConfigBindingModel
|
||||||
|
{
|
||||||
|
MailLogin = builder.Configuration["MailLogin"] ?? string.Empty,
|
||||||
|
MailPassword = builder.Configuration["MailPassword"] ?? string.Empty,
|
||||||
|
SmtpClientHost = builder.Configuration["SmtpClientHost"] ?? string.Empty,
|
||||||
|
SmtpClientPort = Convert.ToInt32(builder.Configuration["SmtpClientPort"]),
|
||||||
|
PopHost = builder.Configuration["PopHost"] ?? string.Empty,
|
||||||
|
PopPort = Convert.ToInt32(builder.Configuration["PopPort"])
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
var logger = app.Services.GetService<ILogger>();
|
||||||
|
logger?.LogError(ex, "Îøèáêà ðàáîòû ñ ïî÷òîé");
|
||||||
|
}
|
||||||
|
|
||||||
// Configure the HTTP request pipeline.
|
// Configure the HTTP request pipeline.
|
||||||
if (!app.Environment.IsDevelopment())
|
if (!app.Environment.IsDevelopment())
|
||||||
|
@ -0,0 +1,48 @@
|
|||||||
|
@using BankContracts.BindingModels
|
||||||
|
@model ReportBindingModel
|
||||||
|
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "CurrencyPurchasePaymentReport";
|
||||||
|
}
|
||||||
|
<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>
|
||||||
|
<div class="row">
|
||||||
|
<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>
|
||||||
|
<h1>Вывести на:</h1>
|
||||||
|
<div class="d-flex flex-row">
|
||||||
|
<div class="col-2">На форму</div>
|
||||||
|
@Html.RadioButton("reptype", "onForm", true)
|
||||||
|
</div>
|
||||||
|
<div class="d-flex flex-row">
|
||||||
|
<div class="col-2">На почту (.pdf)</div>
|
||||||
|
@Html.RadioButton("reptype", "pdf")
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-4">email:</div>
|
||||||
|
<div class="col-8"><input type="text" name="email" id="email" /></div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-4">Имя файла (необязательно):</div>
|
||||||
|
<div class="col-8"><input type="text" name="fileName" id="fileName" /></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>
|
@ -27,8 +27,11 @@
|
|||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="CurrencyPurchases">Покупки валют</a>
|
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="CurrencyPurchases">Покупки валют</a>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="CurrencyReport">Отчет по валютам</a>
|
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="CurrencyReport">Отчет по валютам</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="CurrencyPurchasePaymentsReport">Отчет по закупкам</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Личные данные</a>
|
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Личные данные</a>
|
||||||
|
@ -5,5 +5,11 @@
|
|||||||
"Microsoft.AspNetCore": "Warning"
|
"Microsoft.AspNetCore": "Warning"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"AllowedHosts": "*"
|
"AllowedHosts": "*",
|
||||||
|
"SmtpClientHost": "smtp.gmail.com",
|
||||||
|
"SmtpClientPort": "587",
|
||||||
|
"PopHost": "pop.gmail.com",
|
||||||
|
"PopPort": "995",
|
||||||
|
"MailLogin": "rpplab7@gmail.com",
|
||||||
|
"MailPassword": "edjc dmsf pqne gxwy"
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user