docx is done

This commit is contained in:
Илья Федотов 2024-08-07 21:48:54 +04:00
parent 3bbee9e09b
commit e3fda489a5
10 changed files with 222 additions and 117 deletions

View File

@ -78,14 +78,6 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
$".PayOption{model.PayOption}"); $".PayOption{model.PayOption}");
} }
public bool SetFullPayment(PaymeantBindingModel model) {
throw new NotImplementedException();
}
public bool SetPartialPayemnt(PaymeantBindingModel model) {
throw new NotImplementedException();
}
public bool SetStatus(PaymeantBindingModel model, PaymeantOption paymeantOption) { public bool SetStatus(PaymeantBindingModel model, PaymeantOption paymeantOption) {
CheckModel(model, false); CheckModel(model, false);
model.PayOption = paymeantOption; model.PayOption = paymeantOption;

View File

@ -35,17 +35,25 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
} }
// Получение списка оплаченных товаров за период // Получение списка оплаченных товаров за период
public List<ReportProductsViewModel>? GetProducts (ReportBindingModel model) { public List<ReportProductsViewModel>? GetProducts (ReportBindingModel? model = null, List<PaymeantViewModel>? paymeants = null) {
var paymeants = _paymeantstorage.GetFillteredList(new PaymeantSearchModel {
DateFrom = model.DateFrom, List<PaymeantViewModel> paymeantList = new();
DateTo = model.DateTo,
ClientID = model.ClientID, if (model != null) {
}); paymeantList = _paymeantstorage.GetFillteredList(new PaymeantSearchModel {
DateFrom = model.DateFrom,
DateTo = model.DateTo,
ClientID = model.ClientID,
});
}
else if (paymeants != null){
paymeantList = paymeants;
}
List<ReportProductsViewModel>? products = new(); List<ReportProductsViewModel>? products = new();
foreach (var paymeant in paymeants) { foreach (var paymeant in paymeantList) {
var order = _orderStorage.GetElement(new OrderSearchModel { ID = paymeant.OrderID }) var order = _orderStorage.GetElement(new OrderSearchModel { ID = paymeant.OrderID })
?? throw new Exception("Ошибка полуения данных"); ?? throw new Exception("Ошибка полуения данных");
@ -65,7 +73,33 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
return products; return products;
} }
// получение списка оплат за период public List<ReportProductsViewModel>? GetProductsFix(List<PaymeantViewModel> paymeants) {
List<ReportProductsViewModel>? products = new();
foreach (var paymeant in paymeants) {
var order = _orderStorage.GetElement(new OrderSearchModel { ID = paymeant.OrderID })
?? throw new Exception("Ошибка полуения данных");
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
?? "Отсутствует",
PaymentID = paymeant.ID,
count = product.Value.Item2
});
}
}
return products;
}
// получение списка оплат за период
public List<ReportPaymeantsViewModel>? GetPaymeants(ReportBindingModel model) public List<ReportPaymeantsViewModel>? GetPaymeants(ReportBindingModel model)
{ {
return _paymeantstorage.GetFillteredList(new PaymeantSearchModel { return _paymeantstorage.GetFillteredList(new PaymeantSearchModel {
@ -128,14 +162,11 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
return document; return document;
} }
public byte[]? SavePaymeantToWordFile(ReportBindingModel model) public byte[]? SavePaymeantToWordFile(List<PaymeantViewModel> paymeants)
{ {
var document = _saveToWord.CreateDoc(new WordInfoClient { var document = _saveToWord.CreateDoc(new WordInfoClient {
Title = "Список оплат", Title = "Список оплат",
Products = GetProductsFix(paymeants)
DateFrom = model.DateFrom,
DateTo = model.DateTo,
Products = GetProducts(model)
}); });
return document; return document;
} }

View File

@ -18,8 +18,5 @@ namespace ElectronicsShopContracts.BusinessLogicContracts
bool CreatePay(PaymeantBindingModel model); bool CreatePay(PaymeantBindingModel model);
bool SetStatus(PaymeantBindingModel model, PaymeantOption paymeantOption); bool SetStatus(PaymeantBindingModel model, PaymeantOption paymeantOption);
bool SetFullPayment(PaymeantBindingModel model);
bool SetPartialPayemnt(PaymeantBindingModel model);
} }
} }

