diff --git a/CarService/CarServiceBusinessLogic/BusinessLogics/ReportLogic.cs b/CarService/CarServiceBusinessLogic/BusinessLogics/ReportLogic.cs index ea1c933..b23867e 100644 --- a/CarService/CarServiceBusinessLogic/BusinessLogics/ReportLogic.cs +++ b/CarService/CarServiceBusinessLogic/BusinessLogics/ReportLogic.cs @@ -11,7 +11,7 @@ namespace CarServiceBusinessLogic.BusinessLogics private readonly ILogger _logger; private readonly IWorkStorage _workStorage; private readonly IWorkPaymentStorage _workPaymentStorage; - public ReportLogic(ILogger logger, IWorkStorage workStorage, IWorkPaymentStorage workPaymentStorage) + public ReportLogic(ILogger logger, IWorkStorage workStorage, IWorkPaymentStorage workPaymentStorage) { _logger = logger; _workStorage = workStorage; diff --git a/CarService/CarServiceContracts/ViewModels/ReportWorksWithPaymentsViewModel.cs b/CarService/CarServiceContracts/ViewModels/ReportWorksWithPaymentsViewModel.cs index f6e726e..75552c8 100644 --- a/CarService/CarServiceContracts/ViewModels/ReportWorksWithPaymentsViewModel.cs +++ b/CarService/CarServiceContracts/ViewModels/ReportWorksWithPaymentsViewModel.cs @@ -23,10 +23,18 @@ /// public string WorkName { get; set; } = string.Empty; /// + /// Цена работы + /// + public decimal WorkPrice { get; set; } + /// /// Количество работ /// public int Count { get; set; } /// + /// Общая сумма + /// + public decimal TotalSum { get; set; } + /// /// Внесенная сумма /// public decimal PaymentSum { get; set; } @@ -35,7 +43,7 @@ /// public decimal Paid { get; set; } /// - /// Всего не оплачено + /// Осталось оплатить /// public decimal NotPaid { get; set; } } diff --git a/CarService/CarServiceDatabase/Implements/WorkPaymentStorage.cs b/CarService/CarServiceDatabase/Implements/WorkPaymentStorage.cs index e36dfd8..6f52903 100644 --- a/CarService/CarServiceDatabase/Implements/WorkPaymentStorage.cs +++ b/CarService/CarServiceDatabase/Implements/WorkPaymentStorage.cs @@ -50,6 +50,8 @@ namespace CarServiceDatabase.Implements .ThenInclude(wir => wir.RepairRequest) .ThenInclude(rr => rr.Vehicle) .ThenInclude(v => v.Customer) + .Include(wp => wp.WorkInRequest) + .ThenInclude(wp => wp.Work) .Where(wp => wp.DatePayment >= model.DateFrom && wp.DatePayment <= model.DateTo) .Select(wp => new ReportWorksWithPaymentsViewModel() { @@ -59,9 +61,11 @@ namespace CarServiceDatabase.Implements VehicleNameAndPlate = wp.WorkInRequest.RepairRequest.Vehicle.Name + " " + wp.WorkInRequest.RepairRequest.Vehicle.Plate, WorkName = wp.WorkInRequest.Work.Name, Count = wp.WorkInRequest.Count, + WorkPrice = wp.WorkInRequest.Work.Price, + TotalSum = Convert.ToDecimal(wp.WorkInRequest.Count * wp.WorkInRequest.Work.Price), PaymentSum = wp.Sum, Paid = context.WorkPayments.Where(x => x.WorkInRequestId == wp.WorkInRequestId).Select(x => x.Sum).Sum(), - NotPaid = context.WorksInRequest.Where(y => y.RepairRequestId == wp.WorkInRequest.RepairRequestId).Select(z => z.Cost).Sum() - context.WorkPayments.Where(x => x.WorkInRequestId == wp.WorkInRequestId).Select(x => x.Sum).Sum() + NotPaid = Convert.ToDecimal(wp.WorkInRequest.Count * wp.WorkInRequest.Work.Price - context.WorkPayments.Where(x => x.WorkInRequestId == wp.WorkInRequestId).Select(x => x.Sum).Sum()) }) .ToList(); } diff --git a/CarService/CarServiceWebApp/Controllers/ReportController.cs b/CarService/CarServiceWebApp/Controllers/ReportController.cs new file mode 100644 index 0000000..fb4b341 --- /dev/null +++ b/CarService/CarServiceWebApp/Controllers/ReportController.cs @@ -0,0 +1,79 @@ +using CarServiceContracts.BindingModels; +using CarServiceContracts.BusinessLogicsContracts; +using CarServiceWebApp.Models; +using Microsoft.AspNetCore.Mvc; + +namespace CarServiceWebApp.Controllers +{ + public class ReportController : Controller + { + private readonly IReportLogic _reportLogic; + private readonly IWorkLogic _workLogic; + private static List SelectedWorks = new(); + private static ReportBindingModel PaymentsModel = new(); + + + public ReportController(IReportLogic reportLogic, IWorkLogic workLogic) + { + _reportLogic = reportLogic; + _workLogic = workLogic; + } + + public IActionResult Index() + { + if (CurrentUser.UserId < 1) + { + return Redirect("~/Home/Enter"); + } + return View(); + } + public IActionResult ReportRequestsByWorks() + { + if (CurrentUser.UserId < 1) + { + return Redirect("~/Home/Enter"); + } + var requestsByWorks = _reportLogic.GetRequestsByWorks(new() { SelectedWorks = SelectedWorks } ); + ViewBag.RequestsByWorks = requestsByWorks; + return View(); + } + [HttpGet] + public IActionResult WorksSelection() + { + if (CurrentUser.UserId < 1) + { + return Redirect("~/Home/Enter"); + } + var works = _workLogic.ReadList(new() { Id = CurrentUser.UserId}); + ViewBag.Works = works; + return View(); + } + [HttpPost] + public IActionResult WorksSelection(List selwor) + { + SelectedWorks = selwor; + return Redirect("~/Report/ReportRequestsByWorks"); + } + [HttpGet] + public IActionResult DateSelection() + { + if (CurrentUser.UserId < 1) + { + return Redirect("~/Home/Enter"); + } + return View(); + } + [HttpPost] + public IActionResult DateSelection(DateTime dateFrom, DateTime dateTo) + { + PaymentsModel = new() { DateFrom = dateFrom, DateTo = dateTo }; + return Redirect("~/Report/ReportPayments"); + } + public IActionResult ReportPayments() + { + var payments = _reportLogic.GetPayments(PaymentsModel); + ViewBag.Payments = payments; + return View(); + } + } +} diff --git a/CarService/CarServiceWebApp/Program.cs b/CarService/CarServiceWebApp/Program.cs index fa9562c..25cdde4 100644 --- a/CarService/CarServiceWebApp/Program.cs +++ b/CarService/CarServiceWebApp/Program.cs @@ -22,6 +22,10 @@ builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); + + var app = builder.Build(); // Configure the HTTP request pipeline. diff --git a/CarService/CarServiceWebApp/Views/Report/DateSelection.cshtml b/CarService/CarServiceWebApp/Views/Report/DateSelection.cshtml new file mode 100644 index 0000000..106b245 --- /dev/null +++ b/CarService/CarServiceWebApp/Views/Report/DateSelection.cshtml @@ -0,0 +1,9 @@ +@using CarServiceContracts.BindingModels +@model ReportBindingModel +
+
+ + +
+
+
\ No newline at end of file diff --git a/CarService/CarServiceWebApp/Views/Report/Index.cshtml b/CarService/CarServiceWebApp/Views/Report/Index.cshtml new file mode 100644 index 0000000..e983c77 --- /dev/null +++ b/CarService/CarServiceWebApp/Views/Report/Index.cshtml @@ -0,0 +1,5 @@ +
+

Работы

+

Список заявок по работам

+

Сведения по оплатам

+
\ No newline at end of file diff --git a/CarService/CarServiceWebApp/Views/Report/ReportPayments.cshtml b/CarService/CarServiceWebApp/Views/Report/ReportPayments.cshtml new file mode 100644 index 0000000..12e1022 --- /dev/null +++ b/CarService/CarServiceWebApp/Views/Report/ReportPayments.cshtml @@ -0,0 +1,60 @@ + +
+ @if (ViewBag.Payments.Count != 0) + { + @foreach (var payment in ViewBag.Payments) + { + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Дата оплаты@payment.PaymentDate
Имя и фамилия клиента@payment.CustomerName
Номер заявки@payment.RepairRequestId
Транспортное средство@payment.VehicleNameAndPlate
Работа@payment.WorkName
Количество работ@payment.Count
Общая стоимость работ@payment.TotalSum
Внесенная сумма@payment.PaymentSum
Всего оплачено@payment.Paid
Осталось оплатить@payment.NotPaid
+
+ } + } + else + { +

Нет оплат за указанный период

+ } +
\ No newline at end of file diff --git a/CarService/CarServiceWebApp/Views/Report/ReportRequestsByWorks.cshtml b/CarService/CarServiceWebApp/Views/Report/ReportRequestsByWorks.cshtml new file mode 100644 index 0000000..bfbaed7 --- /dev/null +++ b/CarService/CarServiceWebApp/Views/Report/ReportRequestsByWorks.cshtml @@ -0,0 +1,46 @@ + +
+ @foreach (var rbw in ViewBag.RequestsByWorks) + { +

@rbw.WorkName

+ @if (rbw.RepairRequests.Count != 0) + { + @foreach (var rr in rbw.RepairRequests) + { + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Номер заявки@rr.RepairRequestId
Дата заявки@rr.RepairRequestDateCreated
Клиент@rr.CustomerName
Транспортное средство@rr.VehicleName
Гос. номер@rr.Plate
Количество работ@rr.WorksCount
+
+ } + } + else + { +

Заявок нет

+ } + } +
\ No newline at end of file diff --git a/CarService/CarServiceWebApp/Views/Report/WorksSelection.cshtml b/CarService/CarServiceWebApp/Views/Report/WorksSelection.cshtml new file mode 100644 index 0000000..65c46e4 --- /dev/null +++ b/CarService/CarServiceWebApp/Views/Report/WorksSelection.cshtml @@ -0,0 +1,8 @@ +@model List +
+ @foreach (var work in ViewBag.Works) + { +

@work.Name

+ } +
+
\ No newline at end of file diff --git a/CarService/CarServiceWebApp/Views/Shared/_Layout.cshtml b/CarService/CarServiceWebApp/Views/Shared/_Layout.cshtml index 673ce29..58ac89e 100644 --- a/CarService/CarServiceWebApp/Views/Shared/_Layout.cshtml +++ b/CarService/CarServiceWebApp/Views/Shared/_Layout.cshtml @@ -29,7 +29,7 @@ Запчасти