@@ -18,4 +18,5 @@ interface ItemUomRespository : AbstractRepository<ItemUom, Long> { | |||
fun findByItemIdAndPurchaseUnitIsTrueAndDeletedIsFalse(itemId: Serializable): ItemUom? | |||
fun findByItemM18IdAndPurchaseUnitIsTrueAndDeletedIsFalse(itemM18Id: Long): ItemUom? | |||
fun findBaseUnitByItemIdAndBaseUnitIsTrueAndDeletedIsFalse(itemId: Long): ItemUom? | |||
} |
@@ -100,7 +100,7 @@ open class BomService( | |||
return savedBom | |||
} | |||
fun saveBomMaterial(req: ImportBomMatRequest): BomMaterial { | |||
private fun saveBomMaterial(req: ImportBomMatRequest): BomMaterial { | |||
// val uom = uomConversionRepository.findByCodeAndDeletedFalse() | |||
val bomMaterial = BomMaterial().apply { | |||
this.item = req.item | |||
@@ -116,7 +116,7 @@ open class BomService( | |||
} | |||
return bomMaterialRepository.saveAndFlush(bomMaterial) | |||
} | |||
fun saveBomProcess(req: ImportBomProcessRequest): BomProcess { | |||
private fun saveBomProcess(req: ImportBomProcessRequest): BomProcess { | |||
val bomProcess = BomProcess().apply { | |||
this.process = req.process | |||
this.equipment = req.equipment | |||
@@ -155,10 +155,11 @@ open class BomService( | |||
var bomMatRequest = ImportBomMatRequest( | |||
bom = bom | |||
) | |||
println("starting new loop") | |||
while (startRowIndex != endRowIndex || startColumnIndex != endColumnIndex) { | |||
val tempRow = sheet.getRow(startRowIndex) | |||
val tempCell = tempRow.getCell(startColumnIndex) | |||
if (tempCell == null || tempCell.cellType == CellType.BLANK) { | |||
if (startColumnIndex == 0 && (tempCell == null || tempCell.cellType == CellType.BLANK)) { | |||
break | |||
} else { | |||
try { | |||
@@ -185,6 +186,8 @@ open class BomService( | |||
bomMatRequest.salesUnit = salesUnit | |||
} | |||
10 -> { | |||
println("seqNo: ${tempCell.numericCellValue.toInt()}") | |||
println("bomId: ${bom.id!!}") | |||
val bomProcess = bomProcessRepository.findBySeqNoAndBomIdAndDeletedIsFalse( | |||
seqNo = tempCell.numericCellValue.toInt(), | |||
bomId = bom.id!! | |||
@@ -192,11 +195,19 @@ open class BomService( | |||
bomProcessMatRequest.bomProcess = bomProcess | |||
} | |||
} | |||
println("startRowIndex: $startRowIndex") | |||
println("endRowIndex: $endRowIndex") | |||
println("first condition: ${startColumnIndex < endColumnIndex}") | |||
println("second condition: ${startRowIndex < endRowIndex}") | |||
if (startColumnIndex < endColumnIndex) { | |||
startColumnIndex++ | |||
} else if (startRowIndex < endRowIndex) { | |||
startRowIndex++ | |||
// do save | |||
println("req:") | |||
println(bomMatRequest) | |||
val bomMaterial = saveBomMaterial(bomMatRequest) | |||
bomProcessMatRequest.bomMaterial = bomMaterial | |||
val bomProcessMaterial = saveBomProcessMaterial(bomProcessMatRequest) | |||
@@ -205,6 +216,7 @@ open class BomService( | |||
bomMatRequest = ImportBomMatRequest( | |||
bom = bom | |||
) | |||
println("saved: $bomMatRequest") | |||
} | |||
} catch(e: Error) { | |||
println("DEBUG ERROR:") | |||
@@ -307,13 +319,17 @@ open class BomService( | |||
} | |||
private fun extractDurationStringToMinutes(str: String): Int { | |||
val regex = """(\d+)(\D+)""".toRegex() | |||
val regex = """(\d+)(\D+)(\d+)(\D+)""".toRegex() | |||
val matchResult = regex.find(str) | |||
// fun returnMultiplier(unit: String): { | |||
// | |||
// } | |||
val (number, unit) = matchResult?.let { | |||
val number = it.groupValues[1].toInt() | |||
val unit = it.groupValues[2] | |||
Pair(number, unit) | |||
val num1 = it.groupValues[1].toInt() | |||
val unit1 = it.groupValues[2] | |||
// val num2 = it.groupValues[3].toInt() | |||
// val unit2 = it.groupValues[4] | |||
Pair(num1, unit1) | |||
}!! | |||
var multiplier = 1 | |||
when { | |||
@@ -336,7 +352,7 @@ open class BomService( | |||
val tempCell = tempRow.getCell(startColumnIndex) | |||
if (tempCell != null && tempCell.cellType == CellType.STRING && tempCell.stringCellValue.trim() == "工序") { | |||
startRowIndex += 2 // skip column header | |||
println("last: $startRowIndex") | |||
// println("last: $startRowIndex") | |||
break | |||
} | |||
startRowIndex++ | |||
@@ -349,7 +365,7 @@ open class BomService( | |||
val tempCell = tempRow.getCell(startColumnIndex) | |||
val checkCell = tempRow.getCell(0) | |||
if (startColumnIndex == 0 && (tempCell == null || tempCell.cellType == CellType.BLANK)) { | |||
println("hi") | |||
// println("hi") | |||
break | |||
} else { | |||
println(tempCell.cellType) | |||
@@ -357,16 +373,16 @@ open class BomService( | |||
try { | |||
when (startColumnIndex) { | |||
0 -> { | |||
println("startRowIndex: $startRowIndex") | |||
// println("startRowIndex: $startRowIndex") | |||
bomProcessRequest.seqNo = tempCell.numericCellValue.toLong() | |||
println("seqNo: ${tempCell.numericCellValue.toLong()}") | |||
println("bomProcessRequest: $bomProcessRequest") | |||
// println("seqNo: ${tempCell.numericCellValue.toLong()}") | |||
// println("bomProcessRequest: $bomProcessRequest") | |||
} | |||
1 -> { | |||
val equipmentName = tempCell.stringCellValue.trim() | |||
if (equipmentName != "不適用") { | |||
val equipment = bomGetOrCreateEquipment(equipmentName) | |||
println("equipment created") | |||
// println("equipment created") | |||
bomProcessRequest.equipment = equipment | |||
} | |||
} | |||
@@ -374,7 +390,7 @@ open class BomService( | |||
val processName = tempCell.stringCellValue.trim() | |||
val process = bomGetOrCreateProcess(processName) | |||
bomProcessRequest.process = process | |||
println("process created") | |||
// println("process created") | |||
} | |||
3 -> { | |||
val description = tempCell.stringCellValue.trim() | |||
@@ -420,18 +436,18 @@ open class BomService( | |||
} | |||
} | |||
} | |||
println("req:") | |||
println(bomProcessRequest) | |||
// println("req:") | |||
// println(bomProcessRequest) | |||
// moving the loop | |||
if (startColumnIndex < endColumnIndex) { | |||
println("case1") | |||
// println("case1") | |||
startColumnIndex++ | |||
println("next col startColumnIndex: $startColumnIndex") | |||
// println("next col startColumnIndex: $startColumnIndex") | |||
} else if (startRowIndex < endRowIndex) { | |||
println("case2") | |||
// println("case2") | |||
// when doesn't meet first condition, falls to this and go new row | |||
startRowIndex++ | |||
println("next row startRowIndex: $startRowIndex") | |||
// println("next row startRowIndex: $startRowIndex") | |||
// do save | |||
saveBomProcess(bomProcessRequest) | |||
// clean up | |||
@@ -2,16 +2,21 @@ package com.ffii.fpsms.modules.purchaseOrder.entity | |||
import com.ffii.core.support.AbstractRepository | |||
import com.ffii.fpsms.modules.purchaseOrder.entity.projections.PurchaseOrderInfo | |||
import org.springframework.data.domain.Page | |||
import org.springframework.stereotype.Repository | |||
import java.io.Serializable | |||
import java.util.Optional | |||
import org.springframework.data.domain.Pageable | |||
@Repository | |||
interface PurchaseOrderRepository : AbstractRepository<PurchaseOrder, Long> { | |||
fun findTopByM18DataLogIdAndDeletedIsFalseOrderByModifiedDesc(m18datalogId: Serializable): PurchaseOrder? | |||
fun findPurchaseOrderInfoByDeletedIsFalse(): List<PurchaseOrderInfo> | |||
fun findPurchaseOrderInfoByDeletedIsFalse(pageable: Pageable): Page<PurchaseOrderInfo> | |||
fun findPurchaseOrderInfoByIdAndDeletedIsFalse(id: Long): PurchaseOrderInfo | |||
fun findByIdAndDeletedFalse(id: Long): Optional<PurchaseOrder> | |||
override fun findAll(pageable: Pageable): Page<PurchaseOrder> | |||
} |
@@ -1,5 +1,6 @@ | |||
package com.ffii.fpsms.modules.purchaseOrder.service | |||
import com.ffii.core.response.RecordsRes | |||
import com.ffii.core.support.AbstractBaseEntityService | |||
import com.ffii.core.support.JdbcDao | |||
import com.ffii.fpsms.m18.entity.M18DataLogRepository | |||
@@ -16,12 +17,16 @@ import com.ffii.fpsms.modules.purchaseOrder.entity.projections.PurchaseOrderInfo | |||
import com.ffii.fpsms.modules.purchaseOrder.enums.PurchaseOrderLineStatus | |||
import com.ffii.fpsms.modules.purchaseOrder.enums.PurchaseOrderStatus | |||
import com.ffii.fpsms.modules.purchaseOrder.enums.PurchaseOrderType | |||
import com.ffii.fpsms.modules.purchaseOrder.web.model.PagingRequest | |||
import com.ffii.fpsms.modules.purchaseOrder.web.model.SavePurchaseOrderRequest | |||
import com.ffii.fpsms.modules.purchaseOrder.web.model.SavePurchaseOrderResponse | |||
import com.ffii.fpsms.modules.stock.entity.StockInLine | |||
import com.ffii.fpsms.modules.stock.entity.StockInLineRepository | |||
import com.ffii.fpsms.modules.stock.entity.StockInRepository | |||
import com.ffii.fpsms.modules.stock.web.model.StockInLineStatus | |||
import org.springframework.data.domain.Page | |||
import org.springframework.data.domain.PageRequest | |||
import org.springframework.data.domain.Pageable | |||
import org.springframework.stereotype.Service | |||
import org.springframework.transaction.annotation.Transactional | |||
import java.io.IOException | |||
@@ -42,8 +47,16 @@ open class PurchaseOrderService( | |||
private val currencyService: CurrencyService, | |||
private val shopService: ShopService, | |||
) : AbstractBaseEntityService<PurchaseOrder, Long, PurchaseOrderRepository>(jdbcDao, purchaseOrderRepository) { | |||
open fun getPoList(): List<PurchaseOrderDataClass> { | |||
val list = purchaseOrderRepository.findPurchaseOrderInfoByDeletedIsFalse() | |||
open fun getPoList(request: PagingRequest): RecordsRes<PurchaseOrderDataClass> { | |||
println(request) | |||
val totalCount = purchaseOrderRepository.count().toInt() | |||
val list: List<PurchaseOrderInfo> = if (request.pageNum != null && request.pageSize != null) { | |||
val pageable = PageRequest.of(request.pageNum!!, request.pageSize!!) | |||
purchaseOrderRepository.findPurchaseOrderInfoByDeletedIsFalse(pageable).content | |||
} else { | |||
purchaseOrderRepository.findPurchaseOrderInfoByDeletedIsFalse() | |||
} | |||
val mappedList = list.map { | |||
val escalated = stockInLineRepository.findAllStockInLineInfoByPurchaseOrderIdAndStatusStartsWithAndDeletedFalse( | |||
purchaseOrderId = it.id, | |||
@@ -60,7 +73,7 @@ open class PurchaseOrderService( | |||
escalated = escalated.isNotEmpty(), | |||
) | |||
} | |||
return mappedList | |||
return RecordsRes(mappedList, totalCount) | |||
} | |||
open fun allPurchaseOrder(): List<PurchaseOrder> { | |||
@@ -1,5 +1,6 @@ | |||
package com.ffii.fpsms.modules.purchaseOrder.web | |||
import com.ffii.core.response.RecordsRes | |||
import com.ffii.core.support.JdbcDao | |||
import com.ffii.fpsms.modules.master.entity.Items | |||
import com.ffii.fpsms.modules.master.service.ItemsService | |||
@@ -8,6 +9,11 @@ import com.ffii.fpsms.modules.purchaseOrder.entity.PurchaseOrder | |||
import com.ffii.fpsms.modules.purchaseOrder.entity.projections.PurchaseOrderDataClass | |||
import com.ffii.fpsms.modules.purchaseOrder.entity.projections.PurchaseOrderInfo | |||
import com.ffii.fpsms.modules.purchaseOrder.service.PurchaseOrderService | |||
import com.ffii.fpsms.modules.purchaseOrder.web.model.PagingRequest | |||
import com.ffii.fpsms.modules.stock.web.model.SaveStockInLineRequest | |||
import jakarta.servlet.http.HttpServletRequest | |||
import org.springframework.data.domain.Page | |||
import org.springframework.data.domain.PageRequest | |||
import org.springframework.web.bind.annotation.* | |||
@RestController | |||
@@ -16,9 +22,12 @@ class PurchaseOrderController( | |||
private val purchaseOrderService: PurchaseOrderService | |||
) { | |||
@GetMapping("/list") | |||
fun getPoList(): List<PurchaseOrderDataClass> { | |||
return purchaseOrderService.getPoList() | |||
fun getPoList(@RequestParam(required = false) pageNum: Int, @RequestParam(required = false) pageSize: Int ): RecordsRes<PurchaseOrderDataClass> { | |||
println("request") | |||
val pageRequest = PagingRequest(pageSize = pageSize, pageNum = pageNum,) | |||
return purchaseOrderService.getPoList(pageRequest) | |||
} | |||
@GetMapping("/detail/{id}") // purchaseOrderId | |||
fun getDetailedPo(@PathVariable id: Long): Map<String, Any> { | |||
return purchaseOrderService.getDetailedPo(id) | |||
@@ -0,0 +1,6 @@ | |||
package com.ffii.fpsms.modules.purchaseOrder.web.model | |||
data class PagingRequest( | |||
var pageNum: Int?, | |||
var pageSize: Int? | |||
) |
@@ -1,6 +1,7 @@ | |||
package com.ffii.fpsms.modules.stock.entity | |||
import com.ffii.core.entity.BaseEntity | |||
import com.ffii.fpsms.modules.master.entity.ItemUom | |||
import com.ffii.fpsms.modules.master.entity.Warehouse | |||
import jakarta.persistence.Column | |||
import jakarta.persistence.Entity | |||
@@ -31,6 +32,11 @@ open class InventoryLotLine : BaseEntity<Long>() { | |||
@Column(name = "outQty") | |||
open var outQty: BigDecimal? = null | |||
@NotNull | |||
@ManyToOne | |||
@JoinColumn(name = "baseItemUomId") | |||
open var baseUom: ItemUom? = null | |||
@Column(name = "holdQty") | |||
open var holdQty: BigDecimal? = null | |||
@@ -25,6 +25,7 @@ import java.math.BigDecimal | |||
import java.time.LocalDate | |||
import java.time.LocalDateTime | |||
import com.ffii.core.utils.PdfUtils; | |||
import com.ffii.fpsms.modules.master.entity.ItemUomRespository | |||
import com.ffii.fpsms.modules.master.entity.WarehouseRepository | |||
import com.ffii.fpsms.modules.purchaseOrder.entity.PurchaseOrderRepository | |||
import com.ffii.fpsms.modules.purchaseOrder.enums.PurchaseOrderLineStatus | |||
@@ -53,6 +54,7 @@ open class StockInLineService( | |||
private val inventoryLotLineRepository: InventoryLotLineRepository, | |||
private val itemRepository: ItemsRepository, | |||
private val warehouseRepository: WarehouseRepository, | |||
private val itemUomRespository: ItemUomRespository, | |||
): AbstractBaseEntityService<StockInLine, Long, StockInLineRepository>(jdbcDao, stockInLineRepository) { | |||
open fun getStockInLineInfo(stockInLineId: Long): StockInLineInfo { | |||
@@ -130,11 +132,17 @@ open class StockInLineService( | |||
val inventoryLotLine = InventoryLotLine() | |||
println(request.warehouseId!!) | |||
val warehouse = warehouseRepository.findById(request.warehouseId!!).orElseThrow() | |||
val baseItemUom = itemUomRespository.findBaseUnitByItemIdAndBaseUnitIsTrueAndDeletedIsFalse( | |||
itemId = request.itemId | |||
) | |||
println(stockInLine.purchaseOrderLine!!.uom!!.id!!) | |||
println(request.itemId) | |||
inventoryLotLine.apply { | |||
this.inventoryLot = stockInLine.inventoryLot | |||
this.warehouse = warehouse | |||
this.inQty = request.acceptedQty | |||
this.status = "available" | |||
this.baseUom = baseItemUom | |||
} | |||
val savedInventoryLotLine = inventoryLotLineRepository.saveAndFlush(inventoryLotLine) | |||
return savedInventoryLotLine | |||
@@ -0,0 +1,4 @@ | |||
-- liquibase formatted sql | |||
-- changeset derek:update_inventory_lot_line_uom_id | |||
ALTER TABLE `inventory_lot_line` | |||
ADD COLUMN `baseItemUomId` INT(11) NOT NULL |