View File

@ -18,7 +18,7 @@ namespace ElectronicsShopContracts.BusinessLogicContracts
List<ReportPaymeantsViewModel>? GetPaymeants(ReportBindingModel model); List<ReportPaymeantsViewModel>? GetPaymeants(ReportBindingModel model);
// Сохранение отчета оплат в .word // Сохранение отчета оплат в .word
byte[]? SavePaymeantToWordFile(ReportBindingModel model); byte[]? SavePaymeantToWordFile(List<PaymeantViewModel> paymeants);
// Сохранение отчета оплат с товарами в .excel // Сохранение отчета оплат с товарами в .excel
byte[]? SavePaymeantToExcelFile(ReportBindingModel model); byte[]? SavePaymeantToExcelFile(ReportBindingModel model);

View File

@ -159,6 +159,18 @@ namespace ElectronicsShopRestAPI.Controllers {
throw; throw;
} }
} }
[HttpGet]
public PaymeantViewModel? GetPaymeant(int _paymeantID) {
try {
return _payLogic?.ReadElement(new PaymeantSearchModel { ID = _paymeantID });
}
catch (Exception ex) {
_logger.LogError(ex, $"ошибка получения данных об оплате id = {_paymeantID}");
throw;
}
}
[HttpGet] [HttpGet]
public List<ReportPaymeantsViewModel>? GetReport(string _start,string _end) { public List<ReportPaymeantsViewModel>? GetReport(string _start,string _end) {
try { try {
@ -191,13 +203,20 @@ namespace ElectronicsShopRestAPI.Controllers {
} }
[HttpGet] [HttpGet]
public byte[]? CreateDocxReport (int _clientID, string DateFrom, string DateTo) { public byte[]? CreateDocxReport (string _ids) {
try { try {
var document = _reportLogic.SavePaymeantToWordFile (new ReportBindingModel {
ClientID = _clientID, List<PaymeantViewModel> _paymeants = new();
DateFrom = DateTime.Parse(DateFrom),
DateTo = DateTime.Parse(DateTo) foreach (char i in _ids) {
}); if (int.TryParse(i.ToString(), out int id)) {
var paymeant = _payLogic.ReadElement(new PaymeantSearchModel { ID = id }) ?? throw new Exception("Ошибка получения данных");
_paymeants.Add(paymeant);
}
}
var document = _reportLogic.SavePaymeantToWordFile(_paymeants);
return document; return document;
} }
catch (Exception ex) { catch (Exception ex) {

View File

@ -7,6 +7,7 @@ using ElectronicsShopContracts.ViewModels;
using ElectronicsShopDataModels.Enums; using ElectronicsShopDataModels.Enums;
using ElectronicsShopDataModels.Models; using ElectronicsShopDataModels.Models;
using ElectronicsShopUserApp.Models; using ElectronicsShopUserApp.Models;
using Microsoft.AspNetCore.Http.Extensions;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json; using Newtonsoft.Json;
using System.Diagnostics; using System.Diagnostics;
@ -292,20 +293,11 @@ namespace ElectronicsShopUserApp.Controllers {
[HttpPost] [HttpPost]
public void Report(DateTime DateFrom, DateTime DateTo, int[] ids, bool _isFixReport) { public void Report(DateTime DateFrom, DateTime DateTo, int[] ids, bool _isFixReport) {
// ïðîâåðêà òèï ôîðìèðîâàíèÿ îò÷åòà, îòïðàâëÿòü íà íóæíî ñòðàíèöó ïðåäïðîñìîòðà if (DateTo == DateTime.MinValue || DateFrom > DateTo) {
// todo throw new Exception("Íåêîðåêòíî óêàçàí âðåìåííîé èíòåðâàë");
if (_isFixReport == false) {
if (DateTo == DateTime.MinValue || DateFrom > DateTo) {
throw new Exception("Íåêîðåêòíî óêàçàí âðåìåííîé èíòåðâàë");
}
Response.Redirect($"ReportSearch?_datefrom={DateFrom}&_dateto={DateTo + DateTime.Now.TimeOfDay}");
} }
else { Response.Redirect($"ReportSearch?_datefrom={DateFrom}&_dateto={DateTo + DateTime.Now.TimeOfDay}");
if (ids.Length == 0) { }
throw new Exception("Êîëè÷åñòâî îò÷åòîâ äîëæíî áûòü áîëüøå 0");
}
}
}
[HttpGet] [HttpGet]
public IActionResult ReportSearch(string _datefrom, string _dateto) { public IActionResult ReportSearch(string _datefrom, string _dateto) {
@ -317,8 +309,24 @@ namespace ElectronicsShopUserApp.Controllers {
} }
[HttpGet] [HttpGet]
public IActionResult ReportSearchFix(string jsonStr) { public IActionResult ReportSearchFix() {
return View(); string strUrl = Request.GetDisplayUrl();
strUrl = strUrl.Replace("https://localhost:7219/Home/ReportSearchFix/", "");
string ids = "";
List<PaymeantViewModel> paymeantsFix = new();
foreach (char i in strUrl) {
if (int.TryParse(i.ToString(), out int id)) {
var paymeant = APIClient.GetRequset<PaymeantViewModel>($"api/Client/GetPaymeant?_paymeantID={id}") ??
throw new Exception ("Îïëàòà íå íàéäåíà");
paymeantsFix.Add(paymeant);
ids += "/" + id;
}
}
(List<PaymeantViewModel>, string) tuple = (paymeantsFix, ids);
return View(tuple);
} }
[HttpGet] [HttpGet]
@ -334,18 +342,15 @@ namespace ElectronicsShopUserApp.Controllers {
} }
[HttpGet] [HttpGet]
public IActionResult CreateWordReport(string idsStr) { public IActionResult CreateWordReport(string ids) {
/*
var fileMemStream = APIClient.GetRequset<byte[]>($"api/client/CreateDocxReport?_clientID={APIClient.Client?.ID}&DateFrom={DateFrom}&" + var fileMemStream = APIClient.GetRequset<byte[]>($"api/client/CreateDocxReport?_ids={ids}");
$"DateTo={DateTo}");
if (fileMemStream == null) { if (fileMemStream == null) {
throw new Exception("Îøèáêà ñîçäàíèÿ îò÷åòà"); throw new Exception("Îøèáêà ñîçäàíèÿ îò÷åòà");
} }
return File(fileMemStream, "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "Report.docx"); return File(fileMemStream, "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "Report.docx");
*/
return View();
} }
[HttpGet] [HttpGet]
@ -356,7 +361,7 @@ namespace ElectronicsShopUserApp.Controllers {
DateTo = DateTime.Parse(DateTo), DateTo = DateTime.Parse(DateTo),
ClientID = APIClient.Client.ID ClientID = APIClient.Client.ID
}); });
return View("Report"); return Redirect("Report");
} }
} }
} }

