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(); }