diff --git a/.gitignore b/.gitignore index 64eadf0..acb5b73 100644 --- a/.gitignore +++ b/.gitignore @@ -43,4 +43,11 @@ bin/ application.yaml initial-data.sql app.yaml -*.env.json \ No newline at end of file +*.env.json + +### API Logs ### +api.log +api.2024* + +### Excel FIles ### +./excel \ No newline at end of file diff --git a/excel/Pos.xls b/excel/Pos.xls new file mode 100644 index 0000000..63ee154 Binary files /dev/null and b/excel/Pos.xls differ diff --git a/excel/Products.xls b/excel/Products.xls new file mode 100644 index 0000000..118f9e0 Binary files /dev/null and b/excel/Products.xls differ diff --git a/excel/Quotes.xls b/excel/Quotes.xls new file mode 100644 index 0000000..54a01e6 Binary files /dev/null and b/excel/Quotes.xls differ diff --git a/excel/VendorList.xls b/excel/VendorList.xls new file mode 100644 index 0000000..98fc001 Binary files /dev/null and b/excel/VendorList.xls differ diff --git a/src/main/kotlin/com/restapi/Main.kt b/src/main/kotlin/com/restapi/Main.kt index c297d01..0b7dfef 100644 --- a/src/main/kotlin/com/restapi/Main.kt +++ b/src/main/kotlin/com/restapi/Main.kt @@ -119,6 +119,7 @@ fun main(args: Array) { get("quotes/{id}", VendorCtrl::getQuotes, Roles(Role.Explicit("ROLE_QUOTE_VIEW", "ROLE_QUOTE_CREATE", "ROLE_VENDOR_VIEW"))) get("pos/{id}", VendorCtrl::getPos, Roles(Role.Explicit("ROLE_PO_VIEW", "ROLE_PO_CREATE`"))) put("/rate/{id}/{rating}", VendorCtrl::rate, Roles(Role.Explicit("ROLE_VENDOR_CREATE"))) + put("/{id}", VendorCtrl::update, Roles(Role.Explicit("ROLE_VENDOR_CREATE"))) } path("/po") { get("/next", PurchaseOrderCtrl::getNextNum, Roles(Role.Explicit("ROLE_PO_CREATE"))) @@ -126,6 +127,7 @@ fun main(args: Array) { post("/batch", PurchaseOrderCtrl::createBatch, Roles(Role.Explicit("ROLE_PO_CREATE"))) post("/getAll", PurchaseOrderCtrl::getAll, Roles(Role.Explicit("ROLE_PO_CREATE", "ROLE_PO_VIEW", "ROLE_VENDOR_CREATE"))) get("/{id}", PurchaseOrderCtrl::get, Roles(Role.Explicit("ROLE_PO_CREATE", "ROLE_PO_VIEW", "ROLE_QUOTE_CREATE"))) + put("/{id}", PurchaseOrderCtrl::update, Roles(Role.Explicit("ROLE_PO_CREATE"))) put("/approve/{id}", PurchaseOrderCtrl::approve, Roles(Role.Explicit())) put("/reject/{id}", PurchaseOrderCtrl::reject, Roles(Role.Explicit())) get("/refQuote/{id}", PurchaseOrderCtrl::quoteReference, Roles(Role.Explicit("ROLE_PO_CREATE"))) @@ -136,6 +138,7 @@ fun main(args: Array) { post("/batch", QuotationCtrl::createBatch, Roles(Role.Explicit("ROLE_QUOTE_CREATE"))) post("/getAll", QuotationCtrl::getAll, Roles(Role.Explicit("ROLE_QUOTE_CREATE", "ROLE_QUOTE_VIEW"))) get("/{id}", QuotationCtrl::get, Roles(Role.Explicit("ROLE_QUOTE_VIEW", "ROLE_QUOTE_CREATE"))) + put("/{id}", QuotationCtrl::update, Roles(Role.Explicit("ROLE_QUOTE_CREATE"))) delete("/{id}", QuotationCtrl::delete, Roles(Role.Explicit("ROLE_QUOTE_CREATE"))) } path("/product") { diff --git a/src/main/kotlin/com/restapi/controllers/Entities.kt b/src/main/kotlin/com/restapi/controllers/Entities.kt index 0e6ddf7..e1262b0 100644 --- a/src/main/kotlin/com/restapi/controllers/Entities.kt +++ b/src/main/kotlin/com/restapi/controllers/Entities.kt @@ -14,6 +14,7 @@ import io.ebean.CallableSql import io.ebean.RawSqlBuilder import io.javalin.http.* import org.slf4j.LoggerFactory +import java.io.FileInputStream import java.sql.Types import java.time.LocalDate import java.time.LocalDateTime @@ -396,7 +397,14 @@ object PurchaseOrderCtrl { fun getAll(ctx: Context) { val filters = ctx.bodyAsClass() val pos = searchPos(filters.common, filters.poFilters) - ctx.json(pos).status(HttpStatus.OK) + val excel = ctx.queryParam("excel") + if(excel != null){ + exportPos(pos) + val inputStream = FileInputStream("./excel/Pos.xls") + ctx.result(inputStream).status(HttpStatus.OK) + }else{ + ctx.json(pos).status(HttpStatus.OK) + } } fun create(ctx: Context) { @@ -450,13 +458,16 @@ object PurchaseOrderCtrl { ?: throw NotFoundResponse("reference quotation not found for po $id") ctx.json(quote) } + fun update(ctx: Context) { - val id = ctx.pathParam("id") + val id = ctx.pathParam("id").toLong() val po = database.find(PurchaseOrder::class.java, id) ?: throw NotFoundResponse("po not found for $id") val updatedPo = ctx.bodyAsClass() po.patchValues(updatedPo) po.update() + ctx.json(po).status(HttpStatus.OK) } + fun delete(ctx: Context) { val id = ctx.pathParam("id") val po = database.find(PurchaseOrder::class.java, id) ?: throw NotFoundResponse("no po found with id $id") @@ -487,8 +498,15 @@ object ProductCtrl { val productList = Session.database.find(Product::class.java) .findList() .sortedBy { it.name } + val excel = ctx.queryParam("excel") + if(excel != null){ + exportProds(productList) + val inputStream = FileInputStream("./excel/Products.xls") + ctx.result(inputStream).status(HttpStatus.OK) - ctx.json(productList) + }else{ + ctx.json(productList) + } } fun create(ctx: Context) { @@ -496,12 +514,14 @@ object ProductCtrl { database.save(product) ctx.json(product).status(HttpStatus.CREATED) } + fun delete(ctx: Context) { val id = ctx.pathParam("id") val prod = database.find(Product::class.java, id) ?: throw NotFoundResponse("no product found with id $id") database.delete(prod) ctx.status(HttpStatus.OK) } + fun patch(ctx: Context) { val id = ctx.pathParam("id") val patchValues = ctx.bodyAsClass>() @@ -520,11 +540,12 @@ object ProductCtrl { } fun update(ctx: Context) { - val id = ctx.pathParam("id") + val id = ctx.pathParam("id").toLong() val product = database.find(Product::class.java, id) ?: throw NotFoundResponse("product not found for $id") val updatedProduct = ctx.bodyAsClass() product.patchValues(updatedProduct) product.update() + ctx.json(product).status(HttpStatus.OK) } @@ -573,8 +594,15 @@ object QuotationCtrl { fun getAll(ctx: Context) { val filters = ctx.bodyAsClass() + val excel: String? = ctx.queryParam("excel") val quotes = searchQuotes(filters.common, filters.quoteFilters) - ctx.json(quotes).status(HttpStatus.OK) + if (excel != null) { + exportQuotations(quotes) + val inputStream = FileInputStream("./excel/Quotes.xls") + ctx.result(inputStream).status(HttpStatus.OK) + } else { + ctx.json(quotes).status(HttpStatus.OK) + } } fun create(ctx: Context) { @@ -599,18 +627,21 @@ object QuotationCtrl { } ctx.result("Quotes batch created").status(HttpStatus.CREATED) } + fun delete(ctx: Context) { val id = ctx.pathParam("id") val quote = database.find(Quotation::class.java, id) ?: throw NotFoundResponse("no quote found with id $id") database.delete(quote) ctx.status(HttpStatus.OK) } + fun update(ctx: Context) { - val id = ctx.pathParam("id") + val id = ctx.pathParam("id").toLong() val quote = database.find(Quotation::class.java, id) ?: throw NotFoundResponse("quote not found for $id") val updatedQuote = ctx.bodyAsClass() quote.patchValues(updatedQuote) quote.update() + ctx.json(quote).status(HttpStatus.OK) } } @@ -632,12 +663,14 @@ object DocumentCtrl { fun print(ctx: Context) { //would be handled in the frontend ?? } + fun delete(ctx: Context) { val id = ctx.pathParam("id") val doc = database.find(Document::class.java, id) ?: throw NotFoundResponse("no document found with id $id") database.delete(doc) ctx.status(HttpStatus.OK) } + fun getWithRefId(ctx: Context) { //fetches a particular doc (po, quote) with ref id val refId = ctx.pathParam("refId") @@ -655,8 +688,8 @@ object DocumentCtrl { object VendorCtrl { val logger = LoggerFactory.getLogger("Vendor") fun get(ctx: Context) { - val id = ctx.pathParam("id") - val vendor =database.find(Vendor::class.java, id) ?: throw NotFoundResponse("no vendor found with id $id") + val id = ctx.pathParam("id").toLong() + val vendor = database.find(Vendor::class.java, id) ?: throw NotFoundResponse("no vendor found with id $id") ctx.status(HttpStatus.OK) ctx.json(vendor) } @@ -666,9 +699,15 @@ object VendorCtrl { fun getAll(ctx: Context) { val filters = ctx.bodyAsClass() logger.info("filters = {}", filters) - val pos = searchVendors(filters.common, filters.vendorFilters) - ctx.status(HttpStatus.OK) - ctx.json(pos) + val excel: String? = ctx.queryParam("excel") + val vendors = searchVendors(filters.common, filters.vendorFilters) + if (excel !== null) { + exportVendors(vendors) + val inputStream = FileInputStream("./excel/VendorList.xls") + ctx.result(inputStream).status(HttpStatus.OK) + } else { + ctx.json(vendors).status(HttpStatus.OK) + } } fun createBatch(ctx: Context) { @@ -684,12 +723,14 @@ object VendorCtrl { } fun update(ctx: Context) { - val id = ctx.pathParam("id") + val id = ctx.pathParam("id").toLong() val vendor = database.find(Vendor::class.java, id) ?: throw NotFoundResponse("vendor not found for $id") val updatedVendor = ctx.bodyAsClass() vendor.patchValues(updatedVendor) vendor.update() + ctx.json(vendor).status(HttpStatus.OK) } + fun delete(ctx: Context) { val id = ctx.pathParam("id") val vendor = database.find(Vendor::class.java, id) ?: throw NotFoundResponse("no vendor found with id $id") diff --git a/src/main/kotlin/com/restapi/controllers/Excel.kt b/src/main/kotlin/com/restapi/controllers/Excel.kt index 833cbd0..292e051 100644 --- a/src/main/kotlin/com/restapi/controllers/Excel.kt +++ b/src/main/kotlin/com/restapi/controllers/Excel.kt @@ -1,4 +1,5 @@ package com.restapi.controllers + import com.google.gson.Gson import com.restapi.domain.* import com.restapi.domain.Document @@ -25,7 +26,7 @@ import java.time.LocalDate import java.time.ZoneId import java.util.* -fun createHeaderRow(cols :List, sh :HSSFSheet, wb: Workbook) { +fun createHeaderRow(cols: List, sh: HSSFSheet, wb: Workbook) { val boldFont = wb.createFont() boldFont.bold = true val style = wb.createCellStyle() @@ -33,13 +34,14 @@ fun createHeaderRow(cols :List, sh :HSSFSheet, wb: Workbook) { style.locked = true sh.createRow(0).apply { - cols.forEachIndexed{index, value -> + cols.forEachIndexed { index, value -> val cell = createCell(index) cell.setCellValue(value) cell.setCellStyle(style) } } } + fun String.parseDate(format: String): Date? { val locale = Locale.getDefault() return try { @@ -48,227 +50,310 @@ fun String.parseDate(format: String): Date? { null } } -fun dateFromCellHelper(cell: Cell): LocalDate?{ - val date = when(cell.cellType){ + +fun dateFromCellHelper(cell: Cell): LocalDate? { + val date = when (cell.cellType) { CellType.STRING -> cell.stringCellValue.parseDate("yyyy-MM-dd") CellType.NUMERIC -> { if (DateUtil.isCellDateFormatted(cell)) { cell.getDateCellValue() - } else{ + } else { null } } + else -> null } return date?.toInstant()?.atZone(ZoneId.systemDefault())?.toLocalDate() } + fun stringFromCellHelper(cell: Cell): String { - val string = when(cell.cellType){ + val string = when (cell.cellType) { CellType.NUMERIC -> cell.numericCellValue.toString() CellType.STRING -> cell.stringCellValue else -> "" } return string } + fun doubleFromCellHelper(cell: Cell): Double { - val double = when(cell.cellType){ + val double = when (cell.cellType) { CellType.NUMERIC -> cell.numericCellValue CellType.STRING -> cell.stringCellValue.toDoubleOrNull() else -> 0.0 } - return double?:0.0 + return double ?: 0.0 } -fun longIntFromCellHelper(cell : Cell) :Long { - val long = when(cell.cellType){ +fun longIntFromCellHelper(cell: Cell): Long { + val long = when (cell.cellType) { CellType.NUMERIC -> cell.numericCellValue.toLong() CellType.STRING -> cell.stringCellValue.toLong() else -> 0 } return long } + enum class FileType { QUOTES, POS, VENDORS, PRODS, DOCS } + enum class EnumFor { UOM, DocType } -fun saveExcelFileLocally(fileName :String, wb: Workbook){ - val out = FileOutputStream(fileName) +fun saveExcelFileLocally(fileName: String, wb: Workbook) { + val path = "./excel/" + val out = FileOutputStream(path + fileName) wb.use { it.write(out) } out.close() } -fun TemplateExcelFile(fileType: FileType){ - when(fileType){ + +fun TemplateExcelFile(fileType: FileType) { + when (fileType) { FileType.QUOTES -> { - val headers : List = listOf("Quotation Number", "Date", "Open Till", "Product Id", "Product Name", "Product Unit Price", "Quantity", "Vendor Name", "Vendor Address", "RFQ Number", "Total Amount", "Terms and Conditions") + val headers: List = listOf( + "Quotation Number", + "Date", + "Open Till", + "Product Id", + "Product Name", + "Product Unit Price", + "Quantity", + "Vendor Name", + "Vendor Address", + "RFQ Number", + "Total Amount", + "Terms and Conditions" + ) val wb = HSSFWorkbook() val sh = wb.createSheet() createHeaderRow(headers, sh, wb) saveExcelFileLocally("Quotes_Template.xls", wb) } + FileType.POS -> { - val headers : List = listOf("Number", "Date", "Open Till", "Reference Quotation Number", "Vendor Name", "Vendor Address", "Product Id", "Product Name", "Unit Price", "Quantity", "Total Amount", "Terms and Conditions") + val headers: List = listOf( + "Number", + "Date", + "Open Till", + "Reference Quotation Number", + "Vendor Name", + "Vendor Address", + "Product Id", + "Product Name", + "Unit Price", + "Quantity", + "Total Amount", + "Terms and Conditions" + ) val wb = HSSFWorkbook() val sh = wb.createSheet() createHeaderRow(headers, sh, wb) saveExcelFileLocally("Purchase_Order_Template.xls", wb) } + FileType.VENDORS -> { - val headers : List = listOf("Name", "MSME", "GST Number", "Address", "Rating", "Contact Name", "Contact Email", "Contact Mobile") + val headers: List = listOf( + "Name", + "MSME", + "GST Number", + "Address", + "Rating", + "Contact Name", + "Contact Email", + "Contact Mobile" + ) val wb = HSSFWorkbook() val sh = wb.createSheet() createHeaderRow(headers, sh, wb) saveExcelFileLocally("Vendors_Template.xls", wb) } + FileType.PRODS -> { - val headers : List = listOf("Id", "Name", "Description", "HSN Code", "UOM") + val headers: List = listOf("Id", "Name", "Description", "HSN Code", "UOM") val wb = HSSFWorkbook() val sh = wb.createSheet() createHeaderRow(headers, sh, wb) val r0 = CellRangeAddressList(0, 1000, 4, 4) - val dv0 = HSSFDataValidation(r0, DVConstraint.createExplicitListConstraint(arrayOf("LTR", "MTR", "NOS", "ALL"))).apply { + val dv0 = HSSFDataValidation( + r0, + DVConstraint.createExplicitListConstraint(arrayOf("LTR", "MTR", "NOS", "ALL")) + ).apply { suppressDropDownArrow = true } sh.addValidationData(dv0) saveExcelFileLocally("Products_Template.xls", wb) } + FileType.DOCS -> { } } } -fun ExportQuotations(quotes :List) { + +fun exportQuotations(quotes: List) { val wb = HSSFWorkbook() val sh = wb.createSheet() - val headers : List = listOf("Quotation Number", "Date", "Open Till", "Product Id", "Product Name", "Product Unit Price", "Quantity", "Vendor Name", "Vendor Address", "RFQ Number", "Total AMount", "Terms and Conditions") + val headers: List = listOf( + "Quotation Number", + "Date", + "Open Till", + "Product Id", + "Product Name", + "Product Unit Price", + "Quantity", + "Vendor Name", + "Vendor Address", + "RFQ Number", + "Total AMount", + "Terms and Conditions" + ) createHeaderRow(headers, sh, wb) - val totalCols = headers.size var rowCnt = 1 - for(quote in quotes){ + for (quote in quotes) { val prodCnt = quote.products.size - for (j in 0..prodCnt - 1){ + for (j in 0..){ +fun exportVendors(vendors: List) { val wb = HSSFWorkbook() val sh = wb.createSheet() - val headers : List = listOf("Name", "MSME", "GST Number", "Address", "Rating", "Contact Name", "Contact Email", "Contact Mobile") + val headers: List = + listOf("No.", "Name", "MSME", "GST Number", "Address", "Rating", "Contact Name", "Contact Email", "Contact Mobile") createHeaderRow(headers, sh, wb) val totalCols = headers.size var rowCnt = 1 - for (vendor in vendors){ + for (vendor in vendors) { val contactCnt = vendor.contacts.size - for (j in 0..contactCnt - 1){ + for (j in 0..){ +fun exportProds(prods: List) { val wb = HSSFWorkbook() val sh = wb.createSheet() - val headers : List = listOf("Id", "Name", "Description", "HSN Code", "UOM") + val headers: List = listOf("Id", "Name", "Description", "HSN Code", "UOM") createHeaderRow(headers, sh, wb) - val totalCols = headers.size var rowCnt = 1 - for (prod in prods){ + for (prod in prods) { val row = sh.createRow(rowCnt++) var i = 0 - row.createCell(i++).setCellValue(prod.id.toString()) - row.createCell(i++).setCellValue(prod.name) - row.createCell(i++).setCellValue(prod.description) - row.createCell(i++).setCellValue(prod.hsnCode) - row.createCell(i++).setCellValue(prod.uom?.name) + row.createCell(i++).setCellValue(prod.id.toString()) + row.createCell(i++).setCellValue(prod.name) + row.createCell(i++).setCellValue(prod.description) + row.createCell(i++).setCellValue(prod.hsnCode) + row.createCell(i++).setCellValue(prod.uom?.name) } + saveExcelFileLocally("Products.xls", wb) } -fun ExportPos(pos :List){ + +fun exportPos(pos: List) { val wb = HSSFWorkbook() val sh = wb.createSheet() - val headers : List = listOf("Number", "Date", "Open Till", "Reference Quotation Number", "Vendor Name", "Vendor Address", "Product Id", "Product Name", "Unit Price", "Quantity", "Total Amount", "Terms and Conditions") + val headers: List = listOf( + "Number", + "Date", + "Open Till", + "Reference Quotation Number", + "Vendor Name", + "Vendor Address", + "Product Id", + "Product Name", + "Unit Price", + "Quantity", + "Total Amount", + "Terms and Conditions" + ) createHeaderRow(headers, sh, wb) - val totalCols = headers.size var rowCnt = 1 - for(po in pos){ + for (po in pos) { val prodCnt = po.products.size - for (j in 0..prodCnt - 1){ + for (j in 0.. { //Quote Number, ProductName, Product Quantity, Total Amount, RFQ Number, Quote Date, Valid Till, TNC[], Documents[] - val quotesMap : MutableMap = mutableMapOf() - val quotesList : List = mutableListOf() + val quotesMap: MutableMap = mutableMapOf() + val quotesList: List = mutableListOf() sh.rowIterator().forEach { row -> - if(row == null){ + if (row == null) { //reached eof return@forEach } @@ -288,7 +373,7 @@ fun ImportFromExcel(fileType: FileType, filePath : String) { if (quotesMap.containsKey(quoteNumber)) { //duplicated row quotesMap.get(quoteNumber)?.products?.add(prod) - }else { + } else { val v = Vendor() v.apply { name = vendorName @@ -309,17 +394,18 @@ fun ImportFromExcel(fileType: FileType, filePath : String) { } } //docs, tncs - // println("$quotesMap") + // println("$quotesMap") // quotesMap.forEach { (k, v) -> // println("$v") // } } + FileType.POS -> { //poNum, poDate, validTill, refQuoteNum, prodName, prodQuantity, totalAmount, products, vendorName, vendorGst, vendorAddress, tnc[]. docs[] - val PoMap : MutableMap = mutableMapOf() + val PoMap: MutableMap = mutableMapOf() sh.rowIterator().forEach { row -> - if(row == null) return@forEach + if (row == null) return@forEach val poNum = stringFromCellHelper(row.getCell(0)) val poDate = dateFromCellHelper(row.getCell(1)) val refQuoteNum = stringFromCellHelper(row.getCell(2)) @@ -332,11 +418,11 @@ fun ImportFromExcel(fileType: FileType, filePath : String) { val totalPoAmount = doubleFromCellHelper(row.getCell(9)) //tncs, docs - val prod = POProducts("", prodName, 0.0, prodQuantity,"") - if(PoMap.containsKey(poNum)){ + val prod = POProducts("", prodName, 0.0, prodQuantity, "") + if (PoMap.containsKey(poNum)) { //repeated row PoMap.get(poNum)?.products?.add(prod) - }else{ + } else { val vendor = Vendor() vendor.name = vendorName vendor.address = vendorAddress @@ -350,15 +436,16 @@ fun ImportFromExcel(fileType: FileType, filePath : String) { } } } + FileType.VENDORS -> { sh.rowIterator().forEach { row -> //name, msme, gstNum, addresss, rating, contacts - if(row == null) return@forEach + if (row == null) return@forEach val name = stringFromCellHelper(row.getCell(0)) val msme = stringFromCellHelper(row.getCell(1)) val gstNum = stringFromCellHelper(row.getCell(2)) val address = stringFromCellHelper(row.getCell(3)) - val rating = doubleFromCellHelper(row.getCell(4)) + val rating = doubleFromCellHelper(row.getCell(4)) //vendor object val vendor = Vendor() @@ -369,9 +456,10 @@ fun ImportFromExcel(fileType: FileType, filePath : String) { vendor.rating = rating } } + FileType.PRODS -> { sh.rowIterator().forEach { row -> - if(row == null) return@forEach + if (row == null) return@forEach //id, name, description, hsnCode, uom val prodId = longIntFromCellHelper(row.getCell(0)) val prodName = stringFromCellHelper(row.getCell(1)) @@ -385,7 +473,7 @@ fun ImportFromExcel(fileType: FileType, filePath : String) { prod.name = prodName prod.description = prodDesc prod.hsnCode = prodHsnCode - prod.uom = when(prodUom) { + prod.uom = when (prodUom) { "nos" -> UOM.NOS "ltr" -> UOM.LTR "mtr" -> UOM.MTR @@ -393,6 +481,7 @@ fun ImportFromExcel(fileType: FileType, filePath : String) { } } } + FileType.DOCS -> { sh.rowIterator().forEach { row -> //Document Name, Document Type, RefID, url @@ -405,7 +494,7 @@ fun ImportFromExcel(fileType: FileType, filePath : String) { //new doc object val doc = Document() doc.name = docName - doc.typeOfDoc = when(docType) { + doc.typeOfDoc = when (docType) { "quote" -> DocType.QUOTE "po" -> DocType.PO "invoice" -> DocType.INVOICE diff --git a/src/main/kotlin/com/restapi/controllers/Filters.kt b/src/main/kotlin/com/restapi/controllers/Filters.kt index 7745f7f..a329843 100644 --- a/src/main/kotlin/com/restapi/controllers/Filters.kt +++ b/src/main/kotlin/com/restapi/controllers/Filters.kt @@ -14,8 +14,8 @@ const val RATING_MIN = 0.0 //common filters would be used by most of the handlers //require a list of vendor ids to be passed data class CommonFilters( - val fromDate: LocalDate = baseDate, - val toDate: LocalDate = maxDate, + val from: LocalDate = baseDate, + val to: LocalDate = maxDate, val vendor: List? = null, val sortAsc: Boolean = true, val sortBy: String = IGNORE @@ -97,14 +97,14 @@ fun applyCommonFilters(q: io.ebean.ExpressionList, commonFilters: CommonF fun searchQuotes(commonFilters: CommonFilters, quoteFilters: QuoteFilters): List { val q = database.find(Quotation::class.java) .where() - .ge("quoteDate", commonFilters.fromDate) - .le("quoteDate", commonFilters.toDate) + .ge("quoteDate", commonFilters.from) + .le("quoteDate", commonFilters.to) .ge("validTill", quoteFilters.validAfter) .le("validTill", quoteFilters.validBefore) .ge("totalAmount", quoteFilters.totalAmountExceeds) .le("totalAmount", quoteFilters.totalAmountLessThan) .ilike("quoteNum", "%" + quoteFilters.quoteNumLike + "%") - applyFromToHelper(q, commonFilters.fromDate, commonFilters.toDate, "quoteDate") + applyFromToHelper(q, commonFilters.from, commonFilters.to, "quoteDate") applyVendorHelper(q, commonFilters.vendor) applySortHelper(q, commonFilters.sortBy, commonFilters.sortAsc) return q.findList() @@ -123,6 +123,18 @@ fun searchVendors(commonFilters: CommonFilters, vendorFilters: VendorFilters): L return q.findList() } +fun searchProducts(commonFilters: CommonFilters, productFilters: ProductFilters) : List { + 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) + return q.findList() +} fun searchDocs(commonFilters: CommonFilters, documentFilters: DocumentFilters): List { val q = database.find(Document::class.java) .where() @@ -147,7 +159,7 @@ fun searchPos(commonFilters: CommonFilters, poFilters: POFilters?): List = mutableListOf() @@ -306,8 +325,16 @@ open class Product : BaseTenantModel() { @Entity open class Quotation : BaseTenantModel() { - fun patchValues(updatedQuote : Quotation) { - + fun patchValues(updatedQuote: Quotation) { + this.quoteDate = updatedQuote.quoteDate + this.vendorQuoteNum = updatedQuote.vendorQuoteNum + this.validTill = updatedQuote.validTill + this.reqForQuoteNum = updatedQuote.reqForQuoteNum + this.tnc = updatedQuote.tnc + this.products = updatedQuote.products + this.vendor = updatedQuote.vendor + this.documents = updatedQuote.documents + this.totalAmount = updatedQuote.totalAmount } @DbJsonB