Compare commits
No commits in common. "66c934e950db3aa2820661b3a58ab6fe0ba763f6" and "631bcdd29092d2da0420b687eb9d006f6b36224d" have entirely different histories.
66c934e950
...
631bcdd290
|
|
@ -147,26 +147,6 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Controllers
|
||||||
return await ctx.ShippingItems.GetByIdAsync(shippingItem.Id, shippingItem.ShippingDocument != null);
|
return await ctx.ShippingItems.GetByIdAsync(shippingItem.Id, shippingItem.ShippingDocument != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
[SignalR(SignalRTags.AddShippingItemPallet)]
|
|
||||||
public async Task<ShippingItemPallet> AddShippingItemPallet(ShippingItemPallet shippingItemPallet)
|
|
||||||
{
|
|
||||||
ArgumentNullException.ThrowIfNull(shippingItemPallet);
|
|
||||||
|
|
||||||
_logger.Detail($"AddShippingItemPallet invoked; {shippingItemPallet}");
|
|
||||||
|
|
||||||
return await ctx.AddShippingItemPalletAsync(shippingItemPallet);
|
|
||||||
}
|
|
||||||
|
|
||||||
[SignalR(SignalRTags.UpdateShippingItemPallet)]
|
|
||||||
public async Task<ShippingItemPallet> UpdateShippingItemPallet(ShippingItemPallet shippingItemPallet)
|
|
||||||
{
|
|
||||||
ArgumentNullException.ThrowIfNull(shippingItemPallet);
|
|
||||||
|
|
||||||
_logger.Detail($"UpdateShippingItemPallet invoked; {shippingItemPallet}");
|
|
||||||
|
|
||||||
return await ctx.UpdateShippingItemPalletAsync(shippingItemPallet);
|
|
||||||
}
|
|
||||||
|
|
||||||
[SignalR(SignalRTags.GetShippingDocuments)]
|
[SignalR(SignalRTags.GetShippingDocuments)]
|
||||||
public async Task<List<ShippingDocument>> GetShippingDocuments()
|
public async Task<List<ShippingDocument>> GetShippingDocuments()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,6 @@ using Nop.Services.Common;
|
||||||
using System.Transactions;
|
using System.Transactions;
|
||||||
using FruitBank.Common.Dtos;
|
using FruitBank.Common.Dtos;
|
||||||
using Mango.Nop.Core.Dtos;
|
using Mango.Nop.Core.Dtos;
|
||||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
|
||||||
|
|
||||||
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
|
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
|
||||||
|
|
||||||
|
|
@ -161,8 +160,7 @@ public class FruitBankDbContext : MgDbContextBase,
|
||||||
|
|
||||||
public Task<bool> UpdateMeasuredShippingItemSafeAsync(ShippingItem shippingItem)
|
public Task<bool> UpdateMeasuredShippingItemSafeAsync(ShippingItem shippingItem)
|
||||||
{
|
{
|
||||||
if (shippingItem.IsValidMeasuringValues() && shippingItem.ShippingItemPallets?.Count == shippingItem.PalletsOnDocument)
|
if (shippingItem.IsValidMeasuringValues()) return UpdateShippingItemSafeAsync(shippingItem);
|
||||||
return UpdateShippingItemSafeAsync(shippingItem);
|
|
||||||
|
|
||||||
Logger.Error("shippingItem.IsMeasurable && !shippingItem.IsValidMeasuringValues()");
|
Logger.Error("shippingItem.IsMeasurable && !shippingItem.IsValidMeasuringValues()");
|
||||||
return Task.FromResult(false);
|
return Task.FromResult(false);
|
||||||
|
|
@ -197,20 +195,15 @@ public class FruitBankDbContext : MgDbContextBase,
|
||||||
|
|
||||||
shippingItem.IsMeasurable = productIsMeasurable;
|
shippingItem.IsMeasurable = productIsMeasurable;
|
||||||
|
|
||||||
if (shippingItem.ShippingItemPallets is { Count: > 0 }) await AddOrUpdateShippingItemPalletAsync(shippingItem);
|
if (shippingItem.MeasuredQuantity < 0) shippingItem.MeasuredQuantity = 0;
|
||||||
|
if (!shippingItem.IsMeasurable || shippingItem.MeasuredNetWeight < 0) shippingItem.MeasuredNetWeight = 0;
|
||||||
//Nem tudhatjuk, h minden Pallet-et tartalmaz-e a shippingItem paraméter! A Biztonság kedvéért lekérjük db-ből! - J.
|
if (!shippingItem.IsMeasurable || shippingItem.MeasuredGrossWeight < 0) shippingItem.MeasuredGrossWeight = 0;
|
||||||
shippingItem.ShippingItemPallets = await ShippingItemPallets.GetAllByShippingItemIdAsync(shippingItem.Id, false).ToListAsync();
|
|
||||||
|
|
||||||
//Update előtt kivesszük a korábbi ShippingItem-et a db-ből! - J.
|
//Update előtt kivesszük a korábbi ShippingItem-et a db-ből! - J.
|
||||||
var dbShippingItem = await ShippingItems.GetByIdAsync(shippingItem.Id, false);
|
var dbShippingItem = await ShippingItems.GetByIdAsync(shippingItem.Id);
|
||||||
if (dbShippingItem == null) throw new Exception($"dbShippingItem == null; shippingItem.Id: {shippingItem.Id}");
|
if (dbShippingItem == null) throw new Exception($"dbShippingItem == null; shippingItem.Id: {shippingItem.Id}");
|
||||||
|
|
||||||
var isMeasuredPrerequisite = product != null && shippingItem.PalletsOnDocument == shippingItem.ShippingItemPallets.Count
|
shippingItem.IsMeasured = product != null && shippingItem.IsValidMeasuringValues();
|
||||||
&& shippingItem.ShippingItemPallets.All(x => x.IsMeasured && x.IsValidMeasuringValues(shippingItem.IsMeasurable));
|
|
||||||
|
|
||||||
SetupShippingItemMeasuringValues(shippingItem, isMeasuredPrerequisite);
|
|
||||||
shippingItem.IsMeasured = isMeasuredPrerequisite && shippingItem.IsValidMeasuringValues();
|
|
||||||
|
|
||||||
await ShippingItems.UpdateAsync(shippingItem, shippingItem.IsMeasured != dbShippingItem.IsMeasured);
|
await ShippingItems.UpdateAsync(shippingItem, shippingItem.IsMeasured != dbShippingItem.IsMeasured);
|
||||||
|
|
||||||
|
|
@ -225,24 +218,23 @@ public class FruitBankDbContext : MgDbContextBase,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
var productIdChanged = shippingItem.ProductId != dbShippingItem.ProductId;
|
var productIdUnchanged = shippingItem.ProductId == dbShippingItem.ProductId;
|
||||||
|
|
||||||
if (shippingItem.IsMeasured)
|
if (shippingItem.IsMeasured)
|
||||||
{
|
{
|
||||||
product!.StockQuantity += productIdChanged ? shippingItem.MeasuredQuantity : shippingItem.MeasuredQuantity - dbShippingItem.MeasuredQuantity;
|
product!.StockQuantity += productIdUnchanged ? shippingItem.MeasuredQuantity - dbShippingItem.MeasuredQuantity : shippingItem.MeasuredQuantity;
|
||||||
|
|
||||||
if (!await UpdateProductStockQuantityAsync(product, true))
|
if (!await UpdateProductStockQuantityAsync(product, true))
|
||||||
throw new Exception($"UpdateProductStockQuantity() == false; shippingItem! product.Id: {product.Id}");
|
throw new Exception($"UpdateProductStockQuantity() == false; shippingItem! product.Id: {product.Id}");
|
||||||
|
|
||||||
if (productIsMeasurable)
|
if (productIsMeasurable)
|
||||||
await _fruitBankAttributeService.InsertOrUpdateMeasuringAttributeValuesAsync<Product>(product.Id,
|
await _fruitBankAttributeService.InsertOrUpdateMeasuringAttributeValuesAsync<Product>(product.Id,
|
||||||
productIdChanged ? shippingItem.MeasuredNetWeight : shippingItem.MeasuredNetWeight - dbShippingItem.MeasuredNetWeight,
|
productIdUnchanged ? shippingItem.MeasuredNetWeight - dbShippingItem.MeasuredNetWeight : shippingItem.MeasuredNetWeight,
|
||||||
productIdChanged ? shippingItem.MeasuredGrossWeight : shippingItem.MeasuredGrossWeight - dbShippingItem.MeasuredGrossWeight,
|
productIdUnchanged ? shippingItem.MeasuredGrossWeight - dbShippingItem.MeasuredGrossWeight : shippingItem.MeasuredGrossWeight,
|
||||||
shippingItem.IsMeasurable, true);
|
shippingItem.IsMeasurable, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
//if (productIdUnchanged || !dbShippingItem.IsMeasured) return true;
|
if (productIdUnchanged || !dbShippingItem.IsMeasured) return true;
|
||||||
if (!productIdChanged && (shippingItem.IsMeasured || !dbShippingItem.IsMeasured)) return true;
|
|
||||||
|
|
||||||
product = await Products.GetByIdAsync(dbShippingItem.ProductId);
|
product = await Products.GetByIdAsync(dbShippingItem.ProductId);
|
||||||
|
|
||||||
|
|
@ -272,82 +264,6 @@ public class FruitBankDbContext : MgDbContextBase,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void SetupShippingItemMeasuringValues(ShippingItem shippingItem, bool shippingItemIsMeasured)
|
|
||||||
{
|
|
||||||
shippingItem.MeasuredQuantity = 0;
|
|
||||||
shippingItem.MeasuredNetWeight = 0;
|
|
||||||
shippingItem.MeasuredGrossWeight = 0;
|
|
||||||
|
|
||||||
if (!shippingItemIsMeasured) return;
|
|
||||||
|
|
||||||
foreach (var shippingItemPallet in shippingItem.ShippingItemPallets!.Where(x => x.IsMeasured && x.IsValidMeasuringValues(shippingItem.IsMeasurable)))
|
|
||||||
{
|
|
||||||
shippingItem.MeasuredQuantity += shippingItemPallet.Quantity;
|
|
||||||
if (!shippingItem.IsMeasurable) continue;
|
|
||||||
|
|
||||||
shippingItem.MeasuredNetWeight += shippingItemPallet.NetWeight;
|
|
||||||
shippingItem.MeasuredGrossWeight += shippingItemPallet.GrossWeight;
|
|
||||||
}
|
|
||||||
|
|
||||||
//if (shippingItem.MeasuredQuantity < 0) shippingItem.MeasuredQuantity = 0;
|
|
||||||
//if (!shippingItem.IsMeasurable || shippingItem.MeasuredNetWeight < 0) shippingItem.MeasuredNetWeight = 0;
|
|
||||||
//if (!shippingItem.IsMeasurable || shippingItem.MeasuredGrossWeight < 0) shippingItem.MeasuredGrossWeight = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<ShippingItemPallet?> AddShippingItemPalletAsync(ShippingItemPallet shippingItemPallet)
|
|
||||||
{
|
|
||||||
if (!await SetupShippingItemPalletMeauringValues(shippingItemPallet)) return null;
|
|
||||||
|
|
||||||
await ShippingItemPallets.InsertAsync(shippingItemPallet);
|
|
||||||
return shippingItemPallet;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<ShippingItemPallet?> UpdateShippingItemPalletAsync(ShippingItemPallet shippingItemPallet)
|
|
||||||
{
|
|
||||||
if (!await SetupShippingItemPalletMeauringValues(shippingItemPallet)) return null;
|
|
||||||
|
|
||||||
await ShippingItemPallets.UpdateAsync(shippingItemPallet);
|
|
||||||
return shippingItemPallet;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task AddOrUpdateShippingItemPalletAsync(List<ShippingItemPallet> shippingItemPallets, ShippingItem parentShippingItem)
|
|
||||||
{
|
|
||||||
foreach (var shippingItemPallet in shippingItemPallets)
|
|
||||||
{
|
|
||||||
shippingItemPallet.ShippingItem = parentShippingItem;
|
|
||||||
|
|
||||||
if (await AddOrUpdateShippingItemPalletAsync(shippingItemPallet) == null)
|
|
||||||
throw new Exception($"AddOrUpdateShippingItemPalletAsync->AddOrUpdateShippingItemPalletAsync() == null");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task AddOrUpdateShippingItemPalletAsync(ShippingItem shippingItem)
|
|
||||||
=> AddOrUpdateShippingItemPalletAsync(shippingItem.ShippingItemPallets!, shippingItem);
|
|
||||||
|
|
||||||
public async Task<ShippingItemPallet?> AddOrUpdateShippingItemPalletAsync(ShippingItemPallet shippingItemPallet)
|
|
||||||
{
|
|
||||||
if (shippingItemPallet.Id <= 0) return await AddShippingItemPalletAsync(shippingItemPallet);
|
|
||||||
|
|
||||||
return await UpdateShippingItemPalletAsync(shippingItemPallet);
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task<bool> SetupShippingItemPalletMeauringValues(ShippingItemPallet shippingItemPallet)
|
|
||||||
{
|
|
||||||
var shippingItem = shippingItemPallet.ShippingItem ?? await ShippingItems.GetByIdAsync(shippingItemPallet.ShippingItemId, false);
|
|
||||||
if (shippingItem == null || shippingItemPallet.ShippingItemId != shippingItem.Id) return false;
|
|
||||||
|
|
||||||
if (!shippingItem.IsMeasurable)
|
|
||||||
{
|
|
||||||
shippingItemPallet.NetWeight = 0;
|
|
||||||
shippingItemPallet.GrossWeight = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (shippingItemPallet.Quantity < 0 || shippingItemPallet.NetWeight < 0 || shippingItemPallet.GrossWeight < 0) return false;
|
|
||||||
|
|
||||||
shippingItemPallet.IsMeasured = shippingItemPallet.IsValidMeasuringValues(shippingItem.IsMeasurable);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task<bool> UpdateProductStockQuantityAsync(int productId, bool publishEvent)
|
private async Task<bool> UpdateProductStockQuantityAsync(int productId, bool publishEvent)
|
||||||
{
|
{
|
||||||
var product = await Products.GetByIdAsync(productId);
|
var product = await Products.GetByIdAsync(productId);
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ public class ShippingItemDbTable : MgDbTableBase<ShippingItem>
|
||||||
.LoadWith(si => si.ShippingDocument).ThenLoad(sd => sd.ShippingDocumentToFiles).ThenLoad(sdtof => sdtof.ShippingDocumentFile)
|
.LoadWith(si => si.ShippingDocument).ThenLoad(sd => sd.ShippingDocumentToFiles).ThenLoad(sdtof => sdtof.ShippingDocumentFile)
|
||||||
.LoadWith(si => si.ShippingItemPallets)
|
.LoadWith(si => si.ShippingItemPallets)
|
||||||
.LoadWith(si => si.Product)
|
.LoadWith(si => si.Product)
|
||||||
: GetAll().LoadWith(si => si.ShippingItemPallets).LoadWith(si => si.Product);
|
: GetAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IQueryable<ShippingItem> GetAllNotMeasured(bool loadRelations)
|
public IQueryable<ShippingItem> GetAllNotMeasured(bool loadRelations)
|
||||||
|
|
|
||||||
|
|
@ -51,13 +51,13 @@ public class FruitBankEventConsumer(IHttpContextAccessor httpContextAccessor, Fr
|
||||||
Logger.Info($"HandleEventAsync EntityUpdatedEvent<ShippingItem>; id: {eventMessage.Entity.Id}");
|
Logger.Info($"HandleEventAsync EntityUpdatedEvent<ShippingItem>; id: {eventMessage.Entity.Id}");
|
||||||
|
|
||||||
var shippingItem = eventMessage.Entity;
|
var shippingItem = eventMessage.Entity;
|
||||||
//var isMeasured = shippingItem.IsValidMeasuringValues();
|
var isMeasured = shippingItem.IsValidMeasuringValues();
|
||||||
|
|
||||||
//if (shippingItem.IsMeasured != isMeasured)
|
if (shippingItem.IsMeasured != isMeasured)
|
||||||
//{
|
{
|
||||||
// shippingItem.IsMeasured = isMeasured;
|
shippingItem.IsMeasured = isMeasured;
|
||||||
// await ctx.ShippingItems.UpdateAsync(shippingItem, false);
|
await ctx.ShippingItems.UpdateAsync(shippingItem, false);
|
||||||
//}
|
}
|
||||||
|
|
||||||
await UpdateShippingDocumentIsAllMeasuredAsync(shippingItem);
|
await UpdateShippingDocumentIsAllMeasuredAsync(shippingItem);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue