This commit is contained in:
Adam 2025-10-31 15:10:57 +01:00
commit 771832c6e4
18 changed files with 384 additions and 96 deletions

View File

@ -4,11 +4,13 @@ using FruitBank.Common.Dtos;
using FruitBank.Common.Entities; using FruitBank.Common.Entities;
using FruitBank.Common.Interfaces; using FruitBank.Common.Interfaces;
using FruitBank.Common.Server.Interfaces; using FruitBank.Common.Server.Interfaces;
using FruitBank.Common.Server.Services.SignalRs;
using FruitBank.Common.SignalRs; using FruitBank.Common.SignalRs;
using Mango.Nop.Core.Extensions; using Mango.Nop.Core.Extensions;
using Mango.Nop.Core.Loggers; using Mango.Nop.Core.Loggers;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR;
using Newtonsoft.Json; using Newtonsoft.Json;
using Nop.Core; using Nop.Core;
using Nop.Core.Domain.Customers; using Nop.Core.Domain.Customers;
@ -43,6 +45,9 @@ using System.Text;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
using System.Xml; using System.Xml;
using System.Xml.Serialization; using System.Xml.Serialization;
using AyCode.Services.Server.SignalRs;
using AyCode.Core.Extensions;
using MessagePack.Resolvers;
namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers 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 public class CustomOrderController : BaseAdminController, ICustomOrderSignalREndpointServer
{ {
private readonly FruitBankDbContext _dbContext; private readonly FruitBankDbContext _dbContext;
private readonly SignalRSendToClientService _sendToClient;
private readonly IOrderService _orderService; private readonly IOrderService _orderService;
private readonly CustomOrderModelFactory _orderModelFactory; private readonly CustomOrderModelFactory _orderModelFactory;
@ -96,7 +102,7 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers
return hasVendorProducts; return hasVendorProducts;
} }
public CustomOrderController(FruitBankDbContext fruitBankDbContext, public CustomOrderController(FruitBankDbContext fruitBankDbContext, SignalRSendToClientService sendToClient,
IOrderService orderService, IOrderService orderService,
IPriceCalculationService priceCalculationService, IPriceCalculationService priceCalculationService,
IOrderModelFactory orderModelFactory, IOrderModelFactory orderModelFactory,
@ -120,6 +126,8 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers
_logger = new Logger<CustomOrderController>(logWriters.ToArray()); _logger = new Logger<CustomOrderController>(logWriters.ToArray());
_dbContext = fruitBankDbContext; _dbContext = fruitBankDbContext;
_sendToClient = sendToClient;
_orderService = orderService; _orderService = orderService;
_orderModelFactory = orderModelFactory as CustomOrderModelFactory; _orderModelFactory = orderModelFactory as CustomOrderModelFactory;
_customOrderSignalREndpoint = customOrderSignalREndpoint; _customOrderSignalREndpoint = customOrderSignalREndpoint;
@ -144,6 +152,7 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers
} }
#region CustomOrderSignalREndpoint #region CustomOrderSignalREndpoint
[NonAction] public Task<List<OrderDto>> GetAllOrderDtos() => _customOrderSignalREndpoint.GetAllOrderDtos(); [NonAction] public Task<List<OrderDto>> GetAllOrderDtos() => _customOrderSignalREndpoint.GetAllOrderDtos();
[NonAction] public Task<OrderDto> GetOrderDtoById(int orderId) => _customOrderSignalREndpoint.GetOrderDtoById(orderId); [NonAction] public Task<OrderDto> GetOrderDtoById(int orderId) => _customOrderSignalREndpoint.GetOrderDtoById(orderId);
[NonAction] public Task<List<OrderDto>> GetPendingOrderDtos() => _customOrderSignalREndpoint.GetPendingOrderDtos(); [NonAction] public Task<List<OrderDto>> GetPendingOrderDtos() => _customOrderSignalREndpoint.GetPendingOrderDtos();
@ -151,7 +160,18 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers
[NonAction] public Task<OrderDto> StartMeasuring(int orderId, int userId) => _customOrderSignalREndpoint.StartMeasuring(orderId, userId); [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<List<OrderDto>> GetAllOrderDtoByIds(int[] orderIds) => _customOrderSignalREndpoint.GetAllOrderDtoByIds(orderIds);
[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); [NonAction]public Task<OrderItemPallet> AddOrUpdateMeasuredOrderItemPallet(OrderItemPallet orderItemPallet) => _customOrderSignalREndpoint.AddOrUpdateMeasuredOrderItemPallet(orderItemPallet);
#endregion CustomOrderSignalREndpoint #endregion CustomOrderSignalREndpoint
[CheckPermission(StandardPermission.Orders.ORDERS_VIEW)] [CheckPermission(StandardPermission.Orders.ORDERS_VIEW)]
@ -329,12 +349,16 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers
if (order == null) if (order == null)
return RedirectToAction("List", "Order"); 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 // store attributes in GenericAttribute table
//await _genericAttributeService.SaveAttributeAsync(order, nameof(IMeasurable.IsMeasurable), model.IsMeasurable, _storeContext.GetCurrentStore().Id); //await _genericAttributeService.SaveAttributeAsync(order, nameof(IMeasurable.IsMeasurable), model.IsMeasurable, _storeContext.GetCurrentStore().Id);
await _genericAttributeService.SaveAttributeAsync(order, nameof(IOrderDto.DateOfReceipt), model.DateOfReceipt, _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 }); return RedirectToAction("Edit", "Order", new { id = model.OrderId });
} }
@ -459,6 +483,9 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers
await _orderService.UpdateOrderAsync(order); 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; return true;
}); });
@ -809,10 +836,12 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers
[CheckPermission(StandardPermission.Orders.ORDERS_IMPORT_EXPORT)] [CheckPermission(StandardPermission.Orders.ORDERS_IMPORT_EXPORT)]
public virtual async Task<IActionResult> ExportXmlAll(OrderSearchModelExtended model) public virtual async Task<IActionResult> ExportXmlAll(OrderSearchModelExtended model)
{ {
var startDateValue = model.StartDate == null ? null var startDateValue = model.StartDate == null
? null
: (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.StartDate.Value, await _dateTimeHelper.GetCurrentTimeZoneAsync()); : (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); : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.EndDate.Value, await _dateTimeHelper.GetCurrentTimeZoneAsync()).AddDays(1);
//a vendor should have access only to his products //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)] [CheckPermission(StandardPermission.Orders.ORDERS_IMPORT_EXPORT)]
public virtual async Task<IActionResult> ExportExcelAll(OrderSearchModelExtended model) public virtual async Task<IActionResult> ExportExcelAll(OrderSearchModelExtended model)
{ {
var startDateValue = model.StartDate == null ? null var startDateValue = model.StartDate == null
? null
: (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.StartDate.Value, await _dateTimeHelper.GetCurrentTimeZoneAsync()); : (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); : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.EndDate.Value, await _dateTimeHelper.GetCurrentTimeZoneAsync()).AddDays(1);
//a vendor should have access only to his products //a vendor should have access only to his products
@ -1025,9 +1056,7 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers
return RedirectToAction("List"); return RedirectToAction("List");
} }
} }
#endregion #endregion
} }
} }

