CourseWork_Bank/Bank/BankEmployeeApp/Views/Home/Purchases.cshtml

89 lines
2.9 KiB
Plaintext
Raw Permalink Normal View History

@using BankContracts.ViewModels;
@model List<OperationViewModel>
@{
<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>
<th>Стоимость</th>
</tr>
</thead>
<tbody>
@foreach (var car in Model)
{
<tr>
<td>
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" name="isIncludeInReports" id="@car.Id" checked>
</div>
</td>
<td>@car.EmployeePhoneNumber</td>
<td>@car.Mark</td>
<td>@car.Model</td>
<td>@car.Price</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/ReportPurchasesInWord',
xhrFields: {
responseType: 'blob'
},
data: { ids: getIds() },
success: downloadFile
});
}
function reportToExcel() {
$.get({
url: '/Home/ReportPurchasesInExcel',
xhrFields: {
responseType: 'blob'
},
data: { ids: getIds() },
success: downloadFile
});
}
</script>
}