Gaurantor : Reports

This commit is contained in:
Yuee Shiness 2023-04-09 23:13:09 +04:00
parent 2f7dac91e4
commit b37e13575b
8 changed files with 179 additions and 73 deletions

View File

@ -1,67 +0,0 @@
using ComputerStoreContracts.BindingModels;
using ComputerStoreContracts.BusinessLogicContracts;
using ComputerStoreContracts.SearchModels;
using ComputerStoreContracts.StorageContracts;
using ComputerStoreContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace ComputerStoreBusinessLogic.BusinessLogic
{
public class EmployeeReportByDateLogic : IEmployeeReportByDateLogic
{
private readonly IPCStorage _pcStorage;
private readonly IProductStorage _productStorage;
public EmployeeReportByDateLogic(IPCStorage pcStorage, IProductStorage productStorage)
{
_pcStorage = pcStorage;
_productStorage = productStorage;
}
public List<ReportPCByDateViewModel> GetPCs(ReportDateBindingModel model)
{
return _pcStorage.GetFilteredList(new PCSearchModel
{
DateFrom = model.DateFrom,
DateTo = model.DateTo
})
.Select(x => new ReportPCByDateViewModel
{
PCName = x.Name,
Components = x.PCComponents.Values.Select(x => (x.Item1.Name, x.Item2)).ToList(),
EmployeeUsername = x.EmployeeUsername
}).ToList();
}
public List<ReportProductByDateViewModel> GetProducts(ReportDateBindingModel model)
{
return _productStorage.GetFilteredList(new ProductSearchModel
{
DateFrom = model.DateFrom,
DateTo = model.DateTo
})
.Select(x => new ReportProductByDateViewModel
{
ProductName = x.Name,
Components = x.ProductComponents.Values.Select(x => (x.Item1.Name, x.Item2)).ToList()
}).ToList();
}
public void SaveProductsToPdfFile(ReportDateBindingModel model)
{
//will be implemented in the future!
}
public void SavePCsToPdfFile(ReportDateBindingModel model)
{
//will be implemented in the future!
}
}
}

View File

@ -0,0 +1,137 @@
using ComputerStoreContracts.BindingModels;
using ComputerStoreContracts.BusinessLogicContracts;
using ComputerStoreContracts.SearchModels;
using ComputerStoreContracts.StorageContracts;
using ComputerStoreContracts.ViewModels;
using ComputerStoreDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
namespace ComputerStoreBusinessLogic.BusinessLogic
{
public class EmployeeReportLogic : IEmployeeReportLogic
{
private readonly IPCStorage _pcStorage;
private readonly IProductStorage _productStorage;
private readonly IConsignmentStorage _consignmentStorage;
private readonly IOrderStorage _orderStorage;
public EmployeeReportLogic(IPCStorage pcStorage, IProductStorage productStorage, IConsignmentStorage consignmentStorage, IOrderStorage orderStorage)
{
_pcStorage = pcStorage;
_productStorage = productStorage;
_consignmentStorage = consignmentStorage;
_orderStorage = orderStorage;
}
public List<ReportPCByDateViewModel> GetPCsByDate(ReportDateBindingModel model)
{
return _pcStorage.GetFilteredList(new PCSearchModel
{
DateFrom = model.DateFrom,
DateTo = model.DateTo
})
.Select(x => new ReportPCByDateViewModel
{
PCName = x.Name,
Components = x.PCComponents.Values.Select(x => (x.Item1.Name, x.Item2)).ToList(),
EmployeeUsername = x.EmployeeUsername
}).ToList();
}
public List<ReportProductByDateViewModel> GetProductsByDate(ReportDateBindingModel model)
{
return _productStorage.GetFilteredList(new ProductSearchModel
{
DateFrom = model.DateFrom,
DateTo = model.DateTo
})
.Select(x => new ReportProductByDateViewModel
{
ProductName = x.Name,
Components = x.ProductComponents.Values.Select(x => (x.Item1.Name, x.Item2)).ToList()
}).ToList();
}
public List<ReportConsignmentsViewModel> GetConsignmentsByComponents(ReportComponentsBindingModel model)
{
var list = new List<ReportConsignmentsViewModel>();
Dictionary<int, IProductModel> specifiedProducts = new Dictionary<int, IProductModel>();
foreach(var component in model.Components)
{
var products = _productStorage.GetFilteredList(new ProductSearchModel
{
ComponentID = component.ID
});
foreach(var product in products)
{
if(!specifiedProducts.ContainsKey(product.ID))
{
specifiedProducts.Add(product.ID, product);
}
}
}
Dictionary<int, IConsignmentModel> specifiedConsignments = new Dictionary<int, IConsignmentModel>();
foreach (var product in specifiedProducts)
{
var consignments = _consignmentStorage.GetFilteredList(new ConsignmentSearchModel
{
ProductID = product.Key
});
if(!specifiedConsignments.Any())
{
foreach (var consignment in consignments)
{
specifiedConsignments.Add(consignment.ID, consignment);
}
}
foreach(var consignment in specifiedConsignments.Values)
{
if(!consignments.Contains(consignment))
{
specifiedConsignments.Remove(consignment.ID);
}
}
}
foreach(var consignment in specifiedConsignments)
{
var record = new ReportConsignmentsViewModel
{
ID = consignment.Key,
Products = consignment.Value.ConsignmentProducts.Values.Select(x => (x.Item1.Name,x.Item2)).ToList()
};
list.Add(record);
}
return list;
}
public void SaveProductsToPdfFile(ReportDateBindingModel model)
{
//will be implemented in the future!
}
public void SavePCsToPdfFile(ReportDateBindingModel model)
{
//will be implemented in the future!
}
}
}