View File

@ -4,6 +4,7 @@ using FruitBank.Common.Dtos;
using FruitBank.Common.Entities; using FruitBank.Common.Entities;
using FruitBank.Common.Interfaces; using FruitBank.Common.Interfaces;
using FruitBank.Common.Server.Interfaces; using FruitBank.Common.Server.Interfaces;
using FruitBank.Common.Server.Services.SignalRs;
using FruitBank.Common.SignalRs; using FruitBank.Common.SignalRs;
using Mango.Nop.Core.Loggers; using Mango.Nop.Core.Loggers;
using Nop.Core; 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.Domains.DataLayer;
using Nop.Plugin.Misc.FruitBankPlugin.Services; using Nop.Plugin.Misc.FruitBankPlugin.Services;
using Nop.Services.Catalog; using Nop.Services.Catalog;
using static Nop.Services.Security.StandardPermission;
namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers; 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()); 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(); 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) public async Task<OrderDto> StartMeasuring(int orderId, int userId)
{ {
_logger.Detail($"StartMeasuring invoked; orderId: {orderId}; userId: {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); 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) public async Task<OrderDto> SetOrderStatusToComplete(int orderId, int revisorId)
{ {
_logger.Detail($"SetOrderStatusToComplete invoked; orderId: {orderId}; revisorId: {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); return await ctx.OrderDtos.GetByIdAsync(orderId, true);
} }
[SignalR(SignalRTags.AddOrUpdateMeasuredOrderItemPallet)] [SignalR(SignalRTags.AddOrUpdateMeasuredOrderItemPallet, SignalRTags.SendOrderItemPalletChanged, SendToClientType.Others)]
public async Task<OrderItemPallet> AddOrUpdateMeasuredOrderItemPallet(OrderItemPallet orderItemPallet) public async Task<OrderItemPallet> AddOrUpdateMeasuredOrderItemPallet(OrderItemPallet orderItemPallet)
{ {
ArgumentNullException.ThrowIfNull(orderItemPallet); ArgumentNullException.ThrowIfNull(orderItemPallet);
@ -87,6 +148,21 @@ public class CustomOrderSignalREndpoint(FruitBankDbContext ctx, IPriceCalculatio
_logger.Detail($"AddOrUpdateMeasuredOrderItemPallet invoked; {orderItemPallet}"); _logger.Detail($"AddOrUpdateMeasuredOrderItemPallet invoked; {orderItemPallet}");
if (!await ctx.AddOrUpdateOrderItemPalletSafeAsync(orderItemPallet)) return null; 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); return await ctx.OrderItemPallets.GetByIdAsync(orderItemPallet.Id, false);
} }

View File

@ -405,14 +405,22 @@
ClassName = NopColumnClassDefaults.CenterAll 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, Title = "Mérés állapota", //T($"FruitBank.{nameof(OrderModelExtended.MeasuringStatus)}").Text,
Width = "80", Width = "100",
Render = new RenderCustom("renderColumnIsMeasurable"), Render = new RenderCustom("renderColumnMeasuringStatus"),
ClassName = NopColumnClassDefaults.CenterAll 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)) gridModel.ColumnCollection.Add(new ColumnProperty(nameof(IOrderDto.DateOfReceipt))
{ {
Title = T($"FruitBank.{nameof(IOrderDto.DateOfReceipt)}").Text, Title = T($"FruitBank.{nameof(IOrderDto.DateOfReceipt)}").Text,
@ -428,13 +436,15 @@
{ {
Title = T("Admin.Orders.Fields.OrderStatus").Text, Title = T("Admin.Orders.Fields.OrderStatus").Text,
Width = "100", Width = "100",
Render = new RenderCustom("renderColumnOrderStatus") Render = new RenderCustom("renderColumnOrderStatus"),
ClassName = NopColumnClassDefaults.CenterAll
}); });
} }
gridModel.ColumnCollection.Add(new ColumnProperty(nameof(OrderModel.PaymentStatus)) gridModel.ColumnCollection.Add(new ColumnProperty(nameof(OrderModel.PaymentStatus))
{ {
Title = T("Admin.Orders.Fields.PaymentStatus").Text, Title = T("Admin.Orders.Fields.PaymentStatus").Text,
Width = "130" Width = "130",
ClassName = NopColumnClassDefaults.CenterAll
}); });
//a vendor does not have access to this functionality //a vendor does not have access to this functionality
if (!Model.IsLoggedInAsVendor) 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 '<span class="grid-report-item ' + color + '">' + data + '</span>';
}
function renderColumnCustomer(data, type, row, meta) { function renderColumnCustomer(data, type, row, meta) {
console.log("Hello World 2"); console.log("Hello World 2");
var link = '@Url.Content("~/Admin/Customer/Edit/")' + row.CustomerId; var link = '@Url.Content("~/Admin/Customer/Edit/")' + row.CustomerId;

View File

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

View File

@ -12,6 +12,7 @@ using Mango.Nop.Core.Repositories;
using Nop.Core; using Nop.Core;
using Nop.Core.Caching; using Nop.Core.Caching;
using Nop.Core.Domain.Catalog; using Nop.Core.Domain.Catalog;
using Nop.Core.Domain.Common;
using Nop.Core.Domain.Customers; using Nop.Core.Domain.Customers;
using Nop.Core.Domain.Orders; using Nop.Core.Domain.Orders;
using Nop.Core.Events; using Nop.Core.Events;
@ -63,6 +64,8 @@ public class FruitBankDbContext : MgDbContextBase,
public IRepository<CustomerCustomerRoleMapping> CustomerRoleMappings { get; set; } public IRepository<CustomerCustomerRoleMapping> CustomerRoleMappings { get; set; }
public IRepository<CustomerAddressMapping> CustomerAddressMappings { get; set; } public IRepository<CustomerAddressMapping> CustomerAddressMappings { get; set; }
public IRepository<GenericAttribute> GenericAttributes { get; set; }
public FruitBankDbContext(INopDataProvider dataProvider, ILockService lockService, FruitBankAttributeService fruitBankAttributeService, IStoreContext storeContext, public FruitBankDbContext(INopDataProvider dataProvider, ILockService lockService, FruitBankAttributeService fruitBankAttributeService, IStoreContext storeContext,
PartnerDbTable partnerDbTable, ShippingDbTable shippingDbTable, ShippingDocumentDbTable shippingDocumentDbTable, ShippingItemDbTable shippingItemDbTable, PartnerDbTable partnerDbTable, ShippingDbTable shippingDbTable, ShippingDocumentDbTable shippingDocumentDbTable, ShippingItemDbTable shippingItemDbTable,
ShippingItemPalletDbTable shippingItemPalletDbTable, FilesDbTable filesDbTable, ShippingDocumentToFilesDbTable shippingDocumentToFilesDbTable, ShippingItemPalletDbTable shippingItemPalletDbTable, FilesDbTable filesDbTable, ShippingDocumentToFilesDbTable shippingDocumentToFilesDbTable,
@ -74,7 +77,9 @@ public class FruitBankDbContext : MgDbContextBase,
IRepository<Customer> customerRepository, IRepository<Customer> customerRepository,
IRepository<CustomerCustomerRoleMapping> customerCustomerRoleMappingRepository, IRepository<CustomerCustomerRoleMapping> customerCustomerRoleMappingRepository,
IRepository<CustomerAddressMapping> customerAddressMappingRepository, IRepository<CustomerAddressMapping> customerAddressMappingRepository,
IRepository<CustomerRole> customerRoleRepository,IEventPublisher eventPublisher, IRepository<CustomerRole> customerRoleRepository,
IRepository<GenericAttribute> genericAttributes,
IEventPublisher eventPublisher,
IEnumerable<IAcLogWriterBase> logWriters) : base(productRepository, orderRepository, orderItemRepository, dataProvider, lockService, new Logger<FruitBankDbContext>(logWriters.ToArray())) IEnumerable<IAcLogWriterBase> logWriters) : base(productRepository, orderRepository, orderItemRepository, dataProvider, lockService, new Logger<FruitBankDbContext>(logWriters.ToArray()))
{ {
_eventPublisher = eventPublisher; _eventPublisher = eventPublisher;
@ -103,6 +108,8 @@ public class FruitBankDbContext : MgDbContextBase,
CustomerRoles = customerRoleRepository; CustomerRoles = customerRoleRepository;
CustomerRoleMappings = customerCustomerRoleMappingRepository; CustomerRoleMappings = customerCustomerRoleMappingRepository;
CustomerAddressMappings = customerAddressMappingRepository; CustomerAddressMappings = customerAddressMappingRepository;
GenericAttributes = genericAttributes;
} }
public IQueryable<Customer> GetCustomersBySystemRoleName(string systemRoleName) public IQueryable<Customer> GetCustomersBySystemRoleName(string systemRoleName)
@ -193,7 +200,7 @@ public class FruitBankDbContext : MgDbContextBase,
ProductDto? productDto = null; ProductDto? productDto = null;
var productIsMeasurable = false; var productIsMeasurable = false;
if (shippingItem.ProductId > 0) if (shippingItem.ProductId.GetValueOrDefault(0) > 0)
{ {
productDto = await ProductDtos.GetByIdAsync(shippingItem.ProductId!.Value, true); productDto = await ProductDtos.GetByIdAsync(shippingItem.ProductId!.Value, true);
@ -263,7 +270,7 @@ public class FruitBankDbContext : MgDbContextBase,
//if (productIdUnchanged || !dbShippingItem.IsMeasured) return true; //if (productIdUnchanged || !dbShippingItem.IsMeasured) return true;
if (!productIdChanged && (shippingItem.IsMeasured || !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) if (productDto != null)
{ {
@ -431,24 +438,65 @@ public class FruitBankDbContext : MgDbContextBase,
{ {
if (orderItemDto.TrayQuantity != orderItemDto.Quantity) return null; if (orderItemDto.TrayQuantity != orderItemDto.Quantity) return null;
//orderItemDto.ProductDto!.StockQuantity -= orderItemDto.TrayQuantity; foreach (var orderItemPallet in orderItemDto.OrderItemPallets.Where(oip => oip.RevisorId <= 0))
//await ProductDtos.UpdateAsync(orderItemDto.ProductDto); {
orderItemPallet.RevisorId = revisorId;
await OrderItemPallets.UpdateAsync(orderItemPallet, false);
}
if (!orderItemDto.IsMeasurable) continue; 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> await _fruitBankAttributeService.InsertOrUpdateGenericAttributeAsync<OrderItem, double>
(orderItemDto.Id, nameof(IMeasuringNetWeight.NetWeight), orderItemDto.NetWeight); (orderItemDto.Id, nameof(IMeasuringNetWeight.NetWeight), orderItemDto.NetWeight);
await _fruitBankAttributeService.InsertOrUpdateMeasuringAttributeValuesAsync<Product> 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)); //await _eventPublisher.PublishAsync(new OrderStatusChangedEvent(order, prevOrderStatus));
return orderDto; 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<double>(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<Product, double>(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<OrderItemPallet?> AddOrderItemPalletAsync(OrderItemPallet orderItemPallet) public async Task<OrderItemPallet?> AddOrderItemPalletAsync(OrderItemPallet orderItemPallet)
{ {
if (!await SetupOrderItemPalletMeauringValues(orderItemPallet)) return null; if (!await SetupOrderItemPalletMeauringValues(orderItemPallet)) return null;
@ -486,10 +534,7 @@ public class FruitBankDbContext : MgDbContextBase,
private async Task<bool> SetupOrderItemPalletMeauringValues(OrderItemPallet orderItemPallet) private async Task<bool> SetupOrderItemPalletMeauringValues(OrderItemPallet orderItemPallet)
{ {
OrderItemDto orderItemDto; var orderItemDto = await OrderItemDtos.GetByIdAsync(orderItemPallet.OrderItemId, true);
if (orderItemPallet.OrderItemDto?.ProductDto == null) orderItemDto = await OrderItemDtos.GetByIdAsync(orderItemPallet.OrderItemId, true);
else orderItemDto = orderItemPallet.OrderItemDto;
if (orderItemDto == null || orderItemPallet.OrderItemId != orderItemDto.Id || //orderItemDto.IsOtherMeasuringInProgress(orderItemPallet.CreatorId) || if (orderItemDto == null || orderItemPallet.OrderItemId != orderItemDto.Id || //orderItemDto.IsOtherMeasuringInProgress(orderItemPallet.CreatorId) ||
orderItemPallet.TrayQuantity > orderItemDto.Quantity || !orderItemPallet.IsValidSafeMeasuringValues()) return false; orderItemPallet.TrayQuantity > orderItemDto.Quantity || !orderItemPallet.IsValidSafeMeasuringValues()) return false;
@ -503,7 +548,7 @@ public class FruitBankDbContext : MgDbContextBase,
private async Task<bool> UpdateProductDtoStockQuantityAsync(int productDtoId, bool publishEvent) private async Task<bool> 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); if (productDto != null) return await UpdateProductDtoStockQuantityAsync(productDto, publishEvent);
Logger.Error($"product == null; id: {productDtoId}"); Logger.Error($"product == null; id: {productDtoId}");

View File

@ -8,6 +8,7 @@ using Nop.Core.Domain.Orders;
using Nop.Core.Events; using Nop.Core.Events;
using Nop.Data; using Nop.Data;
using Mango.Nop.Core.Loggers; using Mango.Nop.Core.Loggers;
using Nop.Core.Domain.Payments;
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer; namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
@ -34,7 +35,10 @@ public class OrderDtoDbTable : MgDtoDbTableBase<OrderDto, Order>
=> GetAll(loadRelations).Where(o => o.OrderStatusId == (int)orderStatus); => GetAll(loadRelations).Where(o => o.OrderStatusId == (int)orderStatus);
public IQueryable<OrderDto> GetAllForMeasuring(bool loadRelations = true) 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)); 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) public IQueryable<OrderItemDto> GetAll(bool loadRelations)
{ {
return GetAll() return GetAll()
.LoadWith(oi => oi.OrderDto)
.LoadWith(oi => oi.OrderItemPallets)
.LoadWith(oi => oi.GenericAttributes) .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); .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 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> 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> 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 return loadRelations
? GetAll() ? 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(); : GetAll();
} }
public Task<OrderItemPallet> GetByIdAsync(int id, bool loadRelations) public Task<OrderItemPallet> GetByIdAsync(int id, bool loadRelations)
=> GetAll(loadRelations).FirstOrDefaultAsync(oip => oip.Id == id); => 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); => 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

@ -29,19 +29,21 @@ public class FruitBankEventConsumer :
IConsumer<EntityDeletedEvent<ShippingItemPallet>>, IConsumer<EntityDeletedEvent<ShippingItemPallet>>,
IConsumer<EntityInsertedEvent<OrderItem>>, IConsumer<EntityInsertedEvent<OrderItem>>,
IConsumer<EntityUpdatedEvent<OrderItem>> IConsumer<EntityUpdatedEvent<OrderItem>>,
IConsumer<EntityDeletedEvent<OrderItem>>
{ {
private readonly CustomPriceCalculationService _customPriceCalculationService; //private readonly CustomPriceCalculationService _customPriceCalculationService;
private readonly FruitBankDbContext _ctx; private readonly FruitBankDbContext _ctx;
private readonly MeasurementService _measurementService;
private readonly FruitBankAttributeService _fruitBankAttributeService; private readonly FruitBankAttributeService _fruitBankAttributeService;
public FruitBankEventConsumer(IHttpContextAccessor httpContextAcc, IPriceCalculationService customPriceCalculationService, FruitBankDbContext ctx, FruitBankAttributeService fruitBankAttributeService, IEnumerable<IAcLogWriterBase> logWriters) : base(ctx, httpContextAcc, logWriters) public FruitBankEventConsumer(IHttpContextAccessor httpContextAcc, FruitBankDbContext ctx, MeasurementService measurementService,
FruitBankAttributeService fruitBankAttributeService, IEnumerable<IAcLogWriterBase> logWriters) : base(ctx, httpContextAcc, logWriters)
{ {
_ctx = ctx; _ctx = ctx;
_measurementService = measurementService;
_fruitBankAttributeService = fruitBankAttributeService; _fruitBankAttributeService = fruitBankAttributeService;
_customPriceCalculationService = customPriceCalculationService as CustomPriceCalculationService;
} }
public override async Task HandleEventAsync(EntityUpdatedEvent<Product> eventMessage) public override async Task HandleEventAsync(EntityUpdatedEvent<Product> eventMessage)
@ -257,26 +259,22 @@ public class FruitBankEventConsumer :
await _ctx.ShippingItemPallets.DeleteAsync(sp => sp.ShippingItemId == eventMessage.Entity.Id, false); await _ctx.ShippingItemPallets.DeleteAsync(sp => sp.ShippingItemId == eventMessage.Entity.Id, false);
} }
public async Task HandleEventAsync(EntityUpdatedEvent<OrderItem> eventMessage) public async Task HandleEventAsync(EntityDeletedEvent<OrderItem> eventMessage)
{ {
//await _customPriceCalculationService.CheckAndUpdateOrderItemFinalPricesAsync(eventMessage.Entity); await _measurementService.DeleteOrderItemConstraintsAsync(eventMessage.Entity);
if (await _customPriceCalculationService.CheckAndUpdateOrderItemFinalPricesAsync(eventMessage.Entity))
{
var order = await _ctx.Orders.GetByIdAsync(eventMessage.Entity.OrderId);
await _customPriceCalculationService.CheckAndUpdateOrderTotalPrice(order);
}
} }
public async Task HandleEventAsync(EntityUpdatedEvent<OrderItem> eventMessage)
{
await _measurementService.OrderItemInsertedOrUpdatedPostProcess(eventMessage.Entity);
}
public async Task HandleEventAsync(EntityInsertedEvent<OrderItem> eventMessage) public async Task HandleEventAsync(EntityInsertedEvent<OrderItem> eventMessage)
{ {
//await _customPriceCalculationService.CheckAndUpdateOrderItemFinalPricesAsync(eventMessage.Entity); await _measurementService.OrderItemInsertedOrUpdatedPostProcess(eventMessage.Entity);
if (await _customPriceCalculationService.CheckAndUpdateOrderItemFinalPricesAsync(eventMessage.Entity))
{
var order = await _ctx.Orders.GetByIdAsync(eventMessage.Entity.OrderId);
await _customPriceCalculationService.CheckAndUpdateOrderTotalPrice(order);
}
} }
} }
#endregion Delete #endregion Delete

View File

@ -177,6 +177,7 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Factories
private static void PrepareOrderModelExtended(OrderModelExtended orderModelExtended, OrderDto orderDto) private static void PrepareOrderModelExtended(OrderModelExtended orderModelExtended, OrderDto orderDto)
{ {
orderModelExtended.IsMeasured = orderDto.IsMeasured; orderModelExtended.IsMeasured = orderDto.IsMeasured;
orderModelExtended.MeasuringStatus = orderDto.MeasuringStatus;
orderModelExtended.IsMeasurable = orderDto.IsMeasurable; orderModelExtended.IsMeasurable = orderDto.IsMeasurable;
orderModelExtended.DateOfReceipt = orderDto.DateOfReceipt; orderModelExtended.DateOfReceipt = orderDto.DateOfReceipt;
orderModelExtended.OrderTotal = !orderDto.IsComplete && orderDto.IsMeasurable ? "kalkuláció alatt..." : orderModelExtended.OrderTotal; 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.IsMeasured = orderItemDto.IsMeasured;
orderItemModelExtended.IsMeasurable = orderItemDto.IsMeasurable; orderItemModelExtended.IsMeasurable = orderItemDto.IsMeasurable;
orderItemModelExtended.MeasuringStatus = orderItemDto.MeasuringStatus;
orderItemModelExtended.NetWeight = (decimal)orderItemDto.NetWeight; orderItemModelExtended.NetWeight = (decimal)orderItemDto.NetWeight;
orderItemModelExtended.ProductStockQuantity = orderItemDto.ProductDto!.StockQuantity; orderItemModelExtended.ProductStockQuantity = orderItemDto.ProductDto!.StockQuantity;
orderItemModelExtended.ProductIncomingQuantity = orderItemDto.ProductDto.IncomingQuantity; orderItemModelExtended.ProductIncomingQuantity = orderItemDto.ProductDto.IncomingQuantity;
orderItemModelExtended.ProductAvailableQuantity = orderItemDto.ProductDto.AvailableQuantity; 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 ??= new List<OrderItemModelExtended>();
orderModelExtended.ItemExtendeds.Add(orderItemModelExtended); orderModelExtended.ItemExtendeds.Add(orderItemModelExtended);

View File

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

View File

@ -3,16 +3,18 @@ using Nop.Plugin.Misc.FruitBankPlugin.Models.MgBase.OrderModels;
namespace Nop.Plugin.Misc.FruitBankPlugin.Models.Orders; 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; } decimal NetWeight { get; set; }
int ProductStockQuantity { get; set; } int ProductStockQuantity { get; set; }
int ProductIncomingQuantity { get; set; } int ProductIncomingQuantity { get; set; }
int ProductAvailableQuantity { 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; } DateTime? DateOfReceipt { get; set; }
string CustomerCompany { 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; using Nop.Web.Areas.Admin.Models.Orders;
namespace Nop.Plugin.Misc.FruitBankPlugin.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 IsMeasured { get; set; }
public bool IsMeasurable { get; set; } public bool IsMeasurable { get; set; }
public MeasuringStatus MeasuringStatus { get; set; }
public string MeasuringStatusString => MeasuringStatus.ToString();
public decimal NetWeight { get; set; } public decimal NetWeight { get; set; }
public int ProductStockQuantity { get; set; } public int ProductStockQuantity { get; set; }
public int ProductIncomingQuantity { 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 IsMeasured { get; set; }
public bool IsMeasurable { get; set; } public bool IsMeasurable { get; set; }
public MeasuringStatus MeasuringStatus { get; set; }
public string MeasuringStatusString => MeasuringStatus.ToString();
public DateTime? DateOfReceipt { get; set; } public DateTime? DateOfReceipt { get; set; }
public string CustomerCompany { get; set; } public string CustomerCompany { get; set; }

View File

@ -71,10 +71,10 @@ public class CustomPriceCalculationService : PriceCalculationService
return (finalPriceInclTax, finalPriceExclTax); return (finalPriceInclTax, finalPriceExclTax);
} }
public async Task<bool> CheckAndUpdateOrderItemFinalPricesAsync(OrderItem orderItem) public async Task<bool> CheckAndUpdateOrderItemFinalPricesAsync(OrderItem orderItem, OrderItemDto? orderItemDtoHelper = null)
{ {
var orderItemDto = await _dbContext.OrderItemDtos.GetByIdAsync(orderItem.Id, true); orderItemDtoHelper ??= await _dbContext.OrderItemDtos.GetByIdAsync(orderItem.Id, true);
return await CheckAndUpdateOrderItemFinalPricesAsync(orderItem, orderItemDto.IsMeasurable, orderItemDto.NetWeight); return await CheckAndUpdateOrderItemFinalPricesAsync(orderItem, orderItemDtoHelper.IsMeasurable, orderItemDtoHelper.NetWeight);
} }
//public async Task<bool> CheckAndUpdateOrderItemFinalPricesAsync(OrderItemDto orderItemDto) //public async Task<bool> CheckAndUpdateOrderItemFinalPricesAsync(OrderItemDto orderItemDto)

View File

@ -166,6 +166,12 @@ public class FruitBankAttributeService(IGenericAttributeService genericAttribute
var ga = await GetGenericAttributeAsync<TEntity>(entityId, key, storeId); var ga = await GetGenericAttributeAsync<TEntity>(entityId, key, storeId);
if (ga == null) return; 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<GenericAttribute> genericAttributes)
=> await genericAttributeService.DeleteAttributesAsync(genericAttributes);
} }

View File

@ -1,4 +1,4 @@
using Mango.Nop.Services; using Mango.Nop.Core.Services;
namespace Nop.Plugin.Misc.FruitBankPlugin.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,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<Logger>, IMeasurementService
{
private readonly FruitBankDbContext _dbContext;
private readonly SignalRSendToClientService _signalRSendToClientService;
private readonly CustomPriceCalculationService _customPriceCalculationService;
public MeasurementService(FruitBankDbContext dbContext, SignalRSendToClientService signalRSendToClientService, FruitBankAttributeService fruitBankAttributeService,
IPriceCalculationService customPriceCalculationService, IEnumerable<IAcLogWriterBase> logWriters) : base(new Logger<MeasurementService>(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);
}
}
}