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 PF(val common: CommonFilters, val productFilters: ProductFilters)
data class GetPrice(val productId: Long, val vendor: Any) data class GetPrice(val productId: Long, val vendor: Long, val po: Long?)
fun getPrice(ctx: Context) { fun getPrice(ctx: Context) {
val gp = ctx.bodyAsClass<GetPrice>() val gp = ctx.bodyAsClass<GetPrice>()
val vendor = Session.database.find(Vendor::class.java, gp.vendor) ?: throw BadRequestResponse("vendor not found for ${gp.vendor}") 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 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) 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() .where()
.eq("vendor", vendor) .eq("vendor", vendor)
.findList() .findList()
.flatMap { .flatMap { it.products }
it.products .firstOrNull { it.productId == product.sysPk }
}
.firstOrNull {
it.productId == product.sysPk
}
}
ctx.json( 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) { fun getAll(ctx: Context) {
val filters = ctx.bodyAsClass<PF>() val filters = ctx.bodyAsClass<PF>()
val prods = searchProducts(filters.common, filters.productFilters) val prods = searchProducts(filters.common, filters.productFilters)

View File

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