SignalR improvements; etc...

This commit is contained in:
Loretta 2025-10-30 14:54:33 +01:00
parent 9a94bc6c06
commit 946748134c
16 changed files with 269 additions and 82 deletions

View File

@ -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;
@ -42,6 +44,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
{
@ -50,6 +55,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;
@ -58,13 +64,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;
@ -95,30 +101,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<IAcLogWriterBase> 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<IAcLogWriterBase> logWriters,
IStoreContext storeContext,
IWorkContext workContext,
IEventPublisher eventPublisher,
ILocalizationService localizationService,
ICustomerActivityService customerActivityService,
IExportManager exportManager,
IGiftCardService giftCardService,
IImportManager importManager,
IDateTimeHelper dateTimeHelper)
{
_logger = new Logger<CustomOrderController>(logWriters.ToArray());
_dbContext = fruitBankDbContext;
_sendToClient = sendToClient;
_orderService = orderService;
_orderModelFactory = orderModelFactory as CustomOrderModelFactory;
_customOrderSignalREndpoint = customOrderSignalREndpoint;
@ -143,14 +151,26 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers
}
#region CustomOrderSignalREndpoint
[NonAction] public Task<List<OrderDto>> GetAllOrderDtos() => _customOrderSignalREndpoint.GetAllOrderDtos();
[NonAction]public Task<OrderDto> GetOrderDtoById(int orderId) => _customOrderSignalREndpoint.GetOrderDtoById(orderId);
[NonAction]public Task<List<OrderDto>> GetPendingOrderDtos() => _customOrderSignalREndpoint.GetPendingOrderDtos();
[NonAction]public Task<List<OrderDto>> GetPendingOrderDtosForMeasuring() => _customOrderSignalREndpoint.GetPendingOrderDtosForMeasuring();
[NonAction] public Task<OrderDto> GetOrderDtoById(int orderId) => _customOrderSignalREndpoint.GetOrderDtoById(orderId);
[NonAction] public Task<List<OrderDto>> GetPendingOrderDtos() => _customOrderSignalREndpoint.GetPendingOrderDtos();
[NonAction] public Task<List<OrderDto>> GetPendingOrderDtosForMeasuring() => _customOrderSignalREndpoint.GetPendingOrderDtosForMeasuring();
[NonAction] public Task<OrderDto> StartMeasuring(int orderId, int userId) => _customOrderSignalREndpoint.StartMeasuring(orderId, userId);
[NonAction]public Task<OrderDto> SetOrderStatusToComplete(int orderId, int revisorId) => _customOrderSignalREndpoint.SetOrderStatusToComplete(orderId, revisorId);
[NonAction] public Task<OrderDto> SetOrderStatusToComplete(int orderId, int revisorId) => _customOrderSignalREndpoint.SetOrderStatusToComplete(orderId, revisorId);
[NonAction] public Task<List<OrderDto>> GetAllOrderDtoByIds(int[] orderIds) => _customOrderSignalREndpoint.GetAllOrderDtoByIds(orderIds);
[NonAction] public Task<OrderItemPallet> AddOrUpdateMeasuredOrderItemPallet(OrderItemPallet orderItemPallet) => _customOrderSignalREndpoint.AddOrUpdateMeasuredOrderItemPallet(orderItemPallet);
[NonAction] public Task<List<OrderItemDto>> GetAllOrderItemDtos() => _customOrderSignalREndpoint.GetAllOrderItemDtos();
[NonAction]public Task<List<OrderDto>> GetAllOrderDtoByProductId(int productId) => _customOrderSignalREndpoint.GetAllOrderDtoByProductId(productId);
[NonAction]public Task<OrderItemDto> GetOrderItemDtoById(int orderItemId) => _customOrderSignalREndpoint.GetOrderItemDtoById(orderItemId);
[NonAction]public Task<List<OrderItemDto>> GetAllOrderItemDtoByOrderId(int orderId) => _customOrderSignalREndpoint.GetAllOrderItemDtoByOrderId(orderId);
[NonAction]public Task<List<OrderItemDto>> GetAllOrderItemDtoByProductId(int productId) => _customOrderSignalREndpoint.GetAllOrderItemDtoByProductId(productId);
[NonAction] public Task<List<OrderItemPallet>> GetAllOrderItemPallets() => _customOrderSignalREndpoint.GetAllOrderItemPallets();
[NonAction] public Task<OrderItemPallet> GetOrderItemPalletById(int orderItemPalletId) => _customOrderSignalREndpoint.GetOrderItemPalletById(orderItemPalletId);
[NonAction] public Task<List<OrderItemPallet>> GetAllOrderItemPalletByOrderItemId(int orderItemId) => _customOrderSignalREndpoint.GetAllOrderItemPalletByOrderItemId(orderItemId);
[NonAction] public Task<List<OrderItemPallet>> GetAllOrderItemPalletByOrderId(int orderId) => _customOrderSignalREndpoint.GetAllOrderItemPalletByOrderId(orderId);
[NonAction] public Task<List<OrderItemPallet>> GetAllOrderItemPalletByProductId(int productId) => _customOrderSignalREndpoint.GetAllOrderItemPalletByProductId(productId);
[NonAction]public Task<OrderItemPallet> AddOrUpdateMeasuredOrderItemPallet(OrderItemPallet orderItemPallet) => _customOrderSignalREndpoint.AddOrUpdateMeasuredOrderItemPallet(orderItemPallet);
#endregion CustomOrderSignalREndpoint
[CheckPermission(StandardPermission.Orders.ORDERS_VIEW)]
@ -162,7 +182,7 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers
OrderStatusIds = orderStatuses,
PaymentStatusIds = paymentStatuses,
ShippingStatusIds = shippingStatuses,
});
});
return View("~/Plugins/Misc.FruitBankPlugin/Areas/Admin/Views/Order/List.cshtml", model);
}
@ -174,7 +194,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;
@ -217,7 +237,7 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers
{
//return _customOrderService.
var orderListModel = await _orderModelFactory.PrepareOrderListModelExtendedAsync(searchModel);
_logger.Detail($"Total: {orderListModel.RecordsTotal}, Data Count: {orderListModel.Data.Count()}");
foreach (var item in orderListModel.Data.Take(3))
{
@ -258,12 +278,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 });
}
@ -279,11 +303,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];
@ -330,7 +354,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)
@ -388,6 +412,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;
});
@ -485,7 +512,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<IActionResult> CustomerSearchAutoComplete(string term)
{
@ -534,7 +561,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}";
@ -738,10 +765,12 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers
[CheckPermission(StandardPermission.Orders.ORDERS_IMPORT_EXPORT)]
public virtual async Task<IActionResult> ExportXmlAll(OrderSearchModel 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
@ -834,10 +863,12 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers
[CheckPermission(StandardPermission.Orders.ORDERS_IMPORT_EXPORT)]
public virtual async Task<IActionResult> ExportExcelAll(OrderSearchModel 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
@ -954,9 +985,7 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers
return RedirectToAction("List");
}
}
#endregion
#endregion
}
}

