| @@ -318,4 +318,55 @@ open class ItemsService( | |||||
| errorPosition = null, | errorPosition = null, | ||||
| ) | ) | ||||
| } | } | ||||
| open fun getItemsWithDetailsByPage(args: Map<String, Any>): List<Map<String, Any>> { | |||||
| val sql = StringBuilder("select" | |||||
| + " i.id, " | |||||
| + " i.code, " | |||||
| + " i.name, " | |||||
| + " i.type, " | |||||
| + " i.description, " | |||||
| + " uc.id as uomId, " | |||||
| + " uc.code as uom, " | |||||
| + " uc.udfudesc as uomDesc, " | |||||
| + " COALESCE(inv.availableQty, 0) as currentStockBalance " | |||||
| + " from items i " | |||||
| + " left join item_uom iu on iu.itemId = i.id and iu.deleted = false and iu.salesUnit = true " | |||||
| + " left join uom_conversion uc on uc.id = iu.uomId " | |||||
| + " left join (" | |||||
| + " SELECT " | |||||
| + " il.itemId, " | |||||
| + " SUM(COALESCE(ill.inQty, 0) - COALESCE(ill.outQty, 0) - COALESCE(ill.holdQty, 0)) as availableQty " | |||||
| + " FROM inventory_lot_line ill " | |||||
| + " JOIN inventory_lot il ON il.id = ill.inventoryLotId " | |||||
| + " LEFT JOIN item_uom iu_ratio ON iu_ratio.itemId = il.itemId AND iu_ratio.deleted = false AND iu_ratio.salesUnit = true " | |||||
| + " WHERE ill.status = 'available' " | |||||
| + " AND (COALESCE(ill.inQty, 0) - COALESCE(ill.outQty, 0) - COALESCE(ill.holdQty, 0)) > 0 " | |||||
| + " AND (il.expiryDate IS NULL OR il.expiryDate >= CURDATE()) " | |||||
| + " GROUP BY il.itemId " | |||||
| + " ) inv ON inv.itemId = i.id " | |||||
| + " where i.deleted = false " | |||||
| ) | |||||
| // Add search conditions | |||||
| if (args.containsKey("name")) { | |||||
| sql.append(" AND i.name LIKE :name ") | |||||
| } | |||||
| if (args.containsKey("code")) { | |||||
| sql.append(" AND i.code LIKE :code ") | |||||
| } | |||||
| if (args.containsKey("description")) { | |||||
| sql.append(" AND i.description LIKE :description ") | |||||
| } | |||||
| if (args.containsKey("type")) { | |||||
| sql.append(" AND i.type = :type ") | |||||
| } | |||||
| sql.append(" ORDER BY i.name ASC ") | |||||
| return jdbcDao.queryForList(sql.toString(), args); | |||||
| } | |||||
| } | } | ||||
| @@ -104,4 +104,22 @@ class ItemsController( | |||||
| println("`````TESTING`````") | println("`````TESTING`````") | ||||
| return itemsService.saveItem(newItem) | return itemsService.saveItem(newItem) | ||||
| } | } | ||||
| @GetMapping("/itemsWithDetails") | |||||
| fun getItemsWithDetailsByPage(request: HttpServletRequest): RecordsRes<Map<String, Any>> { | |||||
| val criteriaArgs = CriteriaArgsBuilder.withRequest(request) | |||||
| .addStringLike("name") | |||||
| .addStringLike("code") | |||||
| .addStringLike("description") | |||||
| .addString("type") | |||||
| .build() | |||||
| val pageSize = request.getParameter("pageSize")?.toIntOrNull() ?: 10 | |||||
| val pageNum = request.getParameter("pageNum")?.toIntOrNull() ?: 1 | |||||
| val fullList = itemsService.getItemsWithDetailsByPage(criteriaArgs) | |||||
| val paginatedList = PagingUtils.getPaginatedList(fullList, pageSize, pageNum) | |||||
| return RecordsRes(paginatedList, fullList.size) | |||||
| } | |||||
| } | } | ||||
| @@ -741,9 +741,9 @@ open class PickOrderService( | |||||
| println("Stock Out Lines: ${stockOutLines.map { "${it.id}(status=${it.status}, qty=${it.qty})" }}") | println("Stock Out Lines: ${stockOutLines.map { "${it.id}(status=${it.status}, qty=${it.qty})" }}") | ||||
| val totalPickedQty = stockOutLines | val totalPickedQty = stockOutLines | ||||
| .filter { it.status == "completed" || it.status == "COMPLETE" } // Only completed lines | |||||
| .filter { (it.qty ?: zero) > BigDecimal.ZERO } // Only lines with actual quantities | |||||
| .sumOf { it.qty ?: zero } | |||||
| .filter { it.status in listOf("completed", "COMPLETE", "partially_completed") } // Include partially completed | |||||
| .filter { (it.qty ?: zero) > BigDecimal.ZERO } // Only lines with actual quantities | |||||
| .sumOf { it.qty ?: zero } | |||||
| println("Total Picked Qty: $totalPickedQty") | println("Total Picked Qty: $totalPickedQty") | ||||
| println("=== END DEBUG ===") | println("=== END DEBUG ===") | ||||
| @@ -13,6 +13,8 @@ enum class StockOutLineStatus(val status: String) { | |||||
| PENDING("pending"), | PENDING("pending"), | ||||
| DETERMINE1("determine1"), // qc failed qty? | DETERMINE1("determine1"), // qc failed qty? | ||||
| LOT_CHANGE_APPROVAL("lot-change"), // just a flag for frontend | LOT_CHANGE_APPROVAL("lot-change"), // just a flag for frontend | ||||
| CHECKED("checked"), | |||||
| PARTIALLY_COMPLETE("partially_completed"), | |||||
| REJECTED("rejected"), | REJECTED("rejected"), | ||||
| COMPLETE("completed"), // == picked | COMPLETE("completed"), // == picked | ||||
| } | } | ||||