| @@ -15,6 +15,8 @@ import java.time.LocalDateTime | |||||
| import java.time.LocalDate | import java.time.LocalDate | ||||
| import com.ffii.fpsms.modules.jobOrder.entity.JobOrderRepository | import com.ffii.fpsms.modules.jobOrder.entity.JobOrderRepository | ||||
| import com.ffii.fpsms.modules.productProcess.entity.ProductProcessRepository | import com.ffii.fpsms.modules.productProcess.entity.ProductProcessRepository | ||||
| import com.ffii.fpsms.modules.master.entity.ItemUomRespository | |||||
| import java.math.BigDecimal | |||||
| @Service | @Service | ||||
| open class BagService( | open class BagService( | ||||
| private val bagRepository: BagRepository, | private val bagRepository: BagRepository, | ||||
| @@ -22,20 +24,34 @@ open class BagService( | |||||
| private val joBagConsumptionRepository: JoBagConsumptionRepository, | private val joBagConsumptionRepository: JoBagConsumptionRepository, | ||||
| private val inventoryLotRepository: InventoryLotRepository, | private val inventoryLotRepository: InventoryLotRepository, | ||||
| private val jobOrderRepository: JobOrderRepository, | private val jobOrderRepository: JobOrderRepository, | ||||
| private val productProcessRepository: ProductProcessRepository | |||||
| private val productProcessRepository: ProductProcessRepository, | |||||
| private val itemUomRepository: ItemUomRespository, | |||||
| ) { | ) { | ||||
| open fun createBagLotLinesByBagId(request: CreateBagLotLineRequest): MessageResponse { | open fun createBagLotLinesByBagId(request: CreateBagLotLineRequest): MessageResponse { | ||||
| val bag = bagRepository.findById(request.bagId).orElse(null) | val bag = bagRepository.findById(request.bagId).orElse(null) | ||||
| val lot = inventoryLotRepository.findByLotNoAndItemId(request.lotNo, request.itemId) | val lot = inventoryLotRepository.findByLotNoAndItemId(request.lotNo, request.itemId) | ||||
| val BaseUnitOfMeasure= itemUomRepository.findByItemIdAndStockUnitIsTrueAndDeletedIsFalse(request.itemId) | |||||
| val baseRatioN = BaseUnitOfMeasure?.ratioN ?: BigDecimal.ONE | |||||
| println("baseRatioN: $baseRatioN") | |||||
| val baseRatioD = BaseUnitOfMeasure?.ratioD ?: BigDecimal.ONE | |||||
| println("baseRatioD: $baseRatioD") | |||||
| val bagLotLine = BagLotLine().apply { | val bagLotLine = BagLotLine().apply { | ||||
| this.bagId = bag?.id | this.bagId = bag?.id | ||||
| this.lotId = lot?.id | this.lotId = lot?.id | ||||
| this.lotNo = lot?.lotNo | this.lotNo = lot?.lotNo | ||||
| this.startQty = request.stockQty | |||||
| this.startQty = request.stockQty.toBigDecimal() | |||||
| .multiply(baseRatioN) | |||||
| .divide(baseRatioD) | |||||
| .toInt() | |||||
| println("startQty: $startQty") | |||||
| this.consumedQty = 0 | this.consumedQty = 0 | ||||
| this.stockOutLineId = request.stockOutLineId | this.stockOutLineId = request.stockOutLineId | ||||
| this.scrapQty = 0 | this.scrapQty = 0 | ||||
| this.balanceQty = request.stockQty | |||||
| this.balanceQty = request.stockQty.toBigDecimal() | |||||
| .multiply(baseRatioN) | |||||
| .divide(baseRatioD) | |||||
| .toInt() | |||||
| println("balanceQty: $balanceQty") | |||||
| } | } | ||||
| bagLotLineRepository.save(bagLotLine) | bagLotLineRepository.save(bagLotLine) | ||||
| bag.takenBagBalance = (bag.takenBagBalance ?: 0) + (bagLotLine.balanceQty ?: 0) | bag.takenBagBalance = (bag.takenBagBalance ?: 0) + (bagLotLine.balanceQty ?: 0) | ||||