diff --git a/src/main/java/com/ffii/fpsms/modules/qc/entity/QcResult.kt b/src/main/java/com/ffii/fpsms/modules/qc/entity/QcResult.kt new file mode 100644 index 0000000..b8ac868 --- /dev/null +++ b/src/main/java/com/ffii/fpsms/modules/qc/entity/QcResult.kt @@ -0,0 +1,40 @@ +package com.ffii.fpsms.modules.qc.entity + +import com.ffii.core.entity.BaseEntity +import com.ffii.fpsms.modules.master.entity.Items +import com.ffii.fpsms.modules.master.entity.QcItem +import com.ffii.fpsms.modules.stock.entity.StockInLine +import com.ffii.fpsms.modules.stock.entity.StockOutLine +import jakarta.persistence.* +import jakarta.validation.constraints.NotNull + +@Entity +@Table(name = "qc_result") +class QcResult: BaseEntity() { + @NotNull + @ManyToOne + @JoinColumn(name = "qcItemId") + open var qcItem: QcItem? = null + + @NotNull + @ManyToOne + @JoinColumn(name = "itemId") + open var item: Items? = null + + @ManyToOne + @JoinColumn(name = "stockInLineId") + open var stockInLine: StockInLine? = null + + @ManyToOne + @JoinColumn(name = "stockOutLineId") + open var stockOutLine: StockOutLine? = null + + @Column(name = "failQty") + open var failQty: Double? = null + + @Column(name = "type") + open var type: String? = null + + @Column(name = "remarks") + open var remarks: String? = null +} \ No newline at end of file diff --git a/src/main/java/com/ffii/fpsms/modules/qc/entity/QcResultRepository.kt b/src/main/java/com/ffii/fpsms/modules/qc/entity/QcResultRepository.kt new file mode 100644 index 0000000..a2b7a6f --- /dev/null +++ b/src/main/java/com/ffii/fpsms/modules/qc/entity/QcResultRepository.kt @@ -0,0 +1,8 @@ +package com.ffii.fpsms.modules.qc.entity + +import com.ffii.core.support.AbstractRepository +import org.springframework.stereotype.Repository + +@Repository +interface QcResultRepository: AbstractRepository { +} \ No newline at end of file diff --git a/src/main/java/com/ffii/fpsms/modules/qc/service/QcResultService.kt b/src/main/java/com/ffii/fpsms/modules/qc/service/QcResultService.kt new file mode 100644 index 0000000..a459a90 --- /dev/null +++ b/src/main/java/com/ffii/fpsms/modules/qc/service/QcResultService.kt @@ -0,0 +1,57 @@ +package com.ffii.fpsms.modules.qc.service + +import com.ffii.core.support.AbstractBaseEntityService +import com.ffii.core.support.JdbcDao +import com.ffii.fpsms.modules.master.entity.ItemsRepository +import com.ffii.fpsms.modules.master.entity.QcItemRepository +import com.ffii.fpsms.modules.master.web.models.MessageResponse +import com.ffii.fpsms.modules.purchaseOrder.entity.PurchaseOrderLineRepository +import com.ffii.fpsms.modules.qc.entity.QcResult +import com.ffii.fpsms.modules.qc.entity.QcResultRepository +import com.ffii.fpsms.modules.qc.web.model.SaveQcResultRequest +import com.ffii.fpsms.modules.stock.entity.StockInLine +import com.ffii.fpsms.modules.stock.entity.StockInLineRepository +import com.ffii.fpsms.modules.stock.entity.StockOutLIneRepository +import org.springframework.stereotype.Service +import org.springframework.transaction.annotation.Transactional +import java.io.IOException + +@Service +open class QcResultService( + private val jdbcDao: JdbcDao, + private val qcResultRepository: QcResultRepository, + private val qcItemRepository: QcItemRepository, + private val itemRepository: ItemsRepository, + private val stockInLineRepository: StockInLineRepository, + private val stockOutLIneRepository: StockOutLIneRepository, +): AbstractBaseEntityService(jdbcDao, qcResultRepository) { + @Throws(IOException::class) + @Transactional + open fun createOrUpdate(request: SaveQcResultRequest): MessageResponse { + val qcResult = if (request.id != null) qcResultRepository.findById(request.id).orElseThrow() else QcResult() + val qcItem = qcItemRepository.findById(request.qcItemId).orElseThrow() + val item = itemRepository.findById(request.itemId).orElseThrow() + val stockInLine = if (request.stockInLineId != null) stockInLineRepository.findById(request.stockInLineId).orElseThrow() else null + val stockOutLine = if (request.stockOutLineId != null) stockOutLIneRepository.findById(request.stockOutLineId).orElseThrow() else null + + qcResult.apply { + this.qcItem = qcItem + this.item = item + this.stockInLine = stockInLine + this.stockOutLine = stockOutLine + this.failQty = request.failQty + this.type = request.type + this.remarks = request.remarks + } + val savedQcResult = saveAndFlush(qcResult) + return MessageResponse( + id = savedQcResult.id, + name = savedQcResult.qcItem!!.name, + code = savedQcResult.qcItem!!.code, + type = savedQcResult.type, + message = null, + errorPosition = null + ) + } + +} \ No newline at end of file diff --git a/src/main/java/com/ffii/fpsms/modules/qc/web/QcResultController.kt b/src/main/java/com/ffii/fpsms/modules/qc/web/QcResultController.kt new file mode 100644 index 0000000..8069203 --- /dev/null +++ b/src/main/java/com/ffii/fpsms/modules/qc/web/QcResultController.kt @@ -0,0 +1,23 @@ +package com.ffii.fpsms.modules.qc.web + +import com.ffii.fpsms.modules.master.web.models.MessageResponse +import com.ffii.fpsms.modules.master.web.models.NewItemRequest +import com.ffii.fpsms.modules.qc.service.QcResultService +import com.ffii.fpsms.modules.qc.web.model.SaveQcResultRequest +import jakarta.validation.Valid +import org.springframework.web.bind.annotation.PostMapping +import org.springframework.web.bind.annotation.RequestBody +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RestController + +@RestController +@RequestMapping("/qcResult") +class QcResultController( + private val qcResultService: QcResultService +) { + + @PostMapping("/new") + fun saveItem(@Valid @RequestBody request: SaveQcResultRequest): MessageResponse { + return qcResultService.createOrUpdate(request) + } +} \ No newline at end of file diff --git a/src/main/java/com/ffii/fpsms/modules/qc/web/model/SaveQcResultRequest.kt b/src/main/java/com/ffii/fpsms/modules/qc/web/model/SaveQcResultRequest.kt new file mode 100644 index 0000000..9d395a4 --- /dev/null +++ b/src/main/java/com/ffii/fpsms/modules/qc/web/model/SaveQcResultRequest.kt @@ -0,0 +1,12 @@ +package com.ffii.fpsms.modules.qc.web.model + +data class SaveQcResultRequest( + val id: Long?, + val qcItemId: Long, + val itemId: Long, + val stockInLineId: Long?, + val stockOutLineId: Long?, + val failQty: Double, + val type: String?, + val remarks: String?, +) diff --git a/src/main/java/com/ffii/fpsms/modules/stock/service/StockInLineService.kt b/src/main/java/com/ffii/fpsms/modules/stock/service/StockInLineService.kt index 1578dd6..9c87629 100644 --- a/src/main/java/com/ffii/fpsms/modules/stock/service/StockInLineService.kt +++ b/src/main/java/com/ffii/fpsms/modules/stock/service/StockInLineService.kt @@ -4,8 +4,11 @@ import com.ffii.core.support.AbstractBaseEntityService import com.ffii.core.support.JdbcDao import com.ffii.fpsms.modules.common.CodeGenerator import com.ffii.fpsms.modules.master.entity.ItemsRepository +import com.ffii.fpsms.modules.master.entity.QcItemRepository import com.ffii.fpsms.modules.master.web.models.MessageResponse import com.ffii.fpsms.modules.purchaseOrder.entity.PurchaseOrderLineRepository +import com.ffii.fpsms.modules.qc.entity.QcResult +import com.ffii.fpsms.modules.qc.entity.QcResultRepository import com.ffii.fpsms.modules.stock.entity.* import com.ffii.fpsms.modules.stock.web.model.SaveStockInLineRequest import com.ffii.fpsms.modules.stock.web.model.SaveStockInRequest @@ -23,6 +26,8 @@ import java.time.LocalDateTime open class StockInLineService( private val jdbcDao: JdbcDao, private val polRepository: PurchaseOrderLineRepository, + private val qcItemsRepository: QcItemRepository, + private val qcResultRepository: QcResultRepository, private val stockInService: StockInService, private val stockInRepository: StockInRepository, private val stockInLineRepository: StockInLineRepository, @@ -60,6 +65,7 @@ open class StockInLineService( ) } + @Throws(IOException::class) @Transactional fun saveInventoryLotWhenStockIn(request: SaveStockInLineRequest, stockInLine: StockInLine): InventoryLot { val inventoryLot = InventoryLot() @@ -79,18 +85,39 @@ open class StockInLineService( } return inventoryLotRepository.saveAndFlush(inventoryLot) } + + @Throws(IOException::class) + @Transactional + fun saveQcResultWhenStockIn(request: SaveStockInLineRequest, stockInLine: StockInLine): List? { + if (!request.qcResult.isNullOrEmpty()) { + val qcResultEntries = request.qcResult!!.map { + val qcItem = qcItemsRepository.findById(it.qcItemId).orElseThrow() + val item = itemRepository.findById(stockInLine.item!!.id!!).orElseThrow() + QcResult().apply { + this.qcItem = qcItem + this.item = item + this.stockInLine = stockInLine + this.failQty = it.failQty + this.type = "qc" // default as qc for now + this.remarks = it.remarks + } + } + return qcResultRepository.saveAllAndFlush(qcResultEntries) + } + return null + } @Throws(IOException::class) @Transactional open fun update(request: SaveStockInLineRequest): MessageResponse { - val stockInLine = if (request.id != null) stockInLineRepository.findById(request.id).orElseThrow() - else return MessageResponse( - id = null, - code = null, - name = null, - type = "Found Null", - message = "stock in line id is null", - errorPosition = null, - ) + val stockInLine = if (request.id != null) stockInLineRepository.findById(request.id!!).orElseThrow() + else return MessageResponse( + id = null, + code = null, + name = null, + type = "Found Null", + message = "stock in line id is null", + errorPosition = null, + ) if (stockInLine.expiryDate != null && request.expiryDate == null) { request.apply { expiryDate = stockInLine.expiryDate @@ -99,9 +126,9 @@ open class StockInLineService( // return list of stock in line, update data grid with the list if (request.acceptedQty.compareTo(stockInLine.acceptedQty) == 0) { var savedInventoryLot: InventoryLot? = null + saveQcResultWhenStockIn(request, stockInLine) if (request.status == StockInLineStatus.RECEIVED.status) { if (request.expiryDate == null) { - println("trigger1?") return MessageResponse( id = null, code = null, @@ -113,8 +140,6 @@ open class StockInLineService( } savedInventoryLot = saveInventoryLotWhenStockIn(request = request, stockInLine = stockInLine) } -// if (request.status == StockInLineStatus.RECEIVED.status) { -// } stockInLine.apply { // user = null productionDate = request.productionDate?.atStartOfDay() // maybe need to change the request to LocalDateTime @@ -161,6 +186,7 @@ open class StockInLineService( status = stockInLine.status // this does update status user = stockInLine.user } + saveQcResultWhenStockIn(request, stockInLine) var savedInventoryLot: InventoryLot? = null if (request.status == StockInLineStatus.RECEIVED.status) { if (request.expiryDate == null) { diff --git a/src/main/java/com/ffii/fpsms/modules/stock/web/model/SaveStockInRequest.kt b/src/main/java/com/ffii/fpsms/modules/stock/web/model/SaveStockInRequest.kt index cc1dc20..aba9a99 100644 --- a/src/main/java/com/ffii/fpsms/modules/stock/web/model/SaveStockInRequest.kt +++ b/src/main/java/com/ffii/fpsms/modules/stock/web/model/SaveStockInRequest.kt @@ -1,5 +1,6 @@ package com.ffii.fpsms.modules.stock.web.model +import com.ffii.fpsms.modules.qc.web.model.SaveQcResultRequest import java.math.BigDecimal import java.time.LocalDate import java.time.LocalDateTime @@ -45,4 +46,5 @@ data class SaveStockInLineRequest( var productLotNo: String?, var receiptDate: LocalDate?, var productionDate: LocalDate?, + var qcResult: List? )