Compare commits
No commits in common. "7b63e421fc806005f19917ddf36ee34e9958d0af" and "148abdfb8e16519b2ee8f721ffa1cbb0440f0d63" have entirely different histories.
7b63e421fc
...
148abdfb8e
@ -8,25 +8,17 @@ namespace CarServiceBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class ReportLogic : IReportLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
//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)
|
||||
{
|
||||
_logger = logger;
|
||||
//_logger = logger;
|
||||
_workStorage = workStorage;
|
||||
_workPaymentStorage = workPaymentStorage;
|
||||
}
|
||||
public List<ReportWorkWithRequestsViewModel> GetRequestsByWorks(ReportBindingModel model)
|
||||
{
|
||||
_logger.LogInformation("Reading requests by works");
|
||||
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)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
|
@ -15,7 +15,7 @@ namespace CarServiceContracts.BusinessLogicsContracts
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
List<ReportWorksWithPaymentsViewModel> GetPayments(ReportBindingModel model);
|
||||
//List<ReportOrdersViewModel> GetPayments(ReportBindingModel model);
|
||||
/// <summary>
|
||||
/// Сохранение компонент в файл-Word
|
||||
/// </summary>
|
||||
|
@ -3,7 +3,5 @@
|
||||
public class WorkPaymentSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public DateTime? DateFrom { get; set; }
|
||||
public DateTime? DateTo { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,5 @@ namespace CarServiceContracts.StorageContracts
|
||||
WorkPaymentViewModel? Insert(WorkPaymentBindingModel model);
|
||||
WorkPaymentViewModel? Update(WorkPaymentBindingModel model);
|
||||
WorkPaymentViewModel? Delete(WorkPaymentBindingModel model);
|
||||
List<ReportWorksWithPaymentsViewModel> GetPaymentsByWorks(WorkPaymentSearchModel model);
|
||||
}
|
||||
}
|
||||
|
@ -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; }
|
||||
}
|
||||
}
|
@ -3,7 +3,6 @@ using CarServiceContracts.SearchModels;
|
||||
using CarServiceContracts.StorageContracts;
|
||||
using CarServiceContracts.ViewModels;
|
||||
using CarServiceDatabase.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace CarServiceDatabase.Implements
|
||||
{
|
||||
@ -38,35 +37,6 @@ namespace CarServiceDatabase.Implements
|
||||
}
|
||||
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)
|
||||
{
|
||||
using var context = new CarServiceDbContext();
|
||||
|
@ -59,11 +59,22 @@ namespace CarServiceDatabase.Implements
|
||||
.Select(w => new ReportWorkWithRequestsViewModel()
|
||||
{
|
||||
WorkName = w.Name,
|
||||
RepairRequests = context.WorksInRequest
|
||||
RepairRequests = GetRepairRequestsByWork(context, new() { Id = w.Id })
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение списка заявок по выбранной работе
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
private static List<ReportRepairRequestViewModel> GetRepairRequestsByWork(CarServiceDbContext context, WorkSearchModel model)
|
||||
{
|
||||
return context.WorksInRequest
|
||||
.Include(wir => wir.RepairRequest)
|
||||
.ThenInclude(rr => rr.Vehicle)
|
||||
.ThenInclude(v => v.Customer)
|
||||
.Where(wir => wir.WorkId == w.Id)
|
||||
.Where(wir => wir.WorkId == model.Id)
|
||||
.Select(wir => new ReportRepairRequestViewModel()
|
||||
{
|
||||
RepairRequestId = wir.RepairRequest.Id,
|
||||
@ -73,8 +84,6 @@ namespace CarServiceDatabase.Implements
|
||||
Plate = wir.RepairRequest.Vehicle.Plate ?? "[отсутствует]",
|
||||
WorksCount = wir.Count
|
||||
})
|
||||
.ToList()
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
public WorkViewModel? Insert(WorkBindingModel model)
|
||||
|
Loading…
Reference in New Issue
Block a user