View File

@ -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<IAcLogWriterBase> logWriters) : ICustomOrderSignalREndpointServer
public class CustomOrderSignalREndpoint(FruitBankDbContext ctx, SignalRSendToClientService sendToClient, IPriceCalculationService customPriceCalculationService,IEventPublisher eventPublisher, IWorkContext workContext, IEnumerable<IAcLogWriterBase> logWriters)
: ICustomOrderSignalREndpointServer
{
private readonly ILogger _logger = new Logger<CustomOrderSignalREndpoint>(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<List<OrderDto>> GetAllOrderDtoByProductId(int productId)
{
return await ctx.OrderDtos.GetAllByProductId(productId, true).ToListAsync();
}
[SignalR(SignalRTags.GetOrderItemDtoById)]
public async Task<OrderItemDto> GetOrderItemDtoById(int orderItemId)
{
return await ctx.OrderItemDtos.GetByIdAsync(orderItemId, true);
}
[SignalR(SignalRTags.GetAllOrderItemDtos)]
public async Task<List<OrderItemDto>> GetAllOrderItemDtos()
{
return await ctx.OrderItemDtos.GetAll(true).ToListAsync();
}
[SignalR(SignalRTags.GetAllOrderItemDtoByOrderId)]
public async Task<List<OrderItemDto>> GetAllOrderItemDtoByOrderId(int orderId)
{
return await ctx.OrderItemDtos.GetAllByOrderId(orderId, true).ToListAsync();
}
[SignalR(SignalRTags.GetAllOrderItemDtoByProductId)]
public async Task<List<OrderItemDto>> GetAllOrderItemDtoByProductId(int productId)
{
return await ctx.OrderItemDtos.GetAllByProductId(productId, true).ToListAsync();
}
[SignalR(SignalRTags.GetOrderItemPalletById)]
public async Task<OrderItemPallet> GetOrderItemPalletById(int orderItemPalletId)
{
return await ctx.OrderItemPallets.GetByIdAsync(orderItemPalletId, true);
}
[SignalR(SignalRTags.GetAllOrderItemPallets)]
public async Task<List<OrderItemPallet>> GetAllOrderItemPallets()
{
return await ctx.OrderItemPallets.GetAll(true).ToListAsync();
}
[SignalR(SignalRTags.GetAllOrderItemPalletByOrderItemId)]
public async Task<List<OrderItemPallet>> GetAllOrderItemPalletByOrderItemId(int orderItemId)
{
return await ctx.OrderItemPallets.GetAllByOrderItemId(orderItemId, true).ToListAsync();
}
[SignalR(SignalRTags.GetAllOrderItemPalletByOrderId)]
public async Task<List<OrderItemPallet>> GetAllOrderItemPalletByOrderId(int orderId)
{
return await ctx.OrderItemPallets.GetAllByOrderId(orderId).ToListAsync();
}
[SignalR(SignalRTags.GetAllOrderItemPalletByProductId)]
public async Task<List<OrderItemPallet>> GetAllOrderItemPalletByProductId(int productId)
{
return await ctx.OrderItemPallets.GetAllByProductId(productId).ToListAsync();
}
[SignalR(SignalRTags.StartMeasuring, SignalRTags.SendOrderChanged, SendToClientType.Others)]
public async Task<OrderDto> 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<OrderDto> 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<OrderItemPallet> 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);
}

