Merge branch '4.80' of https://git.aycode.com/Adam/Mango.Nop.Plugins into 4.80
This commit is contained in:
commit
ad683a587e
|
|
@ -30,6 +30,7 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Controllers
|
||||||
public class FruitBankDataController(
|
public class FruitBankDataController(
|
||||||
FruitBankDbContext ctx,
|
FruitBankDbContext ctx,
|
||||||
MeasurementService measurementService,
|
MeasurementService measurementService,
|
||||||
|
StockQuantityHistoryDtoDbTable stockQuantityHistoryDtoDbTable,
|
||||||
IWorkContext workContext,
|
IWorkContext workContext,
|
||||||
ICustomerService customerService,
|
ICustomerService customerService,
|
||||||
ICustomerRegistrationService customerRegistrationService,
|
ICustomerRegistrationService customerRegistrationService,
|
||||||
|
|
@ -51,6 +52,14 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Controllers
|
||||||
throw new NotImplementedException("GetMeasuringModels");
|
throw new NotImplementedException("GetMeasuringModels");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[SignalR(SignalRTags.GetStockQuantityHistoryDtos)]
|
||||||
|
public async Task<List<StockQuantityHistoryDto>> GetStockQuantityHistoryDtos()
|
||||||
|
=> await stockQuantityHistoryDtoDbTable.GetAll(true).ToListAsync();
|
||||||
|
|
||||||
|
[SignalR(SignalRTags.GetStockQuantityHistoryDtosByProductId)]
|
||||||
|
public async Task<List<StockQuantityHistoryDto>> GetStockQuantityHistoryDtosByProductId(int productId)
|
||||||
|
=> await stockQuantityHistoryDtoDbTable.GetByProductIdAsync(productId, true).ToListAsync();
|
||||||
|
|
||||||
[SignalR(SignalRTags.GetPartners)]
|
[SignalR(SignalRTags.GetPartners)]
|
||||||
public async Task<List<Partner>> GetPartners()
|
public async Task<List<Partner>> GetPartners()
|
||||||
{
|
{
|
||||||
|
|
@ -313,26 +322,26 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Controllers
|
||||||
switch (loginResult)
|
switch (loginResult)
|
||||||
{
|
{
|
||||||
case CustomerLoginResults.Successful:
|
case CustomerLoginResults.Successful:
|
||||||
{
|
|
||||||
var customer = await customerService.GetCustomerByEmailAsync(customerEmail);
|
|
||||||
|
|
||||||
var isInMeasuringRole = await customerService.IsInCustomerRoleAsync(customer, FruitBankConst.MeasuringRoleSystemName);
|
|
||||||
if (!isInMeasuringRole)
|
|
||||||
{
|
{
|
||||||
resultLoginModel.ErrorMessage = "Is not in MeauringRole!";
|
var customer = await customerService.GetCustomerByEmailAsync(customerEmail);
|
||||||
|
|
||||||
|
var isInMeasuringRole = await customerService.IsInCustomerRoleAsync(customer, FruitBankConst.MeasuringRoleSystemName);
|
||||||
|
if (!isInMeasuringRole)
|
||||||
|
{
|
||||||
|
resultLoginModel.ErrorMessage = "Is not in MeauringRole!";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
//var actionResult = await customerRegistrationService.SignInCustomerAsync(customer, returnUrl, loginModel.RememberMe);
|
||||||
|
|
||||||
|
//await _workContext.SetCurrentCustomerAsync(customer);
|
||||||
|
//await _authenticationService.SignInAsync(customer, isPersist);
|
||||||
|
////raise event
|
||||||
|
//await _eventPublisher.PublishAsync(new CustomerLoggedinEvent(customer));
|
||||||
|
|
||||||
|
resultLoginModel.CustomerDto = new CustomerDto(customer); //customer.ToModel<CustomerDto>();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
//var actionResult = await customerRegistrationService.SignInCustomerAsync(customer, returnUrl, loginModel.RememberMe);
|
|
||||||
|
|
||||||
//await _workContext.SetCurrentCustomerAsync(customer);
|
|
||||||
//await _authenticationService.SignInAsync(customer, isPersist);
|
|
||||||
////raise event
|
|
||||||
//await _eventPublisher.PublishAsync(new CustomerLoggedinEvent(customer));
|
|
||||||
|
|
||||||
resultLoginModel.CustomerDto = new CustomerDto(customer); //customer.ToModel<CustomerDto>();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case CustomerLoginResults.CustomerNotExist:
|
case CustomerLoginResults.CustomerNotExist:
|
||||||
resultLoginModel.ErrorMessage = await localizationService.GetResourceAsync("Account.Login.WrongCredentials.CustomerNotExist");
|
resultLoginModel.ErrorMessage = await localizationService.GetResourceAsync("Account.Login.WrongCredentials.CustomerNotExist");
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -6,15 +6,18 @@ using FruitBank.Common.Dtos;
|
||||||
using FruitBank.Common.Entities;
|
using FruitBank.Common.Entities;
|
||||||
using FruitBank.Common.Interfaces;
|
using FruitBank.Common.Interfaces;
|
||||||
using FruitBank.Common.Models;
|
using FruitBank.Common.Models;
|
||||||
|
using Mango.Nop.Core.Entities;
|
||||||
using Mango.Nop.Core.Extensions;
|
using Mango.Nop.Core.Extensions;
|
||||||
using Mango.Nop.Core.Loggers;
|
using Mango.Nop.Core.Loggers;
|
||||||
using Mango.Nop.Data.Repositories;
|
using Mango.Nop.Data.Repositories;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
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.Common;
|
||||||
using Nop.Core.Domain.Customers;
|
using Nop.Core.Domain.Customers;
|
||||||
using Nop.Core.Domain.Orders;
|
using Nop.Core.Domain.Orders;
|
||||||
|
using Nop.Core.Domain.Shipping;
|
||||||
using Nop.Core.Events;
|
using Nop.Core.Events;
|
||||||
using Nop.Data;
|
using Nop.Data;
|
||||||
using Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer.Interfaces;
|
using Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer.Interfaces;
|
||||||
|
|
@ -65,6 +68,8 @@ public class FruitBankDbContext : MgDbContextBase,
|
||||||
public IRepository<CustomerAddressMapping> CustomerAddressMappings { get; set; }
|
public IRepository<CustomerAddressMapping> CustomerAddressMappings { get; set; }
|
||||||
|
|
||||||
public IRepository<GenericAttribute> GenericAttributes { get; set; }
|
public IRepository<GenericAttribute> GenericAttributes { get; set; }
|
||||||
|
public IRepository<StockQuantityHistory> StockQuantityHistories { get; set; }
|
||||||
|
public IRepository<StockQuantityHistoryExt> StockQuantityHistoriesExt { 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,
|
||||||
|
|
@ -79,6 +84,8 @@ public class FruitBankDbContext : MgDbContextBase,
|
||||||
IRepository<CustomerAddressMapping> customerAddressMappingRepository,
|
IRepository<CustomerAddressMapping> customerAddressMappingRepository,
|
||||||
IRepository<CustomerRole> customerRoleRepository,
|
IRepository<CustomerRole> customerRoleRepository,
|
||||||
IRepository<GenericAttribute> genericAttributes,
|
IRepository<GenericAttribute> genericAttributes,
|
||||||
|
IRepository<StockQuantityHistory> stockQuantityHistories,
|
||||||
|
IRepository<StockQuantityHistoryExt> stockQuantityHistoriesExt,
|
||||||
IEventPublisher eventPublisher,
|
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()))
|
||||||
{
|
{
|
||||||
|
|
@ -110,6 +117,9 @@ public class FruitBankDbContext : MgDbContextBase,
|
||||||
CustomerAddressMappings = customerAddressMappingRepository;
|
CustomerAddressMappings = customerAddressMappingRepository;
|
||||||
|
|
||||||
GenericAttributes = genericAttributes;
|
GenericAttributes = genericAttributes;
|
||||||
|
|
||||||
|
StockQuantityHistories = stockQuantityHistories;
|
||||||
|
StockQuantityHistoriesExt = stockQuantityHistoriesExt;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IQueryable<Customer> GetCustomersBySystemRoleName(string systemRoleName)
|
public IQueryable<Customer> GetCustomersBySystemRoleName(string systemRoleName)
|
||||||
|
|
@ -282,38 +292,42 @@ public class FruitBankDbContext : MgDbContextBase,
|
||||||
if (shippingItem.IsMeasured)
|
if (shippingItem.IsMeasured)
|
||||||
{
|
{
|
||||||
var quantityInc = productIdChanged ? shippingItem.MeasuredQuantity : shippingItem.MeasuredQuantity - dbShippingItem.MeasuredQuantity;
|
var quantityInc = productIdChanged ? shippingItem.MeasuredQuantity : shippingItem.MeasuredQuantity - dbShippingItem.MeasuredQuantity;
|
||||||
productDto!.StockQuantity += quantityInc;
|
|
||||||
|
|
||||||
if (!await UpdateProductDtoStockQuantityAsync(productDto, true))
|
//productDto!.StockQuantity += quantityInc;
|
||||||
throw new Exception($"UpdateProductStockQuantity() == false; shippingItem! product.Id: {productDto.Id}");
|
//if (!await UpdateProductDtoStockQuantityAsync(productDto, true))
|
||||||
|
// throw new Exception($"UpdateProductStockQuantity() == false; shippingItem! product.Id: {productDto.Id}");
|
||||||
|
|
||||||
var incomingQuantity = productDto.GenericAttributes.GetValueOrNull<int>(nameof(IIncomingQuantity.IncomingQuantity));
|
var incomingQuantity = productDto!.GenericAttributes.GetValueOrNull<int>(nameof(IIncomingQuantity.IncomingQuantity));
|
||||||
if (incomingQuantity != null)
|
if (incomingQuantity != null)
|
||||||
{
|
{
|
||||||
await _fruitBankAttributeService.UpdateGenericAttributeAsync<Product, int>
|
await _fruitBankAttributeService.UpdateGenericAttributeAsync<Product, int>
|
||||||
(productDto.Id, nameof(IIncomingQuantity.IncomingQuantity), incomingQuantity.Value - quantityInc);
|
(productDto.Id, nameof(IIncomingQuantity.IncomingQuantity), incomingQuantity.Value - quantityInc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var weightToChange = 0d;
|
||||||
if (productIsMeasurable)
|
if (productIsMeasurable)
|
||||||
{
|
{
|
||||||
await _fruitBankAttributeService.InsertOrUpdateMeasuringAttributeValuesAsync<Product>(productDto.Id,
|
weightToChange = productIdChanged ? shippingItem.MeasuredNetWeight : shippingItem.MeasuredNetWeight - dbShippingItem.MeasuredNetWeight;
|
||||||
productIdChanged ? shippingItem.MeasuredNetWeight : shippingItem.MeasuredNetWeight - dbShippingItem.MeasuredNetWeight,
|
|
||||||
shippingItem.IsMeasurable, true);
|
//await _fruitBankAttributeService.InsertOrUpdateMeasuringAttributeValuesAsync<Product>(productDto.Id, weightToChange, shippingItem.IsMeasurable, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await UpdateStockQuantityAndWeightAsync(productDto, quantityInc, $"Bejövő mérés, shippingItem: #{shippingItem.Id}", weightToChange);
|
||||||
|
//productDto!.StockQuantity += quantityInc;
|
||||||
}
|
}
|
||||||
|
|
||||||
//if (productIdUnchanged || !dbShippingItem.IsMeasured) return true;
|
//if (productIdUnchanged || !dbShippingItem.IsMeasured) return true;
|
||||||
if (!dbShippingItem.ProductId.HasValue || (!productIdChanged && (shippingItem.IsMeasured || !dbShippingItem.IsMeasured))) return true;
|
if (!dbShippingItem.ProductId.HasValue || (!productIdChanged && (shippingItem.IsMeasured || !dbShippingItem.IsMeasured))) return true;
|
||||||
|
|
||||||
productDto = await ProductDtos.GetByIdAsync(dbShippingItem.ProductId!.Value, true);
|
productDto = await ProductDtos.GetByIdAsync(dbShippingItem.ProductId!.Value, true);
|
||||||
|
|
||||||
if (productDto != null)
|
if (productDto != null)
|
||||||
{
|
{
|
||||||
productIsMeasurable = productDto.IsMeasurable;
|
productIsMeasurable = productDto.IsMeasurable;
|
||||||
productDto.StockQuantity -= dbShippingItem.MeasuredQuantity;
|
|
||||||
|
|
||||||
if (!await UpdateProductDtoStockQuantityAsync(productDto, true))
|
//productDto.StockQuantity -= dbShippingItem.MeasuredQuantity;
|
||||||
throw new Exception($"UpdateProductStockQuantity() == false; dbShippingItem! product.Id: {productDto.Id}");
|
//if (!await UpdateProductDtoStockQuantityAsync(productDto, true))
|
||||||
|
// throw new Exception($"UpdateProductStockQuantity() == false; dbShippingItem! product.Id: {productDto.Id}");
|
||||||
|
|
||||||
var incomingQuantity = productDto.GenericAttributes.GetValueOrNull<int>(nameof(IIncomingQuantity.IncomingQuantity));
|
var incomingQuantity = productDto.GenericAttributes.GetValueOrNull<int>(nameof(IIncomingQuantity.IncomingQuantity));
|
||||||
if (incomingQuantity != null)
|
if (incomingQuantity != null)
|
||||||
|
|
@ -322,10 +336,17 @@ public class FruitBankDbContext : MgDbContextBase,
|
||||||
(productDto.Id, nameof(IIncomingQuantity.IncomingQuantity), incomingQuantity.Value + dbShippingItem.MeasuredQuantity);
|
(productDto.Id, nameof(IIncomingQuantity.IncomingQuantity), incomingQuantity.Value + dbShippingItem.MeasuredQuantity);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!productIsMeasurable) return true;
|
//if (productIsMeasurable)
|
||||||
|
//{
|
||||||
|
// var measuringValues = new MeasuringAttributeValues(productDto.Id, -dbShippingItem.MeasuredNetWeight, dbShippingItem.IsMeasurable);
|
||||||
|
// await _fruitBankAttributeService.InsertOrUpdateMeasuringAttributeValuesAsync<Product>(measuringValues, true);
|
||||||
|
//}
|
||||||
|
|
||||||
var measuringValues = new MeasuringAttributeValues(productDto.Id, -dbShippingItem.MeasuredNetWeight, dbShippingItem.IsMeasurable);
|
await UpdateStockQuantityAndWeightAsync(productDto, -dbShippingItem.MeasuredQuantity,
|
||||||
await _fruitBankAttributeService.InsertOrUpdateMeasuringAttributeValuesAsync<Product>(measuringValues, true);
|
$"Bejövő mérés, ShippingItem.Id: #{shippingItem.Id}. Product.Id megváltozott, #{productDto.Id}->#{shippingItem.ProductId}!",
|
||||||
|
-dbShippingItem.MeasuredNetWeight);
|
||||||
|
|
||||||
|
//productDto!.StockQuantity -= dbShippingItem.MeasuredQuantity;
|
||||||
}
|
}
|
||||||
else Logger.Warning($"product == null; dbShippingItem.ProductId: {dbShippingItem.ProductId}");
|
else Logger.Warning($"product == null; dbShippingItem.ProductId: {dbShippingItem.ProductId}");
|
||||||
//else //TODO: productIdUnchanged-et lekezelni! - J.
|
//else //TODO: productIdUnchanged-et lekezelni! - J.
|
||||||
|
|
@ -466,7 +487,7 @@ public class FruitBankDbContext : MgDbContextBase,
|
||||||
orderDto.OrderStatus = OrderStatus.Complete;
|
orderDto.OrderStatus = OrderStatus.Complete;
|
||||||
|
|
||||||
await OrderDtos.UpdateAsync(orderDto);
|
await OrderDtos.UpdateAsync(orderDto);
|
||||||
|
|
||||||
await _fruitBankAttributeService.InsertOrUpdateGenericAttributeAsync<Order, int>(orderDto.Id, nameof(IOrderDto.RevisorId), revisorId);
|
await _fruitBankAttributeService.InsertOrUpdateGenericAttributeAsync<Order, int>(orderDto.Id, nameof(IOrderDto.RevisorId), revisorId);
|
||||||
|
|
||||||
foreach (var orderItemDto in orderDto.OrderItemDtos)
|
foreach (var orderItemDto in orderDto.OrderItemDtos)
|
||||||
|
|
@ -481,14 +502,18 @@ public class FruitBankDbContext : MgDbContextBase,
|
||||||
|
|
||||||
if (!orderItemDto.IsMeasurable) continue;
|
if (!orderItemDto.IsMeasurable) continue;
|
||||||
|
|
||||||
var prevNetWeightFromGa = orderItemDto.GenericAttributes.GetValueOrDefault<double>(nameof(IMeasuringNetWeight.NetWeight), 0);
|
var prevOrderItemNetWeightFromGa = orderItemDto.GenericAttributes.GetValueOrDefault<double>(nameof(IMeasuringNetWeight.NetWeight), 0);
|
||||||
//var gaNetWeight = CommonHelper.To<double>(orderItemDto.GenericAttributes.FirstOrDefault(x => x.Key == nameof(IMeasuringNetWeight.NetWeight))?.Value ?? "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>
|
var productWeightToChange = -(orderItemDto.NetWeight - prevOrderItemNetWeightFromGa);
|
||||||
(orderItemDto.ProductId, -(orderItemDto.NetWeight - prevNetWeightFromGa), orderItemDto.IsMeasurable, true);
|
|
||||||
|
//await _fruitBankAttributeService.InsertOrUpdateMeasuringAttributeValuesAsync<Product>(orderItemDto.ProductId, productWeightToChange, orderItemDto.IsMeasurable, true);
|
||||||
|
|
||||||
|
await UpdateStockQuantityAndWeightAsync(orderItemDto.ProductId, 0,
|
||||||
|
$"Kimenő mérés, OrderStatus set to complete. Rendelés: #{orderDto.Id}, rendelés tétel: #{orderItemDto.Id}",
|
||||||
|
productWeightToChange);
|
||||||
}
|
}
|
||||||
|
|
||||||
//await _eventPublisher.PublishAsync(new OrderStatusChangedEvent(order, prevOrderStatus));
|
//await _eventPublisher.PublishAsync(new OrderStatusChangedEvent(order, prevOrderStatus));
|
||||||
|
|
@ -552,7 +577,7 @@ public class FruitBankDbContext : MgDbContextBase,
|
||||||
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;
|
||||||
|
|
||||||
await OrderItemPallets.InsertAsync(orderItemPallet);
|
await OrderItemPallets.InsertAsync(orderItemPallet);
|
||||||
return orderItemPallet;
|
return orderItemPallet;
|
||||||
}
|
}
|
||||||
|
|
@ -571,7 +596,7 @@ public class FruitBankDbContext : MgDbContextBase,
|
||||||
public async Task<OrderItemPallet?> AddOrUpdateOrderItemPalletAsync(OrderItemPallet orderItemPallet)
|
public async Task<OrderItemPallet?> AddOrUpdateOrderItemPalletAsync(OrderItemPallet orderItemPallet)
|
||||||
{
|
{
|
||||||
if (orderItemPallet.Id <= 0) return await AddOrderItemPalletAsync(orderItemPallet);
|
if (orderItemPallet.Id <= 0) return await AddOrderItemPalletAsync(orderItemPallet);
|
||||||
|
|
||||||
return await UpdateOrderItemPalletAsync(orderItemPallet);
|
return await UpdateOrderItemPalletAsync(orderItemPallet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -590,7 +615,7 @@ public class FruitBankDbContext : MgDbContextBase,
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
orderItemDto.OrderItemPallets.UpdateCollection(orderItemPallet, false);
|
orderItemDto.OrderItemPallets.UpdateCollection(orderItemPallet, false);
|
||||||
if (orderItemDto.TrayQuantity > orderItemDto.Quantity) return false;
|
if (orderItemDto.TrayQuantity > orderItemDto.Quantity) return false;
|
||||||
|
|
||||||
|
|
@ -598,29 +623,102 @@ public class FruitBankDbContext : MgDbContextBase,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<bool> UpdateProductDtoStockQuantityAsync(int productDtoId, bool publishEvent)
|
//private async Task<bool> UpdateProductDtoStockQuantityAsync(int productDtoId, bool publishEvent)
|
||||||
{
|
//{
|
||||||
var productDto = await ProductDtos.GetByIdAsync(productDtoId, false);
|
// 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}");
|
||||||
return await Task.FromResult(false);
|
// return await Task.FromResult(false);
|
||||||
|
//}
|
||||||
|
|
||||||
|
//private async Task<bool> UpdateProductDtoStockQuantityAsync(ProductDto productDto, bool publishEvent)
|
||||||
|
//{
|
||||||
|
// //TODO: !!!!!!!!!!!!!!!! - J.
|
||||||
|
// //await _productService.AdjustInventoryAsync(product, quantityInc, string.Empty, "");
|
||||||
|
|
||||||
|
// await ProductDtos.UpdateAsync(productDto, publishEvent);
|
||||||
|
// return await Task.FromResult(true);
|
||||||
|
|
||||||
|
// //var updatedRowsCount = await DataProvider.ExecuteNonQueryAsync($"update product set {nameof(Product.StockQuantity)} = {product.StockQuantity} where {nameof(Product.Id)} = {product.Id}");
|
||||||
|
// //if (updatedRowsCount == 1) return await Task.FromResult(true);
|
||||||
|
|
||||||
|
// //Logger.Error($"Product updatedRowsCount != 1; id: {product.Id}");
|
||||||
|
// //return await Task.FromResult(false);
|
||||||
|
//}
|
||||||
|
|
||||||
|
public async Task UpdateStockQuantityAndWeightAsync(int productId, int quantityToChange, string message, double weightToChange = 0)
|
||||||
|
{
|
||||||
|
if (quantityToChange == 0 && weightToChange == 0) return;
|
||||||
|
|
||||||
|
var product = await Products.GetByIdAsync(productId);
|
||||||
|
await UpdateStockQuantityAndWeightAsync(product, quantityToChange, message, weightToChange);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task UpdateStockQuantityAndWeightAsync(ProductDto productDto, int quantityToChange, string message, double weightToChange = 0)
|
||||||
|
{
|
||||||
|
if (quantityToChange == 0 && weightToChange == 0) return;
|
||||||
|
|
||||||
|
await UpdateStockQuantityAndWeightAsync(productDto.Id, quantityToChange, message, weightToChange);
|
||||||
|
productDto.StockQuantity += quantityToChange;
|
||||||
|
|
||||||
|
if (weightToChange == 0) return;
|
||||||
|
productDto.GenericAttributes = await GenericAttributes.Table.Where(x => x.EntityId == productDto.Id && x.KeyGroup == nameof(Product) && x.StoreId == _storeContext.GetCurrentStore().Id).ToListAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<bool> UpdateProductDtoStockQuantityAsync(ProductDto productDto, bool publishEvent)
|
public async Task UpdateStockQuantityAndWeightAsync(Product product, int quantityToChange, string message, double weightToChange = 0)
|
||||||
{
|
{
|
||||||
//Itt mi legyen? RollBack? - J.
|
weightToChange = double.Round(weightToChange, 1);
|
||||||
if (productDto.StockQuantity < 0)
|
if (quantityToChange == 0 && weightToChange == 0) return;
|
||||||
Logger.Error($"productDto.StockQuantity < 0; Id: {productDto.Id}; StockQuantity: {productDto.StockQuantity}");
|
|
||||||
|
|
||||||
await ProductDtos.UpdateAsync(productDto, publishEvent);
|
var latStockQuantityHistoryId = 0;
|
||||||
return await Task.FromResult(true);
|
|
||||||
|
|
||||||
//var updatedRowsCount = await DataProvider.ExecuteNonQueryAsync($"update product set {nameof(Product.StockQuantity)} = {product.StockQuantity} where {nameof(Product.Id)} = {product.Id}");
|
if (quantityToChange != 0) await _productService.AdjustInventoryAsync(product, quantityToChange, string.Empty, message);
|
||||||
//if (updatedRowsCount == 1) return await Task.FromResult(true);
|
else if (weightToChange != 0)
|
||||||
|
{
|
||||||
|
//Vizsgálja, h a quantityToChange != 0... - J.
|
||||||
|
//await _productService.AddStockQuantityHistoryEntryAsync(product, 0, product.StockQuantity, product.WarehouseId, message);
|
||||||
|
|
||||||
//Logger.Error($"Product updatedRowsCount != 1; id: {product.Id}");
|
var historyEntry = new StockQuantityHistory
|
||||||
//return await Task.FromResult(false);
|
{
|
||||||
|
ProductId = product.Id,
|
||||||
|
CombinationId = null,
|
||||||
|
WarehouseId = product.WarehouseId > 0 ? (int?)product.WarehouseId : null,
|
||||||
|
QuantityAdjustment = 0,
|
||||||
|
StockQuantity = product.StockQuantity,
|
||||||
|
Message = message,
|
||||||
|
CreatedOnUtc = DateTime.UtcNow
|
||||||
|
};
|
||||||
|
|
||||||
|
await StockQuantityHistories.InsertAsync(historyEntry);
|
||||||
|
latStockQuantityHistoryId = historyEntry.Id;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (weightToChange == 0) return;
|
||||||
|
|
||||||
|
await _fruitBankAttributeService.InsertOrUpdateMeasuringAttributeValuesAsync<Product>(product.Id, weightToChange, true, true);
|
||||||
|
|
||||||
|
if (latStockQuantityHistoryId <= 0)
|
||||||
|
{
|
||||||
|
//A LastOrDefaultAsync elszáll! - J.
|
||||||
|
latStockQuantityHistoryId = await StockQuantityHistories.Table.Where(x => x.ProductId == product.Id).MaxAsync(x => x.Id);
|
||||||
|
if (latStockQuantityHistoryId == 0)
|
||||||
|
{
|
||||||
|
Logger.Error($"UpdateProductDtoStockQuantityAndWeightAsync (latStockQuantityHistory == 0). product.Id: {product.Id}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var stockWeight = double.Round(await _fruitBankAttributeService.GetGenericAttributeValueAsync<Product, double>(product.Id, nameof(IMeasuringNetWeight.NetWeight)), 1);
|
||||||
|
|
||||||
|
var stockQuantityHistoryExt = new StockQuantityHistoryExt
|
||||||
|
{
|
||||||
|
StockQuantityHistoryId = latStockQuantityHistoryId,
|
||||||
|
NetWeightAdjustment = weightToChange,
|
||||||
|
NetWeight = stockWeight,
|
||||||
|
};
|
||||||
|
|
||||||
|
await StockQuantityHistoriesExt.InsertAsync(stockQuantityHistoryExt, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<List<ShippingDocument>> GetShippingDocumentsByShippingIdAsync(int shippingId)
|
public async Task<List<ShippingDocument>> GetShippingDocumentsByShippingIdAsync(int shippingId)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,37 @@
|
||||||
|
using FruitBank.Common.Dtos;
|
||||||
|
using FruitBank.Common.Entities;
|
||||||
|
using LinqToDB;
|
||||||
|
using Mango.Nop.Core.Entities;
|
||||||
|
using Mango.Nop.Core.Loggers;
|
||||||
|
using Mango.Nop.Data.Repositories;
|
||||||
|
using Nop.Core.Caching;
|
||||||
|
using Nop.Core.Configuration;
|
||||||
|
using Nop.Core.Domain.Catalog;
|
||||||
|
using Nop.Core.Events;
|
||||||
|
using Nop.Data;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
|
||||||
|
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
|
||||||
|
|
||||||
|
public class StockQuantityHistoryDtoDbTable : MgDtoDbTableBase<StockQuantityHistoryDto, StockQuantityHistory>
|
||||||
|
{
|
||||||
|
public StockQuantityHistoryDtoDbTable(IEventPublisher eventPublisher, INopDataProvider dataProvider, IShortTermCacheManager shortTermCacheManager, IStaticCacheManager staticCacheManager, AppSettings appSettings)
|
||||||
|
: base(eventPublisher, dataProvider, shortTermCacheManager, staticCacheManager, appSettings)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public override IQueryable<StockQuantityHistoryDto> GetAll() => base.GetAll().LoadWith(sqh => sqh.StockQuantityHistoryExt);
|
||||||
|
|
||||||
|
public IQueryable<StockQuantityHistoryDto> GetAll(bool loadProductRelation)
|
||||||
|
{
|
||||||
|
return loadProductRelation
|
||||||
|
? GetAll().LoadWith(sqh => sqh.ProductDto).ThenLoad(p => p.GenericAttributes)
|
||||||
|
: GetAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<StockQuantityHistoryDto> GetByIdAsync(int id, bool loadProductRelation)
|
||||||
|
=> GetAll(loadProductRelation).FirstOrDefaultAsync(p => p.Id == id);
|
||||||
|
|
||||||
|
public IQueryable<StockQuantityHistoryDto> GetByProductIdAsync(int productId, bool loadProductRelation)
|
||||||
|
=> GetAll(loadProductRelation).Where(p => p.ProductId == productId);
|
||||||
|
}
|
||||||
|
|
@ -45,7 +45,7 @@ public class FruitBankEventConsumer :
|
||||||
_measurementService = measurementService;
|
_measurementService = measurementService;
|
||||||
_fruitBankAttributeService = fruitBankAttributeService;
|
_fruitBankAttributeService = fruitBankAttributeService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task HandleEventAsync(EntityUpdatedEvent<Product> eventMessage)
|
public override async Task HandleEventAsync(EntityUpdatedEvent<Product> eventMessage)
|
||||||
{
|
{
|
||||||
var product = await CheckAndUpdateProductManageInventoryMethodToManageStock(eventMessage.Entity);
|
var product = await CheckAndUpdateProductManageInventoryMethodToManageStock(eventMessage.Entity);
|
||||||
|
|
@ -117,7 +117,10 @@ public class FruitBankEventConsumer :
|
||||||
var productDtoNetWeight = productDto?.GenericAttributes.GetValueOrNull<double>(nameof(IMeasuringNetWeight.NetWeight));
|
var productDtoNetWeight = productDto?.GenericAttributes.GetValueOrNull<double>(nameof(IMeasuringNetWeight.NetWeight));
|
||||||
|
|
||||||
if (productDtoNetWeight == null || double.Round(productDtoNetWeight.Value, 1) != netWeight)
|
if (productDtoNetWeight == null || double.Round(productDtoNetWeight.Value, 1) != netWeight)
|
||||||
await _fruitBankAttributeService.InsertOrUpdateGenericAttributeAsync<Product, double>(product.Id, nameof(IMeasuringNetWeight.NetWeight), netWeight);
|
{
|
||||||
|
//await _fruitBankAttributeService.InsertOrUpdateGenericAttributeAsync<Product, double>(product.Id, nameof(IMeasuringNetWeight.NetWeight), netWeight);
|
||||||
|
await _ctx.UpdateStockQuantityAndWeightAsync(productDto, 0, $"Manuális készlet súly változtatás az admin felületen.", netWeight - productDtoNetWeight.GetValueOrDefault(0));
|
||||||
|
}
|
||||||
|
|
||||||
//Tára
|
//Tára
|
||||||
var tare = double.Round(CommonHelper.To<double>(form[nameof(ITare.Tare)].ToString()), 1);
|
var tare = double.Round(CommonHelper.To<double>(form[nameof(ITare.Tare)].ToString()), 1);
|
||||||
|
|
@ -274,7 +277,7 @@ public class FruitBankEventConsumer :
|
||||||
await _measurementService.OrderItemInsertedOrUpdatedPostProcess(eventMessage.Entity);
|
await _measurementService.OrderItemInsertedOrUpdatedPostProcess(eventMessage.Entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion Delete
|
#endregion Delete
|
||||||
|
|
|
||||||
|
|
@ -72,6 +72,8 @@ public class PluginNopStartup : INopStartup
|
||||||
services.AddScoped<FilesDbTable>();
|
services.AddScoped<FilesDbTable>();
|
||||||
services.AddScoped<ShippingDocumentToFilesDbTable>();
|
services.AddScoped<ShippingDocumentToFilesDbTable>();
|
||||||
|
|
||||||
|
services.AddScoped<StockQuantityHistoryDtoDbTable>();
|
||||||
|
|
||||||
services.AddScoped<FruitBankDbContext>();
|
services.AddScoped<FruitBankDbContext>();
|
||||||
|
|
||||||
services.AddScoped<SignalRSendToClientService>();
|
services.AddScoped<SignalRSendToClientService>();
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
using FruitBank.Common;
|
using FruitBank.Common;
|
||||||
using FruitBank.Common.Dtos;
|
using FruitBank.Common.Dtos;
|
||||||
using FruitBank.Common.Entities;
|
using FruitBank.Common.Entities;
|
||||||
|
using Mango.Nop.Core.Dtos;
|
||||||
|
using Mango.Nop.Core.Entities;
|
||||||
using Nop.Core.Domain.Catalog;
|
using Nop.Core.Domain.Catalog;
|
||||||
using Nop.Core.Domain.Orders;
|
using Nop.Core.Domain.Orders;
|
||||||
using Nop.Data.Mapping;
|
using Nop.Data.Mapping;
|
||||||
|
|
@ -29,6 +31,10 @@ public partial class NameCompatibility : INameCompatibility
|
||||||
{ typeof(ShippingItemPallet), FruitBankConstClient.ShippingItemPalletDbTableName},
|
{ typeof(ShippingItemPallet), FruitBankConstClient.ShippingItemPalletDbTableName},
|
||||||
|
|
||||||
{ typeof(ShippingDocumentToFiles), FruitBankConstClient.ShippingDocumentToFilesDbTableName},
|
{ typeof(ShippingDocumentToFiles), FruitBankConstClient.ShippingDocumentToFilesDbTableName},
|
||||||
|
|
||||||
|
{ typeof(StockQuantityHistoryDto), nameof(StockQuantityHistory)},
|
||||||
|
{ typeof(StockQuantityHistoryExt), FruitBankConstClient.StockQuantityHistoryExtDbTableName},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue