Date in reporst bv client

This commit is contained in:
Илья Федотов 2024-08-01 22:33:30 +04:00
parent 45cf0818fc
commit 84442ed049
10 changed files with 81 additions and 20 deletions

View File

@ -82,8 +82,12 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
}
// Получение списка товаров с указанием, в какие оплаты товар входит
public List<ReportPaymeantProductsViewModel> GetPaymeantProducts(int _clientID) {
var paymeants = _paymeantstorage.GetFillteredList(new PaymeantSearchModel { ClientID = _clientID });
public List<ReportPaymeantProductsViewModel> GetPaymeantProducts(ReportBindingModel model) {
var paymeants = _paymeantstorage.GetFillteredList(new PaymeantSearchModel {
ClientID = model.ClientID,
DateFrom = model.DateFrom,
DateTo = model.DateTo,
});
var list = new List<ReportPaymeantProductsViewModel>();
@ -112,21 +116,29 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
return list;
}
public byte[]? SavePaymeantToExcelFile(int _clientID)
public byte[]? SavePaymeantToExcelFile(ReportBindingModel model)
{
var document = _saveToExcel.CreateReport(new ExcelInfoClient
{
Title = "Список оплат и товаров",
PaymeantProducts = GetPaymeantProducts(_clientID)
PaymeantProducts = GetPaymeantProducts(model),
DateFrom = model.DateFrom,
DateTo = model.DateTo
});
return document;
}
public byte[]? SavePaymeantToWordFile(int _clientID)
public byte[]? SavePaymeantToWordFile(ReportBindingModel model)
{
var document = _saveToWord.CreateDoc(new WordInfoClient {
Title = "Список оплат",
ListPaymeant = _paymeantstorage.GetFillteredList(new PaymeantSearchModel { ClientID = _clientID }),
ListPaymeant = _paymeantstorage.GetFillteredList(new PaymeantSearchModel {
ClientID = model.ClientID,
DateFrom = model.DateFrom,
DateTo = model.DateTo,
}),
DateFrom = model.DateFrom,
DateTo = model.DateTo,
});
return document;
}

View File

@ -22,7 +22,19 @@ namespace ElectronicsShopBusinessLogic.OfficePackage
CellToName = "C1"
});
uint rowIndex = 2;
InsertCellInWorksheet(new ExcelCellParameters {
ColumnName = "A",
RowIndex = 2,
Text = $"С {info.DateFrom.ToShortDateString()} по {info.DateTo.ToShortDateString()}",
StyleInfo = ExcelStyleInfoType.Title
});
MergeCells(new ExcelMergeParameters {
CellFromName = "A2",
CellToName = "H2"
});
uint rowIndex = 3;
foreach (var pp in info.PaymeantProducts) {
InsertCellInWorksheet(new ExcelCellParameters {
ColumnName = "A",

View File

@ -24,6 +24,15 @@ namespace ElectronicsShopBusinessLogic.OfficePackage
}
});
CreateParagraph(new WordParagraph {
Texts = new List<(string, WordTextProperties)> { ($"С {info.DateFrom.ToShortDateString()} по {info.DateTo.ToShortDateString()}",
new WordTextProperties { Bold = true, Size = "24", }) },
TextProperties = new WordTextProperties {
Size = "24",
JustificationType = WordJustificationType.Both
}
});
foreach (var pre in info.ListPaymeant)
{
CreateParagraph(new WordParagraph

View File

@ -5,6 +5,11 @@ namespace ElectronicsShopBusinessLogic.OfficePackage.HelperModels
public class ExcelInfoClient
{
public string Title { get; set; } = string.Empty;
public DateTime DateFrom { get; set; }
public DateTime DateTo { get; set; }
public List<ReportPaymeantProductsViewModel> PaymeantProducts { get; set; } = new();
}
}

View File

@ -6,6 +6,11 @@ namespace ElectronicsShopBusinessLogic.OfficePackage.HelperModels
public class WordInfoClient
{
public string Title { get; set; } = string.Empty;
public DateTime DateFrom { get; set; }
public DateTime DateTo { get; set; }
public List<PaymeantViewModel> ListPaymeant { get; set; } = new();
}
}

View File

