Pdf Report Client
This commit is contained in:
parent
1e4ea0c6d7
commit
93e0fe9524
@ -6,6 +6,9 @@ using ElectronicsShopContracts.BusinessLogicContracts;
|
||||
using ElectronicsShopContracts.SearchModels;
|
||||
using ElectronicsShopContracts.StorageContracts;
|
||||
using ElectronicsShopContracts.ViewModels;
|
||||
using MigraDoc.DocumentObjectModel;
|
||||
using PdfSharp.Pdf;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ElectronicsShopBusinessLogic.BusinessLogic
|
||||
{
|
||||
@ -14,20 +17,49 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
|
||||
private readonly IPaymeantStorage _paymeantstorage;
|
||||
private readonly IProductStorage _productstorage;
|
||||
private readonly IOrderStorage _orderStorage;
|
||||
private readonly ICostItemStorage _costItemStorage;
|
||||
private readonly AbstractSaveToExcelClient _saveToExcel;
|
||||
private readonly AbstractSaveToWordClient _saveToWord;
|
||||
private readonly AbstractSaveToPdfClient _saveToPdf;
|
||||
|
||||
public ReportClientLogic(AbstractSaveToExcelClient abstractSaveToExcelClient, AbstractSaveToWordClient abstractSaveToWordClient,
|
||||
IPaymeantStorage paymeantStorage, IProductStorage productStorage, IOrderStorage orderStorage) {
|
||||
IPaymeantStorage paymeantStorage, IProductStorage productStorage, IOrderStorage orderStorage,
|
||||
AbstractSaveToPdfClient abstractSaveToPdfClient, ICostItemStorage costItemStorage) {
|
||||
_saveToExcel = abstractSaveToExcelClient;
|
||||
_saveToWord= abstractSaveToWordClient;
|
||||
_paymeantstorage = paymeantStorage;
|
||||
_productstorage = productStorage;
|
||||
_orderStorage = orderStorage;
|
||||
_costItemStorage = costItemStorage;
|
||||
_saveToPdf = abstractSaveToPdfClient;
|
||||
}
|
||||
|
||||
// Получение списка оплаченных товаров за период
|
||||
public List<ReportProductsViewModel>? GetProducts (ReportBindingModel model) {
|
||||
var paymeants = _paymeantstorage.GetFillteredList(new PaymeantSearchModel {
|
||||
DateFrom = model.DateFrom,
|
||||
DateTo = model.DateTo,
|
||||
});
|
||||
|
||||
List<ReportProductsViewModel>? products = new();
|
||||
|
||||
foreach (var paymeant in paymeants) {
|
||||
var order = _orderStorage.GetElement(new OrderSearchModel { ID = paymeant.OrderID });
|
||||
foreach (var product in order.ProductList) {
|
||||
products.Add(new ReportProductsViewModel {
|
||||
ID = product.Value.Item1.ID,
|
||||
ProductName = product.Value.Item1.ProductName,
|
||||
Price = product.Value.Item1.Price,
|
||||
CostItemName = _costItemStorage.GetElement(new CostItemSearchModel { ID = product.Value.Item1.CostItemID }).Name
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return products;
|
||||
}
|
||||
|
||||
// получение списка оплат за период
|
||||
public List<ReportPaymeantsViewModel> GetPaymeants(ReportBindingModel model)
|
||||
public List<ReportPaymeantsViewModel>? GetPaymeants(ReportBindingModel model)
|
||||
{
|
||||
return _paymeantstorage.GetFillteredList(new PaymeantSearchModel {
|
||||
DateFrom = model.DateFrom,
|
||||
@ -73,7 +105,7 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
|
||||
return list;
|
||||
}
|
||||
|
||||
public byte[] SavePaymeantToExcelFile(int _clientID)
|
||||
public byte[]? SavePaymeantToExcelFile(int _clientID)
|
||||
{
|
||||
var document = _saveToExcel.CreateReport(new ExcelInfoClient
|
||||
{
|
||||
@ -83,13 +115,24 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
|
||||
return document;
|
||||
}
|
||||
|
||||
public byte[] SavePaymeantToWordFile(int _clientID)
|
||||
public byte[]? SavePaymeantToWordFile(int _clientID)
|
||||
{
|
||||
var document = _saveToWord.CreateDoc(new WordInfoClient {
|
||||
Title = "Список оплат",
|
||||
Title = "Список оплат и товаров",
|
||||
ListPaymeant = _paymeantstorage.GetFillteredList(new PaymeantSearchModel { ClientID = _clientID }),
|
||||
});
|
||||
return document;
|
||||
}
|
||||
|
||||
public PdfDocument SaveProductToPdfFile(ReportBindingModel model) {
|
||||
var document = _saveToPdf.CreteDoc(new PdfInfoClient {
|
||||
Title = "Список оплаченных товаров",
|
||||
FileName = "Report",
|
||||
DateFrom = model.DateFrom,
|
||||
DateTo = model.DateTo,
|
||||
Products = GetProducts(model)
|
||||
});
|
||||
return document;
|
||||
}
|
||||
}
|
||||
}
|
@ -12,6 +12,7 @@
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
|
||||
<PackageReference Include="MigraDocCore.DocumentObjectModel" Version="1.3.63" />
|
||||
<PackageReference Include="MigraDocCore.Rendering" Version="1.3.63" />
|
||||
<PackageReference Include="PdfSharp.MigraDoc.Standard" Version="1.51.15" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -10,12 +10,14 @@ using System.Threading.Tasks;
|
||||
using ElectronicsShopContracts.BindingModels;
|
||||
using MailKit.Net.Pop3;
|
||||
using MailKit.Security;
|
||||
using MigraDoc.DocumentObjectModel;
|
||||
|
||||
namespace ElectronicsShopBusinessLogic.MailWorker
|
||||
{
|
||||
public class MailKitWorker : AbstractMailWorker
|
||||
{
|
||||
public MailKitWorker(ILogger<MailKitWorker> logger, IMessageInfoLogic messageInfoLogic, IClientLogic clientLogic) : base(logger, messageInfoLogic, clientLogic) { }
|
||||
public MailKitWorker(ILogger<MailKitWorker> logger, IMessageInfoLogic messageInfoLogic,
|
||||
IClientLogic clientLogic) : base(logger, messageInfoLogic, clientLogic) { }
|
||||
|
||||
protected override async Task SendMailAsync(MailSendInfoBindingModel info)
|
||||
{
|
||||
@ -27,6 +29,12 @@ namespace ElectronicsShopBusinessLogic.MailWorker
|
||||
objMailMessage.To.Add(new MailAddress(info.MailAddress));
|
||||
objMailMessage.Subject = info.Subject;
|
||||
objMailMessage.Body = info.Text;
|
||||
|
||||
Attachment attachment = new Attachment(new MemoryStream(info.document), name: "Report.pdf");
|
||||
if (attachment != null) {
|
||||
objMailMessage.Attachments.Add(attachment);
|
||||
}
|
||||
|
||||
objMailMessage.SubjectEncoding = Encoding.UTF8;
|
||||
objMailMessage.BodyEncoding = Encoding.UTF8;
|
||||
|
||||
|
@ -0,0 +1,65 @@
|
||||
using ElectronicsShopBusinessLogic.OfficePackage.HelperEnums;
|
||||
using ElectronicsShopBusinessLogic.OfficePackage.HelperModels;
|
||||
using MigraDoc.DocumentObjectModel;
|
||||
using PdfSharp.Pdf;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ElectronicsShopBusinessLogic.OfficePackage
|
||||
{
|
||||
public abstract class AbstractSaveToPdfClient {
|
||||
public PdfDocument CreteDoc (PdfInfoClient info) {
|
||||
CretePdf(info);
|
||||
|
||||
CreateParagraph(new PdfParagraph {
|
||||
Text = info.Title,
|
||||
Style = "NormalTitle",
|
||||
alignmentType = PdfParagraphAlignmentType.Center,
|
||||
});
|
||||
CreateParagraph(new PdfParagraph {
|
||||
Text = $"c {info.DateFrom.ToShortDateString()} по {info.DateTo.ToShortDateString()}",
|
||||
Style = "Normal",
|
||||
alignmentType = PdfParagraphAlignmentType.Right
|
||||
});
|
||||
|
||||
CreateTable(new List<string> { "2cm", "6cm", "4cm", "6cm"});
|
||||
|
||||
CreateRow(new PdfRowParameters {
|
||||
Text = new List<string> { "Номер", "Товар", "Цена", "Статья затрат" },
|
||||
Style = "NormalTittle",
|
||||
alignmentType = PdfParagraphAlignmentType.Center,
|
||||
});
|
||||
|
||||
foreach (var products in info.Products) {
|
||||
CreateRow(new PdfRowParameters {
|
||||
Text = new List<string> { products.ID.ToString(), products.ProductName.ToString(), products.Price.ToString(),
|
||||
products.CostItemName.ToString()},
|
||||
Style = "Normal",
|
||||
alignmentType = PdfParagraphAlignmentType.Left,
|
||||
});
|
||||
}
|
||||
CreateParagraph(new PdfParagraph {
|
||||
Text = $"Итого: {info.Products.Sum(x => x.Price)}\t",
|
||||
Style = "Normal",
|
||||
alignmentType = PdfParagraphAlignmentType.Right
|
||||
});
|
||||
|
||||
var document = SavePdf(info);
|
||||
return document;
|
||||
}
|
||||
|
||||
// Создание doc-файла
|
||||
protected abstract void CretePdf (PdfInfoClient info);
|
||||
// Создание параграфа с текстом
|
||||
protected abstract void CreateParagraph(PdfParagraph paragraph);
|
||||
// Создание таблицы
|
||||
protected abstract void CreateTable(List<string> columns);
|
||||
// Создание и заполнение строки
|
||||
protected abstract void CreateRow(PdfRowParameters rowParameters);
|
||||
// Сохранение файла
|
||||
protected abstract PdfDocument SavePdf(PdfInfoClient info);
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ElectronicsShopBusinessLogic.OfficePackage.HelperEnums {
|
||||
public enum PdfParagraphAlignmentType {
|
||||
Center,
|
||||
Left,
|
||||
Right,
|
||||
}
|
||||
}
|
@ -4,7 +4,6 @@ namespace ElectronicsShopBusinessLogic.OfficePackage.HelperModels
|
||||
{
|
||||
public class ExcelInfoClient
|
||||
{
|
||||
public string FileName { get; set; } = string.Empty;
|
||||
public string Title { get; set; } = string.Empty;
|
||||
public List<ReportPaymeantProductsViewModel> PaymeantProducts { get; set; } = new();
|
||||
}
|
||||
|
@ -0,0 +1,16 @@
|
||||
using ElectronicsShopContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ElectronicsShopBusinessLogic.OfficePackage.HelperModels {
|
||||
public class PdfInfoClient {
|
||||
public string FileName { get; set; } = string.Empty;
|
||||
public string Title { get; set; } = string.Empty;
|
||||
public DateTime DateFrom { get; set; }
|
||||
public DateTime DateTo { get; set; }
|
||||
public List<ReportProductsViewModel>? Products { get; set; } = new();
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
using ElectronicsShopBusinessLogic.OfficePackage.HelperEnums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ElectronicsShopBusinessLogic.OfficePackage.HelperModels {
|
||||
public class PdfParagraph {
|
||||
public string Text { get; set; } = string.Empty;
|
||||
public string Style { get; set; } = string.Empty;
|
||||
public PdfParagraphAlignmentType alignmentType { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
using ElectronicsShopBusinessLogic.OfficePackage.HelperEnums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ElectronicsShopBusinessLogic.OfficePackage.HelperModels {
|
||||
public class PdfRowParameters {
|
||||
public List<string> Text { get; set; } = new();
|
||||
public string Style { get; set; } = string.Empty;
|
||||
public PdfParagraphAlignmentType alignmentType { get; set; }
|
||||
}
|
||||
}
|
@ -5,10 +5,7 @@ namespace ElectronicsShopBusinessLogic.OfficePackage.HelperModels
|
||||
{
|
||||
public class WordInfoClient
|
||||
{
|
||||
public string FileName { get; set; } = string.Empty;
|
||||
|
||||
public string Title { get; set; } = string.Empty;
|
||||
|
||||
public List<PaymeantViewModel> ListPaymeant { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -286,4 +286,4 @@ namespace ElectronicsShopBusinessLogic.OfficePackage.Implements
|
||||
return _mem.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,98 @@
|
||||
using DocumentFormat.OpenXml.Bibliography;
|
||||
using ElectronicsShopBusinessLogic.OfficePackage.HelperEnums;
|
||||
using ElectronicsShopBusinessLogic.OfficePackage.HelperModels;
|
||||
using MigraDoc.DocumentObjectModel;
|
||||
using MigraDoc.DocumentObjectModel.Tables;
|
||||
using MigraDoc.Rendering;
|
||||
using PdfSharp.Pdf;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ElectronicsShopBusinessLogic.OfficePackage.Implements {
|
||||
public class SaveToPdfClient : AbstractSaveToPdfClient {
|
||||
|
||||
private Document? _document;
|
||||
private Section? _section;
|
||||
private Table? _table;
|
||||
|
||||
// Типы выравнивания
|
||||
private static ParagraphAlignment GetParagraphAlignment(PdfParagraphAlignmentType type) {
|
||||
return type switch {
|
||||
PdfParagraphAlignmentType.Center => ParagraphAlignment.Center,
|
||||
PdfParagraphAlignmentType.Left => ParagraphAlignment.Left,
|
||||
PdfParagraphAlignmentType.Right => ParagraphAlignment.Right,
|
||||
_ => ParagraphAlignment.Justify
|
||||
};
|
||||
}
|
||||
|
||||
// Создание стилей для документа
|
||||
private static void DefineStyles(Document document) {
|
||||
var style = document.Styles["Normal"];
|
||||
style.Font.Name = "Times New Roman";
|
||||
style.Font.Size = 14;
|
||||
style = document.Styles.AddStyle("NormalTitle", "Normal");
|
||||
style.Font.Bold = true;
|
||||
}
|
||||
|
||||
protected override void CreateParagraph(PdfParagraph pdfParagraph) {
|
||||
if (_section == null) {
|
||||
return;
|
||||
}
|
||||
var paragraph = _section.AddParagraph(pdfParagraph.Text);
|
||||
paragraph.Format.SpaceAfter = "1cm";
|
||||
paragraph.Format.Alignment = GetParagraphAlignment(pdfParagraph.alignmentType);
|
||||
paragraph.Style = pdfParagraph.Style;
|
||||
}
|
||||
|
||||
protected override void CreateRow(PdfRowParameters rowParameters) {
|
||||
if (_table == null) {
|
||||
return;
|
||||
}
|
||||
var row = _table.AddRow();
|
||||
for (int i = 0; i < rowParameters.Text.Count; ++i) {
|
||||
// заполнение ячейки (добавление параграфа в ячейку)
|
||||
row.Cells[i].AddParagraph(rowParameters.Text[i]);
|
||||
if (!string.IsNullOrEmpty(rowParameters.Style)) {
|
||||
row.Cells[i].Style = rowParameters.Style;
|
||||
}
|
||||
Unit borderWidth = 0.5;
|
||||
row.Cells[i].Borders.Left.Width = borderWidth;
|
||||
row.Cells[i].Borders.Right.Width = borderWidth;
|
||||
row.Cells[i].Borders.Top.Width = borderWidth;
|
||||
row.Cells[i].Borders.Bottom.Width = borderWidth;
|
||||
|
||||
row.Cells[i].Format.Alignment = GetParagraphAlignment(rowParameters.alignmentType);
|
||||
row.Cells[i].VerticalAlignment = VerticalAlignment.Center;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void CreateTable(List<string> columns) {
|
||||
if (_document == null) {
|
||||
return;
|
||||
}
|
||||
_table = _document.LastSection.AddTable();
|
||||
foreach (var elem in columns) {
|
||||
_table.AddColumn(elem);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void CretePdf(PdfInfoClient info) {
|
||||
_document = new Document();
|
||||
DefineStyles(_document);
|
||||
// Ссылка нп первую секцию
|
||||
_section = _document.AddSection();
|
||||
}
|
||||
|
||||
protected override PdfDocument SavePdf(PdfInfoClient info) {
|
||||
var renderer = new PdfDocumentRenderer(true) {
|
||||
Document = _document,
|
||||
};
|
||||
renderer.RenderDocument();
|
||||
renderer.PdfDocument.Save(info.FileName);
|
||||
return renderer.PdfDocument;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using MigraDoc.DocumentObjectModel;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@ -11,5 +12,6 @@ namespace ElectronicsShopContracts.BindingModels
|
||||
public string MailAddress { get; set; } = string.Empty;
|
||||
public string Subject { get; set; } = string.Empty;
|
||||
public string Text { get; set; } = string.Empty;
|
||||
public byte[]? document { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -10,8 +10,8 @@ namespace ElectronicsShopContracts.BindingModels
|
||||
{
|
||||
public class ReportBindingModel
|
||||
{
|
||||
public string FileName { get; set; } = string.Empty;
|
||||
public DateTime? DateFrom { get; set; }
|
||||
public DateTime? DateTo { get; set; }
|
||||
public string ClientEmail { get; set; } = string.Empty;
|
||||
public DateTime DateFrom { get; set; }
|
||||
public DateTime DateTo { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
using DocumentFormat.OpenXml.Packaging;
|
||||
using ElectronicsShopContracts.BindingModels;
|
||||
using ElectronicsShopContracts.BindingModels;
|
||||
using ElectronicsShopContracts.ViewModels;
|
||||
using MigraDoc.DocumentObjectModel;
|
||||
using PdfSharp.Pdf;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -12,12 +13,17 @@ namespace ElectronicsShopContracts.BusinessLogicContracts
|
||||
public interface IReportClientLogic
|
||||
{
|
||||
// получение списка товаров с указанием, в какие оплаты товар входит
|
||||
List<ReportPaymeantProductsViewModel> GetPaymeantProducts(int _clientID);
|
||||
List<ReportPaymeantProductsViewModel>? GetPaymeantProducts(int _clientID);
|
||||
// получения списка оплат
|
||||
List<ReportPaymeantsViewModel> GetPaymeants(ReportBindingModel model);
|
||||
byte[] SavePaymeantToWordFile(int _clientID);
|
||||
List<ReportPaymeantsViewModel>? GetPaymeants(ReportBindingModel model);
|
||||
|
||||
// Сохранение компонент с указанием отчета в .excel
|
||||
byte[] SavePaymeantToExcelFile(int _clientID);
|
||||
// Сохранение отчета оплат в .word
|
||||
byte[]? SavePaymeantToWordFile(int _clientID);
|
||||
|
||||
// Сохранение отчета оплат с товарами в .excel
|
||||
byte[]? SavePaymeantToExcelFile(int _clientID);
|
||||
|
||||
// Отчет оплаченных товаров в .pdf
|
||||
PdfDocument SaveProductToPdfFile(ReportBindingModel model);
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="DocumentFormat.OpenXml" Version="3.0.2" />
|
||||
<PackageReference Include="PdfSharp.MigraDoc.Standard" Version="1.51.15" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -9,7 +9,9 @@ namespace ElectronicsShopContracts.ViewModels
|
||||
{
|
||||
public class ReportProductsViewModel
|
||||
{
|
||||
public int ID { get; set; }
|
||||
public string ProductName { get; set; } = string.Empty;
|
||||
public List<ProductViewModel> Products { get; set; } = new();
|
||||
public double Price { get; set; }
|
||||
public string CostItemName { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,14 @@
|
||||
using DocumentFormat.OpenXml.Drawing.Diagrams;
|
||||
using DocumentFormat.OpenXml.Packaging;
|
||||
using ElectronicsShopBusinessLogic.BusinessLogic;
|
||||
using ElectronicsShopBusinessLogic.MailWorker;
|
||||
using ElectronicsShopContracts.BindingModels;
|
||||
using ElectronicsShopContracts.BusinessLogicContracts;
|
||||
using ElectronicsShopContracts.SearchModels;
|
||||
using ElectronicsShopContracts.ViewModels;
|
||||
using ElectronicsShopDataBaseImplement.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using MigraDoc.Rendering;
|
||||
|
||||
namespace ElectronicsShopRestAPI.Controllers {
|
||||
|
||||
@ -17,12 +21,15 @@ namespace ElectronicsShopRestAPI.Controllers {
|
||||
private readonly IClientLogic _logic;
|
||||
private readonly IPaymeantLogic _payLogic;
|
||||
private readonly IReportClientLogic _reportLogic;
|
||||
private readonly AbstractMailWorker _mailWorker;
|
||||
|
||||
public ClientController(ILogger<ClientController> logger, IClientLogic logic, IPaymeantLogic payLogic, IReportClientLogic reportlogic) {
|
||||
public ClientController(ILogger<ClientController> logger, IClientLogic logic, IPaymeantLogic payLogic, IReportClientLogic reportlogic,
|
||||
AbstractMailWorker mailWorker) {
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
_payLogic = payLogic;
|
||||
_reportLogic = reportlogic;
|
||||
_mailWorker = mailWorker;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
@ -81,11 +88,11 @@ namespace ElectronicsShopRestAPI.Controllers {
|
||||
}
|
||||
}
|
||||
[HttpGet]
|
||||
public List<ReportPaymeantsViewModel>? GetReport(DateTime _start, DateTime _end) {
|
||||
public List<ReportPaymeantsViewModel>? GetReport(string _start,string _end) {
|
||||
try {
|
||||
var dataSource = _reportLogic.GetPaymeants(new ReportBindingModel {
|
||||
DateFrom = _start,
|
||||
DateTo = _end
|
||||
DateFrom = DateTime.Parse(_start),
|
||||
DateTo = DateTime.Parse(_end)
|
||||
});
|
||||
return dataSource;
|
||||
}
|
||||
@ -118,5 +125,31 @@ namespace ElectronicsShopRestAPI.Controllers {
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void SendReportMail (ReportBindingModel model) {
|
||||
try {
|
||||
|
||||
var doc = _reportLogic.SaveProductToPdfFile(model);
|
||||
|
||||
MemoryStream stream = new MemoryStream();
|
||||
doc.Save(stream, true);
|
||||
byte[] data = stream.ToArray();
|
||||
|
||||
|
||||
_mailWorker.MailSendAsync(new() {
|
||||
MailAddress = model.ClientEmail,
|
||||
Subject = "Отчет",
|
||||
Text = $"Отчет оплаченных товаров с {model.DateFrom} по {model.DateTo}",
|
||||
document = data
|
||||
});
|
||||
|
||||
}
|
||||
catch (Exception ex) {
|
||||
_logger.LogError(ex, $"Ошибка создания файла");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ builder.Services.AddTransient<AbstractSaveToExcelClient, SaveToExcelClient>();
|
||||
builder.Services.AddTransient<AbstractSaveToExcelEmployee, SaveToExcelEmployee>();
|
||||
builder.Services.AddTransient<AbstractSaveToWordClient, SaveToWordClient>();
|
||||
builder.Services.AddTransient<AbstractSaveToWordEmployee, SaveToWordEmployee>();
|
||||
builder.Services.AddTransient<AbstractSaveToPdfClient, SaveToPdfClient>();
|
||||
|
||||
builder.Services.AddTransient<IClientLogic, ClientLogic>();
|
||||
builder.Services.AddTransient<IEmployeeLogic, EmployeeLogic>();
|
||||
|
BIN
ElectronicsShop/ElectronicsShopRestAPI/Report
Normal file
BIN
ElectronicsShop/ElectronicsShopRestAPI/Report
Normal file
Binary file not shown.
Binary file not shown.
@ -9,6 +9,7 @@ using ElectronicsShopUserApp.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Newtonsoft.Json;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Net.Mime;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Serialization;
|
||||
@ -18,7 +19,7 @@ using System.Xml.Serialization;
|
||||
namespace ElectronicsShopUserApp.Controllers {
|
||||
public class HomeController : Controller {
|
||||
private readonly ILogger<HomeController> _logger;
|
||||
private Dictionary<int, (IProductModel, int)> _productList;
|
||||
private Dictionary<int, (IProductModel, int)> _productList;
|
||||
public int Id;
|
||||
|
||||
public HomeController(ILogger<HomeController> logger) {
|
||||
@ -28,10 +29,10 @@ namespace ElectronicsShopUserApp.Controllers {
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Index() {
|
||||
if (APIClient.Client == null) {
|
||||
if (APIClient.Client == null) {
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return View(APIClient.GetRequset<List<PaymeantViewModel>>($"api/client/getpaymeants?_clientid={APIClient.Client.ID}"));
|
||||
}
|
||||
return View(APIClient.GetRequset<List<PaymeantViewModel>>($"api/client/getpaymeants?_clientid={APIClient.Client.ID}"));
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
@ -63,7 +64,7 @@ namespace ElectronicsShopUserApp.Controllers {
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
|
||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||
public IActionResult Error() {
|
||||
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
||||
}
|
||||
@ -73,7 +74,7 @@ namespace ElectronicsShopUserApp.Controllers {
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[HttpPost]
|
||||
public void Enter(string email, string password) {
|
||||
if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password)) {
|
||||
throw new Exception("Ââåäèòå ïî÷òó è ïàðîëü");
|
||||
@ -110,7 +111,7 @@ namespace ElectronicsShopUserApp.Controllers {
|
||||
|
||||
var view = APIClient.GetRequset<List<OrderViewModel>>($"api/main/getorders?_clientid={APIClient.Client.ID}");
|
||||
|
||||
return View(view);
|
||||
return View(view);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
@ -123,45 +124,45 @@ namespace ElectronicsShopUserApp.Controllers {
|
||||
DateCreate = DateTime.Now,
|
||||
});
|
||||
return RedirectToAction("OrderView");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult DeleteOrder(int id) {
|
||||
APIClient.PostRequest($"api/main/deleteorders", new OrderBindingModel { ID = id });
|
||||
APIClient.PostRequest($"api/main/deleteorders", new OrderBindingModel { ID = id });
|
||||
return RedirectToAction("Orders");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult EditOrder(int id) {
|
||||
if (APIClient.Client == null) {
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
if (APIClient.Client == null) {
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
|
||||
if (id == 0) {
|
||||
return RedirectToAction("Orders");
|
||||
}
|
||||
var products = APIClient.GetRequset<List<List<string>>>($"api/main/getorderproducts?_orderid={id}");
|
||||
var products = APIClient.GetRequset<List<List<string>>>($"api/main/getorderproducts?_orderid={id}");
|
||||
|
||||
foreach (var pr in products) {
|
||||
var product = JsonConvert.DeserializeObject<ProductViewModel>(pr[0]);
|
||||
int count = JsonConvert.DeserializeObject<int>(pr[1]);
|
||||
_productList.Add(product.ID, (product, count));
|
||||
}
|
||||
foreach (var pr in products) {
|
||||
var product = JsonConvert.DeserializeObject<ProductViewModel>(pr[0]);
|
||||
int count = JsonConvert.DeserializeObject<int>(pr[1]);
|
||||
_productList.Add(product.ID, (product, count));
|
||||
}
|
||||
|
||||
(int, Dictionary<int, (IProductModel, int)>) tuple = (id, _productList);
|
||||
return View(tuple);
|
||||
}
|
||||
(int, Dictionary<int, (IProductModel, int)>) tuple = (id, _productList);
|
||||
return View(tuple);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void EditOrder(double sum, int id) {
|
||||
if (sum <= 0) {
|
||||
APIClient.PostRequest($"api/main/deleteorders", new OrderBindingModel { ID = id });
|
||||
}
|
||||
public void EditOrder(double sum, int id) {
|
||||
if (sum <= 0) {
|
||||
APIClient.PostRequest($"api/main/deleteorders", new OrderBindingModel { ID = id });
|
||||
}
|
||||
|
||||
Response.Redirect("Orders");
|
||||
}
|
||||
Response.Redirect("Orders");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[HttpGet]
|
||||
public IActionResult OrderView() {
|
||||
if (APIClient.Client == null) {
|
||||
return Redirect("~/Home/Enter");
|
||||
@ -174,10 +175,10 @@ namespace ElectronicsShopUserApp.Controllers {
|
||||
var products = APIClient.GetRequset<List<List<string>>>($"api/main/getorderproducts?_orderid={view?.ID}");
|
||||
|
||||
foreach (var pr in products) {
|
||||
var product = JsonConvert.DeserializeObject<ProductViewModel>(pr[0]);
|
||||
var product = JsonConvert.DeserializeObject<ProductViewModel>(pr[0]);
|
||||
int count = JsonConvert.DeserializeObject<int>(pr[1]);
|
||||
_productList.Add(product.ID, (product, count));
|
||||
}
|
||||
}
|
||||
|
||||
(int, Dictionary<int, (IProductModel, int)>) tuple = (Id, _productList);
|
||||
return View(tuple);
|
||||
@ -186,71 +187,66 @@ namespace ElectronicsShopUserApp.Controllers {
|
||||
[HttpPost]
|
||||
public void OrderView(double sum, int id) {
|
||||
if (sum <= 0) {
|
||||
APIClient.PostRequest($"api/main/deleteorders", new OrderBindingModel { ID = id});
|
||||
APIClient.PostRequest($"api/main/deleteorders", new OrderBindingModel { ID = id });
|
||||
}
|
||||
Response.Redirect("Orders");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult DeleteProductOrder(int id) {
|
||||
var view = APIClient.GetRequset<OrderViewModel>($"api/main/getorder?_clientid={APIClient.Client?.ID}");
|
||||
APIClient.PostRequestStr($"api/main/deleteproductorder", view.ID, id);
|
||||
var view = APIClient.GetRequset<OrderViewModel>($"api/main/getorder?_clientid={APIClient.Client?.ID}");
|
||||
APIClient.PostRequestStr($"api/main/deleteproductorder", view.ID, id);
|
||||
|
||||
return RedirectToAction("OrderView");
|
||||
return RedirectToAction("OrderView");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[HttpGet]
|
||||
public IActionResult AddProduct() {
|
||||
ViewBag.Products = APIClient.GetRequset<List<ProductViewModel>>($"api/main/getproducts");
|
||||
return View();
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[HttpPost]
|
||||
public void AddProduct(int product, int count) {
|
||||
var _product = APIClient.GetRequset<ProductViewModel>($"api/main/getproduct?_productid={product}");
|
||||
var _order = APIClient.GetRequset<OrderViewModel>($"api/main/getorder?_clientid={APIClient.Client?.ID}");
|
||||
|
||||
APIClient.ListPostRequest($"api/main/addproduct", _product, count, _order.ID);
|
||||
Response.Redirect("OrderView");
|
||||
}
|
||||
APIClient.ListPostRequest($"api/main/addproduct", _product, count, _order.ID);
|
||||
Response.Redirect("OrderView");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Message()
|
||||
{
|
||||
public IActionResult Message() {
|
||||
//ViewBag.Reports = APIClient.GetRequset<List<ProductViewModel>>($"api/main/getproducts"); Ïèñåì òàê æå ïîêà íåìà
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Payment(int id)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
public IActionResult Payment(int id) {
|
||||
if (APIClient.Client == null) {
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
|
||||
if (id == 0)
|
||||
{
|
||||
if (id == 0) {
|
||||
return Redirect("~/Home/Index");
|
||||
}
|
||||
var products = APIClient.GetRequset<List<List<string>>>($"api/main/getorderproducts?_orderid={id}");
|
||||
}
|
||||
var products = APIClient.GetRequset<List<List<string>>>($"api/main/getorderproducts?_orderid={id}");
|
||||
|
||||
foreach (var pr in products)
|
||||
{
|
||||
var product = JsonConvert.DeserializeObject<ProductViewModel>(pr[0]);
|
||||
int count = JsonConvert.DeserializeObject<int>(pr[1]);
|
||||
_productList.Add(product.ID, (product, count));
|
||||
}
|
||||
foreach (var pr in products) {
|
||||
var product = JsonConvert.DeserializeObject<ProductViewModel>(pr[0]);
|
||||
int count = JsonConvert.DeserializeObject<int>(pr[1]);
|
||||
_productList.Add(product.ID, (product, count));
|
||||
}
|
||||
|
||||
(int, Dictionary<int, (IProductModel, int)>) tuple = (id, _productList);
|
||||
return View(tuple);
|
||||
}
|
||||
(int, Dictionary<int, (IProductModel, int)>) tuple = (id, _productList);
|
||||
return View(tuple);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Payment(double sum, double paysum, int id) {
|
||||
if (APIClient.Client == null) {
|
||||
throw new Exception("Òîëüêî äëÿ àâòîðèçîâàííûõ");
|
||||
}
|
||||
if (APIClient.Client == null) {
|
||||
throw new Exception("Òîëüêî äëÿ àâòîðèçîâàííûõ");
|
||||
}
|
||||
if (paysum <= 0) {
|
||||
throw new Exception("Ñóììà îïïëàòû äîëæíà áûòü áîëüøå 0");
|
||||
}
|
||||
@ -265,7 +261,7 @@ namespace ElectronicsShopUserApp.Controllers {
|
||||
DatePaymeant = DateTime.Now,
|
||||
});
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public PaymeantOption PayOptionCalc(double sum, double paysum) {
|
||||
@ -280,10 +276,10 @@ namespace ElectronicsShopUserApp.Controllers {
|
||||
}
|
||||
}
|
||||
[HttpPost]
|
||||
public double Calc(int count, int product) {
|
||||
var _product = APIClient.GetRequset<ProductViewModel>($"api/main/getproduct?_productid={product}");
|
||||
return count * (_product?.Price ?? 1);
|
||||
}
|
||||
public double Calc(int count, int product) {
|
||||
var _product = APIClient.GetRequset<ProductViewModel>($"api/main/getproduct?_productid={product}");
|
||||
return count * (_product?.Price ?? 1);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Report() {
|
||||
@ -295,31 +291,32 @@ namespace ElectronicsShopUserApp.Controllers {
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Report(DateTime DateFrom, DateTime DateTo) {
|
||||
public void Report(DateTime DateFrom, DateTime DateTo){
|
||||
if (DateTo == DateTime.MinValue || DateFrom > DateTo) {
|
||||
throw new Exception("Íåêîðåêòíî óêàçàí âðåìåííîé èíòåðâàë");
|
||||
}
|
||||
Response.Redirect($"ReportSearch?_datefrom={DateFrom}&_dateTo={DateTo}");
|
||||
Response.Redirect($"ReportSearch?_datefrom={DateFrom}&_dateto={DateTo}");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult ReportSearch(DateTime _datefrom, DateTime _dateto) {
|
||||
public IActionResult ReportSearch(string _datefrom, string _dateto) {
|
||||
|
||||
var reports = APIClient.GetRequset<List<PaymeantViewModel>>($"api/client/getreport?_start={_datefrom}&_end={_dateto}");
|
||||
|
||||
(DateTime, DateTime, List<PaymeantViewModel>) tuple = (_datefrom, _dateto, reports);
|
||||
(DateTime, DateTime, List<PaymeantViewModel>?) tuple = (DateTime.Parse(_datefrom), DateTime.Parse(_dateto), reports);
|
||||
return View(tuple);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult CreateExcelReport() {
|
||||
var fileMemStream = APIClient.GetRequset<byte[]>($"api/Client/CreateXlsxReport?_clientID={APIClient.Client.ID}");
|
||||
var fileMemStream = APIClient.GetRequset<byte[]>($"api/Client/CreateXlsxReport?_clientID={APIClient.Client.ID}");
|
||||
|
||||
if (fileMemStream == null) {
|
||||
throw new Exception("Îøèáêà ñîçäàíèÿ îò÷åòà");
|
||||
}
|
||||
|
||||
return File(fileMemStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "Report.xlsx");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult CreateWordReport() {
|
||||
@ -331,5 +328,15 @@ namespace ElectronicsShopUserApp.Controllers {
|
||||
|
||||
return File(fileMemStream, "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "Report.docx");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult CreatePdfReport(string DateFrom, string DateTo) {
|
||||
APIClient.PostRequest("api/client/SendReportMail", new ReportBindingModel {
|
||||
ClientEmail = APIClient.Client.Email,
|
||||
DateFrom = DateTime.Parse(DateFrom),
|
||||
DateTo = DateTime.Parse(DateTo)
|
||||
});
|
||||
return View("Report");
|
||||
}
|
||||
}
|
||||
}
|
@ -27,7 +27,8 @@
|
||||
<div class="col-8">
|
||||
<a class="btn btn-primary btn-sm" asp-action="CreateWordReport" style="background-color:#335a95;">Экспорт отчета в .xlsx</a>
|
||||
<a class="btn btn-primary btn-sm" asp-action="CreateExcelReport" style="background-color:#04713A;">Экспорт отчета в .docx</a>
|
||||
<a class="btn btn-primary btn-sm" asp-action="CreatePdfReport" style="background-color:#ad0d09;">отправить на Email отчет в .pdf</a>
|
||||
<a class="btn btn-primary btn-sm" asp-action="CreatePdfReport" asp-route-DateFrom="@Model.Item1"
|
||||
asp-route-DateTo="@Model.Item2" style="background-color:#ad0d09;">отправить на Email отчет в .pdf</a>
|
||||
</div>
|
||||
</h1>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user