add demonstrating pdf report in view
This commit is contained in:
parent
a4942de30e
commit
ed31093f33
@ -6,6 +6,7 @@ using BankDataModels.Models;
|
||||
using BankManagersClientApp.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
|
||||
namespace BankManagersClientApp.Controllers
|
||||
{
|
||||
@ -528,11 +529,152 @@ namespace BankManagersClientApp.Controllers
|
||||
Email = APIClient.Client.Email,
|
||||
});
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
#region//Error
|
||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||
[HttpGet]
|
||||
public string GetTransfersWithdrawals(DateTime dateFrom, DateTime dateTo)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||
}
|
||||
List<ReportTransfersWithdrawalsViewModel> result;
|
||||
try
|
||||
{
|
||||
string dateFromS = dateFrom.ToString("s", CultureInfo.InvariantCulture);
|
||||
string dateToS = dateTo.ToString("s", CultureInfo.InvariantCulture);
|
||||
result = APIClient.GetRequest<List<ReportTransfersWithdrawalsViewModel>>
|
||||
($"api/report/gettransferswithdrawals?datefrom={dateFromS}&dateto={dateToS}")!;
|
||||
}
|
||||
catch
|
||||
{
|
||||
_logger.LogError("Ошибка создания отчета");
|
||||
throw;
|
||||
}
|
||||
//sender transfers
|
||||
string senderTransfersTable = "";
|
||||
senderTransfersTable += "<h2 class=\"text-custom-color-1\">Переводы на другие счета</h2>";
|
||||
senderTransfersTable += "<div class=\"table-responsive\">";
|
||||
senderTransfersTable += "<table class=\"table table-striped table-bordered table-hover\">";
|
||||
senderTransfersTable += "<thead class=\"table-dark\">";
|
||||
senderTransfersTable += "<tr>";
|
||||
senderTransfersTable += "<th scope=\"col\">Номер счёта</th>";
|
||||
senderTransfersTable += "<th scope=\"col\">Номер перевода</th>";
|
||||
senderTransfersTable += "<th scope=\"col\">Время перевода</th>";
|
||||
senderTransfersTable += "<th scope=\"col\">Сумма</th>";
|
||||
senderTransfersTable += "<th scope=\"col\">Номер счёта получателя</th>";
|
||||
senderTransfersTable += "</tr>";
|
||||
senderTransfersTable += "</thead>";
|
||||
senderTransfersTable += "<tbody>";
|
||||
foreach (var report in result)
|
||||
{
|
||||
senderTransfersTable += "<tr>";
|
||||
senderTransfersTable += $"<td>{report.AccountNumber}</td>";
|
||||
senderTransfersTable += $"<td></td>";
|
||||
senderTransfersTable += $"<td></td>";
|
||||
senderTransfersTable += $"<td></td>";
|
||||
senderTransfersTable += $"<td></td>";
|
||||
senderTransfersTable += "</tr>";
|
||||
foreach (var senderTransfer in report.SenderTransfers)
|
||||
{
|
||||
senderTransfersTable += "<tr>";
|
||||
senderTransfersTable += $"<td></td>";
|
||||
senderTransfersTable += $"<td>{senderTransfer.Id}</td>";
|
||||
senderTransfersTable += $"<td>{senderTransfer.TransferTime}</td>";
|
||||
senderTransfersTable += $"<td>{senderTransfer.Sum}</td>";
|
||||
senderTransfersTable += $"<td>{senderTransfer.RecipientAccountNumber}</td>";
|
||||
senderTransfersTable += "</tr>";
|
||||
}
|
||||
}
|
||||
senderTransfersTable += "</tbody>";
|
||||
senderTransfersTable += "</table>";
|
||||
senderTransfersTable += "</div>";
|
||||
//recipient transfers
|
||||
string recipientTransfersTable = "";
|
||||
recipientTransfersTable += "<h2 class=\"text-custom-color-1\">Переводы с других счетов</h2>";
|
||||
recipientTransfersTable += "<div class=\"table-responsive\">";
|
||||
recipientTransfersTable += "<table class=\"table table-striped table-bordered table-hover\">";
|
||||
recipientTransfersTable += "<thead class=\"table-dark\">";
|
||||
recipientTransfersTable += "<tr>";
|
||||
recipientTransfersTable += "<th scope=\"col\">Номер счёта</th>";
|
||||
recipientTransfersTable += "<th scope=\"col\">Номер перевода</th>";
|
||||
recipientTransfersTable += "<th scope=\"col\">Время перевода</th>";
|
||||
recipientTransfersTable += "<th scope=\"col\">Сумма</th>";
|
||||
recipientTransfersTable += "<th scope=\"col\">Номер счёта отправителя</th>";
|
||||
recipientTransfersTable += "</tr>";
|
||||
recipientTransfersTable += "</thead>";
|
||||
recipientTransfersTable += "<tbody>";
|
||||
foreach (var report in result)
|
||||
{
|
||||
recipientTransfersTable += "<tr>";
|
||||
recipientTransfersTable += $"<td>{report.AccountNumber}</td>";
|
||||
recipientTransfersTable += $"<td></td>";
|
||||
recipientTransfersTable += $"<td></td>";
|
||||
recipientTransfersTable += $"<td></td>";
|
||||
recipientTransfersTable += $"<td></td>";
|
||||
recipientTransfersTable += "</tr>";
|
||||
foreach (var recipientTransfer in report.RecipientTransfers)
|
||||
{
|
||||
recipientTransfersTable += "<tr>";
|
||||
recipientTransfersTable += $"<td></td>";
|
||||
recipientTransfersTable += $"<td>{recipientTransfer.Id}</td>";
|
||||
recipientTransfersTable += $"<td>{recipientTransfer.TransferTime}</td>";
|
||||
recipientTransfersTable += $"<td>{recipientTransfer.Sum}</td>";
|
||||
recipientTransfersTable += $"<td>{recipientTransfer.SenderAccountNumber}</td>";
|
||||
recipientTransfersTable += "</tr>";
|
||||
}
|
||||
}
|
||||
recipientTransfersTable += "</tbody>";
|
||||
recipientTransfersTable += "</table>";
|
||||
recipientTransfersTable += "</div>";
|
||||
//withdrawals
|
||||
string withdrawalsTable = "";
|
||||
withdrawalsTable += "<h2 class=\"text-custom-color-1\">Выдачи наличных</h2>";
|
||||
withdrawalsTable += "<div class=\"table-responsive\">";
|
||||
withdrawalsTable += "<table class=\"table table-striped table-bordered table-hover\">";
|
||||
withdrawalsTable += "<thead class=\"table-dark\">";
|
||||
withdrawalsTable += "<tr>";
|
||||
withdrawalsTable += "<th scope=\"col\">Номер счёта</th>";
|
||||
withdrawalsTable += "<th scope=\"col\">Номер выдачи</th>";
|
||||
withdrawalsTable += "<th scope=\"col\">Время выдачи</th>";
|
||||
withdrawalsTable += "<th scope=\"col\">Сумма</th>";
|
||||
withdrawalsTable += "</tr>";
|
||||
withdrawalsTable += "</thead>";
|
||||
withdrawalsTable += "<tbody>";
|
||||
foreach (var report in result)
|
||||
{
|
||||
withdrawalsTable += "<tr>";
|
||||
withdrawalsTable += $"<td>{report.AccountNumber}</td>";
|
||||
withdrawalsTable += $"<td></td>";
|
||||
withdrawalsTable += $"<td></td>";
|
||||
withdrawalsTable += $"<td></td>";
|
||||
withdrawalsTable += "</tr>";
|
||||
foreach (var withdrawal in report.Withdrawals)
|
||||
{
|
||||
withdrawalsTable += "<tr>";
|
||||
withdrawalsTable += $"<td></td>";
|
||||
withdrawalsTable += $"<td>{withdrawal.Id}</td>";
|
||||
withdrawalsTable += $"<td>{withdrawal.WithdrawalTime}</td>";
|
||||
withdrawalsTable += $"<td>{withdrawal.Sum}</td>";
|
||||
withdrawalsTable += "</tr>";
|
||||
}
|
||||
}
|
||||
withdrawalsTable += "</tbody>";
|
||||
withdrawalsTable += "</table>";
|
||||
withdrawalsTable += "</div>";
|
||||
//title
|
||||
string tables = "";
|
||||
tables += "<h2 class=\"text-custom-color-1\">Отчет по счетам</h2>";
|
||||
tables += $"<div class=\"text-custom-color-1\">с {dateFrom.ToShortDateString()} по {dateTo.ToShortDateString()}</div>";
|
||||
tables += senderTransfersTable;
|
||||
tables += recipientTransfersTable;
|
||||
tables += withdrawalsTable;
|
||||
return tables;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region//Error
|
||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||
public IActionResult Error()
|
||||
{
|
||||
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
||||
|
@ -17,24 +17,36 @@
|
||||
<input type="date" id="dateTo" name="dateTo" class="form-control">
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="row mb-2">
|
||||
<div class="col-8"></div>
|
||||
<div class="col-4"><input value="Создать отчет" class="btn btn-primary" /></div>
|
||||
<div class="col-4"><input id="demonstrate" value="Создать отчет" class="btn btn-primary" /></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-8"></div>
|
||||
<div class="col-4"><input type="submit" value="Отправить на почту" class="btn btn-primary" /></div>
|
||||
</div>
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Номер</th>
|
||||
<th>Дата</th>
|
||||
<th>Счёт</th>
|
||||
<th>Перевод</th>
|
||||
<th>Выдача</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody></tbody>
|
||||
</table>
|
||||
</form>
|
||||
<div id="report"></div>
|
||||
</form>
|
||||
|
||||
@section Scripts {
|
||||
<script>
|
||||
function check() {
|
||||
var dateFrom = $('#dateFrom').val();
|
||||
var dateTo = $('#dateTo').val();
|
||||
if (dateFrom && dateTo) {
|
||||
$.ajax({
|
||||
method: "GET",
|
||||
url: "/Home/GetTransfersWithdrawals",
|
||||
data: { dateFrom: dateFrom, dateTo: dateTo },
|
||||
success: function (result) {
|
||||
if (result != null) {
|
||||
$('#report').html(result);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
check();
|
||||
$('#demonstrate').on('click', (e) => check());
|
||||
</script>
|
||||
}
|
@ -1,6 +1,8 @@
|
||||
using BankBusinessLogic.MailWorker;
|
||||
using BankContracts.BindingModels;
|
||||
using BankContracts.BusinessLogicsContracts;
|
||||
using BankContracts.SearchModels;
|
||||
using BankContracts.ViewModels;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace BankRestApi.Controllers
|
||||
@ -111,5 +113,24 @@ namespace BankRestApi.Controllers
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpGet]
|
||||
public List<ReportTransfersWithdrawalsViewModel> GetTransfersWithdrawals(string dateFrom, string dateTo)
|
||||
{
|
||||
try
|
||||
{
|
||||
DateTime DateFrom = DateTime.Parse(dateFrom);
|
||||
DateTime DateTo = DateTime.Parse(dateTo);
|
||||
return _logic.CreateReportTransfersWithdrawals(new AccountSearchModel
|
||||
{
|
||||
DateFrom = DateFrom,
|
||||
DateTo = DateTo,
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка сохранения счетов в pdf");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user