add filters, excel
This commit is contained in:
parent
dd55cd22cf
commit
0b75681236
@ -373,7 +373,7 @@ object Entities {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
data class Filters(val common :CommonFilters, val custom :CustomFilters)
|
||||
object PurchaseOrder {
|
||||
fun get(ctx :Context){
|
||||
val id = ctx.pathParam("id")
|
||||
@ -381,6 +381,12 @@ object PurchaseOrder {
|
||||
|
||||
ctx.json(po)
|
||||
}
|
||||
fun getAll(ctx :Context){
|
||||
val filters = ctx.bodyAsClass<Filters>()
|
||||
val poFilters :POFilters? = filters.custom as? POFilters
|
||||
val pos = searchPos(filters.common, poFilters)
|
||||
ctx.json(pos)
|
||||
}
|
||||
fun create(ctx :Context){
|
||||
val po = ctx.bodyAsClass<PurchaseOrder>()
|
||||
database.save(po)
|
||||
|
||||
@ -1,9 +1,29 @@
|
||||
package com.restapi.controllers
|
||||
import org.apache.poi
|
||||
import org.apache.poi.hssf.usermodel.HSSFSheet
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook
|
||||
import com.restapi.domain.Session.database
|
||||
|
||||
|
||||
import java.io.FileOutputStream
|
||||
enum class DataType {
|
||||
QUOTE, PO, VENDOR
|
||||
}
|
||||
fun CreateExcel(cols :List<String>, excelFor :DataType) {
|
||||
val wb = HSSFWorkbook()
|
||||
fun createHeaderRow(cols :List<String>, sh :HSSFSheet) {
|
||||
sh.createRow(0).apply {
|
||||
cols.forEachIndexed{index, value ->
|
||||
createCell(index).setCellValue(value)
|
||||
}
|
||||
}
|
||||
}
|
||||
fun ExportToExcel(cols :List<String>, data :List<List<String>>) {
|
||||
val wb = HSSFWorkbook()
|
||||
val sh = wb.createSheet()
|
||||
createHeaderRow(cols, sh)
|
||||
for((rowCount, row) in data.withIndex()) {
|
||||
sh.createRow(rowCount).apply{
|
||||
for((colCount, cell) in row.withIndex()) {
|
||||
createCell(colCount).setCellValue(cell)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -23,6 +23,7 @@ data class CommonFilters (
|
||||
val sortAsc :Boolean = true,
|
||||
val sortBy :String = IGNORE
|
||||
)
|
||||
interface CustomFilters{}
|
||||
data class POFilters (
|
||||
val poNumLike :String = IGNORE,
|
||||
val totalAmountExceeds :Long = Long.MIN_VALUE,
|
||||
@ -30,16 +31,18 @@ data class POFilters (
|
||||
val validAfter: LocalDate = baseDate,
|
||||
val validBefore: LocalDate = maxDate,
|
||||
val refQuotation :String = IGNORE,
|
||||
)
|
||||
) : CustomFilters
|
||||
data class ProductFilters (
|
||||
val nameLike :String = IGNORE,
|
||||
val hsnLike :String = IGNORE,
|
||||
val uom :UOM = UOM.ALL,
|
||||
)
|
||||
) : CustomFilters
|
||||
data class DocumentFilters (
|
||||
val nameLike :String = IGNORE,
|
||||
val typeOfDoc :DocType = DocType.ALL,
|
||||
)
|
||||
val docDateFrom :LocalDate = baseDate,
|
||||
val docDataTo :LocalDate = maxDate,
|
||||
) :CustomFilters
|
||||
data class RFQFilters (
|
||||
val validBefore :LocalDate = maxDate,
|
||||
val validAfter :LocalDate = baseDate,
|
||||
@ -51,7 +54,7 @@ data class QuoteFilters (
|
||||
val validAfter :LocalDate = maxDate,
|
||||
val totalAmountExceeds :Long = Long.MIN_VALUE,
|
||||
val totalAmountLessThan :Long = Long.MAX_VALUE,
|
||||
)
|
||||
) :CustomFilters
|
||||
data class VendorFilters (
|
||||
val nameLike :String = IGNORE,
|
||||
val msmeLike :String = IGNORE,
|
||||
@ -59,7 +62,7 @@ data class VendorFilters (
|
||||
val addressLike :String = IGNORE,
|
||||
val ratingExceeds :Double = RATING_MIN,
|
||||
val ratingLessThan :Double = RATING_MAX,
|
||||
)
|
||||
) :CustomFilters
|
||||
fun<T> applyVendorHelper(q :io.ebean.ExpressionList<T>, vids :List<Long>?) {
|
||||
if (vids.isNullOrEmpty()) return
|
||||
q.apply {
|
||||
@ -71,6 +74,10 @@ fun<T> applySortHelper(q :io.ebean.ExpressionList<T>, sortBy :String, asc :Boole
|
||||
val order = if (asc) "ASC" else "DESC"
|
||||
q.orderBy("$sortBy $order")
|
||||
}
|
||||
fun<T> applyFromToHelper(q :io.ebean.ExpressionList<T>, fromDate: LocalDate, toDate: LocalDate, colName :String) {
|
||||
q.ge(colName, fromDate)
|
||||
.le(colName, toDate)
|
||||
}
|
||||
fun<T> applyCommonFilters(q :io.ebean.ExpressionList<T>, commonFilters: CommonFilters) {
|
||||
applyVendorHelper<T>(q, commonFilters.vendor)
|
||||
applySortHelper<T>(q, commonFilters.sortBy, commonFilters.sortAsc)
|
||||
@ -78,12 +85,13 @@ fun<T> applyCommonFilters(q :io.ebean.ExpressionList<T>, commonFilters: CommonFi
|
||||
fun searchQuotes(commonFilters: CommonFilters, quoteFilters: QuoteFilters) : List<Quotation> {
|
||||
val q = database.find(Quotation::class.java)
|
||||
.where()
|
||||
.between("quoteDate", commonFilters.fromDate, commonFilters.toDate)
|
||||
.ilike("quoteNum", quoteFilters.quoteNumLike )
|
||||
.ge("quoteDate", commonFilters.fromDate)
|
||||
.le("quoteDate", commonFilters.toDate)
|
||||
.ge("validTill",quoteFilters.validAfter)
|
||||
.le("validTill", quoteFilters.validBefore)
|
||||
.le("totalAmount", quoteFilters.totalAmountLessThan)
|
||||
.ge("totalAmount", quoteFilters.totalAmountExceeds)
|
||||
.le("totalAmount", quoteFilters.totalAmountLessThan)
|
||||
.ilike("quoteNum", quoteFilters.quoteNumLike )
|
||||
.apply {
|
||||
if(!commonFilters.vendor?.isEmpty()!!){
|
||||
commonFilters.vendor.let { this.`in`("vendor", it) }
|
||||
@ -114,13 +122,17 @@ fun searchDocs(commonFilters: CommonFilters, documentFilters: DocumentFilters) :
|
||||
}
|
||||
.ilike("name", documentFilters.nameLike )
|
||||
applySortHelper(q, commonFilters.sortBy, commonFilters.sortAsc)
|
||||
applyVendorHelper(q, commonFilters.vendor)
|
||||
return q.findList()
|
||||
}
|
||||
fun searchPos(commonFilters: CommonFilters, poFilters: POFilters) : List<PurchaseOrder> {
|
||||
fun searchPos(commonFilters: CommonFilters, poFilters: POFilters?) : List<PurchaseOrder> {
|
||||
val poFilters = poFilters ?: POFilters()
|
||||
val q = database.find(PurchaseOrder::class.java)
|
||||
.where()
|
||||
.between("totalAmount", poFilters.totalAmountExceeds, poFilters.totalAmountLessThan)
|
||||
.between("validTill", poFilters.validAfter, poFilters.validBefore)
|
||||
.ge("totalAmount", poFilters.totalAmountExceeds)
|
||||
.le("totalAmount", poFilters.totalAmountLessThan)
|
||||
.ge("validTill", poFilters.validAfter)
|
||||
.le("validTill", poFilters.validBefore)
|
||||
.ilike("poNum", poFilters.poNumLike )
|
||||
.ilike("referenceQuotation", poFilters.refQuotation )
|
||||
applyVendorHelper(q, commonFilters.vendor)
|
||||
@ -130,7 +142,8 @@ fun searchPos(commonFilters: CommonFilters, poFilters: POFilters) : List<Purchas
|
||||
fun searchRFQ(commonFilters: CommonFilters, rfqFilters: RFQFilters) : List<ReqForQuote> {
|
||||
val q = database.find(ReqForQuote::class.java)
|
||||
.where()
|
||||
.between("validTill", rfqFilters.validAfter, rfqFilters.validBefore)
|
||||
.ge("validTill", rfqFilters.validAfter)
|
||||
.le("validTill", rfqFilters.validBefore)
|
||||
.ilike("reqForQuoteNum", rfqFilters.reqForQuoteNumLike)
|
||||
applyVendorHelper(q, commonFilters.vendor)
|
||||
applySortHelper(q, commonFilters.sortBy, commonFilters.sortAsc)
|
||||
|
||||
@ -312,6 +312,8 @@ open class Document :BaseTenantModel() {
|
||||
var refId: Long? = null
|
||||
var description :String = ""
|
||||
var url :String = ""
|
||||
var docDate :LocalDate? = null
|
||||
var vendor :Vendor? = null
|
||||
}
|
||||
|
||||
enum class RFQStatus{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user