handle po filter in incoming
This commit is contained in:
parent
a9961027d1
commit
9528134eda
@ -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)
|
||||
|
||||
@ -24,6 +24,7 @@ data class POProducts(
|
||||
val totalValue: Double = 0.0,
|
||||
val description: String = "",
|
||||
val uom: String = "",
|
||||
val poId: Long? = null
|
||||
)
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user