View File

@ -41,61 +41,61 @@
<div class="text-center"> <div class="text-center">
@{ @{
if (Model == null) { if (Model == null) {
<h3 class="display-4">Авторизируйтесь</h3> <h3 class="display-4">Авторизируйтесь</h3>
return; return;
} }
<div class="text-end"> <div class="text-end">
<button class="btn btn-sm btn-outline-danger m-2 p-2" id="btnFix">Cформировать отчет</button> <button class="btn btn-sm btn-outline-danger m-2 p-2" id="btnFix">Cформировать отчет</button>
</div> </div>
<table class="table"> <table class="table">
<thead> <thead>
<tr> <tr>
<th> <th>
Номер Номер
</th> </th>
<th> <th>
Номер заказа Номер заказа
</th> </th>
<th> <th>
Сумма к оплате Сумма к оплате
</th> </th>
<th> <th>
Статус оплаты Статус оплаты
</th> </th>
<th> <th>
Дата оплаты Дата оплаты
</th> </th>
<th> <th>
<input type="checkbox" class="form-check-input" id="Select_all" name="Select_all" /> Выбрать все <input type="checkbox" class="form-check-input" id="Select_all" name="Select_all" /> Выбрать все
</th> </th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@foreach (var item in Model) { @foreach (var item in Model) {
<tr> <tr>
<th> <th>
@Html.DisplayFor(modelItem => item.ID) @Html.DisplayFor(modelItem => item.ID)
</th> </th>
<th> <th>
@Html.DisplayFor(modelItem => item.OrderID) @Html.DisplayFor(modelItem => item.OrderID)
</th> </th>
<th> <th>
@Html.DisplayFor(modelItem => item.SumPayment) @Html.DisplayFor(modelItem => item.SumPayment)
</th> </th>
<th> <th>
@Html.DisplayFor(modelItem => item.PayOption) @Html.DisplayFor(modelItem => item.PayOption)
</th> </th>
<th> <th>
@Html.DisplayFor(modelItem => item.DatePaymeant) @Html.DisplayFor(modelItem => item.DatePaymeant)
</th> </th>
<th> <th>
<input type="checkbox" class="form-check-input" id="Select_rec" name="Select_rec" value="@item.ID" /> <input type="checkbox" class="form-check-input" id="Select_rec" name="Select_rec" value="@item.ID" />
</th> </th>
</tr> </tr>
} }
</tbody> </tbody>
</table> </table>
} }
</div> </div>
@ -124,13 +124,14 @@
val.push($(this).val()); val.push($(this).val());
}); });
$.ajax({
type: 'POST', var str = 'ids=';
url: '/Home/Report', for (let i = 0; i < val.length - 1; i++) {
data: { 'ids': val, '_isFixReport': true}, str += val[i] + '&='
success: function (result) { }
$("#idsStr").val(result); str += val[val.length - 1];
}
}); window.location.href = "ReportSearchFix/" + str;
}); });
</script> </script>

