|
|
|
@@ -318,4 +318,55 @@ open class ItemsService( |
|
|
|
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); |
|
|
|
} |
|
|
|
} |