diff --git a/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Controllers/CustomOrderController.cs b/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Controllers/CustomOrderController.cs index f95efb3..aa29b8a 100644 --- a/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Controllers/CustomOrderController.cs +++ b/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Controllers/CustomOrderController.cs @@ -4,11 +4,13 @@ using FruitBank.Common.Dtos; using FruitBank.Common.Entities; using FruitBank.Common.Interfaces; using FruitBank.Common.Server.Interfaces; +using FruitBank.Common.Server.Services.SignalRs; using FruitBank.Common.SignalRs; using Mango.Nop.Core.Extensions; using Mango.Nop.Core.Loggers; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.SignalR; using Newtonsoft.Json; using Nop.Core; using Nop.Core.Domain.Customers; @@ -43,6 +45,9 @@ using System.Text; using System.Text.Json.Serialization; using System.Xml; using System.Xml.Serialization; +using AyCode.Services.Server.SignalRs; +using AyCode.Core.Extensions; +using MessagePack.Resolvers; namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers { @@ -51,6 +56,7 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers public class CustomOrderController : BaseAdminController, ICustomOrderSignalREndpointServer { private readonly FruitBankDbContext _dbContext; + private readonly SignalRSendToClientService _sendToClient; private readonly IOrderService _orderService; private readonly CustomOrderModelFactory _orderModelFactory; @@ -59,13 +65,13 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers private readonly IGenericAttributeService _genericAttributeService; private readonly INotificationService _notificationService; private readonly ICustomerService _customerService; - private readonly IProductService _productService; + private readonly IProductService _productService; private readonly IStoreContext _storeContext; private readonly IWorkContext _workContext; private readonly IPriceCalculationService _priceCalculationService; protected readonly IEventPublisher _eventPublisher; protected readonly ILocalizationService _localizationService; - protected readonly ICustomerActivityService _customerActivityService; + protected readonly ICustomerActivityService _customerActivityService; protected readonly IExportManager _exportManager; protected readonly IGiftCardService _giftCardService; protected readonly IImportManager _importManager; @@ -96,30 +102,32 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers return hasVendorProducts; } - public CustomOrderController(FruitBankDbContext fruitBankDbContext, + public CustomOrderController(FruitBankDbContext fruitBankDbContext, SignalRSendToClientService sendToClient, IOrderService orderService, - IPriceCalculationService priceCalculationService, - IOrderModelFactory orderModelFactory, - ICustomOrderSignalREndpointServer customOrderSignalREndpoint, - IPermissionService permissionService, - IGenericAttributeService genericAttributeService, - INotificationService notificationService, - ICustomerService customerService, - IProductService productService, - IEnumerable logWriters, - IStoreContext storeContext, - IWorkContext workContext, - IEventPublisher eventPublisher, - ILocalizationService localizationService, - ICustomerActivityService customerActivityService, + IPriceCalculationService priceCalculationService, + IOrderModelFactory orderModelFactory, + ICustomOrderSignalREndpointServer customOrderSignalREndpoint, + IPermissionService permissionService, + IGenericAttributeService genericAttributeService, + INotificationService notificationService, + ICustomerService customerService, + IProductService productService, + IEnumerable logWriters, + IStoreContext storeContext, + IWorkContext workContext, + IEventPublisher eventPublisher, + ILocalizationService localizationService, + ICustomerActivityService customerActivityService, IExportManager exportManager, IGiftCardService giftCardService, IImportManager importManager, IDateTimeHelper dateTimeHelper) { _logger = new Logger(logWriters.ToArray()); - + _dbContext = fruitBankDbContext; + _sendToClient = sendToClient; + _orderService = orderService; _orderModelFactory = orderModelFactory as CustomOrderModelFactory; _customOrderSignalREndpoint = customOrderSignalREndpoint; @@ -144,14 +152,26 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers } #region CustomOrderSignalREndpoint + [NonAction] public Task> GetAllOrderDtos() => _customOrderSignalREndpoint.GetAllOrderDtos(); - [NonAction]public Task GetOrderDtoById(int orderId) => _customOrderSignalREndpoint.GetOrderDtoById(orderId); - [NonAction]public Task> GetPendingOrderDtos() => _customOrderSignalREndpoint.GetPendingOrderDtos(); - [NonAction]public Task> GetPendingOrderDtosForMeasuring() => _customOrderSignalREndpoint.GetPendingOrderDtosForMeasuring(); + [NonAction] public Task GetOrderDtoById(int orderId) => _customOrderSignalREndpoint.GetOrderDtoById(orderId); + [NonAction] public Task> GetPendingOrderDtos() => _customOrderSignalREndpoint.GetPendingOrderDtos(); + [NonAction] public Task> GetPendingOrderDtosForMeasuring() => _customOrderSignalREndpoint.GetPendingOrderDtosForMeasuring(); [NonAction] public Task StartMeasuring(int orderId, int userId) => _customOrderSignalREndpoint.StartMeasuring(orderId, userId); - [NonAction]public Task SetOrderStatusToComplete(int orderId, int revisorId) => _customOrderSignalREndpoint.SetOrderStatusToComplete(orderId, revisorId); + [NonAction] public Task SetOrderStatusToComplete(int orderId, int revisorId) => _customOrderSignalREndpoint.SetOrderStatusToComplete(orderId, revisorId); [NonAction] public Task> GetAllOrderDtoByIds(int[] orderIds) => _customOrderSignalREndpoint.GetAllOrderDtoByIds(orderIds); - [NonAction] public Task AddOrUpdateMeasuredOrderItemPallet(OrderItemPallet orderItemPallet) => _customOrderSignalREndpoint.AddOrUpdateMeasuredOrderItemPallet(orderItemPallet); + [NonAction] public Task> GetAllOrderItemDtos() => _customOrderSignalREndpoint.GetAllOrderItemDtos(); + [NonAction]public Task> GetAllOrderDtoByProductId(int productId) => _customOrderSignalREndpoint.GetAllOrderDtoByProductId(productId); + [NonAction]public Task GetOrderItemDtoById(int orderItemId) => _customOrderSignalREndpoint.GetOrderItemDtoById(orderItemId); + [NonAction]public Task> GetAllOrderItemDtoByOrderId(int orderId) => _customOrderSignalREndpoint.GetAllOrderItemDtoByOrderId(orderId); + [NonAction]public Task> GetAllOrderItemDtoByProductId(int productId) => _customOrderSignalREndpoint.GetAllOrderItemDtoByProductId(productId); + [NonAction] public Task> GetAllOrderItemPallets() => _customOrderSignalREndpoint.GetAllOrderItemPallets(); + [NonAction] public Task GetOrderItemPalletById(int orderItemPalletId) => _customOrderSignalREndpoint.GetOrderItemPalletById(orderItemPalletId); + [NonAction] public Task> GetAllOrderItemPalletByOrderItemId(int orderItemId) => _customOrderSignalREndpoint.GetAllOrderItemPalletByOrderItemId(orderItemId); + [NonAction] public Task> GetAllOrderItemPalletByOrderId(int orderId) => _customOrderSignalREndpoint.GetAllOrderItemPalletByOrderId(orderId); + [NonAction] public Task> GetAllOrderItemPalletByProductId(int productId) => _customOrderSignalREndpoint.GetAllOrderItemPalletByProductId(productId); + [NonAction]public Task AddOrUpdateMeasuredOrderItemPallet(OrderItemPallet orderItemPallet) => _customOrderSignalREndpoint.AddOrUpdateMeasuredOrderItemPallet(orderItemPallet); + #endregion CustomOrderSignalREndpoint [CheckPermission(StandardPermission.Orders.ORDERS_VIEW)] @@ -177,7 +197,7 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers //prepare model var orderListModel = await GetOrderListModelByFilter(searchModel); //var orderListModel = new OrderListModel(); - + var valami = Json(orderListModel); Console.WriteLine(valami); return valami; @@ -329,12 +349,16 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers if (order == null) return RedirectToAction("List", "Order"); + //TODO: A FruitBankAttributeService-t használjuk és akkor az OrderDto lehet lekérni és beadni a SaveAttribute-ba! - J. + // store attributes in GenericAttribute table //await _genericAttributeService.SaveAttributeAsync(order, nameof(IMeasurable.IsMeasurable), model.IsMeasurable, _storeContext.GetCurrentStore().Id); await _genericAttributeService.SaveAttributeAsync(order, nameof(IOrderDto.DateOfReceipt), model.DateOfReceipt, _storeContext.GetCurrentStore().Id); - _notificationService.SuccessNotification("Custom attributes saved successfully."); + var orderDto = await _dbContext.OrderDtos.GetByIdAsync(model.OrderId, true); + await _sendToClient.SendOrderChanged(orderDto); + _notificationService.SuccessNotification("Custom attributes saved successfully."); return RedirectToAction("Edit", "Order", new { id = model.OrderId }); } @@ -350,11 +374,11 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers if (customer == null) return RedirectToAction("List"); var billingAddress = await _customerService.GetCustomerBillingAddressAsync(customer); - if(billingAddress == null) + if (billingAddress == null) { //let's see if he has any address at all var addresses = await _customerService.GetAddressesByCustomerIdAsync(customer.Id); - if(addresses != null && addresses.Count > 0) + if (addresses != null && addresses.Count > 0) { //set the first one as billing billingAddress = addresses[0]; @@ -401,7 +425,7 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers var transactionSuccess = await _dbContext.TransactionSafeAsync(async _ => { await _orderService.InsertOrderAsync(order); - + order.OrderTotal = 0; foreach (var item in orderProducts) @@ -459,6 +483,9 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers await _orderService.UpdateOrderAsync(order); + var orderDto = await _dbContext.OrderDtos.GetByIdAsync(order.Id, true); + await _sendToClient.SendMeasuringNotification("Módosult a rendelés, mérjétek újra!", orderDto); + return true; }); @@ -556,7 +583,7 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers } - [HttpGet] // Change from [HttpPost] to [HttpGet] + [HttpGet] // Change from [HttpPost] to [HttpGet] [CheckPermission(StandardPermission.Customers.CUSTOMERS_VIEW)] public virtual async Task CustomerSearchAutoComplete(string term) { @@ -605,7 +632,7 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers if (string.IsNullOrEmpty(fullName)) fullName = "[No name]"; - if(string.IsNullOrEmpty(company)) + if (string.IsNullOrEmpty(company)) company = "[No company]"; string fullText = $"{company} ({fullName}), {customer.Email}"; @@ -809,10 +836,12 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers [CheckPermission(StandardPermission.Orders.ORDERS_IMPORT_EXPORT)] public virtual async Task ExportXmlAll(OrderSearchModelExtended model) { - var startDateValue = model.StartDate == null ? null + var startDateValue = model.StartDate == null + ? null : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.StartDate.Value, await _dateTimeHelper.GetCurrentTimeZoneAsync()); - var endDateValue = model.EndDate == null ? null + var endDateValue = model.EndDate == null + ? null : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.EndDate.Value, await _dateTimeHelper.GetCurrentTimeZoneAsync()).AddDays(1); //a vendor should have access only to his products @@ -905,10 +934,12 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers [CheckPermission(StandardPermission.Orders.ORDERS_IMPORT_EXPORT)] public virtual async Task ExportExcelAll(OrderSearchModelExtended model) { - var startDateValue = model.StartDate == null ? null + var startDateValue = model.StartDate == null + ? null : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.StartDate.Value, await _dateTimeHelper.GetCurrentTimeZoneAsync()); - var endDateValue = model.EndDate == null ? null + var endDateValue = model.EndDate == null + ? null : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.EndDate.Value, await _dateTimeHelper.GetCurrentTimeZoneAsync()).AddDays(1); //a vendor should have access only to his products @@ -1025,9 +1056,7 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers return RedirectToAction("List"); } } - - #endregion - + #endregion } } diff --git a/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Controllers/CustomOrderSignalREndpoint.cs b/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Controllers/CustomOrderSignalREndpoint.cs index 8542acd..52d482a 100644 --- a/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Controllers/CustomOrderSignalREndpoint.cs +++ b/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Controllers/CustomOrderSignalREndpoint.cs @@ -4,6 +4,7 @@ using FruitBank.Common.Dtos; using FruitBank.Common.Entities; using FruitBank.Common.Interfaces; using FruitBank.Common.Server.Interfaces; +using FruitBank.Common.Server.Services.SignalRs; using FruitBank.Common.SignalRs; using Mango.Nop.Core.Loggers; using Nop.Core; @@ -13,11 +14,11 @@ using Nop.Plugin.Misc.FruitBankPlugin.Controllers; using Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer; using Nop.Plugin.Misc.FruitBankPlugin.Services; using Nop.Services.Catalog; -using static Nop.Services.Security.StandardPermission; namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers; -public class CustomOrderSignalREndpoint(FruitBankDbContext ctx, IPriceCalculationService customPriceCalculationService,IEventPublisher eventPublisher, IWorkContext workContext, IEnumerable logWriters) : ICustomOrderSignalREndpointServer +public class CustomOrderSignalREndpoint(FruitBankDbContext ctx, SignalRSendToClientService sendToClient, IPriceCalculationService customPriceCalculationService,IEventPublisher eventPublisher, IWorkContext workContext, IEnumerable logWriters) + : ICustomOrderSignalREndpointServer { private readonly ILogger _logger = new Logger(logWriters.ToArray()); @@ -51,7 +52,67 @@ public class CustomOrderSignalREndpoint(FruitBankDbContext ctx, IPriceCalculatio return await ctx.OrderDtos.GetAllByIds(orderIds).ToListAsync(); } - [SignalR(SignalRTags.StartMeasuring)] + [SignalR(SignalRTags.GetAllOrderDtoByProductId)] + public async Task> GetAllOrderDtoByProductId(int productId) + { + return await ctx.OrderDtos.GetAllByProductId(productId, true).ToListAsync(); + } + + [SignalR(SignalRTags.GetOrderItemDtoById)] + public async Task GetOrderItemDtoById(int orderItemId) + { + return await ctx.OrderItemDtos.GetByIdAsync(orderItemId, true); + } + + + [SignalR(SignalRTags.GetAllOrderItemDtos)] + public async Task> GetAllOrderItemDtos() + { + return await ctx.OrderItemDtos.GetAll(true).ToListAsync(); + } + + [SignalR(SignalRTags.GetAllOrderItemDtoByOrderId)] + public async Task> GetAllOrderItemDtoByOrderId(int orderId) + { + return await ctx.OrderItemDtos.GetAllByOrderId(orderId, true).ToListAsync(); + } + + [SignalR(SignalRTags.GetAllOrderItemDtoByProductId)] + public async Task> GetAllOrderItemDtoByProductId(int productId) + { + return await ctx.OrderItemDtos.GetAllByProductId(productId, true).ToListAsync(); + } + + [SignalR(SignalRTags.GetOrderItemPalletById)] + public async Task GetOrderItemPalletById(int orderItemPalletId) + { + return await ctx.OrderItemPallets.GetByIdAsync(orderItemPalletId, true); + } + + [SignalR(SignalRTags.GetAllOrderItemPallets)] + public async Task> GetAllOrderItemPallets() + { + return await ctx.OrderItemPallets.GetAll(true).ToListAsync(); + } + [SignalR(SignalRTags.GetAllOrderItemPalletByOrderItemId)] + public async Task> GetAllOrderItemPalletByOrderItemId(int orderItemId) + { + return await ctx.OrderItemPallets.GetAllByOrderItemId(orderItemId, true).ToListAsync(); + } + + [SignalR(SignalRTags.GetAllOrderItemPalletByOrderId)] + public async Task> GetAllOrderItemPalletByOrderId(int orderId) + { + return await ctx.OrderItemPallets.GetAllByOrderId(orderId).ToListAsync(); + } + + [SignalR(SignalRTags.GetAllOrderItemPalletByProductId)] + public async Task> GetAllOrderItemPalletByProductId(int productId) + { + return await ctx.OrderItemPallets.GetAllByProductId(productId).ToListAsync(); + } + + [SignalR(SignalRTags.StartMeasuring, SignalRTags.SendOrderChanged, SendToClientType.Others)] public async Task StartMeasuring(int orderId, int userId) { _logger.Detail($"StartMeasuring invoked; orderId: {orderId}; userId: {userId}"); @@ -60,7 +121,7 @@ public class CustomOrderSignalREndpoint(FruitBankDbContext ctx, IPriceCalculatio return await ctx.OrderDtos.GetByIdAsync(orderId, true); } - [SignalR(SignalRTags.SetOrderStatusToComplete)] + [SignalR(SignalRTags.SetOrderStatusToComplete, SignalRTags.SendOrderChanged, SendToClientType.Others)] public async Task SetOrderStatusToComplete(int orderId, int revisorId) { _logger.Detail($"SetOrderStatusToComplete invoked; orderId: {orderId}; revisorId: {revisorId}"); @@ -79,7 +140,7 @@ public class CustomOrderSignalREndpoint(FruitBankDbContext ctx, IPriceCalculatio return await ctx.OrderDtos.GetByIdAsync(orderId, true); } - [SignalR(SignalRTags.AddOrUpdateMeasuredOrderItemPallet)] + [SignalR(SignalRTags.AddOrUpdateMeasuredOrderItemPallet, SignalRTags.SendOrderItemPalletChanged, SendToClientType.Others)] public async Task AddOrUpdateMeasuredOrderItemPallet(OrderItemPallet orderItemPallet) { ArgumentNullException.ThrowIfNull(orderItemPallet); @@ -87,6 +148,21 @@ public class CustomOrderSignalREndpoint(FruitBankDbContext ctx, IPriceCalculatio _logger.Detail($"AddOrUpdateMeasuredOrderItemPallet invoked; {orderItemPallet}"); if (!await ctx.AddOrUpdateOrderItemPalletSafeAsync(orderItemPallet)) return null; + + var isMeasurable = orderItemPallet.GrossWeight > 0; + if (isMeasurable) + { + var orderItemDto = await ctx.OrderItemDtos.GetByIdAsync(orderItemPallet.OrderItemId, true); + + if (orderItemDto.IsAudited && orderItemDto.IsMeasurable) + { + var orderItem = ctx.OrderItems.GetById(orderItemDto.Id); + + await ((CustomPriceCalculationService)customPriceCalculationService).CheckAndUpdateOrderItemFinalPricesAsync + (orderItem, orderItemDto.IsMeasurable, orderItemDto.NetWeight); + } + } + return await ctx.OrderItemPallets.GetByIdAsync(orderItemPallet.Id, false); } diff --git a/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Views/Order/List.cshtml b/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Views/Order/List.cshtml index ec17234..5b565d8 100644 --- a/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Views/Order/List.cshtml +++ b/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Views/Order/List.cshtml @@ -404,15 +404,23 @@ Render = new RenderCustom("renderColumnIsMeasurable"), ClassName = NopColumnClassDefaults.CenterAll }); - - gridModel.ColumnCollection.Add(new ColumnProperty(nameof(OrderModelExtended.IsMeasured)) + + gridModel.ColumnCollection.Add(new ColumnProperty(nameof(OrderModelExtended.MeasuringStatusString)) { - Title = T($"FruitBank.{nameof(OrderModelExtended.IsMeasured)}").Text, - Width = "80", - Render = new RenderCustom("renderColumnIsMeasurable"), + Title = "Mérés állapota", //T($"FruitBank.{nameof(OrderModelExtended.MeasuringStatus)}").Text, + Width = "100", + Render = new RenderCustom("renderColumnMeasuringStatus"), ClassName = NopColumnClassDefaults.CenterAll }); + // gridModel.ColumnCollection.Add(new ColumnProperty(nameof(OrderModelExtended.IsMeasured)) + // { + // Title = T($"FruitBank.{nameof(OrderModelExtended.IsMeasured)}").Text, + // Width = "80", + // Render = new RenderCustom("renderColumnIsMeasurable"), + // ClassName = NopColumnClassDefaults.CenterAll + // }); + gridModel.ColumnCollection.Add(new ColumnProperty(nameof(IOrderDto.DateOfReceipt)) { Title = T($"FruitBank.{nameof(IOrderDto.DateOfReceipt)}").Text, @@ -428,13 +436,15 @@ { Title = T("Admin.Orders.Fields.OrderStatus").Text, Width = "100", - Render = new RenderCustom("renderColumnOrderStatus") + Render = new RenderCustom("renderColumnOrderStatus"), + ClassName = NopColumnClassDefaults.CenterAll }); } gridModel.ColumnCollection.Add(new ColumnProperty(nameof(OrderModel.PaymentStatus)) { Title = T("Admin.Orders.Fields.PaymentStatus").Text, - Width = "130" + Width = "130", + ClassName = NopColumnClassDefaults.CenterAll }); //a vendor does not have access to this functionality if (!Model.IsLoggedInAsVendor) @@ -502,6 +512,18 @@ } } + function renderColumnMeasuringStatus(data, type, row, meta) { + var color; + switch (row.MeasuringStatus) { + case 10: color = 'yellow'; break; + case 20: color = 'blue'; break; + case 30: color = 'green'; break; + case 40: color = 'red'; break; + default: color = 'gray'; + } + return '' + data + ''; + } + function renderColumnCustomer(data, type, row, meta) { console.log("Hello World 2"); var link = '@Url.Content("~/Admin/Customer/Edit/")' + row.CustomerId; diff --git a/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Views/Order/_CustomOrderDetails.Products.cshtml b/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Views/Order/_CustomOrderDetails.Products.cshtml index b48764c..3d3f640 100644 --- a/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Views/Order/_CustomOrderDetails.Products.cshtml +++ b/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Views/Order/_CustomOrderDetails.Products.cshtml @@ -154,6 +154,10 @@ @T("FruitBank.IsMeasurable") + + Mérés állapota + + @* @T("Admin.Orders.Products.Discount") *@ @@ -323,6 +327,12 @@ } + + +
+ @($"{item.MeasuringStatusString}") +
+ @* @if (Model.AllowCustomersToSelectTaxDisplayType) diff --git a/Nop.Plugin.Misc.AIPlugin/Domains/DataLayer/FruitBankDbContext.cs b/Nop.Plugin.Misc.AIPlugin/Domains/DataLayer/FruitBankDbContext.cs index 0f5e19f..b60b8ad 100644 --- a/Nop.Plugin.Misc.AIPlugin/Domains/DataLayer/FruitBankDbContext.cs +++ b/Nop.Plugin.Misc.AIPlugin/Domains/DataLayer/FruitBankDbContext.cs @@ -12,6 +12,7 @@ using Mango.Nop.Core.Repositories; using Nop.Core; using Nop.Core.Caching; using Nop.Core.Domain.Catalog; +using Nop.Core.Domain.Common; using Nop.Core.Domain.Customers; using Nop.Core.Domain.Orders; using Nop.Core.Events; @@ -63,6 +64,8 @@ public class FruitBankDbContext : MgDbContextBase, public IRepository CustomerRoleMappings { get; set; } public IRepository CustomerAddressMappings { get; set; } + public IRepository GenericAttributes { get; set; } + public FruitBankDbContext(INopDataProvider dataProvider, ILockService lockService, FruitBankAttributeService fruitBankAttributeService, IStoreContext storeContext, PartnerDbTable partnerDbTable, ShippingDbTable shippingDbTable, ShippingDocumentDbTable shippingDocumentDbTable, ShippingItemDbTable shippingItemDbTable, ShippingItemPalletDbTable shippingItemPalletDbTable, FilesDbTable filesDbTable, ShippingDocumentToFilesDbTable shippingDocumentToFilesDbTable, @@ -74,7 +77,9 @@ public class FruitBankDbContext : MgDbContextBase, IRepository customerRepository, IRepository customerCustomerRoleMappingRepository, IRepository customerAddressMappingRepository, - IRepository customerRoleRepository,IEventPublisher eventPublisher, + IRepository customerRoleRepository, + IRepository genericAttributes, + IEventPublisher eventPublisher, IEnumerable logWriters) : base(productRepository, orderRepository, orderItemRepository, dataProvider, lockService, new Logger(logWriters.ToArray())) { _eventPublisher = eventPublisher; @@ -103,6 +108,8 @@ public class FruitBankDbContext : MgDbContextBase, CustomerRoles = customerRoleRepository; CustomerRoleMappings = customerCustomerRoleMappingRepository; CustomerAddressMappings = customerAddressMappingRepository; + + GenericAttributes = genericAttributes; } public IQueryable GetCustomersBySystemRoleName(string systemRoleName) @@ -193,7 +200,7 @@ public class FruitBankDbContext : MgDbContextBase, ProductDto? productDto = null; var productIsMeasurable = false; - if (shippingItem.ProductId > 0) + if (shippingItem.ProductId.GetValueOrDefault(0) > 0) { productDto = await ProductDtos.GetByIdAsync(shippingItem.ProductId!.Value, true); @@ -263,7 +270,7 @@ public class FruitBankDbContext : MgDbContextBase, //if (productIdUnchanged || !dbShippingItem.IsMeasured) return true; if (!productIdChanged && (shippingItem.IsMeasured || !dbShippingItem.IsMeasured)) return true; - productDto = await ProductDtos.GetByIdAsync(dbShippingItem.ProductId); + productDto = await ProductDtos.GetByIdAsync(dbShippingItem.ProductId!.Value, true); if (productDto != null) { @@ -431,24 +438,65 @@ public class FruitBankDbContext : MgDbContextBase, { if (orderItemDto.TrayQuantity != orderItemDto.Quantity) return null; - //orderItemDto.ProductDto!.StockQuantity -= orderItemDto.TrayQuantity; - //await ProductDtos.UpdateAsync(orderItemDto.ProductDto); + foreach (var orderItemPallet in orderItemDto.OrderItemPallets.Where(oip => oip.RevisorId <= 0)) + { + orderItemPallet.RevisorId = revisorId; + await OrderItemPallets.UpdateAsync(orderItemPallet, false); + } if (!orderItemDto.IsMeasurable) continue; - var gaNetWeight = CommonHelper.To(orderItemDto.GenericAttributes.FirstOrDefault(x => x.Key == nameof(IMeasuringNetWeight.NetWeight))?.Value ?? "0"); + var prevNetWeightFromGa = orderItemDto.GenericAttributes.GetValueOrDefault(nameof(IMeasuringNetWeight.NetWeight), 0); + //var gaNetWeight = CommonHelper.To(orderItemDto.GenericAttributes.FirstOrDefault(x => x.Key == nameof(IMeasuringNetWeight.NetWeight))?.Value ?? "0"); await _fruitBankAttributeService.InsertOrUpdateGenericAttributeAsync (orderItemDto.Id, nameof(IMeasuringNetWeight.NetWeight), orderItemDto.NetWeight); await _fruitBankAttributeService.InsertOrUpdateMeasuringAttributeValuesAsync - (orderItemDto.ProductId, -(orderItemDto.NetWeight-gaNetWeight), orderItemDto.IsMeasurable, true); + (orderItemDto.ProductId, -(orderItemDto.NetWeight - prevNetWeightFromGa), orderItemDto.IsMeasurable, true); } - + //await _eventPublisher.PublishAsync(new OrderStatusChangedEvent(order, prevOrderStatus)); return orderDto; } + public Task DeleteOrderItemConstraintsSafeAsync(OrderItem orderItem, bool publishEvent = false) + { + return TransactionSafeAsync(async _ => + { + await DeleteOrderItemConstraintsAsync(orderItem, publishEvent); + return true; + }); + } + + public async Task DeleteOrderItemConstraintsAsync(OrderItem orderItem, bool publishEvent = false) + { + //Itt nincs már OrderItemDto!!!! - J. + var storeId = _storeContext.GetCurrentStore().Id; + var orderItemGenericAttributes = await GenericAttributes.Table.Where(x => x.EntityId == orderItem.Id && x.KeyGroup == nameof(OrderItem) && x.StoreId == storeId).ToListAsync(); + + var validOrderItemNetWeight = orderItemGenericAttributes.GetValueOrDefault(nameof(IMeasuringNetWeight.NetWeight), 0); + if (validOrderItemNetWeight != 0) + { + var productDto = await ProductDtos.GetByIdAsync(orderItem.ProductId, true); + if (productDto != null && productDto.IsMeasurable) + { + var newProductNetWeight = productDto.NetWeight + validOrderItemNetWeight; + + await _fruitBankAttributeService.InsertOrUpdateGenericAttributeAsync(productDto.Id, nameof(IMeasuringNetWeight.NetWeight), newProductNetWeight); + + Logger.Info($"DeleteOrderItemConstraints; Product netWeight updated! productId: {productDto.Id}; newNetWeight: {newProductNetWeight}; oldNetWeight: {productDto.NetWeight}; deleted orderItemNetWeight: {validOrderItemNetWeight}; orderItem.Id: {orderItem.Id};"); + } + } + + await _fruitBankAttributeService.DeleteGenericAttributesAsync(orderItemGenericAttributes); + var deletedPalletCount = await OrderItemPallets.DeleteAsync(x => x.OrderItemId == orderItem.Id); + + //await OrderItems.DeleteAsync(orderItem, publishEvent); + + Logger.Info($"DeleteOrderItemConstraints; OrderItem constraints deleted! deletedPalletCount: {deletedPalletCount}; orderItem.Id: {orderItem.Id};"); + } + public async Task AddOrderItemPalletAsync(OrderItemPallet orderItemPallet) { if (!await SetupOrderItemPalletMeauringValues(orderItemPallet)) return null; @@ -486,10 +534,7 @@ public class FruitBankDbContext : MgDbContextBase, private async Task SetupOrderItemPalletMeauringValues(OrderItemPallet orderItemPallet) { - OrderItemDto orderItemDto; - - if (orderItemPallet.OrderItemDto?.ProductDto == null) orderItemDto = await OrderItemDtos.GetByIdAsync(orderItemPallet.OrderItemId, true); - else orderItemDto = orderItemPallet.OrderItemDto; + var orderItemDto = await OrderItemDtos.GetByIdAsync(orderItemPallet.OrderItemId, true); if (orderItemDto == null || orderItemPallet.OrderItemId != orderItemDto.Id || //orderItemDto.IsOtherMeasuringInProgress(orderItemPallet.CreatorId) || orderItemPallet.TrayQuantity > orderItemDto.Quantity || !orderItemPallet.IsValidSafeMeasuringValues()) return false; @@ -503,7 +548,7 @@ public class FruitBankDbContext : MgDbContextBase, private async Task UpdateProductDtoStockQuantityAsync(int productDtoId, bool publishEvent) { - var productDto = await ProductDtos.GetByIdAsync(productDtoId); + var productDto = await ProductDtos.GetByIdAsync(productDtoId, false); if (productDto != null) return await UpdateProductDtoStockQuantityAsync(productDto, publishEvent); Logger.Error($"product == null; id: {productDtoId}"); diff --git a/Nop.Plugin.Misc.AIPlugin/Domains/DataLayer/OrderDtoDbTable.cs b/Nop.Plugin.Misc.AIPlugin/Domains/DataLayer/OrderDtoDbTable.cs index 836ce0b..0b57f11 100644 --- a/Nop.Plugin.Misc.AIPlugin/Domains/DataLayer/OrderDtoDbTable.cs +++ b/Nop.Plugin.Misc.AIPlugin/Domains/DataLayer/OrderDtoDbTable.cs @@ -8,6 +8,7 @@ using Nop.Core.Domain.Orders; using Nop.Core.Events; using Nop.Data; using Mango.Nop.Core.Loggers; +using Nop.Core.Domain.Payments; namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer; @@ -30,11 +31,14 @@ public class OrderDtoDbTable : MgDtoDbTableBase public Task GetByIdAsync(int orderId, bool loadRelations) => GetAll(loadRelations).Where(x => x.Id == orderId).FirstOrDefaultAsync(null); - public IQueryable GetAllByOrderStatus(OrderStatus orderStatus, bool loadRelations = true) + public IQueryable GetAllByOrderStatus(OrderStatus orderStatus, bool loadRelations = true) => GetAll(loadRelations).Where(o => o.OrderStatusId == (int)orderStatus); public IQueryable GetAllForMeasuring(bool loadRelations = true) - => GetAllByOrderStatus(OrderStatus.Pending, loadRelations).Where(o => o.GenericAttributes.Any(ga => ga.Key == nameof(OrderDto.DateOfReceipt))); + => GetAll(loadRelations).Where(o => o.PaymentStatusId < (int)PaymentStatus.Paid && o.GenericAttributes.Any(ga => ga.Key == nameof(OrderDto.DateOfReceipt))); + //=> GetAllByOrderStatus(OrderStatus.Pending, loadRelations).Where(o => o.GenericAttributes.Any(ga => ga.Key == nameof(OrderDto.DateOfReceipt))); + + public IQueryable GetAllByProductId(int productId, bool loadRelations = true) => GetAll(loadRelations).Where(o => o.OrderItemDtos.Any(oi => oi.ProductId == productId)); public IQueryable GetAllByIds(IEnumerable orderIds, bool loadRelations = true) => GetAll(loadRelations).Where(o => orderIds.Contains(o.Id)); } diff --git a/Nop.Plugin.Misc.AIPlugin/Domains/DataLayer/OrderItemDtoDbTable.cs b/Nop.Plugin.Misc.AIPlugin/Domains/DataLayer/OrderItemDtoDbTable.cs index 8510123..ce7a67c 100644 --- a/Nop.Plugin.Misc.AIPlugin/Domains/DataLayer/OrderItemDtoDbTable.cs +++ b/Nop.Plugin.Misc.AIPlugin/Domains/DataLayer/OrderItemDtoDbTable.cs @@ -20,15 +20,17 @@ public class OrderItemDtoDbTable : MgDtoDbTableBase public IQueryable GetAll(bool loadRelations) { return GetAll() - .LoadWith(oi => oi.OrderDto) - .LoadWith(oi => oi.OrderItemPallets) .LoadWith(oi => oi.GenericAttributes) + .LoadWith(oi => oi.OrderDto).ThenLoad(prod => prod.GenericAttributes) + .LoadWith(oi => oi.OrderItemPallets).ThenLoad(oip => oip.OrderItemDto).ThenLoad(oi => oi.GenericAttributes) .LoadWith(oi => oi.ProductDto).ThenLoad(prod => prod.GenericAttributes); } public Task GetByIdAsync(int orderItemId, bool loadRelations) => GetAll(loadRelations).Where(oi => oi.Id == orderItemId).FirstOrDefaultAsync(null); public IQueryable GetAllByOrderId(int orderId, bool loadRelations = true)=> GetAll(loadRelations).Where(oi => oi.OrderId == orderId); + public IQueryable GetAllByProductId(int productId, bool loadRelations = true)=> GetAll(loadRelations).Where(oi => oi.ProductId == productId); public IQueryable GetAllByIds(IEnumerable orderItemIds, bool loadRelations = true) => GetAll(loadRelations).Where(oi => orderItemIds.Contains(oi.Id)); + public IQueryable GetAllByOrderIds(IEnumerable orderIds, bool loadRelations = true) => GetAll(loadRelations).Where(oi => orderIds.Contains(oi.OrderId)); } \ No newline at end of file diff --git a/Nop.Plugin.Misc.AIPlugin/Domains/DataLayer/OrderItemPalletDbTable.cs b/Nop.Plugin.Misc.AIPlugin/Domains/DataLayer/OrderItemPalletDbTable.cs index 783c415..56446b5 100644 --- a/Nop.Plugin.Misc.AIPlugin/Domains/DataLayer/OrderItemPalletDbTable.cs +++ b/Nop.Plugin.Misc.AIPlugin/Domains/DataLayer/OrderItemPalletDbTable.cs @@ -21,13 +21,21 @@ public class OrderItemPalletDbTable : MeasuringItemPalletBaseDbTable oip.OrderItemDto).ThenLoad(oi => oi.ProductDto).ThenLoad(oip => oip.GenericAttributes) + .LoadWith(oip => oip.OrderItemDto).ThenLoad(oi => oi.OrderDto).ThenLoad(o => o.GenericAttributes) + .LoadWith(oip => oip.OrderItemDto).ThenLoad(oi => oi.ProductDto).ThenLoad(p => p.GenericAttributes) : GetAll(); } public Task GetByIdAsync(int id, bool loadRelations) => GetAll(loadRelations).FirstOrDefaultAsync(oip => oip.Id == id); - public IQueryable GetAllByOrderItemIdAsync(int orderItemId, bool loadRelations) + public IQueryable GetAllByOrderItemId(int orderItemId, bool loadRelations) => GetAll(loadRelations).Where(oip => oip.OrderItemId == orderItemId); + + public IQueryable GetAllByOrderId(int orderId) + => GetAll(true).Where(oip => oip.OrderItemDto.OrderId == orderId); + + public IQueryable GetAllByProductId(int productId) + => GetAll(true).Where(oip => oip.OrderItemDto.ProductId == productId); + } \ No newline at end of file diff --git a/Nop.Plugin.Misc.AIPlugin/Domains/EventConsumers/FruitBankEventConsumer.cs b/Nop.Plugin.Misc.AIPlugin/Domains/EventConsumers/FruitBankEventConsumer.cs index 7274504..61c2278 100644 --- a/Nop.Plugin.Misc.AIPlugin/Domains/EventConsumers/FruitBankEventConsumer.cs +++ b/Nop.Plugin.Misc.AIPlugin/Domains/EventConsumers/FruitBankEventConsumer.cs @@ -29,19 +29,21 @@ public class FruitBankEventConsumer : IConsumer>, IConsumer>, - IConsumer> + IConsumer>, + IConsumer> { - private readonly CustomPriceCalculationService _customPriceCalculationService; + //private readonly CustomPriceCalculationService _customPriceCalculationService; private readonly FruitBankDbContext _ctx; + private readonly MeasurementService _measurementService; private readonly FruitBankAttributeService _fruitBankAttributeService; - public FruitBankEventConsumer(IHttpContextAccessor httpContextAcc, IPriceCalculationService customPriceCalculationService, FruitBankDbContext ctx, FruitBankAttributeService fruitBankAttributeService, IEnumerable logWriters) : base(ctx, httpContextAcc, logWriters) + public FruitBankEventConsumer(IHttpContextAccessor httpContextAcc, FruitBankDbContext ctx, MeasurementService measurementService, + FruitBankAttributeService fruitBankAttributeService, IEnumerable logWriters) : base(ctx, httpContextAcc, logWriters) { _ctx = ctx; - + _measurementService = measurementService; _fruitBankAttributeService = fruitBankAttributeService; - _customPriceCalculationService = customPriceCalculationService as CustomPriceCalculationService; } public override async Task HandleEventAsync(EntityUpdatedEvent eventMessage) @@ -257,26 +259,22 @@ public class FruitBankEventConsumer : await _ctx.ShippingItemPallets.DeleteAsync(sp => sp.ShippingItemId == eventMessage.Entity.Id, false); } - public async Task HandleEventAsync(EntityUpdatedEvent eventMessage) + public async Task HandleEventAsync(EntityDeletedEvent eventMessage) { - //await _customPriceCalculationService.CheckAndUpdateOrderItemFinalPricesAsync(eventMessage.Entity); - if (await _customPriceCalculationService.CheckAndUpdateOrderItemFinalPricesAsync(eventMessage.Entity)) - { - var order = await _ctx.Orders.GetByIdAsync(eventMessage.Entity.OrderId); - await _customPriceCalculationService.CheckAndUpdateOrderTotalPrice(order); - } + await _measurementService.DeleteOrderItemConstraintsAsync(eventMessage.Entity); } + public async Task HandleEventAsync(EntityUpdatedEvent eventMessage) + { + await _measurementService.OrderItemInsertedOrUpdatedPostProcess(eventMessage.Entity); + } public async Task HandleEventAsync(EntityInsertedEvent eventMessage) { - //await _customPriceCalculationService.CheckAndUpdateOrderItemFinalPricesAsync(eventMessage.Entity); - if (await _customPriceCalculationService.CheckAndUpdateOrderItemFinalPricesAsync(eventMessage.Entity)) - { - var order = await _ctx.Orders.GetByIdAsync(eventMessage.Entity.OrderId); - await _customPriceCalculationService.CheckAndUpdateOrderTotalPrice(order); - } + await _measurementService.OrderItemInsertedOrUpdatedPostProcess(eventMessage.Entity); } + + } #endregion Delete diff --git a/Nop.Plugin.Misc.AIPlugin/Factories/CustomOrderModelFactory.cs b/Nop.Plugin.Misc.AIPlugin/Factories/CustomOrderModelFactory.cs index 5cd9b0f..3062375 100644 --- a/Nop.Plugin.Misc.AIPlugin/Factories/CustomOrderModelFactory.cs +++ b/Nop.Plugin.Misc.AIPlugin/Factories/CustomOrderModelFactory.cs @@ -177,6 +177,7 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Factories private static void PrepareOrderModelExtended(OrderModelExtended orderModelExtended, OrderDto orderDto) { orderModelExtended.IsMeasured = orderDto.IsMeasured; + orderModelExtended.MeasuringStatus = orderDto.MeasuringStatus; orderModelExtended.IsMeasurable = orderDto.IsMeasurable; orderModelExtended.DateOfReceipt = orderDto.DateOfReceipt; orderModelExtended.OrderTotal = !orderDto.IsComplete && orderDto.IsMeasurable ? "kalkuláció alatt..." : orderModelExtended.OrderTotal; @@ -210,11 +211,14 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Factories orderItemModelExtended.IsMeasured = orderItemDto.IsMeasured; orderItemModelExtended.IsMeasurable = orderItemDto.IsMeasurable; + orderItemModelExtended.MeasuringStatus = orderItemDto.MeasuringStatus; orderItemModelExtended.NetWeight = (decimal)orderItemDto.NetWeight; orderItemModelExtended.ProductStockQuantity = orderItemDto.ProductDto!.StockQuantity; orderItemModelExtended.ProductIncomingQuantity = orderItemDto.ProductDto.IncomingQuantity; orderItemModelExtended.ProductAvailableQuantity = orderItemDto.ProductDto.AvailableQuantity; - //orderItemModelExtended.SubTotalInclTax = !orderDto.IsComplete && orderItemDto.IsMeasurable ? "kalkuláció alatt..." : orderItemModelExtended.SubTotalInclTax; + + + orderItemModelExtended.SubTotalInclTax = orderItemDto.IsMeasurable && !orderItemDto.IsAudited ? "kalkuláció alatt..." : orderItemModelExtended.SubTotalInclTax; orderModelExtended.ItemExtendeds ??= new List(); orderModelExtended.ItemExtendeds.Add(orderItemModelExtended); diff --git a/Nop.Plugin.Misc.AIPlugin/Infrastructure/PluginNopStartup.cs b/Nop.Plugin.Misc.AIPlugin/Infrastructure/PluginNopStartup.cs index 46ac4ec..aa7f93c 100644 --- a/Nop.Plugin.Misc.AIPlugin/Infrastructure/PluginNopStartup.cs +++ b/Nop.Plugin.Misc.AIPlugin/Infrastructure/PluginNopStartup.cs @@ -72,6 +72,8 @@ public class PluginNopStartup : INopStartup services.AddScoped(); services.AddScoped(); + + services.AddScoped(); services.AddScoped(); services.AddScoped(); @@ -84,6 +86,8 @@ public class PluginNopStartup : INopStartup services.AddScoped(); services.AddScoped(); + services.AddScoped(); + //services.AddScoped(); //services.AddScoped(); //services.AddScoped(); @@ -100,7 +104,13 @@ public class PluginNopStartup : INopStartup options.Filters.AddService(); }); - services.AddSignalR(options => options.MaximumReceiveMessageSize = 256 * 1024); + services.AddSignalR(hubOptions => + { + //hubOptions.EnableDetailedErrors = true; + hubOptions.MaximumReceiveMessageSize = 256 * 1024; + hubOptions.KeepAliveInterval = TimeSpan.FromSeconds(FruitBankConstClient.SignalRKeepAliveIntervalSecond); + hubOptions.ClientTimeoutInterval = TimeSpan.FromSeconds(FruitBankConstClient.SignarlRTimeoutIntervalSecond); + }); } /// diff --git a/Nop.Plugin.Misc.AIPlugin/Models/Orders/IOrderModelExtended.cs b/Nop.Plugin.Misc.AIPlugin/Models/Orders/IOrderModelExtended.cs index 5939175..25905f1 100644 --- a/Nop.Plugin.Misc.AIPlugin/Models/Orders/IOrderModelExtended.cs +++ b/Nop.Plugin.Misc.AIPlugin/Models/Orders/IOrderModelExtended.cs @@ -3,16 +3,18 @@ using Nop.Plugin.Misc.FruitBankPlugin.Models.MgBase.OrderModels; namespace Nop.Plugin.Misc.FruitBankPlugin.Models.Orders; -public interface IOrderItemModelExtended : /*IMgOrderItemModelExtended,*/ IMeasurable, IMeasured +public interface IOrderItemModelExtended : /*IMgOrderItemModelExtended,*/ IMeasurable, IMeasured, IMeasurableStatus { + string MeasuringStatusString { get; } decimal NetWeight { get; set; } int ProductStockQuantity { get; set; } int ProductIncomingQuantity { get; set; } int ProductAvailableQuantity { get; set; } } -public interface IOrderModelExtended : IMgOrderModelExtended, IMeasurable, IMeasured +public interface IOrderModelExtended : IMgOrderModelExtended, IMeasurable, IMeasured, IMeasurableStatus { + string MeasuringStatusString { get; } DateTime? DateOfReceipt { get; set; } string CustomerCompany { get; set; } } \ No newline at end of file diff --git a/Nop.Plugin.Misc.AIPlugin/Models/Orders/OrderModelExtended.cs b/Nop.Plugin.Misc.AIPlugin/Models/Orders/OrderModelExtended.cs index 3490243..910be24 100644 --- a/Nop.Plugin.Misc.AIPlugin/Models/Orders/OrderModelExtended.cs +++ b/Nop.Plugin.Misc.AIPlugin/Models/Orders/OrderModelExtended.cs @@ -1,4 +1,5 @@ -using Nop.Plugin.Misc.FruitBankPlugin.Models.MgBase.OrderModels; +using FruitBank.Common.Enums; +using Nop.Plugin.Misc.FruitBankPlugin.Models.MgBase.OrderModels; using Nop.Web.Areas.Admin.Models.Orders; namespace Nop.Plugin.Misc.FruitBankPlugin.Models.Orders @@ -7,6 +8,8 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Models.Orders { public bool IsMeasured { get; set; } public bool IsMeasurable { get; set; } + public MeasuringStatus MeasuringStatus { get; set; } + public string MeasuringStatusString => MeasuringStatus.ToString(); public decimal NetWeight { get; set; } public int ProductStockQuantity { get; set; } public int ProductIncomingQuantity { get; set; } @@ -17,6 +20,8 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Models.Orders { public bool IsMeasured { get; set; } public bool IsMeasurable { get; set; } + public MeasuringStatus MeasuringStatus { get; set; } + public string MeasuringStatusString => MeasuringStatus.ToString(); public DateTime? DateOfReceipt { get; set; } public string CustomerCompany { get; set; } diff --git a/Nop.Plugin.Misc.AIPlugin/Services/CustomPriceCalculationService.cs b/Nop.Plugin.Misc.AIPlugin/Services/CustomPriceCalculationService.cs index 152ad48..16e165e 100644 --- a/Nop.Plugin.Misc.AIPlugin/Services/CustomPriceCalculationService.cs +++ b/Nop.Plugin.Misc.AIPlugin/Services/CustomPriceCalculationService.cs @@ -71,10 +71,10 @@ public class CustomPriceCalculationService : PriceCalculationService return (finalPriceInclTax, finalPriceExclTax); } - public async Task CheckAndUpdateOrderItemFinalPricesAsync(OrderItem orderItem) + public async Task CheckAndUpdateOrderItemFinalPricesAsync(OrderItem orderItem, OrderItemDto? orderItemDtoHelper = null) { - var orderItemDto = await _dbContext.OrderItemDtos.GetByIdAsync(orderItem.Id, true); - return await CheckAndUpdateOrderItemFinalPricesAsync(orderItem, orderItemDto.IsMeasurable, orderItemDto.NetWeight); + orderItemDtoHelper ??= await _dbContext.OrderItemDtos.GetByIdAsync(orderItem.Id, true); + return await CheckAndUpdateOrderItemFinalPricesAsync(orderItem, orderItemDtoHelper.IsMeasurable, orderItemDtoHelper.NetWeight); } //public async Task CheckAndUpdateOrderItemFinalPricesAsync(OrderItemDto orderItemDto) diff --git a/Nop.Plugin.Misc.AIPlugin/Services/FruitBankAttributeService.cs b/Nop.Plugin.Misc.AIPlugin/Services/FruitBankAttributeService.cs index a3a1f0e..1458992 100644 --- a/Nop.Plugin.Misc.AIPlugin/Services/FruitBankAttributeService.cs +++ b/Nop.Plugin.Misc.AIPlugin/Services/FruitBankAttributeService.cs @@ -166,6 +166,12 @@ public class FruitBankAttributeService(IGenericAttributeService genericAttribute var ga = await GetGenericAttributeAsync(entityId, key, storeId); if (ga == null) return; - await genericAttributeService.DeleteAttributeAsync(ga); + await DeleteGenericAttributeAsync(ga); } + + public async Task DeleteGenericAttributeAsync(GenericAttribute genericAttribute) + => await genericAttributeService.DeleteAttributeAsync(genericAttribute); + + public async Task DeleteGenericAttributesAsync(IList genericAttributes) + => await genericAttributeService.DeleteAttributesAsync(genericAttributes); } \ No newline at end of file diff --git a/Nop.Plugin.Misc.AIPlugin/Services/ILockService.cs b/Nop.Plugin.Misc.AIPlugin/Services/ILockService.cs index 160a6b4..e7cf9c0 100644 --- a/Nop.Plugin.Misc.AIPlugin/Services/ILockService.cs +++ b/Nop.Plugin.Misc.AIPlugin/Services/ILockService.cs @@ -1,4 +1,4 @@ -using Mango.Nop.Services; +using Mango.Nop.Core.Services; namespace Nop.Plugin.Misc.FruitBankPlugin.Services; diff --git a/Nop.Plugin.Misc.AIPlugin/Services/IMeasurementService.cs b/Nop.Plugin.Misc.AIPlugin/Services/IMeasurementService.cs new file mode 100644 index 0000000..fe145b5 --- /dev/null +++ b/Nop.Plugin.Misc.AIPlugin/Services/IMeasurementService.cs @@ -0,0 +1,8 @@ +using FruitBank.Common.Interfaces; + +namespace Nop.Plugin.Misc.FruitBankPlugin.Services; + +public interface IMeasurementService : IMeasurementServiceBase +{ + +} \ No newline at end of file diff --git a/Nop.Plugin.Misc.AIPlugin/Services/MeasurementService.cs b/Nop.Plugin.Misc.AIPlugin/Services/MeasurementService.cs new file mode 100644 index 0000000..518e5f3 --- /dev/null +++ b/Nop.Plugin.Misc.AIPlugin/Services/MeasurementService.cs @@ -0,0 +1,59 @@ +using AyCode.Core.Loggers; +using FruitBank.Common.Dtos; +using FruitBank.Common.Interfaces; +using FruitBank.Common.Server.Services.SignalRs; +using FruitBank.Common.Services; +using Mango.Nop.Core.Extensions; +using Mango.Nop.Core.Loggers; +using Nop.Core.Domain.Catalog; +using Nop.Core.Domain.Orders; +using Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer; +using Nop.Services.Catalog; + +namespace Nop.Plugin.Misc.FruitBankPlugin.Services; + +#nullable enable +public class MeasurementService : MeasurementServiceBase, IMeasurementService +{ + private readonly FruitBankDbContext _dbContext; + private readonly SignalRSendToClientService _signalRSendToClientService; + private readonly CustomPriceCalculationService _customPriceCalculationService; + + public MeasurementService(FruitBankDbContext dbContext, SignalRSendToClientService signalRSendToClientService, FruitBankAttributeService fruitBankAttributeService, + IPriceCalculationService customPriceCalculationService, IEnumerable logWriters) : base(new Logger(logWriters.ToArray())) + { + _dbContext = dbContext; + _signalRSendToClientService = signalRSendToClientService; + _customPriceCalculationService = (CustomPriceCalculationService)customPriceCalculationService; + } + + + public async Task DeleteOrderItemConstraintsAsync(int orderItemId) => await DeleteOrderItemConstraintsAsync(await _dbContext.OrderItems.GetByIdAsync(orderItemId)); + + public async Task DeleteOrderItemConstraintsAsync(OrderItem orderItem) + { + Logger.Info($"DeleteOrderItemConstraintsAsync invoked; orderItem.Id: {orderItem?.Id}"); + + if (orderItem == null) return; + + await _dbContext.DeleteOrderItemConstraintsSafeAsync(orderItem); + await _signalRSendToClientService.SendOrderItemDeleted(orderItem); + } + + public async Task OrderItemInsertedOrUpdatedPostProcess(OrderItem orderItem) + { + var orderItemDto = await _dbContext.OrderItemDtos.GetByIdAsync(orderItem.Id, true); + + await CheckAndUpdateOrderItemFinalPricesAsync(orderItem, orderItemDto); + await _signalRSendToClientService.SendOrderItemChanged(orderItemDto); + } + + public async Task CheckAndUpdateOrderItemFinalPricesAsync(OrderItem orderItem, OrderItemDto? orderItemDtoHelper = null) + { + if (await _customPriceCalculationService.CheckAndUpdateOrderItemFinalPricesAsync(orderItem, orderItemDtoHelper)) + { + var order = await _dbContext.Orders.GetByIdAsync(orderItem.OrderId); + await _customPriceCalculationService.CheckAndUpdateOrderTotalPrice(order); + } + } +} \ No newline at end of file