View File

@ -3,13 +3,13 @@
@model (DateTime, DateTime, List<PaymeantViewModel>) @model (DateTime, DateTime, List<PaymeantViewModel>)
@{ @{
ViewData["Title"] = "Reports"; ViewData["Title"] = "ReportSearch";
} }
<div class="text-center"> <div class="text-center">
<h1 class="row align-items-center mb-3"> <h1 class="row align-items-center mb-3">
<div class="text-center"> <div class="text-center">
<label>Отчет по оплатам:</label> <label>Предпросмотр отчета:</label>
</div> </div>
<div class="col-sm-auto"> <div class="col-sm-auto">
<label>С:</label> <label>С:</label>

View File

@ -1,5 +1,65 @@
@* @using ElectronicsShopContracts.ViewModels
For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 @model (List<PaymeantViewModel>, string)
*@
@{ @{
ViewData["Title"] = "ReportSearchFix";
} }
<div class="text-center">
<h1 class="row align-items-center mb-3">
<div class="text-center">
<label>Предпросмотр отчета:</label>
</div>
<div class="text-end">
<a class="btn btn-primary btn-sm" asp-action="CreateWordReport" asp-route-ids ="@Model.Item2" style="background-color:#335a95;">Экспорт отчета в .docx</a>
<a class="btn btn-primary btn-sm" asp-action="CreateExcelReport" style="background-color:#04713A;">Экспорт отчета в .xlsx</a>
</div>
</h1>
</div>
<div class="text-center">
@{
<table class="table">
<thead>
<tr>
<th>
Номер оплаты
</th>
<th>
Номер заказа
</th>
<th>
Статус оплаты
</th>
<th>
Сумма оплаты
</th>
<th>
Дата оплаты
</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model.Item1) {
<tr>
<th>
@Html.DisplayFor(modelItem => item.ID)
</th>
<th>
@Html.DisplayFor(modelItem => item.OrderID)
</th>
<th>
@Html.DisplayFor(modelItem => item.PayOption)
</th>
<th>
@Html.DisplayFor(modelItem => item.SumPayment)
</th>
<th>
@Html.DisplayFor(modelItem => item.DatePaymeant)
</th>
</tr>
}
</tbody>
</table>
}
</div>