View File

@ -360,15 +360,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,
@ -384,13 +392,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)
@ -458,6 +468,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 '<span class="grid-report-item ' + color + '">' + data + '</span>';
}
function renderColumnCustomer(data, type, row, meta) {
console.log("Hello World 2");
var link = '@Url.Content("~/Admin/Customer/Edit/")' + row.CustomerId;

View File

@ -154,6 +154,10 @@
<th>
@T("FruitBank.IsMeasurable")
</th>
<th>
Mérés állapota
</th>
@* <th>
@T("Admin.Orders.Products.Discount")
</th> *@
@ -323,6 +327,12 @@
}
<input type="hidden" name="pvIsMeasurable@(item.Id)" id="pvIsMeasurable@(item.Id)" value="@(item.IsMeasurable.ToString())" disabled />
</td>
<td style="width: 100px;" class="text-center">
<div>
<span>@($"{item.MeasuringStatusString}")</span>
</div>
</td>
@* <td style="width: 15%;" class="text-center">
@if (Model.AllowCustomersToSelectTaxDisplayType)

View File

@ -428,20 +428,24 @@ 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<double>(orderItemDto.GenericAttributes.FirstOrDefault(x => x.Key == nameof(IMeasuringNetWeight.NetWeight))?.Value ?? "0");
var prevNetWeightFromGa = orderItemDto.GenericAttributes.GetValueOrDefault(nameof(IMeasuringNetWeight.NetWeight), 0);
//var gaNetWeight = CommonHelper.To<double>(orderItemDto.GenericAttributes.FirstOrDefault(x => x.Key == nameof(IMeasuringNetWeight.NetWeight))?.Value ?? "0");
await _fruitBankAttributeService.InsertOrUpdateGenericAttributeAsync<OrderItem, double>
(orderItemDto.Id, nameof(IMeasuringNetWeight.NetWeight), orderItemDto.NetWeight);
await _fruitBankAttributeService.InsertOrUpdateMeasuringAttributeValuesAsync<Product>
(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;
}
@ -483,10 +487,7 @@ public class FruitBankDbContext : MgDbContextBase,
private async Task<bool> 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;

View File

@ -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<OrderDto, Order>
public Task<OrderDto> GetByIdAsync(int orderId, bool loadRelations) => GetAll(loadRelations).Where(x => x.Id == orderId).FirstOrDefaultAsync(null);
public IQueryable<OrderDto> GetAllByOrderStatus(OrderStatus orderStatus, bool loadRelations = true)
public IQueryable<OrderDto> GetAllByOrderStatus(OrderStatus orderStatus, bool loadRelations = true)
=> GetAll(loadRelations).Where(o => o.OrderStatusId == (int)orderStatus);
public IQueryable<OrderDto> 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<OrderDto> GetAllByProductId(int productId, bool loadRelations = true) => GetAll(loadRelations).Where(o => o.OrderItemDtos.Any(oi => oi.ProductId == productId));
public IQueryable<OrderDto> GetAllByIds(IEnumerable<int> orderIds, bool loadRelations = true) => GetAll(loadRelations).Where(o => orderIds.Contains(o.Id));
}

View File

@ -20,15 +20,17 @@ public class OrderItemDtoDbTable : MgDtoDbTableBase<OrderItemDto, OrderItem>
public IQueryable<OrderItemDto> 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<OrderItemDto> GetByIdAsync(int orderItemId, bool loadRelations) => GetAll(loadRelations).Where(oi => oi.Id == orderItemId).FirstOrDefaultAsync(null);
public IQueryable<OrderItemDto> GetAllByOrderId(int orderId, bool loadRelations = true)=> GetAll(loadRelations).Where(oi => oi.OrderId == orderId);
public IQueryable<OrderItemDto> GetAllByProductId(int productId, bool loadRelations = true)=> GetAll(loadRelations).Where(oi => oi.ProductId == productId);
public IQueryable<OrderItemDto> GetAllByIds(IEnumerable<int> orderItemIds, bool loadRelations = true) => GetAll(loadRelations).Where(oi => orderItemIds.Contains(oi.Id));
public IQueryable<OrderItemDto> GetAllByOrderIds(IEnumerable<int> orderIds, bool loadRelations = true) => GetAll(loadRelations).Where(oi => orderIds.Contains(oi.OrderId));
}

