improvements, fixes, etc..

This commit is contained in:
Loretta 2025-11-15 08:14:03 +01:00
parent ad683a587e
commit 6c58cf6ee8
4 changed files with 36 additions and 10 deletions

View File

@ -30,7 +30,6 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Controllers
public class FruitBankDataController(
FruitBankDbContext ctx,
MeasurementService measurementService,
StockQuantityHistoryDtoDbTable stockQuantityHistoryDtoDbTable,
IWorkContext workContext,
ICustomerService customerService,
ICustomerRegistrationService customerRegistrationService,
@ -54,11 +53,11 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Controllers
[SignalR(SignalRTags.GetStockQuantityHistoryDtos)]
public async Task<List<StockQuantityHistoryDto>> GetStockQuantityHistoryDtos()
=> await stockQuantityHistoryDtoDbTable.GetAll(true).ToListAsync();
=> await ctx.StockQuantityHistoryDtos.GetAll(true).ToListAsync();
[SignalR(SignalRTags.GetStockQuantityHistoryDtosByProductId)]
public async Task<List<StockQuantityHistoryDto>> GetStockQuantityHistoryDtosByProductId(int productId)
=> await stockQuantityHistoryDtoDbTable.GetByProductIdAsync(productId, true).ToListAsync();
=> await ctx.StockQuantityHistoryDtos.GetByProductIdAsync(productId, true).ToListAsync();
[SignalR(SignalRTags.GetPartners)]
public async Task<List<Partner>> GetPartners()

View File

@ -61,6 +61,7 @@ public class FruitBankDbContext : MgDbContextBase,
public FilesDbTable Files { get; set; }
public ShippingDocumentToFilesDbTable ShippingDocumentToFiles { get; set; }
public StockQuantityHistoryDtoDbTable StockQuantityHistoryDtos { get; set; }
public IRepository<Customer> Customers { get; set; }
public IRepository<CustomerRole> CustomerRoles { get; set; }
@ -75,6 +76,7 @@ public class FruitBankDbContext : MgDbContextBase,
PartnerDbTable partnerDbTable, ShippingDbTable shippingDbTable, ShippingDocumentDbTable shippingDocumentDbTable, ShippingItemDbTable shippingItemDbTable,
ShippingItemPalletDbTable shippingItemPalletDbTable, FilesDbTable filesDbTable, ShippingDocumentToFilesDbTable shippingDocumentToFilesDbTable,
ProductDtoDbTable productDtoDbTable, OrderDtoDbTable orderDtoDbTable, OrderItemDtoDbTable orderItemDtoDbTable, OrderItemPalletDbTable orderItemPalletDbTable,
StockQuantityHistoryDtoDbTable stockQuantityHistoryDtos,
IProductService productService, IStaticCacheManager staticCacheManager,
IRepository<Order> orderRepository,
IRepository<OrderItem> orderItemRepository,
@ -120,6 +122,7 @@ public class FruitBankDbContext : MgDbContextBase,
StockQuantityHistories = stockQuantityHistories;
StockQuantityHistoriesExt = stockQuantityHistoriesExt;
StockQuantityHistoryDtos = stockQuantityHistoryDtos;
}
public IQueryable<Customer> GetCustomersBySystemRoleName(string systemRoleName)
@ -696,8 +699,9 @@ public class FruitBankDbContext : MgDbContextBase,
if (weightToChange == 0) return;
await _fruitBankAttributeService.InsertOrUpdateMeasuringAttributeValuesAsync<Product>(product.Id, weightToChange, true, true);
var storeId = (await _storeContext.GetCurrentStoreAsync()).Id;
var newStockWeight = await _fruitBankAttributeService.InsertOrUpdateNetWeightAsync<Product>(product.Id, weightToChange, true, storeId);
if (latStockQuantityHistoryId <= 0)
{
//A LastOrDefaultAsync elszáll! - J.
@ -709,13 +713,15 @@ public class FruitBankDbContext : MgDbContextBase,
}
}
var stockWeight = double.Round(await _fruitBankAttributeService.GetGenericAttributeValueAsync<Product, double>(product.Id, nameof(IMeasuringNetWeight.NetWeight)), 1);
//var stockWeight = double.Round(await _fruitBankAttributeService.GetGenericAttributeValueAsync<Product, double>(product.Id, nameof(IMeasuringNetWeight.NetWeight), storeId), 1);
var lastStockQuantityHistoryExtNetWeight = await StockQuantityHistoryDtos.Table.Where(x => x.ProductId == product.Id && x.StockQuantityHistoryExt != null).Select(x => x.StockQuantityHistoryExt!.NetWeight).FirstOrDefaultAsync(netWeight => netWeight != null);
var stockQuantityHistoryExt = new StockQuantityHistoryExt
{
StockQuantityHistoryId = latStockQuantityHistoryId,
NetWeightAdjustment = weightToChange,
NetWeight = stockWeight,
NetWeight = newStockWeight,
IsInconsistent = lastStockQuantityHistoryExtNetWeight != null && double.Round(lastStockQuantityHistoryExtNetWeight.Value + weightToChange, 1) != newStockWeight
};
await StockQuantityHistoriesExt.InsertAsync(stockQuantityHistoryExt, false);

