|
|
@@ -9,6 +9,8 @@ import java.io.IOException |
|
|
import java.math.BigDecimal |
|
|
import java.math.BigDecimal |
|
|
import java.math.RoundingMode |
|
|
import java.math.RoundingMode |
|
|
import kotlin.jvm.optionals.getOrNull |
|
|
import kotlin.jvm.optionals.getOrNull |
|
|
|
|
|
import org.slf4j.Logger |
|
|
|
|
|
import org.slf4j.LoggerFactory |
|
|
|
|
|
|
|
|
@Service |
|
|
@Service |
|
|
open class ItemUomService( |
|
|
open class ItemUomService( |
|
|
@@ -17,6 +19,8 @@ open class ItemUomService( |
|
|
val itemUomRespository: ItemUomRespository, |
|
|
val itemUomRespository: ItemUomRespository, |
|
|
val currencyService: CurrencyService |
|
|
val currencyService: CurrencyService |
|
|
) { |
|
|
) { |
|
|
|
|
|
val logger = org.slf4j.LoggerFactory.getLogger(this::class.java) |
|
|
|
|
|
|
|
|
open fun findAllByItemsId(itemId: Long): List<ItemUom> { |
|
|
open fun findAllByItemsId(itemId: Long): List<ItemUom> { |
|
|
return itemUomRespository.findAllByItemIdAndDeletedIsFalse(itemId); |
|
|
return itemUomRespository.findAllByItemIdAndDeletedIsFalse(itemId); |
|
|
} |
|
|
} |
|
|
@@ -44,6 +48,10 @@ open class ItemUomService( |
|
|
return itemUomRespository.findFirstByItemIdAndUomIdAndDeletedIsFalse(itemId, uomId) |
|
|
return itemUomRespository.findFirstByItemIdAndUomIdAndDeletedIsFalse(itemId, uomId) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
open fun findByItemIdAndUomIdAndStockUnit(itemId: Long, uomId: Long, stockUnit: Boolean): ItemUom? { |
|
|
|
|
|
return itemUomRespository.findByItemIdAndUomIdAndStockUnitAndDeletedIsFalse(itemId, uomId, stockUnit) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
open fun findPurchaseUnitByM18ItemId(m18ItemId: Long): ItemUom? { |
|
|
open fun findPurchaseUnitByM18ItemId(m18ItemId: Long): ItemUom? { |
|
|
return itemUomRespository.findByItemM18IdAndPurchaseUnitIsTrueAndDeletedIsFalse(m18ItemId) |
|
|
return itemUomRespository.findByItemM18IdAndPurchaseUnitIsTrueAndDeletedIsFalse(m18ItemId) |
|
|
} |
|
|
} |
|
|
@@ -79,7 +87,7 @@ open class ItemUomService( |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
open fun convertQtyToStockQty(itemId: Long, uomId: Long, sourceQty: BigDecimal): BigDecimal { |
|
|
open fun convertQtyToStockQty(itemId: Long, uomId: Long, sourceQty: BigDecimal): BigDecimal { |
|
|
val itemUom = findFirstByItemIdAndUomId(itemId, uomId) |
|
|
|
|
|
|
|
|
val itemUom = findFirstByItemIdAndUomId(itemId, uomId) ?: return sourceQty; |
|
|
|
|
|
|
|
|
val stockUnit = findStockUnitByItemId(itemId) ?: return BigDecimal.ZERO; |
|
|
val stockUnit = findStockUnitByItemId(itemId) ?: return BigDecimal.ZERO; |
|
|
val one = BigDecimal.ONE; |
|
|
val one = BigDecimal.ONE; |
|
|
@@ -93,9 +101,11 @@ open class ItemUomService( |
|
|
// See if need to update the response |
|
|
// See if need to update the response |
|
|
open fun saveItemUom(request: ItemUomRequest): ItemUom { |
|
|
open fun saveItemUom(request: ItemUomRequest): ItemUom { |
|
|
val itemUom = request.m18Id?.let { findByM18Id(it) } ?: request.id?.let { findById(it) } ?: ItemUom() |
|
|
val itemUom = request.m18Id?.let { findByM18Id(it) } ?: request.id?.let { findById(it) } ?: ItemUom() |
|
|
if (request.m18LastModifyDate == itemUom.m18LastModifyDate) { |
|
|
|
|
|
return itemUom |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//if (request.m18LastModifyDate == itemUom.m18LastModifyDate) { |
|
|
|
|
|
// logger.info("Skipping update - m18LastModifyDate unchanged") |
|
|
|
|
|
// return itemUom |
|
|
|
|
|
//} |
|
|
|
|
|
|
|
|
val item = request.itemId?.let { itemsService.find(it).getOrNull() } |
|
|
val item = request.itemId?.let { itemsService.find(it).getOrNull() } |
|
|
val uom = request.m18UomId?.let { uomConversionService.findByM18Id(it) } ?: request.uomId?.let { uomConversionService.find(it).getOrNull() } |
|
|
val uom = request.m18UomId?.let { uomConversionService.findByM18Id(it) } ?: request.uomId?.let { uomConversionService.find(it).getOrNull() } |
|
|
@@ -115,7 +125,7 @@ open class ItemUomService( |
|
|
m18LastModifyDate = request.m18LastModifyDate |
|
|
m18LastModifyDate = request.m18LastModifyDate |
|
|
ratioD = request.ratioD |
|
|
ratioD = request.ratioD |
|
|
ratioN = request.ratioN |
|
|
ratioN = request.ratioN |
|
|
deleted = request.deleted |
|
|
|
|
|
|
|
|
deleted = request.deleted // ← EXPLICIT assignment (same as before) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
val savedItemUom = itemUomRespository.saveAndFlush(itemUom) |
|
|
val savedItemUom = itemUomRespository.saveAndFlush(itemUom) |
|
|
|