kelvin.yau 13 hours ago
parent
commit
3e8a8b2adc
1 changed files with 18 additions and 2 deletions
  1. +18
    -2
      src/main/java/com/ffii/fpsms/modules/master/service/ItemUomService.kt

+ 18
- 2
src/main/java/com/ffii/fpsms/modules/master/service/ItemUomService.kt View File

@@ -224,6 +224,22 @@ open class ItemUomService(
return stockQty.setScale(0, RoundingMode.DOWN) return stockQty.setScale(0, RoundingMode.DOWN)
} }


/**
* Stock UOM code [PCS/CTN]* denotes pieces-per-carton; displayed stock qty should be whole cartons (integer).
*/
private fun isPiecesPerCartonStockUomCode(stockUnit: ItemUom?): Boolean {
val code = stockUnit?.uom?.code?.trim() ?: return false
return code.startsWith("PCS/CTN", ignoreCase = true)
}

/** After ratio math: 2 decimals, or integer when stock unit is PCS/CTN… */
private fun finalizePreciseStockQty(stockUnit: ItemUom?, stockQty: BigDecimal): BigDecimal {
if (isPiecesPerCartonStockUomCode(stockUnit)) {
return stockQty.setScale(0, RoundingMode.HALF_UP)
}
return stockQty.setScale(2, RoundingMode.HALF_UP)
}

/** /**
* Convert purchase qty -> stock qty and keep decimal precision. * Convert purchase qty -> stock qty and keep decimal precision.
* Used for PO flows where decimal quantity must be preserved. * Used for PO flows where decimal quantity must be preserved.
@@ -242,7 +258,7 @@ open class ItemUomService(
.multiply(stockUnit.ratioD ?: one) .multiply(stockUnit.ratioD ?: one)
.divide(stockUnit.ratioN ?: one, calcScale, RoundingMode.HALF_UP) .divide(stockUnit.ratioN ?: one, calcScale, RoundingMode.HALF_UP)


return stockQty.setScale(2, RoundingMode.HALF_UP)
return finalizePreciseStockQty(stockUnit, stockQty)
} }


/** /**
@@ -263,7 +279,7 @@ open class ItemUomService(
.multiply(stockUnit.ratioD ?: one) .multiply(stockUnit.ratioD ?: one)
.divide(stockUnit.ratioN ?: one, calcScale, RoundingMode.HALF_UP) .divide(stockUnit.ratioN ?: one, calcScale, RoundingMode.HALF_UP)


return stockQty.setScale(2, RoundingMode.HALF_UP)
return finalizePreciseStockQty(stockUnit, stockQty)
} }


// See if need to update the response // See if need to update the response


Loading…
Cancel
Save