|
|
@@ -4,10 +4,15 @@ import com.ffii.core.response.RecordsRes |
|
|
|
import com.ffii.core.support.AbstractBaseEntityService |
|
|
|
import com.ffii.core.support.JdbcDao |
|
|
|
import com.ffii.fpsms.modules.common.SecurityUtils |
|
|
|
import com.ffii.fpsms.modules.master.entity.ItemsRepository |
|
|
|
import com.ffii.fpsms.modules.master.entity.UomConversionRepository |
|
|
|
import com.ffii.fpsms.modules.master.web.models.MessageResponse |
|
|
|
import com.ffii.fpsms.modules.pickOrder.entity.PickOrder |
|
|
|
import com.ffii.fpsms.modules.pickOrder.entity.PickOrderLine |
|
|
|
import com.ffii.fpsms.modules.pickOrder.entity.PickOrderLineRepository |
|
|
|
import com.ffii.fpsms.modules.pickOrder.entity.PickOrderRepository |
|
|
|
import com.ffii.fpsms.modules.pickOrder.entity.projection.PickOrderInfo |
|
|
|
import com.ffii.fpsms.modules.pickOrder.enums.PickOrderLineStatus |
|
|
|
import com.ffii.fpsms.modules.pickOrder.enums.PickOrderStatus |
|
|
|
import com.ffii.fpsms.modules.pickOrder.web.models.* |
|
|
|
import com.ffii.fpsms.modules.stock.entity.InventoryLotLineRepository |
|
|
@@ -39,14 +44,47 @@ import kotlin.jvm.optionals.getOrNull |
|
|
|
@Service |
|
|
|
open class PickOrderService( |
|
|
|
private val jdbcDao: JdbcDao, |
|
|
|
val pickOrderRepository: PickOrderRepository, |
|
|
|
val suggestedPickLotService: SuggestedPickLotService, |
|
|
|
val userService: UserService, |
|
|
|
private val pickOrderRepository: PickOrderRepository, |
|
|
|
private val pickOrderLineRepository: PickOrderLineRepository, |
|
|
|
private val suggestedPickLotService: SuggestedPickLotService, |
|
|
|
private val userService: UserService, |
|
|
|
private val stockOutLIneRepository: StockOutLIneRepository, |
|
|
|
private val inventoryLotLineRepository: InventoryLotLineRepository, |
|
|
|
val inventoryService: InventoryService, |
|
|
|
private val stockOutRepository: StockOutRepository |
|
|
|
private val inventoryService: InventoryService, |
|
|
|
private val stockOutRepository: StockOutRepository, |
|
|
|
private val itemsRepository: ItemsRepository, |
|
|
|
private val uomConversionRepository: UomConversionRepository |
|
|
|
): AbstractBaseEntityService<PickOrder, Long, PickOrderRepository>(jdbcDao, pickOrderRepository) { |
|
|
|
open fun create(request: SavePickOrderRequest): MessageResponse { |
|
|
|
val code = assignPickCode() |
|
|
|
val pickOrder = PickOrder().apply { |
|
|
|
this.code = code |
|
|
|
this.targetDate = request.targetDate |
|
|
|
this.type = request.type |
|
|
|
this.status = PickOrderStatus.PENDING |
|
|
|
} |
|
|
|
val savedPickOrder = saveAndFlush(pickOrder) |
|
|
|
val polEntries = request.pickOrderLine.map { |
|
|
|
val item = itemsRepository.findById(it.itemId).orElseThrow() |
|
|
|
val uom = uomConversionRepository.findById(it.uomId).orElseThrow() |
|
|
|
PickOrderLine().apply { |
|
|
|
this.pickOrder = savedPickOrder |
|
|
|
this.item = item |
|
|
|
this.qty = it.qty |
|
|
|
this.uom = uom |
|
|
|
this.status = PickOrderLineStatus.PENDING |
|
|
|
} |
|
|
|
} |
|
|
|
pickOrderLineRepository.saveAll(polEntries) |
|
|
|
return MessageResponse( |
|
|
|
id = savedPickOrder.id, |
|
|
|
name = savedPickOrder.code, |
|
|
|
code = savedPickOrder.code, |
|
|
|
type = savedPickOrder.type!!.value, |
|
|
|
message = "success", |
|
|
|
errorPosition = "", |
|
|
|
) |
|
|
|
} |
|
|
|
open fun localDateTimeParse(dateTime: String?, pattern: String? = "YYYY-MM-DD hh:mm:ss"): LocalDateTime? { |
|
|
|
try { |
|
|
|
val formatter = DateTimeFormatter.ofPattern(pattern!!) |
|
|
@@ -97,6 +135,26 @@ open class PickOrderService( |
|
|
|
sql.append(" group by po.consoCode, po.releasedDate, po.status, po.assignTo ") |
|
|
|
return jdbcDao.queryForList(sql.toString(), args); |
|
|
|
} |
|
|
|
open fun assignPickCode(): String { |
|
|
|
val suffixFormat = "%03d" |
|
|
|
val pattern = "yyyyMMdd" |
|
|
|
val formatter = DateTimeFormatter.ofPattern(pattern) |
|
|
|
|
|
|
|
val prefix = "P" |
|
|
|
val midfix = LocalDate.now().format(formatter) |
|
|
|
val suffix = String.format(suffixFormat, 1) |
|
|
|
|
|
|
|
val latestCode = pickOrderRepository.findLatestCodeByPrefix("${prefix}-${midfix}") |
|
|
|
if (latestCode != null) { |
|
|
|
val splitLatestCode = latestCode.split("-") |
|
|
|
if (splitLatestCode.size > 2) { |
|
|
|
val latestNo = splitLatestCode[2].toInt() |
|
|
|
return listOf<String>(prefix, midfix, String.format(suffixFormat, latestNo + 1)).joinToString("-") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return listOf<String>(prefix, midfix, suffix).joinToString("-") |
|
|
|
} |
|
|
|
// Consolidating Pick Orders |
|
|
|
open fun assignConsoCode(): String { |
|
|
|
val suffixFormat = "%03d" |
|
|
|