логика отчета по оплатам за работы
This commit is contained in:
parent
148abdfb8e
commit
168611ec1d
@ -10,15 +10,21 @@ namespace CarServiceBusinessLogic.BusinessLogics
|
|||||||
{
|
{
|
||||||
//private readonly ILogger _logger;
|
//private readonly ILogger _logger;
|
||||||
private readonly IWorkStorage _workStorage;
|
private readonly IWorkStorage _workStorage;
|
||||||
public ReportLogic(/*ILogger logger,*/ IWorkStorage workStorage)
|
private readonly IWorkPaymentStorage _workPaymentStorage;
|
||||||
|
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)
|
||||||
{
|
{
|
||||||
return _workStorage.GetWorksWithRequest(new() { SelectedWorksIds = model.SelectedWorks });
|
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)
|
public void SaveComponentsToWordFile(ReportBindingModel model)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
|
@ -15,7 +15,7 @@ namespace CarServiceContracts.BusinessLogicsContracts
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="model"></param>
|
/// <param name="model"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
//List<ReportOrdersViewModel> GetPayments(ReportBindingModel model);
|
List<ReportWorksWithPaymentsViewModel> GetPayments(ReportBindingModel model);
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Сохранение компонент в файл-Word
|
/// Сохранение компонент в файл-Word
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -3,5 +3,7 @@
|
|||||||
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; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,5 +12,6 @@ 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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.StorageContracts;
|
||||||
using CarServiceContracts.ViewModels;
|
using CarServiceContracts.ViewModels;
|
||||||
using CarServiceDatabase.Models;
|
using CarServiceDatabase.Models;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace CarServiceDatabase.Implements
|
namespace CarServiceDatabase.Implements
|
||||||
{
|
{
|
||||||
@ -37,6 +38,35 @@ 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();
|
||||||
|
@ -59,30 +59,21 @@ namespace CarServiceDatabase.Implements
|
|||||||
.Select(w => new ReportWorkWithRequestsViewModel()
|
.Select(w => new ReportWorkWithRequestsViewModel()
|
||||||
{
|
{
|
||||||
WorkName = w.Name,
|
WorkName = w.Name,
|
||||||
RepairRequests = GetRepairRequestsByWork(context, new() { Id = w.Id })
|
RepairRequests = context.WorksInRequest
|
||||||
})
|
.Include(wir => wir.RepairRequest)
|
||||||
.ToList();
|
.ThenInclude(rr => rr.Vehicle)
|
||||||
}
|
.ThenInclude(v => v.Customer)
|
||||||
/// <summary>
|
.Where(wir => wir.WorkId == w.Id)
|
||||||
/// Получение списка заявок по выбранной работе
|
.Select(wir => new ReportRepairRequestViewModel()
|
||||||
/// </summary>
|
{
|
||||||
/// <param name="model"></param>
|
RepairRequestId = wir.RepairRequest.Id,
|
||||||
/// <returns></returns>
|
RepairRequestDateCreated = wir.RepairRequest.DateCreated,
|
||||||
private static List<ReportRepairRequestViewModel> GetRepairRequestsByWork(CarServiceDbContext context, WorkSearchModel model)
|
CustomerName = wir.RepairRequest.Vehicle.Customer.Name,
|
||||||
{
|
VehicleName = wir.RepairRequest.Vehicle.Name,
|
||||||
return context.WorksInRequest
|
Plate = wir.RepairRequest.Vehicle.Plate ?? "[отсутствует]",
|
||||||
.Include(wir => wir.RepairRequest)
|
WorksCount = wir.Count
|
||||||
.ThenInclude(rr => rr.Vehicle)
|
})
|
||||||
.ThenInclude(v => v.Customer)
|
.ToList()
|
||||||
.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();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user