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