From 168611ec1d0affe03b870c7c0117c8eb66707604 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: Sat, 8 Apr 2023 14:01:54 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B0=20=D0=BE?= =?UTF-8?q?=D1=82=D1=87=D0=B5=D1=82=D0=B0=20=D0=BF=D0=BE=20=D0=BE=D0=BF?= =?UTF-8?q?=D0=BB=D0=B0=D1=82=D0=B0=D0=BC=20=D0=B7=D0=B0=20=D1=80=D0=B0?= =?UTF-8?q?=D0=B1=D0=BE=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/ReportLogic.cs | 8 +++- .../BusinessLogicsContracts/IReportLogic.cs | 2 +- .../SearchModels/WorkPaymentSearchModel.cs | 2 + .../StorageContracts/IWorkPaymentStorage.cs | 1 + .../ReportWorksWithPaymentsViewModel.cs | 42 +++++++++++++++++++ .../Implements/WorkPaymentStorage.cs | 30 +++++++++++++ .../Implements/WorkStorage.cs | 39 +++++++---------- 7 files changed, 98 insertions(+), 26 deletions(-) create mode 100644 CarService/CarServiceContracts/ViewModels/ReportWorksWithPaymentsViewModel.cs diff --git a/CarService/CarServiceBusinessLogic/BusinessLogics/ReportLogic.cs b/CarService/CarServiceBusinessLogic/BusinessLogics/ReportLogic.cs index 972e9c1..e407dd8 100644 --- a/CarService/CarServiceBusinessLogic/BusinessLogics/ReportLogic.cs +++ b/CarService/CarServiceBusinessLogic/BusinessLogics/ReportLogic.cs @@ -10,15 +10,21 @@ namespace CarServiceBusinessLogic.BusinessLogics { //private readonly ILogger _logger; private readonly IWorkStorage _workStorage; - public ReportLogic(/*ILogger logger,*/ IWorkStorage workStorage) + private readonly IWorkPaymentStorage _workPaymentStorage; + public ReportLogic(/*ILogger logger,*/ IWorkStorage workStorage, IWorkPaymentStorage workPaymentStorage) { //_logger = logger; _workStorage = workStorage; + _workPaymentStorage = workPaymentStorage; } public List GetRequestsByWorks(ReportBindingModel model) { return _workStorage.GetWorksWithRequest(new() { SelectedWorksIds = model.SelectedWorks }); } + public List GetPayments(ReportBindingModel model) + { + return _workPaymentStorage.GetPaymentsByWorks(new() {DateFrom = model.DateFrom, DateTo = model.DateTo }); + } public void SaveComponentsToWordFile(ReportBindingModel model) { throw new NotImplementedException(); diff --git a/CarService/CarServiceContracts/BusinessLogicsContracts/IReportLogic.cs b/CarService/CarServiceContracts/BusinessLogicsContracts/IReportLogic.cs index 859756c..4347eba 100644 --- a/CarService/CarServiceContracts/BusinessLogicsContracts/IReportLogic.cs +++ b/CarService/CarServiceContracts/BusinessLogicsContracts/IReportLogic.cs @@ -15,7 +15,7 @@ namespace CarServiceContracts.BusinessLogicsContracts /// /// /// - //List GetPayments(ReportBindingModel model); + List GetPayments(ReportBindingModel model); /// /// Сохранение компонент в файл-Word /// diff --git a/CarService/CarServiceContracts/SearchModels/WorkPaymentSearchModel.cs b/CarService/CarServiceContracts/SearchModels/WorkPaymentSearchModel.cs index d6c2246..312e96c 100644 --- a/CarService/CarServiceContracts/SearchModels/WorkPaymentSearchModel.cs +++ b/CarService/CarServiceContracts/SearchModels/WorkPaymentSearchModel.cs @@ -3,5 +3,7 @@ public class WorkPaymentSearchModel { public int? Id { get; set; } + public DateTime? DateFrom { get; set; } + public DateTime? DateTo { get; set; } } } diff --git a/CarService/CarServiceContracts/StorageContracts/IWorkPaymentStorage.cs b/CarService/CarServiceContracts/StorageContracts/IWorkPaymentStorage.cs index 2f7f685..ad45abb 100644 --- a/CarService/CarServiceContracts/StorageContracts/IWorkPaymentStorage.cs +++ b/CarService/CarServiceContracts/StorageContracts/IWorkPaymentStorage.cs @@ -12,5 +12,6 @@ namespace CarServiceContracts.StorageContracts WorkPaymentViewModel? Insert(WorkPaymentBindingModel model); WorkPaymentViewModel? Update(WorkPaymentBindingModel model); WorkPaymentViewModel? Delete(WorkPaymentBindingModel model); + List GetPaymentsByWorks(WorkPaymentSearchModel model); } } diff --git a/CarService/CarServiceContracts/ViewModels/ReportWorksWithPaymentsViewModel.cs b/CarService/CarServiceContracts/ViewModels/ReportWorksWithPaymentsViewModel.cs new file mode 100644 index 0000000..f6e726e --- /dev/null +++ b/CarService/CarServiceContracts/ViewModels/ReportWorksWithPaymentsViewModel.cs @@ -0,0 +1,42 @@ +namespace CarServiceContracts.ViewModels +{ + public class ReportWorksWithPaymentsViewModel + { + /// + /// Дата оплаты + /// + public DateTime PaymentDate { get; set; } = DateTime.Now; + /// + /// Имя и фамилия клиента + /// + public string CustomerName { get; set; } = string.Empty; + /// + /// Номер заявки + /// + public int RepairRequestId { get; set; } + /// + /// Название + гос. номер ТС + /// + public string VehicleNameAndPlate { get; set; } = string.Empty; + /// + /// Название работы + /// + public string WorkName { get; set; } = string.Empty; + /// + /// Количество работ + /// + public int Count { get; set; } + /// + /// Внесенная сумма + /// + public decimal PaymentSum { get; set; } + /// + /// Всего оплачено + /// + 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 5bc657a..fda73ba 100644 --- a/CarService/CarServiceDatabase/Implements/WorkPaymentStorage.cs +++ b/CarService/CarServiceDatabase/Implements/WorkPaymentStorage.cs @@ -3,6 +3,7 @@ using CarServiceContracts.SearchModels; using CarServiceContracts.StorageContracts; using CarServiceContracts.ViewModels; using CarServiceDatabase.Models; +using Microsoft.EntityFrameworkCore; namespace CarServiceDatabase.Implements { @@ -37,6 +38,35 @@ namespace CarServiceDatabase.Implements } return null; } + public List GetPaymentsByWorks (WorkPaymentSearchModel model) + { + if (model.DateFrom == null || model.DateTo == null) + { + return new(); + } + using var context = new CarServiceDbContext(); + return context.WorkPayments + .Include(wp => wp.WorkInRequest) + .ThenInclude(wir => wir.Work)//добираемся до названия работы + .Include(wp => wp.WorkInRequest) + .ThenInclude(wir => wir.RepairRequest) + .ThenInclude(rr => rr.Vehicle) + .ThenInclude(v => v.Customer) + .Where(wp => wp.DatePayment >= model.DateFrom && wp.DatePayment <= model.DateTo) + .Select(wp => new ReportWorksWithPaymentsViewModel() + { + PaymentDate = wp.DatePayment, + CustomerName = wp.WorkInRequest.RepairRequest.Vehicle.Customer.Name + " " + wp.WorkInRequest.RepairRequest.Vehicle.Customer.Surname, + RepairRequestId = wp.WorkInRequest.RepairRequest.Id, + VehicleNameAndPlate = wp.WorkInRequest.RepairRequest.Vehicle.Name + " " + wp.WorkInRequest.RepairRequest.Vehicle.Plate, + WorkName = wp.WorkInRequest.Work.Name, + Count = wp.WorkInRequest.Count, + 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() + }) + .ToList(); + } public WorkPaymentViewModel? Insert(WorkPaymentBindingModel model) { using var context = new CarServiceDbContext(); diff --git a/CarService/CarServiceDatabase/Implements/WorkStorage.cs b/CarService/CarServiceDatabase/Implements/WorkStorage.cs index e4cfa28..96a9d09 100644 --- a/CarService/CarServiceDatabase/Implements/WorkStorage.cs +++ b/CarService/CarServiceDatabase/Implements/WorkStorage.cs @@ -59,30 +59,21 @@ namespace CarServiceDatabase.Implements .Select(w => new ReportWorkWithRequestsViewModel() { WorkName = w.Name, - RepairRequests = GetRepairRequestsByWork(context, new() { Id = w.Id }) - }) - .ToList(); - } - /// - /// Получение списка заявок по выбранной работе - /// - /// - /// - private static List GetRepairRequestsByWork(CarServiceDbContext context, WorkSearchModel model) - { - return context.WorksInRequest - .Include(wir => wir.RepairRequest) - .ThenInclude(rr => rr.Vehicle) - .ThenInclude(v => v.Customer) - .Where(wir => wir.WorkId == model.Id) - .Select(wir => new ReportRepairRequestViewModel() - { - RepairRequestId = wir.RepairRequest.Id, - RepairRequestDateCreated = wir.RepairRequest.DateCreated, - CustomerName = wir.RepairRequest.Vehicle.Customer.Name, - VehicleName = wir.RepairRequest.Vehicle.Name, - Plate = wir.RepairRequest.Vehicle.Plate ?? "[отсутствует]", - WorksCount = wir.Count + RepairRequests = context.WorksInRequest + .Include(wir => wir.RepairRequest) + .ThenInclude(rr => rr.Vehicle) + .ThenInclude(v => v.Customer) + .Where(wir => wir.WorkId == w.Id) + .Select(wir => new ReportRepairRequestViewModel() + { + RepairRequestId = wir.RepairRequest.Id, + RepairRequestDateCreated = wir.RepairRequest.DateCreated, + CustomerName = wir.RepairRequest.Vehicle.Customer.Name, + VehicleName = wir.RepairRequest.Vehicle.Name, + Plate = wir.RepairRequest.Vehicle.Plate ?? "[отсутствует]", + WorksCount = wir.Count + }) + .ToList() }) .ToList(); }