handle po filter in incoming

This commit is contained in:
gowthaman 2024-06-01 13:53:49 +05:30
parent a9961027d1
commit 9528134eda
2 changed files with 16 additions and 13 deletions

View File

@ -19,27 +19,29 @@ object ProductCtrl {
}
data class PF(val common: CommonFilters, val productFilters: ProductFilters)
data class GetPrice(val productId: Long, val vendor: Any)
fun getPrice(ctx: Context){
data class GetPrice(val productId: Long, val vendor: Long, val po: Long?)
fun getPrice(ctx: Context) {
val gp = ctx.bodyAsClass<GetPrice>()
val vendor = Session.database.find(Vendor::class.java, gp.vendor) ?: throw BadRequestResponse("vendor not found for ${gp.vendor}")
val product = Session.database.find(Product::class.java, gp.productId) ?: throw BadRequestResponse("product not found for ${gp.productId}")
val poProduct = Session.database.find(PurchaseOrder::class.java)
.where()
.eq("vendor", vendor)
.findList()
.flatMap {
it.products
}
.firstOrNull {
it.productId == product.sysPk
}
val poProduct = if (gp.po != null) {
Session.database.find(PurchaseOrder::class.java, gp.po)?.products?.firstOrNull { it.productId == product.sysPk }
} else {
Session.database.find(PurchaseOrder::class.java)
.where()
.eq("vendor", vendor)
.findList()
.flatMap { it.products }
.firstOrNull { it.productId == product.sysPk }
}
ctx.json(
poProduct ?: throw BadRequestResponse("price not found for this vendor and product")
poProduct ?: throw BadRequestResponse("price not found for this vendor and product and po")
)
}
fun getAll(ctx: Context) {
val filters = ctx.bodyAsClass<PF>()
val prods = searchProducts(filters.common, filters.productFilters)

View File

@ -24,6 +24,7 @@ data class POProducts(
val totalValue: Double = 0.0,
val description: String = "",
val uom: String = "",
val poId: Long? = null
)