View File

@ -119,7 +119,7 @@ public class FruitBankEventConsumer :
if (productDtoNetWeight == null || double.Round(productDtoNetWeight.Value, 1) != 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));
await _ctx.UpdateStockQuantityAndWeightAsync(product, 0, $"Manuális készlet súly változtatás az admin felületen.", netWeight - productDtoNetWeight.GetValueOrDefault(0));
}
//Tára

View File

@ -99,9 +99,30 @@ public class FruitBankAttributeService(IGenericAttributeService genericAttribute
//await UpdateGenericAttributeAsync(measuringAttributes.Single(ma => ma.Key == IS_MEASURABLE_KEY), measuringAttributeValues.IsMeasurable);
}
private async Task UpdateMeasuringWeightAttributeValueAsync(GenericAttribute genericAttribute, double newWeightValue, bool cumulativeWeightUpdate)
/// <returns>Inserted NetWeight</returns>
private async Task<double> UpdateMeasuringWeightAttributeValueAsync(GenericAttribute genericAttribute, double newWeightValue, bool cumulativeWeightUpdate)
{
await UpdateGenericAttributeAsync(genericAttribute, double.Round((cumulativeWeightUpdate ? CommonHelper.To<double>(genericAttribute.Value) + newWeightValue : newWeightValue), 1));
var newNetWeight = double.Round((cumulativeWeightUpdate ? CommonHelper.To<double>(genericAttribute.Value) + newWeightValue : newWeightValue), 1);
await UpdateGenericAttributeAsync(genericAttribute, newNetWeight);
return newNetWeight;
}
/// <returns>Inserted NetWeight</returns>
public async Task<double> InsertOrUpdateNetWeightAsync<TEntity>(int entityId, double netWeight, bool cumulativeWeightUpdate)
=> await InsertOrUpdateNetWeightAsync<TEntity>(entityId, netWeight, cumulativeWeightUpdate, (await storeContext.GetCurrentStoreAsync()).Id);
/// <returns>Inserted NetWeight</returns>
public async Task<double> InsertOrUpdateNetWeightAsync<TEntity>(int entityId, double netWeight, bool cumulativeWeightUpdate, int storeId)
{
var netWeightGa = await GetGenericAttributeAsync<TEntity>(entityId, NET_WEIGHT_KEY, storeId);
if (netWeightGa != null) return await UpdateMeasuringWeightAttributeValueAsync(netWeightGa, netWeight, cumulativeWeightUpdate);
netWeight = double.Round(netWeight, 1);
await InsertGenericAttributeAsync<TEntity, double>(entityId, NET_WEIGHT_KEY, double.Round(netWeight, 1), storeId);
return netWeight;
}
public async Task DeleteAllMeasuringAttributesAsync<TEntity>(int entityId, int storeId)