вывод отчета на форму

This commit is contained in:
dasha 2023-05-18 16:32:53 +04:00
parent 4997506a44
commit acdd3e1554
7 changed files with 103 additions and 14 deletions

View File

@ -50,12 +50,12 @@ namespace HardwareShopBusinessLogic.BusinessLogics.Storekeeper
}
/// Получение сведений по комплектующим за период,
/// с указанием в каких товарах и сборках они использовались
public List<ReportComponentsViewModel> GetComponents(UserBindingModel user, ReportBindingModel model)
public List<ReportComponentsViewModel> GetComponents(ReportBindingModel model)
{
var result = new List<ReportComponentsViewModel>();
var components = _componentStorage.GetFilteredList(new()
{
UserId = user.Id,
UserId = model.UserId,
DateFrom = model.DateFrom,
DateTo = model.DateTo
});

View File

@ -418,5 +418,18 @@ namespace HardwareShopStorekeeperApp.Controllers
}
return View();
}
[HttpPost]
public List<ReportComponentsViewModel> Report([FromBody] ReportBindingModel reportModel)
{
if (APIClient.User == null)
{
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
}
reportModel.UserId = APIClient.User.Id;
List<ReportComponentsViewModel>? list = APIClient.PostRequestWithResult
<ReportBindingModel, List<ReportComponentsViewModel>>("api/report/componentsreport", reportModel);
return list!;
}
}
}

View File

@ -4,13 +4,71 @@
Layout = "~/Views/Shared/_LayoutStorekeeper.cshtml";
}
<form method="post" class="d-flex flex-column align-items-center">
<div class="col-sm-3">
<label class="form-label">С</label>
<input type="date" class="form-control" name="dateFrom">
<label class="form-label">По</label>
<input type="date" class="form-control" name="dateTo">
</div>
<button type="submit" class="btn btn-primary mt-3 px-4">Вывод на страницу</button>
<button type="submit" class="btn btn-primary mt-3 px-4">Отправить на почту</button>
</form>
<div class="d-flex flex-column align-items-center">
<div class="col-sm-3">
<label class="form-label">С</label>
<input type="date" class="form-control" name="dateFrom" id="dateFrom">
<label class="form-label">По</label>
<input type="date" class="form-control" name="dateTo" id="dateTo">
</div>
<button type="submit" class="btn btn-primary mt-3 px-4" id="page">Вывод на страницу</button>
<button type="submit" class="btn btn-primary mt-3 px-4" id="mail">Отправить на почту</button>
</div>
<table class="table">
<thead>
<tr>
<th scope="col">Комплектующее</th>
<th scope="col">Товар/Сборка</th>
<th scope="col">Количество</th>
</tr>
</thead>
<tbody id="result">
</tbody>
</table>
@section Scripts
{
<script>
let list = []
const from = document.getElementById("dateFrom");
const to = document.getElementById("dateTo");
const onpage = document.getElementById("page");
const onmail = document.getElementById("mail");
const resultTable = document.getElementById("result");
onpage.addEventListener("click", () => {
console.log('try to get report')
if (from.value && to.value && from.value !== '' && to.value !== '') {
const dateFrom = new Date(from.value);
const dateTo = new Date(to.value);
const reportModel = { "DateFrom": dateFrom, "DateTo": dateTo }
$.ajax({
method: "POST",
contentType: "application/json",
url: `/Storekeeper/Report`,
data: JSON.stringify(reportModel),
success: function (result) {
list = result
console.log(list)
reloadTable()
}
}).fail(function(xhr, textStatus, errorThrown) {
alert(xhr.responseText);
})
} else { alert("empty fields") }
})
function reloadTable() {
resultString = '';
list.forEach((elem) => {
resultString += `<tr><td>${elem.componentName}</td><td></td><td></td></tr>`;
elem.goodOrBuilds.forEach((goodOrBuild) => {
resultString += `<tr><td></td><td>${goodOrBuild.item1}</td><td>${goodOrBuild.item2}</td></tr>`;
})
resultString += `<tr><td>Итого</td><td></td><td>${elem.totalCount}</td></tr>`;
})
resultTable.innerHTML = resultString
}
</script>
}

View File

@ -4,6 +4,8 @@
{
public string FileName { get; set; } = string.Empty;
public int UserId { get; set; }
public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; }

View File

@ -18,7 +18,7 @@ namespace HardwareShopContracts.BusinessLogicsContracts
/// <param name="model"></param>
/// <param name="user"></param>
/// <returns></returns>
List<ReportComponentsViewModel> GetComponents(UserBindingModel user, ReportBindingModel model);
List<ReportComponentsViewModel> GetComponents(ReportBindingModel model);
/// <summary>
/// Сохранение списка сборок по выбранным товарам в файл-Word

View File

@ -1,5 +1,6 @@
using HardwareShopContracts.BindingModels;
using HardwareShopContracts.BusinessLogicsContracts;
using HardwareShopContracts.ViewModels;
using Microsoft.AspNetCore.Mvc;
namespace HardwareShopRestApi.Controllers
@ -40,7 +41,22 @@ namespace HardwareShopRestApi.Controllers
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка сохранения списка сборок по выбранным товарам");
_logger.LogError(ex, "Ошибка получения списка сборок по выбранным товарам");
throw;
}
}
[HttpPost]
public List<ReportComponentsViewModel>? ComponentsReport(ReportBindingModel model)
{
try
{
var list = _reportStorekeeperLogic.GetComponents(model);
return list;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения сведений по полученным пользователем комплектующим за период");
throw;
}
}