|
@@ -13,10 +13,6 @@ import com.ffii.fpsms.modules.qc.entity.QcResult |
|
|
import com.ffii.fpsms.modules.qc.entity.QcResultRepository |
|
|
import com.ffii.fpsms.modules.qc.entity.QcResultRepository |
|
|
import com.ffii.fpsms.modules.stock.entity.* |
|
|
import com.ffii.fpsms.modules.stock.entity.* |
|
|
import com.ffii.fpsms.modules.stock.sql.StockSql.SQL.INVENTORY_COUNT |
|
|
import com.ffii.fpsms.modules.stock.sql.StockSql.SQL.INVENTORY_COUNT |
|
|
import com.ffii.fpsms.modules.stock.web.model.ExportQrCodeRequest |
|
|
|
|
|
import com.ffii.fpsms.modules.stock.web.model.SaveStockInLineRequest |
|
|
|
|
|
import com.ffii.fpsms.modules.stock.web.model.SaveStockInRequest |
|
|
|
|
|
import com.ffii.fpsms.modules.stock.web.model.StockInLineStatus |
|
|
|
|
|
import net.sf.jasperreports.engine.JasperCompileManager |
|
|
import net.sf.jasperreports.engine.JasperCompileManager |
|
|
import org.springframework.core.io.ClassPathResource |
|
|
import org.springframework.core.io.ClassPathResource |
|
|
import org.springframework.stereotype.Service |
|
|
import org.springframework.stereotype.Service |
|
@@ -33,11 +29,14 @@ import com.ffii.fpsms.modules.purchaseOrder.enums.PurchaseOrderLineStatus |
|
|
import com.ffii.fpsms.modules.purchaseOrder.enums.PurchaseOrderStatus |
|
|
import com.ffii.fpsms.modules.purchaseOrder.enums.PurchaseOrderStatus |
|
|
import com.ffii.fpsms.modules.stock.entity.enum.InventoryLotLineStatus |
|
|
import com.ffii.fpsms.modules.stock.entity.enum.InventoryLotLineStatus |
|
|
import com.ffii.fpsms.modules.stock.entity.projection.StockInLineInfo |
|
|
import com.ffii.fpsms.modules.stock.entity.projection.StockInLineInfo |
|
|
|
|
|
import com.ffii.fpsms.modules.stock.enums.EscalationLogStatus |
|
|
|
|
|
import com.ffii.fpsms.modules.stock.web.model.* |
|
|
import java.io.FileNotFoundException |
|
|
import java.io.FileNotFoundException |
|
|
import java.time.format.DateTimeFormatter |
|
|
import java.time.format.DateTimeFormatter |
|
|
import kotlinx.serialization.Serializable |
|
|
import kotlinx.serialization.Serializable |
|
|
import kotlinx.serialization.json.Json |
|
|
import kotlinx.serialization.json.Json |
|
|
import kotlinx.serialization.encodeToString |
|
|
import kotlinx.serialization.encodeToString |
|
|
|
|
|
import kotlin.math.max |
|
|
|
|
|
|
|
|
@Serializable |
|
|
@Serializable |
|
|
data class QrContent(val itemId: Long, val stockInLineId: Long) |
|
|
data class QrContent(val itemId: Long, val stockInLineId: Long) |
|
@@ -49,6 +48,8 @@ open class StockInLineService( |
|
|
private val polRepository: PurchaseOrderLineRepository, |
|
|
private val polRepository: PurchaseOrderLineRepository, |
|
|
private val qcItemsRepository: QcItemRepository, |
|
|
private val qcItemsRepository: QcItemRepository, |
|
|
private val qcResultRepository: QcResultRepository, |
|
|
private val qcResultRepository: QcResultRepository, |
|
|
|
|
|
private val escalationLogService: EscalationLogService, |
|
|
|
|
|
private val escalationLogRepository: EscalationLogRepository, |
|
|
private val stockInService: StockInService, |
|
|
private val stockInService: StockInService, |
|
|
private val stockInRepository: StockInRepository, |
|
|
private val stockInRepository: StockInRepository, |
|
|
private val stockInLineRepository: StockInLineRepository, |
|
|
private val stockInLineRepository: StockInLineRepository, |
|
@@ -135,6 +136,7 @@ open class StockInLineService( |
|
|
val savedInventoryLot = inventoryLotRepository.saveAndFlush(inventoryLot) |
|
|
val savedInventoryLot = inventoryLotRepository.saveAndFlush(inventoryLot) |
|
|
return savedInventoryLot |
|
|
return savedInventoryLot |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Throws(IOException::class) |
|
|
@Throws(IOException::class) |
|
|
@Transactional |
|
|
@Transactional |
|
|
fun saveInventoryLotLineWhenStockIn(request: SaveStockInLineRequest, stockInLine: StockInLine): InventoryLotLine { |
|
|
fun saveInventoryLotLineWhenStockIn(request: SaveStockInLineRequest, stockInLine: StockInLine): InventoryLotLine { |
|
@@ -181,6 +183,42 @@ open class StockInLineService( |
|
|
return null |
|
|
return null |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Throws(IOException::class) |
|
|
|
|
|
@Transactional |
|
|
|
|
|
fun saveEscalationLogWhenStockIn(request: SaveStockInLineRequest, stockInLine: StockInLine): EscalationLog? { |
|
|
|
|
|
if (request.escalationLog != null) { |
|
|
|
|
|
val escReq = request.escalationLog; |
|
|
|
|
|
|
|
|
|
|
|
var qcTotal = 0; |
|
|
|
|
|
var qcFailed = 0; |
|
|
|
|
|
if (request.qcResult!!.isEmpty()) { |
|
|
|
|
|
val escLogList = stockInLine.id?.let { escalationLogRepository.findAllByDeletedFalseAndStockInLineIdIn(listOf(it)); } |
|
|
|
|
|
val latestLog = escLogList?.maxBy { it.id!! }; |
|
|
|
|
|
latestLog?.apply { status = EscalationLogStatus.ESCALATED } |
|
|
|
|
|
escalationLogService.save(latestLog); |
|
|
|
|
|
|
|
|
|
|
|
val qcRes = qcResultRepository.findQcResultInfoByStockInLineIdAndDeletedFalse(stockInLine.id!!); |
|
|
|
|
|
qcTotal = qcRes.size; |
|
|
|
|
|
qcFailed = qcRes.count{ !it.qcPassed}; |
|
|
|
|
|
} else { |
|
|
|
|
|
qcTotal = request.qcResult?.size ?: 5; |
|
|
|
|
|
qcFailed = request.qcResult?.count { !it.qcPassed } ?: 0; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
escReq?.apply { |
|
|
|
|
|
this.stockInLineId = stockInLine.id; |
|
|
|
|
|
this.qcTotalCount = qcTotal; |
|
|
|
|
|
this.qcFailCount = qcFailed; |
|
|
|
|
|
} |
|
|
|
|
|
if (escReq != null) { |
|
|
|
|
|
val res = escalationLogService.saveEscalationLog(escReq) |
|
|
|
|
|
return res.id?.let { escalationLogRepository.findById(it).orElseThrow() }; |
|
|
|
|
|
}; |
|
|
|
|
|
// return qcResultRepository.saveAllAndFlush(qcResultEntries) |
|
|
|
|
|
} |
|
|
|
|
|
return null |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@Throws(IOException::class) |
|
|
@Throws(IOException::class) |
|
|
@Transactional |
|
|
@Transactional |
|
|
fun updatePurchaseOrderStatus(request: SaveStockInLineRequest) { |
|
|
fun updatePurchaseOrderStatus(request: SaveStockInLineRequest) { |
|
@@ -287,7 +325,7 @@ open class StockInLineService( |
|
|
this.status = StockInLineStatus.COMPLETE.status |
|
|
this.status = StockInLineStatus.COMPLETE.status |
|
|
this.inventoryLotLine = savedInventoryLotLine |
|
|
this.inventoryLotLine = savedInventoryLotLine |
|
|
} |
|
|
} |
|
|
} else if (request.status == StockInLineStatus.PENDING.status) { |
|
|
|
|
|
|
|
|
} else if (request.status == StockInLineStatus.PENDING.status || request.status == StockInLineStatus.ESCALATED.status) { |
|
|
// QC |
|
|
// QC |
|
|
if (request.qcAccept == true) { |
|
|
if (request.qcAccept == true) { |
|
|
// Accepted |
|
|
// Accepted |
|
@@ -384,9 +422,17 @@ open class StockInLineService( |
|
|
// ) |
|
|
// ) |
|
|
// } |
|
|
// } |
|
|
} else if (request.qcAccept == false) { |
|
|
} else if (request.qcAccept == false) { |
|
|
// Rejected |
|
|
|
|
|
stockInLine.apply { |
|
|
|
|
|
this.status = StockInLineStatus.REJECT.status |
|
|
|
|
|
|
|
|
if (request.escalationLog != null) { |
|
|
|
|
|
// Escalated |
|
|
|
|
|
stockInLine.apply { |
|
|
|
|
|
this.status = StockInLineStatus.ESCALATED.status |
|
|
|
|
|
} |
|
|
|
|
|
saveEscalationLogWhenStockIn(request, stockInLine); |
|
|
|
|
|
} else { |
|
|
|
|
|
// Rejected |
|
|
|
|
|
stockInLine.apply { |
|
|
|
|
|
this.status = StockInLineStatus.REJECT.status |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
saveQcResultWhenStockIn(request, stockInLine) |
|
|
saveQcResultWhenStockIn(request, stockInLine) |
|
|