CourseWork_Bank/Bank/BankClientApp/Views/Home/PurchasesReport.cshtml

88 lines
3.0 KiB
Plaintext
Raw Normal View History

2024-05-01 01:31:46 +04:00
@using BankContracts.ViewModels;
@model List<PurchaseViewModel>
@{
ViewData["Title"] = "Отчет по операциям";
}
<h1>@ViewData["Title"]</h1>
<h5>Выбрать сделки, по которым будут включены в отчет операции</h5>
<div class="text-center">
<a id="reportToWord" href="javascript:void(0)" onclick="reportToWord();">Отчет в word</a>
<a id="reportToExcel" href="javascript:void(0)" onclick="reportToExcel();">Отчет в excel</a>
<table class="table">
<thead>
<tr>
<th>Включить в отчет</th>
<th>Сделка</th>
<th>Номер телефона клиента</th>
<th>Дата</th>
</tr>
</thead>
<tbody>
@foreach (var purchase in Model)
{
<tr>
<td>
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" name="isIncludeInReports" id="@purchase.Id" checked>
</div>
</td>
<td>@purchase.Id</td>
<td>@purchase.ClientPhoneNumber</td>
<td>@purchase.DatePurchase</td>
</tr>
}
</tbody>
</table>
</div>
@section Scripts
{
<script>
jQuery.ajaxSettings.traditional = true;
function getIds() {
const ids = [];
var res = $("input[name=isIncludeInReports]");
for (var i = 0; i < res.length; i++) {
if (res[i].checked) {
ids.push(res[i].id);
}
}
return ids;
}
function downloadFile(data, textStatus, request) {
var a = document.createElement('a');
var url = window.URL.createObjectURL(data);
a.href = url;
a.download = request.getResponseHeader("content-disposition").split(";")[1].split("=")[1];
document.body.append(a);
a.click();
a.remove();
window.URL.revokeObjectURL(url);
}
function reportToWord() {
$.get({
url: '/Home/ReportOperationsInWord',
xhrFields: {
responseType: 'blob'
},
data: { ids: getIds() },
success: downloadFile
});
}
function reportToExcel() {
$.get({
url: '/Home/ReportOperationsInExcel',
xhrFields: {
responseType: 'blob'
},
data: { ids: getIds() },
success: downloadFile
});
}
</script>
}