Compare commits

..

No commits in common. "7b63e421fc806005f19917ddf36ee34e9958d0af" and "148abdfb8e16519b2ee8f721ffa1cbb0440f0d63" have entirely different histories.

7 changed files with 28 additions and 102 deletions

View File

@ -8,25 +8,17 @@ namespace CarServiceBusinessLogic.BusinessLogics
{ {
public class ReportLogic : IReportLogic public class ReportLogic : IReportLogic
{ {
private readonly ILogger _logger; //private readonly ILogger _logger;
private readonly IWorkStorage _workStorage; private readonly IWorkStorage _workStorage;
private readonly IWorkPaymentStorage _workPaymentStorage; public ReportLogic(/*ILogger logger,*/ IWorkStorage workStorage)
public ReportLogic(ILogger logger, IWorkStorage workStorage, IWorkPaymentStorage workPaymentStorage)
{ {
_logger = logger; //_logger = logger;
_workStorage = workStorage; _workStorage = workStorage;
_workPaymentStorage = workPaymentStorage;
} }
public List<ReportWorkWithRequestsViewModel> GetRequestsByWorks(ReportBindingModel model) public List<ReportWorkWithRequestsViewModel> GetRequestsByWorks(ReportBindingModel model)
{ {
_logger.LogInformation("Reading requests by works");
return _workStorage.GetWorksWithRequest(new() { SelectedWorksIds = model.SelectedWorks }); return _workStorage.GetWorksWithRequest(new() { SelectedWorksIds = model.SelectedWorks });
} }
public List<ReportWorksWithPaymentsViewModel> GetPayments(ReportBindingModel model)
{
_logger.LogInformation("Reading payments by works in requests");
return _workPaymentStorage.GetPaymentsByWorks(new() {DateFrom = model.DateFrom, DateTo = model.DateTo });
}
public void SaveComponentsToWordFile(ReportBindingModel model) public void SaveComponentsToWordFile(ReportBindingModel model)
{ {
throw new NotImplementedException(); throw new NotImplementedException();

View File

@ -15,7 +15,7 @@ namespace CarServiceContracts.BusinessLogicsContracts
/// </summary> /// </summary>
/// <param name="model"></param> /// <param name="model"></param>
/// <returns></returns> /// <returns></returns>
List<ReportWorksWithPaymentsViewModel> GetPayments(ReportBindingModel model); //List<ReportOrdersViewModel> GetPayments(ReportBindingModel model);
/// <summary> /// <summary>
/// Сохранение компонент в файл-Word /// Сохранение компонент в файл-Word
/// </summary> /// </summary>

View File

@ -3,7 +3,5 @@
public class WorkPaymentSearchModel public class WorkPaymentSearchModel
{ {
public int? Id { get; set; } public int? Id { get; set; }
public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; }
} }
} }

View File

@ -12,6 +12,5 @@ namespace CarServiceContracts.StorageContracts
WorkPaymentViewModel? Insert(WorkPaymentBindingModel model); WorkPaymentViewModel? Insert(WorkPaymentBindingModel model);
WorkPaymentViewModel? Update(WorkPaymentBindingModel model); WorkPaymentViewModel? Update(WorkPaymentBindingModel model);
WorkPaymentViewModel? Delete(WorkPaymentBindingModel model); WorkPaymentViewModel? Delete(WorkPaymentBindingModel model);
List<ReportWorksWithPaymentsViewModel> GetPaymentsByWorks(WorkPaymentSearchModel model);
} }
} }

View File

@ -1,42 +0,0 @@
namespace CarServiceContracts.ViewModels
{
public class ReportWorksWithPaymentsViewModel
{
/// <summary>
/// Дата оплаты
/// </summary>
public DateTime PaymentDate { get; set; } = DateTime.Now;
/// <summary>
/// Имя и фамилия клиента
/// </summary>
public string CustomerName { get; set; } = string.Empty;
/// <summary>
/// Номер заявки
/// </summary>
public int RepairRequestId { get; set; }
/// <summary>
/// Название + гос. номер ТС
/// </summary>
public string VehicleNameAndPlate { get; set; } = string.Empty;
/// <summary>
/// Название работы
/// </summary>
public string WorkName { get; set; } = string.Empty;
/// <summary>
/// Количество работ
/// </summary>
public int Count { get; set; }
/// <summary>
/// Внесенная сумма
/// </summary>
public decimal PaymentSum { get; set; }
/// <summary>
/// Всего оплачено
/// </summary>
public decimal Paid { get; set; }
/// <summary>
/// Всего не оплачено
/// </summary>
public decimal NotPaid { get; set; }
}
}

View File

@ -3,7 +3,6 @@ using CarServiceContracts.SearchModels;
using CarServiceContracts.StorageContracts; using CarServiceContracts.StorageContracts;
using CarServiceContracts.ViewModels; using CarServiceContracts.ViewModels;
using CarServiceDatabase.Models; using CarServiceDatabase.Models;
using Microsoft.EntityFrameworkCore;
namespace CarServiceDatabase.Implements namespace CarServiceDatabase.Implements
{ {
@ -38,35 +37,6 @@ namespace CarServiceDatabase.Implements
} }
return null; return null;
} }
public List<ReportWorksWithPaymentsViewModel> 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) public WorkPaymentViewModel? Insert(WorkPaymentBindingModel model)
{ {
using var context = new CarServiceDbContext(); using var context = new CarServiceDbContext();

View File

@ -59,21 +59,30 @@ namespace CarServiceDatabase.Implements
.Select(w => new ReportWorkWithRequestsViewModel() .Select(w => new ReportWorkWithRequestsViewModel()
{ {
WorkName = w.Name, WorkName = w.Name,
RepairRequests = context.WorksInRequest RepairRequests = GetRepairRequestsByWork(context, new() { Id = w.Id })
.Include(wir => wir.RepairRequest) })
.ThenInclude(rr => rr.Vehicle) .ToList();
.ThenInclude(v => v.Customer) }
.Where(wir => wir.WorkId == w.Id) /// <summary>
.Select(wir => new ReportRepairRequestViewModel() /// Получение списка заявок по выбранной работе
{ /// </summary>
RepairRequestId = wir.RepairRequest.Id, /// <param name="model"></param>
RepairRequestDateCreated = wir.RepairRequest.DateCreated, /// <returns></returns>
CustomerName = wir.RepairRequest.Vehicle.Customer.Name, private static List<ReportRepairRequestViewModel> GetRepairRequestsByWork(CarServiceDbContext context, WorkSearchModel model)
VehicleName = wir.RepairRequest.Vehicle.Name, {
Plate = wir.RepairRequest.Vehicle.Plate ?? "[отсутствует]", return context.WorksInRequest
WorksCount = wir.Count .Include(wir => wir.RepairRequest)
}) .ThenInclude(rr => rr.Vehicle)
.ToList() .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
}) })
.ToList(); .ToList();
} }