pdf 3
This commit is contained in:
parent
343788051b
commit
93037d38db
@ -20,16 +20,18 @@ namespace ComputerShopBusinessLogic.BusinessLogics
|
||||
private readonly ISupplyStorage _supplyStorage;
|
||||
private readonly IAssemblyStorage _assemblyStorage;
|
||||
private readonly IEquipmentReceivingStorage _receivingStorage;
|
||||
private readonly IPurchaseStorage _purchaseStorage;
|
||||
private readonly AbstractSaveToExcel _saveToExcel;
|
||||
private readonly AbstractSaveToWord _saveToWord;
|
||||
private readonly AbstractSaveToPdf _saveToPdf;
|
||||
|
||||
public ReportLogic(IComponentStorage componentStorage, IAssemblyStorage assemblyStorage, IEquipmentReceivingStorage receivingStorage, ISupplyStorage supplyStorage, AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf)
|
||||
public ReportLogic(IComponentStorage componentStorage, IAssemblyStorage assemblyStorage, IEquipmentReceivingStorage receivingStorage, ISupplyStorage supplyStorage, IPurchaseStorage purchaseStorage, AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf)
|
||||
{
|
||||
_componentStorage = componentStorage;
|
||||
_assemblyStorage = assemblyStorage;
|
||||
_receivingStorage = receivingStorage;
|
||||
_supplyStorage = supplyStorage;
|
||||
_purchaseStorage = purchaseStorage;
|
||||
_saveToExcel = saveToExcel;
|
||||
_saveToWord = saveToWord;
|
||||
_saveToPdf = saveToPdf;
|
||||
@ -87,6 +89,32 @@ namespace ComputerShopBusinessLogic.BusinessLogics
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<ReportPurchaseSupplyViewModel> GetPurchaseSupply(ReportBindingModel model)
|
||||
{
|
||||
var result = new List<ReportPurchaseSupplyViewModel>();
|
||||
var purchases = _purchaseStorage.GetFilteredList(new()
|
||||
{
|
||||
DateFrom = model.DateFrom,
|
||||
DateTo = model.DateTo
|
||||
});
|
||||
foreach(var purchase in purchases)
|
||||
{
|
||||
var supplies = _supplyStorage.GetFilteredList(new()
|
||||
{
|
||||
ComponentId = purchase.ComponentId
|
||||
});
|
||||
foreach( var supply in supplies)
|
||||
{
|
||||
result.Add(new()
|
||||
{
|
||||
Purchase = purchase,
|
||||
Supply = supply
|
||||
});
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void SaveReceivingComponentsToWordFile(ReportBindingModel model)
|
||||
{
|
||||
if (model.Ids != null)
|
||||
@ -120,7 +148,14 @@ namespace ComputerShopBusinessLogic.BusinessLogics
|
||||
{
|
||||
throw new ArgumentException("Дата окончания не задана");
|
||||
}
|
||||
|
||||
_saveToPdf.CreateDoc(new PdfInfoProvider
|
||||
{
|
||||
FileName = model.FileName,
|
||||
Title = "Связанные закупки и поставки",
|
||||
SupplyPurchases = GetPurchaseSupply(model),
|
||||
DateFrom = model.DateFrom,
|
||||
DateTo = model.DateTo
|
||||
});
|
||||
}
|
||||
|
||||
public List<ReportPurchaseReceivingViewModel> GetPurchaseReceiving()
|
||||
@ -128,11 +163,6 @@ namespace ComputerShopBusinessLogic.BusinessLogics
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public List<ReportPurchaseSupplyViewModel> GetPurchaseSupply()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void SaveOrdersToPdfFile(ReportBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
|
@ -21,7 +21,7 @@ namespace ComputerShopBusinessLogic.OfficePackage
|
||||
});
|
||||
CreateParagraph(new PdfParagraph
|
||||
{
|
||||
Text = $"с {info.DateFrom.ToShortDateString()} по {info.DateTo.ToShortDateString()}",
|
||||
Text = $"с {info.DateFrom.ToString()} по {info.DateTo.ToString()}",
|
||||
Style = "Normal",
|
||||
ParagraphAlignment = PdfParagraphAlignmentType.Center
|
||||
});
|
||||
|
@ -11,8 +11,8 @@ namespace ComputerShopBusinessLogic.OfficePackage.HelperModels
|
||||
{
|
||||
public string FileName { get; set; } = "F:\\ReportsCourseWork\\pdffile.pdf";
|
||||
public string Title { get; set; } = string.Empty;
|
||||
public DateTime DateFrom { get; set; }
|
||||
public DateTime DateTo { get; set; }
|
||||
public DateTime? DateFrom { get; set; }
|
||||
public DateTime? DateTo { get; set; }
|
||||
public List<ReportPurchaseSupplyViewModel> SupplyPurchases { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
using ComputerShopClientApp.Models;
|
||||
using ComputerShopContracts.BindingModels;
|
||||
using ComputerShopContracts.BusinessLogicContracts;
|
||||
using ComputerShopContracts.SearchModels;
|
||||
using ComputerShopContracts.ViewModels;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
@ -13,10 +14,12 @@ namespace ComputerShopClientApp.Controllers
|
||||
public class HomeController : Controller
|
||||
{
|
||||
private readonly ILogger<HomeController> _logger;
|
||||
private readonly IReportLogic _report;
|
||||
|
||||
public HomeController(ILogger<HomeController> logger)
|
||||
public HomeController(ILogger<HomeController> logger, IReportLogic report)
|
||||
{
|
||||
_logger = logger;
|
||||
_report = report;
|
||||
}
|
||||
|
||||
public IActionResult Index()
|
||||
@ -149,6 +152,98 @@ namespace ComputerShopClientApp.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult ReportPdf()
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return View("ReportPdf");
|
||||
}
|
||||
[HttpGet]
|
||||
public string GetPurchasesReport(DateTime dateFrom, DateTime dateTo)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||
}
|
||||
List<ReportPurchaseSupplyViewModel> result;
|
||||
try
|
||||
{
|
||||
result = _report.GetPurchaseSupply(new ReportBindingModel
|
||||
{
|
||||
DateFrom = dateFrom,
|
||||
DateTo = dateTo
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка создания отчета");
|
||||
throw;
|
||||
}
|
||||
|
||||
double sum = 0;
|
||||
string table = "";
|
||||
table += $"<h2 class=\"u-text u-text-custom-color-1 u-text-default u-text-1\">Предварительный отчет</h2>";
|
||||
table += $"<table class=\"u-table-entity\">";
|
||||
table += "<colgroup>";
|
||||
table += "<col width=\"20%\" />";
|
||||
table += "<col width=\"20%\" />";
|
||||
table += "<col width=\"20%\" />";
|
||||
table += "<col width=\"20%\" />";
|
||||
table += "<col width=\"20%\" />";
|
||||
table += "</colgroup>";
|
||||
table += "<thead class=\"u-custom-color-1 u-table-header u-table-header-1\">";
|
||||
table += "<tr style=\"height: 31px\">";
|
||||
table += $"<th class=\"u-border-1 u-border-grey-50 u-table-cell\">ID закупки</th>";
|
||||
table += $"<th class=\"u-border-1 u-border-grey-50 u-table-cell\">Название компонента</th>";
|
||||
table += $"<th class=\"u-border-1 u-border-grey-50 u-table-cell\">Дата создание закупки</th>";
|
||||
table += $"<th class=\"u-border-1 u-border-grey-50 u-table-cell\">Дата создания поставки</th>";
|
||||
table += $"<th class=\"u-border-1 u-border-grey-50 u-table-cell\">Статус поставки</th>";
|
||||
table += "</tr>";
|
||||
table += "</thead>";
|
||||
foreach (var report in result)
|
||||
{
|
||||
table += "<tbody class=\"u-table-body\">";
|
||||
table += "<tr style=\"height: 75px\">";
|
||||
table += $"<td class=\"u-border-1 u-border-grey-40 u-border-no-left u-border-no-right u-table-cell\">{report.Purchase.Id.ToString()}</td>";
|
||||
table += $"<td class=\"u-border-1 u-border-grey-40 u-border-no-left u-border-no-right u-table-cell\">{report.Purchase.ComponentName}</td>";
|
||||
table += $"<td class=\"u-border-1 u-border-grey-40 u-border-no-left u-border-no-right u-table-cell\">{report.Purchase.DateCreate.ToShortDateString()}</td>";
|
||||
table += $"<td class=\"u-border-1 u-border-grey-40 u-border-no-left u-border-no-right u-table-cell\">{report.Supply.DateCreate.ToShortDateString()}</td>";
|
||||
table += $"<td class=\"u-border-1 u-border-grey-40 u-border-no-left u-border-no-right u-table-cell\">{report.Supply.Status.ToString()}</td>";
|
||||
table += "</tr>";
|
||||
table += "</tbody>";
|
||||
}
|
||||
table += "</table>";
|
||||
return table;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void ReportPdf(DateTime dateFrom, DateTime dateTo, string clientEmail)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||
}
|
||||
//if (string.IsNullOrEmpty(clientEmail))
|
||||
//{
|
||||
// throw new Exception("Email пуст");
|
||||
//}
|
||||
APIClient.PostRequest("api/report/CreatePdfReport", new ReportBindingModel
|
||||
{
|
||||
DateFrom = dateFrom,
|
||||
DateTo = dateTo,
|
||||
});
|
||||
//APIClient.PostRequest("api/report/SendPdfToMail", new MailSendInfoBindingModel
|
||||
//{
|
||||
// MailAddress = organiserEmail,
|
||||
// Subject = "Отчет по участникам (pdf)",
|
||||
// Text = "Отчет по участникам с " + dateFrom.ToShortDateString() + " до " + dateTo.ToShortDateString()
|
||||
//});
|
||||
Response.Redirect("GetPdfFile");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Enter()
|
||||
{
|
||||
|
@ -1,6 +1,21 @@
|
||||
using ComputerShopBusinessLogic.BusinessLogics;
|
||||
using ComputerShopBusinessLogic.OfficePackage;
|
||||
using ComputerShopBusinessLogic.OfficePackage.Implements;
|
||||
using ComputerShopClientApp;
|
||||
using ComputerShopContracts.BusinessLogicContracts;
|
||||
using ComputerShopContracts.StorageContracts;
|
||||
using ComputerShopDatabaseImplement.Implements;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
builder.Services.AddTransient<IComponentStorage, ComponentStorage>();
|
||||
builder.Services.AddTransient<ISupplyStorage, SupplyStorage>();
|
||||
builder.Services.AddTransient<IAssemblyStorage, AssemblyStorage>();
|
||||
builder.Services.AddTransient<IEquipmentReceivingStorage, EquipmentReceivingStorage>();
|
||||
builder.Services.AddTransient<IPurchaseStorage, PurchaseStorage>();
|
||||
builder.Services.AddTransient<IReportLogic, ReportLogic>();
|
||||
builder.Services.AddTransient<AbstractSaveToWord, SaveToWord>();
|
||||
builder.Services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
|
||||
builder.Services.AddTransient<AbstractSaveToPdf, SaveToPdf>();
|
||||
|
||||
// Add services to the container.
|
||||
builder.Services.AddControllersWithViews();
|
||||
|
@ -0,0 +1,73 @@
|
||||
@using ComputerShopContracts.ViewModels
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "ReportPdf";
|
||||
}
|
||||
|
||||
<div class="text-center">
|
||||
<h2 class="u-text u-text-custom-color-1 u-text-default u-text-1"> Отчет по закупкам за период </h2>
|
||||
</div>
|
||||
|
||||
<div class="text-center">
|
||||
@{
|
||||
<form method="post">
|
||||
<div class="u-form-email u-form-group u-label-top">
|
||||
<label class="u-label u-text-custom-color-1 u-label-2" for="dateFrom">Начало периода</label>
|
||||
<input
|
||||
type="datetime-local"
|
||||
placeholder="Выберите дату начала периода"
|
||||
id="dateFrom" name="dateFrom"
|
||||
class="u-input u-input-rectangle"/>
|
||||
</div>
|
||||
<div class="u-form-email u-form-group u-label-top">
|
||||
<label class="u-label u-text-custom-color-1 u-label-2" for="dateTo">Окончание периода</label>
|
||||
<input
|
||||
type="datetime-local"
|
||||
placeholder="Выберите дату окончания периода"
|
||||
id="dateTo" name="dateTo"
|
||||
class="u-input u-input-rectangle"/>
|
||||
</div>
|
||||
<div class="u-form-group u-form-name u-label-top">
|
||||
<label class="u-label u-text-custom-color-1 u-label-1">Введите почту</label>
|
||||
<input
|
||||
type="email"
|
||||
placeholder="Введите вашу почту"
|
||||
name="organiserEmail"
|
||||
class="u-input u-input-rectangle"/>
|
||||
</div>
|
||||
<div class="u-align-right u-form-group u-form-submit u-label-top">
|
||||
<div class="col-8"></div>
|
||||
<div class="col-4"><input type="submit" value="Отправить на почту" class="u-active-custom-color-6 u-border-none u-btn u-btn-submit u-button-style u-custom-color-1 u-hover-custom-color-2 u-btn-1" /></div>
|
||||
</div>
|
||||
<div class="mt-3" id="report">
|
||||
</div>
|
||||
</form>
|
||||
<div class="u-align-right u-form-group u-form-submit u-label-top">
|
||||
<div class="col-8"></div>
|
||||
<div class="col-4"><button type="button" id="demonstrate" class="u-active-custom-color-6 u-border-none u-btn u-btn-submit u-button-style u-custom-color-1 u-hover-custom-color-2 u-btn-1">Продемонстрировать</button></div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
@section Scripts {
|
||||
<script>
|
||||
function check() {
|
||||
var dateFrom = $('#dateFrom').val();
|
||||
var dateTo = $('#dateTo').val();
|
||||
if (dateFrom && dateTo) {
|
||||
$.ajax({
|
||||
method: "GET",
|
||||
url: "/Home/GetPurchasesReport",
|
||||
data: { dateFrom: dateFrom, dateTo: dateTo },
|
||||
success: function (result) {
|
||||
if (result != null) {
|
||||
$('#report').html(result);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
check();
|
||||
$('#demonstrate').on('click', (e) => check());
|
||||
</script>
|
||||
}
|
@ -13,7 +13,7 @@ namespace ComputerShopContracts.BusinessLogicContracts
|
||||
/// Получение списка компонент с указанием, в каких изделиях используются
|
||||
List<ReportPurchaseReceivingViewModel> GetPurchaseReceiving();
|
||||
|
||||
List<ReportPurchaseSupplyViewModel> GetPurchaseSupply();
|
||||
List<ReportPurchaseSupplyViewModel> GetPurchaseSupply(ReportBindingModel model);
|
||||
|
||||
public List<ReportComponentReceivingViewModel> GetComponentReceivings(List<int> ids);
|
||||
|
||||
@ -24,5 +24,6 @@ namespace ComputerShopContracts.BusinessLogicContracts
|
||||
void SaveOrdersToPdfFile(ReportBindingModel model);
|
||||
void SaveReceivingComponentsToWordFile(ReportBindingModel model);
|
||||
void SaveReceivingComponentsToXmlFile(ReportBindingModel model);
|
||||
void SavePurchaseSuppliesToPdfFile(ReportBindingModel model);
|
||||
}
|
||||
}
|
||||
|
@ -30,11 +30,17 @@ namespace ComputerShopDatabaseImplement.Implements
|
||||
|
||||
public List<PurchaseViewModel> GetFilteredList(PurchaseSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue && !model.ClientId.HasValue)
|
||||
if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue && !model.ClientId.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new ComputerShopDatabase();
|
||||
if (model.DateFrom.HasValue && model.DateTo.HasValue)
|
||||
return context.Purchases
|
||||
.Include(x => x.Component)
|
||||
.Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
if (model.ClientId.HasValue)
|
||||
{
|
||||
return context.Purchases
|
||||
|
@ -43,4 +43,22 @@ public class ReportController : Controller
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpPost]
|
||||
public void CreatePdfReport(ReportBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_reportLogic.SavePurchaseSuppliesToPdfFile(new ReportBindingModel
|
||||
{
|
||||
DateFrom = model.DateFrom,
|
||||
DateTo = model.DateTo,
|
||||
FileName = "F:\\ReportsCourseWork\\pdffile.pdf",
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка создания отчета");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user