View File

@ -0,0 +1,15 @@
using ComputerStoreContracts.SearchModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ComputerStoreContracts.BindingModels
{
public class ReportComponentsBindingModel
{
public string FileName { get; set; } = string.Empty;
public List<ComponentSearchModel> Components { get; set; } = new List<ComponentSearchModel>();
}
}

View File

@ -8,10 +8,11 @@ using System.Threading.Tasks;
namespace ComputerStoreContracts.BusinessLogicContracts
{
public interface IEmployeeReportByDateLogic
public interface IEmployeeReportLogic
{
List<ReportProductByDateViewModel> GetProducts(ReportDateBindingModel model);
List<ReportPCByDateViewModel> GetPCs(ReportDateBindingModel model);
List<ReportProductByDateViewModel> GetProductsByDate(ReportDateBindingModel model);
List<ReportPCByDateViewModel> GetPCsByDate(ReportDateBindingModel model);
List<ReportConsignmentsViewModel> GetConsignmentsByComponents(ReportComponentsBindingModel model);
void SaveProductsToPdfFile(ReportDateBindingModel model);
void SavePCsToPdfFile(ReportDateBindingModel model);

View File

@ -11,6 +11,7 @@ namespace ComputerStoreContracts.SearchModels
public int? ID { get; set; }
public string? Name { get; set; }
public int? EmployeeID { get; set; }
public int? ComponentID { get; set; }
public DateTime? DateTo { get; set; }
public DateTime? DateFrom { get; set; }
}

View File

@ -0,0 +1,15 @@
using ComputerStoreDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ComputerStoreContracts.ViewModels
{
public class ReportConsignmentsViewModel
{
public int ID { get; set; }
public List<(string product, int count)> Products { get; set; } = new List<(string, int)>();
}
}

View File

@ -36,7 +36,7 @@ namespace ComputerStoreDatabaseImplement.Implements
{
return context.PCs.Include(x => x.Employee).Where(x => x.EmployeeID == model.EmployeeID).Select(x => x.GetViewModel).ToList();
}
return context.PCs.Include(x => x.Components).ThenInclude(x => x.Component).Where(p => p.RequestID == context.Requests.First(r => r.OrderID == context.Orders.First(o => o.DateCreate >= model.DateFrom && o.DateImplement <= model.DateTo ).ID).ID).ToList().Select(x => x.GetViewModel).ToList();
return context.PCs.Include(x => x.Components).ThenInclude(x => x.Component).Where(p => context.Requests.Where(r => context.Orders.Where(o => o.DateCreate >= model.DateFrom && o.DateCreate <= model.DateTo).Select(o => o.ID).Contains(r.OrderID)).Select(r => r.ID).Contains(p.RequestID)).ToList().Select(x => x.GetViewModel).ToList();
}
public List<PCViewModel> GetFullList()

View File

@ -24,7 +24,7 @@ namespace ComputerStoreDatabaseImplement.Implements
public List<ProductViewModel> GetFilteredList(ProductSearchModel model)
{
if(string.IsNullOrEmpty(model.Name) && !model.EmployeeID.HasValue && !model.DateTo.HasValue && !model.DateFrom.HasValue)
if(string.IsNullOrEmpty(model.Name) && !model.EmployeeID.HasValue && !model.DateTo.HasValue && !model.DateFrom.HasValue && !model.ComponentID.HasValue)
{
return new();
}
@ -34,7 +34,11 @@ namespace ComputerStoreDatabaseImplement.Implements
{
return context.Products.Include(x => x.Employee).Where(x => x.EmployeeID == model.EmployeeID).Select(x => x.GetViewModel).ToList();
}
return context.Products.Include(x => x.Components).ThenInclude(x => x.Component).Where(p => p.ID == context.Consignments.First(r => r.OrderID == context.Orders.First(o => o.DateCreate >= model.DateFrom && o.DateImplement <= model.DateTo).ID).ID).ToList().Select(x => x.GetViewModel).ToList();
if(model.ComponentID.HasValue)
{
return context.Products.Include(x => x.Components).ThenInclude(x => x.Component).Where(p => context.ProductComponents.Where(pc => pc.ComponentID == model.ComponentID).Select(pc => pc.ProductID).Contains(p.ID)).Select(x => x.GetViewModel).ToList();
}
return context.Products.Include(x => x.Components).ThenInclude(x => x.Component).Where(p => context.ConsignmentProducts.Where(cp => context.Consignments.Where(c => context.Orders.Where(o => o.DateCreate >= model.DateFrom && o.DateCreate <= model.DateTo).Select(o => o.ID).Contains(c.OrderID)).Select(c => c.ID).Contains(cp.ConsignmentID)).Select(cp => cp.ProductID).Contains(p.ID)).ToList().Select(x => x.GetViewModel).ToList();
}
public List<ProductViewModel> GetFullList()