docx is done
This commit is contained in:
parent
3bbee9e09b
commit
e3fda489a5
@ -78,14 +78,6 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
|
||||
$".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) {
|
||||
CheckModel(model, false);
|
||||
model.PayOption = paymeantOption;
|
||||
|
@ -35,17 +35,25 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
|
||||
}
|
||||
|
||||
// Получение списка оплаченных товаров за период
|
||||
public List<ReportProductsViewModel>? GetProducts (ReportBindingModel model) {
|
||||
var paymeants = _paymeantstorage.GetFillteredList(new PaymeantSearchModel {
|
||||
DateFrom = model.DateFrom,
|
||||
DateTo = model.DateTo,
|
||||
ClientID = model.ClientID,
|
||||
});
|
||||
public List<ReportProductsViewModel>? GetProducts (ReportBindingModel? model = null, List<PaymeantViewModel>? paymeants = null) {
|
||||
|
||||
List<PaymeantViewModel> paymeantList = new();
|
||||
|
||||
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();
|
||||
|
||||
|
||||
foreach (var paymeant in paymeants) {
|
||||
foreach (var paymeant in paymeantList) {
|
||||
var order = _orderStorage.GetElement(new OrderSearchModel { ID = paymeant.OrderID })
|
||||
?? throw new Exception("Ошибка полуения данных");
|
||||
|
||||
@ -65,7 +73,33 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
|
||||
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)
|
||||
{
|
||||
return _paymeantstorage.GetFillteredList(new PaymeantSearchModel {
|
||||
@ -128,14 +162,11 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
|
||||
return document;
|
||||
}
|
||||
|
||||
public byte[]? SavePaymeantToWordFile(ReportBindingModel model)
|
||||
public byte[]? SavePaymeantToWordFile(List<PaymeantViewModel> paymeants)
|
||||
{
|
||||
var document = _saveToWord.CreateDoc(new WordInfoClient {
|
||||
Title = "Список оплат",
|
||||
|
||||
DateFrom = model.DateFrom,
|
||||
DateTo = model.DateTo,
|
||||
Products = GetProducts(model)
|
||||
Products = GetProductsFix(paymeants)
|
||||
});
|
||||
return document;
|
||||
}
|
||||
|
@ -18,8 +18,5 @@ namespace ElectronicsShopContracts.BusinessLogicContracts
|
||||
|
||||
bool CreatePay(PaymeantBindingModel model);
|
||||
bool SetStatus(PaymeantBindingModel model, PaymeantOption paymeantOption);
|
||||
|
||||
bool SetFullPayment(PaymeantBindingModel model);
|
||||
bool SetPartialPayemnt(PaymeantBindingModel model);
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ namespace ElectronicsShopContracts.BusinessLogicContracts
|
||||
List<ReportPaymeantsViewModel>? GetPaymeants(ReportBindingModel model);
|
||||
|
||||
// Сохранение отчета оплат в .word
|
||||
byte[]? SavePaymeantToWordFile(ReportBindingModel model);
|
||||
byte[]? SavePaymeantToWordFile(List<PaymeantViewModel> paymeants);
|
||||
|
||||
// Сохранение отчета оплат с товарами в .excel
|
||||
byte[]? SavePaymeantToExcelFile(ReportBindingModel model);
|
||||
|
@ -159,6 +159,18 @@ namespace ElectronicsShopRestAPI.Controllers {
|
||||
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]
|
||||
public List<ReportPaymeantsViewModel>? GetReport(string _start,string _end) {
|
||||
try {
|
||||
@ -191,13 +203,20 @@ namespace ElectronicsShopRestAPI.Controllers {
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public byte[]? CreateDocxReport (int _clientID, string DateFrom, string DateTo) {
|
||||
public byte[]? CreateDocxReport (string _ids) {
|
||||
try {
|
||||
var document = _reportLogic.SavePaymeantToWordFile (new ReportBindingModel {
|
||||
ClientID = _clientID,
|
||||
DateFrom = DateTime.Parse(DateFrom),
|
||||
DateTo = DateTime.Parse(DateTo)
|
||||
});
|
||||
|
||||
List<PaymeantViewModel> _paymeants = new();
|
||||
|
||||
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;
|
||||
}
|
||||
catch (Exception ex) {
|
||||
|
Binary file not shown.
@ -7,6 +7,7 @@ using ElectronicsShopContracts.ViewModels;
|
||||
using ElectronicsShopDataModels.Enums;
|
||||
using ElectronicsShopDataModels.Models;
|
||||
using ElectronicsShopUserApp.Models;
|
||||
using Microsoft.AspNetCore.Http.Extensions;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Newtonsoft.Json;
|
||||
using System.Diagnostics;
|
||||
@ -292,20 +293,11 @@ namespace ElectronicsShopUserApp.Controllers {
|
||||
[HttpPost]
|
||||
public void Report(DateTime DateFrom, DateTime DateTo, int[] ids, bool _isFixReport) {
|
||||
|
||||
// ïðîâåðêà òèï ôîðìèðîâàíèÿ îò÷åòà, îòïðàâëÿòü íà íóæíî ñòðàíèöó ïðåäïðîñìîòðà
|
||||
// todo
|
||||
if (_isFixReport == false) {
|
||||
if (DateTo == DateTime.MinValue || DateFrom > DateTo) {
|
||||
throw new Exception("Íåêîðåêòíî óêàçàí âðåìåííîé èíòåðâàë");
|
||||
}
|
||||
Response.Redirect($"ReportSearch?_datefrom={DateFrom}&_dateto={DateTo + DateTime.Now.TimeOfDay}");
|
||||
if (DateTo == DateTime.MinValue || DateFrom > DateTo) {
|
||||
throw new Exception("Íåêîðåêòíî óêàçàí âðåìåííîé èíòåðâàë");
|
||||
}
|
||||
else {
|
||||
if (ids.Length == 0) {
|
||||
throw new Exception("Êîëè÷åñòâî îò÷åòîâ äîëæíî áûòü áîëüøå 0");
|
||||
}
|
||||
}
|
||||
}
|
||||
Response.Redirect($"ReportSearch?_datefrom={DateFrom}&_dateto={DateTo + DateTime.Now.TimeOfDay}");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult ReportSearch(string _datefrom, string _dateto) {
|
||||
@ -317,8 +309,24 @@ namespace ElectronicsShopUserApp.Controllers {
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult ReportSearchFix(string jsonStr) {
|
||||
return View();
|
||||
public IActionResult ReportSearchFix() {
|
||||
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]
|
||||
@ -334,18 +342,15 @@ namespace ElectronicsShopUserApp.Controllers {
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult CreateWordReport(string idsStr) {
|
||||
/*
|
||||
var fileMemStream = APIClient.GetRequset<byte[]>($"api/client/CreateDocxReport?_clientID={APIClient.Client?.ID}&DateFrom={DateFrom}&" +
|
||||
$"DateTo={DateTo}");
|
||||
public IActionResult CreateWordReport(string ids) {
|
||||
|
||||
var fileMemStream = APIClient.GetRequset<byte[]>($"api/client/CreateDocxReport?_ids={ids}");
|
||||
|
||||
if (fileMemStream == null) {
|
||||
throw new Exception("Îøèáêà ñîçäàíèÿ îò÷åòà");
|
||||
}
|
||||
|
||||
return File(fileMemStream, "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "Report.docx");
|
||||
*/
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
@ -356,7 +361,7 @@ namespace ElectronicsShopUserApp.Controllers {
|
||||
DateTo = DateTime.Parse(DateTo),
|
||||
ClientID = APIClient.Client.ID
|
||||
});
|
||||
return View("Report");
|
||||
return Redirect("Report");
|
||||
}
|
||||
}
|
||||
}
|
@ -41,61 +41,61 @@
|
||||
<div class="text-center">
|
||||
@{
|
||||
if (Model == null) {
|
||||
<h3 class="display-4">Авторизируйтесь</h3>
|
||||
<h3 class="display-4">Авторизируйтесь</h3>
|
||||
return;
|
||||
}
|
||||
<div class="text-end">
|
||||
<button class="btn btn-sm btn-outline-danger m-2 p-2" id="btnFix">Cформировать отчет</button>
|
||||
</div>
|
||||
<div class="text-end">
|
||||
<button class="btn btn-sm btn-outline-danger m-2 p-2" id="btnFix">Cформировать отчет</button>
|
||||
</div>
|
||||
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
Номер
|
||||
</th>
|
||||
<th>
|
||||
Номер заказа
|
||||
</th>
|
||||
<th>
|
||||
Сумма к оплате
|
||||
</th>
|
||||
<th>
|
||||
Статус оплаты
|
||||
</th>
|
||||
<th>
|
||||
Дата оплаты
|
||||
</th>
|
||||
<th>
|
||||
<input type="checkbox" class="form-check-input" id="Select_all" name="Select_all" /> Выбрать все
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var item in Model) {
|
||||
<tr>
|
||||
<th>
|
||||
@Html.DisplayFor(modelItem => item.ID)
|
||||
</th>
|
||||
<th>
|
||||
@Html.DisplayFor(modelItem => item.OrderID)
|
||||
</th>
|
||||
<th>
|
||||
@Html.DisplayFor(modelItem => item.SumPayment)
|
||||
</th>
|
||||
<th>
|
||||
@Html.DisplayFor(modelItem => item.PayOption)
|
||||
</th>
|
||||
<th>
|
||||
@Html.DisplayFor(modelItem => item.DatePaymeant)
|
||||
</th>
|
||||
<th>
|
||||
<input type="checkbox" class="form-check-input" id="Select_rec" name="Select_rec" value="@item.ID" />
|
||||
</th>
|
||||
</tr>
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
Номер
|
||||
</th>
|
||||
<th>
|
||||
Номер заказа
|
||||
</th>
|
||||
<th>
|
||||
Сумма к оплате
|
||||
</th>
|
||||
<th>
|
||||
Статус оплаты
|
||||
</th>
|
||||
<th>
|
||||
Дата оплаты
|
||||
</th>
|
||||
<th>
|
||||
<input type="checkbox" class="form-check-input" id="Select_all" name="Select_all" /> Выбрать все
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var item in Model) {
|
||||
<tr>
|
||||
<th>
|
||||
@Html.DisplayFor(modelItem => item.ID)
|
||||
</th>
|
||||
<th>
|
||||
@Html.DisplayFor(modelItem => item.OrderID)
|
||||
</th>
|
||||
<th>
|
||||
@Html.DisplayFor(modelItem => item.SumPayment)
|
||||
</th>
|
||||
<th>
|
||||
@Html.DisplayFor(modelItem => item.PayOption)
|
||||
</th>
|
||||
<th>
|
||||
@Html.DisplayFor(modelItem => item.DatePaymeant)
|
||||
</th>
|
||||
<th>
|
||||
<input type="checkbox" class="form-check-input" id="Select_rec" name="Select_rec" value="@item.ID" />
|
||||
</th>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
}
|
||||
</div>
|
||||
@ -124,13 +124,14 @@
|
||||
val.push($(this).val());
|
||||
});
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: '/Home/Report',
|
||||
data: { 'ids': val, '_isFixReport': true},
|
||||
success: function (result) {
|
||||
$("#idsStr").val(result);
|
||||
}
|
||||
});
|
||||
|
||||
var str = 'ids=';
|
||||
for (let i = 0; i < val.length - 1; i++) {
|
||||
str += val[i] + '&='
|
||||
}
|
||||
str += val[val.length - 1];
|
||||
|
||||
window.location.href = "ReportSearchFix/" + str;
|
||||
|
||||
});
|
||||
</script>
|
@ -3,13 +3,13 @@
|
||||
@model (DateTime, DateTime, List<PaymeantViewModel>)
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Reports";
|
||||
ViewData["Title"] = "ReportSearch";
|
||||
}
|
||||
|
||||
<div class="text-center">
|
||||
<h1 class="row align-items-center mb-3">
|
||||
<div class="text-center">
|
||||
<label>Отчет по оплатам:</label>
|
||||
<label>Предпросмотр отчета:</label>
|
||||
</div>
|
||||
<div class="col-sm-auto">
|
||||
<label>С:</label>
|
||||
|
@ -1,5 +1,65 @@
|
||||
@*
|
||||
For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
|
||||
*@
|
||||
@using ElectronicsShopContracts.ViewModels
|
||||
@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>
|
Loading…
Reference in New Issue
Block a user