@ -13,15 +13,15 @@ namespace ElectronicsShopContracts.BusinessLogicContracts
public interface IReportClientLogic
{
// получение списка товаров с указанием, в какие оплаты товар входит
List<ReportPaymeantProductsViewModel>? GetPaymeantProducts(int _clientID);
List<ReportPaymeantProductsViewModel>? GetPaymeantProducts(ReportBindingModel model);
// получения списка оплат
List<ReportPaymeantsViewModel>? GetPaymeants(ReportBindingModel model);
// Сохранение отчета оплат в .word
byte[]? SavePaymeantToWordFile(int _clientID);
byte[]? SavePaymeantToWordFile(ReportBindingModel model);
// Сохранение отчета оплат с товарами в .excel
byte[]? SavePaymeantToExcelFile(int _clientID);
byte[]? SavePaymeantToExcelFile(ReportBindingModel model);
// Отчет оплаченных товаров в .pdf
PdfDocument SaveProductToPdfFile(ReportBindingModel model);

View File

@ -53,6 +53,12 @@ namespace ElectronicsShopDataBaseImplement.Implements {
.Select(x => x.GetViewModel)
.ToList();
}
else if (model.ClientID.HasValue && model.DateFrom.HasValue && model.DateTo.HasValue) {
return context.Paymeants
.Where(x => x.DatePaymeant >= model.DateFrom && x.DatePaymeant <= model.DateTo && x.ClientID == model.ClientID)
.Select(x => x.GetViewModel)
.ToList();
}
else if (model.ClientID.HasValue) {
return context.Paymeants

View File

@ -175,9 +175,13 @@ namespace ElectronicsShopRestAPI.Controllers {
}
[HttpGet]
public byte[]? CreateXlsxReport (int _clientID) {
public byte[]? CreateXlsxReport (int _clientID, string DateFrom, string DateTo) {
try {
var document = _reportLogic.SavePaymeantToExcelFile (_clientID);
var document = _reportLogic.SavePaymeantToExcelFile (new ReportBindingModel {
ClientID = _clientID,
DateFrom = DateTime.Parse(DateFrom),
DateTo = DateTime.Parse(DateTo)
});
return document;
}
catch (Exception ex) {
@ -187,9 +191,13 @@ namespace ElectronicsShopRestAPI.Controllers {
}
[HttpGet]
public byte[]? CreateDocxReport (int _clientID) {
public byte[]? CreateDocxReport (int _clientID, string DateFrom, string DateTo) {
try {
var document = _reportLogic.SavePaymeantToWordFile (_clientID);
var document = _reportLogic.SavePaymeantToWordFile (new ReportBindingModel {
ClientID = _clientID,
DateFrom = DateTime.Parse(DateFrom),
DateTo = DateTime.Parse(DateTo)
});
return document;
}
catch (Exception ex) {

View File

@ -308,8 +308,9 @@ namespace ElectronicsShopUserApp.Controllers {
}
[HttpGet]
public IActionResult CreateExcelReport() {
var fileMemStream = APIClient.GetRequset<byte[]>($"api/Client/CreateXlsxReport?_clientID={APIClient.Client?.ID}");
public IActionResult CreateExcelReport(string DateFrom, string DateTo) {
var fileMemStream = APIClient.GetRequset<byte[]>($"api/Client/CreateXlsxReport?_clientID={APIClient.Client?.ID}&DateFrom={DateFrom}&" +
$"DateTo={DateTo}");
if (fileMemStream == null) {
throw new Exception("Îøèáêà ñîçäàíèÿ îò÷åòà");
@ -319,8 +320,9 @@ namespace ElectronicsShopUserApp.Controllers {
}
[HttpGet]
public IActionResult CreateWordReport() {
var fileMemStream = APIClient.GetRequset<byte[]>($"api/client/CreateDocxReport?_clientID={APIClient.Client?.ID}");
public IActionResult CreateWordReport(string DateFrom, string DateTo) {
var fileMemStream = APIClient.GetRequset<byte[]>($"api/client/CreateDocxReport?_clientID={APIClient.Client?.ID}&DateFrom={DateFrom}&" +
$"DateTo={DateTo}");
if (fileMemStream == null) {
throw new Exception("Îøèáêà ñîçäàíèÿ îò÷åòà");

View File

@ -25,8 +25,10 @@
</div>
<div class="row">
<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="CreateWordReport" asp-route-DateFrom="@Model.Item1"
asp-route-DateTo="@Model.Item2" style="background-color:#335a95;">Экспорт отчета в .xlsx</a>
<a class="btn btn-primary btn-sm" asp-action="CreateExcelReport" asp-route-DateFrom="@Model.Item1"
asp-route-DateTo="@Model.Item2" style="background-color:#04713A;">Экспорт отчета в .docx</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>