From 79527c933a861c23710fb7fa2eeb0767c766430d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=BA=20=D0=98=D0=B3=D0=BE=D1=80=D1=8C?= Date: Thu, 25 May 2023 20:53:47 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B2=D1=8B=D0=B2=D0=BE=D0=B4=20=D0=BE=D1=82?= =?UTF-8?q?=D1=87=D0=B5=D1=82=D0=BE=D0=B2=20=D0=BD=D0=B0=20=D1=84=D0=BE?= =?UTF-8?q?=D1=80=D0=BC=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/ReportLogic.cs | 2 +- .../ReportWorksWithPaymentsViewModel.cs | 10 ++- .../Implements/WorkPaymentStorage.cs | 6 +- .../Controllers/ReportController.cs | 79 +++++++++++++++++++ CarService/CarServiceWebApp/Program.cs | 4 + .../Views/Report/DateSelection.cshtml | 9 +++ .../Views/Report/Index.cshtml | 5 ++ .../Views/Report/ReportPayments.cshtml | 60 ++++++++++++++ .../Views/Report/ReportRequestsByWorks.cshtml | 46 +++++++++++ .../Views/Report/WorksSelection.cshtml | 8 ++ .../Views/Shared/_Layout.cshtml | 2 +- 11 files changed, 227 insertions(+), 4 deletions(-) create mode 100644 CarService/CarServiceWebApp/Controllers/ReportController.cs create mode 100644 CarService/CarServiceWebApp/Views/Report/DateSelection.cshtml create mode 100644 CarService/CarServiceWebApp/Views/Report/Index.cshtml create mode 100644 CarService/CarServiceWebApp/Views/Report/ReportPayments.cshtml create mode 100644 CarService/CarServiceWebApp/Views/Report/ReportRequestsByWorks.cshtml create mode 100644 CarService/CarServiceWebApp/Views/Report/WorksSelection.cshtml 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 @@ Запчасти