|
|
|
|
@@ -2,7 +2,9 @@ package com.restapi.controllers
|
|
|
|
|
|
|
|
|
|
import com.restapi.domain.*
|
|
|
|
|
import com.restapi.domain.Session.database
|
|
|
|
|
import net.jodah.expiringmap.ExpiringMap
|
|
|
|
|
import java.time.LocalDate
|
|
|
|
|
import java.util.concurrent.TimeUnit
|
|
|
|
|
|
|
|
|
|
//constants
|
|
|
|
|
const val IGNORE = "%"
|
|
|
|
|
@@ -98,16 +100,16 @@ data class PaymentFilters(
|
|
|
|
|
) : CustomFilters
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data class FleetFilters(
|
|
|
|
|
val fleetNameLike: String = IGNORE
|
|
|
|
|
):CustomFilters
|
|
|
|
|
) : CustomFilters
|
|
|
|
|
|
|
|
|
|
data class ReminderLogFilters(
|
|
|
|
|
val reminderType: String = IGNORE,
|
|
|
|
|
val actedUpon: Boolean? = null,
|
|
|
|
|
val fleetId: Long? = null
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
fun <T> applyVendorHelper(q: io.ebean.ExpressionList<T>, vids: List<Long>?) {
|
|
|
|
|
if (vids.isNullOrEmpty()) return
|
|
|
|
|
// q.apply {
|
|
|
|
|
@@ -163,17 +165,23 @@ fun searchVendors(commonFilters: CommonFilters, vendorFilters: VendorFilters): L
|
|
|
|
|
return q.findList()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun searchProducts(commonFilters: CommonFilters, productFilters: ProductFilters): List<Product> {
|
|
|
|
|
val q = database.find(Product::class.java)
|
|
|
|
|
.where()
|
|
|
|
|
.ilike("name", "%" + productFilters.nameLike + "%")
|
|
|
|
|
.ilike("hsnCode", "%" + productFilters.hsnLike + "%")
|
|
|
|
|
private val productCache = ExpiringMap.builder()
|
|
|
|
|
.expiration(5, TimeUnit.MINUTES)
|
|
|
|
|
.build<String, List<Product>>()
|
|
|
|
|
|
|
|
|
|
if (productFilters.uom != UOM.ALL) {
|
|
|
|
|
q.eq("uom", productFilters.uom)
|
|
|
|
|
fun searchProducts(commonFilters: CommonFilters, productFilters: ProductFilters): List<Product> {
|
|
|
|
|
return productCache.computeIfAbsent("$commonFilters:$productFilters:${Session.currentUser()}") {
|
|
|
|
|
val q = database.find(Product::class.java)
|
|
|
|
|
.where()
|
|
|
|
|
.ilike("name", "%" + productFilters.nameLike + "%")
|
|
|
|
|
.ilike("hsnCode", "%" + productFilters.hsnLike + "%")
|
|
|
|
|
|
|
|
|
|
if (productFilters.uom != UOM.ALL) {
|
|
|
|
|
q.eq("uom", productFilters.uom)
|
|
|
|
|
}
|
|
|
|
|
applySortHelper(q, commonFilters.sortBy, commonFilters.sortAsc)
|
|
|
|
|
q.findList()
|
|
|
|
|
}
|
|
|
|
|
applySortHelper(q, commonFilters.sortBy, commonFilters.sortAsc)
|
|
|
|
|
return q.findList()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun searchDocs(commonFilters: CommonFilters, documentFilters: DocumentFilters): List<Document> {
|
|
|
|
|
@@ -267,17 +275,17 @@ fun searchInvoices(commonFilters: CommonFilters, invoiceFilters: InvoiceFilters)
|
|
|
|
|
|
|
|
|
|
fun searchPayments(commonFilters: CommonFilters, paymentFilters: PaymentFilters): List<Payment> {
|
|
|
|
|
val q = database.find(Payment::class.java)
|
|
|
|
|
.where()
|
|
|
|
|
.where()
|
|
|
|
|
.ilike("refNumber", "%" + paymentFilters.refNumberLike + "%")
|
|
|
|
|
// .ge("amount", paymentFilters.amountExceeds)
|
|
|
|
|
//.le("amount", paymentFilters.amountLessThan)
|
|
|
|
|
// .ge("amount", paymentFilters.amountExceeds)
|
|
|
|
|
//.le("amount", paymentFilters.amountLessThan)
|
|
|
|
|
applyFromToHelper(q, commonFilters.from, commonFilters.to, "date")
|
|
|
|
|
applyVendorHelper(q, commonFilters.vendor)
|
|
|
|
|
applySortHelper(q, commonFilters.sortBy, commonFilters.sortAsc)
|
|
|
|
|
return q.findList()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun searchFleets(filters: CommonFilters, fleetFilters: FleetFilters) : List<Fleet> {
|
|
|
|
|
fun searchFleets(filters: CommonFilters, fleetFilters: FleetFilters): List<Fleet> {
|
|
|
|
|
val q = database.find(Fleet::class.java)
|
|
|
|
|
.where()
|
|
|
|
|
.ilike("name", "%" + fleetFilters.fleetNameLike + "%")
|
|
|
|
|
@@ -290,17 +298,17 @@ fun searchFleets(filters: CommonFilters, fleetFilters: FleetFilters) : List<Flee
|
|
|
|
|
// applyFromToHelper(q, filters.from, filters.to, "insuranceRenewalDate")
|
|
|
|
|
// applyFromToHelper(q, filters.from, filters.to, "pollutionRenewalDate")
|
|
|
|
|
// applyFromToHelper(q, filters.from, filters.to, "fitnessRenewalDate")
|
|
|
|
|
return q.findList()
|
|
|
|
|
return q.findList()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun searchReminderLogs(filters: CommonFilters, reminderLogFilters: ReminderLogFilters) : List<ReminderLog> {
|
|
|
|
|
fun searchReminderLogs(filters: CommonFilters, reminderLogFilters: ReminderLogFilters): List<ReminderLog> {
|
|
|
|
|
val q = database.find(ReminderLog::class.java)
|
|
|
|
|
.where()
|
|
|
|
|
.ilike("reminder_type", reminderLogFilters.reminderType)
|
|
|
|
|
if(reminderLogFilters.actedUpon != null){
|
|
|
|
|
if (reminderLogFilters.actedUpon != null) {
|
|
|
|
|
q.eq("acted_upon", reminderLogFilters.actedUpon)
|
|
|
|
|
}
|
|
|
|
|
if(reminderLogFilters.fleetId != null){
|
|
|
|
|
if (reminderLogFilters.fleetId != null) {
|
|
|
|
|
q.eq("fleet_sys_pk", reminderLogFilters.fleetId)
|
|
|
|
|
}
|
|
|
|
|
return q.findList()
|
|
|
|
|
|