View File

@ -21,13 +21,21 @@ public class OrderItemPalletDbTable : MeasuringItemPalletBaseDbTable<OrderItemPa
{
return loadRelations
? GetAll()
.LoadWith(oip => 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<OrderItemPallet> GetByIdAsync(int id, bool loadRelations)
=> GetAll(loadRelations).FirstOrDefaultAsync(oip => oip.Id == id);
public IQueryable<OrderItemPallet> GetAllByOrderItemIdAsync(int orderItemId, bool loadRelations)
public IQueryable<OrderItemPallet> GetAllByOrderItemId(int orderItemId, bool loadRelations)
=> GetAll(loadRelations).Where(oip => oip.OrderItemId == orderItemId);
public IQueryable<OrderItemPallet> GetAllByOrderId(int orderId)
=> GetAll(true).Where(oip => oip.OrderItemDto.OrderId == orderId);
public IQueryable<OrderItemPallet> GetAllByProductId(int productId)
=> GetAll(true).Where(oip => oip.OrderItemDto.ProductId == productId);
}

View File

@ -259,21 +259,19 @@ public class FruitBankEventConsumer :
public async Task HandleEventAsync(EntityUpdatedEvent<OrderItem> 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 CheckAndUpdateOrderItemFinalPricesAsync(eventMessage.Entity);
}
public async Task HandleEventAsync(EntityInsertedEvent<OrderItem> eventMessage)
{
//await _customPriceCalculationService.CheckAndUpdateOrderItemFinalPricesAsync(eventMessage.Entity);
if (await _customPriceCalculationService.CheckAndUpdateOrderItemFinalPricesAsync(eventMessage.Entity))
await CheckAndUpdateOrderItemFinalPricesAsync(eventMessage.Entity);
}
private async Task CheckAndUpdateOrderItemFinalPricesAsync(OrderItem orderItem)
{
if (await _customPriceCalculationService.CheckAndUpdateOrderItemFinalPricesAsync(orderItem))
{
var order = await _ctx.Orders.GetByIdAsync(eventMessage.Entity.OrderId);
var order = await _ctx.Orders.GetByIdAsync(orderItem.OrderId);
await _customPriceCalculationService.CheckAndUpdateOrderTotalPrice(order);
}
}

View File

@ -176,6 +176,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;
@ -209,11 +210,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<OrderItemModelExtended>();
orderModelExtended.ItemExtendeds.Add(orderItemModelExtended);

View File

@ -72,6 +72,8 @@ public class PluginNopStartup : INopStartup
services.AddScoped<ShippingDocumentToFilesDbTable>();
services.AddScoped<FruitBankDbContext>();
services.AddScoped<SignalRSendToClientService>();
services.AddScoped<IFruitBankDataControllerServer, FruitBankDataController>();
services.AddScoped<ICustomOrderSignalREndpointServer, CustomOrderSignalREndpoint>();
@ -84,6 +86,8 @@ public class PluginNopStartup : INopStartup
services.AddScoped<InnVoiceApiService>();
services.AddScoped<InnVoiceOrderService>();
services.AddScoped<MeasurementService>();
//services.AddScoped<OrderListModel, OrderListModelExtended>();
//services.AddScoped<OrderModel, OrderModelExtended>();
//services.AddScoped<OrderSearchModel, OrderSearchModelExtended>();
@ -100,7 +104,13 @@ public class PluginNopStartup : INopStartup
options.Filters.AddService<PendingMeasurementCheckoutFilter>();
});
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);
});
}
/// <summary>

View File

@ -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; }
}

View File

@ -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; }

View File

@ -1,4 +1,4 @@
using Mango.Nop.Services;
using Mango.Nop.Core.Services;
namespace Nop.Plugin.Misc.FruitBankPlugin.Services;

View File

@ -0,0 +1,8 @@
using FruitBank.Common.Interfaces;
namespace Nop.Plugin.Misc.FruitBankPlugin.Services;
public interface IMeasurementService : IMeasurementServiceBase
{
}

View File

@ -0,0 +1,8 @@
using FruitBank.Common.Services;
namespace Nop.Plugin.Misc.FruitBankPlugin.Services;
public class MeasurementService : MeasurementServiceBase, IMeasurementService
{
}