логика отчета по оплатам за работы
This commit is contained in:
parent
148abdfb8e
commit
168611ec1d
@ -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<ReportWorkWithRequestsViewModel> GetRequestsByWorks(ReportBindingModel model)
|
||||
{
|
||||
return _workStorage.GetWorksWithRequest(new() { SelectedWorksIds = model.SelectedWorks });
|
||||
}
|
||||
public List<ReportWorksWithPaymentsViewModel> GetPayments(ReportBindingModel model)
|
||||
{
|
||||
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<ReportOrdersViewModel> GetPayments(ReportBindingModel model);
|
||||
List<ReportWorksWithPaymentsViewModel> GetPayments(ReportBindingModel model);
|
||||
/// <summary>
|
||||
/// Сохранение компонент в файл-Word
|
||||
/// </summary>
|
||||
|
@ -3,5 +3,7 @@
|
||||
public class WorkPaymentSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public DateTime? DateFrom { get; set; }
|
||||
public DateTime? DateTo { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -12,5 +12,6 @@ namespace CarServiceContracts.StorageContracts
|
||||
WorkPaymentViewModel? Insert(WorkPaymentBindingModel model);
|
||||
WorkPaymentViewModel? Update(WorkPaymentBindingModel model);
|
||||
WorkPaymentViewModel? Delete(WorkPaymentBindingModel model);
|
||||
List<ReportWorksWithPaymentsViewModel> GetPaymentsByWorks(WorkPaymentSearchModel model);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,42 @@
|
||||
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,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<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,22 +59,11 @@ namespace CarServiceDatabase.Implements
|
||||
.Select(w => new ReportWorkWithRequestsViewModel()
|
||||
{
|
||||
WorkName = w.Name,
|
||||
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
|
||||
RepairRequests = context.WorksInRequest
|
||||
.Include(wir => wir.RepairRequest)
|
||||
.ThenInclude(rr => rr.Vehicle)
|
||||
.ThenInclude(v => v.Customer)
|
||||
.Where(wir => wir.WorkId == model.Id)
|
||||
.Where(wir => wir.WorkId == w.Id)
|
||||
.Select(wir => new ReportRepairRequestViewModel()
|
||||
{
|
||||
RepairRequestId = wir.RepairRequest.Id,
|
||||
@ -84,6 +73,8 @@ 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