- Fixed issue #9

- schema updated.
- decimals fixed in frontend
- weight conversion enhanced.
This commit is contained in:
Jan 2025-09-26 17:19:21 +02:00
parent 13df95d32f
commit 64f36098d9
3 changed files with 22 additions and 14 deletions

View file

@ -135,11 +135,11 @@ export default {
},
dimensionDecimals() {
const unitType = this.huDimensionUnits.find(unit => unit.id === this.huDimensionUnitSelected)?.value;
return (unitType === 'cm') ? 2 : ((unitType === 'm') ? 4 : 0);
return (unitType === 'cm') ? 2 : ((unitType === 'm') ? 3 : 0);
},
weightDecimals() {
const unitType = this.huWeightUnits.find(unit => unit.id === this.huWeightUnitSelected)?.value;
return (unitType === 'kg') ? 4 : ((unitType === 't') ? 8 : 0);
return (unitType === 'kg') ? 3 : ((unitType === 't') ? 6 : 0);
},
huDimensionUnitSelected: {
get() {
@ -151,7 +151,7 @@ export default {
},
set(value) {
const unitType = this.huDimensionUnits.find(unit => unit.id === value)?.value;
const decimals = (unitType === 'cm') ? 2 : ((unitType === 'm') ? 4 : 0);
const decimals = (unitType === 'cm') ? 2 : ((unitType === 'm') ? 3 : 0);
if (this.length) {
const parsedLength = parseFloat(this.length.toFixed(decimals));
@ -180,7 +180,7 @@ export default {
},
set(value) {
const unitType = this.huWeightUnits.find(unit => unit.id === value)?.value;
const decimals = (unitType === 'kg') ? 4 : ((unitType === 't') ? 8 : 0);
const decimals = (unitType === 'kg') ? 4 : ((unitType === 't') ? 6 : 0);
if (this.weight) {
const parsedWeight = parseFloat(this.weight.toFixed(decimals));
@ -205,7 +205,7 @@ export default {
});
},
validateDimension(type, event) {
const decimals = (this.huDimensionUnitSelected === 2) ? 2 : ((this.huDimensionUnitSelected === 3) ? 4 : 0);
const decimals = (this.huDimensionUnitSelected === 2) ? 2 : ((this.huDimensionUnitSelected === 3) ? 3 : 0);
const parsed = parseNumberFromString(event.target.value, decimals);
@ -217,7 +217,7 @@ export default {
this.updateInputValue(inputRef, formattedValue);
},
validateWeight(type, event) {
const decimals = (this.huWeightUnitSelected === 2) ? 4 : ((this.huWeightUnitSelected === 3) ? 8 : 0);
const decimals = (this.huWeightUnitSelected === 2) ? 3 : ((this.huWeightUnitSelected === 3) ? 6 : 0);
const parsed = parseNumberFromString(event.target.value, decimals);
this.$emit('update:weight', parsed);

View file

@ -3,6 +3,9 @@ package de.avatic.lcc.model.utils;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import java.math.BigDecimal;
import java.math.RoundingMode;
/**
* Represents the supported units of weight measurement in the system.
* This enum is utilized to specify the weight unit for various entities
@ -53,28 +56,33 @@ public enum WeightUnit {
/**
* Converts a value from one weight unit to this unit.
*
* @param value the value to convert
* @param value the value to convert
* @param fromUnit the source unit
* @return the converted value
* @throws IllegalArgumentException if value or fromUnit is null
*/
public Double convertFrom(Number value, WeightUnit fromUnit) {
public BigDecimal convertFrom(Number value, WeightUnit fromUnit) {
if (value == null || fromUnit == null) {
throw new IllegalArgumentException("Value and fromUnit must not be null");
}
// Convert to base unit (grams)
double valueInBaseUnit = value.doubleValue() * fromUnit.baseFactor;
BigDecimal valueInBaseUnit = BigDecimal.valueOf(value.doubleValue()).multiply(BigDecimal.valueOf(fromUnit.baseFactor));
// Convert from base unit to target unit
return valueInBaseUnit / this.baseFactor;
return valueInBaseUnit.divide(BigDecimal.valueOf(this.baseFactor), 8, RoundingMode.HALF_UP);
}
public Double convertFromG(Number value) {
return convertFrom(value, G);
var converted = convertFrom(value, G);
return converted.doubleValue();
}
public Integer convertToG(Double weight) {
return Math.toIntExact(Math.round(WeightUnit.G.convertFrom(weight, this)));
var converted = WeightUnit.G.convertFrom(weight, this);
return converted.intValue();
}
}

View file

@ -287,7 +287,7 @@ CREATE TABLE IF NOT EXISTS packaging_dimension
CONSTRAINT `chk_packaging_dimension_displayed_dimension_unit` CHECK (`displayed_dimension_unit` IN
('MM', 'CM', 'M')),
CONSTRAINT `chk_packaging_dimension_displayed_weight_unit` CHECK (`displayed_weight_unit` IN
('G', 'KG'))
('T', 'G', 'KG'))
);
CREATE TABLE IF NOT EXISTS packaging
@ -377,7 +377,7 @@ CREATE TABLE IF NOT EXISTS premise
CONSTRAINT `chk_premise_displayed_dimension_unit` CHECK (`hu_displayed_dimension_unit` IN
('MM', 'CM', 'M')),
CONSTRAINT `chk_premise_displayed_weight_unit` CHECK (`hu_displayed_weight_unit` IN
('G', 'KG')),
('T', 'G', 'KG')),
INDEX idx_material_id (material_id),
INDEX idx_supplier_node_id (supplier_node_id),
INDEX idx_packaging_id (packaging_id),