This commit is contained in:
Галина Федоренко 2024-05-30 06:45:25 +04:00
commit 45fd65dbd2
12 changed files with 213 additions and 134 deletions

View File

@ -25,8 +25,8 @@ namespace LawFirmBusinessLogic.MailWorker
objMailMessage.Body = info.Text;
objMailMessage.SubjectEncoding = Encoding.UTF8;
objMailMessage.BodyEncoding = Encoding.UTF8;
Attachment attachment = new Attachment("E:\\reports\\pdf\\file.pdf", new ContentType(MediaTypeNames.Application.Pdf));
//Attachment attachment = new Attachment("D:\\CourseWork\\pdffile.pdf", new ContentType(MediaTypeNames.Application.Pdf));
//Attachment attachment = new Attachment("E:\\reports\\pdf\\file.pdf", new ContentType(MediaTypeNames.Application.Pdf));
Attachment attachment = new Attachment("D:\\CourseWork\\pdffile.pdf", new ContentType(MediaTypeNames.Application.Pdf));
objMailMessage.Attachments.Add(attachment);
objSmtpClient.UseDefaultCredentials = false;

View File

@ -10,6 +10,6 @@ namespace LawFirmContracts.BindingModels
public DateTime DateFrom { get; set; } = DateTime.Now;
public DateTime DateTo { get; set; } = DateTime.Now;
public int? GuarantorId { get; set; }
//public string? Email { get; set; }
public string? Email { get; set; }
}
}

View File

@ -3,6 +3,7 @@ using LawFirmContracts.ViewModels;
using LawFirmGuarantorApp.Models;
using Microsoft.AspNetCore.Mvc;
using System.Diagnostics;
using System.Globalization;
namespace LawFirmGuarantorApp.Controllers
{
@ -146,5 +147,107 @@ namespace LawFirmGuarantorApp.Controllers
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
public IActionResult Report()
{
ViewBag.Report = new List<ReportConsultationHearingBindingModel>();
return View();
}
[HttpGet]
public string GetReport(DateTime dateFrom, DateTime dateTo)
{
if (APIClient.Guarantor == null)
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
List<ReportConsultationHearingViewModel> result;
try
{
string dateFromS = dateFrom.ToString("s", CultureInfo.InvariantCulture);
string dateToS = dateTo.ToString("s", CultureInfo.InvariantCulture);
result = APIClient.GetRequest<List<ReportConsultationHearingViewModel>>
($"api/reportguarantor/getconsultationhearingreport?datefrom={dateFromS}&dateto={dateToS}&guarantorid={APIClient.Guarantor.Id}")!;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания отчета");
throw;
}
string table = "";
table += "<h2 class=\"text-custom-color-1\">Предварительный отчет</h2>";
table += "<div class=\"table-responsive\">";
table += "<table class=\"table table-striped table-bordered table-hover\">";
table += "<thead class=\"table-dark\">";
table += "<tr>";
table += "<th scope=\"col\">Юрист</th>";
table += "<th scope=\"col\">Цена консультации</th>";
table += "<th scope=\"col\">Дата консультации</th>";
table += "<th scope=\"col\">Суд</th>";
table += "<th scope=\"col\">Дата слушания</th>";
table += "</tr>";
table += "</thead>";
foreach (var lawyer in result)
{
table += "<tbody>";
table += "<tr>";
table += $"<td>{lawyer.LawyerName}</td>";
table += $"<td></td>";
table += $"<td></td>";
table += $"<td></td>";
table += $"<td></td>";
table += "</tr>";
foreach (var cons in lawyer.Consultation)
{
table += "<tr>";
table += $"<td></td>";
table += $"<td>{cons.ConsultationDate}</td>";
table += $"<td>{cons.Price}</td>";
table += $"<td></td>";
table += $"<td></td>";
table += "</tr>";
}
foreach (var hear in lawyer.Hearing)
{
table += "<tr>";
table += $"<td></td>";
table += $"<td></td>";
table += $"<td></td>";
table += $"<td>{hear.Judge}</td>";
table += $"<td>{hear.HearingDate}</td>";
table += "</tr>";
}
table += "</tbody>";
}
table += "</table>";
table += "</div>";
return table;
}
[HttpPost]
public void Report(DateTime dateFrom, DateTime dateTo)
{
if (APIClient.Guarantor == null)
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
APIClient.PostRequest("api/reportguarantor/mailsend", new ReportConsultationHearingBindingModel
{
FileName = "D:\\CourseWork\\pdfConsultationHearingsReport.pdf",
GuarantorId = APIClient.Guarantor.Id,
DateFrom = dateFrom,
DateTo = dateTo,
Email = APIClient.Guarantor.Email
});
Response.Redirect("Report");
}
}
}

View File

@ -132,5 +132,35 @@ namespace LawFirmGuarantorApp.Controllers
{
return new PhysicalFileResult("D:\\CourseWork\\excelVisitLawyerReport.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
}
[HttpGet]
public IActionResult SendMail()
{
ViewBag.Lawyers = APIClient.GetRequest<List<LawyerViewModel>>($"api/lawyer/getlawyerlist?guarantorid={APIClient.Guarantor.Id}");
ViewBag.Report = new List<ReportCaseHearingBindingModel>();
return View();
}
[HttpPost]
public void SendMail(DateTime dateFrom, DateTime dateTo, int lawyerId)
{
if (APIClient.Guarantor == null)
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
APIClient.PostRequest("api/reportguarantor/mailsend", new ReportCaseHearingBindingModel
{
//FileName = "C:\\ReportsCourseWork\\pdffile.pdf",
GuarantorId = APIClient.Guarantor.Id,
DateFrom = dateFrom,
DateTo = dateTo,
Email = APIClient.Guarantor.Email,
LawyerId = lawyerId
});
Response.Redirect("SendMail");
}
}
}

View File

@ -1,110 +0,0 @@
using LawFirmContracts.BindingModels;
using LawFirmContracts.ViewModels;
using Microsoft.AspNetCore.Mvc;
using System.Globalization;
namespace LawFirmGuarantorApp.Controllers
{
public class ReportController : Controller
{
private readonly ILogger<ReportController> _logger;
public ReportController(ILogger<ReportController> logger)
{
_logger = logger;
}
[HttpGet]
public IActionResult Report()
{
ViewBag.Report = new List<ReportCaseHearingBindingModel>();
return View();
}
[HttpGet]
public string GetReport(DateTime dateFrom, DateTime dateTo)
{
if (APIClient.Guarantor == null)
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
List<ReportCaseHearingViewModel> result;
try
{
string dateFromS = dateFrom.ToString("s", CultureInfo.InvariantCulture);
string dateToS = dateTo.ToString("s", CultureInfo.InvariantCulture);
result = APIClient.GetRequest<List<ReportCaseHearingViewModel>>
($"api/reportguarantor/getconsultationhearingreport?datefrom={dateFromS}&dateto={dateToS}&guarantorid={APIClient.Guarantor.Id}")!;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания отчета");
throw;
}
string table = "";
table += "<h2 class=\"text-custom-color-1\">Предварительный отчет</h2>";
table += "<div class=\"table-responsive\">";
table += "<table class=\"table table-striped table-bordered table-hover\">";
table += "<thead class=\"table-dark\">";
table += "<tr>";
table += "<th scope=\"col\">Дата</th>";
table += "<th scope=\"col\">Название медикамента</th>";
table += "<th scope=\"col\">Услуга рекомендации</th>";
table += "<th scope=\"col\">Название визита</th>";
table += "</tr>";
table += "</thead>";
foreach (var medicine in result)
{
table += "<tbody>";
table += "<tr>";
table += $"<td></td>";
table += $"<td>{medicine.LawyerName}</td>";
table += $"<td></td>";
table += $"<td></td>";
table += "</tr>";
foreach (var guidance in medicine.Hearing)
{
table += "<tr>";
table += $"<td>{guidance.HearingDate}</td>";
table += $"<td></td>";
table += $"<td>{guidance.HearingDate}</td>";
table += $"<td></td>";
table += "</tr>";
}
foreach (var visit in medicine.Case)
{
table += "<tr>";
table += $"<td>{visit.CaseName}</td>";
table += $"<td></td>";
table += $"<td></td>";
table += $"<td>{visit.CaseType}</td>";
table += "</tr>";
}
table += "</tbody>";
}
table += "</table>";
table += "</div>";
return table;
}
[HttpPost]
public void Report(DateTime dateFrom, DateTime dateTo)
{
if (APIClient.Guarantor == null)
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
APIClient.PostRequest("api/reportguarantor/mailsend", new ReportCaseHearingBindingModel
{
FileName = "D:\\CourseWork\\pdffiletest.pdf",
GuarantorId = APIClient.Guarantor.Id,
DateFrom = dateFrom,
DateTo = dateTo,
Email = APIClient.Guarantor.Email
});
Response.Redirect("Report");
}
}
}

View File

@ -16,6 +16,6 @@
</div>
<div class="row">
<div class="col-8"></div>
<div class="col-4"><input type="submit" value="Вход" class="btn btnprimary" /></div>
<div class="col-4"><input type="submit" value="Вход" class="btn btn-primary" /></div>
</div>
</form>

View File

