Some UI changes
This commit is contained in:
parent
98b1ba9b22
commit
efebc96394
|
|
@ -158,26 +158,31 @@ public class MeasurementService : MeasurementServiceBase<Logger>, IMeasurementSe
|
|||
{
|
||||
double averageWeight = 0;
|
||||
|
||||
|
||||
//TODO if 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,
|
||||
//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
|
||||
|
||||
var allPalletsInThisShippingItem = shippingItemPallet.ShippingItem.ShippingItemPallets;
|
||||
var shippingItemPallets = await _dbContext.ShippingItemPallets.GetAllByShippingItemIdAsync(shippingItemPallet.ShippingItemId, false).ToListAsync();
|
||||
var allOtherPalletsInThisShippingItem = await shippingItemPallets.Where(sp => sp.Id != shippingItemPallet.Id).ToListAsync();
|
||||
|
||||
//we need an object to store the netweight and trayquantity for average calculation
|
||||
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++)
|
||||
for (int i = 0; i < allOtherPalletsInThisShippingItem.Count; i++)
|
||||
{
|
||||
if (allPalletsInThisShippingItem[i].IsValidMeasuringValues(shippingItemPallet.ShippingItem.IsMeasurable))
|
||||
if (allOtherPalletsInThisShippingItem[i].IsValidMeasuringValues(shippingItemPallet.ShippingItem.IsMeasurable))
|
||||
{
|
||||
validPalletsForAverageCalculation.Add((allPalletsInThisShippingItem[i].NetWeight, allPalletsInThisShippingItem[i].TrayQuantity));
|
||||
validPalletsForAverageCalculation.Add((allOtherPalletsInThisShippingItem[i].NetWeight, allOtherPalletsInThisShippingItem[i].TrayQuantity));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//add current pallet to the valid pallets if it has valid measuring values
|
||||
|
||||
|
|
@ -188,8 +193,12 @@ public class MeasurementService : MeasurementServiceBase<Logger>, IMeasurementSe
|
|||
var totalTrayQuantity = validPalletsForAverageCalculation.Sum(x => x.TrayQuantity);
|
||||
|
||||
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 _dbContext.ProductDtos.UpdateAsync(productDto);
|
||||
}
|
||||
|
|
@ -198,6 +207,6 @@ public class MeasurementService : MeasurementServiceBase<Logger>, IMeasurementSe
|
|||
|
||||
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);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue