Some UI changes

This commit is contained in:
Adam 2026-03-02 20:53:50 +01:00
parent 98b1ba9b22
commit efebc96394
1 changed files with 18 additions and 9 deletions

View File

@ -158,27 +158,32 @@ public class MeasurementService : MeasurementServiceBase<Logger>, IMeasurementSe
{ {
double averageWeight = 0; double averageWeight = 0;
//TODO if ismeasurable
if (shippingItemPallet.IsValidMeasuringValues(shippingItemPallet.ShippingItem.IsMeasurable)) if (shippingItemPallet.IsValidMeasuringValues(shippingItemPallet.ShippingItem.IsMeasurable))
{ {
//this is only for the current pallet, the average weight should be calculated from all pallets of the product, //this is only for the current pallet, the average weight should be calculated from all pallets of the product,
//so we check if there are any pallets with valid measuring values and calculate the average weight from them, //so we check if there are any pallets with valid measuring values and calculate the average weight from them,
//otherwise we use the current pallet's weight as the average weight //otherwise we use the current pallet's weight as the average weight
var shippingItemPallets = await _dbContext.ShippingItemPallets.GetAllByShippingItemIdAsync(shippingItemPallet.ShippingItemId, false).ToListAsync();
var allPalletsInThisShippingItem = shippingItemPallet.ShippingItem.ShippingItemPallets; var allOtherPalletsInThisShippingItem = await shippingItemPallets.Where(sp => sp.Id != shippingItemPallet.Id).ToListAsync();
//we need an object to store the netweight and trayquantity for average calculation //we need an object to store the netweight and trayquantity for average calculation
var validPalletsForAverageCalculation = new List<(double NetWeight, int TrayQuantity)>(); var validPalletsForAverageCalculation = new List<(double NetWeight, int TrayQuantity)>();
if(allOtherPalletsInThisShippingItem.Count != 0)
//get all pallets with valid measuring values
for (int i = 0; i < allPalletsInThisShippingItem.Count; i++)
{ {
if (allPalletsInThisShippingItem[i].IsValidMeasuringValues(shippingItemPallet.ShippingItem.IsMeasurable)) //get all pallets with valid measuring values
for (int i = 0; i < allOtherPalletsInThisShippingItem.Count; i++)
{ {
validPalletsForAverageCalculation.Add((allPalletsInThisShippingItem[i].NetWeight, allPalletsInThisShippingItem[i].TrayQuantity)); if (allOtherPalletsInThisShippingItem[i].IsValidMeasuringValues(shippingItemPallet.ShippingItem.IsMeasurable))
{
validPalletsForAverageCalculation.Add((allOtherPalletsInThisShippingItem[i].NetWeight, allOtherPalletsInThisShippingItem[i].TrayQuantity));
}
} }
} }
//add current pallet to the valid pallets if it has valid measuring values //add current pallet to the valid pallets if it has valid measuring values
validPalletsForAverageCalculation.Add(new(shippingItemPallet.NetWeight, shippingItemPallet.TrayQuantity)); validPalletsForAverageCalculation.Add(new(shippingItemPallet.NetWeight, shippingItemPallet.TrayQuantity));
@ -188,8 +193,12 @@ public class MeasurementService : MeasurementServiceBase<Logger>, IMeasurementSe
var totalTrayQuantity = validPalletsForAverageCalculation.Sum(x => x.TrayQuantity); var totalTrayQuantity = validPalletsForAverageCalculation.Sum(x => x.TrayQuantity);
var TotalAverageWeight = totalTrayQuantity > 0 ? totalNetWeight / totalTrayQuantity : 0; var TotalAverageWeight = totalTrayQuantity > 0 ? totalNetWeight / totalTrayQuantity : 0;
averageWeight = TotalAverageWeight;
} }
//TODO ELSE - we have to get the net weight from the document, not from measuring
await SetProductAverageWeight(productDto, averageWeight); await SetProductAverageWeight(productDto, averageWeight);
await _dbContext.ProductDtos.UpdateAsync(productDto); await _dbContext.ProductDtos.UpdateAsync(productDto);
} }
@ -198,6 +207,6 @@ public class MeasurementService : MeasurementServiceBase<Logger>, IMeasurementSe
public async Task SetProductAverageWeight(ProductDto productDto, double averageWeight) public async Task SetProductAverageWeight(ProductDto productDto, double averageWeight)
{ {
await _fruitBankAttributeService.InsertOrUpdateGenericAttributeAsync<ProductDto, double>(productDto.Id, nameof(IProductDto.AverageWeight), averageWeight); await _fruitBankAttributeService.InsertOrUpdateGenericAttributeAsync<Product, double>(productDto.Id, nameof(IProductDto.AverageWeight), averageWeight);
} }
} }