@ -58,13 +58,13 @@
<td>
<form action="/Hearing/UpdateHearing">
<input type="hidden" name="id" value="@item.Id" />
<button type="submit" class="btn btn-danger">Изменить</button>
<button type="submit" class="btn btn-primary">Изменить</button>
</form>
</td>
<td>
<form action="/Hearing/HearingLawyers">
<input type="hidden" name="id" value="@item.Id" />
<button type="submit" class="btn btn-danger">Юристы</button>
<button type="submit" class="btn btn-secondary">Юристы</button>
</form>
</td>
</tr>

View File

@ -62,7 +62,7 @@
<td>
<form action="/Lawyer/UpdateLawyer">
<input type="hidden" name="id" value="@item.Id" />
<button type="submit" class="btn btn-danger">Изменить</button>
<button type="submit" class="btn btn-primary">Изменить</button>
</form>
</td>
</tr>
@ -72,7 +72,12 @@
<tr>
<td>
<form action="/Lawyer/GetFile">
<button type="submit" class="btn btn-danger">Получить docx/xlsx файл</button>
<button type="submit" class="btn btn-secondary">Получить docx/xlsx файл</button>
</form>
</td>
<td>
<form action="/Lawyer/SendMail">
<button type="submit" class="btn btn-secondary">Отправить отчет на почту</button>
</form>
</td>
</tr>

View File

@ -22,7 +22,7 @@
<div class="col-8"></div>
<div class="col-4">
<input type="submit" value="Регистрация"
class="btn btn-primary" />
class="btn btn-secondary" />
</div>
</div>
</form>

View File

@ -23,13 +23,6 @@
</div>
</div>
<div class="row mb-4">
<div class="col-md-8"></div>
<div class="col-md-4">
<button type="submit" class="btn btn-outline-dark w-100 text-center d-flex justify-content-md-center">Отправить на почту</button>
</div>
</div>
<div class="row mb-4">
<div class="col-md-8"></div>
<div class="col-md-4">

View File

@ -0,0 +1,63 @@
@{
ViewData["Title"] = "SendMail";
}
<div class="container">
<div class="text-center mb-4">
<h2 class="text-custom-color-1">Отправка на почту отчета по юристам с расшифровкой по слушаниям и делам</h2>
</div>
<form method="post">
<div class="row">
<div class="col-4">Юрист:</div>
<div class="col-8">
<select id="lawyerId" name="lawyerId" class="form-control" asp-items="@(new SelectList(@ViewBag.Lawyers,"Id", "FIO"))"></select>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="dateFrom" class="form-label text-custom-color-1">Начало периода:</label>
<input type="datetime-local" id="dateFrom" name="dateFrom" class="form-control" placeholder="Выберите дату начала периода">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="dateTo" class="form-label text-custom-color-1">Окончание периода:</label>
<input type="datetime-local" id="dateTo" name="dateTo" class="form-control" placeholder="Выберите дату окончания периода">
</div>
</div>
</div>
<div class="row mb-4">
<div class="col-md-8"></div>
<div class="col-md-4">
<button type="submit" class="btn btn-outline-dark w-100 text-center d-flex justify-content-md-center">Отправить на почту</button>
</div>
</div>
</form>
</div>
@section Scripts {
<script>
function check() {
var dateFrom = $('#dateFrom').val();
var dateTo = $('#dateTo').val();
if (dateFrom && dateTo) {
$.ajax({
method: "GET",
url: "/Lawyer/SendMail",
data: { dateFrom: dateFrom, dateTo: dateTo },
success: function (result) {
if (result != null) {
$('#report').html(result);
}
}
});
};
}
check();
$('#demonstrate').on('click', (e) => check());
</script>
}

View File

@ -4,6 +4,7 @@ using LawFirmContracts.BindingModels;
using LawFirmContracts.BindingModels.Mails;
using LawFirmContracts.BusinessLogicContracts;
using LawFirmContracts.ViewModels;
using LawFirmDatabaseImplement.Models;
using Microsoft.AspNetCore.Mvc;
namespace LawFirmRestApi.Controllers
@ -126,17 +127,11 @@ namespace LawFirmRestApi.Controllers
}
}
[HttpGet]
public List<ReportConsultationHearingViewModel> GetConsultationHearingReport(string dateFrom, string dateTo, int guarantorId)
public List<ReportConsultationHearingViewModel> GetConsultationHearingReport(DateTime dateFrom, DateTime dateTo, int guarantorId)
{
try
{
DateTime DateFrom = DateTime.Parse(dateFrom);
DateTime DateTo = DateTime.Parse(dateTo);
ReportConsultationHearingBindingModel model = new();
model.DateFrom = DateFrom;
model.DateTo = DateTo;
model.GuarantorId = guarantorId;
return _reportLogic.GetConsultationHearing(model);
return _reportLogic.GetConsultationHearing(new ReportConsultationHearingBindingModel { DateFrom = dateFrom, DateTo = dateTo, GuarantorId = guarantorId});
}
catch (Exception ex)
{